insert_tags_from_string($value, 'file', $file_id, $access, $page_owner); $metadata = optional_param('metadata'); if (is_array($metadata)) { foreach ($metadata as $name => $value) { $m = new StdClass(); $m->name = trim($name); $m->value = trim($value); $m->file_id = $file_id; insert_record('file_metadata', $m); } } $rssresult = run("files:rss:publish", array($page_owner, false)); $rssresult = run("profile:rss:publish", array($page_owner, false)); $messages[] = gettext("The file was successfully uploaded."); } else { $messages[] = $um->get_errors(); } $redirect_url = url . $ul_username . "/files/"; if ($folderid > -1) { $redirect_url .= $folderid; } define('redirect_url', $redirect_url); } break; // Edit a file // Edit a file case "files:editfile": $f = new stdClass(); $f->ident = optional_param('file_id', 0, PARAM_INT); $f->title = trim(optional_param('edit_file_title')); $f->folder = optional_param('edit_file_folder', 0, PARAM_INT);
function upload_file() { global $CFG, $USER; $mode = optional_param('mode', '', PARAM_ALPHA); $offset = optional_param('offset', 0, PARAM_INT); $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; } $dir = $this->file_area_name($USER->id); check_dir_exists($CFG->dataroot . '/' . $dir, true, true); // better to create now so that student submissions do not block it later require_once $CFG->dirroot . '/lib/uploadlib.php'; $um = new upload_manager('newfile', false, true, $this->course, false, $this->assignment->maxbytes, true); if ($um->process_file_uploads($dir)) { $submission = $this->get_submission($USER->id, true); //create new submission if needed $updated = new object(); $updated->id = $submission->id; $updated->timemodified = time(); if (update_record('assignment_submissions', $updated)) { add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id); $submission = $this->get_submission($USER->id); $this->update_grade($submission); if (!$this->drafts_tracked()) { $this->email_teachers($submission); } } else { $new_filename = $um->get_new_filename(); $this->view_header(get_string('upload')); notify(get_string('uploadnotregistered', 'assignment', $new_filename)); print_continue($returnurl); $this->view_footer(); die; } redirect('view.php?id=' . $this->cm->id); } $this->view_header(get_string('upload')); notify(get_string('uploaderror', 'assignment')); echo $um->get_errors(); print_continue($returnurl); $this->view_footer(); die; }
/** * Saves an uploaded Dialogue attachment to the moddata directory * * @param object $entry * @param string $inputname * @param string messages string, passed by reference * @return string new file name */ function dialogue_add_attachment($entry, $inputname, &$message) { global $CFG, $COURSE; require_once $CFG->dirroot . '/lib/uploadlib.php'; $um = new upload_manager($inputname, true, false, $COURSE, false, 0, true, true); $dir = dialogue_file_area_name($entry); if ($um->process_file_uploads($dir)) { $message .= $um->get_errors(); return $um->get_new_filename(); } $message .= $um->get_errors(); return null; }
/** * */ function forum_add_attachment($post, $inputname, &$message) { global $CFG; if (!($forum = get_record("forum", "id", $post->forum))) { return ""; } if (!($course = get_record("course", "id", $forum->course))) { return ""; } require_once $CFG->dirroot . '/lib/uploadlib.php'; $um = new upload_manager($inputname, true, false, $course, false, $forum->maxbytes, true, true); $dir = forum_file_area_name($post); if ($um->process_file_uploads($dir)) { $message .= $um->get_errors(); return $um->get_new_filename(); } $message .= $um->get_errors(); return null; }
/** * This function add new files into mailid. * * @uses $CFG * @access protected * @version 1.0 * @param $attachments Is an array get to $_FILES * @return string Array of all name attachments upload */ function add_attachments() { global $CFG; /// Note: $attachments is an array, who it's 5 sub-array in here. /// name, type, tmp_name. size, error who have an arrays. // Prevent errors if (empty($this->oldattachments) and (empty($this->attachments) or isset($this->attachments['FILE_0']['error']) and $this->attachments['FILE_0']['error'] == 4)) { return true; } // Get course for upload manager if (!($course = get_record('course', 'id', $this->course))) { return ''; } require_once $CFG->dirroot . '/lib/uploadlib.php'; // Get directory for save this attachments $dir = $this->get_file_area(); // Now, delete old corresponding files if (!empty($this->oldattachments)) { if ($this->type != EMAIL_FORWARD and $this->type != EMAIL_REPLY and $this->type != EMAIL_REPLYALL) { // Working in same email // Necessary library for this function include_once $CFG->dirroot . '/lib/filelib.php'; // Get files of mail if ($files = get_directory_list($dir)) { // Process all attachments foreach ($files as $file) { // Get path of file $attach = $this->get_file_area_name() . '/' . $file; $attachments[] = $attach; } } if ($diff = array_diff($attachments, $this->oldattachments)) { foreach ($diff as $attachment) { unlink($CFG->dataroot . '/' . $attachment); // Drop file } } } else { if ($this->type === EMAIL_FORWARD) { // Copy $this->oldattachments in this new email foreach ($this->oldattachments as $attachment) { copy($CFG->dataroot . '/' . $attachment, $this->get_file_area() . '/' . basename($attachment)); } } } } if (!empty($this->attachments) or isset($this->attachments['FILE_0']['error']) and $this->attachments['FILE_0']['error'] != 4) { // Now, processing all attachments . . . $um = new upload_manager(NULL, false, false, $course, false, 0, true, true); } if (!$um->process_file_uploads($dir)) { // empty file upload. Error solve in latest version of moodle. // Warning! Only comprove first mail. Bug of uploadlib.php. $message = get_string('uploaderror', 'assignment'); $message .= '<br />'; $message .= $um->get_errors(); print_simple_box($message, '', '', '', '', 'errorbox'); print_continue($CFG->wwwroot . '/blocks/email_list/email/index.php?id=' . $course->id); print_footer(); die; } return true; }
function profile_photo_validate_input_field($parameter) { global $CFG, $messages, $data, $profile_id; $found = false; foreach ($data['profile:details'] as $profileitem) { if (is_array($profileitem)) { $fname = $profileitem[1]; $ftype = $profileitem[2]; } else { $fname = $profileitem->internal_name; $ftype = $profileitem->field_type; } if ($fname == $parameter->name) { $found = true; break; } } if ($found && ($ftype = "profile_photo")) { require_once $CFG->dirroot . 'lib/uploadlib.php'; require_once $CFG->dirroot . 'lib/filelib.php'; $textlib = textlib_get_instance(); $upload_folder = $textlib->substr(user_info("username", $profile_id), 0, 1); $um = new upload_manager('profile_photo_' . $fname, true, true, false, 5000000, true); $reldir = "profile_photos/" . $upload_folder . "/" . user_info("username", $profile_id) . "/" . $parameter->name . "/"; $dir = $CFG->dataroot . $reldir; if ($um->process_file_uploads($dir)) { $parameter->value = $reldir . $um->get_new_filename(); update_record('profile_data', $parameter); } else { $messages[] = $um->get_errors(); } } return true; }
$f->size = $um->get_filesize(); $f->reg_time = time(); //insert into db if ($rs = insert_record('prop_files', $f)) { $errmsg[] = __('Archivo registrado exitosamente.'); //reset file $file = new StdClass(); $file->title = ''; $file->descr = ''; $file->public = 0; } else { $errmsg[] = __('Ocurrió un error al registrar el archivo.'); } } else { $errmsg[] = __('Error al subir el archivo.'); $errmsg[] = $um->get_errors(); } //show messages show_error($errmsg, false); } else { show_error($errmsg); } } ?> <h1><?php echo __('Archivos adjuntos de la propuesta'); ?> </h1> <?php
function upload_foaf() { global $data, $CFG; $action = optional_param('action'); if (!empty($action) && $action == "profile:foaf:upload" && logged_on && run("permissions:check", "profile")) { require_once $CFG->dirroot . 'lib/uploadlib.php'; $um = new upload_manager('foaf_file', false, true, 0, true); $dir = $CFG->dataroot . 'tmp/foaf/'; if (!$um->process_file_uploads($dir)) { $messages[] = gettext("There was an error uploading the file. Possibly the file was too large, or the upload was interrupted."); $messages[] = $um->get_errors(); return false; } $file = $um->get_new_filepath(); $foaf = @GetXMLTreeProfile($file); $data['profile:preload'] = array(); if (isset($foaf['RDF:RDF'][0]['PERSON'][0]) && !isset($foaf['RDF:RDF'][0]['FOAF:PERSON'][0])) { $foaf['RDF:RDF'][0]['FOAF:PERSON'][0] = $foaf['RDF:RDF'][0]['PERSON'][0]; } if (isset($foaf['RDF:RDF'][0]['FOAF:PERSON'][0])) { $foaf = $foaf['RDF:RDF'][0]['FOAF:PERSON'][0]; if (!empty($data['foaf:profile']) && sizeof($data['foaf:profile']) > 0) { foreach ($data['foaf:profile'] as $foaf_element) { $profile_value = addslashes($foaf_element[0]); $foaf_name = $foaf_element[1]; $individual = $foaf_element[2]; $resource = $foaf_element[3]; if (isset($foaf[strtoupper($foaf_name)])) { $values = $foaf[strtoupper($foaf_name)]; foreach ($values as $value) { $thisvalue = ""; if (trim($value['VALUE']) != "") { $thisvalue = trim($value['VALUE']); } else { if (isset($value['ATTRIBUTES']['DC:TITLE']) && trim($value['ATTRIBUTES']['DC:TITLE'] != "")) { $thisvalue = trim($value['ATTRIBUTES']['DC:TITLE']); } else { if (isset($value['ATTRIBUTES']['RDF:RESOURCE']) && trim($value['ATTRIBUTES']['RDF:RESOURCE'] != "")) { $thisvalue = trim($value['ATTRIBUTES']['RDF:RESOURCE']); } } } if ($thisvalue != "") { if (!isset($data['profile:preload'][$profile_value])) { $data['profile:preload'][$profile_value] = $thisvalue; } else { $data['profile:preload'][$profile_value] .= ", " . $thisvalue; } } } } } } if (!empty($foaf['VCARD:ADR']) && sizeof($foaf['VCARD:ADR']) > 0) { if (!empty($data['vcard:profile:adr']) && sizeof($data['vcard:profile:adr']) > 0) { $foaf = $foaf['VCARD:ADR'][0]; foreach ($data['vcard:profile:adr'] as $foaf_element) { $profile_value = addslashes($foaf_element[0]); $foaf_name = $foaf_element[1]; $individual = $foaf_element[2]; $resource = $foaf_element[3]; if (isset($foaf[strtoupper($foaf_name)])) { $values = $foaf[strtoupper($foaf_name)]; foreach ($values as $value) { $thisvalue = ""; if (trim($value['VALUE']) != "") { $thisvalue = trim($value['VALUE']); } else { if (isset($value['ATTRIBUTES']['DC:TITLE']) && trim($value['ATTRIBUTES']['DC:TITLE'] != "")) { $thisvalue = trim($value['ATTRIBUTES']['DC:TITLE']); } else { if (isset($value['ATTRIBUTES']['RDF:RESOURCE']) && trim($value['ATTRIBUTES']['RDF:RESOURECE'] != "")) { $thisvalue = trim($value['ATTRIBUTES']['DC:TITLE']); } } } if ($thisvalue != "") { if (!isset($data['profile:preload'][$profile_value])) { $data['profile:preload'][$profile_value] = $thisvalue; } else { $data['profile:preload'][$profile_value] .= ", " . $thisvalue; } } } } } } } $messages[] = gettext("Data from your FOAF file has been preloaded. You must click Save at the bottom of the page for the changes to take effect."); } else { $messages[] = gettext("Error: supplied file did not appear to be a FOAF file."); } } return true; }
/** * Team members should have same files in their folder. * This method will handle the team submission files. */ function upload_file() { global $CFG, $USER; $mode = optional_param('mode', '', PARAM_ALPHA); $offset = optional_param('offset', 0, PARAM_INT); $teamid = optional_param('teamid', '', PARAM_INT); $returnurl = 'view.php?id=' . $this->cm->id; $submission = $this->get_submission($USER->id); if (!$this->can_upload_file($submission, $teamid) || !confirm_sesskey()) { $this->view_header(get_string('upload')); notify(get_string('uploaderror', 'assignment')); print_continue($returnurl); $this->view_footer(); die; } //team can not be empty $members = $this->get_members_from_team($teamid); if ($members && is_array($members)) { require_once $CFG->dirroot . '/lib/uploadlib.php'; $currenttime = time(); $um = new upload_manager('newfile', false, true, $this->course, false, $this->assignment->maxbytes, true); $dir = $this->team_file_area_name($teamid); check_dir_exists($CFG->dataroot . '/' . $dir, true, true); if ($um->process_file_uploads($dir)) { // if file was uploaded successfully, update members' assignment_submission records. foreach ($members as $member) { //update all team members's assignment_submission records. $submission = $this->get_submission($member->student, true); //create new submission if needed $updated = new object(); $updated->id = $submission->id; $updated->timemodified = $currenttime; if (update_record('assignment_submissions', $updated)) { add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id); $submission = $this->get_submission($member->student); $this->update_grade($submission); if (!$this->drafts_tracked()) { $this->email_teachers($submission); } } else { $new_filename = $um->get_new_filename(); $this->view_header(get_string('upload')); notify(get_string('uploadnotregistered', 'assignment', $new_filename)); print_continue($returnurl); $this->view_footer(); die; } } // Start Optional Turnitin code // $plagiarismvalues = get_records_menu('plagiarism_config', 'cm',$this->cm->id,'','name,value'); // if (!empty($plagiarismvalues['use_turnitin']) && // (empty($this->assignment->tii_draft_submit) or !$this->drafts_tracked()) ) { // if ($tii_file = get_record_select('tii_files', "course='".$this->course->id. // "' AND module='".$this->cm->module. // "' AND instance='".$this->assignment->id. // "' AND userid = '".$USER->id. // "' AND filename = '".$um->get_new_filename()."'")) { //update record. // $tii_file->tiicode = 'pending'; // $tii_file->tiiscore ='0'; // if (!update_record('tii_files', $tii_file)) { // debugging("update tii_files failed!"); // } // } else { // $tii_file = new object(); // $tii_file->course = $this->course->id; // $tii_file->module = $this->cm->module; // $tii_file->instance = $this->assignment->id; // $tii_file->userid = $USER->id; // $tii_file->filename = $um->get_new_filename(); // $tii_file->tiicode = 'pending'; // if (!insert_record('tii_files', $tii_file)) { // debugging("insert into tii_files failed"); // } // } // } // End Optional Turnitin code } else { $this->view_header(get_string('upload')); notify('upload process fail'); print_continue($returnurl); $this->view_footer(); } redirect('view.php?id=' . $this->cm->id); } $this->view_header(get_string('upload')); notify(get_string('uploaderror', 'assignment')); echo $um->get_errors(); print_continue($returnurl); $this->view_footer(); die; }
function upload_file() { global $CFG, $USER; $mode = optional_param('mode', '', PARAM_ALPHA); $offset = optional_param('offset', 0, PARAM_INT); $returnurl = 'view.php?id=' . $this->cm->id; $status = false; // Indicated whether the file was successfully moved or not. $form = new backpack_form(); // Make sure that data was returned from the form. if (!($data = $form->get_data())) { $data = $form->get_submitted_data(); } $dir = $this->file_area_name($USER->id); check_dir_exists($CFG->dataroot . '/' . $dir, true, true); // better to create now so that student submissions do not block it later $filecount = $this->count_user_files($USER->id); $submission = $this->get_submission($USER->id); // Ensure that this user can actually submit a file to this assignment or not. if (!$this->can_upload_file($submission)) { $this->view_header(get_string('upload')); notify(get_string('uploaderror', 'assignment')); print_continue($returnurl); $this->view_footer(); die; } //obtain the repository object, if possible //(should be obtainable since the config has already been checked) $repo = $this->get_repository_object(); // If a repository file was chosen for upload if (!empty($data->alfrescoassignment) && isset($repo) && $repo->verify_setup() && $repo->is_configured()) { $file = $data->alfrescoassignment; // Get the UUID value from the repo file URL. if (preg_match('/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/', $file, $matches) > 0) { if (!empty($matches[0])) { $uuid = $matches[0]; $info = $repo->get_info($uuid); $status = $repo->copy_local($uuid, $info->title, $CFG->dataroot . '/' . $dir); } } // If a local file was chosen for upload } else { if (!empty($data->addfile)) { require_once $CFG->dirroot . '/lib/uploadlib.php'; $um = new upload_manager('localassignment', false, true, $this->course, false, $this->assignment->maxbytes, true); $status = $um->process_file_uploads($dir); } } if ($status) { $submission = $this->get_submission($USER->id, true); //create new submission if needed $updated = new stdClass(); $updated->id = $submission->id; $updated->timemodified = time(); if (update_record('assignment_submissions', $updated)) { add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id); $submission = $this->get_submission($USER->id); $this->update_grade($submission); if (!$this->drafts_tracked()) { $this->email_teachers($submission); } } else { $new_filename = $um->get_new_filename(); $this->view_header(get_string('upload')); notify(get_string('uploadnotregistered', 'assignment', $new_filename)); print_continue($returnurl); $this->view_footer(); die; } redirect('view.php?id=' . $this->cm->id); } $this->view_header(get_string('upload')); notify(get_string('uploaderror', 'assignment')); if (!empty($um)) { echo $um->get_errors(); } print_continue($returnurl); $this->view_footer(); die; }
/** * Team members should have same files in their folder. */ function upload_file() { global $CFG, $USER; error_log('upload_file method'); $mode = optional_param('mode', '', PARAM_ALPHA); $offset = optional_param('offset', 0, PARAM_INT); $teamid = optional_param('teamid', '', PARAM_INT); $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, $teamid)) { $this->view_header(get_string('upload')); notify(get_string('uploaderror', 'assignment')); print_continue($returnurl); $this->view_footer(); die; } //team can not be empty $members = $this->get_members_from_team($teamid); if ($members && is_array($members)) { require_once $CFG->dirroot . '/lib/uploadlib.php'; $currenttime = time(); $um = new upload_manager('newfile', false, true, $this->course, false, $this->assignment->maxbytes, true); $dir = $this->file_area_name($USER->id); check_dir_exists($CFG->dataroot . '/' . $dir, true, true); error_log('source dir :' . $dir); if ($um->process_file_uploads($dir)) { //copy this new file to other members dir //update members' assignment_submission records. $file = $um->get_new_filename(); foreach ($members as $member) { //save this file in other team members' file dir. if ($member->student != $USER->id) { //not process the file folder for itself $memberdir = $this->file_area_name($member->student); check_dir_exists($CFG->dataroot . '/' . $memberdir, true, true); error_log('member dir:' . $memberdir); $this->copy_file($USER->id, $file, $CFG->dataroot . '/' . $memberdir); } //update all team members's assignment_submission records. error_log('update member assignment submission'); $submission = $this->get_submission($member->student, true); //create new submission if needed $updated = new object(); $updated->id = $submission->id; $updated->timemodified = $currenttime; if (update_record('assignment_submissions', $updated)) { add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id); $submission = $this->get_submission($member->student); $this->update_grade($submission); if (!$this->drafts_tracked()) { $this->email_teachers($submission); } } else { $new_filename = $um->get_new_filename(); $this->view_header(get_string('upload')); notify(get_string('uploadnotregistered', 'assignment', $new_filename)); print_continue($returnurl); $this->view_footer(); die; } } } else { $this->view_header(get_string('upload')); notify('upload process fail'); print_continue($returnurl); $this->view_footer(); } redirect('view.php?id=' . $this->cm->id); } $this->view_header(get_string('upload')); notify(get_string('uploaderror', 'assignment')); echo $um->get_errors(); print_continue($returnurl); $this->view_footer(); die; }