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 print_header_simple(format_string($workshop->name
), "",
55 "<a href=\"index.php?id=$course->id\">$strworkshops</a> ->
56 <a href=\"view.php?id=$cm->id\">".format_string($workshop->name
,true)."</a> -> $strsubmissions",
59 //...get the action or set up an suitable default
61 $action = "listallsubmissions";
65 /******************* admin amend title ************************************/
66 elseif ($action == 'adminamendtitle' ) {
68 require_capability('mod/workshop:manage', $context);
70 error("Admin Amend Title: submission id missing");
73 $submission = get_record("workshop_submissions", "id", $sid);
74 print_heading(get_string("amendtitle", "workshop"));
76 <form id
="amendtitleform" action
="submissions.php" method
="post">
77 <fieldset
class="invisiblefieldset">
78 <input type
="hidden" name
="action" value
="adminupdatetitle" />
79 <input type
="hidden" name
="id" value
="<?php echo $cm->id ?>" />
80 <input type
="hidden" name
="sid" value
="<?php echo $sid ?>" />
81 <div
class="boxaligncenter">
82 <table cellpadding
="5" border
="1">
85 // now get the comment
86 echo "<tr valign=\"top\">\n";
87 echo " <td align=\"right\"><p><b>". get_string("title", "workshop").":</b></p></td>\n";
89 echo " <input type=\"text\" name=\"title\" size=\"60\" maxlength=\"100\" value=\"$submission->title\" />\n";
90 echo " </td></tr></table>\n";
91 echo "<input type=\"submit\" value=\"".get_string("amendtitle", "workshop")."\" />\n";
92 echo "</div></fieldset></form>\n";
94 print_heading("<a $CFG->frametarget href=\"view.php?id=$cm->id#sid=$submission->id\">".get_string("cancel")."</a>");
98 /******************* admin clear late (flag) ************************************/
99 elseif ($action == 'adminclearlate' ) {
101 require_capability('mod/workshop:manage', $context);
103 error("Admin clear late flag: submission id missing");
106 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
107 error("Admin clear late flag: can not get submission record");
109 if (set_field("workshop_submissions", "late", 0, "id", $sid)) {
110 print_heading(get_string("clearlateflag", "workshop")." ".get_string("ok"));
113 add_to_log($course->id
, "workshop", "late flag cleared", "view.php?id=$cm->id", "submission $submission->id");
115 redirect("view.php?id=$cm->id");
119 /******************* confirm delete ************************************/
120 elseif ($action == 'confirmdelete' ) {
123 error("Confirm delete: submission id missing");
125 notice_yesno(get_string("confirmdeletionofthisitem","workshop", get_string("submission", "workshop")),
126 "submissions.php?action=delete&id=$cm->id&sid=$sid", "view.php?id=$cm->id#sid=$sid");
130 /******************* delete ************************************/
131 elseif ($action == 'delete' ) {
134 error("Delete: submission id missing");
137 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
138 error("Admin delete: can not get submission record");
141 // students are only allowed to delete their own submission and only up to the deadline
142 if (!(workshop_is_teacher($workshop) or
143 (($USER->id
= $submission->userid
) and ($timenow < $workshop->submissionend
)
144 and (($timenow < $workshop->assessmentstart
) or ($timenow < $submission->timecreated +
$CFG->maxeditingtime
))))) {
145 error("You are not authorized to delete this submission");
148 print_string("deleting", "workshop");
149 // first get any assessments...
150 if ($assessments = workshop_get_assessments($submission, 'ALL')) {
151 foreach($assessments as $assessment) {
152 // ...and all the associated records...
153 delete_records("workshop_comments", "assessmentid", $assessment->id
);
154 delete_records("workshop_grades", "assessmentid", $assessment->id
);
157 // ...now delete the assessments...
158 delete_records("workshop_assessments", "submissionid", $submission->id
);
160 // ...and the submission record...
161 delete_records("workshop_submissions", "id", $submission->id
);
162 // ..and finally the submitted file
163 workshop_delete_submitted_files($workshop, $submission);
165 redirect("view.php?id=$cm->id");
169 /******************* admin (confirm) late flag ************************************/
170 elseif ($action == 'adminlateflag' ) {
172 require_capability('mod/workshop:manage', $context);
174 error("Admin confirm late flag: submission id missing");
176 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
177 error("Admin confirm late flag: can not get submission record");
180 notice_yesno(get_string("clearlateflag","workshop")."?",
181 "submissions.php?action=adminclearlate&id=$cm->id&sid=$sid",
182 "view.php?id=$cm->id");
186 /******************* list all submissions ************************************/
187 elseif ($action == 'adminlist' ) {
189 require_capability('mod/workshop:manage', $context);
191 workshop_list_submissions_for_admin($workshop, $order);
192 print_continue("view.php?id=$cm->id");
197 /******************* admin update title ************************************/
198 elseif ($action == 'adminupdatetitle' ) {
200 require_capability('mod/workshop:manage', $context);
202 error("Admin Update Title: submission id missing");
205 if (set_field("workshop_submissions", "title", $title, "id", $sid)) {
206 print_heading(get_string("amendtitle", "workshop")." ".get_string("ok"));
208 print_continue("view.php?id=$cm->id");
212 /******************* confirm remove attachments ************************************/
213 elseif ($action == 'confirmremoveattachments' ) {
216 error("Admin confirm delete: submission id missing");
218 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
219 error("Admin delete: can not get submission record");
222 notice_yesno(get_string("confirmremoveattachments","workshop"),
223 "submissions.php?action=removeattachments&id=$cm->id&sid=$sid",
224 "view.php?id=$cm->id");
228 /******************* edit submission ************************************/
229 elseif ($action == 'editsubmission' ) {
232 error("Edit submission: submission id missing");
234 $usehtmleditor = can_use_html_editor();
236 $submission = get_record("workshop_submissions", "id", $sid);
237 print_heading(get_string("editsubmission", "workshop"));
238 if ($submission->userid
<> $USER->id
) {
239 error("Edit submission: Userids do not match");
241 if (($submission->timecreated
< ($timenow - $CFG->maxeditingtime
)) and ($workshop->assessmentstart
< $timenow)) {
242 error(get_string('notallowed', 'workshop'));
245 <form id
="editform" enctype
="multipart/form-data" action
="submissions.php" method
="post">
246 <fieldset
class="invisiblefieldset">
247 <input type
="hidden" name
="action" value
="updatesubmission" />
248 <input type
="hidden" name
="id" value
="<?php echo $cm->id ?>" />
249 <input type
="hidden" name
="sid" value
="<?php echo $sid ?>" />
250 <div
class="boxaligncenter">
251 <table cellpadding
="5" border
="1">
253 echo "<tr valign=\"top\"><td><b>". get_string("title", "workshop").":</b>\n";
254 echo "<input type=\"text\" name=\"title\" size=\"60\" maxlength=\"100\" value=\"$submission->title\" />\n";
255 echo "</td></tr><tr><td><b>".get_string("submission", "workshop").":</b><br />\n";
256 print_textarea($usehtmleditor, 25,70, 630, 400, "description", $submission->description
);
257 use_html_editor("description");
259 if ($workshop->nattachments
) {
260 $filearea = workshop_file_area_name($workshop, $submission);
261 if ($basedir = workshop_file_area($workshop, $submission)) {
262 if ($files = get_directory_list($basedir)) {
263 echo "<tr><td><b>".get_string("attachments", "workshop").
264 "</b><div style=\"text-align:right;\"><input type=\"button\" value=\"".get_string("removeallattachments",
265 "workshop")."\" onclick=\"getElementById('editform').action.value='removeattachments';
266 getElementById('editform').submit();\"/></div></td></tr>\n";
268 foreach ($files as $file) {
269 $icon = mimeinfo("icon", $file);
270 if ($CFG->slasharguments
) {
271 $ffurl = "file.php/$filearea/$file";
273 $ffurl = "file.php?file=/$filearea/$file";
275 // removed target=\"uploadedfile\"
276 // as it does not validate MDL_7861
277 echo "<tr><td>".get_string("attachment", "workshop")." $n: <img src=\"$CFG->pixpath/f/$icon\"
278 class=\"icon\" alt=\"".get_string('file')."\" />".
279 " <a href=\"$CFG->wwwroot/$ffurl\">$file</a></td></tr>\n";
282 echo "<tr><td><b>".get_string("noattachments", "workshop")."</b></td></tr>\n";
286 require_once($CFG->dirroot
.'/lib/uploadlib.php');
287 for ($i=0; $i < $workshop->nattachments
; $i++
) {
289 $tag[$i] = get_string("newattachment", "workshop")." $iplus1:";
291 upload_print_form_fragment($workshop->nattachments
,null,$tag,false,null,$course->maxbytes
,
292 $workshop->maxbytes
,false);
297 echo "<input type=\"submit\" value=\"".get_string("savemysubmission", "workshop")."\" />\n";
298 echo "</div></fieldset></form>\n";
302 /******************* list all submissions ************************************/
303 elseif ($action == 'listallsubmissions' ) {
304 if (!$users = workshop_get_students($workshop)) {
305 print_heading(get_string("nostudentsyet"));
306 print_footer($course);
309 print_heading(get_string("listofallsubmissions", "workshop").":", "CENTER");
310 workshop_list_all_submissions($workshop, $USER);
311 print_continue("view.php?id=$cm->id");
316 /******************* list for assessment student (submissions) ************************************/
317 elseif ($action == 'listforassessmentstudent' ) {
318 if (!$users = workshop_get_students($workshop)) {
319 print_heading(get_string("nostudentsyet"));
320 print_footer($course);
323 workshop_list_unassessed_student_submissions($workshop, $USER);
324 print_continue("view.php?id=$cm->id");
329 /******************* list for assessment teacher (submissions) ************************************/
330 elseif ($action == 'listforassessmentteacher' ) {
332 require_capability('mod/workshop:manage', $context);
334 workshop_list_unassessed_teacher_submissions($workshop, $USER);
335 print_continue("view.php?id=$cm->id");
340 /******************* remove (all) attachments ************************************/
341 elseif ($action == 'removeattachments' ) {
343 $form = data_submitted();
345 if (empty($form->sid
)) {
346 error("Update submission: submission id missing");
349 $submission = get_record("workshop_submissions", "id", $form->sid
);
351 // students are only allowed to remove their own attachments and only up to the deadline
352 if (!(workshop_is_teacher($workshop) or
353 (($USER->id
= $submission->userid
) and ($timenow < $workshop->submissionend
)
354 and (($timenow < $workshop->assessmentstart
) or ($timenow < $submission->timecreated +
$CFG->maxeditingtime
))))) {
355 error("You are not authorized to delete these attachments");
358 // amend title... just in case they were modified
359 // check existence of title
360 if (empty($form->title
)) {
361 notify(get_string("notitlegiven", "workshop"));
363 set_field("workshop_submissions", "title", $form->title
, "id", $submission->id
);
364 set_field("workshop_submissions", "description", trim($form->description
), "id", $submission->id
);
366 print_string("removeallattachments", "workshop");
367 workshop_delete_submitted_files($workshop, $submission);
368 add_to_log($course->id
, "workshop", "removeattachments", "view.php?id=$cm->id", "submission $submission->id");
370 print_continue("view.php?id=$cm->id#sid=$submission->id");
374 /******************* show submission ************************************/
375 elseif ($action == 'showsubmission' ) {
378 error("Show submission: submission id missing");
381 $submission = get_record("workshop_submissions", "id", $sid);
382 $title = '"'.$submission->title
.'" ';
383 if (workshop_is_teacher($workshop)) {
384 $title .= get_string('by', 'workshop').' '.workshop_fullname($submission->userid
, $course->id
);
386 print_heading($title);
387 echo '<div style="text-align:center">'.get_string('submitted', 'workshop').': '.userdate($submission->timecreated
).'</div><br />';
388 workshop_print_submission($workshop, $submission);
389 print_continue(htmlentities($_SERVER['HTTP_REFERER'].'#sid='.$submission->id
));
393 /*************** update (league table options teacher) ***************************/
394 elseif ($action == 'updateleaguetable') {
396 require_capability('mod/workshop:manage', $context);
398 // save number of entries in showleaguetable option
399 if ($nentries == 'All') {
402 set_field("workshop", "showleaguetable", $nentries, "id", "$workshop->id");
404 // save the anonymous option
405 set_field("workshop", "anonymous", $anonymous, "id", "$workshop->id");
406 add_to_log($course->id
, "workshop", "league table", "view.php?id=$cm->id", $nentries, $cm->id
);
408 redirect("view.php?id=$cm->id");
412 /*************** update submission ***************************/
413 elseif ($action == 'updatesubmission') {
416 error("Update submission: submission id missing");
418 $submission = get_record("workshop_submissions", "id", $sid);
420 // students are only allowed to update their own submission and only up to the deadline
421 if (!(workshop_is_teacher($workshop) or
422 (($USER->id
= $submission->userid
) and ($timenow < $workshop->submissionend
)
423 and (($timenow < $workshop->assessmentstart
) or ($timenow < $submission->timecreated +
$CFG->maxeditingtime
))))) {
424 error("You are not authorized to update your submission");
427 // check existence of title
429 $title = get_string("notitle", "workshop");
431 set_field("workshop_submissions", "title", $title, "id", $submission->id
);
432 set_field("workshop_submissions", "description", trim($description), "id", $submission->id
);
433 set_field("workshop_submissions", "timecreated", $timenow, "id", $submission->id
);
434 if ($workshop->nattachments
) {
435 require_once($CFG->dirroot
.'/lib/uploadlib.php');
436 $um = new upload_manager(null,false,false,$course,false,$workshop->maxbytes
);
437 if ($um->preprocess_files()) {
438 $dir = workshop_file_area_name($workshop, $submission);
439 if ($um->save_files($dir)) {
440 add_to_log($course->id
, "workshop", "newattachment", "view.php?id=$cm->id", "$workshop->id");
441 print_heading(get_string("uploadsuccess", "workshop"));
443 // upload manager will print errors.
445 print_continue("view.php?id=$cm->id");
447 echo '</div>'; // close <div id='page'>
448 redirect("view.php?id=$cm->id#sid=$submission->id");
453 /*************** no man's land **************************************/
457 error("Fatal Error: Unknown Action: ".$action."\n");
462 print_footer($course);