Merge branch 'wip-MDL-27145-master' of git://github.com/samhemelryk/moodle
[moodle.git] / grade / report / index.php
blob145343d9e59804409bbd429843dc09af7816cd35
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 require_once '../../config.php';
20 $courseid = required_param('id', PARAM_INT);
22 $PAGE->set_url('/grade/report/index.php', array('id'=>$courseid));
24 /// basic access checks
25 if (!$course = $DB->get_record('course', array('id' => $courseid))) {
26 print_error('nocourseid');
28 require_login($course);
29 $context = get_context_instance(CONTEXT_COURSE, $course->id);
31 /// find all accessible reports
32 $reports = get_plugin_list('gradereport'); // Get all installed reports
34 foreach ($reports as $plugin => $plugindir) { // Remove ones we can't see
35 if (!has_capability('gradereport/'.$plugin.':view', $context)) {
36 unset($reports[$plugin]);
40 if (empty($reports)) {
41 print_error('noreports', 'debug', $CFG->wwwroot.'/course/view.php?id='.$course->id); // TODO: localize
44 if (!isset($USER->grade_last_report)) {
45 $USER->grade_last_report = array();
48 if (!empty($USER->grade_last_report[$course->id])) {
49 $last = $USER->grade_last_report[$course->id];
50 } else {
51 $last = null;
54 if (!array_key_exists($last, $reports)) {
55 $last = null;
58 if (empty($last)) {
59 if (array_key_exists('grader', $reports)) {
60 $last = 'grader';
62 } else if (array_key_exists('user', $reports)) {
63 $last = 'user';
65 } else {
66 $last = key(reset($reports));
70 //redirect to last or guessed report
71 redirect($CFG->wwwroot.'/grade/report/'.$last.'/index.php?id='.$course->id);