Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / mod / workshop / submissions.php
blob71d9898854a922fe2356843ce6754ca86ed0923b
1 <?php // $Id$
3 /*************************************************
4 ACTIONS handled are:
6 adminamendtitle
7 confirmdelete
8 delete
9 adminlist
10 editsubmission
11 listallsubmissions
12 listforassessmentstudent
13 listforassessmentteacher
14 showsubmission
15 updatesubmission
18 ************************************************/
20 require("../../config.php");
21 require("lib.php");
22 require("locallib.php");
24 $id = required_param('id', PARAM_INT); // Course Module ID
25 $action = optional_param('action', '', PARAM_ALPHA);
26 $sid = optional_param('sid', 0, PARAM_INT); //submission id
27 $order = optional_param('order', 'name', PARAM_ALPHA);
28 $title = optional_param('title', '', PARAM_CLEAN);
29 $nentries = optional_param('nentries', '', PARAM_ALPHANUM);
30 $anonymous = optional_param('anonymous', '', PARAM_CLEAN);
31 $description = optional_param('description', '', PARAM_CLEAN);
33 $timenow = time();
35 // get some useful stuff...
36 if (! $cm = get_coursemodule_from_id('workshop', $id)) {
37 error("Course Module ID was incorrect");
39 if (! $course = get_record("course", "id", $cm->course)) {
40 error("Course is misconfigured");
42 if (! $workshop = get_record("workshop", "id", $cm->instance)) {
43 error("Course module is incorrect");
46 require_login($course->id, false, $cm);
47 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
49 $strworkshops = get_string("modulenameplural", "workshop");
50 $strworkshop = get_string("modulename", "workshop");
51 $strsubmissions = get_string("submissions", "workshop");
53 // ... print the header and...
54 $navlinks = array();
55 $navlinks[] = array('name' => $strworkshops, 'link' => "index.php?id=$course->id", 'type' => 'activity');
56 $navlinks[] = array('name' => format_string($workshop->name,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
57 $navlinks[] = array('name' => $strsubmissions, 'link' => '', 'type' => 'title');
58 $navigation = build_navigation($navlinks);
60 print_header_simple(format_string($workshop->name), "", $navigation,
61 "", "", true);
63 //...get the action or set up an suitable default
64 if (empty($action)) {
65 $action = "listallsubmissions";
69 /******************* admin amend title ************************************/
70 elseif ($action == 'adminamendtitle' ) {
72 require_capability('mod/workshop:manage', $context);
73 if (empty($sid)) {
74 error("Admin Amend Title: submission id missing");
77 $submission = get_record("workshop_submissions", "id", $sid);
78 print_heading(get_string("amendtitle", "workshop"));
80 <form id="amendtitleform" action="submissions.php" method="post">
81 <fieldset class="invisiblefieldset">
82 <input type="hidden" name="action" value="adminupdatetitle" />
83 <input type="hidden" name="id" value="<?php echo $cm->id ?>" />
84 <input type="hidden" name="sid" value="<?php echo $sid ?>" />
85 <div class="boxaligncenter">
86 <table cellpadding="5" border="1">
87 <?php
89 // now get the comment
90 echo "<tr valign=\"top\">\n";
91 echo " <td align=\"right\"><p><b>". get_string("title", "workshop").":</b></p></td>\n";
92 echo " <td>\n";
93 echo " <input type=\"text\" name=\"title\" size=\"60\" maxlength=\"100\" value=\"$submission->title\" />\n";
94 echo " </td></tr></table>\n";
95 echo "<input type=\"submit\" value=\"".get_string("amendtitle", "workshop")."\" />\n";
96 echo "</div></fieldset></form>\n";
98 print_heading("<a $CFG->frametarget href=\"view.php?id=$cm->id#sid=$submission->id\">".get_string("cancel")."</a>");
102 /******************* admin clear late (flag) ************************************/
103 elseif ($action == 'adminclearlate' ) {
105 require_capability('mod/workshop:manage', $context);
106 if (empty($sid)) {
107 error("Admin clear late flag: submission id missing");
110 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
111 error("Admin clear late flag: can not get submission record");
113 if (set_field("workshop_submissions", "late", 0, "id", $sid)) {
114 print_heading(get_string("clearlateflag", "workshop")." ".get_string("ok"));
117 add_to_log($course->id, "workshop", "late flag cleared", "view.php?id=$cm->id", "submission $submission->id");
119 redirect("view.php?id=$cm->id");
123 /******************* confirm delete ************************************/
124 elseif ($action == 'confirmdelete' ) {
126 if (empty($sid)) {
127 error("Confirm delete: submission id missing");
129 notice_yesno(get_string("confirmdeletionofthisitem","workshop", get_string("submission", "workshop")),
130 "submissions.php?action=delete&amp;id=$cm->id&amp;sid=$sid", "view.php?id=$cm->id#sid=$sid");
134 /******************* delete ************************************/
135 elseif ($action == 'delete' ) {
137 if (empty($sid)) {
138 error("Delete: submission id missing");
141 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
142 error("Admin delete: can not get submission record");
145 // students are only allowed to delete their own submission and only up to the deadline
146 if (!(workshop_is_teacher($workshop) or
147 (($USER->id = $submission->userid) and ($timenow < $workshop->submissionend)
148 and (($timenow < $workshop->assessmentstart) or ($timenow < $submission->timecreated + $CFG->maxeditingtime))))) {
149 error("You are not authorized to delete this submission");
152 print_string("deleting", "workshop");
153 // first get any assessments...
154 if ($assessments = workshop_get_assessments($submission, 'ALL')) {
155 foreach($assessments as $assessment) {
156 // ...and all the associated records...
157 delete_records("workshop_comments", "assessmentid", $assessment->id);
158 delete_records("workshop_grades", "assessmentid", $assessment->id);
159 echo ".";
161 // ...now delete the assessments...
162 delete_records("workshop_assessments", "submissionid", $submission->id);
164 // ...and the submission record...
165 delete_records("workshop_submissions", "id", $submission->id);
166 // ..and finally the submitted file
167 workshop_delete_submitted_files($workshop, $submission);
169 redirect("view.php?id=$cm->id");
173 /******************* admin (confirm) late flag ************************************/
174 elseif ($action == 'adminlateflag' ) {
176 require_capability('mod/workshop:manage', $context);
177 if (empty($sid)) {
178 error("Admin confirm late flag: submission id missing");
180 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
181 error("Admin confirm late flag: can not get submission record");
184 notice_yesno(get_string("clearlateflag","workshop")."?",
185 "submissions.php?action=adminclearlate&amp;id=$cm->id&amp;sid=$sid",
186 "view.php?id=$cm->id");
190 /******************* list all submissions ************************************/
191 elseif ($action == 'adminlist' ) {
193 require_capability('mod/workshop:manage', $context);
195 workshop_list_submissions_for_admin($workshop, $order);
196 print_continue("view.php?id=$cm->id");
201 /******************* admin update title ************************************/
202 elseif ($action == 'adminupdatetitle' ) {
204 require_capability('mod/workshop:manage', $context);
205 if (empty($sid)) {
206 error("Admin Update Title: submission id missing");
209 if (set_field("workshop_submissions", "title", $title, "id", $sid)) {
210 print_heading(get_string("amendtitle", "workshop")." ".get_string("ok"));
212 print_continue("view.php?id=$cm->id");
216 /******************* confirm remove attachments ************************************/
217 elseif ($action == 'confirmremoveattachments' ) {
219 if (empty($sid)) {
220 error("Admin confirm delete: submission id missing");
222 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
223 error("Admin delete: can not get submission record");
226 notice_yesno(get_string("confirmremoveattachments","workshop"),
227 "submissions.php?action=removeattachments&amp;id=$cm->id&amp;sid=$sid",
228 "view.php?id=$cm->id");
232 /******************* edit submission ************************************/
233 elseif ($action == 'editsubmission' ) {
235 if (empty($sid)) {
236 error("Edit submission: submission id missing");
238 $usehtmleditor = can_use_html_editor();
240 $submission = get_record("workshop_submissions", "id", $sid);
241 print_heading(get_string("editsubmission", "workshop"));
242 if ($submission->userid <> $USER->id) {
243 error("Edit submission: Userids do not match");
245 if (($submission->timecreated < ($timenow - $CFG->maxeditingtime)) and ($workshop->assessmentstart < $timenow)) {
246 error(get_string('notallowed', 'workshop'));
249 <form id="editform" enctype="multipart/form-data" action="submissions.php" method="post">
250 <fieldset class="invisiblefieldset">
251 <input type="hidden" name="action" value="updatesubmission" />
252 <input type="hidden" name="id" value="<?php echo $cm->id ?>" />
253 <input type="hidden" name="sid" value="<?php echo $sid ?>" />
254 <div class="boxaligncenter">
255 <table cellpadding="5" border="1">
256 <?php
257 echo "<tr valign=\"top\"><td><b>". get_string("title", "workshop").":</b>\n";
258 echo "<input type=\"text\" name=\"title\" size=\"60\" maxlength=\"100\" value=\"$submission->title\" />\n";
259 echo "</td></tr><tr><td><b>".get_string("submission", "workshop").":</b><br />\n";
260 print_textarea($usehtmleditor, 25,70, 630, 400, "description", $submission->description);
261 use_html_editor("description");
262 echo "</td></tr>\n";
263 if ($workshop->nattachments) {
264 $filearea = workshop_file_area_name($workshop, $submission);
265 if ($basedir = workshop_file_area($workshop, $submission)) {
266 if ($files = get_directory_list($basedir)) {
267 echo "<tr><td><b>".get_string("attachments", "workshop").
268 "</b><div style=\"text-align:right;\"><input type=\"button\" value=\"".get_string("removeallattachments",
269 "workshop")."\" onclick=\"getElementById('editform').action.value='removeattachments';
270 getElementById('editform').submit();\"/></div></td></tr>\n";
271 $n = 1;
272 foreach ($files as $file) {
273 $icon = mimeinfo("icon", $file);
274 if ($CFG->slasharguments) {
275 $ffurl = "file.php/$filearea/$file";
276 } else {
277 $ffurl = "file.php?file=/$filearea/$file";
279 // removed target=\"uploadedfile\"
280 // as it does not validate MDL_7861
281 echo "<tr><td>".get_string("attachment", "workshop")." $n: <img src=\"$CFG->pixpath/f/$icon\"
282 class=\"icon\" alt=\"".get_string('file')."\" />".
283 "&nbsp;<a href=\"$CFG->wwwroot/$ffurl\">$file</a></td></tr>\n";
285 } else {
286 echo "<tr><td><b>".get_string("noattachments", "workshop")."</b></td></tr>\n";
289 echo "<tr><td>\n";
290 require_once($CFG->dirroot.'/lib/uploadlib.php');
291 for ($i=0; $i < $workshop->nattachments; $i++) {
292 $iplus1 = $i + 1;
293 $tag[$i] = get_string("newattachment", "workshop")." $iplus1:";
295 upload_print_form_fragment($workshop->nattachments,null,$tag,false,null,$course->maxbytes,
296 $workshop->maxbytes,false);
297 echo "</td></tr>\n";
300 echo "</table>\n";
301 echo "<input type=\"submit\" value=\"".get_string("savemysubmission", "workshop")."\" />\n";
302 echo "</div></fieldset></form>\n";
306 /******************* list all submissions ************************************/
307 elseif ($action == 'listallsubmissions' ) {
308 if (!$users = workshop_get_students($workshop)) {
309 print_heading(get_string("nostudentsyet"));
310 print_footer($course);
311 exit;
313 print_heading(get_string("listofallsubmissions", "workshop").":", "CENTER");
314 workshop_list_all_submissions($workshop, $USER);
315 print_continue("view.php?id=$cm->id");
320 /******************* list for assessment student (submissions) ************************************/
321 elseif ($action == 'listforassessmentstudent' ) {
322 if (!$users = workshop_get_students($workshop)) {
323 print_heading(get_string("nostudentsyet"));
324 print_footer($course);
325 exit;
327 workshop_list_unassessed_student_submissions($workshop, $USER);
328 print_continue("view.php?id=$cm->id");
333 /******************* list for assessment teacher (submissions) ************************************/
334 elseif ($action == 'listforassessmentteacher' ) {
336 require_capability('mod/workshop:manage', $context);
338 workshop_list_unassessed_teacher_submissions($workshop, $USER);
339 print_continue("view.php?id=$cm->id");
344 /******************* remove (all) attachments ************************************/
345 elseif ($action == 'removeattachments' ) {
347 $form = data_submitted();
349 if (empty($form->sid)) {
350 error("Update submission: submission id missing");
353 $submission = get_record("workshop_submissions", "id", $form->sid);
355 // students are only allowed to remove their own attachments and only up to the deadline
356 if (!(workshop_is_teacher($workshop) or
357 (($USER->id = $submission->userid) and ($timenow < $workshop->submissionend)
358 and (($timenow < $workshop->assessmentstart) or ($timenow < $submission->timecreated + $CFG->maxeditingtime))))) {
359 error("You are not authorized to delete these attachments");
362 // amend title... just in case they were modified
363 // check existence of title
364 if (empty($form->title)) {
365 notify(get_string("notitlegiven", "workshop"));
366 } else {
367 set_field("workshop_submissions", "title", $form->title, "id", $submission->id);
368 set_field("workshop_submissions", "description", trim($form->description), "id", $submission->id);
370 print_string("removeallattachments", "workshop");
371 workshop_delete_submitted_files($workshop, $submission);
372 add_to_log($course->id, "workshop", "removeattachments", "view.php?id=$cm->id", "submission $submission->id");
374 print_continue("view.php?id=$cm->id#sid=$submission->id");
378 /******************* show submission ************************************/
379 elseif ($action == 'showsubmission' ) {
381 if (empty($sid)) {
382 error("Show submission: submission id missing");
385 $submission = get_record("workshop_submissions", "id", $sid);
386 $title = '"'.$submission->title.'" ';
387 if (workshop_is_teacher($workshop)) {
388 $title .= get_string('by', 'workshop').' '.workshop_fullname($submission->userid, $course->id);
390 print_heading($title);
391 echo '<div style="text-align:center">'.get_string('submitted', 'workshop').': '.userdate($submission->timecreated).'</div><br />';
392 workshop_print_submission($workshop, $submission);
393 print_continue(htmlentities($_SERVER['HTTP_REFERER'].'#sid='.$submission->id));
397 /*************** update (league table options teacher) ***************************/
398 elseif ($action == 'updateleaguetable') {
400 require_capability('mod/workshop:manage', $context);
402 // save number of entries in showleaguetable option
403 if ($nentries == 'All') {
404 $nentries = 99;
406 set_field("workshop", "showleaguetable", $nentries, "id", "$workshop->id");
408 // save the anonymous option
409 set_field("workshop", "anonymous", $anonymous, "id", "$workshop->id");
410 add_to_log($course->id, "workshop", "league table", "view.php?id=$cm->id", $nentries, $cm->id);
412 redirect("view.php?id=$cm->id");
416 /*************** update submission ***************************/
417 elseif ($action == 'updatesubmission') {
419 if (empty($sid)) {
420 error("Update submission: submission id missing");
422 $submission = get_record("workshop_submissions", "id", $sid);
424 // students are only allowed to update their own submission and only up to the deadline
425 if (!(workshop_is_teacher($workshop) or
426 (($USER->id = $submission->userid) and ($timenow < $workshop->submissionend)
427 and (($timenow < $workshop->assessmentstart) or ($timenow < $submission->timecreated + $CFG->maxeditingtime))))) {
428 error("You are not authorized to update your submission");
431 // check existence of title
432 if (empty($title)) {
433 $title = get_string("notitle", "workshop");
435 set_field("workshop_submissions", "title", $title, "id", $submission->id);
436 set_field("workshop_submissions", "description", trim($description), "id", $submission->id);
437 set_field("workshop_submissions", "timecreated", $timenow, "id", $submission->id);
438 if ($workshop->nattachments) {
439 require_once($CFG->dirroot.'/lib/uploadlib.php');
440 $um = new upload_manager(null,false,false,$course,false,$workshop->maxbytes);
441 if ($um->preprocess_files()) {
442 $dir = workshop_file_area_name($workshop, $submission);
443 if ($um->save_files($dir)) {
444 add_to_log($course->id, "workshop", "newattachment", "view.php?id=$cm->id", "$workshop->id");
445 print_heading(get_string("uploadsuccess", "workshop"));
447 // upload manager will print errors.
449 print_continue("view.php?id=$cm->id");
450 } else {
451 echo '</div>'; // close <div id='page'>
452 redirect("view.php?id=$cm->id#sid=$submission->id");
457 /*************** no man's land **************************************/
459 else {
461 error("Fatal Error: Unknown Action: ".$action."\n");
466 print_footer($course);