Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / mod / workshop / assess.php
blobedafaa4d5fb3d079a9d55f790023efa7b80aa38e
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 // removed <base target="_parent" />
63 // because it does not validate MDL-7861
64 $navlinks = array();
65 $navlinks[] = array('name' => $strworkshops, 'link' => "index.php?id=$course->id", 'type' => 'activity');
66 $navlinks[] = array('name' => format_string($workshop->name,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
67 $navlinks[] = array('name' => $strassess, 'link' => '', 'type' => 'title');
68 $navigation = build_navigation($navlinks);
70 print_header_simple(format_string($workshop->name), "",$navigation,
71 "", '', true);
73 // there can be an assessment record (for teacher submissions), if there isn't...
74 if (!$assessment = get_record("workshop_assessments", "submissionid", $submission->id, "userid",
75 $USER->id)) {
76 // if it's the teacher see if the user has done a self assessment if so copy it
77 if (workshop_is_teacher($workshop) and ($assessment = get_record("workshop_assessments", "submissionid",
78 $submission->id, "userid", $submission->userid))) {
79 $assessment = workshop_copy_assessment($assessment, $submission, true);
80 // need to set owner of assessment
81 set_field("workshop_assessments", "userid", $USER->id, "id", $assessment->id);
82 $assessment->resubmission = 0; // not set by workshop_copy_assessment
83 $assessment->timegraded = 0; // not set by workshop_copy_assessment
84 $assessment->timeagreed = 0; // not set by workshop_copy_assessment
85 } else {
86 $yearfromnow = time() + 365 * 86400;
87 // ...create one and set timecreated way in the future, this is reset when record is updated
88 $assessment->workshopid = $workshop->id;
89 $assessment->submissionid = $submission->id;
90 $assessment->userid = $USER->id;
91 $assessment->timecreated = $yearfromnow;
92 $assessment->grade = -1; // set impossible grade
93 $assessment->timegraded = 0;
94 $assessment->timeagreed = 0;
95 $assessment->resubmission = 0;
96 if (!$assessment->id = insert_record("workshop_assessments", $assessment)) {
97 error("Could not insert workshop assessment!");
99 // if it's the teacher and the workshop is error banded set all the elements to Yes
100 if (workshop_is_teacher($workshop) and ($workshop->gradingstrategy == 2)) {
101 for ($i =0; $i < $workshop->nelements; $i++) {
102 unset($element);
103 $element->workshopid = $workshop->id;
104 $element->assessmentid = $assessment->id;
105 $element->elementno = $i;
106 $element->feedback = '';
107 $element->grade = 1;
108 if (!$element->id = insert_record("workshop_grades", $element)) {
109 error("Could not insert workshop grade!");
112 // now set the adjustment
113 unset($element);
114 $i = $workshop->nelements;
115 $element->workshopid = $workshop->id;
116 $element->assessmentid = $assessment->id;
117 $element->elementno = $i;
118 $element->grade = 0;
119 if (!$element->id = insert_record("workshop_grades", $element)) {
120 error("Could not insert workshop grade!");
126 print_heading_with_help(get_string("assessthissubmission", "workshop"), "grading", "workshop");
128 // show assessment and allow changes
129 workshop_print_assessment($workshop, $assessment, true, $allowcomments, $redirect);
131 print_heading("<a $CFG->frametarget href=\"$redirect\">".get_string("cancel")."</a>");
132 print_footer($course);
133 exit;
136 /// print bottom frame with the submission
137 // removed <base target="_parent" /> as it does not validate MDL-7861
138 print_header('', '', '', '', '');
139 $title = '"'.$submission->title.'" ';
140 if (workshop_is_teacher($workshop)) {
141 $title .= ' '.get_string('by', 'workshop').' '.workshop_fullname($submission->userid, $course->id);
143 print_heading($title);
144 workshop_print_submission($workshop, $submission);
146 if (workshop_is_teacher($workshop)) {
147 echo '<br /><div style="text-align:center"><b>'.get_string('assessments', 'workshop').': </b><br />';
148 echo workshop_print_submission_assessments($workshop, $submission, "all");
149 echo '</div>';
153 print_footer('none');