adding some strings
[moodle-linuxchix.git] / mod / workshop / assessments.php
blobe6c3249b65e465dd9b68b21c64abb415d3102023
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...
74 $navlinks = array();
75 $navlinks[] = array('name' => $strworkshops, 'link' => "index.php?id=$course->id", 'type' => 'activity');
76 $navlinks[] = array('name' => format_string($workshop->name,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
77 $navlinks[] = array('name' => $strassessments, 'link' => '', 'type' => 'title');
78 $navigation = build_navigation($navlinks);
80 print_header_simple(format_string($workshop->name), "", $navigation,
81 "", "", true);
83 /*************** add comment to assessment (by author, assessor or teacher) ***************************/
84 if ($action == 'addcomment') {
86 print_heading_with_help(get_string("addacomment", "workshop"), "addingacomment", "workshop");
87 // get assessment record
88 if (!$assessmentid = $aid) { // comes from link or hidden form variable
89 error("Assessment id not given");
91 $assessment = get_record("workshop_assessments", "id", $assessmentid);
92 if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) {
93 error("Submission not found");
96 <form id="commentform" action="assessments.php" method="post">
97 <input type="hidden" name="action" value="insertcomment" />
98 <input type="hidden" name="id" value="<?php echo $cm->id ?>" />
99 <input type="hidden" name="aid" value="<?php echo $aid ?>" />
100 <div class="boxaligncenter">
101 <table cellpadding="5" border="1">
102 <?php
104 // now get the comment
105 echo "<tr valign=\"top\">\n";
107 echo " <td align=\"right\"><b>". get_string("comment", "workshop").":</b></td>\n";
109 echo " <td>\n";
111 echo " <textarea name=\"comments\" rows=\"5\" cols=\"75\">\n";
112 echo "</textarea>\n";
114 echo " </td></tr></table>\n";
115 echo "<input type=\"submit\" value=\"".get_string("savemycomment", "workshop")."\" />\n";
116 echo "</div></form>\n";
117 echo "<div style=\"text-align:center\"><b>".get_string("assessment", "workshop"). "</b></div>\n";
118 workshop_print_assessment($workshop, $assessment);
122 /*************** add stock comment (by teacher ) ***************************/
123 elseif ($action == 'addstockcomment') {
125 if (empty($aid) or ($elementno<0)) {
126 error("Workshop Assessment ID and/or Element Number missing");
129 require_capability('mod/workshop:manage', $context);
131 if (!$assessment = get_record("workshop_assessments", "id", $aid)) {
132 error("workshop assessment is misconfigured");
134 $form = data_submitted('nomatch'); //Nomatch because we can come from assess.php
136 // store the comment in the stock comments table
137 if ($elementno == 99) { // it's the general comment
138 $form->feedback_99 = $form->generalcomment;
140 $comment->workshopid = $workshop->id;
141 $comment->elementno = $elementno;
142 $comment->comments = clean_param($form->{"feedback_$elementno"}, PARAM_CLEAN);
143 if (!(trim($comment->comments))) {
144 // no comment given - just redisplay assessment form
145 workshop_print_assessment($workshop, $assessment, true, true, $form->returnto);
146 print_footer($course);
147 exit();
150 if (!$element->id = insert_record("workshop_stockcomments", $comment)) {
151 error("Could not insert comment into comment bank");
154 // now upate the assessment (just the elements, the assessment itself is not updated)
156 // first get the assignment elements for maxscores and weights...
157 $elementsraw = get_records("workshop_elements", "workshopid", $workshop->id, "elementno ASC");
158 if (count($elementsraw) < $workshop->nelements) {
159 print_string("noteonassignmentelements", "workshop");
161 if ($elementsraw) {
162 foreach ($elementsraw as $element) {
163 $elements[] = $element; // to renumber index 0,1,2...
165 } else {
166 $elements = null;
169 $timenow = time();
170 // don't fiddle about, delete all the old and add the new!
171 delete_records("workshop_grades", "assessmentid", $assessment->id);
174 //determine what kind of grading we have
175 switch ($workshop->gradingstrategy) {
176 case 0: // no grading
177 // Insert all the elements that contain something
178 for ($i = 0; $i < $workshop->nelements; $i++) {
179 unset($element);
180 $element->workshopid = $workshop->id;
181 $element->assessmentid = $assessment->id;
182 $element->elementno = $i;
183 $element->feedback = clean_param($form->{"feedback_$i"}, PARAM_CLEAN);
184 if (!$element->id = insert_record("workshop_grades", $element)) {
185 error("Could not insert workshop grade!");
188 $grade = 0; // set to satisfy save to db
189 break;
191 case 1: // accumulative grading
192 // Insert all the elements that contain something
193 foreach ($form->grade as $key => $thegrade) {
194 unset($element);
195 $element->workshopid = $workshop->id;
196 $element->assessmentid = $assessment->id;
197 $element->elementno = clean_param($key, PARAM_INT);
198 $element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
199 $element->grade = $thegrade;
200 if (!$element->id = insert_record("workshop_grades", $element)) {
201 error("Could not insert workshop grade!");
204 // now work out the grade...
205 $rawgrade=0;
206 $totalweight=0;
207 foreach ($form->grade as $key => $grade) {
208 $maxscore = $elements[$key]->maxscore;
209 $weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
210 if ($weight > 0) {
211 $totalweight += $weight;
213 $rawgrade += ($grade / $maxscore) * $weight;
214 // echo "\$key, \$maxscore, \$weight, \$totalweight, \$grade, \$rawgrade : $key, $maxscore, $weight, $totalweight, $grade, $rawgrade<br />";
216 $grade = 100.0 * ($rawgrade / $totalweight);
217 break;
219 case 2: // error banded graded
220 // Insert all the elements that contain something
221 $error = 0.0;
222 for ($i =0; $i < $workshop->nelements; $i++) {
223 unset($element);
224 $element->workshopid = $workshop->id;
225 $element->assessmentid = $assessment->id;
226 $element->elementno = $i;
227 $element->feedback = clean_param($form->{"feedback_$i"}, PARAM_CLEAN);
228 $element->grade = $form->grade[$i];
229 if (!$element->id = insert_record("workshop_grades", $element)) {
230 error("Could not insert workshop grade!");
232 if (empty($form->grade[$i])){
233 $error += $WORKSHOP_EWEIGHTS[$elements[$i]->weight];
236 // now save the adjustment
237 unset($element);
238 $i = $workshop->nelements;
239 $element->workshopid = $workshop->id;
240 $element->assessmentid = $assessment->id;
241 $element->elementno = $i;
242 $element->grade = $form->grade[$i];
243 if (!$element->id = insert_record("workshop_grades", $element)) {
244 error("Could not insert workshop grade!");
246 $grade = ($elements[intval($error + 0.5)]->maxscore + $form->grade[$i]) * 100 / $workshop->grade;
247 // do sanity check
248 if ($grade < 0) {
249 $grade = 0;
250 } elseif ($grade > 100) {
251 $grade = 100;
253 echo "<b>".get_string("weightederrorcount", "workshop", intval($error + 0.5))."</b>\n";
254 break;
256 case 3: // criteria grading
257 // save in the selected criteria value in element zero,
258 unset($element);
259 $element->workshopid = $workshop->id;
260 $element->assessmentid = $assessment->id;
261 $element->elementno = 0;
262 $element->grade = $form->grade[0];
263 if (!$element->id = insert_record("workshop_grades", $element)) {
264 error("Could not insert workshop grade!");
266 // now save the adjustment in element one
267 unset($element);
268 $element->workshopid = $workshop->id;
269 $element->assessmentid = $assessment->id;
270 $element->elementno = 1;
271 $element->grade = $form->grade[1];
272 if (!$element->id = insert_record("workshop_grades", $element)) {
273 error("Could not insert workshop grade!");
275 $grade = ($elements[$form->grade[0]]->maxscore + $form->grade[1]);
276 break;
278 case 4: // rubric grading (identical to accumulative grading)
279 // Insert all the elements that contain something
280 foreach ($form->grade as $key => $thegrade) {
281 unset($element);
282 $element->workshopid = $workshop->id;
283 $element->assessmentid = $assessment->id;
284 $element->elementno = clean_param($key, PARAM_INT);
285 $element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
286 $element->grade = $thegrade;
287 if (!$element->id = insert_record("workshop_grades", $element)) {
288 error("Could not insert workshop grade!");
291 // now work out the grade...
292 $rawgrade=0;
293 $totalweight=0;
294 foreach ($form->grade as $key => $grade) {
295 $maxscore = $elements[$key]->maxscore;
296 $weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
297 if ($weight > 0) {
298 $totalweight += $weight;
300 $rawgrade += ($grade / $maxscore) * $weight;
302 $grade = 100.0 * ($rawgrade / $totalweight);
303 break;
305 } // end of switch
308 // any comment?
309 if (!empty($form->generalcomment)) { // update the object (no need to update the db record)
310 $assessment->generalcomment = clean_param($form->generalcomment, PARAM_CLEAN);
313 // redisplay form, going back to original returnto address
314 workshop_print_assessment($workshop, $assessment, true, true, $form->returnto);
316 // add_to_log($course->id, "workshop", "assess", "viewassessment.php?id=$cm->id&amp;aid=$assessment->id", "$assessment->id", "$cm->id");
321 /******************* confirm delete ************************************/
322 elseif ($action == 'confirmdelete' ) {
324 if (empty($aid)) {
325 error("Confirm delete: assessment id missing");
328 notice_yesno(get_string("confirmdeletionofthisitem","workshop", get_string("assessment", "workshop")),
329 "assessments.php?action=delete&amp;id=$cm->id&amp;aid=$aid", "submissions.php?action=adminlist&amp;id=$cm->id");
333 /******************* delete ************************************/
334 elseif ($action == 'delete' ) {
336 if (empty($aid)) {
337 error("Delete: submission id missing");
340 print_string("deleting", "workshop");
341 // first delete all the associated records...
342 delete_records("workshop_comments", "assessmentid", $aid);
343 delete_records("workshop_grades", "assessmentid", $aid);
344 // ...now delete the assessment...
345 delete_records("workshop_assessments", "id", $aid);
347 print_continue("view.php?id=$cm->id");
351 /*********************** admin list of asssessments (of a submission) (by teachers)**************/
352 elseif ($action == 'adminlist') {
354 require_capability('mod/workshop:manage', $context);
356 if (empty($sid)) {
357 error ("Workshop asssessments: adminlist called with no sid");
359 $submission = get_record("workshop_submissions", "id", $sid);
360 workshop_print_assessments_for_admin($workshop, $submission);
361 print_continue("submissions.php?action=adminlist&amp;id=$cm->id");
365 /*********************** admin list of asssessments by a student (used by teachers only )******************/
366 elseif ($action == 'adminlistbystudent') {
368 require_capability('mod/workshop:manage', $context);
370 if (empty($userid)) {
371 error ("Workshop asssessments: adminlistbystudent called with no userid");
373 $user = get_record("user", "id", $userid);
374 workshop_print_assessments_by_user_for_admin($workshop, $user);
375 print_continue("submissions.php?action=adminlist&amp;id=$cm->id");
379 /*************** agree (to) assessment (by student) ***************************/
380 elseif ($action == 'agreeassessment') {
381 $timenow = time();
382 // assessment id comes from link or hidden form variable
383 if (!$assessment = get_record("workshop_assessments", "id", $aid)) {
384 error("Assessment : agree assessment failed");
386 //save time of agreement
387 set_field("workshop_assessments", "timeagreed", $timenow, "id", $assessment->id);
388 echo "<div style=\"text-align:center\"><b>".get_string("savedok", "workshop")."</b></div><br />\n";
390 add_to_log($course->id, "workshop", "agree", "viewassessment.php?id=$cm->id&amp;aid=$assessment->id", "$assessment->id");
391 print_continue("view.php?id=$cm->id");
396 /*************** display grading form (viewed by student) *********************************/
397 elseif ($action == 'displaygradingform') {
399 print_heading_with_help(get_string("specimenassessmentform", "workshop"), "specimen", "workshop");
401 workshop_print_assessment($workshop); // called with no assessment
402 print_continue("view.php?id=$cm->id");
406 /*************** edit comment on assessment (by author, assessor or teacher) ***************************/
407 elseif ($action == 'editcomment') {
409 print_heading_with_help(get_string("editacomment", "workshop"), "editingacomment", "workshop");
410 // get the comment record...
411 if (!$comment = get_record("workshop_comments", "id", $cid)) {
412 error("Edit Comment: Comment not found");
414 if (!$assessment = get_record("workshop_assessments", "id", $comment->assessmentid)) {
415 error("Edit Comment: Assessment not found");
417 if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) {
418 error("Edit Comment: Submission not found");
421 <form id="gradingform" action="assessments.php" method="post">
422 <input type="hidden" name="action" value="updatecomment" />
423 <input type="hidden" name="id" value="<?php echo $cm->id ?>" />
424 <input type="hidden" name="cid" value="<?php echo $cid ?>" />
425 <div class="boxaligncenter">
426 <table cellpadding="5" border="1">
427 <?php
429 // now show the comment
430 echo "<tr valign=\"top\">\n";
431 echo " <td align=\"right\"><b>". get_string("comment", "workshop").":</b></td>\n";
432 echo " <td>\n";
433 echo " <textarea name=\"comments\" rows=\"5\" cols=\"75\">\n";
434 if (isset($comment->comments)) {
435 echo $comment->comments;
437 echo " </textarea>\n";
438 echo " </td></tr></table>\n";
439 echo "<input type=\"submit\" value=\"".get_string("savemycomment", "workshop")."\" />\n";
440 echo "</div></form>\n";
441 workshop_print_assessment($workshop, $assessment);
445 /*********************** edit assessment elements (for teachers) ***********************/
446 elseif ($action == 'editelements') {
448 require_capability('mod/workshop:manage', $context);
450 $count = count_records("workshop_grades", "workshopid", $workshop->id);
451 if ($count) {
452 notify(get_string("warningonamendingelements", "workshop"));
454 // set up heading, form and table
455 print_heading_with_help(get_string("editingassessmentelements", "workshop"), "elements", "workshop");
457 <form id="form" method="post" action="assessments.php">
458 <input type="hidden" name="id" value="<?php echo $cm->id ?>" />
459 <input type="hidden" name="action" value="insertelements" />
460 <div class="boxaligncenter"><table cellpadding="5" border="1">
461 <?php
463 // get existing elements, if none set up appropriate default ones
464 if ($elementsraw = get_records("workshop_elements", "workshopid", $workshop->id, "elementno ASC" )) {
465 foreach ($elementsraw as $element) {
466 $elements[] = $element; // to renumber index 0,1,2...
469 // check for missing elements (this happens either the first time round or when the number of elements is icreased)
470 for ($i=0; $i<$workshop->nelements; $i++) {
471 if (!isset($elements[$i])) {
472 $elements[$i]->description = '';
473 $elements[$i]->scale =0;
474 $elements[$i]->maxscore = 0;
475 $elements[$i]->weight = 11;
479 switch ($workshop->gradingstrategy) {
480 case 0: // no grading
481 for ($i=0; $i<$workshop->nelements; $i++) {
482 $iplus1 = $i+1;
483 echo "<tr valign=\"top\">\n";
484 echo " <td align=\"right\"><b>". get_string("element","workshop")." $iplus1:</b></td>\n";
485 echo "<td><textarea name=\"description[]\" rows=\"3\" cols=\"75\">".$elements[$i]->description."</textarea>\n";
486 echo " </td></tr>\n";
487 echo "<tr valign=\"top\">\n";
488 echo " <td colspan=\"2\" class=\"workshopassessmentheading\">&nbsp;</td>\n";
489 echo "</tr>\n";
491 break;
493 case 1: // accumulative grading
494 // set up scales name
495 foreach ($WORKSHOP_SCALES as $KEY => $SCALE) {
496 $SCALES[] = $SCALE['name'];
498 for ($i=0; $i<$workshop->nelements; $i++) {
499 $iplus1 = $i+1;
500 echo "<tr valign=\"top\">\n";
501 echo " <td align=\"right\"><b>". get_string("element","workshop")." $iplus1:</b></td>\n";
502 echo "<td><textarea name=\"description[]\" rows=\"3\" cols=\"75\">".$elements[$i]->description."</textarea>\n";
503 echo " </td></tr>\n";
504 echo "<tr valign=\"top\">\n";
505 echo " <td align=\"right\"><b>". get_string("typeofscale", "workshop"). ":</b></td>\n";
506 echo "<td valign=\"top\">\n";
507 choose_from_menu($SCALES, "scale[]", $elements[$i]->scale, "");
508 if ($elements[$i]->weight == '') { // not set
509 $elements[$i]->weight = 11; // unity
511 echo "</td></tr>\n";
512 echo "<tr valign=\"top\"><td align=\"right\"><b>".get_string("elementweight", "workshop").":</b></td><td>\n";
513 workshop_choose_from_menu($WORKSHOP_EWEIGHTS, "weight[]", $elements[$i]->weight, "");
514 echo " </td>\n";
515 echo "</tr>\n";
516 echo "<tr valign=\"top\">\n";
517 echo " <td colspan=\"2\" class=\"workshopassessmentheading\">&nbsp;</td>\n";
518 echo "</tr>\n";
520 break;
522 case 2: // error banded grading
523 for ($i=0; $i<$workshop->nelements; $i++) {
524 $iplus1 = $i+1;
525 echo "<tr valign=\"top\">\n";
526 echo " <td align=\"right\"><b>". get_string("element","workshop")." $iplus1:</b></td>\n";
527 echo "<td><textarea name=\"description[$i]\" rows=\"3\" cols=\"75\">".$elements[$i]->description."</textarea>\n";
528 echo " </td></tr>\n";
529 if ($elements[$i]->weight == '') { // not set
530 $elements[$i]->weight = 11; // unity
532 echo "</tr>\n";
533 echo "<tr valign=\"top\"><td align=\"right\"><b>".get_string("elementweight", "workshop").":</b></td><td>\n";
534 workshop_choose_from_menu($WORKSHOP_EWEIGHTS, "weight[]", $elements[$i]->weight, "");
535 echo " </td>\n";
536 echo "</tr>\n";
537 echo "<tr valign=\"top\">\n";
538 echo " <td colspan=\"2\" class=\"workshopassessmentheading\">&nbsp;</td>\n";
539 echo "</tr>\n";
541 echo "</div></table><br />\n";
542 echo "<div style=\"text-align:center\"><b>".get_string("gradetable","workshop")."</b></div>\n";
543 echo "<div class=\"boxaligncenter\"><table cellpadding=\"5\" border=\"1\"><tr><td align=\"CENTER\">".
544 get_string("numberofnegativeresponses", "workshop");
545 echo "</td><td>". get_string("suggestedgrade", "workshop")."</td></tr>\n";
546 for ($j = $workshop->grade; $j >= 0; $j--) {
547 $numbers[$j] = $j;
549 for ($i=0; $i<=$workshop->nelements; $i++) {
550 echo "<tr><td align=\"CENTER\">$i</td><td align=\"CENTER\">";
551 if (!isset($elements[$i])) { // the "last one" will be!
552 $elements[$i]->description = "";
553 $elements[$i]->maxscore = 0;
555 choose_from_menu($numbers, "maxscore[$i]", $elements[$i]->maxscore, "");
556 echo "</td></tr>\n";
558 echo "</table></div>\n";
559 break;
561 case 3: // criterion grading
562 for ($j = 100; $j >= 0; $j--) {
563 $numbers[$j] = $j;
565 for ($i=0; $i<$workshop->nelements; $i++) {
566 $iplus1 = $i+1;
567 echo "<tr valign=\"top\">\n";
568 echo " <td align=\"right\"><b>". get_string("criterion","workshop")." $iplus1:</b></td>\n";
569 echo "<td><textarea name=\"description[$i]\" rows=\"3\" cols=\"75\">".$elements[$i]->description."</textarea>\n";
570 echo " </td></tr>\n";
571 echo "<tr><td><b>". get_string("suggestedgrade", "workshop").":</b></td><td>\n";
572 choose_from_menu($numbers, "maxscore[$i]", $elements[$i]->maxscore, "");
573 echo "</td></tr>\n";
574 echo "<tr valign=\"top\">\n";
575 echo " <td colspan=\"2\" class=\"workshopassessmentheading\">&nbsp;</td>\n";
576 echo "</tr>\n";
578 break;
580 case 4: // rubric
581 for ($j = 100; $j >= 0; $j--) {
582 $numbers[$j] = $j;
584 if ($rubricsraw = get_records("workshop_rubrics", "workshopid", $workshop->id)) {
585 foreach ($rubricsraw as $rubric) {
586 $rubrics[$rubric->elementno][$rubric->rubricno] = $rubric->description; // reindex 0,1,2...
589 for ($i=0; $i<$workshop->nelements; $i++) {
590 $iplus1 = $i+1;
591 echo "<tr valign=\"top\">\n";
592 echo " <td align=\"right\"><b>". get_string("element","workshop")." $iplus1:</b></td>\n";
593 echo "<td><textarea name=\"description[$i]\" rows=\"3\" cols=\"75\">".$elements[$i]->description."</textarea>\n";
594 echo " </td></tr>\n";
595 echo "<tr valign=\"top\"><td align=\"right\"><b>".get_string("elementweight", "workshop").":</b></td><td>\n";
596 workshop_choose_from_menu($WORKSHOP_EWEIGHTS, "weight[]", $elements[$i]->weight, "");
597 echo " </td>\n";
598 echo "</tr>\n";
600 for ($j=0; $j<5; $j++) {
601 $jplus1 = $j+1;
602 if (empty($rubrics[$i][$j])) {
603 $rubrics[$i][$j] = "";
605 echo "<tr valign=\"top\">\n";
606 echo " <td align=\"right\"><b>". get_string("grade","workshop")." $j:</b></td>\n";
607 echo "<td><textarea name=\"rubric[$i][$j]\" rows=\"3\" cols=\"75\">".$rubrics[$i][$j]."</textarea>\n";
608 echo " </td></tr>\n";
610 echo "<tr valign=\"top\">\n";
611 echo " <td colspan=\"2\" class=\"workshopassessmentheading\">&nbsp;</td>\n";
612 echo "</tr>\n";
614 break;
616 // close table and form
619 </table><br />
620 <input type="submit" value="<?php print_string("savechanges") ?>" />
621 <input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
622 </div>
623 </form>
624 <?php
628 /*************** grade all assessments (by teacher) ***************************/
629 elseif ($action == 'gradeallassessments') {
631 require_capability('mod/workshop:manage', $context);
633 print_heading(get_string("gradingallassessments", "workshop"));
634 workshop_grade_assessments($workshop);
635 print_continue("view.php?id=$cm->id");
639 /*************** grade (student's) assessment (by teacher) ***************************/
640 elseif ($action == 'gradeassessment') {
642 require_capability('mod/workshop:manage', $context);
644 print_heading_with_help(get_string("gradeassessment", "workshop"), "gradingassessments", "workshop");
645 // get assessment record
646 if (!$assessmentid = $aid) {
647 error("Assessment id not given");
649 $assessment = get_record("workshop_assessments", "id", $assessmentid);
650 if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) {
651 error("Submission not found");
653 // get the teacher's assessment first
654 if ($teachersassessment = workshop_get_submission_assessment($submission, $USER)) {
655 echo "<div style=\"text-align:center\"><b>".get_string("teacherassessments", "workshop", $course->teacher)."</b></div>\n";
656 workshop_print_assessment($workshop, $teachersassessment);
658 // now the student's assessment (don't allow changes)
659 $user = get_record("user", "id", $assessment->userid);
660 echo "<div style=\"text-align:center\"><b>".get_string("assessmentby", "workshop", $user->firstname." ".$user->lastname)."</b></div>\n";
661 workshop_print_assessment($workshop, $assessment);
663 include('assessment_grading_form.html');
664 die;
668 /*************** insert (new) comment (by author, assessor or teacher) ***************************/
669 elseif ($action == 'insertcomment') {
670 $timenow = time();
672 $form = (object)$_POST;
674 if (!$assessment = get_record("workshop_assessments", "id", $aid)) {
675 error("Unable to insert comment");
677 // save the comment...
678 $comment->workshopid = $workshop->id;
679 $comment->assessmentid = $assessment->id;
680 $comment->userid = $USER->id;
681 $comment->timecreated = $timenow;
682 $comment->comments = clean_param($form->comments, PARAM_CLEAN);
683 if (!$comment->id = insert_record("workshop_comments", $comment)) {
684 error("Could not insert workshop comment!");
687 add_to_log($course->id, "workshop", "comment", "view.php?id=$cm->id", "$comment->id");
689 print_continue("viewassessment.php?id=$cm->id&amp;aid=$assessment->id");
693 /*********************** insert/update assignment elements (for teachers)***********************/
694 elseif ($action == 'insertelements') {
696 require_capability('mod/workshop:manage', $context);
698 $form = data_submitted();
700 // let's not fool around here, dump the junk!
701 delete_records("workshop_elements", "workshopid", $workshop->id);
703 // determine wich type of grading
704 switch ($workshop->gradingstrategy) {
705 case 0: // no grading
706 // Insert all the elements that contain something
707 foreach ($form->description as $key => $description) {
708 if ($description) {
709 unset($element);
710 $element->description = $description;
711 $element->workshopid = $workshop->id;
712 $element->elementno = $key;
713 if (!$element->id = insert_record("workshop_elements", $element)) {
714 error("Could not insert workshop element!");
718 break;
720 case 1: // accumulative grading
721 // Insert all the elements that contain something
722 foreach ($form->description as $key => $description) {
723 if ($description) {
724 unset($element);
725 $element->description = $description;
726 $element->workshopid = $workshop->id;
727 $element->elementno = clean_param($key, PARAM_INT);
728 if (isset($form->scale[$key])) {
729 $element->scale = $form->scale[$key];
730 switch ($WORKSHOP_SCALES[$form->scale[$key]]['type']) {
731 case 'radio' : $element->maxscore = $WORKSHOP_SCALES[$form->scale[$key]]['size'] - 1;
732 break;
733 case 'selection' : $element->maxscore = $WORKSHOP_SCALES[$form->scale[$key]]['size'];
734 break;
737 if (isset($form->weight[$key])) {
738 $element->weight = $form->weight[$key];
740 if (!$element->id = insert_record("workshop_elements", $element)) {
741 error("Could not insert workshop element!");
745 break;
747 case 2: // error banded grading...
748 case 3: // ...and criterion grading
749 // Insert all the elements that contain something, the number of descriptions is one less than the number of grades
750 foreach ($form->maxscore as $key => $themaxscore) {
751 unset($element);
752 $element->workshopid = $workshop->id;
753 $element->elementno = clean_param($key, PARAM_INT);
754 $element->maxscore = $themaxscore;
755 if (isset($form->description[$key])) {
756 $element->description = $form->description[$key];
758 if (isset($form->weight[$key])) {
759 $element->weight = $form->weight[$key];
761 if (!$element->id = insert_record("workshop_elements", $element)) {
762 error("Could not insert workshop element!");
765 break;
767 case 4: // ...and criteria grading
768 // Insert all the elements that contain something
769 foreach ($form->description as $key => $description) {
770 unset($element);
771 $element->workshopid = $workshop->id;
772 $element->elementno = clean_param($key, PARAM_INT);
773 $element->description = $description;
774 $element->weight = $form->weight[$key];
775 for ($j=0;$j<5;$j++) {
776 if (empty($form->rubric[$key][$j]))
777 break;
779 $element->maxscore = $j - 1;
780 if (!$element->id = insert_record("workshop_elements", $element)) {
781 error("Could not insert workshop element!");
784 // let's not fool around here, dump the junk!
785 delete_records("workshop_rubrics", "workshopid", $workshop->id);
786 for ($i=0;$i<$workshop->nelements;$i++) {
787 for ($j=0;$j<5;$j++) {
788 unset($element);
789 if (empty($form->rubric[$i][$j])) { // OK to have an element with fewer than 5 items
790 break;
792 $element->workshopid = $workshop->id;
793 $element->elementno = $i;
794 $element->rubricno = $j;
795 $element->description = $form->rubric[$i][$j];
796 if (!$element->id = insert_record("workshop_rubrics", $element)) {
797 error("Could not insert workshop element!");
801 break;
802 } // end of switch
803 echo "</div>"; // not sure where this one came from MDL-7861
804 redirect("view.php?id=$cm->id", get_string("savedok","workshop"));
808 /*********************** list assessments for grading (Student submissions)(by teachers)***********************/
809 elseif ($action == 'listungradedstudentsubmissions') {
811 require_capability('mod/workshop:manage', $context);
813 workshop_list_ungraded_assessments($workshop, "student");
814 print_continue("view.php?id=$cm->id");
818 /*********************** list assessments for grading (Teacher submissions) (by teachers)***********************/
819 elseif ($action == 'listungradedteachersubmissions') {
821 require_capability('mod/workshop:manage', $context);
823 workshop_list_ungraded_assessments($workshop, "teacher");
824 print_continue("view.php?id=$cm->id");
828 /****************** list teacher submissions ***********************/
829 elseif ($action == 'listteachersubmissions') {
831 workshop_list_teacher_submissions($workshop, $USER);
832 print_continue("view.php?id=$cm->id");
836 /******************* regrade student assessments ************************************/
837 elseif ($action == 'regradestudentassessments' ) {
839 $timenow = time();
840 require_capability('mod/workshop:manage', $context);
841 // get all the submissions...
842 if ($submissions = get_records("workshop_submissions", "workshopid", $workshop->id)) {
843 foreach ($submissions as $submission) {
844 // ...if cold...
845 if (($submission->timecreated + $CFG->maxeditingtime) < $timenow) {
846 // ...clear assessment count so workshop_grade_assessments() can do its thing
847 set_field("workshop_submissions", "nassessments", 0, "id", $submission->id);
851 echo "<pre>";
852 workshop_grade_assessments($workshop);
853 echo '</pre>';
854 print_continue("submissions.php?id=$cm->id&action=adminlist");
858 /*************** remove stock comment (by teacher ) ***************************/
859 elseif ($action == 'removestockcomment') {
861 if (empty($aid) or empty($stockcommentid)) {
862 error("Workshop Assessment id and/or Stock Comment id missing");
865 require_capability('mod/workshop:manage', $context);
867 if (!$assessment = get_record("workshop_assessments", "id", $aid)) {
868 error("workshop assessment is misconfigured");
870 $form = data_submitted('nomatch'); //Nomatch because we can come from assess.php
872 // delete the comment from the stock comments table
873 if (!delete_records("workshop_stockcomments", "id", $stockcommentid)) {
874 error("Could not remove comment from the comment bank");
877 // now upate the assessment (just the elements, the assessment itself is not updated)
879 // first get the assignment elements for maxscores and weights...
880 $elementsraw = get_records("workshop_elements", "workshopid", $workshop->id, "elementno ASC");
881 if (count($elementsraw) < $workshop->nelements) {
882 print_string("noteonassignmentelements", "workshop");
884 if ($elementsraw) {
885 foreach ($elementsraw as $element) {
886 $elements[] = $element; // to renumber index 0,1,2...
888 } else {
889 $elements = null;
892 $timenow = time();
893 // don't fiddle about, delete all the old and add the new!
894 delete_records("workshop_grades", "assessmentid", $assessment->id);
897 //determine what kind of grading we have
898 switch ($workshop->gradingstrategy) {
899 case 0: // no grading
900 // Insert all the elements that contain something
901 for ($i =0; $i < $workshop->nelements; $i++) {
902 unset($element);
903 $element->workshopid = $workshop->id;
904 $element->assessmentid = $assessment->id;
905 $element->elementno = $i;
906 $element->feedback = clean_param($form->{"feedback_$i"}, PARAM_CLEAN);
907 if (!$element->id = insert_record("workshop_grades", $element)) {
908 error("Could not insert workshop grade!");
911 $grade = 0; // set to satisfy save to db
912 break;
914 case 1: // accumulative grading
915 // Insert all the elements that contain something
916 foreach ($form->grade as $key => $thegrade) {
917 unset($element);
918 $element->workshopid = $workshop->id;
919 $element->assessmentid = $assessment->id;
920 $element->elementno = clean_param($key, PARAM_INT);
921 $element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
922 $element->grade = $thegrade;
923 if (!$element->id = insert_record("workshop_grades", $element)) {
924 error("Could not insert workshop grade!");
927 // now work out the grade...
928 $rawgrade=0;
929 $totalweight=0;
930 foreach ($form->grade as $key => $grade) {
931 $maxscore = $elements[$key]->maxscore;
932 $weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
933 if ($weight > 0) {
934 $totalweight += $weight;
936 $rawgrade += ($grade / $maxscore) * $weight;
937 // echo "\$key, \$maxscore, \$weight, \$totalweight, \$grade, \$rawgrade : $key, $maxscore, $weight, $totalweight, $grade, $rawgrade<br />";
939 $grade = 100.0 * ($rawgrade / $totalweight);
940 break;
942 case 2: // error banded graded
943 // Insert all the elements that contain something
944 $error = 0.0;
945 for ($i =0; $i < $workshop->nelements; $i++) {
946 unset($element);
947 $element->workshopid = $workshop->id;
948 $element->assessmentid = $assessment->id;
949 $element->elementno = $i;
950 $element->feedback = clean_param($form->{"feedback_$i"}, PARAM_CLEAN);
951 $element->grade = $form->grade[$i];
952 if (!$element->id = insert_record("workshop_grades", $element)) {
953 error("Could not insert workshop grade!");
955 if (empty($form->grade[$i])){
956 $error += $WORKSHOP_EWEIGHTS[$elements[$i]->weight];
959 // now save the adjustment
960 unset($element);
961 $i = $workshop->nelements;
962 $element->workshopid = $workshop->id;
963 $element->assessmentid = $assessment->id;
964 $element->elementno = $i;
965 $element->grade = $form->grade[$i];
966 if (!$element->id = insert_record("workshop_grades", $element)) {
967 error("Could not insert workshop grade!");
969 $grade = ($elements[intval($error + 0.5)]->maxscore + $form->grade[$i]) * 100 / $workshop->grade;
970 // do sanity check
971 if ($grade < 0) {
972 $grade = 0;
973 } elseif ($grade > 100) {
974 $grade = 100;
976 echo "<b>".get_string("weightederrorcount", "workshop", intval($error + 0.5))."</b>\n";
977 break;
979 case 3: // criteria grading
980 // save in the selected criteria value in element zero,
981 unset($element);
982 $element->workshopid = $workshop->id;
983 $element->assessmentid = $assessment->id;
984 $element->elementno = 0;
985 $element->grade = $form->grade[0];
986 if (!$element->id = insert_record("workshop_grades", $element)) {
987 error("Could not insert workshop grade!");
989 // now save the adjustment in element one
990 unset($element);
991 $element->workshopid = $workshop->id;
992 $element->assessmentid = $assessment->id;
993 $element->elementno = 1;
994 $element->grade = $form->grade[1];
995 if (!$element->id = insert_record("workshop_grades", $element)) {
996 error("Could not insert workshop grade!");
998 $grade = ($elements[$form->grade[0]]->maxscore + $form->grade[1]);
999 break;
1001 case 4: // rubric grading (identical to accumulative grading)
1002 // Insert all the elements that contain something
1003 foreach ($form->grade as $key => $thegrade) {
1004 unset($element);
1005 $element->workshopid = $workshop->id;
1006 $element->assessmentid = $assessment->id;
1007 $element->elementno = clean_param($key, PARAM_INT);
1008 $element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
1009 $element->grade = $thegrade;
1010 if (!$element->id = insert_record("workshop_grades", $element)) {
1011 error("Could not insert workshop grade!");
1014 // now work out the grade...
1015 $rawgrade=0;
1016 $totalweight=0;
1017 foreach ($form->grade as $key => $grade) {
1018 $maxscore = $elements[$key]->maxscore;
1019 $weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
1020 if ($weight > 0) {
1021 $totalweight += $weight;
1023 $rawgrade += ($grade / $maxscore) * $weight;
1025 $grade = 100.0 * ($rawgrade / $totalweight);
1026 break;
1028 } // end of switch
1031 // any comment?
1032 if (!empty($form->generalcomment)) { // update the object (no need to update the db record)
1033 $assessment->generalcomment = clean_param($form->generalcomment, PARAM_CLEAN);
1036 // redisplay form, going back to original returnto address
1037 workshop_print_assessment($workshop, $assessment, true, true, $form->returnto);
1039 // add_to_log($course->id, "workshop", "assess", "viewassessment.php?id=$cm->id&amp;aid=$assessment->id", "$assessment->id", "$cm->id");
1044 /*************** update assessment (by teacher or student) ***************************/
1045 elseif ($action == 'updateassessment') {
1047 if (empty($aid)) {
1048 error("Workshop Assessment id missing");
1051 if (! $assessment = get_record("workshop_assessments", "id", $aid)) {
1052 error("workshop assessment is misconfigured");
1055 // first get the assignment elements for maxscores and weights...
1056 $elementsraw = get_records("workshop_elements", "workshopid", $workshop->id, "elementno ASC");
1057 if (count($elementsraw) < $workshop->nelements) {
1058 print_string("noteonassignmentelements", "workshop");
1060 if ($elementsraw) {
1061 foreach ($elementsraw as $element) {
1062 $elements[] = $element; // to renumber index 0,1,2...
1064 } else {
1065 $elements = null;
1068 $timenow = time();
1069 // don't fiddle about, delete all the old and add the new!
1070 delete_records("workshop_grades", "assessmentid", $assessment->id);
1072 $form = data_submitted('nomatch'); //Nomatch because we can come from assess.php
1074 //determine what kind of grading we have
1075 switch ($workshop->gradingstrategy) {
1076 case 0: // no grading
1077 // Insert all the elements that contain something
1078 for ($i = 0; $i < $workshop->nelements; $i++) {
1079 unset($element);
1080 $element->workshopid = $workshop->id;
1081 $element->assessmentid = $assessment->id;
1082 $element->elementno = $i;
1083 $element->feedback = clean_param($form->{"feedback_$i"}, PARAM_CLEAN);
1084 if (!$element->id = insert_record("workshop_grades", $element)) {
1085 error("Could not insert workshop grade!");
1088 $grade = 0; // set to satisfy save to db
1089 break;
1091 case 1: // accumulative grading
1092 // Insert all the elements that contain something
1093 foreach ($form->grade as $key => $thegrade) {
1094 unset($element);
1095 $element->workshopid = $workshop->id;
1096 $element->assessmentid = $assessment->id;
1097 $element->elementno = $key;
1098 $element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
1099 $element->grade = $thegrade;
1100 if (!$element->id = insert_record("workshop_grades", $element)) {
1101 error("Could not insert workshop grade!");
1104 // now work out the grade...
1105 $rawgrade=0;
1106 $totalweight=0;
1107 foreach ($form->grade as $key => $grade) {
1108 $maxscore = $elements[$key]->maxscore;
1109 $weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
1110 if ($weight > 0) {
1111 $totalweight += $weight;
1113 $rawgrade += ($grade / $maxscore) * $weight;
1114 // echo "\$key, \$maxscore, \$weight, \$totalweight, \$grade, \$rawgrade : $key, $maxscore, $weight, $totalweight, $grade, $rawgrade<br />";
1116 $grade = 100.0 * ($rawgrade / $totalweight);
1117 break;
1119 case 2: // error banded graded
1120 // Insert all the elements that contain something
1121 $error = 0.0;
1122 for ($i =0; $i < $workshop->nelements; $i++) {
1123 unset($element);
1124 $element->workshopid = $workshop->id;
1125 $element->assessmentid = $assessment->id;
1126 $element->elementno = $i;
1127 $element->feedback = $form->{"feedback_$i"};
1128 $element->grade = clean_param($form->grade[$i], PARAM_CLEAN);
1129 if (!$element->id = insert_record("workshop_grades", $element)) {
1130 error("Could not insert workshop grade!");
1132 if (empty($form->grade[$i])){
1133 $error += $WORKSHOP_EWEIGHTS[$elements[$i]->weight];
1136 // now save the adjustment
1137 unset($element);
1138 $i = $workshop->nelements;
1139 $element->workshopid = $workshop->id;
1140 $element->assessmentid = $assessment->id;
1141 $element->elementno = $i;
1142 $element->grade = $form->grade[$i];
1143 if (!$element->id = insert_record("workshop_grades", $element)) {
1144 error("Could not insert workshop grade!");
1146 $grade = ($elements[intval($error + 0.5)]->maxscore + $form->grade[$i]) * 100 / $workshop->grade;
1147 // do sanity check
1148 if ($grade < 0) {
1149 $grade = 0;
1150 } elseif ($grade > 100) {
1151 $grade = 100;
1153 echo "<b>".get_string("weightederrorcount", "workshop", intval($error + 0.5))."</b>\n";
1154 break;
1156 case 3: // criteria grading
1157 // save in the selected criteria value in element zero,
1158 unset($element);
1159 $element->workshopid = $workshop->id;
1160 $element->assessmentid = $assessment->id;
1161 $element->elementno = 0;
1162 $element->grade = $form->grade[0];
1163 if (!$element->id = insert_record("workshop_grades", $element)) {
1164 error("Could not insert workshop grade!");
1166 // now save the adjustment in element one
1167 unset($element);
1168 $element->workshopid = $workshop->id;
1169 $element->assessmentid = $assessment->id;
1170 $element->elementno = 1;
1171 $element->grade = $form->grade[1];
1172 if (!$element->id = insert_record("workshop_grades", $element)) {
1173 error("Could not insert workshop grade!");
1175 $grade = ($elements[$form->grade[0]]->maxscore + $form->grade[1]);
1176 break;
1178 case 4: // rubric grading (identical to accumulative grading)
1179 // Insert all the elements that contain something
1180 foreach ($form->grade as $key => $thegrade) {
1181 unset($element);
1182 $element->workshopid = $workshop->id;
1183 $element->assessmentid = $assessment->id;
1184 $element->elementno = clean_param($key, PARAM_INT);
1185 $element->feedback = clean_param($form->{"feedback_$key"}, PARAM_CLEAN);
1186 $element->grade = $thegrade;
1187 if (!$element->id = insert_record("workshop_grades", $element)) {
1188 error("Could not insert workshop grade!");
1191 // now work out the grade...
1192 $rawgrade=0;
1193 $totalweight=0;
1194 foreach ($form->grade as $key => $grade) {
1195 $maxscore = $elements[$key]->maxscore;
1196 $weight = $WORKSHOP_EWEIGHTS[$elements[$key]->weight];
1197 if ($weight > 0) {
1198 $totalweight += $weight;
1200 $rawgrade += ($grade / $maxscore) * $weight;
1202 $grade = 100.0 * ($rawgrade / $totalweight);
1203 break;
1205 } // end of switch
1207 // update the time of the assessment record (may be re-edited)...
1208 set_field("workshop_assessments", "timecreated", $timenow, "id", $assessment->id);
1210 if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid)) {
1211 error ("Updateassessment: submission record not found");
1214 // if the workshop does need peer agreement AND it's self assessment then set timeagreed
1215 if ($workshop->agreeassessments and ($submission->userid == $assessment->userid)) {
1216 set_field("workshop_assessments", "timeagreed", $timenow, "id", $assessment->id);
1219 // set grade...
1220 set_field("workshop_assessments", "grade", $grade, "id", $assessment->id);
1221 // ...and clear the timegraded but set the graddinggrade to maximum, may be reduced subsequently...
1222 set_field("workshop_assessments", "timegraded", 0, "id", $assessment->id);
1223 set_field("workshop_assessments", "gradinggrade", 100, "id", $assessment->id);
1224 // ...and the resubmission flag
1225 set_field("workshop_assessments", "resubmission", 0, "id", $assessment->id);
1227 // if there's examples or peer assessments clear the counter in the submission so that
1228 // all assessments for this submission will be regraded
1229 if ($workshop->ntassessments or $workshop->nsassessments) {
1230 set_field("workshop_submissions", "nassessments", 0, "id", $submission->id);
1231 workshop_grade_assessments($workshop);
1232 } else { // it could be self assessment....
1233 // now see if there's a corresponding assessment so that the gradinggrade can be set
1234 if (workshop_is_teacher($workshop)) {
1235 // see if there's are student assessments, if so set their gradinggrade
1236 if ($assessments = workshop_get_assessments($submission)) {
1237 foreach($assessments as $studentassessment) {
1238 // skip if it's not a student assessment
1239 if (!workshop_is_student($workshop, $studentassessment->userid)) {
1240 continue;
1242 $gradinggrade = workshop_compare_assessments($workshop, $assessment, $studentassessment);
1243 set_field("workshop_assessments", "timegraded", $timenow, "id", $studentassessment->id);
1244 set_field("workshop_assessments", "gradinggrade", $gradinggrade, "id", $studentassessment->id);
1247 } else { //it's a student assessment, see if there's a corresponding teacher's assessment
1248 if ($assessments = workshop_get_assessments($submission)) {
1249 foreach($assessments as $teacherassessment) {
1250 if (workshop_is_teacher($workshop, $teacherassessment->userid)) {
1251 $gradinggrade = workshop_compare_assessments($workshop, $assessment, $teacherassessment);
1252 set_field("workshop_assessments", "timegraded", $timenow, "id", $assessment->id);
1253 set_field("workshop_assessments", "gradinggrade", $gradinggrade, "id", $assessment->id);
1254 break; // only look for the first teacher assessment
1261 // any comment?
1262 if (!empty($form->generalcomment)) {
1263 set_field("workshop_assessments", "generalcomment", clean_param($form->generalcomment, PARAM_CLEAN), "id", $assessment->id);
1266 add_to_log($course->id, "workshop", "assess",
1267 "viewassessment.php?id=$cm->id&amp;aid=$assessment->id", "$assessment->id", "$cm->id");
1269 // set up return address
1270 if (!$returnto = $form->returnto) {
1271 $returnto = "view.php?id=$cm->id";
1274 // show grade if grading strategy is not zero
1275 if ($workshop->gradingstrategy) {
1276 echo "</div>"; // MDL-7861, this is from <div id=page>
1277 redirect($returnto, get_string("thegradeis", "workshop").": ".
1278 number_format($grade * $workshop->grade / 100, 2).
1279 " (".get_string("maximumgrade")." ".number_format($workshop->grade).")");
1281 else {
1282 redirect($returnto);
1288 /****************** update comment (by author, assessor or teacher) ********************/
1289 elseif ($action == 'updatecomment') {
1290 $timenow = time();
1292 $form = (object)$_POST;
1294 // get the comment record...
1295 if (!$comment = get_record("workshop_comments", "id", $_POST['cid'])) {
1296 error("Update to Comment failed");
1298 if (!$assessment = get_record("workshop_assessments", "id", $comment->assessmentid)) {
1299 error("Update Comment: Assessment not found");
1301 //save the comment for the assessment...
1302 if (isset($form->comments)) {
1303 set_field("workshop_comments", "comments", $form->comments, "id", $comment->id);
1304 set_field("workshop_comments", "timecreated", $timenow, "id", $comment->id);
1305 // ..and kick to comment into life (probably not needed but just in case)
1306 set_field("workshop_comments", "mailed", 0, "id", $comment->id);
1307 echo "<centre><b>".get_string("savedok", "workshop")."</b></div><br />\n";
1309 add_to_log($course->id, "workshop", "comment",
1310 "viewassessment.php?id=$cm->id&amp;aid=$assessment->id", "$comment->id");
1313 print_continue("viewassessment.php?id=$cm->id&amp;aid=$assessment->id");
1317 /****************** update grading (by teacher) ***************************/
1318 elseif ($action == 'updategrading') {
1319 $timenow = time();
1321 require_capability('mod/workshop:manage', $context);
1323 $form = (object)$_POST;
1325 if (!$assessment = get_record("workshop_assessments", "id", $_POST['aid'])) {
1326 error("Update Grading failed");
1328 //save the comment and grade for the assessment
1329 if (isset($form->teachercomment)) {
1330 set_field("workshop_assessments", "teachercomment", $form->teachercomment, "id", $assessment->id);
1331 set_field("workshop_assessments", "gradinggrade", $form->gradinggrade, "id", $assessment->id);
1332 set_field("workshop_assessments", "timegraded", $timenow, "id", $assessment->id);
1333 set_field("workshop_assessments", "mailed", 0, "id", $assessment->id);
1334 set_field("workshop_assessments", "teachergraded", 1, "id", $assessment->id);
1335 echo "<centre><b>".get_string("savedok", "workshop")."</b></centre><br />\n";
1337 add_to_log($course->id, "workshop", "grade",
1338 "viewassessment.php?id=$cm->id&amp;aid=$assessment->id", "$assessment->id", "$cm->id");
1340 redirect($form->redirect);
1344 /****************** view all assessments ***********************/
1345 elseif ($action == 'viewallassessments') {
1347 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
1348 error("View All Assessments: submission record not found");
1351 if ($assessments = workshop_get_assessments($submission)) {
1352 foreach ($assessments as $assessment) {
1353 workshop_print_assessment($workshop, $assessment);
1356 // only called from list all submissions
1357 print_continue("submissions.php?action=listallsubmissions&amp;id=$cm->id");
1360 /*************** no man's land **************************************/
1361 else {
1362 error("Fatal Error: Unknown Action: ".$action."\n");
1364 print_footer($course);