-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstudent.php
More file actions
539 lines (485 loc) · 20.5 KB
/
student.php
File metadata and controls
539 lines (485 loc) · 20.5 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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
<?php
require_once "../config.php";
use \Tsugi\Blob\BlobUtil;
require_once "peer_util.php";
use \Tsugi\Util\U;
use \Tsugi\Core\Cache;
use \Tsugi\Core\LTIX;
use \Tsugi\Core\Result;
use \Tsugi\Core\User;
use \Tsugi\UI\Table;
use \Tsugi\Grades\GradeUtil;
// Set up the GET Params that we want to carry around.
$getparms = $_GET;
unset($getparms['delete']);
unset($getparms['resend']);
if ( !isset($STUDENT_RETURN) ) $STUDENT_RETURN = Table::makeUrl('admin.php', $getparms, Array('user_id'=>false));
// Sanity checks
$LAUNCH = LTIX::requireData();
if ( ! $USER->instructor ) die("Requires instructor role");
$p = $CFG->dbprefix;
if ( !isset($_REQUEST['user_id']) ) die("user_id parameter required");
$user_id = $_REQUEST['user_id'];
// Load the assignment
$row = loadAssignment();
$assn_json = null;
$assn_id = false;
if ( $row !== false ) {
$assn_json = json_decode(upgradeSubmission($row['json']));
$assn_id = $row['assn_id'];
}
if ( $assn_id === false ) {
$_SESSION['error'] = "This assignment is not yet set up.";
header( 'Location: '.addSession('index') ) ;
return;
}
$submit_id = false;
$submit_row = loadSubmission($assn_id, $user_id);
if ( $submit_row !== false ) {
$submit_id = $submit_row['submit_id']+0;
}
// Load user info
$user_row = User::loadUserInfoBypass($user_id);
if ( $user_row == false ) {
$_SESSION['error'] = "Could not load student data.";
header( 'Location: '.addSession('index') ) ;
return;
}
// Handle incoming post to delete the entire submission
if ( isset($_POST['deleteSubmit']) ) {
if ( $submit_id == false ) {
$_SESSION['error'] = "Could not load submission.";
header( 'Location: '.addSession('index') ) ;
return;
}
deleteSubmission($row, $submit_row);
$note = isset($_POST['deleteNote']) ? $_POST['deleteNote'] : '';
$retval = mailDeleteSubmit($user_id, $assn_json, $note);
$stmt = $PDOX->queryDie(
"DELETE FROM {$p}peer_submit
WHERE submit_id = :SID",
array( ':SID' => $submit_id)
);
// Since text items are connected to the assignment not submission
$stmt = $PDOX->queryDie(
"DELETE FROM {$p}peer_text
WHERE assn_id = :AID AND user_id = :UID",
array( ':AID' => $assn_id, ':UID' => $user_id)
);
$msg = "Deleted submission for $user_id";
if ( $retval ) $msg .= ', e-mail notice sent.';
error_log($msg);
Cache::clear('peer_grade');
Cache::clear('peer_submit');
$msg = "Submission deleted";
if ( $retval ) $msg .= ', e-mail notice sent.';
$_SESSION['success'] = $msg;
header( 'Location: '.addSession($STUDENT_RETURN) ) ;
return;
}
// Handle incoming post to set the instructor points and update the grade
if ( isset($_POST['instSubmit']) || isset($_POST['instSubmitAdvance']) ) {
if ( $submit_id == false ) {
$_SESSION['error'] = "Could not load submission.";
header( 'Location: '.addSession('index') ) ;
return;
}
// Check the legit options here
$points = isset($_POST['inst_points']) ? trim($_POST['inst_points']) : null;
if ( U::isEmpty($points) ) {
$points = null;
} else if ( is_numeric($points) ) {
$points = $points + 0;
} else {
$_SESSION['error'] = "Points must either by a number or blank.";
$studenturl = Table::makeUrl('student.php', $getparms);
header( 'Location: '.addSession($studenturl) ) ;
return;
}
// Check the range here
if ( $points < 0 || $points > $assn_json->instructorpoints ) {
$_SESSION['error'] = "Bad value for instructor point value.";
$studenturl = Table::makeUrl('student.php', $getparms);
header( 'Location: '.addSession($studenturl) ) ;
return;
}
$stmt = $PDOX->queryDie(
"UPDATE {$p}peer_submit SET
inst_points = :IP, inst_note = :IN
WHERE submit_id = :SID",
array( ':IP' => $points,
':IN' => $_POST['inst_note'],
':SID' => $submit_id)
);
Cache::clear('peer_grade');
Cache::clear('peer_submit');
$msg = "Submission updated";
$computed_grade = computeGrade($assn_id, $assn_json, $user_id); // Does not cache
$result = Result::lookupResultBypass($user_id);
$old_grade = null;
if ( $result && isset($result['grade']) && $result['grade'] != -1 ) {
$old_grade = floatval($result['grade']);
}
$result['grade'] = -1; // Force resend
$debug_log = array();
$status = LTIX::gradeSend($computed_grade, $result, $debug_log); // This is the slow bit
if ( $status === true ) {
$_SESSION['success'] = 'Grade submitted to server';
// Send notification to the student whose grade was changed (only if grade actually changed)
// Use LTI launch_presentation_return_url if available, otherwise fall back to index
$notification_url = null;
if ( is_object($LAUNCH) && method_exists($LAUNCH, 'returnUrl') ) {
$notification_url = $LAUNCH->returnUrl();
}
if ( empty($notification_url) ) {
$notification_url = Table::makeUrl('index', $getparms);
$notification_url = addSession($notification_url);
}
notifyGradeChange($user_id, $computed_grade, $old_grade, $assn_json->title ?? null, $notification_url);
} else {
error_log("Problem sending grade ".$status);
$_SESSION['error'] = 'Error sending grade to: '.$status;
$_SESSION['debug_log'] = $debug_log;
}
if ( isset($_POST['instSubmitAdvance']) && isset($_POST['next_user_id_ungraded']) && is_numeric($_POST['next_user_id_ungraded']) ) {
$next_user_id_ungraded = $_POST['next_user_id_ungraded']+0;
$studenturl = Table::makeUrl('student.php', $getparms, Array("user_id" => $next_user_id_ungraded));
header( 'Location: '.addSession($studenturl) ) ;
} else {
$studenturl = Table::makeUrl('student.php', $getparms);
header( 'Location: '.addSession($studenturl) ) ;
}
return;
}
// Compute grade
$computed_grade = computeGrade($assn_id, $assn_json, $user_id); // Does not cache
if ( isset($_POST['resendSubmit']) ) {
$result = Result::lookupResultBypass($user_id); // Does not cache
// Force a resend
$_SESSION['lti']['grade'] = -1; // Force a resend
$result['grade'] = -1;
$debug_log = array();
$status = LTIX::gradeSend($computed_grade, $result, $debug_log); // This is the slow bit
if ( $status === true ) {
$_SESSION['success'] = 'Grade submitted to server';
} else {
error_log("Problem sending grade ".$status);
$_SESSION['error'] = 'Error: '.$status;
}
$_SESSION['debug_log'] = $debug_log;
$studenturl = Table::makeUrl('student.php', $getparms);
header( 'Location: '.addSession($studenturl) ) ;
return;
}
// Retrieve received grades and grades that have been
$grades_received = retrieveSubmissionGrades($submit_id);
$grades_given = retrieveGradesGiven($assn_id, $user_id);
$peer_marks = retrievePeerMarks($assn_id, $user_id);
// Handle incoming post to delete a grade entry
if ( isset($_POST['grade_id']) && isset($_POST['deleteGrade']) ) {
// Make sure this is deleting a legit grading entry...
$found = false;
if ( $grades_given != false ) foreach ( $grades_given as $grade ) {
if ($_POST['grade_id'] == $grade['grade_id'] ) $found = true;
}
if ( ! $found ) {
$_SESSION['error'] = "Grade entry not found.";
header( 'Location: '.addSession('index') ) ;
return;
}
$stmt = $PDOX->queryDie(
"DELETE FROM {$p}peer_grade
WHERE grade_id = :GID",
array( ':GID' => $_POST['grade_id'])
);
Cache::clear('peer_grade');
error_log("Instructor deleted grade entry for ".$user_id);
$_SESSION['success'] = "Grade entry deleted.";
$studenturl = Table::makeUrl('student.php', $getparms);
header( 'Location: '.addSession($studenturl) ) ;
return;
}
// Retrieve our flags...
$our_flags = false;
if ( $submit_id !== false ) {
$stmt = $PDOX->queryDie(
"SELECT flag_id, F.user_id AS user_id, grade_id, note, handled, response,
F.updated_at AS updated_at, displayname, email
FROM {$p}peer_flag AS F
JOIN {$p}lti_user as U
ON F.user_id = U.user_id
WHERE submit_id = :SID",
array( ':SID' => $submit_id)
);
$our_flags = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
// Handle incoming post to delete a flag entry
if ( isset($_POST['flag_id']) && isset($_POST['deleteFlag']) ) {
// Make sure this is a legit flag entry
$found = false;
if ( $our_flags != false ) foreach ( $our_flags as $flag ) {
if ($_POST['flag_id'] == $flag['flag_id'] ) $found = true;
}
if ( ! $found ) {
$_SESSION['error'] = "Flag entry not found.";
header( 'Location: '.addSession('index') ) ;
return;
}
$stmt = $PDOX->queryDie(
"DELETE FROM {$p}peer_flag
WHERE flag_id = :FID",
array( ':FID' => $_POST['flag_id'])
);
Cache::clear('peer_flag');
Cache::clear('peer_grade');
error_log("Instructor deleted flag=".$_POST['flag_id']." for ".$user_id);
$_SESSION['success'] = "Flag entry deleted.";
$studenturl = Table::makeUrl('student.php', $getparms);
header( 'Location: '.addSession($studenturl) ) ;
return;
}
// Retrieve the next and previous users for paging
$sql = "(SELECT user_id, inst_points FROM {$p}peer_submit
WHERE user_id < :UID AND assn_id = :AID ORDER BY user_id DESC LIMIT 1)
UNION (SELECT user_id, inst_points FROM {$p}peer_submit
WHERE user_id > :UID AND assn_id = :AID ORDER BY user_id ASC LIMIT 1)";
$rows = $PDOX->allRowsDie($sql,
array(":UID" => $user_id, ":AID" => $assn_id)
);
// Retrieve ungraded rows in a circular manner
$ungraded_rows = false;
if ( $assn_json->instructorpoints > 0 ) {
$ungraded_sql = "(SELECT user_id, inst_points FROM {$p}peer_submit
WHERE user_id > :UID AND assn_id = :AID AND inst_points IS NULL ORDER BY user_id ASC LIMIT 1)
UNION (SELECT user_id, inst_points FROM {$p}peer_submit
WHERE user_id != :UID AND assn_id = :AID AND inst_points IS NULL ORDER BY user_id ASC LIMIT 1)
";
$ungraded_rows = $PDOX->allRowsDie($ungraded_sql,
array(":UID" => $user_id, ":AID" => $assn_id)
);
}
// View
$OUTPUT->header();
?>
<link href="<?= U::get_rest_parent() ?>/static/prism.css" rel="stylesheet"/>
<script>
let html_loads = [];
</script>
<?php
$OUTPUT->bodyStart();
$OUTPUT->topNav();
$prev_user_id = false;
$next_user_id = false;
foreach ($rows as $row ) {
if ( $row['user_id'] < $user_id ) $prev_user_id = $row['user_id'];
if ( $row['user_id'] > $user_id && $next_user_id === false ) $next_user_id = $row['user_id'];
}
$next_user_id_ungraded = false;
if ( $assn_json->instructorpoints > 0 && count($ungraded_rows) > 0 ) {
$next_user_id_ungraded = $ungraded_rows[0]['user_id'];
}
$user_display = false;
echo('<div style="float:right">');
if ( $prev_user_id !== false ) {
$studenturl = Table::makeUrl('student.php', $getparms, Array("user_id" => $prev_user_id));
echo('<button class="btn btn-normal"
title="Students are ordered by user_id"
onclick="location=\''.addSession($studenturl).'\';
return false">Previous Student</button> ');
} else {
echo('<button class="btn btn-normal"
title="Students are ordered by user_id"
disabled="disabled">Previous Student</button> ');
}
if ( $next_user_id !== false ) {
$studenturl = Table::makeUrl('student.php', $getparms, Array("user_id" => $next_user_id));
echo('<button class="btn btn-normal"
title="Students are ordered by user_id"
onclick="location=\''.addSession($studenturl).'\';
return false">Next Student</button> ');
} else {
echo('<button class="btn btn-normal"
title="Students are ordered by user_id"
disabled="disabled">Next Student</button> ');
}
if ( $next_user_id_ungraded !== false ) {
$studenturl = Table::makeUrl('student.php', $getparms, Array("user_id" => $next_user_id_ungraded));
echo('<button class="btn btn-normal"
title="At the end of ungraded students this goes back to the first ungraded student."
onclick="location=\''.addSession($studenturl).'\';
return false">Next Ungraded Student</button> ');
} else if ( $assn_json->instructorpoints > 0 ) {
echo('<button class="btn btn-normal"
title="All students have instructor grades"
disabled="disabled">Next Ungraded Student</button> ');
}
echo('<button type="button" class="btn btn-success"
onclick="location=\''.addSession($STUDENT_RETURN).'\'; return false;" aria-label="Exit to student list">Exit</button>');
echo("</div>");
if ( $user_row != false ) {
$user_display = htmlentities($user_row['displayname'] ?? '')." (".htmlentities($user_row['email'] ?? '').")";
echo("<p><b>Grade record for: ".htmlentities($user_row['displayname'] ?? '')."</b></p>\n");
}
echo('<br clear="all"/>');
// Delay flash messages
$OUTPUT->flashMessages();
if ( $submit_row === false ) {
echo("<p>This student has not made a submission.</p>\n");
} else {
$submit_json = json_decode($submit_row['json']);
showSubmission($assn_json, $submit_json, $assn_id, $user_id);
if ( $submit_json && isset($submit_json->peer_exempt) ) {
echo("<p>This student has requested an peer grading exemption due to accessibility issues.</p>\n");
}
}
echo('<form method="post">
<input type="hidden" name="user_id" value="'.$user_id.'">');
if ( $next_user_id_ungraded !== false ) {
echo('<input type="hidden" name="next_user_id_ungraded" value="'.$next_user_id_ungraded.'">');
}
if ( $assn_json->instructorpoints > 0 ) {
echo('<label for="inst_points">Instructor Points</label>
<input type="number" name="inst_points" id="inst_points" min="0" ');
echo('max="'. $assn_json->instructorpoints.'" value="'.($submit_row["inst_points"]).'">');
echo(" (Maximum ". $assn_json->instructorpoints.' points)<br/>');
}
echo('<label for="inst_note">Instructor Note To Student</label><br/>
<textarea name="inst_note" id="inst_note" style="width:60%" rows="5">');
echo(htmlentities($submit_row['inst_note'] ?? ''));
echo('</textarea><br/>
<input type="submit" name="instSubmit" value="Update" class="btn btn-primary">');
if ( $next_user_id_ungraded !== false ) {
echo(' <input type="submit" name="instSubmitAdvance" value="Update and Go To Next Ungraded Student" class="btn btn-primary">');
}
echo('</form>');
if ( $assn_json->maxassess > 0 ) {
$gradeurl = Table::makeUrl('grade', $getparms);
echo('<p><a href="'.$gradeurl.'">Peer grade this student</a></p>'."\n");
}
if ( $assn_json->rating > 0 ) {
$rateadmin = Table::makeUrl('rate-admin.php', $getparms);
echo('<p><a href="'.$rateadmin.'">Rate this student</a></p>'."\n");
}
if ( isset($_GET['delete']) ) {
$studenturl = Table::makeUrl('student.php', $getparms);
echo('<form method="post">
<input type="hidden" name="user_id" value="'.$user_id.'">
<label for="deleteNote">Enter an optional note to send to the student</label><br/>
<textarea name="deleteNote" id="deleteNote" style="width:60%" rows="5">
</textarea><br/>
<input type="submit" name="deleteSubmit" value="Complete Delete" class="btn btn-danger">
<input type="submit" name="doCancel" value="Cancel Delete" class="btn btn-normal"
onclick="location=\''.addSession($studenturl).'\'; return false;">
</form>');
} else {
$studenturl = Table::makeUrl('student.php', $getparms, Array("delete" => "yes"));
echo('<p><a href="'.$studenturl.'">Delete this
submission and grades (allows student to resubmit)</a></p>'."\n");
}
if ( $assn_json->totalpoints == 0 ) {
echo("<p>This is an ungraded assignment</p>\n");
} else {
echo("<p>Computed grade: ".$computed_grade."<br/>\n");
if ( isset($_GET['resend']) ) {
$studenturl = Table::makeUrl('student.php', $getparms);
echo('<form method="post">
<input type="hidden" name="user_id" value="'.$user_id.'">
<input type="submit" name="resendSubmit" value="Resend the Grade" class="btn btn-warning">
<input type="submit" name="doCancel" value="Cancel Resend" class="btn btn-normal"
onclick="location=\''.addSession($studenturl).'\'; return false;">
</form>');
} else {
$studenturl = Table::makeUrl('student.php', $getparms, Array("resend" => "yes"));
echo('<p><a href="'.$studenturl.'">
Resend computed grade to the LMS</a></p>');
}
}
if ( $user_display !== false ) $user_display = " by ".$user_display;
if ( $our_flags !== false && count($our_flags) > 0 ) {
echo("<p style=\"color:red\">This entry $user_display has the following flags:</p>\n");
echo('<div style="margin:3px;">');
echo('<table border="1" class="table table-hover table-condensed table-responsive"><tr>');
echo("\n<th>Flagged By</th><th>Email</th><th>Comment</th><th>Time</th><th>Action</th></tr>");
foreach ( $our_flags as $flag ) {
echo("\n<tr>");
echo("<td>".htmlentities($flag['displayname'] ?? '')."</td>\n");
echo("<td>".htmlentities($flag['email'] ?? '')."</td>\n");
echo("<td>".htmlentities($flag['note'] ?? '')."</td>\n");
echo("<td>".htmlentities($flag['updated_at'] ?? '')."</td>\n");
echo('<td> <form method="post"><input type="hidden"
name="flag_id" value="'.$flag['flag_id'].'">
<input type="submit" name="deleteFlag" value="delete" class="btn btn-danger"></form></td>');
echo("</tr>\n");
}
echo("</table>\n");
echo("</div>\n");
}
if ( $grades_received === false || count($grades_received) < 1 ) {
echo("<p>No peer has graded this submission $user_display.</p>");
} else {
echo("<p>Grades Received$user_display:</p>");
echo('<div style="margin:3px;">');
echo('<table border="1" class="table table-hover table-condensed table-responsive">');
echo("\n<tr><th>User</th><th>Email</th>");
if ( $assn_json->peerpoints > 0 ) echo("<th>Points</th>");
if ( $assn_json->rating > 0 ) echo("<th>Rating</th>");
echo("<th>Comments</th><th>Action</th></tr>\n");
foreach ( $grades_received as $grade ) {
echo("<tr>
<td>".htmlentities($grade['displayname'] ?? '')."</td>
<td>".htmlentities($grade['email'] ?? '')."</td>");
if ( $assn_json->peerpoints > 0 ) echo("<td>".$grade['points']."</td>");
if ( $assn_json->rating > 0 ) echo("<td>".$grade['rating']."</td>");
echo("<td>".htmlentities($grade['note'] ?? '')."</td>".
'<td> <form method="post"><input type="hidden"
name="grade_id" value="'.$grade['grade_id'].'">
<input type="hidden" name="user_id" value="'.$user_id.'">
<input type="submit" name="deleteGrade" value="delete" class="btn btn-danger"></form></td>'.
"\n</tr>\n");
}
echo("</table>\n");
echo("</div>\n");
}
if ( $grades_given === false || count($grades_given) < 1 ) {
if ( $peer_marks > 0 ) {
echo("<p>$peer_marks peer_marks given $user_display.</p>");
} else {
echo("<p>Nothing has been graded $user_display yet.</p>");
}
} else {
echo("<p>Grades Given$user_display:</p>");
echo('<div style="margin:3px;">');
echo('<table border="1" class="table table-hover table-condensed table-responsive">');
echo("\n<tr><th>User</th><th>Email</th>");
if ( $assn_json->peerpoints > 0 ) echo("<th>Points</th>");
if ( $assn_json->rating > 0 ) echo("<th>Rating</th>");
echo("<th>Comments</th><th>Action</th></tr>\n");
foreach ( $grades_given as $grade ) {
echo("<tr>
<td>".htmlentities($grade['displayname'] ?? '')."</td>
<td>".htmlentities($grade['email'] ?? '')."</td>");
if ( $assn_json->peerpoints > 0 ) echo("<td>".$grade['points']."</td>");
if ( $assn_json->rating > 0 ) echo("<td>".$grade['rating']."</td>");
echo("<td>".htmlentities($grade['note'] ?? '')."</td>".
'<td> <form method="post"><input type="hidden"
name="grade_id" value="'.$grade['grade_id'].'">
<input type="hidden" name="user_id" value="'.$user_id.'">
<input type="submit" name="deleteGrade" value="delete" class="btn btn-danger"></form></td>'.
"\n</tr>\n");
}
echo("</table>\n");
echo("</div>\n");
}
// Delay the debug output to the bottom
if ( isset($_SESSION['debug_log']) ) {
echo("<p>Grade send log below:</p>\n");
$OUTPUT->dumpDebugArray($_SESSION['debug_log']);
unset($_SESSION['debug_log']);
echo("<p></p>\n");
}
$OUTPUT->footerStart();
?>
<script src="<?= U::get_rest_parent() ?>/static/prism.js" type="text/javascript"></script>
<?php
load_htmls();
$OUTPUT->footerEnd();