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 $crumbs[] = array('name' => $strworkshops, 'link' => "index.php?id=$course->id", 'type' => 'activity');
55 $crumbs[] = array('name' => format_string($workshop->name
,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
56 $crumbs[] = array('name' => $strsubmissions, 'link' => '', 'type' => 'title');
57 $navigation = build_navigation($crumbs);
59 print_header_simple(format_string($workshop->name
), "", $navigation,
62 //...get the action or set up an suitable default
64 $action = "listallsubmissions";
68 /******************* admin amend title ************************************/
69 elseif ($action == 'adminamendtitle' ) {
71 require_capability('mod/workshop:manage', $context);
73 error("Admin Amend Title: submission id missing");
76 $submission = get_record("workshop_submissions", "id", $sid);
77 print_heading(get_string("amendtitle", "workshop"));
79 <form id
="amendtitleform" action
="submissions.php" method
="post">
80 <fieldset
class="invisiblefieldset">
81 <input type
="hidden" name
="action" value
="adminupdatetitle" />
82 <input type
="hidden" name
="id" value
="<?php echo $cm->id ?>" />
83 <input type
="hidden" name
="sid" value
="<?php echo $sid ?>" />
84 <div
class="boxaligncenter">
85 <table cellpadding
="5" border
="1">
88 // now get the comment
89 echo "<tr valign=\"top\">\n";
90 echo " <td align=\"right\"><p><b>". get_string("title", "workshop").":</b></p></td>\n";
92 echo " <input type=\"text\" name=\"title\" size=\"60\" maxlength=\"100\" value=\"$submission->title\" />\n";
93 echo " </td></tr></table>\n";
94 echo "<input type=\"submit\" value=\"".get_string("amendtitle", "workshop")."\" />\n";
95 echo "</div></fieldset></form>\n";
97 print_heading("<a $CFG->frametarget href=\"view.php?id=$cm->id#sid=$submission->id\">".get_string("cancel")."</a>");
101 /******************* admin clear late (flag) ************************************/
102 elseif ($action == 'adminclearlate' ) {
104 require_capability('mod/workshop:manage', $context);
106 error("Admin clear late flag: submission id missing");
109 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
110 error("Admin clear late flag: can not get submission record");
112 if (set_field("workshop_submissions", "late", 0, "id", $sid)) {
113 print_heading(get_string("clearlateflag", "workshop")." ".get_string("ok"));
116 add_to_log($course->id
, "workshop", "late flag cleared", "view.php?id=$cm->id", "submission $submission->id");
118 redirect("view.php?id=$cm->id");
122 /******************* confirm delete ************************************/
123 elseif ($action == 'confirmdelete' ) {
126 error("Confirm delete: submission id missing");
128 notice_yesno(get_string("confirmdeletionofthisitem","workshop", get_string("submission", "workshop")),
129 "submissions.php?action=delete&id=$cm->id&sid=$sid", "view.php?id=$cm->id#sid=$sid");
133 /******************* delete ************************************/
134 elseif ($action == 'delete' ) {
137 error("Delete: submission id missing");
140 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
141 error("Admin delete: can not get submission record");
144 // students are only allowed to delete their own submission and only up to the deadline
145 if (!(workshop_is_teacher($workshop) or
146 (($USER->id
= $submission->userid
) and ($timenow < $workshop->submissionend
)
147 and (($timenow < $workshop->assessmentstart
) or ($timenow < $submission->timecreated +
$CFG->maxeditingtime
))))) {
148 error("You are not authorized to delete this submission");
151 print_string("deleting", "workshop");
152 // first get any assessments...
153 if ($assessments = workshop_get_assessments($submission, 'ALL')) {
154 foreach($assessments as $assessment) {
155 // ...and all the associated records...
156 delete_records("workshop_comments", "assessmentid", $assessment->id
);
157 delete_records("workshop_grades", "assessmentid", $assessment->id
);
160 // ...now delete the assessments...
161 delete_records("workshop_assessments", "submissionid", $submission->id
);
163 // ...and the submission record...
164 delete_records("workshop_submissions", "id", $submission->id
);
165 // ..and finally the submitted file
166 workshop_delete_submitted_files($workshop, $submission);
168 redirect("view.php?id=$cm->id");
172 /******************* admin (confirm) late flag ************************************/
173 elseif ($action == 'adminlateflag' ) {
175 require_capability('mod/workshop:manage', $context);
177 error("Admin confirm late flag: submission id missing");
179 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
180 error("Admin confirm late flag: can not get submission record");
183 notice_yesno(get_string("clearlateflag","workshop")."?",
184 "submissions.php?action=adminclearlate&id=$cm->id&sid=$sid",
185 "view.php?id=$cm->id");
189 /******************* list all submissions ************************************/
190 elseif ($action == 'adminlist' ) {
192 require_capability('mod/workshop:manage', $context);
194 workshop_list_submissions_for_admin($workshop, $order);
195 print_continue("view.php?id=$cm->id");
200 /******************* admin update title ************************************/
201 elseif ($action == 'adminupdatetitle' ) {
203 require_capability('mod/workshop:manage', $context);
205 error("Admin Update Title: submission id missing");
208 if (set_field("workshop_submissions", "title", $title, "id", $sid)) {
209 print_heading(get_string("amendtitle", "workshop")." ".get_string("ok"));
211 print_continue("view.php?id=$cm->id");
215 /******************* confirm remove attachments ************************************/
216 elseif ($action == 'confirmremoveattachments' ) {
219 error("Admin confirm delete: submission id missing");
221 if (!$submission = get_record("workshop_submissions", "id", $sid)) {
222 error("Admin delete: can not get submission record");
225 notice_yesno(get_string("confirmremoveattachments","workshop"),
226 "submissions.php?action=removeattachments&id=$cm->id&sid=$sid",
227 "view.php?id=$cm->id");
231 /******************* edit submission ************************************/
232 elseif ($action == 'editsubmission' ) {
235 error("Edit submission: submission id missing");
237 $usehtmleditor = can_use_html_editor();
239 $submission = get_record("workshop_submissions", "id", $sid);
240 print_heading(get_string("editsubmission", "workshop"));
241 if ($submission->userid
<> $USER->id
) {
242 error("Edit submission: Userids do not match");
244 if (($submission->timecreated
< ($timenow - $CFG->maxeditingtime
)) and ($workshop->assessmentstart
< $timenow)) {
245 error(get_string('notallowed', 'workshop'));
248 <form id
="editform" enctype
="multipart/form-data" action
="submissions.php" method
="post">
249 <fieldset
class="invisiblefieldset">
250 <input type
="hidden" name
="action" value
="updatesubmission" />
251 <input type
="hidden" name
="id" value
="<?php echo $cm->id ?>" />
252 <input type
="hidden" name
="sid" value
="<?php echo $sid ?>" />
253 <div
class="boxaligncenter">
254 <table cellpadding
="5" border
="1">
256 echo "<tr valign=\"top\"><td><b>". get_string("title", "workshop").":</b>\n";
257 echo "<input type=\"text\" name=\"title\" size=\"60\" maxlength=\"100\" value=\"$submission->title\" />\n";
258 echo "</td></tr><tr><td><b>".get_string("submission", "workshop").":</b><br />\n";
259 print_textarea($usehtmleditor, 25,70, 630, 400, "description", $submission->description
);
260 use_html_editor("description");
262 if ($workshop->nattachments
) {
263 $filearea = workshop_file_area_name($workshop, $submission);
264 if ($basedir = workshop_file_area($workshop, $submission)) {
265 if ($files = get_directory_list($basedir)) {
266 echo "<tr><td><b>".get_string("attachments", "workshop").
267 "</b><div style=\"text-align:right;\"><input type=\"button\" value=\"".get_string("removeallattachments",
268 "workshop")."\" onclick=\"getElementById('editform').action.value='removeattachments';
269 getElementById('editform').submit();\"/></div></td></tr>\n";
271 foreach ($files as $file) {
272 $icon = mimeinfo("icon", $file);
273 if ($CFG->slasharguments
) {
274 $ffurl = "file.php/$filearea/$file";
276 $ffurl = "file.php?file=/$filearea/$file";
278 // removed target=\"uploadedfile\"
279 // as it does not validate MDL_7861
280 echo "<tr><td>".get_string("attachment", "workshop")." $n: <img src=\"$CFG->pixpath/f/$icon\"
281 class=\"icon\" alt=\"".get_string('file')."\" />".
282 " <a href=\"$CFG->wwwroot/$ffurl\">$file</a></td></tr>\n";
285 echo "<tr><td><b>".get_string("noattachments", "workshop")."</b></td></tr>\n";
289 require_once($CFG->dirroot
.'/lib/uploadlib.php');
290 for ($i=0; $i < $workshop->nattachments
; $i++
) {
292 $tag[$i] = get_string("newattachment", "workshop")." $iplus1:";
294 upload_print_form_fragment($workshop->nattachments
,null,$tag,false,null,$course->maxbytes
,
295 $workshop->maxbytes
,false);
300 echo "<input type=\"submit\" value=\"".get_string("savemysubmission", "workshop")."\" />\n";
301 echo "</div></fieldset></form>\n";
305 /******************* list all submissions ************************************/
306 elseif ($action == 'listallsubmissions' ) {
307 if (!$users = workshop_get_students($workshop)) {
308 print_heading(get_string("nostudentsyet"));
309 print_footer($course);
312 print_heading(get_string("listofallsubmissions", "workshop").":", "CENTER");
313 workshop_list_all_submissions($workshop, $USER);
314 print_continue("view.php?id=$cm->id");
319 /******************* list for assessment student (submissions) ************************************/
320 elseif ($action == 'listforassessmentstudent' ) {
321 if (!$users = workshop_get_students($workshop)) {
322 print_heading(get_string("nostudentsyet"));
323 print_footer($course);
326 workshop_list_unassessed_student_submissions($workshop, $USER);
327 print_continue("view.php?id=$cm->id");
332 /******************* list for assessment teacher (submissions) ************************************/
333 elseif ($action == 'listforassessmentteacher' ) {
335 require_capability('mod/workshop:manage', $context);
337 workshop_list_unassessed_teacher_submissions($workshop, $USER);
338 print_continue("view.php?id=$cm->id");
343 /******************* remove (all) attachments ************************************/
344 elseif ($action == 'removeattachments' ) {
346 $form = data_submitted();
348 if (empty($form->sid
)) {
349 error("Update submission: submission id missing");
352 $submission = get_record("workshop_submissions", "id", $form->sid
);
354 // students are only allowed to remove their own attachments and only up to the deadline
355 if (!(workshop_is_teacher($workshop) or
356 (($USER->id
= $submission->userid
) and ($timenow < $workshop->submissionend
)
357 and (($timenow < $workshop->assessmentstart
) or ($timenow < $submission->timecreated +
$CFG->maxeditingtime
))))) {
358 error("You are not authorized to delete these attachments");
361 // amend title... just in case they were modified
362 // check existence of title
363 if (empty($form->title
)) {
364 notify(get_string("notitlegiven", "workshop"));
366 set_field("workshop_submissions", "title", $form->title
, "id", $submission->id
);
367 set_field("workshop_submissions", "description", trim($form->description
), "id", $submission->id
);
369 print_string("removeallattachments", "workshop");
370 workshop_delete_submitted_files($workshop, $submission);
371 add_to_log($course->id
, "workshop", "removeattachments", "view.php?id=$cm->id", "submission $submission->id");
373 print_continue("view.php?id=$cm->id#sid=$submission->id");
377 /******************* show submission ************************************/
378 elseif ($action == 'showsubmission' ) {
381 error("Show submission: submission id missing");
384 $submission = get_record("workshop_submissions", "id", $sid);
385 $title = '"'.$submission->title
.'" ';
386 if (workshop_is_teacher($workshop)) {
387 $title .= get_string('by', 'workshop').' '.workshop_fullname($submission->userid
, $course->id
);
389 print_heading($title);
390 echo '<div style="text-align:center">'.get_string('submitted', 'workshop').': '.userdate($submission->timecreated
).'</div><br />';
391 workshop_print_submission($workshop, $submission);
392 print_continue(htmlentities($_SERVER['HTTP_REFERER'].'#sid='.$submission->id
));
396 /*************** update (league table options teacher) ***************************/
397 elseif ($action == 'updateleaguetable') {
399 require_capability('mod/workshop:manage', $context);
401 // save number of entries in showleaguetable option
402 if ($nentries == 'All') {
405 set_field("workshop", "showleaguetable", $nentries, "id", "$workshop->id");
407 // save the anonymous option
408 set_field("workshop", "anonymous", $anonymous, "id", "$workshop->id");
409 add_to_log($course->id
, "workshop", "league table", "view.php?id=$cm->id", $nentries, $cm->id
);
411 redirect("view.php?id=$cm->id");
415 /*************** update submission ***************************/
416 elseif ($action == 'updatesubmission') {
419 error("Update submission: submission id missing");
421 $submission = get_record("workshop_submissions", "id", $sid);
423 // students are only allowed to update their own submission and only up to the deadline
424 if (!(workshop_is_teacher($workshop) or
425 (($USER->id
= $submission->userid
) and ($timenow < $workshop->submissionend
)
426 and (($timenow < $workshop->assessmentstart
) or ($timenow < $submission->timecreated +
$CFG->maxeditingtime
))))) {
427 error("You are not authorized to update your submission");
430 // check existence of title
432 $title = get_string("notitle", "workshop");
434 set_field("workshop_submissions", "title", $title, "id", $submission->id
);
435 set_field("workshop_submissions", "description", trim($description), "id", $submission->id
);
436 set_field("workshop_submissions", "timecreated", $timenow, "id", $submission->id
);
437 if ($workshop->nattachments
) {
438 require_once($CFG->dirroot
.'/lib/uploadlib.php');
439 $um = new upload_manager(null,false,false,$course,false,$workshop->maxbytes
);
440 if ($um->preprocess_files()) {
441 $dir = workshop_file_area_name($workshop, $submission);
442 if ($um->save_files($dir)) {
443 add_to_log($course->id
, "workshop", "newattachment", "view.php?id=$cm->id", "$workshop->id");
444 print_heading(get_string("uploadsuccess", "workshop"));
446 // upload manager will print errors.
448 print_continue("view.php?id=$cm->id");
450 echo '</div>'; // close <div id='page'>
451 redirect("view.php?id=$cm->id#sid=$submission->id");
456 /*************** no man's land **************************************/
460 error("Fatal Error: Unknown Action: ".$action."\n");
465 print_footer($course);