2002-08-04 16:19:37 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
|
2003-01-05 14:19:20 +00:00
|
|
|
require_once("../../config.php");
|
|
|
|
require_once("lib.php");
|
2002-08-04 16:19:37 +00:00
|
|
|
|
|
|
|
require_variable($id); // Assignment ID
|
|
|
|
|
2003-01-05 04:20:32 +00:00
|
|
|
if (!empty($_FILES['newfile'])) {
|
|
|
|
$newfile = $_FILES['newfile'];
|
|
|
|
}
|
2002-08-04 16:19:37 +00:00
|
|
|
|
|
|
|
if (! $assignment = get_record("assignment", "id", $id)) {
|
|
|
|
error("Not a valid assignment ID");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $course = get_record("course", "id", $assignment->course)) {
|
|
|
|
error("Course is misconfigured");
|
|
|
|
}
|
|
|
|
|
2004-02-05 05:10:39 +00:00
|
|
|
if (! $cm = get_coursemodule_from_instance("assignment", $assignment->id, $course->id)) {
|
|
|
|
error("Course Module ID was incorrect");
|
|
|
|
}
|
|
|
|
|
2002-08-04 16:19:37 +00:00
|
|
|
require_login($course->id);
|
|
|
|
|
2004-02-05 05:10:39 +00:00
|
|
|
add_to_log($course->id, "assignment", "upload", "view.php?a=$assignment->id", "$assignment->id", $cm->id);
|
2002-08-04 16:19:37 +00:00
|
|
|
|
|
|
|
if ($course->category) {
|
|
|
|
$navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
|
|
|
|
}
|
|
|
|
$strassignments = get_string("modulenameplural", "assignment");
|
|
|
|
$strassignment = get_string("modulename", "assignment");
|
|
|
|
$strupload = get_string("upload");
|
|
|
|
|
|
|
|
print_header("$course->shortname: $assignment->name : $strupload", "$course->fullname",
|
|
|
|
"$navigation <A HREF=index.php?id=$course->id>$strassignments</A> ->
|
|
|
|
<A HREF=\"view.php?a=$assignment->id\">$assignment->name</A> -> $strupload",
|
|
|
|
"", "", true);
|
|
|
|
|
2003-07-25 14:28:26 +00:00
|
|
|
if ($submission = get_record("assignment_submissions", "assignment", $assignment->id, "userid", $USER->id)) {
|
2002-11-15 03:32:30 +00:00
|
|
|
if ($submission->grade and !$assignment->resubmit) {
|
2002-08-04 16:19:37 +00:00
|
|
|
error("You've already been graded - there's no point in uploading anything");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $dir = assignment_file_area($assignment, $USER)) {
|
|
|
|
error("Sorry, an error in the system prevents you from uploading files: contact your teacher or system administrator");
|
|
|
|
}
|
|
|
|
|
2003-01-05 04:20:32 +00:00
|
|
|
if (empty($newfile)) {
|
|
|
|
notify(get_string("uploadnofilefound", "assignment") );
|
|
|
|
|
|
|
|
} else if (is_uploaded_file($newfile['tmp_name']) and $newfile['size'] > 0) {
|
2002-08-04 16:19:37 +00:00
|
|
|
if ($newfile['size'] > $assignment->maxbytes) {
|
2002-10-28 02:24:38 +00:00
|
|
|
notify(get_string("uploadfiletoobig", "assignment", $assignment->maxbytes));
|
2002-08-04 16:19:37 +00:00
|
|
|
} else {
|
|
|
|
$newfile_name = clean_filename($newfile['name']);
|
|
|
|
if ($newfile_name) {
|
|
|
|
if (move_uploaded_file($newfile['tmp_name'], "$dir/$newfile_name")) {
|
2003-04-21 07:11:29 +00:00
|
|
|
chmod("$dir/$newfile_name", $CFG->directorypermissions);
|
2002-08-04 16:19:37 +00:00
|
|
|
assignment_delete_user_files($assignment, $USER, $newfile_name);
|
|
|
|
if ($submission) {
|
|
|
|
$submission->timemodified = time();
|
2002-11-12 04:59:28 +00:00
|
|
|
$submission->numfiles = 1;
|
2003-01-23 04:23:05 +00:00
|
|
|
$submission->comment = addslashes($submission->comment);
|
2002-08-04 16:19:37 +00:00
|
|
|
if (update_record("assignment_submissions", $submission)) {
|
2002-10-28 01:30:00 +00:00
|
|
|
print_heading(get_string("uploadsuccess", "assignment", $newfile_name) );
|
2002-08-04 16:19:37 +00:00
|
|
|
} else {
|
2002-10-28 02:24:38 +00:00
|
|
|
notify(get_string("uploadfailnoupdate", "assignment"));
|
2002-08-04 16:19:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-08-06 09:23:28 +00:00
|
|
|
$newsubmission->assignment = $assignment->id;
|
2002-12-23 09:39:26 +00:00
|
|
|
$newsubmission->userid = $USER->id;
|
2002-08-06 09:23:28 +00:00
|
|
|
$newsubmission->timecreated = time();
|
|
|
|
$newsubmission->timemodified = time();
|
|
|
|
$newsubmission->numfiles = 1;
|
|
|
|
if (insert_record("assignment_submissions", $newsubmission)) {
|
2002-10-28 01:30:00 +00:00
|
|
|
print_heading(get_string("uploadsuccess", "assignment", $newfile_name) );
|
2002-08-04 16:19:37 +00:00
|
|
|
} else {
|
2002-10-28 02:24:38 +00:00
|
|
|
notify(get_string("uploadnotregistered", "assignment", $newfile_name) );
|
2002-08-04 16:19:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2002-10-28 02:24:38 +00:00
|
|
|
notify(get_string("uploaderror", "assignment") );
|
2002-08-04 16:19:37 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-10-28 02:24:38 +00:00
|
|
|
notify(get_string("uploadbadname", "assignment") );
|
2002-08-04 16:19:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2002-10-28 02:24:38 +00:00
|
|
|
notify(get_string("uploadnofilefound", "assignment") );
|
2002-08-04 16:19:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print_continue("view.php?a=$assignment->id");
|
|
|
|
|
|
|
|
print_footer($course);
|
|
|
|
|
|
|
|
?>
|