3 /// Library of extra functions and module workshop
5 $WORKSHOP_TYPE = array (0 => get_string('notgraded', 'workshop'),
6 1 => get_string('accumulative', 'workshop'),
7 2 => get_string('errorbanded', 'workshop'),
8 3 => get_string('criterion', 'workshop'),
9 4 => get_string('rubric', 'workshop') );
11 $WORKSHOP_SHOWGRADES = array (0 => get_string('dontshowgrades', 'workshop'),
12 1 => get_string('showgrades', 'workshop') );
14 $WORKSHOP_SCALES = array(
15 0 => array( 'name' => get_string('scaleyes', 'workshop'), 'type' => 'radio',
16 'size' => 2, 'start' => get_string('yes'), 'end' => get_string('no')),
17 1 => array( 'name' => get_string('scalepresent', 'workshop'), 'type' => 'radio',
18 'size' => 2, 'start' => get_string('present', 'workshop'),
19 'end' => get_string('absent', 'workshop')),
20 2 => array( 'name' => get_string('scalecorrect', 'workshop'), 'type' => 'radio',
21 'size' => 2, 'start' => get_string('correct', 'workshop'),
22 'end' => get_string('incorrect', 'workshop')),
23 3 => array( 'name' => get_string('scalegood3', 'workshop'), 'type' => 'radio',
24 'size' => 3, 'start' => get_string('good', 'workshop'),
25 'end' => get_string('poor', 'workshop')),
26 4 => array( 'name' => get_string('scaleexcellent4', 'workshop'), 'type' => 'radio',
27 'size' => 4, 'start' => get_string('excellent', 'workshop'),
28 'end' => get_string('verypoor', 'workshop')),
29 5 => array( 'name' => get_string('scaleexcellent5', 'workshop'), 'type' => 'radio',
30 'size' => 5, 'start' => get_string('excellent', 'workshop'),
31 'end' => get_string('verypoor', 'workshop')),
32 6 => array( 'name' => get_string('scaleexcellent7', 'workshop'), 'type' => 'radio',
33 'size' => 7, 'start' => get_string('excellent', 'workshop'),
34 'end' => get_string('verypoor', 'workshop')),
35 7 => array( 'name' => get_string('scale10', 'workshop'), 'type' => 'selection',
37 8 => array( 'name' => get_string('scale20', 'workshop'), 'type' => 'selection',
39 9 => array( 'name' => get_string('scale100', 'workshop'), 'type' => 'selection',
43 //////////////////////////////////////////////////////////////////////////////////////
45 /*** Functions for the workshop module ******
47 workshop_choose_from_menu ($options, $name, $selected="", $nothing="choose", $script="",
48 $nothingvalue="0", $return=false) {
50 workshop_compare_assessments($workshop, $assessment1, $assessment2) { ---> in lib.php
51 workshop_count_all_submissions_for_assessment($workshop, $user) {
52 workshop_count_assessments($submission) { ---> in lib.php
53 workshop_count_comments($assessment) {
54 workshop_count_peer_assessments($workshop, $user) {
55 workshop_count_self_assessments($workshop, $user) {
56 workshop_count_student_submissions($workshop) {
57 workshop_count_student_submissions_for_assessment($workshop, $user) {
58 workshop_count_teacher_assessments($courseid, $submission) {
59 workshop_count_teacher_assessments_by_user($workshop, $user) {
60 workshop_count_teacher_submissions($workshop) {
61 workshop_count_teacher_submissions_for_assessment($workshop, $user) {
62 workshop_count_ungraded_assessments($workshop) { --->in lib.php
63 workshop_count_ungraded_assessments_student($workshop) {
64 workshop_count_ungraded_assessments_teacher($workshop) {
65 workshop_count_user_assessments($worshop, $user, $type = "all") { $type is all, student or teacher
66 workshop_count_user_submissions($workshop, $user) {
68 workshop_delete_submitted_files($workshop, $submission) {
69 workshop_delete_user_files($workshop, $user, $exception) {
71 workshop_file_area($workshop, $submission) { ---> in lib.php
72 workshop_file_area_name($workshop, $submission) { ---> in lib.php
74 workshop_get_all_teacher_assessments($workshop) {
75 workshop_get_assessments($submission, $all = '') { ---> in lib.php
76 workshop_get_comments($assessment) {
77 workshop_get_participants($workshopid) {
78 workshop_get_student_assessments($workshop, $user) {
79 workshop_get_student_submission($workshop, $user) { ---> in lib.php
80 workshop_get_student_submission_assessments($workshop) {
81 workshop_get_student_submissions($workshop) { ---> in lib.php
82 workshop_get_submission_assessment($submission, $user) {
83 workshop_get_teacher_assessments($courseid, $submission) {
84 workshop_get_teacher_submission_assessments($workshop) {
85 workshop_get_teacher_submissions($workshop) {
86 workshop_get_ungraded_assessments($workshop) {
87 workshop_get_unmailed_assessments($cutofftime) {
88 workshop_get_unmailed_marked_assessments($cutofftime) {
89 workshop_get_user_assessments($workshop, $user) { ---> in lib.php
90 workshop_get_user_submissions($workshop, $user) { ---> in lib.php
91 workshop_get_users_done($workshop) {
93 workshop_grade_assessments($workshop) { ---> in lib.php
95 workshop_list_all_submissions($workshop) {
96 workshop_list_all_ungraded_assessments($workshop) {
97 workshop_list_assessed_submissions($workshop, $user) {
98 workshop_list_peer_assessments($workshop, $user) {
99 workshop_list_student_submissions($workshop, $user) {
100 workshop_list_submissions_for_admin($workshop, $order) {
101 workshop_list_teacher_assessments_by_user($workshop, $user) {
102 workshop_list_teacher_submissions($workshop) {
103 workshop_list_unassessed_student_submissions($workshop, $user) {
104 workshop_list_unassessed_teacher_submissions($workshop, $user) {
105 workshop_list_ungraded_assessments($workshop, $stype) {
106 workshop_list_user_submissions($workshop, $user) {
108 workshop_calculate_phase($workshop, $style='') {
110 workshop_print_assessment($workshop, $assessment, $allowchanges, $showcommentlinks, $returnto)
111 workshop_print_assessments_by_user_for_admin($workshop, $user) {
112 workshop_print_assessments_for_admin($workshop, $submission) {
113 workshop_print_assignment_info($cm, $workshop) {
114 workshop_print_difference($time) {
115 workshop_print_feedback($course, $submission) {
116 workshop_print_league_table($workshop) {
117 workshop_print_submission_assessments($workshop, $submission, $type) {
118 workshop_print_submission_title($workshop, $user) {
119 workshop_print_time_to_deadline($time) {
120 workshop_print_upload_form($workshop) {
121 workshop_print_user_assessments($workshop, $user) {
123 workshop_submission_grade($submission) { ---> in lib.php
125 workshop_test_user_assessments($workshop, $user) {
126 ***************************************/
129 ///////////////////////////////////////////////////////////////////////////////
130 function workshop_choose_from_menu ($options, $name, $selected="", $nothing="choose", $script="",
131 $nothingvalue="0", $return=false) {
132 /// Given an array of value, creates a popup menu to be part of a form
133 /// $options["value"]["label"]
135 if ($nothing == "choose") {
136 $nothing = get_string("choose")."...";
140 $javascript = "onChange=\"$script\"";
145 $output = "<select name=\"$name\" $javascript>\n";
147 $output .= " <option value=\"$nothingvalue\"\n";
148 if ($nothingvalue == $selected) {
149 $output .= " selected=\"selected\"";
151 $output .= ">$nothing</option>\n";
153 if (!empty($options)) {
154 foreach ($options as $value => $label) {
155 $output .= " <option value=\"$value\"";
156 if ($value == $selected) {
157 $output .= " selected=\"selected\"";
159 // stop zero label being replaced by array index value
161 // $output .= ">$label</option>\n";
163 // $output .= ">$value</option>\n";
165 $output .= ">$label</option>\n";
169 $output .= "</select>\n";
179 ///////////////////////////////////////////////////////////////////////////////////////////////
180 function workshop_copy_assessment($assessment, $submission, $withfeedback = false) {
181 // adds a copy of the given assessment for the submission specified to the workshop_assessments table.
182 // The grades and optionally the comments are added to the workshop_grades table. Returns the new
183 // assessment object. The owner of the assessment is not changed.
185 $yearfromnow = time() +
365 * 86400;
186 $newassessment->workshopid
= $assessment->workshopid
;
187 $newassessment->submissionid
= $submission->id
;
188 $newassessment->userid
= $assessment->userid
;
189 $newassessment->timecreated
= $yearfromnow;
190 $newassessment->grade
= $assessment->grade
;
192 $newassessment->generalcomment
= addslashes($assessment->generalcomment
);
193 $newassessment->teachercomment
= addslashes($assessment->teachercomment
);
195 if (!$newassessment->id
= insert_record("workshop_assessments", $newassessment)) {
196 error("Copy Assessment: Could not insert workshop assessment!");
199 if ($grades = get_records("workshop_grades", "assessmentid", $assessment->id
)) {
200 foreach ($grades as $grade) {
201 unset($grade->id
); // clear id, insert record now seems to believe it!
202 if (!$withfeedback) {
203 $grade->feedback
= '';
206 $grade->feedback
= addslashes($grade->feedback
);
208 $grade->assessmentid
= $newassessment->id
;
209 if (!$grade->id
= insert_record("workshop_grades", $grade)) {
210 error("Copy Assessment: Could not insert workshop grade!");
215 // remove the slashes from comments as the new assessment record might be used,
216 // currently this function is only called in upload which does not!
217 $newassessment->generalcomment
= stripslashes($assessment->generalcomment
);
218 $newassessment->teachercomment
= stripslashes($assessment->teachercomment
);
220 return $newassessment;
225 //////////////////////////////////////////////////////////////////////////////////////
226 function workshop_count_all_submissions_for_assessment($workshop, $user) {
227 // looks at all submissions and deducts the number which has been assessed by this user
229 if ($submissions = get_records_select("workshop_submissions", "workshopid = $workshop->id AND
231 $n =count($submissions);
232 foreach ($submissions as $submission) {
233 $n -= count_records("workshop_assessments", "submissionid", $submission->id
, "userid", $user->id
);
240 //////////////////////////////////////////////////////////////////////////////////////
241 function workshop_count_comments($assessment) {
242 // Return the number of comments for this assessment provided they are newer than the assessment,
243 return count_records_select("workshop_comments", "(assessmentid = $assessment->id) AND
244 timecreated > $assessment->timecreated");
248 //////////////////////////////////////////////////////////////////////////////////////
249 function workshop_count_peer_assessments($workshop, $user) {
250 // returns the number of assessments made by students on user's submissions
253 if ($submissions = workshop_get_user_submissions($workshop, $user)) {
254 foreach ($submissions as $submission) {
255 if ($assessments = workshop_get_assessments($submission)) {
256 foreach ($assessments as $assessment) {
257 // ignore teacher assessments
258 if (!workshop_is_teacher($workshop, $assessment->userid
)) {
269 //////////////////////////////////////////////////////////////////////////////////////
270 function workshop_count_self_assessments($workshop, $user) {
271 // returns the number of assessments made by user on their own submissions
274 if ($submissions = workshop_get_user_submissions($workshop, $user)) {
275 foreach ($submissions as $submission) {
276 if ($assessment = get_record_select("workshop_assessments", "userid = $user->id AND
277 submissionid = $submission->id")) {
286 //////////////////////////////////////////////////////////////////////////////////////
287 function workshop_count_student_submissions($workshop) {
290 // make sure it works on the site course
291 $select = "s.course = '$workshop->course' AND";
292 if ($workshop->course
== SITEID
) {
295 if (!$students = workshop_get_students($workshop)) {
299 foreach ($students as $student) {
300 $list .= "$student->id,";
302 $list = rtrim($list, ',').")";
304 return count_records_sql("SELECT count(*) FROM {$CFG->prefix}workshop_submissions s
305 WHERE $select s.userid IN $list
306 AND s.workshopid = $workshop->id
307 AND timecreated > 0");
311 //////////////////////////////////////////////////////////////////////////////////////
312 function workshop_count_student_submissions_for_assessment($workshop, $user) {
315 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
316 error("Course Module ID was incorrect");
318 if (! $course = get_record("course", "id", $workshop->course
)) {
319 error("Course is misconfigured");
323 if (groupmode($course, $cm) == SEPARATEGROUPS
) {
324 $groupid = get_current_group($course->id
);
330 if ($submissions = workshop_get_student_submissions($workshop)) {
331 foreach ($submissions as $submission) {
332 // check group membership, if necessary
334 // check user's group
335 if (!ismember($groupid, $submission->userid
)) {
336 continue; // skip this user
339 // check if submission is cold
340 if (($submission->timecreated +
$CFG->maxeditingtime
) > $timenow) {
341 continue; // skip this submission
343 // has any teacher assessed this submission?
344 if (!workshop_count_teacher_assessments($course->id
, $submission)) {
353 //////////////////////////////////////////////////////////////////////////////////////
354 function workshop_count_teacher_assessments($courseid, $submission) {
355 // Return count of (cold) teacher assessments of a submission
358 if (!$teachers = workshop_get_teachers($submission->workshopid
)) {
362 foreach ($teachers as $teacher) {
363 $list .= "$teacher->id,";
365 $list = rtrim($list, ',').")";
367 return count_records_sql("SELECT count(*) FROM {$CFG->prefix}workshop_assessments a
368 WHERE a.userid IN $list
369 AND a.submissionid = $submission->id
370 AND $timenow > (a.timecreated + $CFG->maxeditingtime)");
374 //////////////////////////////////////////////////////////////////////////////////////
375 function workshop_count_teacher_assessments_by_user($workshop, $user) {
376 // returns the number of assessments made by teachers on user's submissions
379 if ($submissions = workshop_get_user_submissions($workshop, $user)) {
380 foreach ($submissions as $submission) {
381 if ($assessments = workshop_get_assessments($submission)) {
382 foreach ($assessments as $assessment) {
383 // count only teacher assessments
384 if (workshop_is_teacher($workshop, $assessment->userid
)) {
395 //////////////////////////////////////////////////////////////////////////////////////
396 function workshop_count_teacher_submissions($workshop) {
398 if (!$teachers = workshop_get_teachers($workshop)) {
402 foreach ($teachers as $teacher) {
403 $list .= "$teacher->id,";
405 $list = rtrim($list, ',').")";
408 return count_records_sql("SELECT count(*)
409 FROM {$CFG->prefix}workshop_submissions s
410 WHERE s.userid IN $list
411 AND s.workshopid = $workshop->id");
415 //////////////////////////////////////////////////////////////////////////////////////
416 function workshop_count_teacher_submissions_for_assessment($workshop, $user) {
419 if ($submissions = workshop_get_teacher_submissions($workshop)) {
420 $n =count($submissions);
421 foreach ($submissions as $submission) {
422 $n -= count_records("workshop_assessments", "submissionid", $submission->id
, "userid", $user->id
);
429 //////////////////////////////////////////////////////////////////////////////////////
430 function workshop_count_ungraded_assessments_student($workshop) {
431 // function returns the number of ungraded assessments by students of STUDENT submissions
433 if ($submissions = workshop_get_student_submissions($workshop)) {
434 foreach ($submissions as $submission) {
435 if ($assessments = workshop_get_assessments($submission)) {
436 foreach ($assessments as $assessment) {
437 if ($assessment->timegraded
== 0) {
438 // ignore teacher assessments
439 if (!workshop_is_teacher($workshop, $assessment->userid
)) {
451 //////////////////////////////////////////////////////////////////////////////////////
452 function workshop_count_ungraded_assessments_teacher($workshop) {
453 // function returns the number of ungraded assessments by students of TEACHER submissions
458 if ($submissions = workshop_get_teacher_submissions($workshop)) {
459 foreach ($submissions as $submission) {
460 if ($assessments = workshop_get_assessments($submission)) {
461 foreach ($assessments as $assessment) {
462 if ($assessment->timegraded
== 0) {
463 // ignore teacher assessments
464 if (!workshop_is_teacher($workshop, $assessment->userid
)) {
465 // must have created a little time ago
466 if (($timenow - $assessment->timecreated
) > $CFG->maxeditingtime
) {
479 //////////////////////////////////////////////////////////////////////////////////////
480 function workshop_count_user_assessments($workshop, $user, $stype = "all") {
481 // returns the number of assessments allocated/made by a user, all of them, or just those
482 // for the student or teacher submissions. The student's self assessments are included in the count.
483 // The maxeditingtime is NOT taken into account here also, allocated assessments which have not yet
484 // been done are counted as well
487 if ($assessments = workshop_get_user_assessments($workshop, $user)) {
488 foreach ($assessments as $assessment) {
494 $submission = get_record("workshop_submissions", "id", $assessment->submissionid
);
495 if (workshop_is_student($workshop, $submission->userid
)) {
500 $submission = get_record("workshop_submissions", "id", $assessment->submissionid
);
501 if (workshop_is_teacher($workshop, $submission->userid
)) {
512 //////////////////////////////////////////////////////////////////////////////////////
513 function workshop_count_user_assessments_done($workshop, $user) {
514 // returns the number of assessments actually done by a user
515 // the student's self assessments are included in the count
516 // the maxeditingtime is NOT taken into account here
520 if ($assessments = workshop_get_user_assessments($workshop, $user)) {
521 foreach ($assessments as $assessment) {
522 if ($assessment->timecreated
< $timenow) {
531 //////////////////////////////////////////////////////////////////////////////////////
532 function workshop_count_user_submissions($workshop, $user) {
533 // returns the number of (real) submissions make by this user
534 return count_records_select("workshop_submissions", "workshopid = $workshop->id AND
535 userid = $user->id AND timecreated > 0");
539 //////////////////////////////////////////////////////////////////////////////////////
540 function workshop_delete_submitted_files($workshop, $submission) {
541 // Deletes the files in the workshop area for this submission
543 if ($basedir = workshop_file_area($workshop, $submission)) {
544 if ($files = get_directory_list($basedir)) {
545 foreach ($files as $file) {
546 if (unlink("$basedir/$file")) {
547 notify("Existing file '$file' has been deleted!");
550 notify("Attempt to delete file $basedir/$file has failed!");
558 //////////////////////////////////////////////////////////////////////////////////////
559 function workshop_delete_user_files($workshop, $user, $exception) {
560 // Deletes all the user files in the workshop area for a user
561 // EXCEPT for any file named $exception
563 if (!$submissions = workshop_get_submissions($workshop, $user)) {
564 notify("No submissions!");
567 foreach ($submissions as $submission) {
568 if ($basedir = workshop_file_area($workshop, $submission)) {
569 if ($files = get_directory_list($basedir)) {
570 foreach ($files as $file) {
571 if ($file != $exception) {
572 unlink("$basedir/$file");
573 notify("Existing file '$file' has been deleted!");
582 //////////////////////////////////////////////////////////////////////////////////////
583 function workshop_get_all_teacher_assessments($workshop) {
584 // Return all teacher assessments, ordered by timecreated, oldest first
586 if (!$teachers = workshop_get_teachers($workshop)) {
590 foreach ($teachers as $teacher) {
591 $list .= "$teacher->id,";
593 $list = rtrim($list, ',').")";
595 return get_records_sql("SELECT a.* FROM {$CFG->prefix}workshop_assessments a
596 WHERE a.userid IN $list
597 AND a.workshopid = $workshop->id
598 ORDER BY a.timecreated");
602 //////////////////////////////////////////////////////////////////////////////////////
603 function workshop_get_comments($assessment) {
604 // Return all comments for this assessment provided they are newer than the assessment,
605 // and ordered oldest first, newest last
606 return get_records_select("workshop_comments", "(assessmentid = $assessment->id) AND
607 timecreated > $assessment->timecreated",
612 //////////////////////////////////////////////////////////////////////////////////////
613 function workshop_get_student_assessments($workshop, $user) {
614 // Return all assessments on the student submissions by a user, order by youngest first, oldest last
617 if (!workshop_is_student($workshop, $user->id
)) {
621 return get_records_sql("SELECT a.* FROM {$CFG->prefix}workshop_submissions s, {$CFG->prefix}workshop_assessments a
622 WHERE s.workshopid = $workshop->id
623 AND a.submissionid = s.id
624 AND a.userid = $user->id
625 ORDER BY a.timecreated DESC");
629 //////////////////////////////////////////////////////////////////////////////////////
630 function workshop_get_student_submission_assessments($workshop) {
631 // Return all assessments on the student submissions, order by youngest first, oldest last
635 if (!$students = workshop_get_students($workshop)) {
639 foreach ($students as $student) {
640 $list .= "$student->id,";
642 $list = rtrim($list, ',').")";
644 return get_records_sql("SELECT a.* FROM {$CFG->prefix}workshop_submissions s, {$CFG->prefix}workshop_assessments a
645 WHERE s.userid IN $list
646 AND s.workshopid = $workshop->id
647 AND a.submissionid = s.id
648 ORDER BY a.timecreated DESC");
652 //////////////////////////////////////////////////////////////////////////////////////
653 function workshop_get_submission_assessment($submission, $user) {
654 // Return the user's assessment for this submission (cold or warm, not hot)
657 return get_record_select("workshop_assessments", "submissionid = $submission->id AND
658 userid = $user->id AND timecreated < $timenow");
662 //////////////////////////////////////////////////////////////////////////////////////
663 function workshop_get_teacher_assessments($courseid, $submission) {
664 // Return teacher assessments of a submission, ordered by timecreated, oldest first
667 if (!$teachers = workshop_get_teachers($submission->workshopid
)) {
671 foreach ($teachers as $teacher) {
672 $list .= "$teacher->id,";
674 $list = rtrim($list, ',').")";
675 return get_records_sql("SELECT a.* FROM {$CFG->prefix}workshop_assessments a
676 WHERE a.userid IN $list
677 AND a.submissionid = $submission->id
678 ORDER BY a.timecreated");
682 //////////////////////////////////////////////////////////////////////////////////////
683 function workshop_get_teacher_submission_assessments($workshop) {
684 // Return all assessments on the teacher submissions, order by youngest first, oldest last
687 if (!$teachers = workshop_get_teachers($workshop)) {
691 foreach ($teachers as $teacher) {
692 $list .= "$teacher->id,";
694 $list = rtrim($list, ',').")";
695 return get_records_sql("SELECT a.* FROM {$CFG->prefix}workshop_submissions s, {$CFG->prefix}workshop_assessments a
696 WHERE s.userid IN $list
697 AND s.workshopid = $workshop->id
698 AND a.submissionid = s.id
699 ORDER BY a.timecreated DESC");
703 //////////////////////////////////////////////////////////////////////////////////////
704 function workshop_get_teacher_submissions($workshop) {
705 // Return all teacher submissions, ordered by title
708 if (!$teachers = workshop_get_teachers($workshop)) {
712 foreach ($teachers as $teacher) {
713 $list .= "$teacher->id,";
715 $list = rtrim($list, ',').")";
716 return get_records_sql("SELECT s.* FROM {$CFG->prefix}workshop_submissions s
717 WHERE s.userid IN $list
718 AND s.workshopid = $workshop->id
723 //////////////////////////////////////////////////////////////////////////////////////
724 function workshop_get_ungraded_assessments($workshop) {
726 // Return all assessments which have not been graded or just graded
727 $cutofftime = time() - $CFG->maxeditingtime
;
728 return get_records_select("workshop_assessments", "workshopid = $workshop->id AND (timegraded = 0 OR
729 timegraded > $cutofftime)", "timecreated");
733 //////////////////////////////////////////////////////////////////////////////////////
734 function workshop_get_ungraded_assessments_student($workshop) {
736 // Return all assessments which have not been graded or just graded of student's submissions
738 $cutofftime = time() - $CFG->maxeditingtime
;
740 if (!$students = workshop_get_students($workshop)) {
744 foreach ($students as $student) {
745 $list .= "$student->id,";
747 $list = rtrim($list, ',').")";
748 return get_records_sql("SELECT a.* FROM {$CFG->prefix}workshop_submissions s, {$CFG->prefix}workshop_assessments a
749 WHERE s.userid IN $list
750 AND s.workshopid = $workshop->id
751 AND a.submissionid = s.id
752 AND (a.timegraded = 0 OR a.timegraded > $cutofftime)
753 AND a.timecreated < $cutofftime
754 ORDER BY a.timecreated ASC");
758 //////////////////////////////////////////////////////////////////////////////////////
759 function workshop_get_ungraded_assessments_teacher($workshop) {
761 // Return all assessments which have not been graded or just graded of teacher's submissions
763 $cutofftime =time() - $CFG->maxeditingtime
;
764 if (!$teachers = workshop_get_teachers($workshop)) {
768 foreach ($teachers as $teacher) {
769 $list .= "$teacher->id,";
771 $list = rtrim($list, ',').")";
772 return get_records_sql("SELECT a.* FROM {$CFG->prefix}workshop_submissions s, {$CFG->prefix}workshop_assessments a
773 WHERE s.userid IN $list
774 AND s.workshopid = $workshop->id
775 AND a.submissionid = s.id
776 AND (a.timegraded = 0 OR a.timegraded > $cutofftime)
777 AND a.timecreated < $cutofftime
778 ORDER BY a.timecreated ASC");
782 //////////////////////////////////////////////////////////////////////////////////////
783 function workshop_get_user_assessments_done($workshop, $user) {
784 // Return all the user's assessments, oldest first, newest last (warm and cold ones only)
785 // ignores maxeditingtime
787 return get_records_select("workshop_assessments", "workshopid = $workshop->id AND userid = $user->id
788 AND timecreated < $timenow",
793 //////////////////////////////////////////////////////////////////////////////////////
794 function workshop_get_users_done($workshop) {
797 // make sure it works on the site course
798 $select = "s.course = '$workshop->course' AND";
799 if ($workshop->course
== SITEID
) {
803 if (!$students = workshop_get_students($workshop)) {
807 foreach ($students as $student) {
808 $list .= "$student->id,";
810 $list = rtrim($list, ',').")";
812 return get_records_sql("SELECT u.* FROM {$CFG->prefix}user u, {$CFG->prefix}workshop_submissions a
813 WHERE $select u.user IN $list
814 AND u.id = a.user AND a.workshop = '$workshop->id'
815 ORDER BY a.timemodified DESC");
819 //////////////////////////////////////////////////////////////////////////////////////
820 function workshop_list_all_submissions($workshop, $user) {
821 // list the teacher sublmissions first
824 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
825 error("Course Module ID was incorrect");
827 if (! $course = get_record("course", "id", $workshop->course
)) {
828 error("Course is misconfigured");
830 $table->head
= array (get_string("title", "workshop"), get_string("action", "workshop"),
831 get_string("comment", "workshop"));
832 $table->align
= array ("left", "left", "left");
833 $table->size
= array ("*", "*", "*");
834 $table->cellpadding
= 2;
835 $table->cellspacing
= 0;
837 if ($submissions = workshop_get_teacher_submissions($workshop)) {
838 foreach ($submissions as $submission) {
839 if ($submission->userid
== $user->id
) {
840 $comment = get_string("ownwork", "workshop")."; ";
845 // has user already assessed this submission
846 if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id
847 AND userid = $user->id")) {
849 if (($curtime - $assessment->timecreated
) > $CFG->maxeditingtime
) {
850 $action = "<a href=\"viewassessment.php?id=$cm->id&aid=$assessment->id\">"
851 .get_string("view", "workshop")."</a>";
852 // has teacher graded user's assessment?
853 if ($assessment->timegraded
) {
854 if (($curtime - $assessment->timegraded
) > $CFG->maxeditingtime
) {
855 $comment .= get_string("gradedbyteacher", "workshop", $course->teacher
);
859 else { // there's still time left to edit...
860 $action = "<a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
861 get_string("edit", "workshop")."</a>";
864 else { // user has not graded this submission
865 $action = "<a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
866 get_string("assess", "workshop")."</a>";
868 $table->data
[] = array(workshop_print_submission_title($workshop, $submission), $action,
874 echo "<div style=\"text-align:center;\"><p><b>".get_string("studentsubmissions", "workshop", $course->student
).
875 "</b></div><br />\n";
877 $table->head
= array (get_string("title", "workshop"), get_string("action", "workshop"),
878 get_string("comment", "workshop"));
879 $table->align
= array ("left", "left", "left");
880 $table->size
= array ("*", "*", "*");
881 $table->cellpadding
= 2;
882 $table->cellspacing
= 0;
884 if ($submissions = workshop_get_student_submissions($workshop)) {
885 foreach ($submissions as $submission) {
886 if ($submission->userid
== $user->id
) {
887 $comment = get_string("ownwork", "workshop")."; ";
892 // has user already assessed this submission
893 if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id
894 AND userid = $user->id")) {
896 if (($curtime - $assessment->timecreated
) > $CFG->maxeditingtime
) {
897 $action = "<a href=\"viewassessment.php?id=$cm->id&aid=$assessment->id\">".
898 get_string("view", "workshop")."</a>";
899 // has teacher graded on user's assessment?
900 if ($assessment->timegraded
) {
901 if (($curtime - $assessment->timegraded
) > $CFG->maxeditingtime
) {
902 $comment .= get_string("gradedbyteacher", "workshop", $course->teacher
)."; ";
905 $otherassessments = workshop_get_assessments($submission);
906 if (count($otherassessments) > 1) {
907 $comment .= "<a href=\"assessments.php?action=viewallassessments&id=$cm->id&sid=$submission->id\">".
908 get_string("viewotherassessments", "workshop")."</a>";
911 else { // there's still time left to edit...
912 $action = "<a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
913 get_string("edit", "workshop")."</a>";
916 else { // user has not assessed this submission
917 $action = "<a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
918 get_string("assess", "workshop")."</a>";
920 $table->data
[] = array(workshop_print_submission_title($workshop, $submission), $action,
928 //////////////////////////////////////////////////////////////////////////////////////
929 function workshop_list_all_ungraded_assessments($workshop) {
930 // lists all the assessments for comment by teacher
933 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
934 error("Course Module ID was incorrect");
937 $table->head
= array (get_string("title", "workshop"), get_string("timeassessed", "workshop"), get_string("action", "workshop"));
938 $table->align
= array ("left", "left", "left");
939 $table->size
= array ("*", "*", "*");
940 $table->cellpadding
= 2;
941 $table->cellspacing
= 0;
944 if ($assessments = workshop_get_ungraded_assessments($workshop)) {
945 foreach ($assessments as $assessment) {
946 if (!workshop_is_teacher($workshop, $assessment->userid
)) {
947 if (($timenow - $assessment->timegraded
) < $CFG->maxeditingtime
) {
948 $action = "<a href=\"viewassessment.php?&id=$cm->id&aid=$assessment->id\">".
949 get_string("edit", "workshop")."</a>";
952 $action = "<a href=\"viewassessment.php?&id=$cm->id&aid=$assessment->id\">".
953 get_string("gradeassessment", "workshop")."</a>";
955 $submission = get_record("workshop_submissions", "id", $assessment->submissionid
);
956 $table->data
[] = array(workshop_print_submission_title($workshop, $submission),
957 userdate($assessment->timecreated
), $action);
960 if (isset($table->data
)) {
967 //////////////////////////////////////////////////////////////////////////////////////
968 function workshop_list_assessed_submissions($workshop, $user) {
969 // list the submissions that have been assessed by this user and are COLD
973 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
974 error("Course Module ID was incorrect");
976 if (! $course = get_record("course", "id", $workshop->course
)) {
977 error("Course is misconfigured");
979 $table->head
= array (get_string("title","workshop"), get_string("action","workshop"),
980 get_string("comment","workshop"));
981 $table->align
= array ("left", "left", "left");
982 $table->size
= array ("*", "*", "*");
983 $table->cellpadding
= 2;
984 $table->cellspacing
= 0;
986 if ($assessments = workshop_get_student_assessments($workshop, $user)) {
987 foreach ($assessments as $assessment) {
989 $submission = get_record("workshop_submissions", "id", $assessment->submissionid
);
990 // the assessment may be in three states:
991 // 1. "hot", just created but not completed (timecreated is in the future)
992 // 2. "warm" just created and still capable of being edited, and
993 // 3. "cold" after the editing time
995 if ($assessment->timecreated
< ($timenow - $CFG->maxeditingtime
)) { // it's cold
996 if ($workshop->agreeassessments
) {
997 if (!$assessment->timeagreed
) {
998 $action = "<a href=\"viewassessment.php?id=$cm->id&aid=$assessment->id&".
999 "allowcomments=$workshop->agreeassessments\">".
1000 get_string("view", "workshop")."</a>";
1001 $action .= " | <a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1002 get_string("reassess", "workshop")."</a>";
1004 $action = "<a href=\"viewassessment.php?id=$cm->id&aid=$assessment->id&".
1005 "allowcomments=false\">".get_string("view", "workshop")."</a>";
1008 // if it been graded allow student to re-assess, except if it's a self assessment
1009 if ($assessment->timegraded
and !($USER->id
== $assessment->userid
)) {
1010 $action = "<a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1011 get_string("reassess", "workshop")."</a>";
1013 $action = "<a href=\"viewassessment.php?id=$cm->id&aid=$assessment->id\">".
1014 get_string("view", "workshop")."</a>";
1017 if ($assessment->timecreated
< $timenow) { // only show the date if it's in the past (future dates cause confusion)
1018 $comment = get_string("assessedon", "workshop", userdate($assessment->timecreated
));
1023 if ($submission->userid
== $user->id
) { // self assessment?
1024 $comment .= "; ".get_string("ownwork", "workshop"); // just in case they don't know!
1026 // has assessment been graded?
1027 if ($assessment->timegraded
and ($timenow - $assessment->timegraded
> $CFG->maxeditingtime
)) {
1028 if ($workshop->gradingstrategy
) { // supress grading grade if not graded
1029 $comment .= "; ".get_string("thegradeforthisassessmentis", "workshop",
1030 number_format($assessment->gradinggrade
* $workshop->gradinggrade
/ 100, 0)).
1031 " / $workshop->gradinggrade";
1034 // if peer agreements show whether agreement has been reached
1035 if ($workshop->agreeassessments
) {
1036 if ($assessment->timeagreed
) {
1037 $comment .= "; ".get_string("assessmentwasagreedon", "workshop",
1038 userdate($assessment->timeagreed
));
1041 $comment .= "; ".get_string("assessmentnotyetagreed", "workshop");
1044 $table->data
[] = array(workshop_print_submission_title($workshop, $submission), $action,
1049 if (isset($table->data
)) {
1050 print_table($table);
1053 echo "<div style=\"text-align:center;\">".get_string("noassessmentsdone", "workshop")."</div>\n";
1059 //////////////////////////////////////////////////////////////////////////////////////
1060 function workshop_list_peer_assessments($workshop, $user) {
1063 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
1064 error("Course Module ID was incorrect");
1066 if (! $course = get_record("course", "id", $workshop->course
)) {
1067 error("Course is misconfigured");
1069 $table->head
= array (get_string("title", "workshop"), get_string("action", "workshop"),
1070 get_string("comment", "workshop"));
1071 $table->align
= array ("left", "left", "left");
1072 $table->size
= array ("*", "*", "*");
1073 $table->cellpadding
= 2;
1074 $table->cellspacing
= 0;
1076 // get user's submissions
1077 if ($submissions = workshop_get_user_submissions($workshop, $user)) {
1078 foreach ($submissions as $submission) {
1079 // get the assessments
1080 if ($assessments = workshop_get_assessments($submission)) {
1081 foreach ($assessments as $assessment) {
1082 // assessments by students only and exclude any self assessments
1083 if (workshop_is_student($workshop, $assessment->userid
) and
1084 ($assessment->userid
!= $user->id
)) {
1086 if (($timenow - $assessment->timecreated
) > $CFG->maxeditingtime
) {
1087 $action = "<a href=\"viewassessment.php?id=$cm->id&aid=$assessment->id&".
1088 "allowcomments=$workshop->agreeassessments\">".
1089 get_string("view", "workshop")."</a>";
1090 $comment = get_string("assessedon", "workshop", userdate($assessment->timecreated
));
1091 $grade = number_format($assessment->grade
* $workshop->grade
/ 100, 1);
1092 if ($workshop->gradingstrategy
) { // supress grade if not graded
1093 $comment .= "; ".get_string("gradeforsubmission", "workshop").
1094 ": $grade / $workshop->grade";
1096 if ($assessment->timegraded
) {
1097 if (!$assessment->gradinggrade
) {
1098 // it's a bad assessment
1099 $comment .= "; ".get_string("thisisadroppedassessment", "workshop");
1102 if (workshop_is_teacher($workshop, $assessment->userid
) and $workshop->teacherweight
) {
1103 $comment .= "; ".get_string("thisisadroppedassessment", "workshop");
1105 // if peer agreements show whether agreement has been reached
1106 if ($workshop->agreeassessments
) {
1107 if ($assessment->timeagreed
) {
1108 $comment .= "; ".get_string("assessmentwasagreedon", "workshop",
1109 userdate($assessment->timeagreed
));
1112 $comment .= "; ".get_string("assessmentnotyetagreed", "workshop");
1115 $table->data
[] = array(workshop_print_submission_title($workshop, $submission),
1123 if (isset($table->data
)) {
1124 print_table($table);
1127 echo "<div style=\"text-align:center;\">".get_string("noassessmentsdone", "workshop")."</div>\n";
1133 //////////////////////////////////////////////////////////////////////////////////////
1134 function workshop_list_self_assessments($workshop, $user) {
1135 // list user's submissions for the user to assess
1139 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
1140 error("Course Module ID was incorrect");
1142 if (! $course = get_record("course", "id", $workshop->course
)) {
1143 error("Course is misconfigured");
1145 $table->head
= array (get_string("title", "workshop"), get_string("action", "workshop"),
1146 get_string("comment", "workshop"));
1147 $table->align
= array ("left", "left", "left");
1148 $table->size
= array ("*", "*", "*");
1149 $table->cellpadding
= 2;
1150 $table->cellspacing
= 0;
1152 // get the user's submissions
1153 if ($submissions = workshop_get_user_submissions($workshop, $user)) {
1154 foreach ($submissions as $submission) {
1155 $comment = get_string("ownwork", "workshop"); // just in case they don't know!
1156 if (!$assessment = get_record_select("workshop_assessments", "submissionid = $submission->id AND
1157 userid = $user->id")) {
1158 $action = "<a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1159 get_string("assess", "workshop")."</a>";
1160 $table->data
[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment);
1162 // may still be warm
1163 if (($assessment->timecreated +
$CFG->maxeditingtime
) > $timenow) {
1164 $action = "<a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1165 get_string("reassess", "workshop")."</a>";
1166 $table->data
[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment);
1172 if (isset($table->data
)) {
1173 echo "<p><div style=\"text-align:center;\"><b>".get_string("pleaseassessyoursubmissions", "workshop", $course->student
).
1174 "</b></div><br />\n";
1175 print_table($table);
1180 //////////////////////////////////////////////////////////////////////////////////////
1181 function workshop_list_student_submissions($workshop, $user) {
1182 // list available submissions for this user to assess, submissions with the least number
1183 // of assessments are show first
1186 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
1187 error("Course Module ID was incorrect");
1189 if (! $course = get_record("course", "id", $workshop->course
)) {
1190 error("Course is misconfigured");
1195 // set student's group if workshop is in SEPARATEGROUPS mode
1196 if (groupmode($course, $cm) == SEPARATEGROUPS
) {
1197 $groupid = get_current_group($course->id
);
1202 $table->head
= array (get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop"));
1203 $table->align
= array ("left", "left", "left");
1204 $table->size
= array ("*", "*", "*");
1205 $table->cellpadding
= 2;
1206 $table->cellspacing
= 0;
1208 // get the number of assessments this user has done on student submission, deduct self assessments
1209 $nassessed = workshop_count_user_assessments($workshop, $user, "student") -
1210 workshop_count_self_assessments($workshop, $user);
1211 // user hasn't been allocated enough, try and get some more
1212 if ($nassessed < $workshop->nsassessments
) {
1213 // count the number of assessments for each student submission
1214 if ($submissions = workshop_get_student_submissions($workshop)) {
1215 // srand ((float)microtime()*1000000); // now done automatically in PHP 4.2.0->
1216 foreach ($submissions as $submission) {
1217 // check group membership, if necessary
1219 // check user's group
1220 if (!ismember($groupid, $submission->userid
)) {
1221 continue; // skip this submission
1224 // process only cold submissions
1225 if (($submission->timecreated +
$CFG->maxeditingtime
) > $timenow) {
1228 $n = count_records("workshop_assessments", "submissionid", $submission->id
);
1229 // ...OK to have zero, we add a small random number to randomise things
1230 $nassessments[$submission->id
] = $n +
rand(0, 98) / 100;
1233 if (isset($nassessments)) { // make sure we end up with something to play with
1234 // put the submissions with the lowest number of assessments first
1235 asort($nassessments);
1236 reset($nassessments);
1237 $nsassessments = $workshop->nsassessments
;
1238 foreach ($nassessments as $submissionid =>$n) {
1239 // only use those submissions which fall below the allocation threshold
1240 if ($n < ($workshop->nsassessments +
$workshop->overallocation
)) {
1242 $submission = get_record("workshop_submissions", "id", $submissionid);
1243 // skip submission if it belongs to this user
1244 if ($submission->userid
!= $user->id
) {
1245 // add a "hot" assessment record if user has NOT already assessed this submission
1246 if (!get_record("workshop_assessments", "submissionid", $submission->id
, "userid",
1248 $yearfromnow = time() +
365 * 86400;
1249 // ...create one and set timecreated way in the future, this is reset when record is updated
1250 unset($assessment); // clear previous version object (if any)
1251 $assessment->workshopid
= $workshop->id
;
1252 $assessment->submissionid
= $submission->id
;
1253 $assessment->userid
= $user->id
;
1254 $assessment->grade
= -1; // set impossible grade
1255 $assessment->timecreated
= $yearfromnow;
1256 if (!$assessment->id
= insert_record("workshop_assessments", $assessment)) {
1257 error("List Student submissions: Could not insert workshop assessment!");
1260 // is user up to quota?
1261 if ($nassessed == $nsassessments) {
1271 // now list the student submissions this user has been allocated, list only the hot and warm ones,
1272 // the cold ones are listed in the "your assessments list" (_list_assessed submissions)
1273 if ($assessments = workshop_get_user_assessments($workshop, $user)) {
1275 foreach ($assessments as $assessment) {
1276 if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid
)) {
1277 error ("workshop_list_student_submissions: unable to get submission");
1279 // submission from a student?
1280 if (workshop_is_student($workshop, $submission->userid
)) {
1282 // user assessment has three states: record created but not assessed (date created in the future) [hot];
1283 // just assessed but still editable [warm]; and "static" (may or may not have been graded by teacher, that
1284 // is shown in the comment) [cold]
1285 if ($assessment->timecreated
> $timenow) { // user needs to assess this submission
1286 $action = "<a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1287 get_string("assess", "workshop")."</a>";
1288 $table->data
[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment);
1290 elseif ($assessment->timecreated
> ($timenow - $CFG->maxeditingtime
)) { // there's still time left to edit...
1291 $action = "<a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1292 get_string("edit", "workshop")."</a>";
1293 $table->data
[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment);
1299 if (isset($table->data
)) {
1300 echo "<p><div style=\"text-align:center;\"><b>".get_string("pleaseassessthesestudentsubmissions", "workshop", $course->student
).
1301 "</b></div><br />\n";
1302 print_table($table);
1305 echo "<p><div style=\"text-align:center;\"><b>".get_string("nosubmissionsavailableforassessment", "workshop")."</b></div><br />\n";
1310 //////////////////////////////////////////////////////////////////////////////////////
1311 function workshop_list_submissions_for_admin($workshop, $order) {
1312 // list the teacher sublmissions first
1315 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
1316 error("Course Module ID was incorrect");
1318 if (! $course = get_record("course", "id", $workshop->course
)) {
1319 error("Course is misconfigured");
1321 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $course->id
)) {
1322 error("Course Module ID was incorrect");
1324 if (groupmode($course, $cm) == SEPARATEGROUPS
) {
1325 $groupid = get_current_group($course->id
);
1330 workshop_print_assignment_info($workshop);
1332 if (workshop_is_teacheredit($workshop)) {
1333 // list any teacher submissions
1334 $table->head
= array (get_string("title", "workshop"), get_string("submittedby", "workshop"),
1335 get_string("action", "workshop"));
1336 $table->align
= array ("left", "left", "left");
1337 $table->size
= array ("*", "*", "*");
1338 $table->cellpadding
= 2;
1339 $table->cellspacing
= 0;
1341 if ($submissions = workshop_get_teacher_submissions($workshop)) {
1342 foreach ($submissions as $submission) {
1343 $action = "<a href=\"submissions.php?action=adminamendtitle&id=$cm->id&sid=$submission->id\">".
1344 get_string("amendtitle", "workshop")."</a>";
1345 // has user already assessed this submission
1346 if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id
1347 AND userid = $USER->id")) {
1349 if ($assessment->timecreated
> $curtime) { // it's a "hanging" assessment
1350 $action .= " | <a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1351 get_string("assess", "workshop")."</a>";
1353 elseif (($curtime - $assessment->timecreated
) > $CFG->maxeditingtime
) {
1354 $action .= " | <a href=\"assess.php?id=$cm->id&sid=$submission->id\">"
1355 .get_string("reassess", "workshop")."</a>";
1357 else { // there's still time left to edit...
1358 $action .= " | <a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1359 get_string("edit", "workshop")."</a>";
1362 else { // user has not graded this submission
1363 $action .= " | <a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1364 get_string("assess", "workshop")."</a>";
1366 if ($assessments = workshop_get_assessments($submission)) {
1367 $action .= " | <a href=\"assessments.php?action=adminlist&id=$cm->id&sid=$submission->id\">".
1368 get_string("listassessments", "workshop")."</a>";
1370 if (workshop_is_teacheredit($workshop)) {
1371 $action .= " | <a href=\"submissions.php?action=confirmdelete&id=$cm->id&sid=$submission->id\">".
1372 get_string("delete", "workshop")."</a>";
1374 $table->data
[] = array("<a href=\"submissions.php?action=editsubmission&id=$cm->id&sid=$submission->id\">$submission->title</a>", $course->teacher
, $action);
1376 print_heading(get_string("studentsubmissions", "workshop", $course->teacher
), "center");
1377 print_table($table);
1381 // list student assessments
1382 // Get all the students...
1383 if ($users = workshop_get_students($workshop, "u.lastname, u.firstname")) {
1386 $table->head
= array(get_string("name"), get_string("title", "workshop"), get_string("action", "workshop"));
1387 $table->align
= array ("left", "left", "left");
1388 $table->size
= array ("*", "*", "*");
1389 $table->cellpadding
= 2;
1390 $table->cellspacing
= 0;
1392 foreach ($users as $user) {
1393 // check group membership, if necessary
1395 // check user's group
1396 if (!ismember($groupid, $user->id
)) {
1397 continue; // skip this user
1400 // list the assessments which have been done (exclude the hot ones)
1401 if ($assessments = workshop_get_user_assessments_done($workshop, $user)) {
1403 foreach ($assessments as $assessment) {
1404 if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid
)) {
1405 error("Workshop_list_submissions_for_admin: Submission $assessment->submissionid not found!");
1407 $title .= $submission->title
;
1408 if ($workshop->agreeassessments
and !$assessment->timeagreed
and
1409 workshop_is_student($workshop, $submission->userid
)) { // agreements for student work only
1410 $title .= " <<".number_format($assessment->grade
* $workshop->grade
/ 100, 0)." (".
1411 number_format($assessment->gradinggrade
* $workshop->gradinggrade
/ 100, 0).")>> ";
1412 } elseif ($assessment->timegraded
) {
1413 if ($assessment->gradinggrade
) {
1414 // a good assessment
1415 $title .= " {".number_format($assessment->grade
* $workshop->grade
/ 100, 0)." (".
1416 number_format($assessment->gradinggrade
* $workshop->gradinggrade
/ 100, 0).")} ";
1418 // a poor assessment
1419 $title .= " <".number_format($assessment->grade
* $workshop->grade
/ 100, 0)." (".
1420 number_format($assessment->gradinggrade
* $workshop->gradinggrade
/ 100, 0).")> ";
1424 $title .= " {".number_format($assessment->grade
* $workshop->grade
/ 100, 0)." ((".
1425 number_format($assessment->gradinggrade
* $workshop->gradinggrade
/ 100, 0)."))} ";
1427 if ($realassessments = workshop_count_user_assessments_done($workshop, $user)) {
1428 $action = "<a href=\"assessments.php?action=adminlistbystudent&id=$cm->id&userid=$user->id\">".
1429 get_string("liststudentsassessments", "workshop")." ($realassessments)</a>";
1435 $table->data
[] = array(fullname($user), $title, $action);
1438 if (isset($table->data
)) {
1439 print_heading(get_string("studentassessments", "workshop", $course->student
)." [$nassessments]");
1440 print_table($table);
1441 workshop_print_key($workshop);
1442 // grading grade analysis
1444 $table->head
= array (get_string("count", "workshop"), get_string("mean", "workshop"),
1445 get_string("standarddeviation", "workshop"), get_string("maximum", "workshop"),
1446 get_string("minimum", "workshop"));
1447 $table->align
= array ("center", "center", "center", "center", "center");
1448 $table->size
= array ("*", "*", "*", "*", "*");
1449 $table->cellpadding
= 2;
1450 $table->cellspacing
= 0;
1452 $stats = get_record_sql("SELECT COUNT(*) as count, AVG(gradinggrade) AS mean,
1453 STDDEV(gradinggrade) AS stddev, MIN(gradinggrade) AS min, MAX(gradinggrade) AS max
1454 FROM {$CFG->prefix}groups_members g, {$CFG->prefix}workshop_assessments a
1455 WHERE g.groupid = $groupid AND a.userid = g.userid AND a.timegraded > 0
1456 AND a.workshopid = $workshop->id");
1457 } else { // no group/all participants
1458 $stats = get_record_sql("SELECT COUNT(*) as count, AVG(gradinggrade) AS mean,
1459 STDDEV(gradinggrade) AS stddev, MIN(gradinggrade) AS min, MAX(gradinggrade) AS max
1460 FROM {$CFG->prefix}workshop_assessments a
1461 WHERE a.timegraded > 0 AND a.workshopid = $workshop->id");
1463 $table->data
[] = array($stats->count
, number_format($stats->mean
* $workshop->gradinggrade
/ 100, 1),
1464 number_format($stats->stddev
* $workshop->gradinggrade
/100, 1),
1465 number_format($stats->max
* $workshop->gradinggrade
/ 100, 1),
1466 number_format($stats->min
* $workshop->gradinggrade
/ 100, 1));
1467 print_heading(get_string("gradinggrade", "workshop")." ".get_string("analysis", "workshop"));
1468 print_table($table);
1469 echo "<p style=\"text-align:center\"><a href=\"assessments.php?id=$cm->id&action=regradestudentassessments\">".
1470 get_string("regradestudentassessments", "workshop")."</a> ";
1471 helpbutton("regrading", get_string("regradestudentassessments", "workshop"), "workshop");
1476 // now the sudent submissions
1480 $table->head
= array("<a href=\"submissions.php?action=adminlist&id=$cm->id&order=name\">".
1481 get_string("submittedby", "workshop")."</a>", get_string("title", "workshop"),
1482 get_string("submitted", "workshop"), get_string("action", "workshop"));
1485 $table->head
= array (get_string("submittedby", "workshop"),
1486 "<a href=\"submissions.php?action=adminlist&id=$cm->id&order=title\">".
1487 get_string("title", "workshop")."</a>", get_string("submitted", "workshop"),
1488 get_string("action", "workshop"));
1491 $table->align
= array ("left", "left", "left", "left");
1492 $table->size
= array ("*", "*", "*", "*");
1493 $table->cellpadding
= 2;
1494 $table->cellspacing
= 0;
1497 if ($submissions = workshop_get_student_submissions($workshop, $order)) {
1498 foreach ($submissions as $submission) {
1499 if (!$user = get_record("user", "id", $submission->userid
)) {
1500 error("workshop_list_submissions_for_admin: failure to get user record");
1502 // check group membership, if necessary
1504 // check user's group
1505 if (!ismember($groupid, $user->id
)) {
1506 continue; // skip this user
1509 $datesubmitted = userdate($submission->timecreated
);
1510 if ($submission->late
) {
1511 $datesubmitted = "<span class=\"redfont\">".$datesubmitted."</span>";
1513 $action = "<a href=\"submissions.php?action=adminamendtitle&id=$cm->id&sid=$submission->id\">".
1514 get_string("amendtitle", "workshop")."</a>";
1515 // has teacher already assessed this submission
1516 if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id
1517 AND userid = $USER->id")) {
1519 if (($curtime - $assessment->timecreated
) > $CFG->maxeditingtime
) {
1520 $action .= " | <a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1521 get_string("reassess", "workshop")."</a>";
1523 else { // there's still time left to edit...
1524 $action .= " | <a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1525 get_string("edit", "workshop")."</a>";
1528 else { // user has not assessed this submission
1529 $action .= " | <a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1530 get_string("assess", "workshop")."</a>";
1532 if ($nassessments = workshop_count_assessments($submission)) {
1533 $action .= " | <a href=\"assessments.php?action=adminlist&id=$cm->id&sid=$submission->id\">".
1534 get_string("listassessments", "workshop")." ($nassessments)</a>";
1536 if ($submission->late
) {
1537 $action .= " | <a href=\"submissions.php?action=adminlateflag&id=$cm->id&sid=$submission->id\">".
1538 get_string("clearlateflag", "workshop")."</a>";
1540 $action .= " | <a href=\"submissions.php?action=confirmdelete&id=$cm->id&sid=$submission->id\">".
1541 get_string("delete", "workshop")."</a>";
1543 $table->data
[] = array("$user->firstname $user->lastname", $submission->title
.
1544 " (".get_string("grade").": ".workshop_submission_grade($workshop, $submission)." ".
1545 workshop_print_submission_assessments($workshop, $submission, "teacher").
1546 " ".workshop_print_submission_assessments($workshop, $submission, "student").")", $datesubmitted,
1549 print_heading(get_string("studentsubmissions", "workshop", $course->student
)." [$nsubmissions]", "center");
1550 print_table($table);
1551 workshop_print_key($workshop);
1556 //////////////////////////////////////////////////////////////////////////////////////
1557 function workshop_list_teacher_assessments_by_user($workshop, $user) {
1561 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
1562 error("Course Module ID was incorrect");
1564 if (! $course = get_record("course", "id", $workshop->course
)) {
1565 error("Course is misconfigured");
1568 $table->head
= array (get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop"));
1569 $table->align
= array ("left", "left", "left");
1570 $table->size
= array ("*", "*", "*");
1571 $table->cellpadding
= 2;
1572 $table->cellspacing
= 0;
1574 // get user's submissions
1575 if ($submissions = workshop_get_user_submissions($workshop, $user)) {
1576 foreach ($submissions as $submission) {
1577 // get the assessments
1578 if ($assessments = workshop_get_assessments($submission)) {
1579 foreach ($assessments as $assessment) {
1580 if (workshop_is_teacher($workshop, $assessment->userid
)) { // assessments by teachers only
1581 $action = "<a href=\"viewassessment.php?id=$cm->id&aid=$assessment->id\">".
1582 get_string("view", "workshop")."</a>";
1583 // has teacher commented on teacher's assessment? shouldn't happen but leave test in
1584 if ($assessment->timegraded
and ($timenow - $assessment->timegraded
> $CFG->maxeditingtime
)) {
1585 $comment = get_string("gradedbyteacher", "workshop", $course->teacher
);
1588 $comment = userdate($assessment->timecreated
);
1590 $table->data
[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment);
1596 if (isset($table->data
)) {
1597 print_table($table);
1600 echo "<div style=\"text-align:center;\">".get_string("noassessmentsdone", "workshop")."</div>\n";
1606 //////////////////////////////////////////////////////////////////////////////////////
1607 function workshop_list_teacher_submissions($workshop, $user) {
1610 // set threshold on re-assessments
1611 $reassessthreshold = 80;
1613 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
1614 error("Course Module ID was incorrect");
1616 if (! $course = get_record("course", "id", $workshop->course
)) {
1617 error("Course is misconfigured");
1619 $table->head
= array (get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop"));
1620 $table->align
= array ("left", "left", "left");
1621 $table->size
= array ("*", "*", "*");
1622 $table->cellpadding
= 2;
1623 $table->cellspacing
= 0;
1625 // get the number of assessments this user has done
1626 $nassessed = count_records_select("workshop_assessments", "workshopid = $workshop->id
1627 AND userid = $user->id");
1628 if ($nassessed < $workshop->ntassessments
) {
1629 // if user has not assessed enough, set up "future" assessment records for this user for the teacher submissions...
1630 // ... first count the number of assessments for each teacher submission...
1631 if ($submissions = workshop_get_teacher_submissions($workshop)) {
1632 srand ((float)microtime()*1000000); // initialise random number generator
1633 foreach ($submissions as $submission) {
1634 $n = count_records("workshop_assessments", "submissionid", $submission->id
);
1635 // ...OK to have zero, we add a small random number to randomise things...
1636 $nassessments[$submission->id
] = $n +
rand(0, 99) / 100;
1638 // ...put the submissions with the lowest number of assessments first...
1639 asort($nassessments);
1640 reset($nassessments);
1641 foreach ($nassessments as $submissionid => $n) { // break out of loop when we allocated enough assessments...
1642 $submission = get_record("workshop_submissions", "id", $submissionid);
1643 // ... provided the user has NOT already assessed that submission...
1644 if (!get_record("workshop_assessments", "submissionid", $submission->id
, "userid",
1646 $yearfromnow = time() +
365 * 86400;
1647 // ...create one and set timecreated way in the future, this is reset when record is updated
1648 unset($assessment); // clear previous version of object (if any)
1649 $assessment->workshopid
= $workshop->id
;
1650 $assessment->submissionid
= $submission->id
;
1651 $assessment->userid
= $user->id
;
1652 $assessment->grade
= -1; // set impossible grade
1653 $assessment->timecreated
= $yearfromnow;
1654 if (!$assessment->id
= insert_record("workshop_assessments", $assessment)) {
1655 error("Could not insert workshop assessment!");
1658 if ($nassessed >= $workshop->ntassessments
) {
1665 // now list user's assessments (but only list those which come from teacher submissions)
1666 if ($assessments = workshop_get_user_assessments($workshop, $user)) {
1668 foreach ($assessments as $assessment) {
1669 if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid
)) {
1670 error ("workshop_list_teacher_submissions: unable to get submission");
1672 // submission from a teacher?
1673 if (workshop_is_teacher($workshop, $submission->userid
)) {
1675 // user assessment has two states: record created but not assessed (date created in the future);
1676 // assessed but always available for re-assessment
1677 if ($assessment->timecreated
> $timenow) { // user needs to assess this submission
1678 $action = "<a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1679 get_string("assess", "workshop")."</a>";
1681 elseif ($assessment->timegraded
and ($assessment->gradinggrade
< $reassessthreshold)) {
1682 // allow student to improve on their assessment once it's been graded and is below threshold
1683 $action = "<a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1684 get_string("reassess", "workshop")."</a>";
1686 // allow student just to see their assessment if it hasn't been graded (or above threshold)
1687 $action = "<a href=\"viewassessment.php?id=$cm->id&aid=$assessment->id\">".
1688 get_string("view", "workshop")."</a>";
1690 // see if the assessment is graded
1691 if ($assessment->timegraded
) {
1692 // show grading grade (supressed if workshop not graded)
1693 if ($workshop->gradingstrategy
) {
1694 $comment = get_string("thegradeforthisassessmentis", "workshop",
1695 number_format($assessment->gradinggrade
* $workshop->gradinggrade
/ 100, 1))." / ".
1696 $workshop->gradinggrade
;
1698 } elseif ($assessment->timecreated
< $timenow) {
1699 $comment = get_string("awaitinggradingbyteacher", "workshop", $course->teacher
);
1701 $table->data
[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment);
1705 print_table($table);
1709 //////////////////////////////////////////////////////////////////////////////////////
1710 function workshop_list_unassessed_student_submissions($workshop, $user) {
1711 // list the student submissions not assessed by this user
1715 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
1716 error("Course Module ID was incorrect");
1718 if (! $course = get_record("course", "id", $workshop->course
)) {
1719 error("Course is misconfigured");
1722 if (groupmode($course, $cm) == SEPARATEGROUPS
) {
1723 $groupid = get_current_group($course->id
);
1728 $table->head
= array (get_string("title", "workshop"), get_string("submittedby", "workshop"),
1729 get_string("submitted", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop"));
1730 $table->align
= array ("left", "left", "left", "left", "left");
1731 $table->size
= array ("*", "*", "*", "*", "*");
1732 $table->cellpadding
= 2;
1733 $table->cellspacing
= 0;
1735 if ($submissions = workshop_get_student_submissions($workshop, 'time')) { // oldest first
1736 foreach ($submissions as $submission) {
1737 // check group membership, if necessary
1739 // check user's group
1740 if (!ismember($groupid, $submission->userid
)) {
1741 continue; // skip this user
1744 // see if submission is cold
1745 if (($submission->timecreated +
$CFG->maxeditingtime
) > $timenow) {
1746 continue; // skip this submission
1749 $timegap = get_string("ago", "workshop", format_time($submission->timecreated
- $timenow));
1750 // see if user already graded this assessment
1751 if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id
1752 AND userid = $user->id")) {
1753 if (($timenow - $assessment->timecreated
< $CFG->maxeditingtime
)) {
1754 // last chance salon
1755 $submissionowner = get_record("user", "id", $submission->userid
);
1756 $action = "<a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1757 get_string("edit", "workshop")."</a>";
1758 $table->data
[] = array(workshop_print_submission_title($workshop, $submission),
1759 fullname($submissionowner), $timegap, $action, $comment);
1763 // no assessment by this user, if no other teacher has assessed submission then list it
1764 if (!workshop_count_teacher_assessments($course->id
, $submission)) {
1765 $submissionowner = get_record("user", "id", $submission->userid
);
1766 $action = "<a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1767 get_string("assess", "workshop")."</a>";
1768 $table->data
[] = array(workshop_print_submission_title($workshop, $submission),
1769 fullname($submissionowner), $timegap, $action, $comment);
1773 if (isset($table->data
)) {
1774 print_table($table);
1780 //////////////////////////////////////////////////////////////////////////////////////
1781 function workshop_list_unassessed_teacher_submissions($workshop, $user) {
1782 // list the teacher submissions not assessed by this user
1785 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
1786 error("Course Module ID was incorrect");
1789 $table->head
= array (get_string("title", "workshop"), get_string("action", "workshop"),
1790 get_string("comment", "workshop"));
1791 $table->align
= array ("left", "left", "left");
1792 $table->size
= array ("*", "*", "*");
1793 $table->cellpadding
= 2;
1794 $table->cellspacing
= 0;
1796 if ($submissions = workshop_get_teacher_submissions($workshop)) {
1797 foreach ($submissions as $submission) {
1799 // see if user already graded this assessment
1800 if ($assessment = get_record_select("workshop_assessments", "submissionid = $submission->id
1801 AND userid = $user->id")) {
1803 if (($timenow - $assessment->timecreated
< $CFG->maxeditingtime
)) {
1804 // last chance salon
1805 $action = "<a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1806 get_string("edit", "workshop")."</a>";
1807 $table->data
[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment);
1810 else { // no assessment
1811 $action = "<a href=\"assess.php?id=$cm->id&sid=$submission->id\">".
1812 get_string("assess", "workshop")."</a>";
1813 $table->data
[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment);
1816 if (isset($table->data
)) {
1817 print_table($table);
1823 //////////////////////////////////////////////////////////////////////////////////////
1824 function workshop_list_ungraded_assessments($workshop, $stype) {
1825 // lists all the assessments of student submissions for grading by teacher
1828 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
1829 error("Course Module ID was incorrect");
1832 $table->head
= array (get_string("title", "workshop"), get_string("submittedby", "workshop"),
1833 get_string("assessor", "workshop"), get_string("timeassessed", "workshop"), get_string("action", "workshop"));
1834 $table->align
= array ("left", "left", "left", "left");
1835 $table->size
= array ("*", "*", "*", "*");
1836 $table->cellpadding
= 2;
1837 $table->cellspacing
= 0;
1842 $assessments = workshop_get_ungraded_assessments_student($workshop);
1845 $assessments = workshop_get_ungraded_assessments_teacher($workshop);
1849 foreach ($assessments as $assessment) {
1850 if (!workshop_is_teacher($workshop, $assessment->userid
)) { // don't let teacher grade their own assessments
1851 if (($timenow - $assessment->timegraded
) < $CFG->maxeditingtime
) {
1852 $action = "<a href=\"viewassessment.php?&id=$cm->id&stype=$stype&aid=$assessment->id\">".
1853 get_string("edit", "workshop")."</a>";
1856 $action = "<a href=\"viewassessment.php?&id=$cm->id&stype=$stype&aid=$assessment->id\">".
1857 get_string("grade", "workshop")."</a>";
1859 $submission = get_record("workshop_submissions", "id", $assessment->submissionid
);
1860 $submissionowner = get_record("user", "id", $submission->userid
);
1861 $assessor = get_record("user", "id", $assessment->userid
);
1862 $table->data
[] = array(workshop_print_submission_title($workshop, $submission),
1863 fullname($submissionowner), fullname($assessor), userdate($assessment->timecreated
), $action);
1866 if (isset($table->data
)) {
1867 print_table($table);
1873 //////////////////////////////////////////////////////////////////////////////////////
1874 function workshop_list_user_submissions($workshop, $user) {
1877 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
1878 error("Course Module ID was incorrect");
1882 $table->head
= array (get_string("title", "workshop"), get_string("action", "workshop"),
1883 get_string("submitted", "assignment"), get_string("assessments", "workshop"));
1884 $table->align
= array ("left", "left", "left", "left");
1885 $table->size
= array ("*", "*", "*", "*");
1886 $table->cellpadding
= 2;
1887 $table->cellspacing
= 0;
1889 if ($submissions = workshop_get_user_submissions($workshop, $user)) {
1890 foreach ($submissions as $submission) {
1891 // allow user to edit or delete a submission if it's warm OR if assessment period has not started
1892 if (($submission->timecreated
> ($timenow - $CFG->maxeditingtime
)) or ($workshop->assessmentstart
> time())) {
1893 $action = "<a href=\"submissions.php?action=editsubmission&id=$cm->id&sid=$submission->id\">".
1894 get_string("edit", "workshop")."</a> | ".
1895 "<a href=\"submissions.php?action=confirmdelete&id=$cm->id&sid=$submission->id\">".
1896 get_string("delete", "workshop")."</a>";
1901 $datesubmitted = userdate($submission->timecreated
);
1902 if ($submission->late
) {
1903 $datesubmitted = "<span class=\"redfont\">".$datesubmitted."</span>";
1905 $n = count_records_select("workshop_assessments", "submissionid = $submission->id AND
1906 timecreated < ($timenow - $CFG->maxeditingtime)");
1907 $table->data
[] = array(workshop_print_submission_title($workshop, $submission), $action,
1908 $datesubmitted, $n);
1910 print_table($table);
1916 ///////////////////////////////////////////////////////////////////////////////
1917 function workshop_phase($workshop, $style='') {
1919 if ($time < $workshop->submissionstart
) {
1920 return get_string('phase1'.$style, 'workshop');
1922 else if ($time < $workshop->submissionend
) {
1923 if ($time < $workshop->assessmentstart
) {
1924 return get_string('phase2'.$style, 'workshop');
1926 return get_string('phase3'.$style, 'workshop');
1929 else if ($time < $workshop->assessmentstart
) {
1930 return get_string('phase0'.$style, 'workshop');
1932 else if ($time < $workshop->assessmentend
) {
1933 return get_string('phase4'.$style, 'workshop');
1936 return get_string('phase5'.$style, 'workshop');
1938 error('Something is wrong with the workshop dates');
1942 //////////////////////////////////////////////////////////////////////////////////////
1943 function workshop_print_assessment($workshop, $assessment = false, $allowchanges = false,
1944 $showcommentlinks = false, $returnto = '') {
1945 // $allowchanges added 14/7/03. The form is inactive unless allowchanges = true
1946 // $returnto added 28/8/03. The page to go to after the assessment has been submitted
1947 global $CFG, $USER, $WORKSHOP_SCALES, $WORKSHOP_EWEIGHTS;
1949 if (! $course = get_record("course", "id", $workshop->course
)) {
1950 error("Course is misconfigured");
1952 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $course->id
)) {
1953 error("Course Module ID was incorrect");
1956 if (!$submission = get_record("workshop_submissions", "id", $assessment->submissionid
)) {
1957 error ("Workshop_print_assessment: Submission record not found");
1960 // removed target=\"submission\" as it does not validate
1962 print_heading(get_string('assessmentof', 'workshop',
1963 "<a href=\"submissions.php?id=$cm->id&action=showsubmission&sid=$submission->id\" >".
1964 $submission->title
.'</a>'));
1969 // reset the internal flags
1971 $showgrades = false;
1973 else { // if no assessment, i.e. specimen grade form always show grading scales
1978 // set the internal flag if necessary
1979 if ($allowchanges or !$workshop->agreeassessments
or !$workshop->hidegrades
or
1980 $assessment->timeagreed
) {
1984 echo "<div class=\"boxaligncenter\">\n";
1986 // see if this is a pre-filled assessment for a re-submission...
1987 if ($assessment->resubmission
) {
1988 // ...and print an explaination
1989 print_heading(get_string("assessmentofresubmission", "workshop"));
1992 // print agreement time if the workshop requires peer agreement
1993 if ($workshop->agreeassessments
and $assessment->timeagreed
) {
1994 echo "<p>".get_string("assessmentwasagreedon", "workshop", userdate($assessment->timeagreed
));
1997 // first print any comments on this assessment
1998 if ($comments = workshop_get_comments($assessment)) {
1999 echo "<table cellpadding=\"2\" border=\"1\">\n";
2000 $firstcomment = TRUE;
2001 foreach ($comments as $comment) {
2002 echo "<tr valign=\"top\"><td class=\"workshopassessmentheading\"><p><b>".
2003 get_string("commentby","workshop")." ";
2004 if (workshop_is_teacher($workshop, $comment->userid
)) {
2005 echo $course->teacher
;
2007 elseif ($assessment->userid
== $comment->userid
) {
2008 print_string("assessor", "workshop");
2011 print_string("authorofsubmission", "workshop");
2013 echo " ".get_string("on", "workshop", userdate($comment->timecreated
))."</b></p></td></tr><tr><td>\n";
2014 echo format_text($comment->comments
)." \n";
2015 // add the links if needed
2016 if ($firstcomment and $showcommentlinks and !$assessment->timeagreed
) {
2017 // show links depending on who doing the viewing
2018 $firstcomment = FALSE;
2019 if (workshop_is_teacher($workshop, $USER->id
) and ($comment->userid
!= $USER->id
)) {
2020 echo "<p style=\"text-align:right\"><a href=\"assessments.php?action=addcomment&id=$cm->id&aid=$assessment->id\">".
2021 get_string("reply", "workshop")."</a></p>\n";
2023 elseif (($comment->userid
==$USER->id
) and (($timenow - $comment->timecreated
) < $CFG->maxeditingtime
)) {
2024 echo "<p style=\"text-align:right\"><a href=\"assessments.php?action=editcomment&id=$cm->id&cid=$comment->id\">".
2025 get_string("edit", "workshop")."</a>\n";
2026 if ($USER->id
== $submission->userid
) {
2027 echo " | <a href=\"assessments.php?action=agreeassessment&id=$cm->id&aid=$assessment->id\">".
2028 get_string("agreetothisassessment", "workshop")."</a>\n";
2032 elseif (($comment->userid
!= $USER->id
) and (($USER->id
== $assessment->userid
) or
2033 ($USER->id
== $submission->userid
))) {
2034 echo "<p style=\"text-align:right\"><a href=\"assessments.php?action=addcomment&id=$cm->id&aid=$assessment->id\">".
2035 get_string("reply", "workshop")."</a>\n";
2036 if ($USER->id
== $submission->userid
) {
2037 echo " | <a href=\"assessments.php?action=agreeassessment&id=$cm->id&aid=$assessment->id\">".
2038 get_string("agreetothisassessment", "workshop")."</a>\n";
2050 // now print the grading form with the grading grade if any
2051 // FORM is needed for Mozilla browsers, else radio bttons are not checked
2053 <form id
="assessmentform" method
="post" action
="assessments.php">
2055 <input type
="hidden" name
="id" value
="<?php echo $cm->id ?>" />
2056 <input type
="hidden" name
="aid" value
="<?php echo $assessment->id ?>" />
2057 <input type
="hidden" name
="action" value
="updateassessment" />
2058 <input type
="hidden" name
="returnto" value
="<?php echo $returnto ?>" />
2059 <input type
="hidden" name
="elementno" value
="" />
2060 <input type
="hidden" name
="stockcommentid" value
="" />
2061 <div
class="boxaligncenter">
2062 <table cellpadding
="2" border
="1" class="boxaligncenter">
2064 echo "<tr valign=\"top\">\n";
2065 echo " <td colspan=\"2\" class=\"workshopassessmentheading\"><div style=\"text-align:center;\"><b>";
2066 if ($assessment and workshop_is_teacher($workshop)) {
2067 $user = get_record('user', 'id', $assessment->userid
);
2068 print_string("assessmentby", "workshop", fullname($user));
2070 print_string('assessment', 'workshop');
2072 echo '</b><br />'.userdate($assessment->timecreated
)."</div></td>\n";
2075 // only show the grade if grading strategy > 0 and the grade is positive
2076 if ($showgrades and $workshop->gradingstrategy
and $assessment->grade
>= 0) {
2077 echo "<tr valign=\"top\">\n
2078 <td colspan=\"2\" align=\"center\">
2079 <b>".get_string("thegradeis", "workshop").": ".
2080 number_format($assessment->grade
* $workshop->grade
/ 100, 2)." (".
2081 get_string("maximumgrade")." ".number_format($workshop->grade
, 0).")</b>
2082 </td></tr><tr><td colspan=\"2\" class=\"workshopassessmentheading\"> </td></tr>\n";
2085 // get the assignment elements...
2086 $elementsraw = get_records("workshop_elements", "workshopid", $workshop->id
, "elementno ASC");
2087 if (count($elementsraw) < $workshop->nelements
) {
2088 print_string("noteonassignmentelements", "workshop");
2091 foreach ($elementsraw as $element) {
2092 $elements[] = $element; // to renumber index 0,1,2...
2099 // get any previous grades...
2100 if ($gradesraw = get_records_select("workshop_grades", "assessmentid = $assessment->id", "elementno")) {
2101 foreach ($gradesraw as $grade) {
2102 $grades[] = $grade; // to renumber index 0,1,2...
2107 // setup dummy grades array
2108 for($i = 0; $i < count($elementsraw); $i++
) { // gives a suitable sized loop
2109 $grades[$i]->feedback
= get_string("yourfeedbackgoeshere", "workshop");
2110 $grades[$i]->grade
= 0;
2114 // determine what sort of grading
2115 switch ($workshop->gradingstrategy
) {
2116 case 0: // no grading
2117 // now print the form
2118 for ($i=0; $i < count($elements); $i++
) {
2120 echo "<tr valign=\"top\">\n";
2121 echo " <td align=\"right\"><p><b>". get_string("element","workshop")." $iplus1:</b></p></td>\n";
2122 echo " <td>".format_text($elements[$i]->description
);
2123 echo "</td></tr>\n";
2124 echo "<tr valign=\"top\">\n";
2125 echo " <td align=\"right\"><p><b>". get_string("feedback").":</b></p></td>\n";
2127 if ($allowchanges) {
2128 echo " <textarea name=\"feedback_$i\" rows=\"3\" cols=\"75\" >\n";
2129 if (isset($grades[$i]->feedback
)) {
2130 echo $grades[$i]->feedback
;
2132 echo "</textarea>\n";
2135 echo format_text($grades[$i]->feedback
);
2140 // if active and the teacher show stock comments...
2141 if ($allowchanges and workshop_is_teacher($workshop, $USER->id
)) {
2142 echo "<tr><td valign=\"top\" align=\"right\"><input type=\"button\" value=\"".
2143 get_string("addcomment", "workshop")."\"
2144 onclick=\"getElementById('assessmentform').action.value='addstockcomment';
2145 getElementById('assessmentform').elementno.value=$i;getElementById('assessmentform').submit();\" /> \n";
2146 helpbutton("addcommenttobank", get_string("addcomment", "workshop"), "workshop");
2148 if ($stockcomments = get_records_select("workshop_stockcomments", "workshopid = $workshop->id
2149 AND elementno = $i", "id")) { // show comments in fixed order (oldest first)
2150 foreach ($stockcomments as $stockcomment) {
2151 echo "<a onclick=\"getElementById('assessmentform').feedback_$i.value+=' '+'".
2152 addslashes($stockcomment->comments
)."';\"><<$stockcomment->comments>></a>\n";
2153 if (workshop_is_teacheredit($workshop, $USER->id
)) {
2154 echo " <a onclick=\"getElementById('assessmentform').action.value='removestockcomment';getElementById('assessmentform').stockcommentid.value=$stockcomment->id;getElementById('assessmentform').submit();\"> <small><i><--".get_string("delete","workshop")."</i></small></a>\n";
2159 echo "</td></tr>\n";
2162 echo "<tr valign=\"top\">\n";
2163 echo " <td colspan=\"2\" class=\"workshopassessmentheading\"> </td>\n";
2168 case 1: // accumulative grading
2169 // now print the form
2170 for ($i=0; $i < count($elements); $i++
) {
2172 echo "<tr valign=\"top\">\n";
2173 echo " <td align=\"right\"><p><b>". get_string("element","workshop")." $iplus1:</b></p></td>\n";
2174 echo " <td>".format_text($elements[$i]->description
);
2175 echo "<p style=\"text-align:right\">".get_string("weight", "workshop").": ".
2176 number_format($WORKSHOP_EWEIGHTS[$elements[$i]->weight
], 2)."</p>\n";
2177 echo "</td></tr>\n";
2179 echo "<tr valign=\"top\">\n";
2180 echo " <td align=\"right\"><p><b>". get_string("grade"). ":</b></p></td>\n";
2181 echo " <td valign=\"top\">\n";
2183 // get the appropriate scale
2184 $scalenumber=$elements[$i]->scale
;
2185 $SCALE = (object)$WORKSHOP_SCALES[$scalenumber];
2186 switch ($SCALE->type
) {
2188 // show selections highest first
2189 echo "<div class=\"boxaligncenter\"><b>$SCALE->start</b> ";
2190 for ($j = $SCALE->size
- 1; $j >= 0 ; $j--) {
2192 if (isset($grades[$i]->grade
)) {
2193 if ($j == $grades[$i]->grade
) {
2197 else { // there's no previous grade so check the lowest option
2203 echo " <input type=\"radio\" name=\"grade[$i]\" value=\"$j\" checked=\"checked\" alt=\"$j\" /> \n";
2206 echo " <input type=\"radio\" name=\"grade[$i]\" value=\"$j\" alt=\"$j\" /> \n";
2209 echo " <b>$SCALE->end</b></div>\n";
2213 for ($j = $SCALE->size
; $j >= 0; $j--) {
2216 if (isset($grades[$i]->grade
)) {
2217 choose_from_menu($numbers, "grade[$i]", $grades[$i]->grade
, "");
2220 choose_from_menu($numbers, "grade[$i]", 0, "");
2228 echo "<tr valign=\"top\">\n";
2229 echo " <td align=\"right\"><p><b>". get_string("feedback").":</b></p></td>\n";
2231 if ($allowchanges) {
2232 echo " <textarea name=\"feedback_$i\" rows=\"3\" cols=\"75\" >\n";
2233 if (isset($grades[$i]->feedback
)) {
2234 echo $grades[$i]->feedback
;
2236 echo "</textarea>\n";
2239 echo format_text($grades[$i]->feedback
);
2244 // if active and the teacher show stock comments...
2245 if ($allowchanges and workshop_is_teacher($workshop, $USER->id
)) {
2246 echo "<tr><td valign=\"top\" align=\"right\"><input type=\"button\" value=\"".
2247 get_string("addcomment", "workshop")."\"
2248 onclick=\"getElementById('assessmentform').action.value='addstockcomment';
2249 getElementById('assessmentform').elementno.value=$i;getElementById('assessmentform').submit();\" /> \n";
2250 helpbutton("addcommenttobank", get_string("addcomment", "workshop"), "workshop");
2252 if ($stockcomments = get_records_select("workshop_stockcomments", "workshopid = $workshop->id
2253 AND elementno = $i", "id")) { // get comments in a fixed order - oldest first
2254 foreach ($stockcomments as $stockcomment) {
2255 echo "<a onclick=\"getElementById('assessmentform').feedback_$i.value+=' '+'".
2256 addslashes($stockcomment->comments
).
2257 "';\"><<$stockcomment->comments>></a>\n";
2258 if (workshop_is_teacheredit($workshop, $USER->id
)) {
2259 echo " <a onclick=\"getElementById('assessmentform').action.value='removestockcomment';getElementById('assessmentform').stockcommentid.value=$stockcomment->id;getElementById('assessmentform').submit();\"> <small><i><--".get_string("delete","workshop")."</i></small></a>\n";
2264 echo "</td></tr>\n";
2267 echo "<tr valign=\"top\">\n";
2268 echo " <td colspan=\"2\" class=\"workshopassessmentheading\"> </td>\n";
2273 case 2: // error banded grading
2274 // now run through the elements
2276 for ($i=0; $i < count($elements) - 1; $i++
) {
2278 echo "<tr valign=\"top\">\n";
2279 echo " <td align=\"right\"><p><b>". get_string("element","workshop")." $iplus1:</b></p></td>\n";
2280 echo " <td>".format_text($elements[$i]->description
);
2281 echo "<p style=\"text-align:right\">".get_string("weight", "workshop").": ".
2282 number_format($WORKSHOP_EWEIGHTS[$elements[$i]->weight
], 2)."\n";
2283 echo "</td></tr>\n";
2284 echo "<tr valign=\"top\">\n";
2285 echo " <td align=\"right\"><p><b>". get_string("grade"). ":</b></p></td>\n";
2286 echo " <td valign=\"top\">\n";
2288 // get the appropriate scale - yes/no scale (0)
2289 $SCALE = (object) $WORKSHOP_SCALES[0];
2290 switch ($SCALE->type
) {
2292 // show selections highest first
2293 echo "<div class=\"boxaligncenter\"><b>$SCALE->start</b> ";
2294 for ($j = $SCALE->size
- 1; $j >= 0 ; $j--) {
2296 if (isset($grades[$i]->grade
)) {
2297 if ($j == $grades[$i]->grade
) {
2301 else { // there's no previous grade so check the lowest option
2307 echo " <input type=\"radio\" name=\"grade[$i]\" value=\"$j\" checked=\"checked\" alt=\"$j\" /> \n";
2310 echo " <input type=\"radio\" name=\"grade[$i]\" value=\"$j\" alt=\"$j\" /> \n";
2313 echo " <b>$SCALE->end</b></div>\n";
2317 for ($j = $SCALE->size
; $j >= 0; $j--) {
2320 if (isset($grades[$i]->grade
)) {
2321 choose_from_menu($numbers, "grade[$i]", $grades[$i]->grade
, "");
2324 choose_from_menu($numbers, "grade[$i]", 0, "");
2331 echo "<tr valign=\"top\">\n";
2332 echo " <td align=\"right\"><p><b>". get_string("feedback").":</b></p></td>\n";
2334 if ($allowchanges) {
2335 echo " <textarea name=\"feedback_$i\" rows=\"3\" cols=\"75\" >\n";
2336 if (isset($grades[$i]->feedback
)) {
2337 echo $grades[$i]->feedback
;
2339 echo "</textarea>\n";
2342 if (isset($grades[$i]->feedback
)) {
2343 echo format_text($grades[$i]->feedback
);
2346 echo " </td>\n";
2349 // if active and the teacher show stock comments...
2350 if ($allowchanges and workshop_is_teacher($workshop, $USER->id
)) {
2351 echo "<tr><td valign=\"top\" align=\"right\"><input type=\"button\" value=\"".
2352 get_string("addcomment", "workshop")."\"
2353 onclick=\"getElementById('assessmentform').action.value='addstockcomment';
2354 getElementById('assessmentform').elementno.value=$i;getElementById('assessmentform').submit();\" /> \n";
2355 helpbutton("addcommenttobank", get_string("addcomment", "workshop"), "workshop");
2357 if ($stockcomments = get_records_select("workshop_stockcomments", "workshopid = $workshop->id
2358 AND elementno = $i", "id")) { // get comments in a fixed order - oldest first
2359 foreach ($stockcomments as $stockcomment) {
2360 echo "<a onclick=\"getElementById('assessmentform').feedback_$i.value+=' '+'".
2361 addslashes($stockcomment->comments
).
2362 "';\"><<$stockcomment->comments>></a>\n";
2363 if (workshop_is_teacheredit($workshop, $USER->id
)) {
2364 echo " <a onclick=\"getElementById('assessmentform').action.value='removestockcomment';getElementById('assessmentform').stockcommentid.value=$stockcomment->id;getElementById('assessmentform').submit();\"> <small><i><--".get_string("delete","workshop")."</i></small></a>\n";
2369 echo "</td></tr>\n";
2371 echo "<tr valign=\"top\">\n";
2372 echo " <td colspan=\"2\" class=\"workshopassessmentheading\"> </td>\n";
2374 if (empty($grades[$i]->grade
)) {
2378 // print the number of negative elements
2379 // echo "<tr><td>".get_string("numberofnegativeitems", "workshop")."</td><td>$negativecount</td></tr>\n";
2380 // echo "<tr valign=\"top\">\n";
2381 // echo " <td colspan=\"2\" class=\"workshopassessmentheading\"> </td>\n";
2382 echo "</table></div>\n";
2383 // now print the grade table
2384 echo "<p><div style=\"text-align:center;\"><b>".get_string("gradetable","workshop")."</b></div>\n";
2385 echo "<div class=\"boxaligncenter\"><table cellpadding=\"5\" border=\"1\"><tr><td align=\"CENTER\">".
2386 get_string("numberofnegativeresponses", "workshop");
2387 echo "</td><td>". get_string("suggestedgrade", "workshop")."</td></tr>\n";
2388 for ($j = 100; $j >= 0; $j--) {
2391 for ($i=0; $i<=$workshop->nelements
; $i++
) {
2392 if ($i == $negativecount) {
2393 echo "<tr><td align=\"CENTER\"><img src=\"$CFG->pixpath/t/right.gif\" alt=\"\" /> $i</td><td align=\"center\">{$elements[$i]->maxscore}</td></tr>\n";
2396 echo "<tr><td align=\"CENTER\">$i</td><td align=\"CENTER\">{$elements[$i]->maxscore}</td></tr>\n";
2399 echo "</table></div>\n";
2400 echo "<p><div class=\"boxaligncenter\"><table cellpadding=\"5\" border=\"1\"><tr><td><b>".get_string("optionaladjustment",
2401 "workshop")."</b></td><td>\n";
2403 for ($j = 20; $j >= -20; $j--) {
2406 if (isset($grades[$workshop->nelements
]->grade
)) {
2407 choose_from_menu($numbers, "grade[$workshop->nelements]", $grades[$workshop->nelements
]->grade
, "");
2410 choose_from_menu($numbers, "grade[$workshop->nelements]", 0, "");
2412 echo "</td></tr>\n";
2415 case 3: // criteria grading
2416 echo "<tr valign=\"top\">\n";
2417 echo " <td class=\"workshopassessmentheading\"> </td>\n";
2418 echo " <td class=\"workshopassessmentheading\"><b>". get_string("criterion","workshop")."</b></td>\n";
2419 echo " <td class=\"workshopassessmentheading\"><b>".get_string("select", "workshop")."</b></td>\n";
2420 echo " <td class=\"workshopassessmentheading\"><b>".get_string("suggestedgrade", "workshop")."</b></td>\n";
2421 // find which criteria has been selected (saved in the zero element), if any
2422 if (isset($grades[0]->grade
)) {
2423 $selection = $grades[0]->grade
;
2428 // now run through the elements
2429 for ($i=0; $i < count($elements); $i++
) {
2431 echo "<tr valign=\"top\">\n";
2432 echo " <td>$iplus1</td><td>".format_text($elements[$i]->description
)."</td>\n";
2433 if ($selection == $i) {
2434 echo " <td align=\"center\"><input type=\"radio\" name=\"grade[0]\" value=\"$i\" checked=\"checked\" alt=\"$i\" /></td>\n";
2437 echo " <td align=\"center\"><input type=\"radio\" name=\"grade[0]\" value=\"$i\" alt=\"$i\" /></td>\n";
2439 echo "<td align=\"center\">{$elements[$i]->maxscore}</td></tr>\n";
2441 echo "</table></div>\n";
2442 echo "<p><div class=\"boxaligncenter\"><table cellpadding=\"5\" border=\"1\"><tr><td><b>".get_string("optionaladjustment",
2443 "workshop")."</b></td><td>\n";
2445 for ($j = 20; $j >= -20; $j--) {
2448 if (isset($grades[1]->grade
)) {
2449 choose_from_menu($numbers, "grade[1]", $grades[1]->grade
, "");
2452 choose_from_menu($numbers, "grade[1]", 0, "");
2454 echo "</td></tr>\n";
2457 case 4: // rubric grading
2458 // now run through the elements...
2459 for ($i=0; $i < count($elements); $i++
) {
2461 echo "<tr valign=\"top\">\n";
2462 echo "<td align=\"right\"><b>".get_string("element", "workshop")." $iplus1:</b></td>\n";
2463 echo "<td>".format_text($elements[$i]->description
).
2464 "<p style=\"text-align:right\">".get_string("weight", "workshop").": ".
2465 number_format($WORKSHOP_EWEIGHTS[$elements[$i]->weight
], 2)."</td></tr>\n";
2466 echo "<tr valign=\"top\">\n";
2467 echo " <td class=\"workshopassessmentheading\" align=\"center\"><b>".get_string("select", "workshop").
2469 echo " <td class=\"workshopassessmentheading\"><b>". get_string("criterion","workshop").
2471 if (isset($grades[$i])) {
2472 $selection = $grades[$i]->grade
;
2476 // ...and the rubrics
2477 if ($rubricsraw = get_records_select("workshop_rubrics", "workshopid = $workshop->id AND
2478 elementno = $i", "rubricno ASC")) {
2480 foreach ($rubricsraw as $rubic) {
2481 $rubrics[] = $rubic; // to renumber index 0,1,2...
2483 for ($j=0; $j<5; $j++
) {
2484 if (empty($rubrics[$j]->description
)) {
2485 break; // out of inner for loop
2487 echo "<tr valign=\"top\">\n";
2488 if ($selection == $j) {
2489 echo " <td align=\"center\"><input type=\"radio\" name=\"grade[$i]\" value=\"$j\"
2490 checked=\"checked\" alt=\"$j\" /></td>\n";
2492 echo " <td align=\"center\"><input type=\"radio\" name=\"grade[$i]\" value=\"$j\"
2493 alt=\"$j\" /></td>\n";
2495 echo "<td>".format_text($rubrics[$j]->description
)."</td>\n";
2497 echo "<tr valign=\"top\">\n";
2498 echo " <td align=\"right\"><p><b>". get_string("feedback").":</b></p></td>\n";
2500 if ($allowchanges) {
2501 echo " <textarea name=\"feedback_$i\" rows=\"3\" cols=\"75\" >\n";
2502 if (isset($grades[$i]->feedback
)) {
2503 echo $grades[$i]->feedback
;
2505 echo "</textarea>\n";
2507 echo format_text($grades[$i]->feedback
);
2512 // if active and the teacher show stock comments...
2513 if ($allowchanges and workshop_is_teacher($workshop, $USER->id
)) {
2514 echo "<tr><td valign=\"top\" align=\"right\"><input type=\"button\" value=\"".
2515 get_string("addcomment", "workshop")."\"
2516 onclick=\"getElementById('assessmentform').action.value='addstockcomment';
2517 getElementById('assessmentform').elementno.value=$i;getElementById('assessmentform').submit();\" /> \n";
2518 helpbutton("addcommenttobank", get_string("addcomment", "workshop"), "workshop");
2520 if ($stockcomments = get_records_select("workshop_stockcomments", "workshopid = $workshop->id
2521 AND elementno = $i", "id")) { // show comments in fixed (creation) order
2522 foreach ($stockcomments as $stockcomment) {
2523 echo "<a onclick=\"getElementById('assessmentform').feedback_$i.value+=' '+'".
2524 addslashes($stockcomment->comments
).
2525 "';\"><<$stockcomment->comments>></a>\n";
2526 if (workshop_is_teacheredit($workshop, $USER->id
)) {
2527 echo " <a onclick=\"getElementById('assessmentform').action.value='removestockcomment';getElementById('assessmentform').stockcommentid.value=$stockcomment->id;getElementById('assessmentform').submit();\"> <small><i><--".get_string("delete","workshop")."</i></small></a>\n";
2532 echo "</td></tr>\n";
2535 echo "<tr valign=\"top\">\n";
2536 echo " <td colspan=\"2\" class=\"workshopassessmentheading\"> </td>\n";
2541 } // end of outer switch
2543 // now get the general comment (present in all types)
2544 echo "<tr valign=\"top\">\n";
2545 switch ($workshop->gradingstrategy
) {
2548 case 4 : // no grading, accumulative and rubic
2549 echo " <td align=\"right\"><p><b>". get_string("generalcomment", "workshop").":</b></p></td>\n";
2552 echo " <td align=\"right\"><p><b>".get_string("generalcomment", "workshop")."/<br />".
2553 get_string("reasonforadjustment", "workshop").":</b></p></td>\n";
2556 if ($allowchanges) {
2557 echo " <textarea name=\"generalcomment\" rows=\"5\" cols=\"75\" >\n";
2558 if (isset($assessment->generalcomment
)) {
2559 echo $assessment->generalcomment
;
2561 echo "</textarea>\n";
2564 if (isset($assessment->generalcomment
)) {
2565 echo format_text($assessment->generalcomment
);
2568 print_string("yourfeedbackgoeshere", "workshop");
2571 echo " </td>\n";
2573 // if active and the teacher show stock comments...
2574 if ($allowchanges and workshop_is_teacher($workshop, $USER->id
)) {
2575 echo "<tr><td valign=\"top\" align=\"right\"><input type=\"button\" value=\"".
2576 get_string("addcomment", "workshop")."\"
2577 onclick=\"getElementById('assessmentform').action.value='addstockcomment';
2578 getElementById('assessmentform').elementno.value=99;getElementById('assessmentform').submit();\" /> \n";
2579 helpbutton("addcommenttobank", get_string("addcomment", "workshop"), "workshop");
2581 if ($stockcomments = get_records_select("workshop_stockcomments", "workshopid = $workshop->id
2582 AND elementno = 99", "id")) { // show in the same order (oldest at the top)
2583 foreach ($stockcomments as $stockcomment) {
2584 echo "<a onclick=\"getElementById('assessmentform').generalcomment.value+=' '+'".
2585 addslashes($stockcomment->comments
)."';\"><<$stockcomment->comments>></a>\n";
2586 if (workshop_is_teacheredit($workshop, $USER->id
)) {
2587 echo " <a onclick=\"getElementById('assessmentform').action.value='removestockcomment';getElementById('assessmentform').stockcommentid.value=$stockcomment->id;getElementById('assessmentform').submit();\"> <small><i><--".get_string("delete","workshop")."</i></small></a>\n";
2592 echo "</td></tr>\n";
2596 // now show the grading grade if available...
2597 if ($assessment->timegraded
) {
2598 echo "<tr valign=\"top\">\n";
2599 echo "<td colspan=\"2\" class=\"workshopassessmentheading\" align=\"center\"><b>".
2600 get_string('gradeforstudentsassessment', 'workshop')."</b></td>\n";
2603 if ($assessment->teachercomment
) {
2604 echo "<tr valign=top>\n";
2605 echo " <td align=\"right\"><p><b>". get_string("teacherscomment", "workshop").":</b></p></td>\n";
2607 echo text_to_html($assessment->teachercomment
);
2608 echo " </td>\n";
2612 echo "<tr valign=\"top\">\n";
2613 echo " <td align=\"right\"><p><b>";
2614 print_string('grade', 'workshop');
2615 echo ":</b></p></td><td>\n";
2616 echo number_format($assessment->gradinggrade
* $workshop->gradinggrade
/ 100, 0);
2617 echo " </td>\n";
2621 echo "<tr valign=\"top\">\n";
2622 echo " <td colspan=\"2\" class=\"workshopassessmentheading\"> </td>\n";
2625 // ...and close the table, show submit button if needed...
2628 if ($allowchanges) {
2629 echo "<input type=\"submit\" value=\"".get_string("savemyassessment", "workshop")."\" />\n";
2631 // ...if user is author, assessment not agreed, there's no comments, the showcommentlinks flag is set and
2632 // it's not self assessment then show some buttons!
2633 if (($submission->userid
== $USER->id
) and !$assessment->timeagreed
and !$comments and $showcommentlinks and
2634 $submission->userid
!= $assessment->userid
) {
2635 echo "<input type=\"button\" value=\"".get_string("agreetothisassessment", "workshop")."\"
2636 onclick=\"getElementById('assessmentform').action.value='agreeassessment';getElementById('assessmentform').submit();\" />\n";
2637 echo "<input type=\"submit\" value=\"".get_string("disagreewiththisassessment", "workshop")."\"
2638 onclick=\"getElementById('assessmentform').action.value='addcomment';getElementById('assessmentform').submit();\" />\n";
2642 echo "</div></form>\n";
2646 //////////////////////////////////////////////////////////////////////////////////////
2647 function workshop_print_assessments_by_user_for_admin($workshop, $user) {
2649 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
2650 error("Course Module ID was incorrect");
2653 if ($assessments = workshop_get_user_assessments_done($workshop, $user)) {
2654 foreach ($assessments as $assessment) {
2655 workshop_print_assessment($workshop, $assessment);
2656 echo "<p style=\"text-align:right\">".
2657 '<a href="viewassessment.php?&id='.$cm->id
.'&stype=student&aid='.$assessment->id
.'">'.
2658 get_string('assessthisassessment', 'workshop').'</a> | '.
2659 "<a href=\"assessments.php?action=confirmdelete&id=$cm->id&aid=$assessment->id\">".
2660 get_string("delete", "workshop")."</a></p><hr />\n";
2666 //////////////////////////////////////////////////////////////////////////////////////
2667 function workshop_print_assessments_for_admin($workshop, $submission) {
2669 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
2670 error("Course Module ID was incorrect");
2673 if ($assessments =workshop_get_assessments($submission)) {
2674 foreach ($assessments as $assessment) {
2675 if (!$user = get_record("user", "id", $assessment->userid
)) {
2676 error (" workshop_print_assessments_for_admin: unable to get user record");
2678 echo "<p><div style=\"text-align:center;\"><b>".get_string("assessmentby", "workshop", fullname($user))."</b></div></p>\n";
2679 workshop_print_assessment($workshop, $assessment);
2680 echo "<p style=\"text-align:right\"><a href=\"assessments.php?action=confirmdelete&id=$cm->id&aid=$assessment->id\">".
2681 get_string("delete", "workshop")."</a></p><hr />\n";
2687 //////////////////////////////////////////////////////////////////////////////////////
2688 function workshop_print_assignment_info($workshop) {
2691 if (! $course = get_record("course", "id", $workshop->course
)) {
2692 error("Course is misconfigured");
2694 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $course->id
)) {
2695 error("Course Module ID was incorrect");
2697 // print standard assignment heading
2698 print_heading(format_string($workshop->name
), "center");
2699 print_simple_box_start("center");
2701 // print phase and date info
2702 $string = '<b>'.get_string('currentphase', 'workshop').'</b>: '.workshop_phase($workshop).'<br />';
2704 'submissionstart' => $workshop->submissionstart
,
2705 'submissionend' => $workshop->submissionend
,
2706 'assessmentstart' => $workshop->assessmentstart
,
2707 'assessmentend' => $workshop->assessmentend
2709 foreach ($dates as $type => $date) {
2711 $strdifference = format_time($date - time());
2712 if (($date - time()) < 0) {
2713 $strdifference = "<span class=\"redfont\">$strdifference</span>";
2715 $string .= '<b>'.get_string($type, 'workshop').'</b>: '.userdate($date)." ($strdifference)<br />";
2720 $grade = $workshop->gradinggrade +
$workshop->grade
;
2721 echo "<br /><b>".get_string("maximumgrade")."</b>: $grade ";
2722 // print link to specimen assessment form
2723 echo "(<a href=\"assessments.php?id=$cm->id&action=displaygradingform\">".
2724 get_string("specimenassessmentform", "workshop")."</a>";
2726 if (workshop_is_teacheredit($workshop) and $workshop->nelements
) {
2727 echo " <a href=\"assessments.php?id=$cm->id&action=editelements\">".
2728 "<img src=\"$CFG->pixpath/t/edit.gif\" ".
2729 'class="iconsmall" alt="'.get_string('amendassessmentelements', 'workshop').'" /></a>';
2732 print_simple_box_end();
2736 //////////////////////////////////////////////////////////////////////////////////////
2737 function workshop_print_difference($time) {
2739 $timetext = get_string("late", "assignment", format_time($time));
2740 return " (<span class=\"redfont\">$timetext</span>)";
2742 $timetext = get_string("early", "assignment", format_time($time));
2743 return " ($timetext)";
2748 //////////////////////////////////////////////////////////////////////////////////////
2749 function workshop_print_key($workshop) {
2750 // print an explaination of the grades
2752 if (!$course = get_record("course", "id", $workshop->course
)) {
2753 error("Print key: course not found");
2755 echo "<div class=\"workshopkey\">\n";
2756 echo "<p><small>{} ".get_string("assessmentby", "workshop", $course->student
)."; \n";
2757 echo "[] ".get_string("assessmentby", "workshop", $course->teacher
)."; \n";
2758 echo "<> ".get_string("assessmentdropped", "workshop").";\n";
2759 if ($workshop->agreeassessments
) echo "<<>> ".get_string("assessmentnotyetagreed", "workshop").";\n";
2760 echo "<br />() ".get_string("automaticgradeforassessment", "workshop")."; \n";
2761 echo "[] ".get_string("teachergradeforassessment", "workshop", $course->teacher
).".\n";
2762 echo "<br />".get_string("gradesforsubmissionsare", "workshop", $workshop->grade
)."; \n";
2763 echo get_string("gradesforassessmentsare", "workshop", $workshop->gradinggrade
).".</small></p>\n";
2769 //////////////////////////////////////////////////////////////////////////////////////
2770 function workshop_print_league_table($workshop) {
2771 // print an order table of (student) submissions showing teacher's and student's assessments
2773 if (! $course = get_record("course", "id", $workshop->course
)) {
2774 error("Print league table: Course is misconfigured");
2776 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
2777 error("Course Module ID was incorrect");
2779 // set $groupid if workshop is in SEPARATEGROUPS mode
2780 if (groupmode($course, $cm) == SEPARATEGROUPS
) {
2781 $groupid = get_current_group($course->id
);
2786 $nentries = $workshop->showleaguetable
;
2787 if ($workshop->anonymous
and workshop_is_student($workshop)) {
2788 $table->head
= array (get_string("title", "workshop"),
2789 get_string("teacherassessments", "workshop", $course->teacher
),
2790 get_string("studentassessments", "workshop", $course->student
), get_string("overallgrade", "workshop"));
2791 $table->align
= array ("left", "center", "center", "center");
2792 $table->size
= array ("*", "*", "*", "*");
2794 else { // show names
2795 $table->head
= array (get_string("title", "workshop"), get_string("name"),
2796 get_string("teacherassessments", "workshop", $course->teacher
),
2797 get_string("studentassessments", "workshop", $course->student
), get_string("overallgrade", "workshop"));
2798 $table->align
= array ("left", "left", "center", "center", "center");
2799 $table->size
= array ("*", "*", "*", "*", "*");
2801 $table->cellpadding
= 2;
2802 $table->cellspacing
= 0;
2804 if ($submissions = workshop_get_student_submissions($workshop)) {
2805 foreach ($submissions as $submission) {
2807 // check submission's group
2808 if (!ismember($groupid, $submission->userid
)) {
2809 continue; // skip this submission
2812 $grades[$submission->id
] = workshop_submission_grade($workshop, $submission);
2814 arsort($grades); // largest grade first
2817 while (list($submissionid, $grade) = each($grades)) {
2818 if (!$submission = get_record("workshop_submissions", "id", $submissionid)) {
2819 error("Print league table: submission not found");
2821 if (!$user = get_record("user", "id", $submission->userid
)) {
2822 error("Print league table: user not found");
2824 if ($workshop->anonymous
and workshop_is_student($workshop)) {
2825 $table->data
[] = array(workshop_print_submission_title($workshop, $submission),
2826 workshop_print_submission_assessments($workshop, $submission, "teacher"),
2827 workshop_print_submission_assessments($workshop, $submission, "student"), $grade);
2830 $table->data
[] = array(workshop_print_submission_title($workshop, $submission), fullname($user),
2831 workshop_print_submission_assessments($workshop, $submission, "teacher"),
2832 workshop_print_submission_assessments($workshop, $submission, "student"), $grade);
2835 if ($n > $nentries) {
2839 print_heading(get_string("leaguetable", "workshop"));
2840 print_table($table);
2841 workshop_print_key($workshop);
2846 //////////////////////////////////////////////////////////////////////////////////////
2847 function workshop_print_submission($workshop, $submission) {
2848 // prints the submission with optional attachments
2851 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
2852 error("Course Module ID was incorrect");
2854 print_simple_box(format_text($submission->description
), 'center');
2855 if ($workshop->nattachments
) {
2857 echo "<table align=\"center\">\n";
2858 $filearea = workshop_file_area_name($workshop, $submission);
2859 if ($basedir = workshop_file_area($workshop, $submission)) {
2860 if ($files = get_directory_list($basedir)) {
2861 foreach ($files as $file) {
2862 $icon = mimeinfo("icon", $file);
2863 if ($CFG->slasharguments
) {
2864 $ffurl = "file.php/$filearea/$file";
2866 $ffurl = "file.php?file=/$filearea/$file";
2868 echo "<tr><td><b>".get_string("attachment", "workshop")." $n:</b> \n";
2869 // removed target=\"uploadedfile\" as it does not validate
2871 echo "<img src=\"$CFG->pixpath/f/$icon\" class=\"icon\" alt=\"".get_string('file')."\" />".
2872 " <a href=\"$CFG->wwwroot/$ffurl\">$file</a></td></tr>";
2883 //////////////////////////////////////////////////////////////////////////////////////
2884 function workshop_print_submission_assessments($workshop, $submission, $type) {
2886 // Returns the teacher or peer grade and a hyperlinked list of grades for this submission
2887 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
2888 error("Course Module ID was incorrect");
2891 // get the assessments in grade order, highest first
2892 if ($assessments = workshop_get_assessments($submission, "", "grade DESC")) {
2893 if ($type == 'teacher' or $type == 'all') {
2894 // students can see teacher assessments only if the release date has passed
2896 if (workshop_is_teacher($workshop, $USER->id
) or ($timenow > $workshop->releasegrades
)) {
2897 foreach ($assessments as $assessment) {
2898 if (workshop_is_teacher($workshop, $assessment->userid
)) {
2899 if ($type == 'all') {
2900 $str .= workshop_fullname($assessment->userid
, $workshop->course
).': ';
2902 $str .= "<a href=\"viewassessment.php?aid=$assessment->id\">"
2903 . "[".number_format($assessment->grade
*$workshop->grade
/ 100, 0)."]</a>";
2904 if (workshop_is_teacher($workshop, $USER->id
)) {
2905 $str .= ' <a title="'.get_string('reassess', 'workshop').
2906 "\" href=\"assess.php?id=$cm->id&sid=$submission->id\"><img src=\"$CFG->pixpath/t/edit.gif\" ".
2907 ' class="iconsmall" alt="'.get_string('reassess', 'workshop').'" /></a>';
2908 $str .= ' <a title="'.get_string('delete', 'workshop').
2909 "\" href=\"assessments.php?action=confirmdelete&wid=$workshop->id&aid=$assessment->id\"><img src=\"$CFG->pixpath/t/delete.gif\" ".
2910 ' class="iconsmall" alt="'.get_string('delete', 'workshop').'" /></a><br />';
2916 if ($type == 'student' or $type == 'all') {
2917 foreach ($assessments as $assessment) {
2918 if (workshop_is_student($workshop, $assessment->userid
)) {
2919 if ($type == 'all') {
2920 $str .= workshop_fullname($assessment->userid
, $workshop->course
).': ';
2922 $str .= "<a href=\"viewassessment.php?aid=$assessment->id\">";
2923 if ($workshop->agreeassessments
and !$assessment->timeagreed
and
2924 workshop_is_student($workshop, $submission->userid
)) { // agreement on student work only
2925 $str .= "<<".number_format($assessment->grade
* $workshop->grade
/ 100, 0)." (".
2926 number_format($assessment->gradinggrade
* $workshop->gradinggrade
/ 100, 0).
2928 } elseif ($assessment->timegraded
) {
2929 if ($assessment->gradinggrade
) {
2930 $str .= "{".number_format($assessment->grade
* $workshop->grade
/ 100, 0);
2931 if ($assessment->teachergraded
) {
2932 $str .= " [".number_format($assessment->gradinggrade
* $workshop->gradinggrade
/ 100, 0).
2935 $str .= " (".number_format($assessment->gradinggrade
* $workshop->gradinggrade
/ 100, 0).
2939 $str .= "<".number_format($assessment->grade
* $workshop->grade
/ 100, 0).
2943 $str .= "{".number_format($assessment->grade
* $workshop->grade
/ 100, 0)."}</a> ";
2951 $str = " "; // be kind to Mozilla browsers!
2957 //////////////////////////////////////////////////////////////////////////////////////
2958 function workshop_print_submission_title($workshop, $submission) {
2959 // Arguments are objects
2961 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
2962 error("Course Module ID was incorrect");
2965 if (!$submission->timecreated
) { // a "no submission"
2966 return $submission->title
;
2968 return "<a name=\"sid_$submission->id\" href=\"submissions.php?id=$cm->id&action=showsubmission&sid=$submission->id\">$submission->title</a>";
2973 function workshop_print_time_to_deadline($time) {
2975 $timetext = get_string("afterdeadline", "workshop", format_time($time));
2976 return " (<span class=\"redfont\">$timetext</span>)";
2978 $timetext = get_string("beforedeadline", "workshop", format_time($time));
2979 return " ($timetext)";
2984 //////////////////////////////////////////////////////////////////////////////////////
2985 function workshop_print_upload_form($workshop) {
2988 if (! $course = get_record("course", "id", $workshop->course
)) {
2989 error("Course is misconfigured");
2991 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $course->id
)) {
2992 error("Course Module ID was incorrect");
2994 $usehtmleditor = can_use_html_editor();
2996 echo "<div class=\"workshopuploadform\">";
2997 echo "<form enctype=\"multipart/form-data\" method=\"POST\" action=\"upload.php\">";
2998 echo "<fieldset class=\"invisiblefieldset\">";
2999 echo " <input type=\"hidden\" name=\"id\" value=\"$cm->id\" />";
3000 echo "<table celpadding=\"5\" border=\"1\" align=\"center\">\n";
3001 // now get the submission
3002 echo "<tr valign=\"top\"><td><b>". get_string("title", "workshop").":</b>\n";
3003 echo "<input type=\"text\" name=\"title\" size=\"60\" maxlength=\"100\" value=\"\" />\n";
3004 echo "</td></tr><tr><td><b>".get_string("submission", "workshop").":</b><br />\n";
3005 print_textarea($usehtmleditor, 25,70, 630, 400, "description");
3006 use_html_editor("description");
3007 echo "</td></tr><tr><td>\n";
3008 if ($workshop->nattachments
) {
3009 require_once($CFG->dirroot
.'/lib/uploadlib.php');
3010 for ($i=0; $i < $workshop->nattachments
; $i++
) {
3012 $tag[$i] = get_string("attachment", "workshop")." $iplus1:";
3014 upload_print_form_fragment($workshop->nattachments
,null,$tag,false,null,$course->maxbytes
,
3015 $workshop->maxbytes
,false);
3017 echo "</td></tr></table>\n";
3018 echo " <input type=\"submit\" name=\"save\" value=\"".get_string("submitassignment","workshop")."\" />";
3019 echo "</fieldset></form>";
3024 //////////////////////////////////////////////////////////////////////////////////////
3025 function workshop_print_user_assessments($workshop, $user, &$gradinggrade) {
3026 // Returns the number of assessments and a hyperlinked list of grading grades for the assessments made by this user
3028 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id
, $workshop->course
)) {
3029 error("Course Module ID was incorrect");
3034 if ($assessments = workshop_get_user_assessments_done($workshop, $user)) {
3035 foreach ($assessments as $assessment) {
3036 $gradinggrade +
= $assessment->gradinggrade
;
3038 $str .= "<a href=\"viewassessment.php?aid=$assessment->id\">";
3039 if ($assessment->timegraded
) {
3040 if ($assessment->gradinggrade
) {
3041 $str .= "{".number_format($assessment->grade
* $workshop->grade
/ 100, 0);
3042 if ($assessment->teachergraded
) {
3043 $str .= " [".number_format($assessment->gradinggrade
* $workshop->gradinggrade
/ 100)."]}</a> ";
3045 $str .= " (".number_format($assessment->gradinggrade
* $workshop->gradinggrade
/ 100).")}</a> ";
3048 $str .= "<".number_format($assessment->grade
* $workshop->grade
/ 100, 0)." (0)></a> ";
3051 $str .= "{".number_format($assessment->grade
* $workshop->grade
/ 100, 0)." (-)}</a> ";
3059 if ($n = max($n, $workshop->ntassessments +
$workshop->nsassessments
)) {
3060 $gradinggrade = number_format($gradinggrade/$n * $workshop->gradinggrade
/ 100, 1);
3067 //////////////////////////////////////////////////////////////////////////////////////
3068 function workshop_test_user_assessments($workshop, $user) {
3069 // see if user has assessed required number of assessments of teachers submissions...
3075 if ($submissions = workshop_get_teacher_submissions($workshop)) {
3076 foreach ($submissions as $submission) {
3077 if ($assessment = workshop_get_submission_assessment($submission, $user)) {
3078 // ...the date stamp on the assessment should be in the past
3079 if ($assessment->timecreated
< $timenow) {
3084 if ($n < min($workshop->ntassessments
, workshop_count_teacher_submissions($workshop))) {