mirrored from git://git.moodle.org/moodle.git
/
view.php
493 lines (429 loc) · 22.5 KB
/
view.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
<?php // $Id: view.php, v1.1 23 Aug 2003
/*************************************************
ACTIONS handled are:
allowassessments (for teachers)
allowboth (for teachers)
allowsubmissions (for teachers)
close workshop( for teachers)
displayfinalgrade (for students)
notavailable (for students)
setupassignment (for teachers)
studentsview
submitexample
teachersview
************************************************/
require("../../config.php");
require("lib.php");
require("locallib.php");
require_variable($id); // Course Module ID
// get some useful stuff...
if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
if (! $course = get_record("course", "id", $cm->course)) {
error("Course is misconfigured");
}
if (! $workshop = get_record("workshop", "id", $cm->instance)) {
error("Course module is incorrect");
}
require_login($course->id);
// ...log activity...
add_to_log($course->id, "workshop", "view", "view.php?id=$cm->id", $workshop->id, $cm->id);
$strworkshops = get_string("modulenameplural", "workshop");
$strworkshop = get_string("modulename", "workshop");
// ...display header...
print_header_simple("$workshop->name", "",
"<a href=\"index.php?id=$course->id\">$strworkshops</a> -> $workshop->name",
"", "", true, update_module_button($cm->id, $course->id, $strworkshop), navmenu($course, $cm));
// ...and if necessary set default action
optional_variable($action);
if (isteacher($course->id)) {
if (empty($action)) { // no action specified, either go straight to elements page else the admin page
// has the assignment any elements
if (count_records("workshop_elements", "workshopid", $workshop->id) >= $workshop->nelements) {
$action = "teachersview";
}
else {
redirect("assessments.php?action=editelements&id=$cm->id");
}
}
}
elseif (!isguest()) { // it's a student then
if (!$cm->visible) {
notice(get_string("activityiscurrentlyhidden"));
}
switch ($workshop->phase) {
case 0 :
case 1 : $action = 'notavailable'; break;
case 2 :
case 3 :
case 4 : $action = 'studentsview'; break;
case 5 : $action = 'displayfinalgrade';
}
}
else { // it's a guest, oh no!
$action = 'notavailable';
}
/************** allow (peer) assessments only (move to phase 4) (for teachers)**/
if ($action == 'allowassessments') {
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
// move to phase 4
set_field("workshop", "phase", 4, "id", "$workshop->id");
add_to_log($course->id, "workshop", "assessments only", "view.php?id=$cm->id", "$workshop->id", $cm->id);
redirect("view.php?id=$cm->id", get_string("movingtophase", "workshop", 4));
}
/************** allow both (submissions and assessments) (move to phase 3) (for teachers)**/
if ($action == 'allowboth') {
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
// move to phase 3
set_field("workshop", "phase", 3, "id", "$workshop->id");
add_to_log($course->id, "workshop", "allow both", "view.php?id=$cm->id", "$workshop->id", $cm->id);
redirect("view.php?id=$cm->id", get_string("movingtophase", "workshop", 3));
}
/************** allow submissions only (move to phase 2) (for teachers)**/
if ($action == 'allowsubmissions') {
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
// move to phase 2, check that teacher has made enough submissions
if (workshop_count_teacher_submissions($workshop) < $workshop->ntassessments) {
redirect("view.php?id=$cm->id", get_string("notenoughexamplessubmitted", "workshop",
$course->teacher));
}
else {
if ($n = workshop_count_teacher_submissions_for_assessment($workshop, $USER)) {
notify(get_string("teachersubmissionsforassessment", "workshop", $n));
}
set_field("workshop", "phase", 2, "id", "$workshop->id");
add_to_log($course->id, "workshop", "submissions", "view.php?id=$cm->id", "$workshop->id", $cm->id);
redirect("view.php?id=$cm->id", get_string("movingtophase", "workshop", 2));
}
}
/****************** display final grade (for students) ************************************/
elseif ($action == 'displayfinalgrade' ) {
// show the final grades as stored in the tables...
print_heading_with_help(get_string("displayoffinalgrades", "workshop"), "finalgrades", "workshop");
if ($submissions = workshop_get_user_submissions($workshop, $USER)) { // any submissions from user?
echo "<center><table border=\"1\" width=\"90%\"><tr>";
echo "<td><b>".get_string("submissions", "workshop")."</b></td>";
if ($workshop->wtype) {
echo "<td align=\"center\"><b>".get_string("assessmentsdone", "workshop")."</b></td>";
echo "<td align=\"center\"><b>".get_string("gradeforassessments", "workshop")."</b></td>";
}
echo "<td align=\"center\"><b>".get_string("teacherassessments", "workshop",
$course->teacher)."</b></td>";
if ($workshop->wtype) {
echo "<td align=\"center\"><b>".get_string("studentassessments", "workshop",
$course->student)."</b></td>";
}
echo "<td align=\"center\"><b>".get_string("gradeforsubmission", "workshop")."</b></td>";
echo "<td align=\"center\"><b>".get_string("overallgrade", "workshop")."</b></td></tr>\n";
$gradinggrade = workshop_gradinggrade($workshop, $USER);
foreach ($submissions as $submission) {
$grade = workshop_submission_grade($workshop, $submission);
echo "<tr><td>".workshop_print_submission_title($workshop, $submission)."</td>\n";
if ($workshop->wtype) {
echo "<td align=\"center\">".workshop_print_user_assessments($workshop, $USER)."</td>";
echo "<td align=\"center\">$gradinggrade</td>";
}
echo "<td align=\"center\">".workshop_print_submission_assessments($workshop,
$submission, "teacher")."</td>";
if ($workshop->wtype) {
echo "<td align=\"center\">".workshop_print_submission_assessments($workshop,
$submission, "student")."</td>";
}
echo "<td align=\"center\">$grade</td>";
echo "<td align=\"center\">".number_format($gradinggrade + $grade, 1)."</td></tr>\n";
}
}
echo "</table><br clear=\"all\" />\n";
workshop_print_key($workshop);
if ($workshop->showleaguetable) {
workshop_print_league_table($workshop);
}
}
/****************** make final grades available (go to phase 5) (for teachers only)********/
elseif ($action == 'makefinalgradesavailable') {
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
set_field("workshop", "phase", 5, "id", "$workshop->id");
add_to_log($course->id, "workshop", "display grades", "view.php?id=$cm->id", "$workshop->id", $cm->id);
redirect("view.php?id=$cm->id", get_string("movingtophase", "workshop", 5));
}
/****************** assignment not available (for students)***********************/
elseif ($action == 'notavailable') {
print_heading(get_string("notavailable", "workshop"));
}
/****************** set up assignment (move back to phase 1) (for teachers)***********************/
elseif ($action == 'setupassignment') {
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
set_field("workshop", "phase", 1, "id", "$workshop->id");
add_to_log($course->id, "workshop", "set up", "view.php?id=$cm->id", "$workshop->id", $cm->id);
redirect("view.php?id=$cm->id", get_string("movingtophase", "workshop", 1));
}
/****************** student's view could be in 1 of 4 stages ***********************/
elseif ($action == 'studentsview') {
workshop_print_assignment_info($workshop);
// is a password needed?
if ($workshop->usepassword) {
$correctpass = false;
if (isset($_POST['userpassword'])) {
if ($workshop->password == md5(trim($_POST['userpassword']))) {
$USER->workshoploggedin[$workshop->id] = true;
$correctpass = true;
}
} elseif (isset($USER->workshoploggedin[$workshop->id])) {
$correctpass = true;
}
if (!$correctpass) {
print_simple_box_start("center");
echo "<form name=\"password\" method=\"post\" action=\"view.php\">\n";
echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
echo "<table cellpadding=\"7px\">";
if (isset($_POST['userpassword'])) {
echo "<tr align=\"center\" style='color:#DF041E;'><td>".get_string("wrongpassword", "workshop").
"</td></tr>";
}
echo "<tr align=\"center\"><td>".get_string("passwordprotectedworkshop", "workshop", $workshop->name).
"</td></tr>";
echo "<tr align=\"center\"><td>".get_string("enterpassword", "workshop").
" <input type=\"password\" name=\"userpassword\" /></td></tr>";
echo "<tr align=\"center\"><td>";
echo "<input type=\"button\" value=\"".get_string("cancel").
"\" onclick=\"parent.location='../../course/view.php?id=$course->id';\"> ";
echo "<input type=\"button\" value=\"".get_string("continue").
"\" onclick=\"document.password.submit();\" />";
echo "</td></tr></table>";
print_simple_box_end();
exit();
}
}
// in Stage 1? - are there any teacher's submissions? and...
// ...has student assessed the required number of the teacher's submissions
if ($workshop->ntassessments and (!workshop_test_user_assessments($workshop, $USER))) {
print_heading(get_string("pleaseassesstheseexamplesfromtheteacher", "workshop",
$course->teacher));
workshop_list_teacher_submissions($workshop, $USER);
}
// in stage 2? - submit own first attempt
else {
if ($workshop->ntassessments) {
// show assessment the teacher's examples, there may be feedback from teacher
print_heading(get_string("yourassessmentsofexamplesfromtheteacher", "workshop",
$course->teacher));
workshop_list_teacher_submissions($workshop, $USER);
}
// has user submitted anything yet? (only allowed in phases 2 and 3)
if (!workshop_get_user_submissions($workshop, $USER)) {
if ($workshop->phase < 4) {
// print upload form
print_heading(get_string("submitassignmentusingform", "workshop").":");
workshop_print_upload_form($workshop);
} else {
print_heading(get_string("submissionsnolongerallowed", "workshop"));
}
}
// in stage 3? - grade other student's submissions, resubmit and list all submissions
else {
// is self assessment used in this workshop?
if ($workshop->includeself) {
// prints a table if there are any submissions which have not been self assessed yet
workshop_list_self_assessments($workshop, $USER);
}
// if peer assessments are being done and workshop is in phase 3 then show some to assess...
if ($workshop->nsassessments and ($workshop->phase > 2)) {
workshop_list_student_submissions($workshop, $USER);
}
// ..and any they have already done (and have gone cold)...
if (workshop_count_user_assessments($workshop, $USER, "student")) {
print_heading(get_string("yourassessments", "workshop"));
workshop_list_assessed_submissions($workshop, $USER);
}
// list any assessments by teachers
if (workshop_count_teacher_assessments($workshop, $USER)) {
print_heading(get_string("assessmentsby", "workshop", $course->teachers));
workshop_list_teacher_assessments($workshop, $USER);
}
// ... and show peer assessments
if (workshop_count_peer_assessments($workshop, $USER)) {
print_heading(get_string("assessmentsby", "workshop", $course->students));
workshop_list_peer_assessments($workshop, $USER);
}
// list previous submissions
print_heading(get_string("submissions", "workshop"));
workshop_list_user_submissions($workshop, $USER);
// are resubmissions allowed and the workshop is in submission phases (2 and 3)?
if ($workshop->resubmit and ($workshop->phase < 4)) {
// see if there are any cold assessments of the last submission
// if there are then print upload form
if ($submissions = workshop_get_user_submissions($workshop, $USER)) {
foreach ($submissions as $submission) {
$lastsubmission = $submission;
break;
}
$n = 0; // number of cold assessments (not include self assessments)
if ($assessments = workshop_get_assessments($lastsubmission)) {
foreach ($assessments as $assessment) {
if ($assessment->userid <> $USER->id) {
$n++;
}
}
}
if ($n) {
echo "<hr size=\"1\" noshade=\"noshade\" />";
print_heading(get_string("submitrevisedassignment", "workshop").":");
workshop_print_upload_form($workshop);
echo "<hr size=\"1\" noshade=\"noshade\" />";
}
}
}
}
}
}
/****************** submission of example by teacher only***********************/
elseif ($action == 'submitexample') {
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
$strdifference = format_time($workshop->deadline - time());
if (($workshop->deadline - time()) < 0) {
$strdifference = "<font color=\"red\">$strdifference</font>";
}
$strduedate = userdate($workshop->deadline)." ($strdifference)";
workshop_print_assignment_info($workshop);
// list previous submissions from teacher
workshop_list_user_submissions($workshop, $USER);
echo "<hr size=\"1\" noshade=\"noshade\" />";
// print upload form
print_heading(get_string("submitexampleassignment", "workshop").":");
workshop_print_upload_form($workshop);
}
/****************** teacher's view - display admin page (current phase options) ************/
elseif ($action == 'teachersview') {
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
/// Check to see if groups are being used in this workshop
/// and if so, set $currentgroup to reflect the current group
$changegroup = isset($_GET['group']) ? $_GET['group'] : -1; // Group change requested?
$groupmode = groupmode($course, $cm); // Groups are being used?
$currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
/// Allow the teacher to change groups (for this session)
if ($groupmode) {
if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
print_group_menu($groups, $groupmode, $currentgroup, "view.php?id=$cm->id");
}
}
print_heading_with_help(get_string("managingassignment", "workshop"), "managing2", "workshop");
workshop_print_assignment_info($workshop);
if ($workshop->wtype < 2) {
$tabs->names = array("1. ".get_string("phase1", "workshop"),
"2. ".get_string("phase2", "workshop", $course->student),
"3. ".get_string("phase5", "workshop"));
$tabs->urls = array("view.php?id=$cm->id&action=setupassignment",
"view.php?id=$cm->id&action=allowsubmissions",
"view.php?id=$cm->id&action=makefinalgradesavailable");
} else {
$tabs->names = array("1. ".get_string("phase1", "workshop"),
"2. ".get_string("phase2", "workshop", $course->student),
"3. ".get_string("phase3", "workshop", $course->student),
"4. ".get_string("phase4", "workshop", $course->student),
"5. ".get_string("phase5", "workshop"));
$tabs->urls = array("view.php?id=$cm->id&action=setupassignment",
"view.php?id=$cm->id&action=allowsubmissions",
"view.php?id=$cm->id&action=allowboth",
"view.php?id=$cm->id&action=allowassessments",
"view.php?id=$cm->id&action=makefinalgradesavailable");
}
if ($workshop->phase) { // phase 1 or more
$tabs->highlight = $workshop->phase - 1;
} else {
$tabs->highlight = 0; // phase is zero
}
workshop_print_tabbed_heading($tabs);
echo "<center>\n";
switch ($workshop->phase) {
case 0:
case 1: // set up assignment
if ($workshop->nelements) {
echo "<p><b><a href=\"assessments.php?id=$cm->id&action=editelements\">".
get_string("amendassessmentelements", "workshop")."</a></b> \n";
helpbutton("elements", get_string("amendassessmentelements", "workshop"), "workshop");
}
if ($workshop->ntassessments) {
// if teacher examples show submission and assessment links
echo "<p><b><a href=\"view.php?id=$cm->id&action=submitexample\">".
get_string("submitexampleassignment", "workshop")."</a></b> \n";
helpbutton("submissionofexamples", get_string("submitexampleassignment", "workshop"),
"workshop");
echo "<p><b><a href=\"submissions.php?id=$cm->id&action=listforassessmentteacher\">".
get_string("teachersubmissionsforassessment", "workshop",
workshop_count_teacher_submissions_for_assessment($workshop, $USER)).
"</a></b> \n";
helpbutton("assessmentofexamples", get_string("teachersubmissionsforassessment",
"workshop"), "workshop");
}
break;
case 2: // submissions and assessments
case 3:
case 4:
if ($workshop->ntassessments) { // if teacher examples show student assessments link
if ($n = workshop_count_teacher_submissions_for_assessment($workshop, $USER)) {
echo "<p><b><a href=\"submissions.php?id=$cm->id&action=listforassessmentteacher\">".
get_string("teachersubmissionsforassessment", "workshop", $n)."</a></b> \n";
helpbutton("assessmentofexamples", get_string("teachersubmissionsforassessment",
"workshop"), "workshop");
}
}
if ($workshop->wtype) {
echo "<p><b><a href=\"assessments.php?id=$cm->id&action=gradeallassessments\">".
get_string("ungradedassessments", "workshop",
workshop_count_ungraded_assessments($workshop))."</a></b> \n";
helpbutton("ungradedassessments",
get_string("ungradedassessments", "workshop"), "workshop");
}
echo "<p><b><a href=\"submissions.php?id=$cm->id&action=listforassessmentstudent\">".
get_string("studentsubmissionsforassessment", "workshop",
workshop_count_student_submissions_for_assessment($workshop, $USER))."</a></b> \n";
helpbutton("gradingsubmissions",
get_string("studentsubmissionsforassessment", "workshop"), "workshop");
break;
case 5: // Show "Final" Grades
if ($workshop->ntassessments) { // if teacher examples show student assessments link
if ($n = workshop_count_teacher_submissions_for_assessment($workshop, $USER)) {
echo "<p><b><a href=\"submissions.php?id=$cm->id&action=listforassessmentteacher\">".
get_string("teachersubmissionsforassessment", "workshop", $n)."</a></b> \n";
helpbutton("assessmentofexamples", get_string("teachersubmissionsforassessment",
"workshop"), "workshop");
}
}
if ($workshop->wtype) {
echo "<p><b><a href=\"assessments.php?id=$cm->id&action=gradeallassessments\">".
get_string("ungradedassessments", "workshop",
workshop_count_ungraded_assessments($workshop))."</a></b> \n";
helpbutton("ungradedassessments", get_string("ungradedassessments", "workshop"), "workshop");
}
echo "<p><b><a href=\"submissions.php?id=$cm->id&action=listforassessmentstudent\">".
get_string("studentsubmissionsforassessment", "workshop",
workshop_count_student_submissions_for_assessment($workshop, $USER))."</a></b> \n";
helpbutton("gradingsubmissions",
get_string("studentsubmissionsforassessment", "workshop"), "workshop");
print_heading("<a href=\"submissions.php?id=$cm->id&action=displayfinalgrades\">".
get_string("displayoffinalgrades", "workshop")."</a>");
}
print_heading("<a href=\"submissions.php?id=$cm->id&action=adminlist\">".
get_string("administration")."</a>");
}
/*************** no man's land **************************************/
else {
error("Fatal Error: Unknown Action: ".$action."\n");
}
print_footer($course);
?>