3 require("../../config.php");
5 require("locallib.php");
7 $id = required_param('id', PARAM_INT
); // CM ID
10 if (! $cm = get_record("course_modules", "id", $id)) {
11 error("Course Module ID was incorrect");
13 if (! $course = get_record("course", "id", $cm->course
)) {
14 error("Course is misconfigured");
16 if (! $workshop = get_record("workshop", "id", $cm->instance
)) {
17 error("Course module is incorrect");
20 require_login($course->id
, false, $cm);
22 $strworkshops = get_string('modulenameplural', 'workshop');
23 $strworkshop = get_string('modulename', 'workshop');
24 $strsubmission = get_string('submission', 'workshop');
26 $crumbs[] = array('name' => $strworkshops, 'link' => "index.php?id=$course->id", 'type' => 'activity');
27 $crumbs[] = array('name' => format_string($workshop->name
,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
28 $crumbs[] = array('name' => $strsubmission, 'link' => '', 'type' => 'title');
29 $navigation = build_navigation($crumbs);
31 print_header_simple(format_string($workshop->name
)." : $strsubmission", "", $navigation,
35 $form = data_submitted("nomatch"); // POST may come from two forms
37 // don't be picky about not having a title
38 if (!$title = $form->title
) {
39 $title = get_string("notitle", "workshop");
42 // check that this is not a "rapid" second submission, caused by using the back button
43 // only check if a student, teachers may want to submit a set of workshop examples rapidly
44 if (workshop_is_student($workshop)) {
45 if ($submissions = workshop_get_user_submissions($workshop, $USER)) {
46 // returns all submissions, newest on first
47 foreach ($submissions as $submission) {
48 if ($submission->timecreated
> $timenow - $CFG->maxeditingtime
) {
49 // ignore this new submission
50 redirect("view.php?id=$cm->id");
51 print_footer($course);
58 // get the current set of submissions
59 $submissions = workshop_get_user_submissions($workshop, $USER);
60 // add new submission record
61 $newsubmission->workshopid
= $workshop->id
;
62 $newsubmission->userid
= $USER->id
;
63 $newsubmission->title
= clean_param($title, PARAM_CLEAN
);
64 $newsubmission->description
= trim(clean_param($form->description
, PARAM_CLEAN
));
65 $newsubmission->timecreated
= $timenow;
66 if ($timenow > $workshop->submissionend
) {
67 $newsubmission->late
= 1;
69 if (!$newsubmission->id
= insert_record("workshop_submissions", $newsubmission)) {
70 error("Workshop submission: Failure to create new submission record!");
72 // see if this is a resubmission by looking at the previous submissions...
73 if ($submissions and ($workshop->submissionstart
> time())) { // ...but not teacher submissions
74 // find the last submission
75 foreach ($submissions as $submission) {
76 $lastsubmission = $submission;
79 // find all the possible assessments of this submission
80 // ...and if they have been assessed give the assessor a new assessment
81 // based on their old assessment, if the assessment has not be made
83 if ($assessments = workshop_get_assessments($submission, 'ALL')) {
84 foreach ($assessments as $assessment) {
85 if ($assessment->timecreated
< $timenow) {
86 // a Cold or Warm assessment...
87 if ($assessment->userid
<> $USER->id
) {
88 // only copy other students assessment not the self assessment (if present)
89 // copy it with feedback..
90 $newassessment = workshop_copy_assessment($assessment, $newsubmission, true);
91 // set the resubmission flag so student can be emailed/told about
93 set_field("workshop_assessments", "resubmission", 1, "id", $newassessment->id
);
96 // a hot assessment, was not used, just dump it
97 delete_records("workshop_assessments", "id", $assessment->id
);
101 add_to_log($course->id
, "workshop", "resubmit", "view.php?id=$cm->id", "$workshop->id","$cm->id");
103 // do something about the attachments, if there are any
104 if ($workshop->nattachments
) {
105 require_once($CFG->dirroot
.'/lib/uploadlib.php');
106 $um = new upload_manager(null,false,false,$course,false,$workshop->maxbytes
);
107 if ($um->preprocess_files()) {
108 $dir = workshop_file_area_name($workshop, $newsubmission);
109 if ($um->save_files($dir)) {
110 print_heading(get_string("uploadsuccess", "workshop"));
112 // um will take care of printing errors.
115 if (!$workshop->nattachments
) {
116 print_heading(get_string("submitted", "workshop")." ".get_string("ok"));
118 add_to_log($course->id
, "workshop", "submit", "view.php?id=$cm->id", "$workshop->id", "$cm->id");
119 print_continue("view.php?id=$cm->id");
120 print_footer($course);