$form->attachment = clean_param($form->attachment, PARAM_PATH); if (file_exists($CFG->dataroot . '/' . $course->id . '/' . $form->attachment)) { $attachment = $course->id . '/' . $form->attachment; $pathparts = pathinfo($form->attachment); $attachname = $pathparts['basename']; } else { $form->error = get_string('attachmenterror', 'block_quickmail', $form->attachment); } } } else { require_once $CFG->libdir . '/uploadlib.php'; $um = new upload_manager('attachment', false, true, $course, false, 0, true); // process the student posted attachment if it exists if ($um->process_file_uploads('temp/block_quickmail')) { // original name gets saved in the database $form->attachment = $um->get_original_filename(); // check if file is there if (file_exists($um->get_new_filepath())) { // get path to the file without $CFG->dataroot $attachment = 'temp/block_quickmail/' . $um->get_new_filename(); // get the new name (name may change due to filename collisions) $attachname = $um->get_new_filename(); } else { $form->error = get_string("attachmenterror", "block_quickmail", $form->attachment); } } else { $form->attachment = ''; // no attachment } } // no errors, then email
function upload() { global $CFG, $USER; $NUM_REVIEWS = 2; $POOL_SIZE = 2 * $NUM_REVIEWS + 1; // including current submitter require_capability('mod/assignment:submit', get_context_instance(CONTEXT_MODULE, $this->cm->id)); $this->view_header(get_string('upload')); if ($this->isopen()) { if (!record_exists('assignment_submissions', 'assignment', $this->assignment->id, 'userid', $USER->id)) { $newsubmission = NULL; // Process online text if (isset($this->assignment->var3) && $this->assignment->var3 == self::ONLINE_TEXT) { $newsubmission = $this->prepare_new_submission($USER->id); $newsubmission->data1 = addslashes(required_param('text', PARAM_CLEANHTML)); $sumbissionName = get_string('yoursubmission', 'assignment_peerreview'); // echo '<pre>'.print_r($_POST,true).'</pre>'; } else { $dir = $this->file_area_name($USER->id); require_once $CFG->dirroot . '/lib/uploadlib.php'; $um = new upload_manager('newfile', true, false, $this->course, false, $this->assignment->maxbytes); if ($um->preprocess_files()) { //Check the file extension $submittedFilename = $um->get_original_filename(); $extension = $this->assignment->fileextension; if (strtolower(substr($submittedFilename, strlen($submittedFilename) - strlen($extension))) != $extension) { notify(get_string("incorrectfileextension", "assignment_peerreview", $extension)); } else { if ($um->save_files($dir)) { $sumbissionName = $um->get_new_filename(); $newsubmission = $this->prepare_new_submission($USER->id); $newsubmission->numfiles = 1; } } } } if ($newsubmission) { // Enter submission into DB and log $newsubmission->timecreated = time(); $newsubmission->timemodified = time(); if (insert_record('assignment_submissions', $newsubmission)) { add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id); // $this->email_teachers($newsubmission); print_heading(get_string('uploadedfile')); $submissionSuccess = true; } else { notify(get_string("uploadnotregistered", "assignment", $sumbissionName)); } // Allocate reviews $recentSubmissions = array(); $numberOfRecentSubmissions = 0; if ($submissionResult = get_records_sql('SELECT userid FROM ' . $CFG->prefix . 'assignment_submissions WHERE assignment=\'' . $this->assignment->id . '\' ORDER BY timecreated DESC, id DESC', 0, $POOL_SIZE + 1)) { $recentSubmissions = array_values($submissionResult); $numberOfRecentSubmissions = count($recentSubmissions); } if ($numberOfRecentSubmissions >= $POOL_SIZE) { for ($i = 2; $i < 2 * $NUM_REVIEWS + 1; $i += 2) { if (!insert_record('assignment_review', $this->prepare_new_review($USER->id, $recentSubmissions[$i]->userid))) { notify(get_string("reviewsallocationerror", "assignment_peerreview")); } } } // If pool just got large enough, allocated reviews to previous submitters if ($numberOfRecentSubmissions == $POOL_SIZE) { $recentSubmissions = array_reverse($recentSubmissions); for ($i = 0; $i < $POOL_SIZE - 1; $i++) { for ($j = 1; $j <= $NUM_REVIEWS; $j++) { insert_record('assignment_review', $this->prepare_new_review($recentSubmissions[$i]->userid, $recentSubmissions[$i - 2 * $j + ($i - 2 * $j >= 0 ? 0 : $NUM_REVIEWS * 2 + 1)]->userid)); } // Send an email to student $subject = get_string('reviewsallocatedsubject', 'assignment_peerreview'); $linkToReview = $CFG->wwwroot . '/mod/assignment/view.php?id=' . $this->cm->id; $message = get_string('reviewsallocated', 'assignment_peerreview') . "\n\n" . get_string('assignmentname', 'assignment') . ': ' . $this->assignment->name . "\n" . get_string('course') . ': ' . $this->course->fullname . "\n\n"; $messageText = $message . $linkToReview; $messageHTML = nl2br($message) . '<a href="' . $linkToReview . '" target="_blank">' . get_string('reviewsallocatedlinktext', 'assignment_peerreview') . '</a>'; $this->email_from_teacher($this->course->id, $recentSubmissions[$i]->userid, $subject, $messageText, $messageHTML); } } if ($numberOfRecentSubmissions >= $POOL_SIZE) { redirect('view.php?id=' . $this->cm->id, get_string("reviewsallocated", "assignment_peerreview"), 2); } else { notify(get_string("poolnotlargeenough", "assignment_peerreview"), 'notifysuccess'); print_continue('view.php?id=' . $this->cm->id); } } } else { notify(get_string("resubmit", "assignment_peerreview", $this->course->teacher)); // re-submitting not allowed print_continue('view.php?id=' . $this->cm->id); } } else { notify(get_string("closed", "assignment_peerreview")); // assignment closed print_continue('view.php?id=' . $this->cm->id); } $this->view_footer(); }
} $ul_username = run("users:id_to_name", $page_owner); $upload_folder = $textlib->substr($ul_username, 0, 1); require_once $CFG->dirroot . 'lib/uploadlib.php'; $total_quota = get_field_sql('SELECT sum(size) FROM ' . $CFG->prefix . 'files WHERE owner = ?', array($page_owner)); $max_quota = get_field('users', 'file_quota', 'ident', $page_owner); $maxbytes = $max_quota - $tota_quota; $um = new upload_manager('new_file', false, true, false, $maxbytes, true); $reldir = "files/" . $upload_folder . "/" . $ul_username . "/"; $dir = $CFG->dataroot . $reldir; if ($um->process_file_uploads($dir)) { $f = new StdClass(); $f->owner = $USER->ident; $f->files_owner = $page_owner; $f->folder = $folderid; $f->originalname = $um->get_original_filename(); if (empty($title)) { $title = $um->get_original_filename(); } $f->title = $title; $f->description = $description; $f->location = $reldir . '/' . $um->get_new_filename(); $f->access = $access; $f->size = $um->get_filesize(); $f->time_uploaded = time(); $file_id = insert_record('files', $f); $value = trim(optional_param('new_file_keywords')); insert_tags_from_string($value, 'file', $file_id, $access, $page_owner); $metadata = optional_param('metadata'); if (is_array($metadata)) { foreach ($metadata as $name => $value) {
$submission->timemodified = time(); $submission->data1 = required_param('text', PARAM_CLEANHTML); if (update_record('assignment_submissions', $submission)) { add_to_log($assignmentinstance->course->id, 'assignment', 'upload', 'view.php?a=' . $assignmentinstance->assignment->id, $assignmentinstance->assignment->id, $assignmentinstance->cm->id); notify(get_string('resubmissionsuccessful', 'assignment_peerreview'), 'notifysuccess'); } else { notify(get_string("uploadnotregistered", "assignment", $newfile_name)); } } else { // Process the resubmission $dir = $assignmentinstance->file_area_name($userid); require_once $CFG->dirroot . '/lib/uploadlib.php'; $um = new upload_manager('newfile', true, false, $assignmentinstance->course, false, $assignmentinstance->assignment->maxbytes); if ($um->preprocess_files()) { //Check the file extension $submittedFilename = $um->get_original_filename(); $extension = $assignmentinstance->assignment->fileextension; if (strtolower(substr($submittedFilename, strlen($submittedFilename) - strlen($extension))) != $extension) { notify(get_string("incorrectfileextension", "assignment_peerreview", $extension)); } else { if ($um->save_files($dir)) { $newfile_name = $um->get_new_filename(); $um->config->silent = true; $um->delete_other_files($dir, $dir . '/' . $newfile_name); $submission = $assignmentinstance->get_submission($userid); if (set_field('assignment_submissions', 'timemodified', time(), 'id', $submission->id)) { add_to_log($assignmentinstance->course->id, 'assignment', 'upload', 'view.php?a=' . $assignmentinstance->assignment->id, $assignmentinstance->assignment->id, $assignmentinstance->cm->id); notify(get_string('resubmissionsuccessful', 'assignment_peerreview'), 'notifysuccess'); } else { notify(get_string("uploadnotregistered", "assignment", $newfile_name)); }