-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
233 lines (194 loc) · 8.6 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The gradebook grader report
*
* @package gradereport_gradest
* @copyright 2007 Moodle Pty Ltd (http://moodle.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../../../config.php');
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->dirroot.'/user/renderer.php');
require_once($CFG->dirroot.'/grade/lib.php');
require_once($CFG->dirroot.'/grade/report/gradest/lib.php');
$courseid = required_param('id', PARAM_INT); // course id
$page = optional_param('page', 0, PARAM_INT); // active page
$edit = optional_param('edit', -1, PARAM_BOOL); // sticky editting mode
$sortitemid = optional_param('sortitemid', 0, PARAM_ALPHANUM); // sort by which grade item
$action = optional_param('action', 0, PARAM_ALPHAEXT);
$move = optional_param('move', 0, PARAM_INT);
$type = optional_param('type', 0, PARAM_ALPHA);
$target = optional_param('target', 0, PARAM_ALPHANUM);
$toggle = optional_param('toggle', null, PARAM_INT);
$toggle_type = optional_param('toggle_type', 0, PARAM_ALPHANUM);
$graderreportsifirst = optional_param('sifirst', null, PARAM_NOTAGS);
$graderreportsilast = optional_param('silast', null, PARAM_NOTAGS);
$PAGE->requires->js_call_amd('gradereport_gradest/gradest','init');
// The report object is recreated each time, save search information to SESSION object for future use.
if (isset($graderreportsifirst)) {
$SESSION->gradereport['filterfirstname'] = $graderreportsifirst;
}
if (isset($graderreportsilast)) {
$SESSION->gradereport['filtersurname'] = $graderreportsilast;
}
$PAGE->set_url(new moodle_url('/grade/report/gradest/index.php', array('id'=>$courseid)));
$PAGE->requires->yui_module('moodle-gradereport_gradest-gradereporttable', 'Y.M.gradereport_gradest.init', null, null, true);
$PAGE->requires->js_call_amd('gradereport_gradest/dach19','init');
// basic access checks
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('invalidcourseid');
}
require_login($course);
$context = context_course::instance($course->id);
require_capability('gradereport/gradest:view', $context);
require_capability('moodle/grade:viewall', $context);
// return tracking object
$gpr = new grade_plugin_return(
array(
'type' => 'report',
'plugin' => 'grader',
'course' => $course,
'page' => $page
)
);
// last selected report session tracking
if (!isset($USER->grade_last_report)) {
$USER->grade_last_report = array();
}
$USER->grade_last_report[$course->id] = 'gradest';
// Build editing on/off buttons
if (!isset($USER->gradeediting)) {
$USER->gradeediting = array();
}
if (has_capability('moodle/grade:edit', $context)) {
if (!isset($USER->gradeediting[$course->id])) {
$USER->gradeediting[$course->id] = 0;
}
if (($edit == 1) and confirm_sesskey()) {
$USER->gradeediting[$course->id] = 1;
} else if (($edit == 0) and confirm_sesskey()) {
$USER->gradeediting[$course->id] = 0;
}
// page params for the turn editting on
$options = $gpr->get_options();
$options['sesskey'] = sesskey();
if ($USER->gradeediting[$course->id]) {
$options['edit'] = 0;
$string = get_string('turneditingoff');
} else {
$options['edit'] = 1;
$string = get_string('turneditingon');
}
$buttons = new single_button(new moodle_url('index.php', $options), $string, 'get');
} else {
$USER->gradeediting[$course->id] = 0;
$buttons = '';
}
$gradeserror = array();
// Handle toggle change request
if (!is_null($toggle) && !empty($toggle_type)) {
set_user_preferences(array('grade_report_show'.$toggle_type => $toggle));
}
// Perform actions
if (!empty($target) && !empty($action) && confirm_sesskey()) {
grade_report_gradest::do_process_action($target, $action, $courseid);
}
$reportname = get_string('pluginname', 'gradereport_gradest');
// Do this check just before printing the grade header (and only do it once).
grade_regrade_final_grades_if_required($course);
// Print header
print_grade_page_head($COURSE->id, 'report', 'grader', $reportname, false, $buttons);
//Initialise the grader report object that produces the table
//the class grade_report_gradest_ajax was removed as part of MDL-21562
$report = new grade_report_gradest($courseid, $gpr, $context, $page, $sortitemid);
$numusers = $report->get_numusers(true, true);
// make sure separate group does not prevent view
if ($report->currentgroup == -2) {
echo $OUTPUT->heading(get_string("notingroup"));
echo $OUTPUT->footer();
exit;
}
// processing posted grades & feedback here
if ($data = data_submitted() and confirm_sesskey() and has_capability('moodle/grade:edit', $context)) {
$warnings = $report->process_data($data);
} else {
$warnings = array();
}
// final grades MUST be loaded after the processing
$report->load_users();
$report->load_final_grades();
echo $report->group_selector;
// User search
$url = new moodle_url('/grade/report/gradest/index.php', array('id' => $course->id));
$firstinitial = isset($SESSION->gradereport['filterfirstname']) ? $SESSION->gradereport['filterfirstname'] : '';
$lastinitial = isset($SESSION->gradereport['filtersurname']) ? $SESSION->gradereport['filtersurname'] : '';
$totalusers = $report->get_numusers(true, false);
$renderer = $PAGE->get_renderer('core_user');
echo $renderer->user_search($url, $firstinitial, $lastinitial, $numusers, $totalusers, $report->currentgroupname);
//show warnings if any
foreach ($warnings as $warning) {
echo $OUTPUT->notification($warning);
}
$studentsperpage = $report->get_students_per_page();
// Don't use paging if studentsperpage is empty or 0 at course AND site levels
echo '<div class="d-flex"><div class="p-1" style="margin-right: 10px;">' . get_string('studentsperpage', 'grades') . ': '.
'<input class="studentsperpage" style="width: 40px; text-align: center;" type="text" value="' .
$report->get_numusers(true, true) . '"></input></div>';
echo $OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
echo '</div>';
$displayaverages = true;
if ($numusers == 0) {
$displayaverages = false;
}
$reporthtml = $report->get_grade_table($displayaverages);
// print submit button
if ($USER->gradeediting[$course->id] && ($report->get_pref('showquickfeedback') || $report->get_pref('quickgrading'))) {
echo '<form action="index.php" enctype="application/x-www-form-urlencoded" method="post" id="gradereport_gradest">'; // Enforce compatibility with our max_input_vars hack.
echo '<div>';
echo '<input type="hidden" value="'.s($courseid).'" name="id" />';
echo '<input type="hidden" value="'.sesskey().'" name="sesskey" />';
echo '<input type="hidden" value="'.time().'" name="timepageload" />';
echo '<input type="hidden" value="grader" name="report"/>';
echo '<input type="hidden" value="'.$page.'" name="page"/>';
echo $gpr->get_form_fields();
echo $reporthtml;
echo '<div class="submit"><input type="submit" id="gradersubmit" class="btn btn-primary"
value="'.s(get_string('savechanges')).'" /></div>';
echo '</div></form>';
} else {
echo $reporthtml;
}
// prints paging bar at bottom for large pages
if (!empty($studentsperpage)) {
echo '<div class="d-flex"><form><div class="p-1">' . get_string('studentsperpage', 'grades') . ': '.
'<input class="studentsperpage" style="width: 40px; text-align: center;" type="text" value="' .
$report->get_numusers(true, true) . '"></input>
<input style="margin-right: 10px; margin-left: 10px;" class="btn btn-secondary" type="submit" value="Submit"></form></div>';
echo $OUTPUT->paging_bar($numusers, $report->page, $studentsperpage, $report->pbarurl);
echo '</div>';
}
$event = \gradereport_gradest\event\grade_report_viewed::create(
array(
'context' => $context,
'courseid' => $courseid,
)
);
$event->trigger();
//stefan JS HACK for mockup
echo '<script src="stefan.js">
</script>';
echo $OUTPUT->footer();