1454b51cf8385d595af88b53d67f350424970095
[moodle.git] / mod / workshop / view.php
1 <?php  // $Id: view.php, v1.1 23 Aug 2003
3 /*************************************************
4     ACTIONS handled are:
6     displayfinalgrade (for students)
7     notavailable (for students)
8     studentsview
9     submitexample 
10     teachersview
11     
12 ************************************************/
14     require("../../config.php");
15     require("lib.php");
16     require("locallib.php");
17     
18     require_variable($id);    // Course Module ID
19     
20     $timenow = time();
22     // get some useful stuff...
23     if (! $cm = get_record("course_modules", "id", $id)) {
24         error("Course Module ID was incorrect");
25     }
26     if (! $course = get_record("course", "id", $cm->course)) {
27         error("Course is misconfigured");
28     }
29     if (! $workshop = get_record("workshop", "id", $cm->instance)) {
30         error("Course module is incorrect");
31     }
33     require_login($course->id);
35     // ...log activity...
36     add_to_log($course->id, "workshop", "view", "view.php?id=$cm->id", $workshop->id, $cm->id);
38     $strworkshops = get_string("modulenameplural", "workshop");
39     $strworkshop  = get_string("modulename", "workshop");
41     // ...display header...
42     print_header_simple("$workshop->name", "",
43                  "<a href=\"index.php?id=$course->id\">$strworkshops</a> -> $workshop->name", 
44                   "", "", true, update_module_button($cm->id, $course->id, $strworkshop), navmenu($course, $cm));
46     // ...and if necessary set default action 
47     
48     optional_variable($action);
49     if (isteacher($course->id)) {
50         if (empty($action)) { // no action specified, either go straight to elements page else the admin page
51             // has the assignment any elements
52             if (count_records("workshop_elements", "workshopid", $workshop->id) >= $workshop->nelements) {
53                 $action = "teachersview";
54             }
55             else {
56                 redirect("assessments.php?action=editelements&id=$cm->id");
57             }
58         }
59     }
60     elseif (!isguest()) { // it's a student then
61         if (!$cm->visible) {
62             notice(get_string("activityiscurrentlyhidden"));
63         }
64         if ($timenow < $workshop->submissionstart) { 
65             $action = 'notavailable'; 
66         } else if ($timenow < $workshop->assessmentend) {
67             $action = 'studentsview';
68         } else {
69             $action = 'displayfinalgrade';
70         }
71     }
72     else { // it's a guest, oh no!
73         $action = 'notavailable';
74     }
77     /****************** display final grade (for students) ************************************/
78     if ($action == 'displayfinalgrade' ) {
80         // show the final grades as stored in the tables...
81         print_heading(get_string("displayoffinalgrades", "workshop"));
82         if ($submissions = workshop_get_user_submissions($workshop, $USER)) { // any submissions from user?
83             echo "<center><table border=\"1\" width=\"90%\"><tr>";
84             echo "<td><b>".get_string("submissions", "workshop")."</b></td>";
85             if ($workshop->wtype) {
86                 echo "<td align=\"center\"><b>".get_string("assessmentsdone", "workshop")."</b></td>";
87                 echo "<td align=\"center\"><b>".get_string("gradeforassessments", "workshop")."</b></td>";
88             }
89             echo "<td align=\"center\"><b>".get_string("teacherassessments", "workshop", 
90                         $course->teacher)."</b></td>";
91             if ($workshop->wtype) {
92                 echo "<td align=\"center\"><b>".get_string("studentassessments", "workshop", 
93                         $course->student)."</b></td>";
94             }
95             echo "<td align=\"center\"><b>".get_string("gradeforsubmission", "workshop")."</b></td>";
96             echo "<td align=\"center\"><b>".get_string("overallgrade", "workshop")."</b></td></tr>\n";
97             $gradinggrade = workshop_gradinggrade($workshop, $USER);
98             foreach ($submissions as $submission) {
99                 $grade = workshop_submission_grade($workshop, $submission);
100                 echo "<tr><td>".workshop_print_submission_title($workshop, $submission)."</td>\n";
101                 if ($workshop->wtype) {
102                     echo "<td align=\"center\">".workshop_print_user_assessments($workshop, $USER)."</td>";
103                     echo "<td align=\"center\">$gradinggrade</td>";
104                 }
105                 echo "<td align=\"center\">".workshop_print_submission_assessments($workshop, 
106                             $submission, "teacher")."</td>";
107                 if ($workshop->wtype) {
108                     echo "<td align=\"center\">".workshop_print_submission_assessments($workshop, 
109                             $submission, "student")."</td>";
110                 }
111                 echo "<td align=\"center\">$grade</td>";
112                 echo "<td align=\"center\">".number_format($gradinggrade + $grade, 1)."</td></tr>\n";
113             }
114         }
115         echo "</table><br clear=\"all\" />\n";
116         workshop_print_key($workshop);
117         if ($workshop->showleaguetable) {
118             workshop_print_league_table($workshop);
119         }
120     }   
122     
123     /****************** assignment not available (for students)***********************/
124     elseif ($action == 'notavailable') {
125         print_heading(get_string("notavailable", "workshop"));
126     }
129     /****************** student's view could be in 1 of 4 stages ***********************/
130     elseif ($action == 'studentsview') {
131         // is a password needed?
132         if ($workshop->usepassword) {
133             $correctpass = false;
134             if (isset($_POST['userpassword'])) {
135                 if ($workshop->password == md5(trim($_POST['userpassword']))) {
136                     $USER->workshoploggedin[$workshop->id] = true;
137                     $correctpass = true;
138                 }
139             } elseif (isset($USER->workshoploggedin[$workshop->id])) {
140                 $correctpass = true;
141             }
143             if (!$correctpass) {
144                 print_simple_box_start("center");
145                 echo "<form name=\"password\" method=\"post\" action=\"view.php\">\n";
146                 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
147                 echo "<table cellpadding=\"7px\">";
148                 if (isset($_POST['userpassword'])) {
149                     echo "<tr align=\"center\" style='color:#DF041E;'><td>".get_string("wrongpassword", "workshop").
150                         "</td></tr>";
151                 }
152                 echo "<tr align=\"center\"><td>".get_string("passwordprotectedworkshop", "workshop", $workshop->name).
153                     "</td></tr>";
154                 echo "<tr align=\"center\"><td>".get_string("enterpassword", "workshop").
155                     " <input type=\"password\" name=\"userpassword\" /></td></tr>";
156                         
157                 echo "<tr align=\"center\"><td>";
158                 echo "<input type=\"button\" value=\"".get_string("cancel").
159                     "\" onclick=\"parent.location='../../course/view.php?id=$course->id';\">  ";
160                 echo "<input type=\"button\" value=\"".get_string("continue").
161                     "\" onclick=\"document.password.submit();\" />";
162                 echo "</td></tr></table>";
163                 print_simple_box_end();
164                 exit();
165             }
166         }
167         workshop_print_assignment_info($workshop);
168         // in Stage 1? - are there any teacher's submissions? and...
169         // ...has student assessed the required number of the teacher's submissions 
170         if ($workshop->ntassessments and (!workshop_test_user_assessments($workshop, $USER))) {
171             print_heading(get_string("pleaseassesstheseexamplesfromtheteacher", "workshop", 
172                         $course->teacher));
173             workshop_list_teacher_submissions($workshop, $USER);
174         }
175         // in stage 2? - submit own first attempt
176         else {
177             if ($workshop->ntassessments) { 
178                 // show assessment the teacher's examples, there may be feedback from teacher
179                 print_heading(get_string("yourassessmentsofexamplesfromtheteacher", "workshop", 
180                             $course->teacher));
181                 workshop_list_teacher_submissions($workshop, $USER);
182             }
183             // has user submitted anything yet? 
184             if (!workshop_get_user_submissions($workshop, $USER)) {
185                 if ($timenow < $workshop->submissionend) {
186                     // print upload form
187                     print_heading(get_string("submitassignmentusingform", "workshop").":");
188                     workshop_print_upload_form($workshop);
189                 } else {
190                     print_heading(get_string("submissionsnolongerallowed", "workshop"));
191                 }
192             }   
193             // in stage 3? - grade other student's submissions, resubmit and list all submissions
194             else {
195                 // is self assessment used in this workshop?
196                 if ($workshop->includeself) {
197                     // prints a table if there are any submissions which have not been self assessed yet
198                     workshop_list_self_assessments($workshop, $USER);
199                 }
200                 // if peer assessments are being done then show some  to assess...
201                 if ($workshop->nsassessments and ($workshop->assessmentstart < $timenow and $workshop->assessmentend > $timenow)) {  
202                     workshop_list_student_submissions($workshop, $USER);
203                 }
204                 // ..and any they have already done (and have gone cold)...
205                 if (workshop_count_user_assessments($workshop, $USER, "student")) {
206                     print_heading(get_string("yourassessments", "workshop"));
207                     workshop_list_assessed_submissions($workshop, $USER);
208                 }
209                 // list any assessments by teachers
210                 if (workshop_count_teacher_assessments_by_user($workshop, $USER) and ($timenow > $workshop->releasegrades)) {
211                     print_heading(get_string("assessmentsby", "workshop", $course->teachers));
212                     workshop_list_teacher_assessments_by_user($workshop, $USER);
213                 }
214                 // ... and show peer assessments
215                 if (workshop_count_peer_assessments($workshop, $USER)) {
216                     print_heading(get_string("assessmentsby", "workshop", $course->students));
217                     workshop_list_peer_assessments($workshop, $USER);
218                 }
219                 // list previous submissions
220                 print_heading(get_string("yoursubmissions", "workshop"));
221                 workshop_list_user_submissions($workshop, $USER);
222                 // are resubmissions allowed and the workshop is in submission/assessment phase?
223                 if ($workshop->resubmit and ($timenow > $workshop->assessmentstart and $timenow < $workshop->submissionend)) {
224                     // see if there are any cold assessments of the last submission
225                     // if there are then print upload form
226                     if ($submissions = workshop_get_user_submissions($workshop, $USER)) {
227                         foreach ($submissions as $submission) {
228                             $lastsubmission = $submission;
229                             break;
230                         }
231                         $n = 0; // number of cold assessments (not include self assessments)
232                         if ($assessments = workshop_get_assessments($lastsubmission)) {
233                             foreach ($assessments as $assessment) {
234                                 if ($assessment->userid <> $USER->id) {
235                                     $n++;
236                                 }
237                             }
238                         }
239                         if ($n) {
240                             echo "<hr size=\"1\" noshade=\"noshade\" />";
241                             print_heading(get_string("submitrevisedassignment", "workshop").":");
242                             workshop_print_upload_form($workshop);
243                             echo "<hr size=\"1\" noshade=\"noshade\" />";
244                         }
245                     }
246                 }
247             }
248         }
249     }
252     /****************** submission of example by teacher only***********************/
253     elseif ($action == 'submitexample') {
254     
255         if (!isteacher($course->id)) {
256             error("Only teachers can look at this page");
257         }
258     
259         workshop_print_assignment_info($workshop);
260         
261         // list previous submissions from teacher 
262         workshop_list_user_submissions($workshop, $USER);
263     
264         echo "<hr size=\"1\" noshade=\"noshade\" />";
265     
266         // print upload form
267         print_heading(get_string("submitexampleassignment", "workshop").":");
268         workshop_print_upload_form($workshop);
269     }
272     /****************** teacher's view - display admin page  ************/
273     elseif ($action == 'teachersview') {
275         if (!isteacher($course->id)) {
276             error("Only teachers can look at this page");
277         }
279         /// Check to see if groups are being used in this workshop
280         /// and if so, set $currentgroup to reflect the current group
281         $changegroup = isset($_GET['group']) ? $_GET['group'] : -1;  // Group change requested?
282         $groupmode = groupmode($course, $cm);   // Groups are being used?
283         $currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
284         
285         /// Allow the teacher to change groups (for this session)
286         if ($groupmode) {
287             if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
288                 print_group_menu($groups, $groupmode, $currentgroup, "view.php?id=$cm->id");
289             }
290         }
291         
292         print_heading_with_help(get_string("managingassignment", "workshop"), "managing2", "workshop");
293         
294         workshop_print_assignment_info($workshop);
295         
296         echo "<center>\n";
297         
298         // if there are assessment elements show link to edit them
299         if ($workshop->nelements) {
300             echo "<br /><b><a href=\"assessments.php?id=$cm->id&amp;action=editelements\">".
301                 get_string("amendassessmentelements", "workshop")."</a></b> \n";
302             helpbutton("elements", get_string("amendassessmentelements", "workshop"), "workshop");
303         }
304         
305         // if teacher examples show submission and assessment links
306         if ($workshop->ntassessments) { 
307             // submission link for teacher examples
308             echo "<br /><b><a href=\"view.php?id=$cm->id&amp;action=submitexample\">".
309                 get_string("submitexampleassignment", "workshop")."</a></b> \n";
310             helpbutton("submissionofexamples", get_string("submitexampleassignment", "workshop"),
311                     "workshop");
312             // show assessment link for teachers examples only once there are such examples
313             if ($n = workshop_count_teacher_submissions_for_assessment($workshop, $USER)) {
314                 echo "<br /><b><a href=\"submissions.php?id=$cm->id&amp;action=listforassessmentteacher\">".
315                     get_string("teachersubmissionsforassessment", "workshop", $n)."</a></b> \n";
316                 helpbutton("assessmentofexamples", get_string("teachersubmissionsforassessment", 
317                             "workshop"), "workshop");
318             }
319         }
321         if ($workshop->wtype) {
322             // only show grading assessments if there are grading grades involved
323             if ($numberofassessments = workshop_count_ungraded_assessments($workshop)) {
324                 echo "<br /><b><a href=\"assessments.php?id=$cm->id&amp;action=gradeallassessments\">".
325                     get_string("ungradedassessments", "workshop", 
326                     $numberofassessments)."</a></b> \n";
327                 helpbutton("ungradedassessments", 
328                     get_string("ungradedassessments", "workshop"), "workshop");
329             }
330         }
332         // Show link to student submissions for assessment only if assessment has started
333         if ($timenow > $workshop->assessmentstart) {
334             if ($numberofsubmissions = workshop_count_student_submissions_for_assessment($workshop, $USER)) {
335                 echo "<br /><b><a href=\"submissions.php?id=$cm->id&amp;action=listforassessmentstudent\">".
336                     get_string("studentsubmissionsforassessment", "workshop", 
337                     $numberofsubmissions)."</a></b> \n";
338                 helpbutton("gradingsubmissions", 
339                     get_string("studentsubmissionsforassessment", "workshop"), "workshop");
340             }
341         }
342         
343         // Show link to current grades
344         if ($timenow > $workshop->assessmentstart) {
345             if ($timenow < $workshop->assessmentend) {
346                 echo "<br /><b><a href=\"submissions.php?id=$cm->id&amp;action=displaycurrentgrades\">".
347                         get_string("displayofcurrentgrades", "workshop")."</a></b> \n";
348             } else {
349                 echo "<br /><b><a href=\"submissions.php?id=$cm->id&amp;action=displayfinalgrades\">".
350                         get_string("displayoffinalgrades", "workshop")."</a></b> \n";
351             }
352         }
354         echo "<br /><b><a href=\"submissions.php?id=$cm->id&amp;action=adminlist\">".
355             get_string("administration")."</a></b> \n";
356         
357         echo '</center><br />';
358     }
359     
360     
361     /*************** no man's land **************************************/
362     else {
363         error("Fatal Error: Unknown Action: ".$action."\n");
364     }
366     print_footer($course);
367     
368 ?>