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');
27 $navlinks[] = array('name' => $strworkshops, 'link' => "index.php?id=$course->id", 'type' => 'activity');
28 $navlinks[] = array('name' => format_string($workshop->name
,true), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
29 $navlinks[] = array('name' => $strsubmission, 'link' => '', 'type' => 'title');
30 $navigation = build_navigation($navlinks);
32 print_header_simple(format_string($workshop->name
)." : $strsubmission", "", $navigation,
36 $form = data_submitted("nomatch"); // POST may come from two forms
38 // don't be picky about not having a title
39 if (!$title = $form->title
) {
40 $title = get_string("notitle", "workshop");
43 // check that this is not a "rapid" second submission, caused by using the back button
44 // only check if a student, teachers may want to submit a set of workshop examples rapidly
45 if (workshop_is_student($workshop)) {
46 if ($submissions = workshop_get_user_submissions($workshop, $USER)) {
47 // returns all submissions, newest on first
48 foreach ($submissions as $submission) {
49 if ($submission->timecreated
> $timenow - $CFG->maxeditingtime
) {
50 // ignore this new submission
51 redirect("view.php?id=$cm->id");
52 print_footer($course);
59 // get the current set of submissions
60 $submissions = workshop_get_user_submissions($workshop, $USER);
61 // add new submission record
62 $newsubmission->workshopid
= $workshop->id
;
63 $newsubmission->userid
= $USER->id
;
64 $newsubmission->title
= clean_param($title, PARAM_CLEAN
);
65 $newsubmission->description
= trim(clean_param($form->description
, PARAM_CLEAN
));
66 $newsubmission->timecreated
= $timenow;
67 if ($timenow > $workshop->submissionend
) {
68 $newsubmission->late
= 1;
70 if (!$newsubmission->id
= insert_record("workshop_submissions", $newsubmission)) {
71 error("Workshop submission: Failure to create new submission record!");
73 // see if this is a resubmission by looking at the previous submissions...
74 if ($submissions and ($workshop->submissionstart
> time())) { // ...but not teacher submissions
75 // find the last submission
76 foreach ($submissions as $submission) {
77 $lastsubmission = $submission;
80 // find all the possible assessments of this submission
81 // ...and if they have been assessed give the assessor a new assessment
82 // based on their old assessment, if the assessment has not be made
84 if ($assessments = workshop_get_assessments($submission, 'ALL')) {
85 foreach ($assessments as $assessment) {
86 if ($assessment->timecreated
< $timenow) {
87 // a Cold or Warm assessment...
88 if ($assessment->userid
<> $USER->id
) {
89 // only copy other students assessment not the self assessment (if present)
90 // copy it with feedback..
91 $newassessment = workshop_copy_assessment($assessment, $newsubmission, true);
92 // set the resubmission flag so student can be emailed/told about
94 set_field("workshop_assessments", "resubmission", 1, "id", $newassessment->id
);
97 // a hot assessment, was not used, just dump it
98 delete_records("workshop_assessments", "id", $assessment->id
);
102 add_to_log($course->id
, "workshop", "resubmit", "view.php?id=$cm->id", "$workshop->id","$cm->id");
104 // do something about the attachments, if there are any
105 if ($workshop->nattachments
) {
106 require_once($CFG->dirroot
.'/lib/uploadlib.php');
107 $um = new upload_manager(null,false,false,$course,false,$workshop->maxbytes
);
108 if ($um->preprocess_files()) {
109 $dir = workshop_file_area_name($workshop, $newsubmission);
110 if ($um->save_files($dir)) {
111 print_heading(get_string("uploadsuccess", "workshop"));
113 // um will take care of printing errors.
116 if (!$workshop->nattachments
) {
117 print_heading(get_string("submitted", "workshop")." ".get_string("ok"));
119 add_to_log($course->id
, "workshop", "submit", "view.php?id=$cm->id", "$workshop->id", "$cm->id");
120 print_continue("view.php?id=$cm->id");
121 print_footer($course);