Improvements to uploading error feedback (from Shane)
This commit is contained in:
@@ -681,7 +681,7 @@ function assignment_print_upload_form($assignment) {
|
||||
// Arguments are objects
|
||||
|
||||
echo "<DIV ALIGN=CENTER>";
|
||||
echo "<FORM ENCTYPE=\"multipart/form-data\" METHOD=\"POST\" ACTION=upload.php>";
|
||||
echo "<FORM ENCTYPE=\"multipart/form-data\" METHOD=\"POST\" ACTION=\"upload.php?id=$assignment->id\">";
|
||||
echo " <INPUT TYPE=hidden NAME=MAX_FILE_SIZE value=\"$assignment->maxbytes\">";
|
||||
echo " <INPUT TYPE=hidden NAME=id VALUE=\"$assignment->id\">";
|
||||
echo " <INPUT NAME=\"newfile\" TYPE=\"file\" size=\"50\">";
|
||||
|
||||
+32
-31
@@ -2,6 +2,7 @@
|
||||
|
||||
require_once("../../config.php");
|
||||
require_once("lib.php");
|
||||
|
||||
|
||||
require_variable($id); // Assignment ID
|
||||
|
||||
@@ -9,6 +10,7 @@
|
||||
$newfile = $_FILES['newfile'];
|
||||
}
|
||||
|
||||
|
||||
if (! $assignment = get_record("assignment", "id", $id)) {
|
||||
error("Not a valid assignment ID");
|
||||
}
|
||||
@@ -45,51 +47,50 @@
|
||||
}
|
||||
|
||||
if (empty($newfile)) {
|
||||
notify(get_string("uploadnofilefound", "assignment") );
|
||||
notify(get_string("uploadfiletoobig", "assignment", get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $assignment->maxbytes)) );
|
||||
|
||||
} else if (is_uploaded_file($newfile['tmp_name']) and $newfile['size'] > 0) {
|
||||
if ($newfile['size'] > $assignment->maxbytes) {
|
||||
notify(get_string("uploadfiletoobig", "assignment", $assignment->maxbytes));
|
||||
} else {
|
||||
$newfile_name = clean_filename($newfile['name']);
|
||||
if ($newfile_name) {
|
||||
if (move_uploaded_file($newfile['tmp_name'], "$dir/$newfile_name")) {
|
||||
chmod("$dir/$newfile_name", $CFG->directorypermissions);
|
||||
assignment_delete_user_files($assignment, $USER, $newfile_name);
|
||||
if ($submission) {
|
||||
$submission->timemodified = time();
|
||||
$submission->numfiles = 1;
|
||||
$submission->comment = addslashes($submission->comment);
|
||||
if (update_record("assignment_submissions", $submission)) {
|
||||
print_heading(get_string("uploadsuccess", "assignment", $newfile_name) );
|
||||
} else {
|
||||
notify(get_string("uploadfailnoupdate", "assignment"));
|
||||
}
|
||||
$newfile_name = clean_filename($newfile['name']);
|
||||
if ($newfile_name) {
|
||||
if (move_uploaded_file($newfile['tmp_name'], "$dir/$newfile_name")) {
|
||||
chmod("$dir/$newfile_name", $CFG->directorypermissions);
|
||||
assignment_delete_user_files($assignment, $USER, $newfile_name);
|
||||
if ($submission) {
|
||||
$submission->timemodified = time();
|
||||
$submission->numfiles = 1;
|
||||
$submission->comment = addslashes($submission->comment);
|
||||
if (update_record("assignment_submissions", $submission)) {
|
||||
print_heading(get_string("uploadsuccess", "assignment", $newfile_name) );
|
||||
} else {
|
||||
$newsubmission->assignment = $assignment->id;
|
||||
$newsubmission->userid = $USER->id;
|
||||
$newsubmission->timecreated = time();
|
||||
$newsubmission->timemodified = time();
|
||||
$newsubmission->numfiles = 1;
|
||||
if (insert_record("assignment_submissions", $newsubmission)) {
|
||||
print_heading(get_string("uploadsuccess", "assignment", $newfile_name) );
|
||||
} else {
|
||||
notify(get_string("uploadnotregistered", "assignment", $newfile_name) );
|
||||
}
|
||||
notify(get_string("uploadfailnoupdate", "assignment"));
|
||||
}
|
||||
} else {
|
||||
notify(get_string("uploaderror", "assignment") );
|
||||
$newsubmission->assignment = $assignment->id;
|
||||
$newsubmission->userid = $USER->id;
|
||||
$newsubmission->timecreated = time();
|
||||
$newsubmission->timemodified = time();
|
||||
$newsubmission->numfiles = 1;
|
||||
if (insert_record("assignment_submissions", $newsubmission)) {
|
||||
print_heading(get_string("uploadsuccess", "assignment", $newfile_name) );
|
||||
} else {
|
||||
notify(get_string("uploadnotregistered", "assignment", $newfile_name) );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
notify(get_string("uploadbadname", "assignment") );
|
||||
notify(get_string("uploaderror", "assignment") );
|
||||
}
|
||||
} else {
|
||||
notify(get_string("uploadbadname", "assignment") );
|
||||
}
|
||||
} else {
|
||||
notify(get_string("uploadnofilefound", "assignment") );
|
||||
|
||||
print_file_upload_error();
|
||||
|
||||
}
|
||||
|
||||
print_continue("view.php?a=$assignment->id");
|
||||
|
||||
print_footer($course);
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -130,6 +130,8 @@
|
||||
echo "<p align=\"center\">".get_string("overwritewarning", "assignment")."</p>";
|
||||
}
|
||||
print_heading(get_string("submitassignment", "assignment").":", "center");
|
||||
|
||||
$assignment->maxbytes = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes, $assignment->maxbytes);
|
||||
assignment_print_upload_form($assignment);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user