mirror of
https://github.com/moodle/moodle.git
synced 2025-01-20 15:08:32 +01:00
ec81373f50
(While I was at it I also turned the autologinguests off for most module pages, except on the index.php pages and the view.php pages for those modules that allow guests)
93 lines
3.6 KiB
PHP
93 lines
3.6 KiB
PHP
<?php // $Id: upload.php, v1.0 30th April 2003
|
|
|
|
require("../../config.php");
|
|
require("lib.php");
|
|
require("locallib.php");
|
|
|
|
require_variable($id); // course module ID
|
|
$timenow = time();
|
|
|
|
// get some esential stuff...
|
|
if (! $cm = get_record("course_modules", "id", $id)) {
|
|
error("Course Module ID was incorrect");
|
|
}
|
|
|
|
if (! $course = get_record("course", "id", $cm->course)) {
|
|
error("Course is misconfigured");
|
|
}
|
|
|
|
if (! $exercise = get_record("exercise", "id", $cm->instance)) {
|
|
error("Course module is incorrect");
|
|
}
|
|
|
|
require_login($course->id, false, $cm);
|
|
|
|
$strexercises = get_string("modulenameplural", "exercise");
|
|
$strexercise = get_string("modulename", "exercise");
|
|
$strupload = get_string("upload");
|
|
|
|
print_header_simple("$exercise->name : $strupload", "",
|
|
"<a href=\"index.php?id=$course->id\">$strexercises</a> ->
|
|
<a href=\"view.php?id=$cm->id\">$exercise->name</a> -> $strupload",
|
|
"", "", true);
|
|
|
|
// check that this is not a "rapid" second submission, caused by using the back button
|
|
// only check if a student, teachers may want to submit a set of exercise variants
|
|
if (isstudent($course->id)) {
|
|
if ($submissions = exercise_get_user_submissions($exercise, $USER)) {
|
|
// returns all submissions, newest on first
|
|
foreach ($submissions as $submission) {
|
|
if ($submission->timecreated > $timenow - $CFG->maxeditingtime) {
|
|
// ignore this submission
|
|
redirect("view.php?id=$cm->id");
|
|
print_footer($course);
|
|
exit();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// check existence of title
|
|
if (!$title = $_POST['title']) {
|
|
notify(get_string("notitlegiven", "exercise") );
|
|
}
|
|
else {
|
|
require_once($CFG->dirroot.'/lib/uploadlib.php');
|
|
$um = new upload_manager('newfile',false,false,$course,false,$exercise->maxbytes);
|
|
if ($um->preprocess_files()) {
|
|
$newsubmission->exerciseid = $exercise->id;
|
|
if (isteacher($course->id)) {
|
|
// it's an exercise submission, flag it as such
|
|
$newsubmission->userid = 0;
|
|
$newsubmission->isexercise = 1; // it's a description of an exercise
|
|
}
|
|
else {
|
|
$newsubmission->userid = $USER->id;
|
|
}
|
|
$newsubmission->title = $title;
|
|
$newsubmission->timecreated = $timenow;
|
|
if ($timenow > $exercise->deadline) {
|
|
$newsubmission->late = 1;
|
|
}
|
|
if (!$newsubmission->id = insert_record("exercise_submissions", $newsubmission)) {
|
|
error("exercise upload: Failure to create new submission record!");
|
|
}
|
|
$dir = exercise_file_area_name($exercise, $newsubmission);
|
|
if ($um->save_files($dir)) {
|
|
add_to_log($course->id, "exercise", "submit", "view.php?id=$cm->id", "$exercise->id");
|
|
print_heading(get_string("uploadsuccess", "assignment", $um->get_new_filename()) );
|
|
}
|
|
// upload manager will print errors.
|
|
// clear resubmit flags
|
|
if (!set_field("exercise_submissions", "resubmit", 0, "exerciseid", $exercise->id, "userid", $USER->id)) {
|
|
error("Exercise Upload: unable to reset resubmit flag");
|
|
}
|
|
}
|
|
// upload manager will print errors.
|
|
}
|
|
print_continue("view.php?id=$cm->id");
|
|
|
|
print_footer($course);
|
|
|
|
?>
|