2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Redirects the user to the default grade report
20 * @package core_grades
21 * @copyright 2007 Petr Skoda
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once '../../config.php';
27 $courseid = required_param('id', PARAM_INT
);
29 $PAGE->set_url('/grade/report/index.php', array('id'=>$courseid));
31 /// basic access checks
32 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
33 print_error('invalidcourseid');
35 require_login($course);
36 $context = context_course
::instance($course->id
);
38 /// find all accessible reports
39 $reports = core_component
::get_plugin_list('gradereport'); // Get all installed reports
41 foreach ($reports as $plugin => $plugindir) { // Remove ones we can't see
42 if (!has_capability('gradereport/'.$plugin.':view', $context)) {
43 unset($reports[$plugin]);
47 if (empty($reports)) {
48 print_error('noreports', 'debug', $CFG->wwwroot
.'/course/view.php?id='.$course->id
);
51 if (!isset($USER->grade_last_report
)) {
52 $USER->grade_last_report
= array();
55 if (!empty($USER->grade_last_report
[$course->id
])) {
56 $last = $USER->grade_last_report
[$course->id
];
61 if (!array_key_exists($last, $reports)) {
66 if (array_key_exists('grader', $reports)) {
69 } else if (array_key_exists($CFG->grade_profilereport
, $reports)) {
70 $last = $CFG->grade_profilereport
;
74 $last = key($reports);
78 //redirect to last or guessed report
79 redirect($CFG->wwwroot
.'/grade/report/'.$last.'/index.php?id='.$course->id
);