3 /*************************************************
12 listforassessmentstudent
13 listforassessmentteacher
18 ************************************************/
20 require("../../config.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
);
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 $navigation = build_navigation($strsubmissions, $cm);
55 print_header_simple(format_string($workshop->name
), "", $navigation,
58 //...get the action or set up an suitable default
60 $action = "listallsubmissions";
64 /******************* admin amend title ************************************/
65 elseif ($action == 'adminamendtitle' ) {
67 require_capability('mod/workshop:manage', $context);
69 error("Admin Amend Title: submission id missing");
72 $submission = get_record("workshop_submissions", "id", $sid);
73 print_heading(get_string("amendtitle", "workshop"));
75 <form id
="amendtitleform" action
="submissions.php" method
="post">
76 <fieldset
class="invisiblefieldset">
77 <input type
="hidden" name
="action" value
="adminupdatetitle" />
78 <input type
="hidden" name
="id" value
="<?php echo $cm->id ?>" />
79 <input type
="hidden" name
="sid" value
="<?php echo $sid ?>" />
80 <div
class="boxaligncenter">
81 <table cellpadding
="5" border
="1">
84 // now get the comment
85 echo "<tr valign=\"top\">\n";
86 echo " <td align=\"right\"><p><b>". get_string("title", "workshop").":</b></p></td>\n";
88 echo " <input type=\"text\" name=\"title\" size=\"60\" maxlength=\"100\" value=\"$submission->title\" />\n";
89 echo " </td></tr></table>\n";
90 echo "<input type=\"submit\" value=\"".get_string("amendtitle", "workshop")."\" />\n";
91 echo "</div></fieldset></form>\n";
93 print_heading("<a $CFG->frametarget href=\"view.php?id=$cm->id#sid=$submission->id\">".get_string("cancel")."</a>");
97 /******************* admin clear late (flag) ************************************/
98 elseif ($action == 'adminclearlate' ) {
100 require_capability('mod/workshop:manage', $context);
102 error("Admin clear late flag: submission id missing");
105 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
106 error("Admin clear late flag: can not get submission record");
108 if (set_field("workshop_submissions", "late", 0, "id", $sid)) {
109 print_heading(get_string("clearlateflag", "workshop")." ".get_string("ok"));
112 add_to_log($course->id
, "workshop", "late flag cleared", "view.php?id=$cm->id", "submission $submission->id");
114 redirect("view.php?id=$cm->id");
118 /******************* confirm delete ************************************/
119 elseif ($action == 'confirmdelete' ) {
122 error("Confirm delete: submission id missing");
124 notice_yesno(get_string("confirmdeletionofthisitem","workshop", get_string("submission", "workshop")),
125 "submissions.php?action=delete&id=$cm->id&sid=$sid", "view.php?id=$cm->id#sid=$sid");
129 /******************* delete ************************************/
130 elseif ($action == 'delete' ) {
133 error("Delete: submission id missing");
136 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
137 error("Admin delete: can not get submission record");
140 // students are only allowed to delete their own submission and only up to the deadline
141 if (!(workshop_is_teacher($workshop) or
142 (($USER->id
= $submission->userid
) and ($timenow < $workshop->submissionend
)
143 and (($timenow < $workshop->assessmentstart
) or ($timenow < $submission->timecreated +
$CFG->maxeditingtime
))))) {
144 error("You are not authorized to delete this submission");
147 print_string("deleting", "workshop");
148 // first get any assessments...
149 if ($assessments = workshop_get_assessments($submission, 'ALL')) {
150 foreach($assessments as $assessment) {
151 // ...and all the associated records...
152 delete_records("workshop_comments", "assessmentid", $assessment->id
);
153 delete_records("workshop_grades", "assessmentid", $assessment->id
);
156 // ...now delete the assessments...
157 delete_records("workshop_assessments", "submissionid", $submission->id
);
159 // ...and the submission record...
160 delete_records("workshop_submissions", "id", $submission->id
);
161 // ..and finally the submitted file
162 workshop_delete_submitted_files($workshop, $submission);
164 redirect("view.php?id=$cm->id");
168 /******************* admin (confirm) late flag ************************************/
169 elseif ($action == 'adminlateflag' ) {
171 require_capability('mod/workshop:manage', $context);
173 error("Admin confirm late flag: submission id missing");
175 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
176 error("Admin confirm late flag: can not get submission record");
179 notice_yesno(get_string("clearlateflag","workshop")."?",
180 "submissions.php?action=adminclearlate&id=$cm->id&sid=$sid",
181 "view.php?id=$cm->id");
185 /******************* list all submissions ************************************/
186 elseif ($action == 'adminlist' ) {
188 require_capability('mod/workshop:manage', $context);
190 workshop_list_submissions_for_admin($workshop, $order);
191 print_continue("view.php?id=$cm->id");
196 /******************* admin update title ************************************/
197 elseif ($action == 'adminupdatetitle' ) {
199 require_capability('mod/workshop:manage', $context);
201 error("Admin Update Title: submission id missing");
204 if (set_field("workshop_submissions", "title", $title, "id", $sid)) {
205 print_heading(get_string("amendtitle", "workshop")." ".get_string("ok"));
207 print_continue("view.php?id=$cm->id");
211 /******************* confirm remove attachments ************************************/
212 elseif ($action == 'confirmremoveattachments' ) {
215 error("Admin confirm delete: submission id missing");
217 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
218 error("Admin delete: can not get submission record");
221 notice_yesno(get_string("confirmremoveattachments","workshop"),
222 "submissions.php?action=removeattachments&id=$cm->id&sid=$sid",
223 "view.php?id=$cm->id");
227 /******************* edit submission ************************************/
228 elseif ($action == 'editsubmission' ) {
231 error("Edit submission: submission id missing");
233 $usehtmleditor = can_use_html_editor();
235 $submission = get_record("workshop_submissions", "id", $sid);
236 print_heading(get_string("editsubmission", "workshop"));
237 if ($submission->userid
<> $USER->id
) {
238 error("Edit submission: Userids do not match");
240 if (($submission->timecreated
< ($timenow - $CFG->maxeditingtime
)) and ($workshop->assessmentstart
< $timenow)) {
241 print_error('notallowed', 'workshop');
244 <form id
="editform" enctype
="multipart/form-data" action
="submissions.php" method
="post">
245 <fieldset
class="invisiblefieldset">
246 <input type
="hidden" name
="action" value
="updatesubmission" />
247 <input type
="hidden" name
="id" value
="<?php echo $cm->id ?>" />
248 <input type
="hidden" name
="sid" value
="<?php echo $sid ?>" />
249 <div
class="boxaligncenter">
250 <table cellpadding
="5" border
="1">
252 echo "<tr valign=\"top\"><td><b>". get_string("title", "workshop").":</b>\n";
253 echo "<input type=\"text\" name=\"title\" size=\"60\" maxlength=\"100\" value=\"$submission->title\" />\n";
254 echo "</td></tr><tr><td><b>".get_string("submission", "workshop").":</b><br />\n";
255 print_textarea($usehtmleditor, 25,70, 630, 400, "description", $submission->description
);
256 use_html_editor("description");
258 if ($workshop->nattachments
) {
259 $filearea = workshop_file_area_name($workshop, $submission);
260 if ($basedir = workshop_file_area($workshop, $submission)) {
261 if ($files = get_directory_list($basedir)) {
262 echo "<tr><td><b>".get_string("attachments", "workshop").
263 "</b><div style=\"text-align:right;\"><input type=\"button\" value=\"".get_string("removeallattachments",
264 "workshop")."\" onclick=\"getElementById('editform').action.value='removeattachments';
265 getElementById('editform').submit();\"/></div></td></tr>\n";
267 foreach ($files as $file) {
268 $icon = mimeinfo("icon", $file);
269 if ($CFG->slasharguments
) {
270 $ffurl = "file.php/$filearea/$file";
272 $ffurl = "file.php?file=/$filearea/$file";
274 // removed target=\"uploadedfile\"
275 // as it does not validate MDL_7861
276 echo "<tr><td>".get_string("attachment", "workshop")." $n: <img src=\"$CFG->pixpath/f/$icon\"
277 class=\"icon\" alt=\"".get_string('file')."\" />".
278 " <a href=\"$CFG->wwwroot/$ffurl\">$file</a></td></tr>\n";
281 echo "<tr><td><b>".get_string("noattachments", "workshop")."</b></td></tr>\n";
285 require_once($CFG->dirroot
.'/lib/uploadlib.php');
286 for ($i=0; $i < $workshop->nattachments
; $i++
) {
288 $tag[$i] = get_string("newattachment", "workshop")." $iplus1:";
290 upload_print_form_fragment($workshop->nattachments
,null,$tag,false,null,$course->maxbytes
,
291 $workshop->maxbytes
,false);
296 echo "<input type=\"submit\" value=\"".get_string("savemysubmission", "workshop")."\" />\n";
297 echo "</div></fieldset></form>\n";
301 /******************* list all submissions ************************************/
302 elseif ($action == 'listallsubmissions' ) {
303 if (!$users = workshop_get_students($workshop)) {
304 print_heading(get_string("nostudentsyet"));
305 print_footer($course);
308 print_heading(get_string("listofallsubmissions", "workshop").":", "CENTER");
309 workshop_list_all_submissions($workshop, $USER);
310 print_continue("view.php?id=$cm->id");
315 /******************* list for assessment student (submissions) ************************************/
316 elseif ($action == 'listforassessmentstudent' ) {
317 if (!$users = workshop_get_students($workshop)) {
318 print_heading(get_string("nostudentsyet"));
319 print_footer($course);
322 workshop_list_unassessed_student_submissions($workshop, $USER);
323 print_continue("view.php?id=$cm->id");
328 /******************* list for assessment teacher (submissions) ************************************/
329 elseif ($action == 'listforassessmentteacher' ) {
331 require_capability('mod/workshop:manage', $context);
333 workshop_list_unassessed_teacher_submissions($workshop, $USER);
334 print_continue("view.php?id=$cm->id");
339 /******************* remove (all) attachments ************************************/
340 elseif ($action == 'removeattachments' ) {
342 $form = data_submitted();
344 if (empty($form->sid
)) {
345 error("Update submission: submission id missing");
348 $submission = get_record("workshop_submissions", "id", $form->sid
);
350 // students are only allowed to remove their own attachments and only up to the deadline
351 if (!(workshop_is_teacher($workshop) or
352 (($USER->id
= $submission->userid
) and ($timenow < $workshop->submissionend
)
353 and (($timenow < $workshop->assessmentstart
) or ($timenow < $submission->timecreated +
$CFG->maxeditingtime
))))) {
354 error("You are not authorized to delete these attachments");
357 // amend title... just in case they were modified
358 // check existence of title
359 if (empty($form->title
)) {
360 notify(get_string("notitlegiven", "workshop"));
362 set_field("workshop_submissions", "title", $form->title
, "id", $submission->id
);
363 set_field("workshop_submissions", "description", trim($form->description
), "id", $submission->id
);
365 print_string("removeallattachments", "workshop");
366 workshop_delete_submitted_files($workshop, $submission);
367 add_to_log($course->id
, "workshop", "removeattachments", "view.php?id=$cm->id", "submission $submission->id");
369 print_continue("view.php?id=$cm->id#sid=$submission->id");
373 /******************* show submission ************************************/
374 elseif ($action == 'showsubmission' ) {
377 error("Show submission: submission id missing");
380 $submission = get_record("workshop_submissions", "id", $sid);
381 $title = '"'.$submission->title
.'" ';
382 if (workshop_is_teacher($workshop)) {
383 $title .= get_string('by', 'workshop').' '.workshop_fullname($submission->userid
, $course->id
);
385 print_heading($title);
386 echo '<div style="text-align:center">'.get_string('submitted', 'workshop').': '.userdate($submission->timecreated
).'</div><br />';
387 workshop_print_submission($workshop, $submission);
388 print_continue(htmlentities($_SERVER['HTTP_REFERER'].'#sid='.$submission->id
));
392 /*************** update (league table options teacher) ***************************/
393 elseif ($action == 'updateleaguetable') {
395 require_capability('mod/workshop:manage', $context);
397 // save number of entries in showleaguetable option
398 if ($nentries == 'All') {
401 set_field("workshop", "showleaguetable", $nentries, "id", "$workshop->id");
403 // save the anonymous option
404 set_field("workshop", "anonymous", $anonymous, "id", "$workshop->id");
405 add_to_log($course->id
, "workshop", "league table", "view.php?id=$cm->id", $nentries, $cm->id
);
407 redirect("view.php?id=$cm->id");
411 /*************** update submission ***************************/
412 elseif ($action == 'updatesubmission') {
415 error("Update submission: submission id missing");
417 $submission = get_record("workshop_submissions", "id", $sid);
419 // students are only allowed to update their own submission and only up to the deadline
420 if (!(workshop_is_teacher($workshop) or
421 (($USER->id
= $submission->userid
) and ($timenow < $workshop->submissionend
)
422 and (($timenow < $workshop->assessmentstart
) or ($timenow < $submission->timecreated +
$CFG->maxeditingtime
))))) {
423 error("You are not authorized to update your submission");
426 // check existence of title
428 $title = get_string("notitle", "workshop");
430 set_field("workshop_submissions", "title", $title, "id", $submission->id
);
431 set_field("workshop_submissions", "description", trim($description), "id", $submission->id
);
432 set_field("workshop_submissions", "timecreated", $timenow, "id", $submission->id
);
433 if ($workshop->nattachments
) {
434 require_once($CFG->dirroot
.'/lib/uploadlib.php');
435 $um = new upload_manager(null,false,false,$course,false,$workshop->maxbytes
);
436 if ($um->preprocess_files()) {
437 $dir = workshop_file_area_name($workshop, $submission);
438 if ($um->save_files($dir)) {
439 add_to_log($course->id
, "workshop", "newattachment", "view.php?id=$cm->id", "$workshop->id");
440 print_heading(get_string("uploadsuccess", "workshop"));
442 // upload manager will print errors.
444 print_continue("view.php?id=$cm->id");
446 echo '</div>'; // close <div id='page'>
447 redirect("view.php?id=$cm->id#sid=$submission->id");
452 /*************** no man's land **************************************/
456 error("Fatal Error: Unknown Action: ".$action."\n");
461 print_footer($course);