diff --git a/grade/lib.php b/grade/lib.php index c5c787dcc4d..2b131848109 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -266,10 +266,11 @@ class graded_users_iterator { * @param string $actionpage The page receiving the data from the popoup form * @param int $userid id of the currently selected user (or 'all' if they are all selected) * @param int $groupid id of requested group, 0 means all + * @param int $includeall bool include all option * @param bool $return If true, will return the HTML, otherwise, will print directly * @return null */ -function print_graded_users_selector($course, $actionpage, $userid=null, $groupid=0, $return=false) { +function print_graded_users_selector($course, $actionpage, $userid=0, $groupid=0, $includeall=true, $return=false) { global $CFG, $USER; if (is_null($userid)) { @@ -283,7 +284,7 @@ function print_graded_users_selector($course, $actionpage, $userid=null, $groupi $gui = new graded_users_iterator($course, null, $groupid); $gui->init(); - if ($userid !== 0) { + if ($includeall) { $menu[0] = get_string('allusers', 'grades'); } @@ -296,7 +297,7 @@ function print_graded_users_selector($course, $actionpage, $userid=null, $groupi $gui->close(); - if ($userid !== 0) { + if ($includeall) { $menu[0] .= " (" . (count($menu) - 1) . ")"; } diff --git a/grade/report/overview/index.php b/grade/report/overview/index.php index 7aa93baf028..708887c3d02 100644 --- a/grade/report/overview/index.php +++ b/grade/report/overview/index.php @@ -27,7 +27,7 @@ require_once $CFG->libdir.'/gradelib.php'; require_once $CFG->dirroot.'/grade/lib.php'; require_once $CFG->dirroot.'/grade/report/overview/lib.php'; -$courseid = optional_param('id', $COURSE->id, PARAM_INT); +$courseid = required_param('id', PARAM_INT); $userid = optional_param('userid', $USER->id, PARAM_INT); /// basic access checks @@ -36,26 +36,35 @@ if (!$course = $DB->get_record('course', array('id' => $courseid))) { } require_login($course); -if (!$user = get_complete_user_data('id', $userid)) { - print_error('invaliduser'); -} - -$context = get_context_instance(CONTEXT_COURSE, $course->id); -$usercontext = get_context_instance(CONTEXT_USER, $user->id); +$context = get_context_instance(CONTEXT_COURSE, $course->id); require_capability('gradereport/overview:view', $context); -$access = true; -if (has_capability('moodle/grade:viewall', $context)) { - //ok - can view all course grades - -} else if ($user->id == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) { - //ok - can view own grades - -} else if (has_capability('moodle/grade:viewall', $usercontext) and $course->showgrades) { - // ok - can view grades of this user- parent most probably +if (empty($userid)) { + require_capability('moodle/grade:viewall', $context); } else { - $access = false; + if (!get_complete_user_data('id', $userid) or isguestuser($userid)) { + error("Incorrect userid"); + } +} + +$access = false; +if (has_capability('moodle/grade:viewall', $context)) { + //ok - can view all course grades + $access = true; + +} else if ($userid == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) { + //ok - can view own grades + $access = true; + +} else if (has_capability('moodle/grade:viewall', get_context_instance(CONTEXT_USER, $userid)) and $course->showgrades) { + // ok - can view grades of this user- parent most probably + $access = true; +} + +if (!$access) { + // no access to grades! + error("Can not view grades.", $CFG->wwwroot.'/course/view.php?id='.$courseid); //TODO: localize } /// return tracking object @@ -67,33 +76,67 @@ if (!isset($USER->grade_last_report)) { } $USER->grade_last_report[$course->id] = 'overview'; +//first make sure we have proper final grades - this must be done before constructing of the grade tree +grade_regrade_final_grades($courseid); -if ($access) { +if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all student reports + $groupmode = groups_get_course_groupmode($course); // Groups are being used + $currentgroup = groups_get_course_group($course, true); - //first make sure we have proper final grades - this must be done before constructing of the grade tree - grade_regrade_final_grades($course->id); + if (!$currentgroup) { // To make some other functions work better later + $currentgroup = NULL; + } + + $isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context)); + + if ($isseparategroups and (!$currentgroup)) { + print_grade_page_head($courseid, 'report', 'overview', get_string('modulename', 'gradereport_overview')); + print_heading(get_string("notingroup")); + print_footer($course); + exit; + } + + /// Print graded user selector at the top + $user_selector = '