From 21de6ca1dbe8f7a082ce1b22e1868bcd6366c088 Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Wed, 15 Sep 2004 00:03:04 +0000 Subject: [PATCH] Integration of new centralised file upload code with workshop module. These patches are maintained in an publicly accessible Arch repository, see: http://lists.eduforge.org/cgi-bin/archzoom.cgi/arch-eduforge@catalyst.net.nz--2004-MIRROR/moodle--eduforge--1.3.3 Index of arch patches in this commit: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-57 2004-09-14 23:37:49 GMT Penny Leach added important instruction to handlevirus.php Full logs: Revision: moodle--eduforge--1.3.3--patch-57 Archive: arch-eduforge@catalyst.net.nz--2004 Creator: Penny Leach Date: Wed Sep 15 11:37:49 NZST 2004 Standard-date: 2004-09-14 23:37:49 GMT Modified-files: admin/handlevirus.php mod/workshop/locallib.php mod/workshop/upload.php New-patches: arch-eduforge@catalyst.net.nz--2004/moodle--eduforge--1.3.3--patch-57 Summary: added important instruction to handlevirus.php Keywords: --- admin/handlevirus.php | 1 + mod/workshop/locallib.php | 7 +-- mod/workshop/upload.php | 107 ++++++++++++++++---------------------- 3 files changed, 50 insertions(+), 65 deletions(-) diff --git a/admin/handlevirus.php b/admin/handlevirus.php index a2b1bf3b38..1755905cd8 100644 --- a/admin/handlevirus.php +++ b/admin/handlevirus.php @@ -2,6 +2,7 @@ /** This expects the output from a command like * clamscan -r --infected --no-summary 2>&1 | php thisfile.php * also it's important that the output of clamscan prints the FULL PATH to each infected file, so use absolute paths for area to scan + * also it should be run as root, or whatever the webserver runs as so that it has the right permissions in the quarantine dir etc. */ diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index 7b623d277b..70c0747f44 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -2678,6 +2678,8 @@ function workshop_print_time_to_deadline($time) { function workshop_print_upload_form($workshop) { // Arguments are objects, needs title coming in + global $CFG; + if (! $course = get_record("course", "id", $workshop->course)) { error("Course is misconfigured"); } @@ -2687,10 +2689,9 @@ function workshop_print_upload_form($workshop) { echo "
"; echo "
"; - echo " maxbytes\" />"; echo " id\" />"; - echo "".get_string("title", "workshop").":

\n"; - echo " "; + require_once($CFG->dirroot.'/lib/uploadlib.php'); + upload_print_form_fragment(1,array('newfile'),null,true,array('title'),$course->maxbytes,$workshop->maxbytes,false); echo " "; echo "
"; echo "
"; diff --git a/mod/workshop/upload.php b/mod/workshop/upload.php index 5104f28a2b..28862b59b4 100644 --- a/mod/workshop/upload.php +++ b/mod/workshop/upload.php @@ -6,7 +6,6 @@ require_variable($id); // CM ID - $newfile = $HTTP_POST_FILES["newfile"]; if (! $cm = get_record("course_modules", "id", $id)) { error("Course Module ID was incorrect"); @@ -40,71 +39,55 @@ notify(get_string("notitlegiven", "workshop") ); } else { - if (is_uploaded_file($newfile['tmp_name']) and $newfile['size'] > 0) { - if ($newfile['size'] > $workshop->maxbytes) { - notify(get_string("uploadfiletoobig", "assignment", $workshop->maxbytes)); - } - else { - $newfile_name = clean_filename($newfile['name']); - if ($newfile_name) { - // get the current set of submissions - $submissions = workshop_get_user_submissions($workshop, $USER); - // add new submission record - $newsubmission->workshopid = $workshop->id; - $newsubmission->userid = $USER->id; - $newsubmission->title = $title; - $newsubmission->timecreated = time(); - if (!$newsubmission->id = insert_record("workshop_submissions", $newsubmission)) { - error("Workshop upload: Failure to create new submission record!"); - } - // see if this is a resubmission by looking at the previous submissions... - if ($submissions and ($workshop->phase >1)) { // ...but not teacher submissions - // find the last submission - foreach ($submissions as $submission) { - $lastsubmission = $submission; - break; - } - // find all the possible assessments of this submission - // ...and if they have been assessed give the assessor a new assessment - // based on their old assessment, if the assessment has not be made - // just delete it! - if ($assessments = workshop_get_assessments($submission, 'ALL')) { - foreach ($assessments as $assessment) { - if ($assessment->timecreated < $timenow) { - // a Cold or Warm assessment - copy it with feedback.. - $newassessment = workshop_copy_assessment($assessment, $newsubmission, - true); - // set the resubmission flag so student can be emailed/told about - // this assessment - set_field("workshop_assessments", "resubmission", 1, "id", - $newassessment->id); - } else { - // a hot assessment, was not used, just dump it - delete_records("workshop_assessments", "id", $assessment->id); - } - } + require_once($CFG->dirroot.'/lib/uploadlib.php'); + $um = new upload_manager('newfile',false,false,$course,false,$exercise->maxbytes); + if ($um->preprocess_files()) { + // get the current set of submissions + $submissions = workshop_get_user_submissions($workshop, $USER); + // add new submission record + $newsubmission->workshopid = $workshop->id; + $newsubmission->userid = $USER->id; + $newsubmission->title = $title; + $newsubmission->timecreated = time(); + if (!$newsubmission->id = insert_record("workshop_submissions", $newsubmission)) { + error("Workshop upload: Failure to create new submission record!"); + } + // see if this is a resubmission by looking at the previous submissions... + if ($submissions and ($workshop->phase >1)) { // ...but not teacher submissions + // find the last submission + foreach ($submissions as $submission) { + $lastsubmission = $submission; + break; + } + // find all the possible assessments of this submission + // ...and if they have been assessed give the assessor a new assessment + // based on their old assessment, if the assessment has not be made + // just delete it! + if ($assessments = workshop_get_assessments($submission, 'ALL')) { + foreach ($assessments as $assessment) { + if ($assessment->timecreated < $timenow) { + // a Cold or Warm assessment - copy it with feedback.. + $newassessment = workshop_copy_assessment($assessment, $newsubmission, + true); + // set the resubmission flag so student can be emailed/told about + // this assessment + set_field("workshop_assessments", "resubmission", 1, "id", + $newassessment->id); + } else { + // a hot assessment, was not used, just dump it + delete_records("workshop_assessments", "id", $assessment->id); } - add_to_log($course->id, "workshop", "resubmit", "view.php?id=$cm->id", - "$workshop->id","$cm->id"); - } - if (! $dir = workshop_file_area($workshop, $newsubmission)) { - error("Sorry, an error in the system prevents you from uploading files: contact your teacher or system administrator"); - } - if (move_uploaded_file($newfile['tmp_name'], "$dir/$newfile_name")) { - print_heading(get_string("uploadsuccess", "assignment", $newfile_name) ); - add_to_log($course->id, "workshop", "submit", "view.php?id=$cm->id", "$workshop->id", "$cm->id"); - } - else { - notify(get_string("uploaderror", "assignment") ); } } + add_to_log($course->id, "workshop", "resubmit", "view.php?id=$cm->id", + "$workshop->id","$cm->id"); + } + $dir = workshop_file_area_name($workshop, $newsubmission); + if ($um->save_files($dir)) { + print_heading(get_string("uploadsuccess", "assignment", $um->get_new_filename()) ); + add_to_log($course->id, "workshop", "submit", "view.php?id=$cm->id", "$workshop->id", "$cm->id"); } - } - elseif (!is_uploaded_file($newfile['tmp_name']) and !$newfile['size'] > 0 and $newfile['name']) { - notify(get_string("uploadfiletoobig", "assignment", $workshop->maxbytes)); - } - else { - notify(get_string("uploadnofilefound", "assignment")); + // um will take care of printing errors. } } print_continue("view.php?id=$cm->id"); -- 2.39.5