]> git.mjollnir.org Git - moodle.git/commitdiff
Integration of new centralised file upload code with workshop module.
authormjollnir_ <mjollnir_>
Wed, 15 Sep 2004 00:03:04 +0000 (00:03 +0000)
committermjollnir_ <mjollnir_>
Wed, 15 Sep 2004 00:03:04 +0000 (00:03 +0000)
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 <penny@catalyst.net.nz>
    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 <penny@catalyst.net.nz>
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
mod/workshop/locallib.php
mod/workshop/upload.php

index a2b1bf3b38cc5beb0d713b40ada389385f1bf9cb..1755905cd8f5ad41a83b3617fa7e8380c83577e7 100644 (file)
@@ -2,6 +2,7 @@
 /** This expects the output from a command like
  * clamscan -r --infected --no-summary <files> 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.
  */
 
 
index 7b623d277b70631c93f58037ada02ffa55822c69..70c0747f4429912612486c83cd8cb0b9a2fecd76 100644 (file)
@@ -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 "<div align=\"center\">";
     echo "<form enctype=\"multipart/form-data\" method=\"POST\" action=\"upload\".php>";
-    echo " <input type=\"hidden\" name=MAX_FILE_SIZE value=\"$workshop->maxbytes\" />";
     echo " <input type=\"hidden\" name=\"id\" value=\"$cm->id\" />";
-    echo "<b>".get_string("title", "workshop")."</b>: <input name=\"title\" type=\"text\" size=\"60\" maxsize=\"100\" /><br /><br />\n";
-    echo " <input name=\"newfile\" type=\"file\" size=\"50\" />";
+    require_once($CFG->dirroot.'/lib/uploadlib.php');
+    upload_print_form_fragment(1,array('newfile'),null,true,array('title'),$course->maxbytes,$workshop->maxbytes,false);
     echo " <input type=\"submit\" name=\"save\" value=\"".get_string("uploadthisfile")."\" />";
     echo "</form>";
     echo "</div>";
index 5104f28a2b03b2843aa48dcbdeeb31b28512b1a1..28862b59b4e3bee0c36751116b270e1ba53ef992 100644 (file)
@@ -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");
         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");