if (!has_capability('moodle/course:view', $context, $userid, false)) {
error('This user is not in this course!');
}
+ if (has_capability('moodle/site:doanything', $context, $userid, false)) {
+ print_error('nologinas');
+ }
}
/// User must have permissions
$string['mustbeteacher'] = 'You must be a teacher to look at this page';
$string['nocontext'] = 'Sorry, but that course is not a valid context';
$string['noinstances'] = 'There are no instances of $a in this course!';
+$string['nologinas'] = 'You are not allowed to login as that user';
$string['nonmeaningfulcontent'] = 'Non meaningful content';
$string['noparticipatorycms'] = 'Sorry, but you have no participatory course modules to report on.';
$string['nopermissions'] = 'Sorry, but you do not currently have permissions to do that ($a)';
if (has_capability('moodle/role:assign', $context, NULL)) { // Includes admins
$output .= '<a href="'. $CFG->wwwroot .'/course/unenrol.php?id='. $course->id .'&user='. $user->id .'">'. $string->unenrol .'</a><br />';
}
- if ($USER->id != $user->id && has_capability('moodle/user:loginas', $context)) {
+ if ($USER->id != $user->id && has_capability('moodle/user:loginas', $context) &&
+ ! has_capability('moodle/site:doanything', $context, $user->id, false)) {
$output .= '<a href="'. $CFG->wwwroot .'/course/loginas.php?id='. $course->id .'&user='. $user->id .'">'. $string->loginas .'</a><br />';
}
$output .= '<a href="'. $CFG->wwwroot .'/user/view.php?id='. $user->id .'&course='. $course->id .'">'. $string->fullprofile .'...</a>';
}
}
- if ($USER->id != $user->id && has_capability('moodle/user:loginas', $coursecontext)) {
+ if ($USER->id != $user->id && has_capability('moodle/user:loginas', $coursecontext) &&
+ ! has_capability('moodle/site:doanything', $coursecontext, $user->id, false)) {
echo '<form action="'.$CFG->wwwroot.'/course/loginas.php" method="get">';
echo "<fieldset class='invisiblefieldset'>";
echo '<input type="hidden" name="id" value="'.$course->id.'" />';