3 ///////////////////////////////////////////////////////////////////////////
4 // NOTICE OF COPYRIGHT //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // http://moodle.org //
9 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
11 // This program is free software; you can redistribute it and/or modify //
12 // it under the terms of the GNU General Public License as published by //
13 // the Free Software Foundation; either version 2 of the License, or //
14 // (at your option) any later version. //
16 // This program is distributed in the hope that it will be useful, //
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
19 // GNU General Public License for more details: //
21 // http://www.gnu.org/copyleft/gpl.html //
23 ///////////////////////////////////////////////////////////////////////////
25 require '../../config.php';
27 $courseid = required_param('id', PARAM_INT
);
29 /// basic access checks
30 if (!$course = get_record('course', 'id', $courseid)) {
31 print_error('nocourseid');
33 require_login($course);
34 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
36 /// find all accessible reports
37 if ($reports = get_list_of_plugins('grade/report', 'CVS')) { // Get all installed reports
38 foreach ($reports as $key => $plugin) { // Remove ones we can't see
39 if (!has_capability('gradereport/'.$plugin.':view', $context)) {
40 unset($reports[$key]);
45 if (empty($reports)) {
46 error('No reports accessible', $CFG->wwwroot
.'/course/view.php:id='.$course->id
); // TODO: localize
49 if (!isset($USER->grade_last_report
)) {
50 $USER->grade_last_report
= array();
53 if (!empty($USER->grade_last_report
[$course->id
])) {
54 $last = $USER->grade_last_report
[$course->id
];
59 if (!in_array($last, $reports)) {
64 if (in_array('grader', $reports)) {
67 } else if (in_array('user', $reports)) {
71 $last = reset($reports);
75 //redirect to last or guessed report
76 redirect($CFG->wwwroot
.'/grade/report/'.$last.'/index.php?id='.$course->id
);