MDL-49650 Templates: Move templates out of invalid sub directory.
[moodle.git] / grade / report / index.php
CommitLineData
e060e33d 1<?php
e060e33d 2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
65dd61bd 16
a153c9f2
AD
17/**
18 * Redirects the user to the default grade report
19 *
20 * @package core_grades
21 * @copyright 2007 Petr Skoda
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
fdec3d4f 25require_once '../../config.php';
65dd61bd 26
27$courseid = required_param('id', PARAM_INT);
28
a6855934 29$PAGE->set_url('/grade/report/index.php', array('id'=>$courseid));
beebcf26 30
65dd61bd 31/// basic access checks
5c75a0a3 32if (!$course = $DB->get_record('course', array('id' => $courseid))) {
65dd61bd 33 print_error('nocourseid');
34}
35require_login($course);
d4060472 36$context = context_course::instance($course->id);
65dd61bd 37
38/// find all accessible reports
bd3b3bba 39$reports = core_component::get_plugin_list('gradereport'); // Get all installed reports
17da2e6f 40
41foreach ($reports as $plugin => $plugindir) { // Remove ones we can't see
42 if (!has_capability('gradereport/'.$plugin.':view', $context)) {
9c2d5353 43 unset($reports[$plugin]);
65dd61bd 44 }
45}
46
47if (empty($reports)) {
5cd78698 48 print_error('noreports', 'debug', $CFG->wwwroot.'/course/view.php?id='.$course->id);
65dd61bd 49}
50
51if (!isset($USER->grade_last_report)) {
52 $USER->grade_last_report = array();
53}
54
55if (!empty($USER->grade_last_report[$course->id])) {
56 $last = $USER->grade_last_report[$course->id];
57} else {
58 $last = null;
59}
60
8f2fab88 61if (!array_key_exists($last, $reports)) {
65dd61bd 62 $last = null;
63}
64
65if (empty($last)) {
8f2fab88 66 if (array_key_exists('grader', $reports)) {
65dd61bd 67 $last = 'grader';
68
5cd78698
K
69 } else if (array_key_exists($CFG->grade_profilereport, $reports)) {
70 $last = $CFG->grade_profilereport;
7a6b7acf 71
65dd61bd 72 } else {
5cd78698
K
73 reset($reports);
74 $last = key($reports);
65dd61bd 75 }
76}
77
78//redirect to last or guessed report
79redirect($CFG->wwwroot.'/grade/report/'.$last.'/index.php?id='.$course->id);
80