MDL-11515:
[moodle-linuxchix.git] / grade / report / grader / index.php
blob4576e518ea7cb6c79398117dbd67168534f11843
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);
124 /// processing posted grades & feedback here
125 if ($data = data_submitted() and confirm_sesskey()) {
126 $report->process_data($data);
129 // Override perpage if set in URL
130 if ($perpageurl) {
131 $report->user_prefs['studentsperpage'] = $perpageurl;
134 $report->load_users();
135 $numusers = $report->get_numusers();
136 $report->load_final_grades();
138 /// Print header
139 print_header_simple($strgrades.': '.$reportname, ': '.$strgrades, $navigation,
140 '', '', true, $buttons, navmenu($course));
142 /// Print the plugin selector at the top
143 print_grade_plugin_selector($courseid, 'report', 'grader');
145 // Add tabs
146 $currenttab = 'graderreport';
147 require('tabs.php');
149 echo $report->group_selector;
151 echo '<div class="clearer"></div>';
153 echo $report->get_toggles_html();
154 $studentsperpage = $report->get_pref('studentsperpage');
155 // Don't use paging if studentsperpage is empty or 0 at course AND site levels
156 if (!empty($studentsperpage)) {
157 print_paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
160 $reporthtml = '<table class="gradestable flexible boxaligncenter generaltable">';
161 $reporthtml .= $report->get_headerhtml();
162 $reporthtml .= $report->get_rangehtml();
163 $reporthtml .= $report->get_studentshtml();
164 $reporthtml .= $report->get_avghtml(true);
165 $reporthtml .= $report->get_avghtml();
166 $reporthtml .= "</table>";
168 // print submit button
169 if ($USER->gradeediting[$course->id]) {
170 echo '<form action="index.php" method="post">';
171 echo '<div>';
172 echo '<input type="hidden" value="'.$courseid.'" name="id" />';
173 echo '<input type="hidden" value="'.sesskey().'" name="sesskey" />';
174 echo '<input type="hidden" value="grader" name="report"/>';
177 echo $reporthtml;
179 // print submit button
180 if ($USER->gradeediting[$course->id] && ($report->get_pref('quickfeedback') || $report->get_pref('quickgrading'))) {
181 echo '<div class="submit"><input type="submit" value="'.get_string('update').'" /></div>';
182 echo '</div></form>';
185 // prints paging bar at bottom for large pages
186 if (!empty($studentsperpage) && $studentsperpage >= 20) {
187 print_paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
190 print_footer($course);