/** * Uploads the file submitted (adapted from mod/workshop/submissions.php) * * @param string $fileid string corresponding to the input file ('resp##_file') * @param int $attemptid attempt id * @param int $questionid question id * @param int $maxbytes maximum upload size in bytes * @return string feedback from upload, related to success or failure */ function upload_response($fileid, $course, $attemptid, $questionid, $maxbytes) { global $CFG; require_once $CFG->dirroot . '/lib/uploadlib.php'; $um = new upload_manager($fileid, true, false, $course, true, $maxbytes, true); if ($um->preprocess_files()) { $dir = quiz_file_area_name($attemptid, $questionid); if (!quiz_file_area($dir)) { return get_string('uploadproblem'); } if ($um->save_files($dir)) { return get_string('uploadedfile'); } } return get_string('uploaderror', 'qtype_fileresponse'); }
function wiki_upload_file($file, &$WS) { global $_FILES; if (file_exists($WS->dfdir->name . '/' . $_FILES[$file]['name'])) { //file already existst in the server $WS->dfdir->error[] = get_string('fileexisterror', 'wiki'); } else { //save file $upd = new upload_manager('dfformfile'); $upd->preprocess_files(); if (!$upd->save_files($WS->dfdir->name)) { //error uploading $WS->dfdir->error[] = get_string('fileuploaderror', 'wiki'); } } $WS->dfdir->content = get_directory_list($WS->dfdir->name); }
/** * Internal method. Validates all uploaded files. */ function _validate_files(&$files) { $files = array(); if (empty($_FILES)) { // we do not need to do any checks because no files were submitted // note: server side rules do not work for files - use custom verification in validate() instead return true; } $errors = array(); $mform =& $this->_form; // check the files $status = $this->_upload_manager->preprocess_files(); // now check that we really want each file foreach ($_FILES as $elname => $file) { if ($mform->elementExists($elname) and $mform->getElementType($elname) == 'file') { $required = $mform->isElementRequired($elname); if (!empty($this->_upload_manager->files[$elname]['uploadlog']) and empty($this->_upload_manager->files[$elname]['clear'])) { if (!$required and $file['error'] == UPLOAD_ERR_NO_FILE) { // file not uploaded and not required - ignore it continue; } $errors[$elname] = $this->_upload_manager->files[$elname]['uploadlog']; } else { if (!empty($this->_upload_manager->files[$elname]['clear'])) { $files[$elname] = $this->_upload_manager->files[$elname]['tmp_name']; } } } else { error('Incorrect upload attempt!'); } } // return errors if found if ($status and 0 == count($errors)) { return true; } else { $files = array(); return $errors; } }
/** * Internal method. Validates all uploaded files. */ function _validate_files() { if (empty($_FILES)) { // we do not need to do any checks because no files were submitted // TODO: find out why server side required rule does not work for uploaded files; // testing is easily done by always returning true from this function and adding // $mform->addRule('soubor', get_string('required'), 'required', null, 'server'); // and submitting form without selected file return true; } $errors = array(); $mform =& $this->_form; // check the files $status = $this->_upload_manager->preprocess_files(); // now check that we really want each file foreach ($_FILES as $elname => $file) { if ($mform->elementExists($elname) and $mform->getElementType($elname) == 'file') { $required = $mform->isElementRequired($elname); if (!empty($this->_upload_manager->files[$elname]['uploadlog']) and empty($this->_upload_manager->files[$elname]['clear'])) { if (!$required and $file['error'] == UPLOAD_ERR_NO_FILE) { // file not uploaded and not required - ignore it continue; } $errors[$elname] = $this->_upload_manager->files[$elname]['uploadlog']; } } else { error('Incorrect upload attempt!'); } } // return errors if found if ($status and 0 == count($errors)) { return true; } else { return $errors; } }
if (isset($CFG->CSV_DELIMITER)) { $csv_delimiter = '\\' . $CFG->CSV_DELIMITER; $csv_delimiter2 = $CFG->CSV_DELIMITER; if (isset($CFG->CSV_ENCODE)) { $csv_encode = '/\\&\\#' . $CFG->CSV_ENCODE . '/'; } } else { $csv_delimiter = '\\,'; $csv_delimiter2 = ','; } /// Print the header print_header("{$site->shortname}: {$struploadcourses}", $site->fullname, "<a href=\"index.php\">{$stradministration}</a> -> {$struploadcourses}"); /// If a file has been uploaded, then process it require_once $CFG->dirroot . '/lib/uploadlib.php'; $um = new upload_manager('coursefile', false, false, null, false, 0); if ($um->preprocess_files()) { if (!isset($um->files['coursefile'])) { csverror('Upload Error!', 'uploadcourse.php?sesskey=' . $USER->sesskey); } $filename = $um->files['coursefile']['tmp_name']; // Everything to Unix Line Endings $text = my_file_get_contents($filename); $text = preg_replace('!\\r\\n?!', "\n", $text); if ($fp = fopen($filename, "w")) { fwrite($fp, $text); unset($text); // Memory! fclose($fp); } else { csverror('File I/O Error! (1)', 'uploadcourse.php?sesskey=' . $USER->sesskey); }
/** * Takes the submitted file and adds it to the Moodle file area * * @global object * @global object * @param object $cm The moodle course module object for this instance * @param object $turnitintool The turnitintool object for this activity * @param var $userid User ID of the user to check * @param array $post POST Array of the submission form of the user to check * @return boolean Submission was found / not found */ function turnitintool_dofileupload_pre_29($cm, $turnitintool, $userid, $post) { global $USER, $CFG; $param_do = optional_param('do', null, PARAM_CLEAN); $error = false; $notice = array("error" => '', "subid" => ''); $submissiontitle = ''; if (isset($post['submissiontitle'])) { $submissiontitle = str_replace("<", "", $post['submissiontitle']); $submissiontitle = str_replace(">", "", $submissiontitle); } if (empty($_FILES['submissionfile']['name'])) { $notice["error"] .= get_string('submissionfileerror', 'turnitintool') . '<br />'; $error = true; } if (empty($submissiontitle)) { $notice["error"] .= get_string('submissiontitleerror', 'turnitintool') . '<br />'; $error = true; } if (!isset($post['agreement'])) { $notice["error"] .= get_string('submissionagreementerror', 'turnitintool') . '<br />'; $error = true; } $checksubmission = turnitintool_checkforsubmission($cm, $turnitintool, $post['submissionpart'], $userid); if (!$error and isset($checksubmission->id) and $turnitintool->reportgenspeed == 0) { // Kill the script here as we do not want double errors // We only get here if there are no other errors turnitintool_print_error('alreadysubmitted', 'turnitintool', NULL, NULL, __FILE__, __LINE__); exit; } $resubmission = false; if (isset($checksubmission->id) and $turnitintool->reportgenspeed > 0) { $resubmission = true; } if ($resubmission and $checksubmission->dtdue < time()) { turnitintool_print_error('alreadysubmitted', 'turnitintool', NULL, NULL, __FILE__, __LINE__); exit; } $explode = explode('.', $_FILES['submissionfile']['name']); $extension = array_pop($explode); $_FILES['submissionfile']['name'] = $post['submissionpart'] . '_' . time() . '_' . $userid . '.' . $extension; $upload = new upload_manager(); if (!$upload->preprocess_files()) { $notice["error"] .= $upload->notify; $error = true; } if (!$error) { $submitobject = new stdClass(); $submitobject->userid = $userid; $submitobject->turnitintoolid = $turnitintool->id; $submitobject->submission_part = $post['submissionpart']; $submitobject->submission_type = $post['submissiontype']; $submitobject->submission_filename = $_FILES['submissionfile']['name']; $submitobject->submission_queued = null; $submitobject->submission_attempts = 0; $submitobject->submission_gmimaged = 0; $submitobject->submission_status = null; $submitobject->submission_modified = time(); $submitobject->submission_objectid = !isset($checksubmission->submission_objectid) ? null : $checksubmission->submission_objectid; if (!isset($checksubmission->submission_unanon) or $checksubmission->submission_unanon) { // If non anon resubmission or new submission set the title as what was entered in the form $submitobject->submission_title = $submissiontitle; if (!$turnitintool->anon) { // If not anon assignment and this is a non anon resubmission or a new submission set the unanon flag to true (1) $submitobject->submission_unanon = 1; } } if (!$resubmission) { // Prevent duplication in issues where the TII servers may be inaccessible. if (!($check_existing = turnitintool_get_records_select('turnitintool_submissions', 'userid=' . $submitobject->userid . ' AND turnitintoolid=' . $submitobject->turnitintoolid . ' AND submission_part=' . $submitobject->submission_part))) { if (!($submitobject->id = turnitintool_insert_record('turnitintool_submissions', $submitobject))) { turnitintool_print_error('submissioninserterror', 'turnitintool', NULL, NULL, __FILE__, __LINE__); exit; } } } else { $submitobject->id = $checksubmission->id; $submitobject->submission_score = null; $submitobject->submission_grade = null; if (!turnitintool_update_record('turnitintool_submissions', $submitobject)) { turnitintool_print_error('submissionupdateerror', 'turnitintool', NULL, NULL, __FILE__, __LINE__); exit; } else { $submitobject->id = $checksubmission->id; } } if (is_callable("get_file_storage")) { $fs = get_file_storage(); $file_record = array('contextid' => $cm->id, 'component' => 'mod_turnitintool', 'filearea' => 'submission', 'itemid' => $submitobject->id, 'filepath' => '/', 'filename' => $submitobject->submission_filename, 'userid' => $submitobject->userid); if (!$fs->create_file_from_pathname($file_record, $_FILES['submissionfile']['tmp_name'])) { turnitintool_delete_records('turnitintool_submissions', 'id', $submitobject->id); turnitintool_print_error('fileuploaderror', 'turnitintool', NULL, NULL, __FILE__, __LINE__); exit; } } else { $destination = turnitintool_file_path($cm, $turnitintool, $userid); if (!$upload->save_files($destination)) { turnitintool_delete_records('turnitintool_submissions', 'id', $submitobject->id); turnitintool_print_error('fileuploaderror', 'turnitintool', NULL, NULL, __FILE__, __LINE__); exit; } } if (has_capability('mod/turnitintool:grade', turnitintool_get_context('MODULE', $cm->id)) and !$turnitintool->autosubmission) { turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=allsubmissions'); exit; } else { if (!$turnitintool->autosubmission) { turnitintool_redirect($CFG->wwwroot . '/mod/turnitintool/view.php?id=' . $cm->id . '&do=' . $param_do); exit; } } $notice["subid"] = $submitobject->id; } return $notice; }
error(get_string('noaccess', 'data')); } } /// Print the page header $strdata = get_string('modulenameplural', 'data'); $navigation = build_navigation('', $cm); print_header_simple($data->name, "", $navigation, "", "", true, "", user_login_string($course) . '<hr style="width:95%">' . navmenu($course)); print_heading(format_string($data->name)); /// Groups needed for Add entry tab $currentgroup = groups_get_activity_group($cm); $groupmode = groups_get_activity_groupmode($cm); /// Print the tabs $currenttab = 'add'; include 'tabs.php'; $um = new upload_manager('recordsfile', false, false, null, false, 0); if ($um->preprocess_files() && confirm_sesskey()) { $filename = $um->files['recordsfile']['tmp_name']; // Large files are likely to take their time and memory. Let PHP know // that we'll take longer, and that the process should be recycled soon // to free up memory. @set_time_limit(0); @raise_memory_limit("96M"); if (function_exists('apache_child_terminate')) { @apache_child_terminate(); } //Fix mac/dos newlines $text = my_file_get_contents($filename); $text = preg_replace('!\\r\\n?!', "\n", $text); $fp = fopen($filename, "w"); fwrite($fp, $text); fclose($fp);
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(); }
/** * stores in database the element values * @uses $CFG * @param object $issue */ function tracker_recordelements(&$issue) { global $CFG, $COURSE; $keys = array_keys($_POST); // get the key value of all the fields submitted $keys = preg_grep('/element./', $keys); // filter out only the element keys $filekeys = array_keys($_FILES); // get the key value of all the fields submitted $filekeys = preg_grep('/element./', $filekeys); // filter out only the element keys $keys = array_merge($keys, $filekeys); foreach ($keys as $key) { preg_match('/element(.*)$/', $key, $elementid); $elementname = $elementid[1]; $sql = "\n SELECT \n e.id as elementid,\n e.type as type\n FROM\n {$CFG->prefix}tracker_elementused eu,\n {$CFG->prefix}tracker_element e\n WHERE\n eu.elementid = e.id AND\n e.name = '{$elementname}' AND\n eu.trackerid = {$issue->trackerid} \n "; $attribute = get_record_sql($sql); $attribute->timemodified = $issue->datereported; $values = optional_param($key, '', PARAM_CLEANHTML); $attribute->issueid = $issue->id; $attribute->trackerid = $issue->trackerid; /// For those elements where more than one option can be selected if (is_array($values)) { foreach ($values as $value) { $attribute->elementitemid = $value; $attributeid = insert_record('tracker_issueattribute', $attribute); if (!$attributeid) { error("Could not submit issue(s) attribute(s): issue:{$issue->id} issueid:{$elementid['1']} elementitemid:{$attribute->elementitemid}"); } } } else { //For the rest of the elements that can only support one answer if ($attribute->type != 'file') { require_once $CFG->libdir . '/uploadlib.php'; $attribute->elementitemid = $values; $attributeid = insert_record('tracker_issueattribute', $attribute); } else { $uploader = new upload_manager($key, false, false, $COURSE->id, true, 0, true); $uploader->preprocess_files(); $newfilename = $uploader->get_new_filename(); $encodedfilename = ''; if (!empty($newfilename)) { $encodedfilename = md5(time()) . '_' . $newfilename; $storebase = "{$COURSE->id}/moddata/tracker/{$issue->trackerid}/{$issue->id}"; if (!filesystem_is_dir($storebase)) { filesystem_create_dir($storebase, FS_RECURSIVE); } $uploader->save_files($storebase); filesystem_move_file($storebase . '/' . $newfilename, $storebase . '/' . $encodedfilename); $attribute->elementitemid = $encodedfilename; $attributeid = insert_record('tracker_issueattribute', $attribute); } } if (empty($attributeid)) { error("Could not submit issue attribute: issue:{$issue->id} elementid:{$elementid['1']} elementitemid:{$attribute->elementitemid}"); } } } }
} } else { if ($action == 'import') { /// Allow users to enter their responses if (!has_capability('mod/brainstorm:import', $context)) { error("This user cannot import data"); return -1; } include 'import.html'; return -1; } else { if ($action == 'doimport') { $clearalldata = optional_param('clearall', 0, PARAM_INT); $allusersclear = optional_param('allusersclear', 0, PARAM_INT); $uploader = new upload_manager('inputs', false, false, $course->id, true, 0, true); if ($uploader->preprocess_files()) { $content = file($uploader->files['inputs']['tmp_name']); $ideas = preg_grep("/^[^!\\/#].*\$/", $content); if ($clearalldata) { if ($allusersclear) { delete_records('brainstorm_responses', 'brainstormid', $brainstorm->id); delete_records('brainstorm_operatordata', 'brainstormid', $brainstorm->id); } else { delete_records('brainstorm_responses', 'brainstormid', $brainstorm->id, 'userid', $USER->id); delete_records('brainstorm_operatordata', 'brainstormid', $brainstorm->id, 'userid', $USER->id); } } $response->brainstormid = $brainstorm->id; $response->userid = $USER->id; $response->groupid = $currentgroup; $response->timemodified = time();
} } } switch ($action) { case 'upload': if (!$canedit) { print_error('youdonothaveaccesstothisfunctionality', 'repository_alfresco'); } html_header($course, $wdir); require_once $CFG->dirroot . '/lib/uploadlib.php'; if ($save and confirm_sesskey()) { $course->maxbytes = 0; // We are ignoring course limits $um = new upload_manager('userfile', false, false, $course, false, 0); // Pre-process the upload to see if there were any errors in the upload. if (!$um->preprocess_files()) { if ($id != SITEID) { displaydir($uuid, $wdir, $id); } else { displaydir($uuid, $wdir); } html_footer(); break; } $dir = "{$basedir}{$wdir}"; if (!$um->preprocess_files()) { notify(get_string('uploadedfile')); } if (isset($_FILES['userfile'])) { // Make sure that the uploaded filename does not exist in the destination directory. $issafe = true;