Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / workshop / assess.php
blob3a1a8a5dd613ddd3ec843d11f64937b50bad6ee4
1 <?php // $Id$
3 require("../../config.php");
4 require("lib.php");
5 require("locallib.php");
7 $id = required_param('id', PARAM_INT); // Submission ID
8 $allowcomments = optional_param('allowcomments', 0, PARAM_BOOL);
9 $redirect = optional_param('redirect', '', PARAM_URL);
10 $frameset = optional_param('frameset', '', PARAM_ALPHA);
11 $sid = optional_param('sid', 0, PARAM_INT);
13 if (! $submission = get_record('workshop_submissions', 'id', $sid)) {
14 error("Incorrect submission id");
16 if (! $workshop = get_record("workshop", "id", $submission->workshopid)) {
17 error("Submission is incorrect");
19 if (! $course = get_record("course", "id", $workshop->course)) {
20 error("Workshop is misconfigured");
22 if (! $cm = get_coursemodule_from_instance("workshop", $workshop->id, $course->id)) {
23 error("No coursemodule found");
26 require_login($course->id, false, $cm);
29 if (!$redirect) {
30 //seems not to work properly
31 $redirect = htmlentities($_SERVER["HTTP_REFERER"].'#sid='.$submission->id);
35 $strworkshops = get_string("modulenameplural", "workshop");
36 $strworkshop = get_string("modulename", "workshop");
37 $strassess = get_string("assess", "workshop");
39 /// Now check whether we need to display a frameset
41 if (empty($frameset)) {
42 if ( get_string('thisdirection') == 'rtl' ) {
43 $direction = ' dir="rtl"';
44 } else {
45 $direction = ' dir="ltr"';
47 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n";
48 echo "<html $direction>\n";
49 echo "<head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n";
50 echo "<title>" . format_string($course->shortname) . ": ".format_string($workshop->name,true)."</title></head>\n";
51 echo "<frameset rows=\"50%,*\" border=\"10\">";
52 echo " <frame src=\"assess.php?id=$id&amp;sid=$sid&amp;frameset=top&amp;redirect=$redirect\" border=\"10\" />";
53 echo " <frame src=\"assess.php?id=$id&amp;sid=$sid&amp;frameset=bottom&amp;redirect=$redirect\" />";
54 echo "</frameset>";
55 echo "</html>";
56 exit;
59 /// top frame with the navigation bar and the assessment form
61 if ($frameset == "top") {
62 $navigation = build_navigation($strassess, $cm);
63 print_header_simple(format_string($workshop->name), "",$navigation,
64 "", '', true);
66 // there can be an assessment record (for teacher submissions), if there isn't...
67 if (!$assessment = get_record("workshop_assessments", "submissionid", $submission->id, "userid",
68 $USER->id)) {
69 // if it's the teacher see if the user has done a self assessment if so copy it
70 if (workshop_is_teacher($workshop) and ($assessment = get_record("workshop_assessments", "submissionid",
71 $submission->id, "userid", $submission->userid))) {
72 $assessment = workshop_copy_assessment($assessment, $submission, true);
73 // need to set owner of assessment
74 set_field("workshop_assessments", "userid", $USER->id, "id", $assessment->id);
75 $assessment->resubmission = 0; // not set by workshop_copy_assessment
76 $assessment->timegraded = 0; // not set by workshop_copy_assessment
77 $assessment->timeagreed = 0; // not set by workshop_copy_assessment
78 } else {
79 $yearfromnow = time() + 365 * 86400;
80 // ...create one and set timecreated way in the future, this is reset when record is updated
81 $assessment->workshopid = $workshop->id;
82 $assessment->submissionid = $submission->id;
83 $assessment->userid = $USER->id;
84 $assessment->timecreated = $yearfromnow;
85 $assessment->grade = -1; // set impossible grade
86 $assessment->timegraded = 0;
87 $assessment->timeagreed = 0;
88 $assessment->resubmission = 0;
89 $assessment->generalcomment = '';
90 $assessment->teachercomment = '';
91 if (!$assessment->id = insert_record("workshop_assessments", $assessment)) {
92 error("Could not insert workshop assessment!");
94 // if it's the teacher and the workshop is error banded set all the elements to Yes
95 if (workshop_is_teacher($workshop) and ($workshop->gradingstrategy == 2)) {
96 for ($i =0; $i < $workshop->nelements; $i++) {
97 unset($element);
98 $element->workshopid = $workshop->id;
99 $element->assessmentid = $assessment->id;
100 $element->elementno = $i;
101 $element->feedback = '';
102 $element->grade = 1;
103 if (!$element->id = insert_record("workshop_grades", $element)) {
104 error("Could not insert workshop grade!");
107 // now set the adjustment
108 unset($element);
109 $i = $workshop->nelements;
110 $element->workshopid = $workshop->id;
111 $element->assessmentid = $assessment->id;
112 $element->elementno = $i;
113 $element->grade = 0;
114 if (!$element->id = insert_record("workshop_grades", $element)) {
115 error("Could not insert workshop grade!");
121 print_heading_with_help(get_string("assessthissubmission", "workshop"), "grading", "workshop");
123 // show assessment and allow changes
124 workshop_print_assessment($workshop, $assessment, true, $allowcomments, $redirect);
126 print_heading("<a $CFG->frametarget href=\"$redirect\">".get_string("cancel")."</a>");
127 print_footer($course);
128 exit;
131 /// print bottom frame with the submission
132 // removed <base target="_parent" /> as it does not validate MDL-7861
133 print_header('', '', '', '', '');
134 $title = '"'.$submission->title.'" ';
135 if (workshop_is_teacher($workshop)) {
136 $title .= ' '.get_string('by', 'workshop').' '.workshop_fullname($submission->userid, $course->id);
138 print_heading($title);
139 workshop_print_submission($workshop, $submission);
141 if (workshop_is_teacher($workshop)) {
142 echo '<br /><div style="text-align:center"><b>'.get_string('assessments', 'workshop').': </b><br />';
143 echo workshop_print_submission_assessments($workshop, $submission, "all");
144 echo '</div>';
148 print_footer('none');