Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / workshop / assessments.php
blob7bb8e9743325ac3c3293a199236ebd48e1d3c905
1 <?php // $Id$
3 /*************************************************
4 ACTIONS handled are:
6 addcomment
7 addstockcomment
8 confirmdelete
9 delete
10 adminlist
11 agreeassessment
12 displaygradingform
13 editcomment
14 editelements (teachers only)
15 gradeallassessments (teachers only)
16 gradeassessment (teachers only)
17 insertcomment
18 insertelements (for teachers)
19 listungradedstudentsubmissions (for teachers)
20 listungradedteachersubmissions (for teachers)
21 listteachersubmissions
22 regradestudentassessments (for teachers)
23 updateassessment
24 updatecomment
25 updategrading
27 ************************************************/
29 require("../../config.php");
30 require("lib.php");
31 require("locallib.php");
33 $action = required_param('action', PARAM_ALPHA);
34 $id = optional_param('id', 0, PARAM_INT); // Course Module ID
35 $wid = optional_param('wid', 0, PARAM_INT); // Workshop ID
36 $aid = optional_param('aid', 0, PARAM_INT);
37 $userid = optional_param('userid', 0, PARAM_INT);
38 $cid = optional_param('cid', 0, PARAM_INT ); // comment id
39 $sid = optional_param('sid', 0, PARAM_INT); // submission id
40 $elementno = optional_param('elementno', -1, PARAM_INT);
41 $stockcommentid = optional_param('stockcommentid', 0, PARAM_INT);
43 // get some useful stuff...
44 if ($id) {
45 if (! $cm = get_coursemodule_from_id('workshop', $id)) {
46 error("Course Module ID was incorrect");
48 if (! $workshop = get_record("workshop", "id", $cm->instance)) {
49 error("Course module is incorrect");
51 } else if ($wid) {
52 if (! $workshop = get_record("workshop", "id", $wid)) {
53 error("Workshop id is incorrect");
55 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id, $workshop->course)) {
56 error("No coursemodule found");
58 } else {
59 error("No id given");
61 if (! $course = get_record("course", "id", $cm->course)) {
62 error("Course is misconfigured");
65 require_login($course->id, false, $cm);
66 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
68 $strworkshops = get_string("modulenameplural", "workshop");
69 $strworkshop = get_string("modulename", "workshop");
70 $strassessments = get_string("assessments", "workshop");
72 // ... print the header and...
73 $navigation = build_navigation($strassessments, $cm);
74 print_header_simple(format_string($workshop->name), "", $navigation,
75 "", "", true);
77 /*************** add comment to assessment (by author, assessor or teacher) ***************************/
78 if ($action == 'addcomment') {
80 print_heading_with_help(get_string("addacomment", "workshop"), "addingacomment", "workshop");
81 // get assessment record
82 if (!$assessmentid = $aid) { // comes from link or hidden form variable
83 error("Assessment id not given");
85 $assessment = get_record("workshop_assessments", "id", $assessmentid);
86 if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) {
87 error("Submission not found");
90 <form id="commentform" action="assessments.php" method="post">
91 <input type="hidden" name="action" value="insertcomment" />
92 <input type="hidden" name="id" value="<?php echo $cm->id ?>" />
93 <input type="hidden" name="aid" value="<?php echo $aid ?>" />
94 <div class="boxaligncenter">
95 <table cellpadding="5" border="1">
96 <?php
98 // now get the comment
99 echo "<tr valign=\"top\">\n";
101 echo " <td align=\"right\"><b>". get_string("comment", "workshop").":</b></td>\n";
103 echo " <td>\n";
105 echo " <textarea name=\"comments\" rows=\"5\" cols=\"75\">\n";
106 echo "</textarea>\n";
108 echo " </td></tr></table>\n";
109 echo "<input type=\"submit\" value=\"".get_string("savemycomment", "workshop")."\" />\n";
110 echo "</div></form>\n";
111 echo "<div style=\"text-align:center\"><b>".get_string("assessment", "workshop"). "</b></div>\n";
112 workshop_print_assessment($workshop, $assessment);
116 /*************** add stock comment (by teacher ) ***************************/
117 elseif ($action == 'addstockcomment') {
119 if (empty($aid) or ($elementno<0)) {
120 error("Workshop Assessment ID and/or Element Number missing");
123 require_capability('mod/workshop:manage', $context);
125 if (!$assessment = get_record("workshop_assessments", "id", $aid)) {
126 error("workshop assessment is misconfigured");
128 $form = data_submitted('nomatch'); //Nomatch because we can come from assess.php
130 // store the comment in the stock comments table
131 if ($elementno == 99) { // it's the general comment
132 $form->feedback_99 = $form->generalcomment;
134 $comment->workshopid = $workshop->id;
135 $comment->elementno = $elementno;
136 $comment->comments = clean_param($form->{"feedback_$elementno"}, PARAM_CLEAN);
137 if (!(trim($comment->comments))) {
138 // no comment given - just redisplay assessment form
139 workshop_print_assessment($workshop, $assessment, true, true, $form->returnto);
140 print_footer($course);
141 exit();
144 if (!$element->id = insert_record("workshop_stockcomments", $comment)) {
145 error("Could not insert comment into comment bank");
148 // now upate the assessment (just the elements, the assessment itself is not updated)
150 // first get the assignment elements for maxscores and weights...
151 $elementsraw = get_records("workshop_elements", "workshopid", $workshop->id, "elementno ASC");
152 if (count($elementsraw) < $workshop->nelements) {
153 print_string("noteonassignmentelements", "workshop");
155 if ($elementsraw) {
156 foreach ($elementsraw as $element) {
157 $elements[] = $element; // to renumber index 0,1,2...
159 } else {
160 $elements = null;
163 $timenow = time();
164 // don't fiddle about, delete all the old and add the new!
165 delete_records("workshop_grades", "assessmentid", $assessment->id);
168 //determine what kind of grading we have
169 switch ($workshop->gradingstrategy) {
170 case 0: // no grading
171 // Insert all the elements that contain something
172 for ($i = 0; $i < $workshop->nelements; $i++) {
173 unset($element);
174 $element->workshopid = $workshop->id;
175 $element->assessmentid = $assessment->id;
176 $element->elementno = $i;
177 $element->feedback = clean_param($form->{"feedback_$i"}, PARAM_CLEAN);
178 if (!$element->id = insert_record("workshop_grades", $element)) {
179 error("Could not insert workshop grade!");
182 $grade = 0; // set to satisfy save to db
183 break;
185 case 1: // accumulative grading
186 // Insert all the elements that contain something
187 foreach ($form->grade as $key => $thegrade) {
188 unset($element);
189 $element->workshopid = $workshop->id;
190 $element->assessmentid = $assessment->id;
191 $element->elementno = clean_param($key, PARAM_INT);
192 $element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
193 $element->grade = $thegrade;
194 if (!$element->id = insert_record("workshop_grades", $element)) {
195 error("Could not insert workshop grade!");
198 // now work out the grade...
199 $rawgrade=0;
200 $totalweight=0;
201 foreach ($form->grade as $key => $grade) {
202 $maxscore = $elements[$key]->maxscore;
203 $weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
204 if ($weight > 0) {
205 $totalweight += $weight;
207 $rawgrade += ($grade / $maxscore) * $weight;
208 // echo "\$key, \$maxscore, \$weight, \$totalweight, \$grade, \$rawgrade : $key, $maxscore, $weight, $totalweight, $grade, $rawgrade<br />";
210 $grade = 100.0 * ($rawgrade / $totalweight);
211 break;
213 case 2: // error banded graded
214 // Insert all the elements that contain something
215 $error = 0.0;
216 for ($i =0; $i < $workshop->nelements; $i++) {
217 unset($element);
218 $element->workshopid = $workshop->id;
219 $element->assessmentid = $assessment->id;
220 $element->elementno = $i;
221 $element->feedback = clean_param($form->{"feedback_$i"}, PARAM_CLEAN);
222 $element->grade = $form->grade[$i];
223 if (!$element->id = insert_record("workshop_grades", $element)) {
224 error("Could not insert workshop grade!");
226 if (empty($form->grade[$i])){
227 $error += $WORKSHOP_EWEIGHTS[$elements[$i]->weight];
230 // now save the adjustment
231 unset($element);
232 $i = $workshop->nelements;
233 $element->workshopid = $workshop->id;
234 $element->assessmentid = $assessment->id;
235 $element->elementno = $i;
236 $element->grade = $form->grade[$i];
237 if (!$element->id = insert_record("workshop_grades", $element)) {
238 error("Could not insert workshop grade!");
240 $grade = ($elements[intval($error + 0.5)]->maxscore + $form->grade[$i]) * 100 / $workshop->grade;
241 // do sanity check
242 if ($grade < 0) {
243 $grade = 0;
244 } elseif ($grade > 100) {
245 $grade = 100;
247 echo "<b>".get_string("weightederrorcount", "workshop", intval($error + 0.5))."</b>\n";
248 break;
250 case 3: // criteria grading
251 // save in the selected criteria value in element zero,
252 unset($element);
253 $element->workshopid = $workshop->id;
254 $element->assessmentid = $assessment->id;
255 $element->elementno = 0;
256 $element->grade = $form->grade[0];
257 if (!$element->id = insert_record("workshop_grades", $element)) {
258 error("Could not insert workshop grade!");
260 // now save the adjustment in element one
261 unset($element);
262 $element->workshopid = $workshop->id;
263 $element->assessmentid = $assessment->id;
264 $element->elementno = 1;
265 $element->grade = $form->grade[1];
266 if (!$element->id = insert_record("workshop_grades", $element)) {
267 error("Could not insert workshop grade!");
269 $grade = ($elements[$form->grade[0]]->maxscore + $form->grade[1]);
270 break;
272 case 4: // rubric grading (identical to accumulative grading)
273 // Insert all the elements that contain something
274 foreach ($form->grade as $key => $thegrade) {
275 unset($element);
276 $element->workshopid = $workshop->id;
277 $element->assessmentid = $assessment->id;
278 $element->elementno = clean_param($key, PARAM_INT);
279 $element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
280 $element->grade = $thegrade;
281 if (!$element->id = insert_record("workshop_grades", $element)) {
282 error("Could not insert workshop grade!");
285 // now work out the grade...
286 $rawgrade=0;
287 $totalweight=0;
288 foreach ($form->grade as $key => $grade) {
289 $maxscore = $elements[$key]->maxscore;
290 $weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
291 if ($weight > 0) {
292 $totalweight += $weight;
294 $rawgrade += ($grade / $maxscore) * $weight;
296 $grade = 100.0 * ($rawgrade / $totalweight);
297 break;
299 } // end of switch
302 // any comment?
303 if (!empty($form->generalcomment)) { // update the object (no need to update the db record)
304 $assessment->generalcomment = clean_param($form->generalcomment, PARAM_CLEAN);
307 // redisplay form, going back to original returnto address
308 workshop_print_assessment($workshop, $assessment, true, true, $form->returnto);
310 // add_to_log($course->id, "workshop", "assess", "viewassessment.php?id=$cm->id&amp;aid=$assessment->id", "$assessment->id", "$cm->id");
315 /******************* confirm delete ************************************/
316 elseif ($action == 'confirmdelete' ) {
318 if (empty($aid)) {
319 error("Confirm delete: assessment id missing");
322 notice_yesno(get_string("confirmdeletionofthisitem","workshop", get_string("assessment", "workshop")),
323 "assessments.php?action=delete&amp;id=$cm->id&amp;aid=$aid", "submissions.php?action=adminlist&amp;id=$cm->id");
327 /******************* delete ************************************/
328 elseif ($action == 'delete' ) {
330 if (empty($aid)) {
331 error("Delete: submission id missing");
334 print_string("deleting", "workshop");
335 // first delete all the associated records...
336 delete_records("workshop_comments", "assessmentid", $aid);
337 delete_records("workshop_grades", "assessmentid", $aid);
338 // ...now delete the assessment...
339 delete_records("workshop_assessments", "id", $aid);
341 print_continue("view.php?id=$cm->id");
345 /*********************** admin list of asssessments (of a submission) (by teachers)**************/
346 elseif ($action == 'adminlist') {
348 require_capability('mod/workshop:manage', $context);
350 if (empty($sid)) {
351 error ("Workshop asssessments: adminlist called with no sid");
353 $submission = get_record("workshop_submissions", "id", $sid);
354 workshop_print_assessments_for_admin($workshop, $submission);
355 print_continue("submissions.php?action=adminlist&amp;id=$cm->id");
359 /*********************** admin list of asssessments by a student (used by teachers only )******************/
360 elseif ($action == 'adminlistbystudent') {
362 require_capability('mod/workshop:manage', $context);
364 if (empty($userid)) {
365 error ("Workshop asssessments: adminlistbystudent called with no userid");
367 $user = get_record("user", "id", $userid);
368 workshop_print_assessments_by_user_for_admin($workshop, $user);
369 print_continue("submissions.php?action=adminlist&amp;id=$cm->id");
373 /*************** agree (to) assessment (by student) ***************************/
374 elseif ($action == 'agreeassessment') {
375 $timenow = time();
376 // assessment id comes from link or hidden form variable
377 if (!$assessment = get_record("workshop_assessments", "id", $aid)) {
378 error("Assessment : agree assessment failed");
380 //save time of agreement
381 set_field("workshop_assessments", "timeagreed", $timenow, "id", $assessment->id);
382 echo "<div style=\"text-align:center\"><b>".get_string("savedok", "workshop")."</b></div><br />\n";
384 add_to_log($course->id, "workshop", "agree", "viewassessment.php?id=$cm->id&amp;aid=$assessment->id", "$assessment->id");
385 print_continue("view.php?id=$cm->id");
390 /*************** display grading form (viewed by student) *********************************/
391 elseif ($action == 'displaygradingform') {
393 print_heading_with_help(get_string("specimenassessmentform", "workshop"), "specimen", "workshop");
395 workshop_print_assessment($workshop); // called with no assessment
396 print_continue("view.php?id=$cm->id");
400 /*************** edit comment on assessment (by author, assessor or teacher) ***************************/
401 elseif ($action == 'editcomment') {
403 print_heading_with_help(get_string("editacomment", "workshop"), "editingacomment", "workshop");
404 // get the comment record...
405 if (!$comment = get_record("workshop_comments", "id", $cid)) {
406 error("Edit Comment: Comment not found");
408 if (!$assessment = get_record("workshop_assessments", "id", $comment->assessmentid)) {
409 error("Edit Comment: Assessment not found");
411 if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) {
412 error("Edit Comment: Submission not found");
415 <form id="gradingform" action="assessments.php" method="post">
416 <input type="hidden" name="action" value="updatecomment" />
417 <input type="hidden" name="id" value="<?php echo $cm->id ?>" />
418 <input type="hidden" name="cid" value="<?php echo $cid ?>" />
419 <div class="boxaligncenter">
420 <table cellpadding="5" border="1">
421 <?php
423 // now show the comment
424 echo "<tr valign=\"top\">\n";
425 echo " <td align=\"right\"><b>". get_string("comment", "workshop").":</b></td>\n";
426 echo " <td>\n";
427 echo " <textarea name=\"comments\" rows=\"5\" cols=\"75\">\n";
428 if (isset($comment->comments)) {
429 echo $comment->comments;
431 echo " </textarea>\n";
432 echo " </td></tr></table>\n";
433 echo "<input type=\"submit\" value=\"".get_string("savemycomment", "workshop")."\" />\n";
434 echo "</div></form>\n";
435 workshop_print_assessment($workshop, $assessment);
439 /*********************** edit assessment elements (for teachers) ***********************/
440 elseif ($action == 'editelements') {
442 require_capability('mod/workshop:manage', $context);
444 $count = count_records("workshop_grades", "workshopid", $workshop->id);
445 if ($count) {
446 notify(get_string("warningonamendingelements", "workshop"));
448 // set up heading, form and table
449 print_heading_with_help(get_string("editingassessmentelements", "workshop"), "elements", "workshop");
451 <form id="form" method="post" action="assessments.php">
452 <input type="hidden" name="id" value="<?php echo $cm->id ?>" />
453 <input type="hidden" name="action" value="insertelements" />
454 <div class="boxaligncenter"><table cellpadding="5" border="1">
455 <?php
457 // get existing elements, if none set up appropriate default ones
458 if ($elementsraw = get_records("workshop_elements", "workshopid", $workshop->id, "elementno ASC" )) {
459 foreach ($elementsraw as $element) {
460 $elements[] = $element; // to renumber index 0,1,2...
463 // check for missing elements (this happens either the first time round or when the number of elements is icreased)
464 for ($i=0; $i<$workshop->nelements; $i++) {
465 if (!isset($elements[$i])) {
466 $elements[$i]->description = '';
467 $elements[$i]->scale =0;
468 $elements[$i]->maxscore = 0;
469 $elements[$i]->weight = 11;
473 switch ($workshop->gradingstrategy) {
474 case 0: // no grading
475 for ($i=0; $i<$workshop->nelements; $i++) {
476 $iplus1 = $i+1;
477 echo "<tr valign=\"top\">\n";
478 echo " <td align=\"right\"><b>". get_string("element","workshop")." $iplus1:</b></td>\n";
479 echo "<td><textarea name=\"description[]\" rows=\"3\" cols=\"75\">".$elements[$i]->description."</textarea>\n";
480 echo " </td></tr>\n";
481 echo "<tr valign=\"top\">\n";
482 echo " <td colspan=\"2\" class=\"workshopassessmentheading\">&nbsp;</td>\n";
483 echo "</tr>\n";
485 break;
487 case 1: // accumulative grading
488 // set up scales name
489 foreach ($WORKSHOP_SCALES as $KEY => $SCALE) {
490 $SCALES[] = $SCALE['name'];
492 for ($i=0; $i<$workshop->nelements; $i++) {
493 $iplus1 = $i+1;
494 echo "<tr valign=\"top\">\n";
495 echo " <td align=\"right\"><b>". get_string("element","workshop")." $iplus1:</b></td>\n";
496 echo "<td><textarea name=\"description[]\" rows=\"3\" cols=\"75\">".$elements[$i]->description."</textarea>\n";
497 echo " </td></tr>\n";
498 echo "<tr valign=\"top\">\n";
499 echo " <td align=\"right\"><b>". get_string("typeofscale", "workshop"). ":</b></td>\n";
500 echo "<td valign=\"top\">\n";
501 choose_from_menu($SCALES, "scale[]", $elements[$i]->scale, "");
502 if ($elements[$i]->weight == '') { // not set
503 $elements[$i]->weight = 11; // unity
505 echo "</td></tr>\n";
506 echo "<tr valign=\"top\"><td align=\"right\"><b>".get_string("elementweight", "workshop").":</b></td><td>\n";
507 workshop_choose_from_menu($WORKSHOP_EWEIGHTS, "weight[]", $elements[$i]->weight, "");
508 echo " </td>\n";
509 echo "</tr>\n";
510 echo "<tr valign=\"top\">\n";
511 echo " <td colspan=\"2\" class=\"workshopassessmentheading\">&nbsp;</td>\n";
512 echo "</tr>\n";
514 break;
516 case 2: // error banded grading
517 for ($i=0; $i<$workshop->nelements; $i++) {
518 $iplus1 = $i+1;
519 echo "<tr valign=\"top\">\n";
520 echo " <td align=\"right\"><b>". get_string("element","workshop")." $iplus1:</b></td>\n";
521 echo "<td><textarea name=\"description[$i]\" rows=\"3\" cols=\"75\">".$elements[$i]->description."</textarea>\n";
522 echo " </td></tr>\n";
523 if ($elements[$i]->weight == '') { // not set
524 $elements[$i]->weight = 11; // unity
526 echo "</tr>\n";
527 echo "<tr valign=\"top\"><td align=\"right\"><b>".get_string("elementweight", "workshop").":</b></td><td>\n";
528 workshop_choose_from_menu($WORKSHOP_EWEIGHTS, "weight[]", $elements[$i]->weight, "");
529 echo " </td>\n";
530 echo "</tr>\n";
531 echo "<tr valign=\"top\">\n";
532 echo " <td colspan=\"2\" class=\"workshopassessmentheading\">&nbsp;</td>\n";
533 echo "</tr>\n";
535 echo "</div></table><br />\n";
536 echo "<div style=\"text-align:center\"><b>".get_string("gradetable","workshop")."</b></div>\n";
537 echo "<div class=\"boxaligncenter\"><table cellpadding=\"5\" border=\"1\"><tr><td align=\"CENTER\">".
538 get_string("numberofnegativeresponses", "workshop");
539 echo "</td><td>". get_string("suggestedgrade", "workshop")."</td></tr>\n";
540 for ($j = $workshop->grade; $j >= 0; $j--) {
541 $numbers[$j] = $j;
543 for ($i=0; $i<=$workshop->nelements; $i++) {
544 echo "<tr><td align=\"CENTER\">$i</td><td align=\"CENTER\">";
545 if (!isset($elements[$i])) { // the "last one" will be!
546 $elements[$i]->description = "";
547 $elements[$i]->maxscore = 0;
549 choose_from_menu($numbers, "maxscore[$i]", $elements[$i]->maxscore, "");
550 echo "</td></tr>\n";
552 echo "</table></div>\n";
553 break;
555 case 3: // criterion grading
556 for ($j = 100; $j >= 0; $j--) {
557 $numbers[$j] = $j;
559 for ($i=0; $i<$workshop->nelements; $i++) {
560 $iplus1 = $i+1;
561 echo "<tr valign=\"top\">\n";
562 echo " <td align=\"right\"><b>". get_string("criterion","workshop")." $iplus1:</b></td>\n";
563 echo "<td><textarea name=\"description[$i]\" rows=\"3\" cols=\"75\">".$elements[$i]->description."</textarea>\n";
564 echo " </td></tr>\n";
565 echo "<tr><td><b>". get_string("suggestedgrade", "workshop").":</b></td><td>\n";
566 choose_from_menu($numbers, "maxscore[$i]", $elements[$i]->maxscore, "");
567 echo "</td></tr>\n";
568 echo "<tr valign=\"top\">\n";
569 echo " <td colspan=\"2\" class=\"workshopassessmentheading\">&nbsp;</td>\n";
570 echo "</tr>\n";
572 break;
574 case 4: // rubric
575 for ($j = 100; $j >= 0; $j--) {
576 $numbers[$j] = $j;
578 if ($rubricsraw = get_records("workshop_rubrics", "workshopid", $workshop->id)) {
579 foreach ($rubricsraw as $rubric) {
580 $rubrics[$rubric->elementno][$rubric->rubricno] = $rubric->description; // reindex 0,1,2...
583 for ($i=0; $i<$workshop->nelements; $i++) {
584 $iplus1 = $i+1;
585 echo "<tr valign=\"top\">\n";
586 echo " <td align=\"right\"><b>". get_string("element","workshop")." $iplus1:</b></td>\n";
587 echo "<td><textarea name=\"description[$i]\" rows=\"3\" cols=\"75\">".$elements[$i]->description."</textarea>\n";
588 echo " </td></tr>\n";
589 echo "<tr valign=\"top\"><td align=\"right\"><b>".get_string("elementweight", "workshop").":</b></td><td>\n";
590 workshop_choose_from_menu($WORKSHOP_EWEIGHTS, "weight[]", $elements[$i]->weight, "");
591 echo " </td>\n";
592 echo "</tr>\n";
594 for ($j=0; $j<5; $j++) {
595 $jplus1 = $j+1;
596 if (empty($rubrics[$i][$j])) {
597 $rubrics[$i][$j] = "";
599 echo "<tr valign=\"top\">\n";
600 echo " <td align=\"right\"><b>". get_string("grade","workshop")." $j:</b></td>\n";
601 echo "<td><textarea name=\"rubric[$i][$j]\" rows=\"3\" cols=\"75\">".$rubrics[$i][$j]."</textarea>\n";
602 echo " </td></tr>\n";
604 echo "<tr valign=\"top\">\n";
605 echo " <td colspan=\"2\" class=\"workshopassessmentheading\">&nbsp;</td>\n";
606 echo "</tr>\n";
608 break;
610 // close table and form
613 </table><br />
614 <input type="submit" value="<?php print_string("savechanges") ?>" />
615 <input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
616 </div>
617 </form>
618 <?php
622 /*************** grade all assessments (by teacher) ***************************/
623 elseif ($action == 'gradeallassessments') {
625 require_capability('mod/workshop:manage', $context);
627 print_heading(get_string("gradingallassessments", "workshop"));
628 workshop_grade_assessments($workshop);
629 print_continue("view.php?id=$cm->id");
633 /*************** grade (student's) assessment (by teacher) ***************************/
634 elseif ($action == 'gradeassessment') {
636 require_capability('mod/workshop:manage', $context);
638 print_heading_with_help(get_string("gradeassessment", "workshop"), "gradingassessments", "workshop");
639 // get assessment record
640 if (!$assessmentid = $aid) {
641 error("Assessment id not given");
643 $assessment = get_record("workshop_assessments", "id", $assessmentid);
644 if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) {
645 error("Submission not found");
647 // get the teacher's assessment first
648 if ($teachersassessment = workshop_get_submission_assessment($submission, $USER)) {
649 echo "<div style=\"text-align:center\"><b>".get_string("teacherassessments", "workshop", $course->teacher)."</b></div>\n";
650 workshop_print_assessment($workshop, $teachersassessment);
652 // now the student's assessment (don't allow changes)
653 $user = get_record("user", "id", $assessment->userid);
654 echo "<div style=\"text-align:center\"><b>".get_string("assessmentby", "workshop", $user->firstname." ".$user->lastname)."</b></div>\n";
655 workshop_print_assessment($workshop, $assessment);
657 include('assessment_grading_form.html');
658 die;
662 /*************** insert (new) comment (by author, assessor or teacher) ***************************/
663 elseif ($action == 'insertcomment') {
664 $timenow = time();
666 $form = (object)$_POST;
668 if (!$assessment = get_record("workshop_assessments", "id", $aid)) {
669 error("Unable to insert comment");
671 // save the comment...
672 $comment->workshopid = $workshop->id;
673 $comment->assessmentid = $assessment->id;
674 $comment->userid = $USER->id;
675 $comment->timecreated = $timenow;
676 $comment->comments = clean_param($form->comments, PARAM_CLEAN);
677 if (!$comment->id = insert_record("workshop_comments", $comment)) {
678 error("Could not insert workshop comment!");
681 add_to_log($course->id, "workshop", "comment", "view.php?id=$cm->id", "$comment->id");
683 print_continue("viewassessment.php?id=$cm->id&amp;aid=$assessment->id");
687 /*********************** insert/update assignment elements (for teachers)***********************/
688 elseif ($action == 'insertelements') {
690 require_capability('mod/workshop:manage', $context);
692 $form = data_submitted();
694 // let's not fool around here, dump the junk!
695 delete_records("workshop_elements", "workshopid", $workshop->id);
697 // determine wich type of grading
698 switch ($workshop->gradingstrategy) {
699 case 0: // no grading
700 // Insert all the elements that contain something
701 foreach ($form->description as $key => $description) {
702 if ($description) {
703 unset($element);
704 $element->description = $description;
705 $element->workshopid = $workshop->id;
706 $element->elementno = $key;
707 if (!$element->id = insert_record("workshop_elements", $element)) {
708 error("Could not insert workshop element!");
712 break;
714 case 1: // accumulative grading
715 // Insert all the elements that contain something
716 foreach ($form->description as $key => $description) {
717 if ($description) {
718 unset($element);
719 $element->description = $description;
720 $element->workshopid = $workshop->id;
721 $element->elementno = clean_param($key, PARAM_INT);
722 if (isset($form->scale[$key])) {
723 $element->scale = $form->scale[$key];
724 switch ($WORKSHOP_SCALES[$form->scale[$key]]['type']) {
725 case 'radio' : $element->maxscore = $WORKSHOP_SCALES[$form->scale[$key]]['size'] - 1;
726 break;
727 case 'selection' : $element->maxscore = $WORKSHOP_SCALES[$form->scale[$key]]['size'];
728 break;
731 if (isset($form->weight[$key])) {
732 $element->weight = $form->weight[$key];
734 if (!$element->id = insert_record("workshop_elements", $element)) {
735 error("Could not insert workshop element!");
739 break;
741 case 2: // error banded grading...
742 case 3: // ...and criterion grading
743 // Insert all the elements that contain something, the number of descriptions is one less than the number of grades
744 foreach ($form->maxscore as $key => $themaxscore) {
745 unset($element);
746 $element->workshopid = $workshop->id;
747 $element->elementno = clean_param($key, PARAM_INT);
748 $element->maxscore = $themaxscore;
749 if (isset($form->description[$key])) {
750 $element->description = $form->description[$key];
752 if (isset($form->weight[$key])) {
753 $element->weight = $form->weight[$key];
755 if (!$element->id = insert_record("workshop_elements", $element)) {
756 error("Could not insert workshop element!");
759 break;
761 case 4: // ...and criteria grading
762 // Insert all the elements that contain something
763 foreach ($form->description as $key => $description) {
764 unset($element);
765 $element->workshopid = $workshop->id;
766 $element->elementno = clean_param($key, PARAM_INT);
767 $element->description = $description;
768 $element->weight = $form->weight[$key];
769 for ($j=0;$j<5;$j++) {
770 if (empty($form->rubric[$key][$j]))
771 break;
773 $element->maxscore = $j - 1;
774 if (!$element->id = insert_record("workshop_elements", $element)) {
775 error("Could not insert workshop element!");
778 // let's not fool around here, dump the junk!
779 delete_records("workshop_rubrics", "workshopid", $workshop->id);
780 for ($i=0;$i<$workshop->nelements;$i++) {
781 for ($j=0;$j<5;$j++) {
782 unset($element);
783 if (empty($form->rubric[$i][$j])) { // OK to have an element with fewer than 5 items
784 break;
786 $element->workshopid = $workshop->id;
787 $element->elementno = $i;
788 $element->rubricno = $j;
789 $element->description = $form->rubric[$i][$j];
790 if (!$element->id = insert_record("workshop_rubrics", $element)) {
791 error("Could not insert workshop element!");
795 break;
796 } // end of switch
797 echo "</div>"; // not sure where this one came from MDL-7861
798 redirect("view.php?id=$cm->id", get_string("savedok","workshop"));
802 /*********************** list assessments for grading (Student submissions)(by teachers)***********************/
803 elseif ($action == 'listungradedstudentsubmissions') {
805 require_capability('mod/workshop:manage', $context);
807 workshop_list_ungraded_assessments($workshop, "student");
808 print_continue("view.php?id=$cm->id");
812 /*********************** list assessments for grading (Teacher submissions) (by teachers)***********************/
813 elseif ($action == 'listungradedteachersubmissions') {
815 require_capability('mod/workshop:manage', $context);
817 workshop_list_ungraded_assessments($workshop, "teacher");
818 print_continue("view.php?id=$cm->id");
822 /****************** list teacher submissions ***********************/
823 elseif ($action == 'listteachersubmissions') {
825 workshop_list_teacher_submissions($workshop, $USER);
826 print_continue("view.php?id=$cm->id");
830 /******************* regrade student assessments ************************************/
831 elseif ($action == 'regradestudentassessments' ) {
833 $timenow = time();
834 require_capability('mod/workshop:manage', $context);
835 // get all the submissions...
836 if ($submissions = get_records("workshop_submissions", "workshopid", $workshop->id)) {
837 foreach ($submissions as $submission) {
838 // ...if cold...
839 if (($submission->timecreated + $CFG->maxeditingtime) < $timenow) {
840 // ...clear assessment count so workshop_grade_assessments() can do its thing
841 set_field("workshop_submissions", "nassessments", 0, "id", $submission->id);
845 echo "<pre>";
846 workshop_grade_assessments($workshop);
847 echo '</pre>';
848 print_continue("submissions.php?id=$cm->id&action=adminlist");
852 /*************** remove stock comment (by teacher ) ***************************/
853 elseif ($action == 'removestockcomment') {
855 if (empty($aid) or empty($stockcommentid)) {
856 error("Workshop Assessment id and/or Stock Comment id missing");
859 require_capability('mod/workshop:manage', $context);
861 if (!$assessment = get_record("workshop_assessments", "id", $aid)) {
862 error("workshop assessment is misconfigured");
864 $form = data_submitted('nomatch'); //Nomatch because we can come from assess.php
866 // delete the comment from the stock comments table
867 if (!delete_records("workshop_stockcomments", "id", $stockcommentid)) {
868 error("Could not remove comment from the comment bank");
871 // now upate the assessment (just the elements, the assessment itself is not updated)
873 // first get the assignment elements for maxscores and weights...
874 $elementsraw = get_records("workshop_elements", "workshopid", $workshop->id, "elementno ASC");
875 if (count($elementsraw) < $workshop->nelements) {
876 print_string("noteonassignmentelements", "workshop");
878 if ($elementsraw) {
879 foreach ($elementsraw as $element) {
880 $elements[] = $element; // to renumber index 0,1,2...
882 } else {
883 $elements = null;
886 $timenow = time();
887 // don't fiddle about, delete all the old and add the new!
888 delete_records("workshop_grades", "assessmentid", $assessment->id);
891 //determine what kind of grading we have
892 switch ($workshop->gradingstrategy) {
893 case 0: // no grading
894 // Insert all the elements that contain something
895 for ($i =0; $i < $workshop->nelements; $i++) {
896 unset($element);
897 $element->workshopid = $workshop->id;
898 $element->assessmentid = $assessment->id;
899 $element->elementno = $i;
900 $element->feedback = clean_param($form->{"feedback_$i"}, PARAM_CLEAN);
901 if (!$element->id = insert_record("workshop_grades", $element)) {
902 error("Could not insert workshop grade!");
905 $grade = 0; // set to satisfy save to db
906 break;
908 case 1: // accumulative grading
909 // Insert all the elements that contain something
910 foreach ($form->grade as $key => $thegrade) {
911 unset($element);
912 $element->workshopid = $workshop->id;
913 $element->assessmentid = $assessment->id;
914 $element->elementno = clean_param($key, PARAM_INT);
915 $element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
916 $element->grade = $thegrade;
917 if (!$element->id = insert_record("workshop_grades", $element)) {
918 error("Could not insert workshop grade!");
921 // now work out the grade...
922 $rawgrade=0;
923 $totalweight=0;
924 foreach ($form->grade as $key => $grade) {
925 $maxscore = $elements[$key]->maxscore;
926 $weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
927 if ($weight > 0) {
928 $totalweight += $weight;
930 $rawgrade += ($grade / $maxscore) * $weight;
931 // echo "\$key, \$maxscore, \$weight, \$totalweight, \$grade, \$rawgrade : $key, $maxscore, $weight, $totalweight, $grade, $rawgrade<br />";
933 $grade = 100.0 * ($rawgrade / $totalweight);
934 break;
936 case 2: // error banded graded
937 // Insert all the elements that contain something
938 $error = 0.0;
939 for ($i =0; $i < $workshop->nelements; $i++) {
940 unset($element);
941 $element->workshopid = $workshop->id;
942 $element->assessmentid = $assessment->id;
943 $element->elementno = $i;
944 $element->feedback = clean_param($form->{"feedback_$i"}, PARAM_CLEAN);
945 $element->grade = $form->grade[$i];
946 if (!$element->id = insert_record("workshop_grades", $element)) {
947 error("Could not insert workshop grade!");
949 if (empty($form->grade[$i])){
950 $error += $WORKSHOP_EWEIGHTS[$elements[$i]->weight];
953 // now save the adjustment
954 unset($element);
955 $i = $workshop->nelements;
956 $element->workshopid = $workshop->id;
957 $element->assessmentid = $assessment->id;
958 $element->elementno = $i;
959 $element->grade = $form->grade[$i];
960 if (!$element->id = insert_record("workshop_grades", $element)) {
961 error("Could not insert workshop grade!");
963 $grade = ($elements[intval($error + 0.5)]->maxscore + $form->grade[$i]) * 100 / $workshop->grade;
964 // do sanity check
965 if ($grade < 0) {
966 $grade = 0;
967 } elseif ($grade > 100) {
968 $grade = 100;
970 echo "<b>".get_string("weightederrorcount", "workshop", intval($error + 0.5))."</b>\n";
971 break;
973 case 3: // criteria grading
974 // save in the selected criteria value in element zero,
975 unset($element);
976 $element->workshopid = $workshop->id;
977 $element->assessmentid = $assessment->id;
978 $element->elementno = 0;
979 $element->grade = $form->grade[0];
980 if (!$element->id = insert_record("workshop_grades", $element)) {
981 error("Could not insert workshop grade!");
983 // now save the adjustment in element one
984 unset($element);
985 $element->workshopid = $workshop->id;
986 $element->assessmentid = $assessment->id;
987 $element->elementno = 1;
988 $element->grade = $form->grade[1];
989 if (!$element->id = insert_record("workshop_grades", $element)) {
990 error("Could not insert workshop grade!");
992 $grade = ($elements[$form->grade[0]]->maxscore + $form->grade[1]);
993 break;
995 case 4: // rubric grading (identical to accumulative grading)
996 // Insert all the elements that contain something
997 foreach ($form->grade as $key => $thegrade) {
998 unset($element);
999 $element->workshopid = $workshop->id;
1000 $element->assessmentid = $assessment->id;
1001 $element->elementno = clean_param($key, PARAM_INT);
1002 $element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
1003 $element->grade = $thegrade;
1004 if (!$element->id = insert_record("workshop_grades", $element)) {
1005 error("Could not insert workshop grade!");
1008 // now work out the grade...
1009 $rawgrade=0;
1010 $totalweight=0;
1011 foreach ($form->grade as $key => $grade) {
1012 $maxscore = $elements[$key]->maxscore;
1013 $weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
1014 if ($weight > 0) {
1015 $totalweight += $weight;
1017 $rawgrade += ($grade / $maxscore) * $weight;
1019 $grade = 100.0 * ($rawgrade / $totalweight);
1020 break;
1022 } // end of switch
1025 // any comment?
1026 if (!empty($form->generalcomment)) { // update the object (no need to update the db record)
1027 $assessment->generalcomment = clean_param($form->generalcomment, PARAM_CLEAN);
1030 // redisplay form, going back to original returnto address
1031 workshop_print_assessment($workshop, $assessment, true, true, $form->returnto);
1033 // add_to_log($course->id, "workshop", "assess", "viewassessment.php?id=$cm->id&amp;aid=$assessment->id", "$assessment->id", "$cm->id");
1038 /*************** update assessment (by teacher or student) ***************************/
1039 elseif ($action == 'updateassessment') {
1041 if (empty($aid)) {
1042 error("Workshop Assessment id missing");
1045 if (! $assessment = get_record("workshop_assessments", "id", $aid)) {
1046 error("workshop assessment is misconfigured");
1049 // first get the assignment elements for maxscores and weights...
1050 $elementsraw = get_records("workshop_elements", "workshopid", $workshop->id, "elementno ASC");
1051 if (count($elementsraw) < $workshop->nelements) {
1052 print_string("noteonassignmentelements", "workshop");
1054 if ($elementsraw) {
1055 foreach ($elementsraw as $element) {
1056 $elements[] = $element; // to renumber index 0,1,2...
1058 } else {
1059 $elements = null;
1062 $timenow = time();
1063 // don't fiddle about, delete all the old and add the new!
1064 delete_records("workshop_grades", "assessmentid", $assessment->id);
1066 $form = data_submitted('nomatch'); //Nomatch because we can come from assess.php
1068 //determine what kind of grading we have
1069 switch ($workshop->gradingstrategy) {
1070 case 0: // no grading
1071 // Insert all the elements that contain something
1072 for ($i = 0; $i < $workshop->nelements; $i++) {
1073 unset($element);
1074 $element->workshopid = $workshop->id;
1075 $element->assessmentid = $assessment->id;
1076 $element->elementno = $i;
1077 $element->feedback = clean_param($form->{"feedback_$i"}, PARAM_CLEAN);
1078 if (!$element->id = insert_record("workshop_grades", $element)) {
1079 error("Could not insert workshop grade!");
1082 $grade = 0; // set to satisfy save to db
1083 break;
1085 case 1: // accumulative grading
1086 // Insert all the elements that contain something
1087 foreach ($form->grade as $key => $thegrade) {
1088 unset($element);
1089 $element->workshopid = $workshop->id;
1090 $element->assessmentid = $assessment->id;
1091 $element->elementno = $key;
1092 $element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
1093 $element->grade = $thegrade;
1094 if (!$element->id = insert_record("workshop_grades", $element)) {
1095 error("Could not insert workshop grade!");
1098 // now work out the grade...
1099 $rawgrade=0;
1100 $totalweight=0;
1101 foreach ($form->grade as $key => $grade) {
1102 $maxscore = $elements[$key]->maxscore;
1103 $weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
1104 if ($weight > 0) {
1105 $totalweight += $weight;
1107 $rawgrade += ($grade / $maxscore) * $weight;
1108 // echo "\$key, \$maxscore, \$weight, \$totalweight, \$grade, \$rawgrade : $key, $maxscore, $weight, $totalweight, $grade, $rawgrade<br />";
1110 $grade = 100.0 * ($rawgrade / $totalweight);
1111 break;
1113 case 2: // error banded graded
1114 // Insert all the elements that contain something
1115 $error = 0.0;
1116 for ($i =0; $i < $workshop->nelements; $i++) {
1117 unset($element);
1118 $element->workshopid = $workshop->id;
1119 $element->assessmentid = $assessment->id;
1120 $element->elementno = $i;
1121 $element->feedback = $form->{"feedback_$i"};
1122 $element->grade = clean_param($form->grade[$i], PARAM_CLEAN);
1123 if (!$element->id = insert_record("workshop_grades", $element)) {
1124 error("Could not insert workshop grade!");
1126 if (empty($form->grade[$i])){
1127 $error += $WORKSHOP_EWEIGHTS[$elements[$i]->weight];
1130 // now save the adjustment
1131 unset($element);
1132 $i = $workshop->nelements;
1133 $element->workshopid = $workshop->id;
1134 $element->assessmentid = $assessment->id;
1135 $element->elementno = $i;
1136 $element->grade = $form->grade[$i];
1137 if (!$element->id = insert_record("workshop_grades", $element)) {
1138 error("Could not insert workshop grade!");
1140 $grade = ($elements[intval($error + 0.5)]->maxscore + $form->grade[$i]) * 100 / $workshop->grade;
1141 // do sanity check
1142 if ($grade < 0) {
1143 $grade = 0;
1144 } elseif ($grade > 100) {
1145 $grade = 100;
1147 echo "<b>".get_string("weightederrorcount", "workshop", intval($error + 0.5))."</b>\n";
1148 break;
1150 case 3: // criteria grading
1151 // save in the selected criteria value in element zero,
1152 unset($element);
1153 $element->workshopid = $workshop->id;
1154 $element->assessmentid = $assessment->id;
1155 $element->elementno = 0;
1156 $element->grade = $form->grade[0];
1157 if (!$element->id = insert_record("workshop_grades", $element)) {
1158 error("Could not insert workshop grade!");
1160 // now save the adjustment in element one
1161 unset($element);
1162 $element->workshopid = $workshop->id;
1163 $element->assessmentid = $assessment->id;
1164 $element->elementno = 1;
1165 $element->grade = $form->grade[1];
1166 if (!$element->id = insert_record("workshop_grades", $element)) {
1167 error("Could not insert workshop grade!");
1169 $grade = ($elements[$form->grade[0]]->maxscore + $form->grade[1]);
1170 break;
1172 case 4: // rubric grading (identical to accumulative grading)
1173 // Insert all the elements that contain something
1174 foreach ($form->grade as $key => $thegrade) {
1175 unset($element);
1176 $element->workshopid = $workshop->id;
1177 $element->assessmentid = $assessment->id;
1178 $element->elementno = clean_param($key, PARAM_INT);
1179 $element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
1180 $element->grade = $thegrade;
1181 if (!$element->id = insert_record("workshop_grades", $element)) {
1182 error("Could not insert workshop grade!");
1185 // now work out the grade...
1186 $rawgrade=0;
1187 $totalweight=0;
1188 foreach ($form->grade as $key => $grade) {
1189 $maxscore = $elements[$key]->maxscore;
1190 $weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
1191 if ($weight > 0) {
1192 $totalweight += $weight;
1194 $rawgrade += ($grade / $maxscore) * $weight;
1196 $grade = 100.0 * ($rawgrade / $totalweight);
1197 break;
1199 } // end of switch
1201 // update the time of the assessment record (may be re-edited)...
1202 set_field("workshop_assessments", "timecreated", $timenow, "id", $assessment->id);
1204 if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) {
1205 error ("Updateassessment: submission record not found");
1208 // if the workshop does need peer agreement AND it's self assessment then set timeagreed
1209 if ($workshop->agreeassessments and ($submission->userid == $assessment->userid)) {
1210 set_field("workshop_assessments", "timeagreed", $timenow, "id", $assessment->id);
1213 // set grade...
1214 set_field("workshop_assessments", "grade", $grade, "id", $assessment->id);
1215 // ...and clear the timegraded but set the graddinggrade to maximum, may be reduced subsequently...
1216 set_field("workshop_assessments", "timegraded", 0, "id", $assessment->id);
1217 set_field("workshop_assessments", "gradinggrade", 100, "id", $assessment->id);
1218 // ...and the resubmission flag
1219 set_field("workshop_assessments", "resubmission", 0, "id", $assessment->id);
1221 // if there's examples or peer assessments clear the counter in the submission so that
1222 // all assessments for this submission will be regraded
1223 if ($workshop->ntassessments or $workshop->nsassessments) {
1224 set_field("workshop_submissions", "nassessments", 0, "id", $submission->id);
1225 workshop_grade_assessments($workshop);
1226 } else { // it could be self assessment....
1227 // now see if there's a corresponding assessment so that the gradinggrade can be set
1228 if (workshop_is_teacher($workshop)) {
1229 // see if there's are student assessments, if so set their gradinggrade
1230 if ($assessments = workshop_get_assessments($submission)) {
1231 foreach($assessments as $studentassessment) {
1232 // skip if it's not a student assessment
1233 if (!workshop_is_student($workshop, $studentassessment->userid)) {
1234 continue;
1236 $gradinggrade = workshop_compare_assessments($workshop, $assessment, $studentassessment);
1237 set_field("workshop_assessments", "timegraded", $timenow, "id", $studentassessment->id);
1238 set_field("workshop_assessments", "gradinggrade", $gradinggrade, "id", $studentassessment->id);
1241 } else { //it's a student assessment, see if there's a corresponding teacher's assessment
1242 if ($assessments = workshop_get_assessments($submission)) {
1243 foreach($assessments as $teacherassessment) {
1244 if (workshop_is_teacher($workshop, $teacherassessment->userid)) {
1245 $gradinggrade = workshop_compare_assessments($workshop, $assessment, $teacherassessment);
1246 set_field("workshop_assessments", "timegraded", $timenow, "id", $assessment->id);
1247 set_field("workshop_assessments", "gradinggrade", $gradinggrade, "id", $assessment->id);
1248 break; // only look for the first teacher assessment
1255 // any comment?
1256 if (!empty($form->generalcomment)) {
1257 set_field("workshop_assessments", "generalcomment", clean_param($form->generalcomment, PARAM_CLEAN), "id", $assessment->id);
1260 add_to_log($course->id, "workshop", "assess",
1261 "viewassessment.php?id=$cm->id&amp;aid=$assessment->id", "$assessment->id", "$cm->id");
1263 // set up return address
1264 if (!$returnto = $form->returnto) {
1265 $returnto = "view.php?id=$cm->id";
1268 // show grade if grading strategy is not zero
1269 if ($workshop->gradingstrategy) {
1270 echo "</div>"; // MDL-7861, this is from <div id=page>
1271 redirect($returnto, get_string("thegradeis", "workshop").": ".
1272 number_format($grade * $workshop->grade / 100, 2).
1273 " (".get_string("maximumgrade")." ".number_format($workshop->grade).")");
1275 else {
1276 redirect($returnto);
1282 /****************** update comment (by author, assessor or teacher) ********************/
1283 elseif ($action == 'updatecomment') {
1284 $timenow = time();
1286 $form = (object)$_POST;
1288 // get the comment record...
1289 if (!$comment = get_record("workshop_comments", "id", $_POST['cid'])) {
1290 error("Update to Comment failed");
1292 if (!$assessment = get_record("workshop_assessments", "id", $comment->assessmentid)) {
1293 error("Update Comment: Assessment not found");
1295 //save the comment for the assessment...
1296 if (isset($form->comments)) {
1297 set_field("workshop_comments", "comments", $form->comments, "id", $comment->id);
1298 set_field("workshop_comments", "timecreated", $timenow, "id", $comment->id);
1299 // ..and kick to comment into life (probably not needed but just in case)
1300 set_field("workshop_comments", "mailed", 0, "id", $comment->id);
1301 echo "<centre><b>".get_string("savedok", "workshop")."</b></div><br />\n";
1303 add_to_log($course->id, "workshop", "comment",
1304 "viewassessment.php?id=$cm->id&amp;aid=$assessment->id", "$comment->id");
1307 print_continue("viewassessment.php?id=$cm->id&amp;aid=$assessment->id");
1311 /****************** update grading (by teacher) ***************************/
1312 elseif ($action == 'updategrading') {
1313 $timenow = time();
1315 require_capability('mod/workshop:manage', $context);
1317 $form = (object)$_POST;
1319 if (!$assessment = get_record("workshop_assessments", "id", $_POST['aid'])) {
1320 error("Update Grading failed");
1322 //save the comment and grade for the assessment
1323 if (isset($form->teachercomment)) {
1324 set_field("workshop_assessments", "teachercomment", $form->teachercomment, "id", $assessment->id);
1325 set_field("workshop_assessments", "gradinggrade", $form->gradinggrade, "id", $assessment->id);
1326 set_field("workshop_assessments", "timegraded", $timenow, "id", $assessment->id);
1327 set_field("workshop_assessments", "mailed", 0, "id", $assessment->id);
1328 set_field("workshop_assessments", "teachergraded", 1, "id", $assessment->id);
1329 echo "<centre><b>".get_string("savedok", "workshop")."</b></centre><br />\n";
1331 add_to_log($course->id, "workshop", "grade",
1332 "viewassessment.php?id=$cm->id&amp;aid=$assessment->id", "$assessment->id", "$cm->id");
1334 redirect($form->redirect);
1338 /****************** view all assessments ***********************/
1339 elseif ($action == 'viewallassessments') {
1341 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
1342 error("View All Assessments: submission record not found");
1345 if ($assessments = workshop_get_assessments($submission)) {
1346 foreach ($assessments as $assessment) {
1347 workshop_print_assessment($workshop, $assessment);
1350 // only called from list all submissions
1351 print_continue("submissions.php?action=listallsubmissions&amp;id=$cm->id");
1354 /*************** no man's land **************************************/
1355 else {
1356 error("Fatal Error: Unknown Action: ".$action."\n");
1358 print_footer($course);