MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / grade / report / user / index.php
blob68ef71a109f8f70e423627d8fe4f3ad326f2496c
1 <?php // $Id$
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 ///////////////////////////////////////////////////////////////////////////
25 require_once '../../../config.php';
26 require_once $CFG->libdir.'/gradelib.php';
27 require_once $CFG->dirroot.'/grade/lib.php';
28 require_once $CFG->dirroot.'/grade/report/user/lib.php';
30 $courseid = required_param('id');
31 $userid = optional_param('userid', $USER->id, PARAM_INT);
33 /// basic access checks
34 if (!$course = get_record('course', 'id', $courseid)) {
35 print_error('nocourseid');
37 require_login($course);
39 if (!$user = get_complete_user_data('id', $userid)) {
40 error("Incorrect userid");
43 $context = get_context_instance(CONTEXT_COURSE, $course->id);
44 $usercontext = get_context_instance(CONTEXT_PERSONAL, $user->id);
45 require_capability('gradereport/user:view', $context);
47 $access = true;
48 if (has_capability('moodle/grade:viewall', $context)) {
49 //ok - can view all course grades
51 } else if ($user->id == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) {
52 //ok - can view own grades
54 } else if (has_capability('moodle/grade:view', $usercontext) and $course->showgrades) {
55 // ok - can view grades of this user- parent most probably
57 } else {
58 $acces = false;
61 /// return tracking object
62 $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'user', 'courseid'=>$courseid, 'userid'=>$userid));
64 /// last selected report session tracking
65 if (!isset($USER->grade_last_report)) {
66 $USER->grade_last_report = array();
68 $USER->grade_last_report[$course->id] = 'user';
70 /// Build navigation
71 $strgrades = get_string('grades');
72 $reportname = get_string('modulename', 'gradereport_user');
74 $navigation = grade_build_nav(__FILE__, $reportname, $courseid);
76 /// Print header
77 print_header_simple($strgrades.': '.$reportname, ': '.$strgrades, $navigation,
78 '', '', true, '', navmenu($course));
80 /// Print the plugin selector at the top
81 print_grade_plugin_selector($courseid, 'report', 'user');
83 if ($access) {
85 //first make sure we have proper final grades - this must be done before constructing of the grade tree
86 grade_regrade_final_grades($courseid);
88 // Create a report instance
89 $report = new grade_report_user($courseid, $gpr, $context, $userid);
91 $gradetotal = 0;
92 $gradesum = 0;
94 // print the page
95 print_heading(get_string('modulename', 'gradereport_user'). ' - '.fullname($report->user));
97 if ($report->fill_table()) {
98 echo $report->print_table(true);
101 } else {
102 // no access to grades!
103 echo "Can not view grades."; //TODO: localize
105 print_footer($course);