function upload() { global $CFG, $USER, $DB, $OUTPUT; require_capability('mod/assignment:submit', get_context_instance(CONTEXT_MODULE, $this->cm->id)); $this->view_header(get_string('upload')); $filecount = $this->count_user_files($USER->id); $submission = $this->get_submission($USER->id); if ($this->isopen() && (!$filecount || $this->assignment->resubmit || !$submission->timemarked)) { if ($submission = $this->get_submission($USER->id)) { //TODO: change later to ">= 0", to prevent resubmission when graded 0 if ($submission->grade > 0 and !$this->assignment->resubmit) { echo $OUTPUT->notification(get_string('alreadygraded', 'assignment')); } } $mform = new mod_assignment_upload_file_form('upload.php', $this); if ($mform->get_data()) { $fs = get_file_storage(); $filename = $mform->get_new_filename('newfile'); if ($filename !== false) { $fs->delete_area_files($this->context->id, 'assignment_submission', $USER->id); if ($file = $mform->save_stored_file('newfile', $this->context->id, 'assignment_submission', $USER->id, '/', $filename, false, $USER->id)) { $submission = $this->get_submission($USER->id, true); //create new submission if needed $submission->timemodified = time(); $submission->numfiles = 1; if ($DB->update_record('assignment_submissions', $submission)) { add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id); $this->update_grade($submission); $this->email_teachers($submission); echo $OUTPUT->heading(get_string('uploadedfile')); redirect('view.php?id=' . $this->cm->id); } else { echo $OUTPUT->notification(get_string("uploadnotregistered", "assignment", $newfile_name)); $file->delete(); } } } } else { echo $OUTPUT->notification(get_string("uploaderror", "assignment")); //submitting not allowed! } } echo $OUTPUT->continue_button('view.php?id=' . $this->cm->id); $this->view_footer(); }
function upload_file() { global $CFG, $USER, $DB; $returnurl = 'view.php?id=' . $this->cm->id; $filecount = $this->count_user_files($USER->id); $submission = $this->get_submission($USER->id); if (!$this->can_upload_file($submission)) { $this->view_header(get_string('upload')); notify(get_string('uploaderror', 'assignment')); print_continue($returnurl); $this->view_footer(); die; } $mform = new mod_assignment_upload_file_form('upload.php', $this); if ($mform->get_data()) { $fs = get_file_storage(); $filename = $mform->get_new_filename('newfile'); if ($filename !== false) { if (!$fs->file_exists($this->context->id, 'assignment_submission', $USER->id, '/', $filename)) { if ($file = $mform->save_stored_file('newfile', $this->context->id, 'assignment_submission', $USER->id, '/', $filename, false, $USER->id)) { $submission = $this->get_submission($USER->id, true); //create new submission if needed $submission->timemodified = time(); if ($DB->update_record('assignment_submissions', $submission)) { add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id); $this->update_grade($submission); if (!$this->drafts_tracked()) { $this->email_teachers($submission); } redirect('view.php?id=' . $this->cm->id); } else { $file->delete(); } } } } } $this->view_header(get_string('upload')); notify(get_string('uploaderror', 'assignment')); print_continue($returnurl); $this->view_footer(); die; }