MDL-10579 Implement capability checks in grade import/export/report/edit pages -...
[moodle.git] / grade / report / index.php
CommitLineData
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
25require '../../config.php';
26
27$courseid = required_param('id', PARAM_INT);
28
29/// basic access checks
30if (!$course = get_record('course', 'id', $courseid)) {
31 print_error('nocourseid');
32}
33require_login($course);
34$context = get_context_instance(CONTEXT_COURSE, $course->id);
35
36/// find all accessible reports
37if ($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
45if (empty($reports)) {
46 error('No reports accessible', $CFG->wwwroot.'/course/view.php:id='.$course->id); // TODO: localize
47}
48
49if (!isset($USER->grade_last_report)) {
50 $USER->grade_last_report = array();
51}
52
53if (!empty($USER->grade_last_report[$course->id])) {
54 $last = $USER->grade_last_report[$course->id];
55} else {
56 $last = null;
57}
58
59if (!in_array($last, $reports)) {
60 $last = null;
61}
62
63if (empty($last)) {
64 if (in_array('grader', $reports)) {
65 $last = 'grader';
66
67 } else if (in_array('user', $reports)) {
68 $last = 'user';
69
70 } else {
71 $last = reset($reports);
72 }
73}
74
75//redirect to last or guessed report
76redirect($CFG->wwwroot.'/grade/report/'.$last.'/index.php?id='.$course->id);
77
78?>