MDL-18943 xhtml strict - using class instead of repeated id attribute; merged from...
[moodle.git] / grade / report / overview / index.php
CommitLineData
aa330ebb 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_once '../../../config.php';
26require_once $CFG->libdir.'/gradelib.php';
27require_once $CFG->dirroot.'/grade/lib.php';
28require_once $CFG->dirroot.'/grade/report/overview/lib.php';
29
bc430af2 30$courseid = optional_param('id', $COURSE->id, PARAM_INT);
aa330ebb 31$userid = optional_param('userid', $USER->id, PARAM_INT);
32
33/// basic access checks
5c75a0a3 34if (!$course = $DB->get_record('course', array('id' => $courseid))) {
aa330ebb 35 print_error('nocourseid');
36}
37require_login($course);
38
39if (!$user = get_complete_user_data('id', $userid)) {
14398fd6 40 print_error('invaliduser');
aa330ebb 41}
42
43$context = get_context_instance(CONTEXT_COURSE, $course->id);
eecf76df 44$usercontext = get_context_instance(CONTEXT_USER, $user->id);
aa330ebb 45require_capability('gradereport/overview:view', $context);
46
47$access = true;
48if (has_capability('moodle/grade:viewall', $context)) {
49 //ok - can view all course grades
50
51} else if ($user->id == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) {
52 //ok - can view own grades
53
eecf76df 54} else if (has_capability('moodle/grade:viewall', $usercontext) and $course->showgrades) {
aa330ebb 55 // ok - can view grades of this user- parent most probably
56
57} else {
6477f991 58 $access = false;
aa330ebb 59}
60
61/// return tracking object
bc430af2 62$gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'overview', 'courseid'=>$course->id, 'userid'=>$userid));
aa330ebb 63
64/// last selected report session tracking
65if (!isset($USER->grade_last_report)) {
66 $USER->grade_last_report = array();
67}
bc430af2 68$USER->grade_last_report[$course->id] = 'overview';
aa330ebb 69
aa330ebb 70
71if ($access) {
72
73 //first make sure we have proper final grades - this must be done before constructing of the grade tree
74 grade_regrade_final_grades($course->id);
75
76 // Create a report instance
77 $report = new grade_report_overview($userid, $gpr, $context);
dc482cfa 78 print_grade_page_head($courseid, 'report', 'overview', get_string('modulename', 'gradereport_overview'). ' - '.fullname($report->user));
aa330ebb 79
80 if ($report->fill_table()) {
81 echo $report->print_table(true);
82 }
83
84} else {
85 // no access to grades!
dc482cfa 86 /// Print header
87 /// Build navigation
88 $strgrades = get_string('grades');
89 $reportname = get_string('modulename', 'gradereport_overview');
90
91 $navigation = grade_build_nav(__FILE__, $reportname, $course->id);
92 print_header_simple($strgrades.': '.$reportname, ': '.$strgrades, $navigation,
93 '', '', true, '', navmenu($course));
94
aa330ebb 95 echo "Can not view grades."; //TODO: localize
96}
97print_footer($course);
98
99?>