e060e33d |
1 | <?php |
65dd61bd |
2 | |
e060e33d |
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. |
14 | // |
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/>. |
65dd61bd |
17 | |
fdec3d4f |
18 | require_once '../../config.php'; |
65dd61bd |
19 | |
20 | $courseid = required_param('id', PARAM_INT); |
21 | |
a6855934 |
22 | $PAGE->set_url('/grade/report/index.php', array('id'=>$courseid)); |
beebcf26 |
23 | |
65dd61bd |
24 | /// basic access checks |
5c75a0a3 |
25 | if (!$course = $DB->get_record('course', array('id' => $courseid))) { |
65dd61bd |
26 | print_error('nocourseid'); |
27 | } |
28 | require_login($course); |
29 | $context = get_context_instance(CONTEXT_COURSE, $course->id); |
30 | |
31 | /// find all accessible reports |
17da2e6f |
32 | $reports = get_plugin_list('gradereport'); // Get all installed reports |
17da2e6f |
33 | |
34 | foreach ($reports as $plugin => $plugindir) { // Remove ones we can't see |
35 | if (!has_capability('gradereport/'.$plugin.':view', $context)) { |
9c2d5353 |
36 | unset($reports[$plugin]); |
65dd61bd |
37 | } |
38 | } |
39 | |
40 | if (empty($reports)) { |
14398fd6 |
41 | print_error('noreports', 'debug', $CFG->wwwroot.'/course/view.php?id='.$course->id); // TODO: localize |
65dd61bd |
42 | } |
43 | |
44 | if (!isset($USER->grade_last_report)) { |
45 | $USER->grade_last_report = array(); |
46 | } |
47 | |
48 | if (!empty($USER->grade_last_report[$course->id])) { |
49 | $last = $USER->grade_last_report[$course->id]; |
50 | } else { |
51 | $last = null; |
52 | } |
53 | |
8f2fab88 |
54 | if (!array_key_exists($last, $reports)) { |
65dd61bd |
55 | $last = null; |
56 | } |
57 | |
58 | if (empty($last)) { |
8f2fab88 |
59 | if (array_key_exists('grader', $reports)) { |
65dd61bd |
60 | $last = 'grader'; |
61 | |
8f2fab88 |
62 | } else if (array_key_exists('user', $reports)) { |
65dd61bd |
63 | $last = 'user'; |
7a6b7acf |
64 | |
65dd61bd |
65 | } else { |
8f2fab88 |
66 | $last = key(reset($reports)); |
65dd61bd |
67 | } |
68 | } |
69 | |
70 | //redirect to last or guessed report |
71 | redirect($CFG->wwwroot.'/grade/report/'.$last.'/index.php?id='.$course->id); |
72 | |