-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfigure.php
509 lines (473 loc) · 18.8 KB
/
configure.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
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
<?php
require_once "../config.php";
require_once "peer_util.php";
use \Tsugi\Util\U;
use \Tsugi\Util\LTI;
use \Tsugi\Core\Cache;
use \Tsugi\Core\LTIX;
use \Tsugi\Blob\BlobUtil;
// Sanity checks
$LTI = LTIX::requireData();
// Model
$p = $CFG->dbprefix;
//set json
if ( isset($_POST['save_settings']) ) {
$partsArray = array();
for ($i=0; $i < 20; $i++){
$partList = array();
if ( isset($_POST['part_title_'.$i]) && isset($_POST['part_type_'.$i])){
$partList['title'] = $_POST['part_title_'.$i];
$partList['type'] = $_POST['part_type_'.$i];
if ($partList['type'] == 'code' && isset($_POST['part_code_'.$i])){
$partList['code'] = $_POST['part_code_'.$i];
};
array_push($partsArray, $partList);
};
}
$jsonArray = array(
"title" => U::get($_POST, 'title'),
"description" => U::get($_POST, 'description'),
"grading" => U::get($_POST, 'grading'),
"assignment" => U::get($_POST, 'assignment'),
"parts" => $partsArray,
"gallery" => U::get($_POST, 'gallery'),
"totalpoints" => U::get($_POST, 'totalpoints'),
"instructorpoints" => U::get($_POST, 'instructorpoints'),
"peerpoints" => U::get($_POST, 'peerpoints'),
"rating" => U::get($_POST, 'rating'),
"assesspoints" => U::get($_POST, 'assesspoints'),
"minassess" => U::get($_POST, 'minassess'),
"maxassess" => U::get($_POST, 'maxassess'),
"resubmit" => U::get($_POST, 'resubmit'),
"autopeer" => U::get($_POST, 'autopeer'),
"notepublic" => U::get($_POST, 'notepublic'),
"image_size" => U::get($_POST, 'image_size', '1'),
"pdf_size" => U::get($_POST, 'pdf_size'),
"flag" => U::get($_POST, 'flag')
);
// var_dump($jsonArray);
$json = json_encode($jsonArray);
$json = json_decode(upgradeSubmission($json));
if ( $json === null ) {
$_SESSION['error'] = "Bad JSON Syntax";
header( 'Location: '.addSession('configure.php') ) ;
return;
}
// Some sanity checking...
if ( $json->totalpoints < 0 ) {
$_SESSION['error'] = "totalpoints is required and must be >= 0";
header( 'Location: '.addSession('configure.php') ) ;
return;
}
if ( $json->rating > 0 and $json->peerpoints > 0 ) {
$_SESSION['error'] = "You can include peerpoints or rating range but not both.";
header( 'Location: '.addSession('configure.php') ) ;
return;
}
if ( ( $json->instructorpoints + $json->peerpoints +
($json->assesspoints*$json->minassess) ) != $json->totalpoints ) {
$_SESSION['error'] = "instructorpoints + peerpoints + (assesspoints*minassess) != totalpoints ";
header( 'Location: '.addSession('configure.php') ) ;
return;
}
$json = json_encode($json);
$stmt = $PDOX->queryReturnError(
"INSERT INTO {$p}peer_assn
(link_id, json, created_at, updated_at)
VALUES ( :ID, :JSON, NOW(), NOW())
ON DUPLICATE KEY UPDATE json = :JSON, updated_at = NOW()",
array(
':JSON' => $json,
':ID' => $LINK->id)
);
Cache::clear("peer_assn");
if ( $stmt->success ) {
$_SESSION['success'] = 'Assignment updated';
header( 'Location: '.addSession('index.php') ) ;
} else {
$_SESSION['error'] = $stmt->errorImplode;
header( 'Location: '.addSession('configure.php') ) ;
}
return;
}
// Load up the assignment
$row = loadAssignment();
$json = "";
if ( $row !== false ) $json = $row['json'];
// Clean up the JSON for presentation
if ( U::isEmpty($json) ) $json = getDefaultJson();
$json = LTI::jsonIndent($json);
$jsonObj = json_decode(upgradeSubmission($json),true);
// View
$OUTPUT->header();
?>
<style>
.fieldset {
border: 1px black solid;
padding: 5px;
margin: 5px;
}
.stacked-bar-graph {
width: 100%;
height: 38px;
color: #414042;
}
.stacked-bar-graph span {
display: inline-block;
height: 100%;
-webkit-box-sizing: border-box;
box-sizing: border-box;
float: left;
font-weight: bold;
font-family: arial, sans-serif;
padding: 10px;
border: 1px black solid;
}
.stacked-bar-graph .bar-1 {
background: #F7B334;
text-overflow: clip;
text-overflow: clip;
}
.stacked-bar-graph .bar-2 {
background: #A7A9AC;
text-overflow: clip;
}
.stacked-bar-graph .bar-3 {
background: #D57E00;
overflow: hidden;
}
</style>
<?php
$menu = new \Tsugi\UI\MenuSet();
if ( $USER->instructor ) {
$menu->addLeft('Cancel', 'index.php');
}
$OUTPUT->bodyStart();
$OUTPUT->topNav($menu);
$OUTPUT->flashMessages();
if ( ! $USER->instructor ) die("Requires instructor role");
function input_radio($jsonObj, $field, $value, $onclick=false) {
$retval = '<input type="radio" name="'.$field.'" value="' .$value.'"';
if (U::get($jsonObj,$field) == $value ) {
$retval .= ' checked';
}
if ( $onclick ) {
$retval .= ' onclick="'.$onclick.'"';
}
$retval .= "/>\n";
return $retval;
}
?>
<form method="post">
<p>
<span data-toggle="tooltip" title="
Description of assignment shown to students. This can be edited
at any time - even after the assignment has started.
">Assignment Title <i class="fa fa-question-circle-o" aria-hidden="true"></i></span><br/>
<input type="text" name="title"
value="<?= htmlentities(U::get($jsonObj,'title') ?? '') ?>"
style="width:90%"/>
</p>
<p>
<span data-toggle="tooltip" title="
Description of assignment shown to students. This can be edited at any time - even after the assignment has started.
">Assignment Description
<i class="fa fa-question-circle-o" aria-hidden="true"></i></span><br/>
<textarea name="description" style="width:90%">
<?= htmlentities(U::get($jsonObj,'description') ?? '') ?>
</textarea>
</p>
<p>
<span data-toggle="tooltip" title="
Assignment specification URL (optional)
">Assignment Specification <i class="fa fa-question-circle-o" aria-hidden="true"></i></span><br/>
<input type="text" name="assignment"
value="<?= htmlentities(U::get($jsonObj,'assignment') ?? '') ?>"
style="width:90%"/>
</p>
<span data-toggle="tooltip" title="Description of how the assignment will be/should be graded.
This can be edited at any time - even after the assignment has started.
">Grading Expectations
<i class="fa fa-question-circle-o" aria-hidden="true"></i></span><br/>
<textarea name="grading" style="width:90%">
<?= htmlentities(U::get($jsonObj,'grading') ?? ' ') ?>
</textarea>
</p>
<div class="fieldset">
<p>
Total points are calculated by adding
points from peer-graders,
the instructor-assigned points,
and the points awarded for doing peer grading.
If you are using ratings and gallery mode (below)
you might want to set all of these points to zero.
</p>
<p>
<span data-toggle="tooltip" title="This is the maximum points that come from the other students assessments. Each of the peer-graders will assign a value up to this number. If this is zero, students can comment on assignments but not assign a score. Currently the grading policy is to take the highest score from peers since this is really intended for pass/fail assignments and getting feedback from peers rather than carefully crafted assignments with subtle differences in the scores.">
Points from Peers
<i class="fa fa-question-circle-o" aria-hidden="true"></i></span>
<input type="number" name="peerpoints"
value="<?= htmlentities(U::get($jsonObj,'peerpoints') ?? '') ?>"
required/>
<i class="fa fa-asterisk" aria-hidden="true"></i>
</p>
<p>
<span data-toggle="tooltip" title="This is the number of points that come from the instructor. Leave this as zero for a purely peer-graded assignment. Set all other values to zero to create a purely instructor graded drop box.">
Instructor Points
<i class="fa fa-question-circle-o" aria-hidden="true"></i></span>
<input type="number" name="instructorpoints"
value="<?= htmlentities(U::get($jsonObj,'instructorpoints') ?? '') ?>"
required/>
<i class="fa fa-asterisk" aria-hidden="true"></i>
</p>
<p>
<span data-toggle="tooltip" title="This is the number of points students get for each peer assessment that they perform. If this is zero, students can do peer assessing/commenting but will not award points for their efforts.">
Points for doing an Assessment
<i class="fa fa-question-circle-o" aria-hidden="true"></i></span>
<input type="number" name="assesspoints"
value="<?= htmlentities(U::get($jsonObj,'assesspoints') ?? '') ?>"
required/>
<i class="fa fa-asterisk" aria-hidden="true"></i>
</p>
<p>
<span data-toggle="tooltip" title="This is the minimum number of peer submissions each student must assess. If you set Points for Peer Assessment to zero and this field to something greater than zero, students will be able to comment on their peer submissions but not assign any points.">
Minimum Peer Assessments Required
<i class="fa fa-question-circle-o" aria-hidden="true"></i></span>
<input type="text" name="minassess" id="minassess"
value="<?= htmlentities(U::get($jsonObj,'minassess') ?? '') ?>"
required>
<i class="fa fa-asterisk" aria-hidden="true"></i>
</p>
<p>
<span data-toggle="tooltip" title="This is the maximum number of peer assessments the student can do. It is OK to set this to a high number if you want to allow the students to evaluate a lot of peer submissions.">
Maximum Peer Assessments Allowed
<i class="fa fa-question-circle-o" aria-hidden="true"></i></span>
<input type="number" name="maxassess" id="maxassess"
value="<?= htmlentities(U::get($jsonObj,'maxassess') ?? '') ?>"
required>
</p>
<p>
Total Points (computed):
<input type="number" class="no_border" name="totalpoints" readonly/><br/>
<div id="bar-total" class="stacked-bar-graph">
</div>
</p>
</div>
<div class="fieldset">
<p>
This is a list of deliverables for the assignment. You must have at least one deliverable. Each deliverable has a title and type.
The title text for a deliverable can be edited at any time. You should not change
the order number, type, or order of the deliverables once the assignment has started.
</p>
<p>
<button id="add_part" type="button">Add New Deliverable</button>
<ul id="part_list"></ul>
</p>
</div>
<div class="fieldset">
<p>Assignment Settings</p>
<p>
<span data-toggle="tooltip" title="If this is true, students will be given the option to flag submissions and flag comments on their submissions. Setting this to off, turns off the flagging workflow.">
Flag
<i class="fa fa-question-circle-o" aria-hidden="true"></i></span><br/>
<?= input_radio($jsonObj, 'flag', 'false') ?>Off
<?= input_radio($jsonObj, 'flag', 'true') ?>On
</p>
<p>
<span data-toggle="tooltip" title="This enables students to delete and resubmit their submission as long as the due date has not passed.">
Student Initiated Resubmit
<i class="fa fa-question-circle-o" aria-hidden="true"></i></span><br/>
<?= input_radio($jsonObj, 'resubmit', 'off') ?>Off
<?= input_radio($jsonObj, 'resubmit', 'always') ?>Always
</p>
<p>
<span data-toggle="tooltip" title="
A number of minutes after which if a submission has not received any peer 'grades', we automatically assign a peer grade.
Leave this value zero to disable this feature.
The value is in seconds so a week is 7*24*60*60 or 604800.
The student needs to view their submission or a batch process has to run to trigger this processing.
">
Automatic Peer Grading Interval
<i class="fa fa-question-circle-o" aria-hidden="true"></i></span>
<input type="number" name="autopeer"
value="<?= htmlentities(U::get($jsonObj,'autopeer') ?? '') ?>"
required/>
</p>
<p>
The maximum file size that can be uploaded to this course is
<?= BlobUtil::maxUpload() ?> MB per *form*. You can set
lower limits per artifact if you like.
</p>
<p>
Maximum image size (MB)
<input type="number" name="image_size"
value="<?= htmlentities(U::get($jsonObj,'image_size') ?? '') ?>" />
</p>
<p>
Maximum PDF size (MB)
<input type="number" name="pdf_size"
value="<?= htmlentities(U::get($jsonObj,'pdf_size') ?? '') ?>" />
</p>
</div>
<div class="fieldset">
<p>
Gallery is a variant of the user interface where students can see lots of submissions. Often
gallery is used with no grades at all, and instead focuses on ratings.
</p>
<p>
<span data-toggle="tooltip" title="If enabled, this allows students to browse a gallery of other student submissions. You can indicate if a student can access the gallery before their submission or after their submission.">
Gallery
<i class="fa fa-question-circle-o" aria-hidden="true"></i></span><br/>
<?= input_radio($jsonObj, 'gallery', 'off', 'return gallery_off();') ?>Off
<?= input_radio($jsonObj, 'gallery', 'always', 'return gallery_on();') ?>Always
<?= input_radio($jsonObj, 'gallery', 'after', 'return gallery_on();') ?>After
</p>
<p class="gallery">
<span data-toggle="tooltip" title="
If the gallery view is selected, you can choose the format of the gallery.
">
Gallery Format
<i class="fa fa-question-circle-o" aria-hidden="true"></i></span><br/>
<?= input_radio($jsonObj, 'galleryformat', 'card') ?>Card
<?= input_radio($jsonObj, 'galleryformat', 'table') ?>Table
</p>
<p class="gallery">
<span data-toggle="tooltip" title="This indicates that the peers are rating the submission rather than grading the submission. The number is the rating scale (1-10). If you use ratings, you should not use peer grading at all..">
Rating
<i class="fa fa-question-circle-o" aria-hidden="true"></i></span><br/>
<?= input_radio($jsonObj, 'rating', '0') ?>Off
<?= input_radio($jsonObj, 'rating', '1') ?>On
</p>
<p class="gallery">
<span data-toggle="tooltip" title="Show student-entered note field to other students viewing the gallery.">
Show Note field in Gallery
<i class="fa fa-question-circle-o" aria-hidden="true"></i></span><br/>
<?= input_radio($jsonObj, 'notepublic', 'false') ?>Hide
<?= input_radio($jsonObj, 'notepublic', 'true') ?>Show
</p>
</div>
<p>
<input id="save_settings" name="save_settings" type="submit" value="Save">
<input type=submit name=doCancel onclick="location='<?php echo(addSession('index.php'));?>'; return false;" value="Cancel"></p>
</form>
<pre id="debug_pre" style="display:none">
Previous JSON:
<?= $json ?>
</pre>
<a href="#" onclick="$('#debug_pre').toggle(); return false;">Toggle Debug Data</a>
<?php
$OUTPUT->footerStart();
?>
<script type="text/javascript">
var counter = 0;
function gallery_on() {
$('.gallery').each(function() { $(this).show(); } );
}
function gallery_off() {
$('.gallery').each(function() { $(this).hide(); } );
}
function compute_total() {
if ($("input[name='instructorpoints']").val().length > 0 && $("input[name='peerpoints']").val().length > 0 &&
$("input[name='assesspoints']").val().length > 0 && $("input[name='minassess']").val().length > 0){
var inst_points = parseFloat($("input[name='instructorpoints']").val());
var peer_points = parseFloat($("input[name='peerpoints']").val());
var assess_points = parseFloat($("input[name='assesspoints']").val());
var min_assess = parseFloat($("input[name='minassess']").val());
var bar_total = inst_points + peer_points + assess_points * min_assess;
$("input[name='totalpoints']").val(bar_total);
$("#bar-total").empty();
bar_total = bar_total*1.1;
var inst_pct = Math.trunc(100*inst_points/bar_total);
var peer_pct = Math.trunc(100*peer_points/bar_total);
var assess_pct = Math.trunc(100*assess_points/bar_total);
if ( inst_pct > 0 ) $("#bar-total").append('<span style="width:'+inst_pct+'%" class="bar-1">Instructor</span>');
if ( peer_pct > 0 ) $("#bar-total").append('<span style="width:'+peer_pct+'%" class="bar-2">Peers</span>');
if ( min_assess > 0 ) {
for(var i=0; i<min_assess; i++){
$("#bar-total").append('<span style="width:'+assess_pct+'%" class="bar-3">Assess</span>');
}
}
}
}
function add_part(part) {
counter += 1;
part = part || {} ;
// Grab some HTML with hot spots and insert into the DOM
var source = $("#part-template").html();
$('#part_list').append(source.replace(/@PART@/g,counter));
if ( part.title ) $('#part_title_'+counter).val(part.title);
if ( part.type ) {
$('#part_type_'+counter).val(part.type);
if ( part.type == 'code' && part.language ) {
$('#part_code_'+counter).val(part.language);
$('#part_code_'+counter).show();
}
}
}
$( document ).ready(function() {
compute_total();
<?php
if ( U::get($jsonObj,'parts') ) {
foreach ($jsonObj['parts'] as $part ) {
echo(" add_part(".json_encode($part).");\n");
}
}
if ( U::get($jsonObj,'gallery') == 'off' ) {
echo(" gallery_off();\n");
}
?>
$("input[name='instructorpoints'], input[name='peerpoints'], input[name='assesspoints'], input[name='minassess']").change(compute_total);
$("#add_part").on('click', function(){
add_part();
});
});
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
function update_part_form(partno) {
var x = $('#part_type_'+partno).val();
if ( x == 'code' ) {
$('#part_code_'+partno).show();
} else {
$('#part_code_'+partno).hide();
}
}
</script>
<!-- HTML with Substitution hot spots -->
<script id="part-template" type="text">
<li id="part_@PART@">
<p>
<input type="text" style="width:70%" name="part_title_@PART@" id="part_title_@PART@"
placeholder=" .. Title (Required) .." required>
<span data-toggle="tooltip" title="Please enter the title of the deliverable.">
<i class="fa fa-asterisk"></i>
</span>
<br>
<select name="part_type_@PART@" id="part_type_@PART@" class="part_type" onchange="update_part_form(@PART@);">
<option value="">-- Select Type of Submission --</option>
<option value="image">Image</option>
<option value="pdf">PDF</option>
<option value="url">URL</option>
<option value="html">Formatted text</option>
<option value="code">Code/text</option>
</select>
<select name="part_code_@PART@" id="part_code_@PART@" style="display:none;">
<option value="">-- Select format of submission ---</option>
<option value="markup">Markup</option>
<option value="css">CSS</option>
<option value="javascript">JavaScript</option>
<option value="php">PHP</option>
<option value="java">Java</option>
<option value="c">C</option>
<option value="python">Python</option>
<option value="sql">SQL</option>
<option value="ruby">Ruby</option>
</select>
 
<input type="button" value="Delete Deliverable" onclick="
if( confirm('Are you sure you want to delete this deliverable?') ) $('#part_@PART@').remove();return false;">
</li>
</script>
<?php
$OUTPUT->footerEnd();