-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathedit.php
More file actions
470 lines (400 loc) · 20 KB
/
edit.php
File metadata and controls
470 lines (400 loc) · 20 KB
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
<?php // $Id: edit.php,v 1.16 2008/11/12 08:23:00 jamiesensei Exp $
/**
* Page to grade questions
*
*
* @version $Id: edit.php,v 1.16 2008/11/12 08:23:00 jamiesensei Exp $
* @author Martin Dougiamas and many others.
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
*/
require_once("../../config.php");
require_once($CFG->libdir.'/gradelib.php');
require_once($CFG->libdir.'/tablelib.php');
require_once($CFG->dirroot.'/mod/qcreate/lib.php');
require_once($CFG->dirroot . '/question/editlib.php');
list($thispageurl, $contexts, $cmid, $cm, $qcreate, $pagevars) = question_edit_setup('questions', '/mod/qcreate/edit.php');
$qcreate->cmidnumber = $cm->id;
require_capability('mod/qcreate:grade', get_context_instance(CONTEXT_MODULE, $cm->id));
if ($qcreate->graderatio == 100){
$grading_interface = false;
} else {
$grading_interface = true;
}
$page = optional_param('page', 0, PARAM_INT);
$gradessubmitted = optional_param('gradessubmitted', 0, PARAM_BOOL); // grades submitted?
if ($grading_interface){
$showungraded = optional_param('showungraded', 1, PARAM_BOOL);
$showgraded = optional_param('showgraded', 1, PARAM_BOOL);
$showneedsregrade = optional_param('showneedsregrade', 1, PARAM_BOOL);
} else {
$showungraded = true;
$showgraded = true;
$showneedsregrade = true;
}
/* first we check to see if the form has just been submitted
* to request user_preference updates
*/
if (isset($_POST['updatepref'])){
$perpage = optional_param('perpage', 10, PARAM_INT);
$perpage = ($perpage <= 0) ? 10 : $perpage ;
set_user_preference('qcreate_perpage', $perpage);
}
/// find out current groups mode
$groupmode = groups_get_activity_groupmode($cm);
$currentgroup = groups_get_activity_group($cm, true);
/// Get all ppl that are allowed to submit assignments
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (!$users = get_users_by_capability($context, 'mod/qcreate:submit', '', '', '', '', $currentgroup, '', false)){
$users = array();
}
$users = array_keys($users);
if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) {
$groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id');
$users = array_intersect($users, array_keys($groupingusers));
}
// grades submitted?
if ($gradessubmitted){
qcreate_process_grades($qcreate, $cm, $users);
}
/* next we get perpage params
* from database
*/
$perpage = get_user_preferences('qcreate_perpage', 10);
$grading_info = grade_get_grades($COURSE->id, 'mod', 'qcreate', $qcreate->id);
if (!empty($CFG->enableoutcomes) and !empty($grading_info->outcomes)) {
$uses_outcomes = true;
} else {
$uses_outcomes = false;
}
$teacherattempts = true; /// Temporary measure
$strsaveallfeedback = get_string('saveallfeedback', 'assignment');
$tabindex = 1; //tabindex for quick grading tabbing; Not working for dropdowns yet
add_to_log($COURSE->id, 'qcreate', 'grade', 'grades.php?id='.$qcreate->id, $qcreate->id, $cm->id);
$strqcreate = get_string('modulename', 'qcreate');
$strqcreates = get_string('modulenameplural', 'qcreate');
$navlinks = array();
$navlinks[] = array('name' => $strqcreates, 'link' => "index.php?id=$COURSE->id", 'type' => 'activity');
$navlinks[] = array('name' => format_string($qcreate->name,true),
'link' => "view.php?id={$cm->id}",
'type' => 'activityinstance');
$navlinks[] = array('name' => get_string('grading', 'qcreate'), 'link' => '', 'type' => 'title');
$navigation = build_navigation($navlinks);
$PAGE->set_url($thispageurl);
print_header_simple(format_string($qcreate->name,true), "", $navigation,
'', '', true, update_module_button($cm->id, $COURSE->id, $strqcreate), navmenu($COURSE, $cm));
$mode = 'editq';
include('tabs.php');
//setting this after tabs.php as these params are just for this page and should not be included in urls for tabs.
$thispageurl->params(compact('showgraded', 'showneedsregrade', 'showungraded', 'page'));
groups_print_activity_menu($cm, $thispageurl->out());
if ($grading_interface){
$tablecolumns = array('picture', 'fullname', 'qname', 'grade', 'status', 'gradecomment', 'timemodified', 'timemarked', 'finalgrade');
$tableheaders = array('',
get_string('fullname'),
get_string('question'),
get_string('grade'),
get_string('status'),
get_string('comment', 'qcreate'),
get_string('lastmodified'),
get_string('marked', 'qcreate'),
get_string('finalgrade', 'grades'));
if ($uses_outcomes) {
$tablecolumns[] = 'outcome'; // no sorting based on outcomes column
$tableheaders[] = get_string('outcome', 'grades');
}
} else {
$tablecolumns = array('picture', 'fullname', 'qname', 'gradecomment', 'timemodified', 'finalgrade');
$tableheaders = array('',
get_string('fullname'),
get_string('question'),
get_string('comment', 'qcreate'),
get_string('lastmodified'),
get_string('finalgrade', 'grades'));
}
$table = new flexible_table('mod-qcreate-grades');
$table->define_columns($tablecolumns);
$table->define_headers($tableheaders);
$table->define_baseurl($thispageurl->out());
$table->sortable(true, 'lastname');//sorted by lastname by default
$table->collapsible(true);
$table->initialbars(true);
$table->column_suppress('picture');
$table->column_suppress('fullname');
$table->column_class('picture', 'picture');
$table->column_class('fullname', 'fullname');
$table->column_class('question', 'question');
$table->column_class('gradecomment', 'comment');
$table->column_class('timemodified', 'timemodified');
$table->column_class('finalgrade', 'finalgrade');
if ($grading_interface){
$table->column_class('grade', 'grade');
$table->column_class('timemarked', 'timemarked');
$table->column_class('status', 'status');
if ($uses_outcomes) {
$table->column_class('outcome', 'outcome');
}
}
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'grades');
$table->set_attribute('width', '90%');
//$table->set_attribute('align', 'center');
if ($grading_interface){
$table->no_sorting('finalgrade');
$table->no_sorting('outcome');
}
// Start working -- this is necessary as soon as the niceties are over
$table->setup();
/// Construct the SQL
if (!empty($users) && ($showungraded || $showgraded || $showneedsregrade)){
if ($sort = $table->get_sql_sort()) {
$sort = ' ORDER BY '.$sort;
}
$where = $table->get_sql_where();
if ($where[0]) {
$where[0] .= ' AND ';
}
//unfortunately we cannot use status in WHERE clause
switch ($showungraded . $showneedsregrade . $showgraded){
case '001':
$where[0] .= '(g.timemarked IS NOT NULL) AND (g.timemarked >= q.timemodified ) AND ';
break;
case '010':
$where[0] .= '(g.timemarked IS NOT NULL) AND (g.timemarked < q.timemodified ) AND ';
break;
case '011':
$where[0] .= '(g.timemarked IS NOT NULL) AND ';
break;
case '100':
$where[0] .= '(g.timemarked IS NULL) AND ';
break;
case '101':
$where[0] .= '((g.timemarked IS NULL) OR g.timemarked >= q.timemodified) AND ';
break;
case '110':
$where[0] .= '((g.timemarked IS NULL) OR g.timemarked < q.timemodified) AND ';
break;
case '111': //show everything
break;
}
if ($qcreate->allowed != 'ALL') {
$allowedparts = explode(',', $qcreate->allowed);
$allowedlist = "'".join("','", $allowedparts)."'";
$where[0] .= 'q.qtype IN ('.$allowedlist.') AND ';
}
$countsql = 'SELECT COUNT(*) FROM '.$CFG->prefix.'user u, '.$CFG->prefix.'question_categories c, '.$CFG->prefix.'question q '.
'LEFT JOIN '.$CFG->prefix.'qcreate_grades g ON q.id = g.questionid '.
'WHERE '.$where[0].'q.createdby = u.id AND u.id IN ('.implode(',',$users).
') AND q.hidden=\'0\' AND q.parent=\'0\' AND q.category = c.id and c.contextid='.$context->id;
$answercount = $DB->count_records_sql($countsql, $where[1]);
//complicated status calculation is needed for sorting on status column
$select = 'SELECT q.id AS qid, u.id, u.firstname, u.lastname, u.picture,
g.id AS gradeid, g.grade, g.gradecomment,
q.timemodified, g.timemarked,
q.qtype, q.name AS qname,
COALESCE(
SIGN(SIGN(g.timemarked) + SIGN(g.timemarked - q.timemodified))
,-1
) AS status ';
$sql = 'FROM '.$CFG->prefix.'user u, '.$CFG->prefix.'question_categories c, '.$CFG->prefix.'question q '.
'LEFT JOIN '.$CFG->prefix.'qcreate_grades g ON q.id = g.questionid
AND g.qcreateid = '.$qcreate->id.' '.
'WHERE '.$where[0].'q.createdby = u.id AND u.id IN ('.implode(',',$users).
') AND q.hidden=\'0\' AND q.parent=\'0\' AND q.category = c.id and c.contextid='.$context->id;
} else {
$answercount = 0;
}
if ($grading_interface){
echo '<form id="showoptions" action="'.$thispageurl->out(true).'" method="post">';
echo '<div>';
// TODO: echo $thispageurl->hidden_params_out(array('showgraded', 'showneedsregrade', 'showungraded'));
//default value for checkbox when checkbox not checked.
echo '<input type="hidden" name="showgraded" value="0" />';
echo '<input type="hidden" name="showneedsregrade" value="0" />';
echo '<input type="hidden" name="showungraded" value="0" />';
echo '</div>';
echo '<div class="mdl-align">';
print_string('show', 'qcreate');
$checked = $showgraded?' checked="checked"':'';
echo '<input onchange="getElementById(\'showoptions\').submit(); return true;" type="checkbox" value="1" name="showgraded" id="id_showgraded"'.$checked.'/>';
echo '<label for="id_showgraded">'.get_string('showgraded', 'qcreate').'</label>';
$checked = $showneedsregrade?' checked="checked"':'';
echo '<input onchange="getElementById(\'showoptions\').submit(); return true;" type="checkbox" value="1" name="showneedsregrade" id="id_showneedsregrade"'.$checked.'/>';
echo '<label for="id_showneedsregrade">'.get_string('showneedsregrade', 'qcreate').'</label>';
$checked = $showungraded?' checked="checked"':'';
echo '<input onchange="getElementById(\'showoptions\').submit(); return true;" type="checkbox" value="1" name="showungraded" id="id_showungraded"'.$checked.'/>';
echo '<label for="id_showungraded">'.get_string('showungraded', 'qcreate').'</label>';
echo '<noscript>';
echo '<input type="submit" name="go" value="'.get_string('go').'" />';
echo '</noscript>';
echo '</div></form>';
}
$table->pagesize($perpage, $answercount);
$tableHasData = false;
ob_start();
if ($answercount && false !== ($answers = $DB->get_records_sql($select.$sql.$sort, $where[1], $table->get_page_start(), $table->get_page_size()))) {
$strupdate = get_string('update');
$strgrade = get_string('grade');
$grademenu = make_grades_menu($qcreate->grade);
$grading_info = grade_get_grades($COURSE->id, 'mod', 'qcreate', $qcreate->id, $users);
$qtypemenu = question_type_menu();
foreach ($answers as $answer) {
$final_grade = $grading_info->items[0]->grades[$answer->id];
/// Calculate user status
$answer->needsregrading = ($answer->timemarked <= $answer->timemodified);
$picture = null; // TODO: print_user_picture($answer->id, $COURSE->id, $answer->picture, false, true);
if (empty($answer->gradeid)) {
$answer->grade = -1; //no grade yet
}
if ($grading_interface && !$answer->needsregrading && $answer->timemarked!=0){
$highlight = true;
} else {
$highlight = false;
}
$colquestion = $answer->qname;
//preview?
$strpreview = get_string("preview","quiz");
if (question_has_capability_on($answer->qid, 'use')){
$link = new moodle_url('/question/preview.php?id=' . $answer->qid . '&courseid=' .$COURSE->id);
$colquestion .= $OUTPUT->action_link($link, "<img src=\"".$OUTPUT->pix_url('t/preview')."\" class=\"iconsmall\" alt=\"$strpreview\" />", new popup_action ('click', $link));
}
// edit, hide, delete question, using question capabilities, not quiz capabilieies
if (question_has_capability_on($answer->qid, 'edit') || question_has_capability_on($answer->qid, 'move')) {
$stredit = get_string("edit");
$link = new moodle_url('/question/question.php?id=' . $answer->qid . '&cmid=' .$cm->id. '&inpopup=1');
$colquestion .= $OUTPUT->action_link($link, "<img src=\"".$OUTPUT->pix_url('t/edit')."\" class=\"iconsmall\" alt=\"$stredit\" />", new popup_action ('click', $link));
} elseif (question_has_capability_on($answer->qid, 'view')){
$strview = get_string("view");
$link = new moodle_url('/question/question.php?id=' . $answer->qid . '&cmid=' .$cm->id. '&inpopup=1');
$colquestion .= $OUTPUT->action_link($link, "<img src=\"".$OUTPUT->pix_url('t/info')."\" class=\"iconsmall\" alt=\"$strview\" />", new popup_action ('click', $link));
}
if ($highlight){
$colquestion = '<span class="highlight">'.$colquestion.'</span>';
}
$colquestion .= '<br />('.$qtypemenu[$answer->qtype].')';
if ($answer->timemodified > 0) {
$studentmodified = '<div id="ts'.$answer->qid.'">'.userdate($answer->timemodified).'</div>';
} else {
$studentmodified = '';
}
if (!empty($answer->gradeid)) {
///Prints student answer and student modified date
///attach file or print link to student answer, depending on the type of the assignment.
///Refer to print_student_answer in inherited classes.
///Print grade, dropdown or text
if ($answer->timemarked > 0) {
$teachermodified = '<div id="tt'.$answer->qid.'">'.userdate($answer->timemarked).'</div>';
if ($final_grade->locked or $final_grade->overridden) {
$grade = '<div id="g'.$answer->qid.'">'.$final_grade->str_grade.'</div>';
} else {
$menu = html_writer::select(make_grades_menu($qcreate->grade), 'menu['.$answer->qid.']', $answer->grade, get_string('nograde'));
$grade = '<div id="g'.$answer->qid.'">'. $menu .'</div>';
}
} else {
$teachermodified = '<div id="tt'.$answer->qid.'"> </div>';
if ($final_grade->locked or $final_grade->overridden) {
$grade = '<div id="g'.$answer->qid.'">'.$final_grade->str_grade.'</div>';
} else {
$menu = html_writer::select(make_grades_menu($qcreate->grade), 'menu['.$answer->qid.']', $answer->grade, get_string('nograde'));
$grade = '<div id="g'.$answer->qid.'">'.$menu.'</div>';
}
}
///Print Comment
if ($final_grade->locked or $final_grade->overridden) {
$comment = '<div id="com'.$answer->qid.'">'.shorten_text(strip_tags($final_grade->str_feedback),15).'</div>';
} else {
$comment = '<div id="com'.$answer->qid.'">'
. '<textarea tabindex="'.$tabindex++.'" name="gradecomment['.$answer->qid.']" id="gradecomment'
. $answer->qid.'" rows="4" cols="30">'.($answer->gradecomment).'</textarea></div>';
}
} else {
$teachermodified = '<div id="tt'.$answer->qid.'"> </div>';
$status = '<div id="st'.$answer->qid.'"> </div>';
if ($final_grade->locked or $final_grade->overridden) {
$grade = '<div id="g'.$answer->qid.'">'.$final_grade->str_grade.'</div>';
} else { // allow editing
$menu = html_writer::select(make_grades_menu($qcreate->grade), 'menu['.$answer->qid.']', $answer->grade, get_string('nograde'));
$grade = '<div id="g'.$answer->qid.'">'.$menu.'</div>';
}
if ($final_grade->locked or $final_grade->overridden) {
$comment = '<div id="com'.$answer->qid.'">'.$final_grade->str_feedback.'</div>';
} else {
$comment = '<div id="com'.$answer->qid.'">'
. '<textarea tabindex="'.$tabindex++.'" name="gradecomment['.$answer->qid.']" id="gradecomment'
. $answer->qid.'" rows="4" cols="30">'.($answer->gradecomment).'</textarea></div>';
}
}
if ($answer->timemarked==0){
$status = get_string('needsgrading', 'qcreate');
} else if ($answer->needsregrading){
$status = get_string('needsregrading', 'qcreate');
} else {
$status = get_string('graded', 'qcreate');
}
if ($highlight){
$status = '<span class="highlight">'.$status.'</span>';
}
$finalgrade = '<span id="finalgrade_'.$answer->qid.'">'.$final_grade->str_grade.'</span>';
$outcomes = '';
if ($uses_outcomes) {
foreach($grading_info->outcomes as $n=>$outcome) {
$outcomes .= '<div class="outcome"><label>'.$outcome->name.'</label>';
$options = make_grades_menu(-$outcome->scaleid);
if ($outcome->grades[$answer->id]->locked) {
$options[0] = get_string('nooutcome', 'grades');
$outcomes .= ': <span id="outcome_'.$n.'_'.$answer->qid.'">'.$options[$outcome->grades[$answer->qid]->grade].'</span>';
} else {
$outcomes .= ' ';
$outcomes .= html_writer::select($options, 'outcome_'.$n.'['.$answer->qid.']',
$outcome->grades[$answer->qid]->grade, get_string('nooutcome', 'grades'), array('id'=>'outcome_'.$n.'_'.$answer->qid));
}
$outcomes .= '</div>';
}
}
if ($grading_interface){
$row = array($picture, fullname($answer), $colquestion, $grade, $status, $comment, $studentmodified, $teachermodified, $finalgrade);
} else {
$row = array($picture, fullname($answer), $colquestion, $comment, $studentmodified, $finalgrade);
}
if ($uses_outcomes) {
$row[] = $outcomes;
}
$table->add_data($row);
$tableHasData = true;
}
}
$table->print_html(); /// Print the whole table
$tableOutput = ob_get_clean();
if ($tableHasData) {
echo '<form action="'.$thispageurl->out(true).'" method="post">';
echo '<div>';
echo '<input type="hidden" name="gradessubmitted" value="1" />';
// TODO: echo $thispageurl->hidden_params_out();
echo '</div>';
}
echo $tableOutput;
if ($tableHasData) {
if ($grading_interface){
echo '<div style="text-align:center"><input type="submit" name="fastg" value="'.get_string('saveallfeedbackandgrades', 'qcreate').'" /></div>';
} else {
echo '<div style="text-align:center"><input type="submit" name="fastg" value="'.get_string('saveallfeedback', 'qcreate').'" /></div>';
}
echo '</form>';
/// End of fast grading form
}
/// Mini form for setting user preference
echo "\n<br />";
$form = '<form id="options" action="'.$thispageurl->out(true).'" method="post">';
$form .= '<fieldset class="invisiblefieldset">';
// TODO: $form .= $thispageurl->hidden_params_out();
$form .= '<input type="hidden" id="updatepref" name="updatepref" value="1" />';
$form .= '<p>';
$form .= '<label for="id_perpage">'.get_string('pagesize','qcreate').'</label>';
$form .= '<input type="text" id="id_perpage" name="perpage" size="1" value="'.$perpage.'" /><br />';
$form .= '<input type="submit" value="'.get_string('savepreferences').'" />';
$form .= '</p>';
$form .= '</fieldset>';
$form .= '</form>';
$OUTPUT->box($form, 'generalbox boxaligncenter boxwidthnarrow');
///End of mini form
echo $OUTPUT->footer();