MDL-19404 Getting default values for grade_item object when creating a new grade_cate...
[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
7ac88172 30$courseid = required_param('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
7ac88172 39$context = get_context_instance(CONTEXT_COURSE, $course->id);
aa330ebb 40require_capability('gradereport/overview:view', $context);
41
7ac88172 42if (empty($userid)) {
43 require_capability('moodle/grade:viewall', $context);
44
45} else {
b0639b78 46 if (!$DB->get_record('user', array('id'=>$userid, 'deleted'=>0)) or isguestuser($userid)) {
7ac88172 47 error("Incorrect userid");
48 }
49}
50
51$access = false;
aa330ebb 52if (has_capability('moodle/grade:viewall', $context)) {
53 //ok - can view all course grades
7ac88172 54 $access = true;
aa330ebb 55
7ac88172 56} else if ($userid == $USER->id and has_capability('moodle/grade:view', $context) and $course->showgrades) {
aa330ebb 57 //ok - can view own grades
7ac88172 58 $access = true;
aa330ebb 59
7ac88172 60} else if (has_capability('moodle/grade:viewall', get_context_instance(CONTEXT_USER, $userid)) and $course->showgrades) {
aa330ebb 61 // ok - can view grades of this user- parent most probably
7ac88172 62 $access = true;
63}
aa330ebb 64
7ac88172 65if (!$access) {
66 // no access to grades!
67 error("Can not view grades.", $CFG->wwwroot.'/course/view.php?id='.$courseid); //TODO: localize
aa330ebb 68}
69
70/// return tracking object
bc430af2 71$gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'overview', 'courseid'=>$course->id, 'userid'=>$userid));
aa330ebb 72
73/// last selected report session tracking
74if (!isset($USER->grade_last_report)) {
75 $USER->grade_last_report = array();
76}
bc430af2 77$USER->grade_last_report[$course->id] = 'overview';
aa330ebb 78
7ac88172 79//first make sure we have proper final grades - this must be done before constructing of the grade tree
80grade_regrade_final_grades($courseid);
81
82if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all student reports
83 $groupmode = groups_get_course_groupmode($course); // Groups are being used
84 $currentgroup = groups_get_course_group($course, true);
aa330ebb 85
7ac88172 86 if (!$currentgroup) { // To make some other functions work better later
87 $currentgroup = NULL;
88 }
aa330ebb 89
7ac88172 90 $isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context));
91
92 if ($isseparategroups and (!$currentgroup)) {
48a4c849 93 // no separate group access, can view only self
94 $userid = $USER->id;
95 $user_selector = '';
96 } else {
97 /// Print graded user selector at the top
98 $user_selector = '<div id="graded_users_selector">';
99 $user_selector .= print_graded_users_selector($course, 'report/overview/index.php?id=' . $course->id, $userid, $currentgroup, true, true);
100 $user_selector .= '</div>';
101 $user_selector .= "<p style = 'page-break-after: always;'></p>";
7ac88172 102 }
103
104 /// Print graded user selector at the top
105 $user_selector = '<div id="graded_users_selector">';
106 $user_selector .= print_graded_users_selector($course, 'report/overview/index.php?id=' . $course->id, $userid, $currentgroup, false, true);
107 $user_selector .= '</div>';
108 $user_selector .= "<p style = 'page-break-after: always;'></p>";
109
110 if (empty($userid)) {
111 // Add tabs
112 print_grade_page_head($courseid, 'report', 'overview');
113 groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
114 echo $user_selector.'<br />';
115 // do not list all users
116
117 } else { // Only show one user's report
118 $report = new grade_report_overview($userid, $gpr, $context);
119 print_grade_page_head($courseid, 'report', 'overview', get_string('modulename', 'gradereport_overview'). ' - '.fullname($report->user));
120 groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
121
122 echo $user_selector;
123
124 if ($currentgroup and !groups_is_member($currentgroup, $userid)) {
125 notify(get_string('groupusernotmember', 'error'));
126 } else {
127 if ($report->fill_table()) {
128 echo '<br />'.$report->print_table(true);
129 }
130 }
131 }
132} else { //Students will see just their own report
aa330ebb 133
134 // Create a report instance
135 $report = new grade_report_overview($userid, $gpr, $context);
7ac88172 136
137 // print the page
dc482cfa 138 print_grade_page_head($courseid, 'report', 'overview', get_string('modulename', 'gradereport_overview'). ' - '.fullname($report->user));
aa330ebb 139
140 if ($report->fill_table()) {
7ac88172 141 echo '<br />'.$report->print_table(true);
aa330ebb 142 }
aa330ebb 143}
7ac88172 144
aa330ebb 145print_footer($course);
146
147?>