Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / grade / report / grader / index.php
blob5fe42bf527194f66a6e1a95006e8538c3600545b
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 ///////////////////////////////////////////////////////////////////////////
26 require_once '../../../config.php';
27 require_once $CFG->libdir.'/gradelib.php';
28 require_once $CFG->dirroot.'/grade/lib.php';
29 require_once $CFG->dirroot.'/grade/report/grader/lib.php';
31 $courseid = required_param('id'); // course id
32 $page = optional_param('page', 0, PARAM_INT); // active page
33 $perpageurl = optional_param('perpage', 0, PARAM_INT);
34 $edit = optional_param('edit', -1, PARAM_BOOL); // sticky editting mode
36 $sortitemid = optional_param('sortitemid', 0, PARAM_ALPHANUM); // sort by which grade item
37 $action = optional_param('action', 0, PARAM_ALPHAEXT);
38 $move = optional_param('move', 0, PARAM_INT);
39 $type = optional_param('type', 0, PARAM_ALPHA);
40 $target = optional_param('target', 0, PARAM_ALPHANUM);
41 $toggle = optional_param('toggle', NULL, PARAM_INT);
42 $toggle_type = optional_param('toggle_type', 0, PARAM_ALPHANUM);
44 /// basic access checks
45 if (!$course = get_record('course', 'id', $courseid)) {
46 print_error('nocourseid');
48 require_login($course);
49 $context = get_context_instance(CONTEXT_COURSE, $course->id);
51 require_capability('gradereport/grader:view', $context);
52 require_capability('moodle/grade:viewall', $context);
54 /// return tracking object
55 $gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'grader', 'courseid'=>$courseid, 'page'=>$page));
57 /// last selected report session tracking
58 if (!isset($USER->grade_last_report)) {
59 $USER->grade_last_report = array();
61 $USER->grade_last_report[$course->id] = 'grader';
63 /// Build navigation
65 $strgrades = get_string('grades');
66 $reportname = get_string('modulename', 'gradereport_grader');
68 $navigation = grade_build_nav(__FILE__, $reportname, $courseid);
70 /// Build editing on/off buttons
72 if (!isset($USER->gradeediting)) {
73 $USER->gradeediting = array();
76 if (has_capability('moodle/grade:edit', $context)) {
77 if (!isset($USER->gradeediting[$course->id])) {
78 $USER->gradeediting[$course->id] = 0;
81 if (($edit == 1) and confirm_sesskey()) {
82 $USER->gradeediting[$course->id] = 1;
83 } else if (($edit == 0) and confirm_sesskey()) {
84 $USER->gradeediting[$course->id] = 0;
87 // page params for the turn editting on
88 $options = $gpr->get_options();
89 $options['sesskey'] = sesskey();
91 if ($USER->gradeediting[$course->id]) {
92 $options['edit'] = 0;
93 $string = get_string('turneditingoff');
94 } else {
95 $options['edit'] = 1;
96 $string = get_string('turneditingon');
99 $buttons = print_single_button('index.php', $options, $string, 'get', '_self', true);
101 } else {
102 $USER->gradeediting[$course->id] = 0;
103 $buttons = '';
106 $gradeserror = array();
108 // Handle toggle change request
109 if (!is_null($toggle) && !empty($toggle_type)) {
110 set_user_preferences(array('grade_report_show'.$toggle_type => $toggle));
113 //first make sure we have proper final grades - this must be done before constructing of the grade tree
114 grade_regrade_final_grades($courseid);
116 // Perform actions
117 if (!empty($target) && !empty($action) && confirm_sesskey()) {
118 grade_report_grader::process_action($target, $action);
121 // Initialise the grader report object
122 $report = new grade_report_grader($courseid, $gpr, $context, $page, $sortitemid);
125 /// processing posted grades & feedback here
126 if ($data = data_submitted() and confirm_sesskey() and has_capability('moodle/grade:edit', $context)) {
127 $warnings = $report->process_data($data);
128 } else {
129 $warnings = array();
133 // Override perpage if set in URL
134 if ($perpageurl) {
135 $report->user_prefs['studentsperpage'] = $perpageurl;
138 // final grades MUST be loaded after the processing
139 $report->load_users();
140 $numusers = $report->get_numusers();
141 $report->load_final_grades();
143 /// Print header
144 print_header_simple($strgrades.': '.$reportname, ': '.$strgrades, $navigation,
145 '', '', true, $buttons, navmenu($course));
147 /// Print the plugin selector at the top
148 print_grade_plugin_selector($courseid, 'report', 'grader');
150 // Add tabs
151 $currenttab = 'graderreport';
152 require('tabs.php');
154 echo $report->group_selector;
155 echo '<div class="clearer"></div>';
156 echo $report->get_toggles_html();
158 //show warnings if any
159 foreach($warnings as $warning) {
160 notify($warning);
163 $studentsperpage = $report->get_pref('studentsperpage');
164 // Don't use paging if studentsperpage is empty or 0 at course AND site levels
165 if (!empty($studentsperpage)) {
166 print_paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
169 $reporthtml = '<script src="functions.js" type="text/javascript"></script>';
171 $reporthtml .= '<table id="user-grades" class="gradestable flexible boxaligncenter generaltable">';
172 $reporthtml .= $report->get_headerhtml();
173 $reporthtml .= $report->get_iconshtml();
174 $reporthtml .= $report->get_rangehtml();
175 $reporthtml .= $report->get_studentshtml();
176 $reporthtml .= $report->get_avghtml(true);
177 $reporthtml .= $report->get_avghtml();
178 $reporthtml .= "</table>";
180 // print submit button
181 if ($USER->gradeediting[$course->id]) {
182 echo '<form action="index.php" method="post">';
183 echo '<div>';
184 echo '<input type="hidden" value="'.$courseid.'" name="id" />';
185 echo '<input type="hidden" value="'.sesskey().'" name="sesskey" />';
186 echo '<input type="hidden" value="grader" name="report"/>';
189 echo $reporthtml;
191 // print submit button
192 if ($USER->gradeediting[$course->id] && ($report->get_pref('showquickfeedback') || $report->get_pref('quickgrading'))) {
193 echo '<div class="submit"><input type="submit" value="'.get_string('update').'" /></div>';
194 echo '</div></form>';
197 // prints paging bar at bottom for large pages
198 if (!empty($studentsperpage) && $studentsperpage >= 20) {
199 print_paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
202 print_footer($course);