65dd61bd |
1 | <?php //$Id$ |
2 | |
3 | /////////////////////////////////////////////////////////////////////////// |
4 | // NOTICE OF COPYRIGHT // |
5 | // // |
6 | // Moodle - Modular Object-Oriented Dynamic Learning Environment // |
7 | // http://moodle.org // |
8 | // // |
9 | // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com // |
10 | // // |
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. // |
15 | // // |
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: // |
20 | // // |
21 | // http://www.gnu.org/copyleft/gpl.html // |
22 | // // |
23 | /////////////////////////////////////////////////////////////////////////// |
24 | |
fdec3d4f |
25 | require_once '../../config.php'; |
65dd61bd |
26 | |
27 | $courseid = required_param('id', PARAM_INT); |
28 | |
29 | /// basic access checks |
5c75a0a3 |
30 | if (!$course = $DB->get_record('course', array('id' => $courseid))) { |
65dd61bd |
31 | print_error('nocourseid'); |
32 | } |
33 | require_login($course); |
34 | $context = get_context_instance(CONTEXT_COURSE, $course->id); |
35 | |
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]); |
41 | } |
42 | } |
43 | } |
44 | |
45 | if (empty($reports)) { |
14398fd6 |
46 | print_error('noreports', 'debug', $CFG->wwwroot.'/course/view.php?id='.$course->id); // TODO: localize |
65dd61bd |
47 | } |
48 | |
49 | if (!isset($USER->grade_last_report)) { |
50 | $USER->grade_last_report = array(); |
51 | } |
52 | |
53 | if (!empty($USER->grade_last_report[$course->id])) { |
54 | $last = $USER->grade_last_report[$course->id]; |
55 | } else { |
56 | $last = null; |
57 | } |
58 | |
59 | if (!in_array($last, $reports)) { |
60 | $last = null; |
61 | } |
62 | |
63 | if (empty($last)) { |
64 | if (in_array('grader', $reports)) { |
65 | $last = 'grader'; |
66 | |
67 | } else if (in_array('user', $reports)) { |
68 | $last = 'user'; |
7a6b7acf |
69 | |
65dd61bd |
70 | } else { |
71 | $last = reset($reports); |
72 | } |
73 | } |
74 | |
75 | //redirect to last or guessed report |
76 | redirect($CFG->wwwroot.'/grade/report/'.$last.'/index.php?id='.$course->id); |
77 | |
8ad36f4c |
78 | ?> |