error("Course ID was incorrect");
}
- if (!isteacher($course->id)) {
- error("Only teachers can use this page!");
- }
+ require_capability('moodle/course:viewcoursegrades', get_context_instance(CONTEXT_COURSE, $id));
$strgrades = get_string("grades");
$strgrade = get_string("grade");
$showcourses = 1;
}
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);
+
/// Setup for group handling.
- $isteacher = isteacher($course->id);
- $isteacheredit = isteacheredit($course->id);
- if ($course->groupmode == SEPARATEGROUPS and !$isteacheredit) {
+ if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)) {
$selectedgroup = get_current_group($course->id);
$showgroups = false;
}
if ($showusers) {
if ($courseusers) {
foreach ($courseusers as $courseuser) {
- $users[$courseuser->id] = fullname($courseuser, $isteacher);
+ $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', $context));
}
}
if ($guest = get_guest()) {
// Construct some other ones about which fields are shown
- $isteacher = isteacher($courseid);
+ $isteacher = has_capability('moodle/course:managegrades', get_context_instance(CONTEXT_COURSE, $courseid));
$preferences->show_weighted = (($preferences->display_weighted > 0 && $isteacher) ||
($preferences->display_weighted > 1 && !$isteacher));
function grade_preferences_menu($action, $course, $group=0) {
- if (!isteacher($course->id)) {
+ has_capability('moodle/course:managegrades', get_context_instance(CONTEXT_COURSE, $courseid)) {
return;
}
$strgrades = get_string('grades', 'grades');
$gradenav = "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a>";
- if (isteacher($course->id)) {
+ if (has_capability('moodle/course:managegrades', get_context_instance(CONTEXT_COURSE, $course->id))) {
switch ($action) {
case 'prefs':
case 'set_grade_preferences':
// Next, check if the user can be in a particular course
if ($courseid) {
if ($courseid == SITEID) { // Anyone can be in the site course
- if (isset($cm) and !$cm->visible and !isteacher(SITEID)) { // Not allowed to see module, send to course page
+ if (isset($cm) and !$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_SYSTEM, SITEID))) { // Not allowed to see module, send to course page
redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course, get_string('activityiscurrentlyhidden'));
}
return;
if (has_capability('moodle/course:view', $context)) {
if (isset($USER->realuser)) { // Make sure the REAL person can also access this course
- if (!isteacher($courseid, $USER->realuser)) {
+ if (!has_capability('moodle/course:view', $context, $USER->realuser)) {
print_header();
notice(get_string('studentnotallowed', '', fullname($USER, true)), $CFG->wwwroot .'/');
}
}
- if (isset($cm) and !$cm->visible and !isteacher($courseid)) { // Not allowed to see module, send to course page
+ if (isset($cm) and !$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) { // Not allowed to see module, send to course page
redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course, get_string('activityiscurrentlyhidden'));
}
return; // user is a member of this course.
if (empty($user->editing)) {
return false;
}
- return ($user->editing and isteacher($courseid, $user->id));
+ return ($user->editing and has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $courseid)));
}
/**
global $SESSION, $USER;
if (!isset($SESSION->currentgroup[$courseid])) {
- if (empty($USER->groupmember[$courseid]) or isteacheredit($courseid)) {
+ if (empty($USER->groupmember[$courseid]) or has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $courseid))) {
return 0;
} else {
if ($groupid) { // Try to change the current group to this groupid
if ($group = get_record('groups', 'id', $groupid, 'courseid', $course->id)) { // Exists
- if (isteacheredit($course->id)) { // Sets current default group
+ if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $course->id))) { // Sets current default group
$currentgroupid = set_current_group($course->id, $group->id);
} else if ($groupmode == VISIBLEGROUPS) {
}
} else { // When groupid = 0 it means show ALL groups
//this is changed, non editting teacher needs access to group 0 as well, for viewing work in visible groups (need to set current group for multiple pages)
- if (isteacheredit($course->id) OR (isteacher($course->id) AND ($groupmode == VISIBLEGROUPS))) { // Sets current default group
+ if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $course->id)) AND ($groupmode == VISIBLEGROUPS)) { // Sets current default group
$currentgroupid = set_current_group($course->id, 0);
} else if ($groupmode == VISIBLEGROUPS) { // All groups are visible
return false;
}
- if ($groupmode == SEPARATEGROUPS and !isteacheredit($course->id) and !$currentgroup) {
+ if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $course->id)) and !$currentgroup) {
//we are in separate groups and the current group is group 0, as last set.
//this can mean that either, this guy has no group
//or, this guy just came from a visible all forum, and he left when he set his current group to 0 (show all)
}
}
- if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
+ if ($groupmode == VISIBLEGROUPS or ($groupmode and has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $course->id)))) {
if ($groups = get_records_menu('groups', 'courseid', $course->id, 'name ASC', 'id,name')) {
echo '<div align="center">';
print_group_menu($groups, $groupmode, $currentgroup, $urlroot);
}
}//added code here to allow non-editting teacher to swap in-between his own groups
//added code for students in separategrous to swtich groups
- else if ($groupmode == SEPARATEGROUPS and (isteacher($course->id) or isstudent($course->id))) {
+ else if ($groupmode == SEPARATEGROUPS and has_capability('moodle/course:view', get_context_instance(CONTEXT_COURSE, $course->id))) {
$validgroups = array();
//get all the groups this guy is in in this course
if ($p = user_group($course->id,$USER->id)){
$user = get_record("user","id",$entry->uid);
print_user_picture($user->id, $course->id, $user->picture);
- $pivottoshow = fullname($user, isteacher($course->id));;
+ $pivottoshow = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
} else {
echo '<td align="center">';
}
$this->navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id={$this->course->id}\">$this->strresources</a> ->";
}
- if (!$this->cm->visible and !isteacher($this->course->id)) {
+ if (!$this->cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $this->cm->id))) {
$pagetitle = strip_tags($this->course->shortname.': '.$this->strresource);
print_header($pagetitle, $this->course->fullname, "$this->navigation $this->strresource", "", "", true, '', navmenu($this->course, $this->cm));
notice(get_string("activityiscurrentlyhidden"), "$CFG->wwwroot/course/view.php?id={$this->course->id}");
}
require_login($course->id, false);
-
- if (!isteacher($course->id)) {
- error( get_string('onlyteachersexport','quiz') );
- }
+
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ require_capability('moodle/question:export', $context);
// ensure the files area exists for this course
make_upload_directory( "$course->id" );
/// Header:
if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
- $strupdatemodule = isteacheredit($course->id)
+ $strupdatemodule = has_capability('moodle/course:manageactivities', $context)
? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
: "";
print_header_simple($strexportquestions, '',
require_login();
+ // this might break things in the future
if (!isteacherinanycourse()) {
error('This page is for teachers only');
}
error("This question doesn't belong to a valid category!");
}
- if (!isteacher($category->course) and !$category->publish) {
+ if (!has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $category->course)) and !$category->publish) {
error("You can't preview these questions!");
}
$quiz->course = $category->course;
rss_not_found();
}
- $isstudent = isstudent($courseid,$userid);
- $isteacher = isteacher($courseid,$userid);
-
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $isuser = has_capability('moodle/course:view', $context, $userid);
+
//Check for "security" if !course->guest or course->password
if ($course->id != SITEID) {
- if ((!$course->guest || $course->password) && (!($isstudent || $isteacher))) {
+ if ((!$course->guest || $course->password) && (!$isuser)) {
rss_not_found();
}
}
//Check for "security" if the course is hidden or the activity is hidden
- if (!$isblog and (!$course->visible || !$cm->visible) && (!$isteacher)) {
+ if (!$isblog and (!$course->visible || !$cm->visible) && (!has_capability('moodle/course:viewhiddenactivities', $context))) {
rss_not_found();
}
if ($newaccount) {
$userfullname = $strnewuser;
} else {
- $userfullname = fullname($user, isteacher($course->id));
+ $userfullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
}
if ($course->category) {
print_header("$course->shortname: $streditmyprofile", "$course->fullname: $streditmyprofile",
require_capability('moodle/course:viewparticipants', $context);
if (!$course->category) {
- if (!$CFG->showsiteparticipantslist and !isteacher(SITEID)) {
+ if (!$CFG->showsiteparticipantslist and !has_capability('moodle/course:viewparticipants', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
print_header("$course->shortname: ".get_string('participants'), $course->fullname,
get_string('participants'), "", "", true, " ", navmenu($course));
notice(get_string('sitepartlist0'));
}
$isseparategroups = ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce and
- !isteacheredit($course->id));
+ !has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $course->id)));
if ($isseparategroups and (!$currentgroup) ) { //XXX
print_heading(get_string("notingroup", "forum"));
popup_form($CFG->wwwroot.'/user/index.php?contextid='.$context->id.'&roleid='.$roleid.'&id=',$my_course,'courseform',$course->id);
echo '</td>';
- if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
+ if ($groupmode == VISIBLEGROUPS or ($groupmode and has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $course->id)))) {
if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
echo '<td class="left">';
print_group_menu($groups, $groupmode, $currentgroup, $baseurl);
echo popup_form($baseurl.'&mode=', $formatmenu, 'formatmenu', $fullmode, '', '', '', true);
echo '</td></tr></table>';
- if ($currentgroup and (!$isseparategroups or isteacheredit($course->id))) { /// Display info about the group
+ if ($currentgroup and (!$isseparategroups or has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $course->id)))) { /// Display info about the group
if ($group = get_record('groups', 'id', $currentgroup)) {
if (!empty($group->description) or (!empty($group->picture) and empty($group->hidepicture))) {
echo '<table class="groupinfobox"><tr><td class="left side picture">';
print_group_picture($group, $course->id, true, false, false);
echo '</td><td class="content">';
echo '<h3>'.$group->name;
- if (isteacheredit($course->id)) {
+ if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
echo ' <a title="'.get_string('editgroupprofile').'" href="../course/groups.php?id='.$course->id.'&group='.$group->id.'">';
echo '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="" border="0">';
echo '</a>';
$a->count = $totalcount;
$a->items = $currentrole->name;
echo '<h2>'.get_string('counteditems', '', $a);
- if (isteacheredit($course->id)) {
+ if (user_can_assign($context, $roleid)) {
echo ' <a href="'.$CFG->wwwroot.'/admin/roles/assign.php?roleid='.$roleid.'&contextid='.$context->id.'">';
echo '<img src="'.$CFG->pixpath.'/i/edit.gif" height="16" width="16" alt="" /></a>';
}
if (isset($userid)) {
$user = get_record('user','id', $userid);
}
- print_heading(fullname($user, isteacher($course->id)));
+ print_heading(fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))));
$toprow[] = new tabobject('profile', $CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$course->id, get_string('profile'));
}
}
- $fullname = fullname($user, isteacher($course->id));
+ $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
$personalprofile = get_string("personalprofile");
$participants = get_string("participants");
$currentuser = ($user->id == $USER->id);
}
- if (groupmode($course) == SEPARATEGROUPS and !isteacheredit($course->id)) { // Groups must be kept separate
+ if (groupmode($course) == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { // Groups must be kept separate
require_login();
///this is changed because of mygroupid
if ($course->category and ! isguest() ) { // Need to have access to a course to see that info
- if (!isstudent($course->id, $user->id) && !isteacher($course->id, $user->id)) {
+ if (!has_capability('moodle/course:view', get_context_instance(CONTEXT_COURSE, $course->id))) {
print_heading(get_string("notenrolled", "", $fullname));
print_footer($course);
die;
print_heading(get_string("userdeleted"));
}
-/// Get the hidden field list
- if (isteacher($course->id) || isadmin()) {
+/// Get the hidden field list (user must have update capability to see hidden files?)
+ if (has_capability('moodle/user:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
$hiddenfields = array(); // teachers and admins are allowed to see everything
} else {
$hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
print_row(get_string("location").":", $location);
}
- if (isteacher($course->id)) {
+ if (has_capability('moodle/user:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
if ($user->address) {
print_row(get_string("address").":", "$user->address");
}
/// Printing groups
$isseparategroups = ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce and
- !isteacheredit($course->id));
+ !has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $course->id)));
if (!$isseparategroups){
if ($usergroups = user_group($course->id, $user->id)){
$groupstr = '';