コード例 #1
0
function moodle_binary_store_file(&$filename, &$id, &$meta, $ext = ".bin")
{
    # READ-Only
    global $_FILES, $CFG, $course, $wiki, $groupid, $userid, $ewiki_title, $cm;
    if (!$wiki->ewikiacceptbinary) {
        print_error('cannotacceptbin', 'wiki');
        return 0;
    }
    $entry = wiki_get_entry($wiki, $course, $userid, $groupid);
    if (!$entry->id) {
        print_error('cannotgetentry', 'wiki');
    }
    require_once $CFG->dirroot . '/lib/uploadlib.php';
    $um = new upload_manager('upload', false, false, $course, false, 0, true, true);
    if ($um->process_file_uploads("{$course->id}/{$CFG->moddata}/wiki/{$wiki->id}/{$entry->id}/{$ewiki_title}")) {
        $filename = '';
        // this to make sure we don't keep processing in the parent function
        if (!$id) {
            $newfilename = $um->get_new_filename();
            $id = EWIKI_IDF_INTERNAL . $newfilename;
        }
        return true;
    }
    print_error('uploaderror', 'wiki', '', $um->print_upload_log(true));
    return false;
}
コード例 #2
0
ファイル: lib.php プロジェクト: r007/PMoodle
/**
 *
 */
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;
}
コード例 #3
0
ファイル: lib.php プロジェクト: netspotau/moodle-mod_dialogue
/**
 * 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;
}
コード例 #4
0
 function _postprocess(&$resource)
 {
     global $RESOURCE_WINDOW_OPTIONS;
     global $COURSE, $CFG;
     // for file upload patch
     $alloptions = $RESOURCE_WINDOW_OPTIONS;
     if (!empty($resource->forcedownload)) {
         $resource->popup = '';
         $resource->options = 'forcedownload';
     } else {
         if ($resource->windowpopup) {
             $optionlist = array();
             foreach ($alloptions as $option) {
                 $optionlist[] = $option . "=" . $resource->{$option};
                 unset($resource->{$option});
             }
             $resource->popup = implode(',', $optionlist);
             unset($resource->windowpopup);
             $resource->options = '';
         } else {
             if (empty($resource->framepage)) {
                 $resource->options = '';
             } else {
                 switch ($resource->framepage) {
                     case 1:
                         $resource->options = 'frame';
                         break;
                     case 2:
                         $resource->options = 'objectframe';
                         break;
                     default:
                         $resource->options = '';
                         break;
                 }
             }
             unset($resource->framepage);
             $resource->popup = '';
         }
     }
     $optionlist = array();
     for ($i = 0; $i < $this->maxparameters; $i++) {
         $parametername = "parameter{$i}";
         $parsename = "parse{$i}";
         if (!empty($resource->{$parsename}) and $resource->{$parametername} != "-") {
             $optionlist[] = $resource->{$parametername} . "=" . $resource->{$parsename};
         }
         unset($resource->{$parsename});
         unset($resource->{$parametername});
     }
     $resource->alltext = implode(',', $optionlist);
     //	if ($fromform->type == 'fileupload') {
     // upload file to fixed pre-defined "/" folder
     require_once $CFG->dirroot . '/lib/uploadlib.php';
     if (!($basedir = make_upload_directory("{$COURSE->id}"))) {
         error("The site administrator needs to fix the file permissions");
     }
     $wdir = '/';
     $um = new upload_manager('userfile', false, false, $course, false, 0);
     $dir = "{$basedir}{$wdir}";
     if ($um->process_file_uploads($dir)) {
         notify(get_string('uploadedfile'));
     }
     $resource->reference = $um->files["userfile"]["name"];
     // end of upload code
     //	}
 }
コード例 #5
0
ファイル: field.class.php プロジェクト: nadavkav/MoodleTAO
 function update_content($recordid, $value, $name)
 {
     global $CFG;
     if (!($oldcontent = get_record('data_content', 'fieldid', $this->field->id, 'recordid', $recordid))) {
         // Quickly make one now!
         $oldcontent = new object();
         $oldcontent->fieldid = $this->field->id;
         $oldcontent->recordid = $recordid;
         if ($oldcontent->id = insert_record('data_content', $oldcontent)) {
             error('Could not make an empty record!');
         }
     }
     $content = new object();
     $content->id = $oldcontent->id;
     $names = explode('_', $name);
     switch ($names[2]) {
         case 'file':
             // file just uploaded
             #                $course = get_course('course', 'id', $this->data->course);
             $filename = $_FILES[$names[0] . '_' . $names[1]];
             $filename = $filename['name'];
             $dir = $this->data->course . '/' . $CFG->moddata . '/data/' . $this->data->id . '/' . $this->field->id . '/' . $recordid;
             // only use the manager if file is present, to avoid "are you sure you selected a file to upload" msg
             if ($filename) {
                 require_once $CFG->libdir . '/uploadlib.php';
                 // FIX ME: $course not defined here
                 $um = new upload_manager($names[0] . '_' . $names[1], true, false, $this->data->course, false, $this->field->param3);
                 if ($um->process_file_uploads($dir)) {
                     $newfile_name = $um->get_new_filename();
                     $content->content = $newfile_name;
                     update_record('data_content', $content);
                 }
             }
             break;
         case 'filename':
             // only changing alt tag
             $content->content1 = clean_param($value, PARAM_NOTAGS);
             update_record('data_content', $content);
             break;
         default:
             break;
     }
 }
コード例 #6
0
 /**
  * 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;
 }
コード例 #7
0
        if ($item) {
            $template = get_record('assignment_uploadpdf_tmpl', 'id', $item->template);
            if ($template && $template->course == 0 && !$caneditsite) {
                error("No permission to edit site templates");
            }
            delete_records('assignment_uploadpdf_tmplitm', 'id', $itemid);
            $itemid = 0;
        }
    }
} elseif ($uploadpreview) {
    $partdest = $courseid . IMAGE_PATH;
    $fulldest = $CFG->dataroot . '/' . $partdest;
    check_dir_exists($fulldest);
    require_once $CFG->dirroot . '/lib/uploadlib.php';
    $um = new upload_manager('preview', false, false, $course, false, 0, true);
    if ($um->process_file_uploads($partdest)) {
        $fp = $um->get_new_filepath();
        $fn = $um->get_new_filename();
        require_once 'mypdflib.php';
        $pdf = new MyPDFLib();
        $pdf->load_pdf($fp);
        $pdf->set_image_folder($fulldest);
        $imagename = $pdf->get_image(1);
        unlink($fp);
    } else {
        //echo 'No file uploaded';
        //die;
    }
} elseif ($duplicatetemplate) {
    // Should not have access to the 'duplicate' button unless a template is selected
    // but, just in case, we check here (but just do nothing if that is not the case)
コード例 #8
0
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/lightboxgallery:addimage', $context);
$galleryurl = $CFG->wwwroot . '/mod/lightboxgallery/view.php?id=' . $cm->id;
$straddimage = get_string('addimage', 'lightboxgallery');
$navigation = build_navigation($straddimage, $cm);
print_header($course->shortname . ': ' . $gallery->name . ': ' . $straddimage, $course->fullname, $navigation, '', '', true, '&nbsp;', navmenu($course, $cm));
$mform = new mod_lightboxgallery_imageadd_form(null, $gallery);
if ($mform->is_cancelled()) {
    redirect($galleryurl);
} else {
    if (($formdata = $mform->get_data()) && confirm_sesskey()) {
        require_once $CFG->dirroot . '/lib/uploadlib.php';
        $handlecollisions = !get_config('lightboxgallery', 'overwritefiles');
        $um = new upload_manager('attachment', false, $handlecollisions, $course);
        $uploaddir = $course->id . '/' . $gallery->folder;
        if ($um->process_file_uploads($uploaddir)) {
            $folder = $CFG->dataroot . '/' . $uploaddir;
            $filename = $um->get_new_filename();
            $messages = array();
            if (lightboxgallery_get_file_extension($filename) == 'zip') {
                $thumb = '<img src="' . $CFG->pixpath . '/f/zip.gif" class="icon" alt="zip" />';
                $before = lightboxgallery_directory_images($folder);
                if (unzip_file($folder . '/' . $filename, $folder, false)) {
                    $messages[] = get_string('zipextracted', 'lightboxgallery', $filename);
                    $after = lightboxgallery_directory_images($folder);
                    if ($newfiles = array_diff($after, $before)) {
                        $resizeoption = 0;
                        if (in_array($gallery->autoresize, array(AUTO_RESIZE_UPLOAD, AUTO_RESIZE_BOTH))) {
                            $resizeoption = $gallery->resize;
                        } else {
                            if (isset($formdata->resize)) {
コード例 #9
0
ファイル: lib.php プロジェクト: rrusso/EARS
 function process_attachment($course = null)
 {
     if (!$course) {
         $course = get_record('course', 'id', $this->courseid);
     }
     $rtn = array();
     $um = new upload_manager('attach', false, true, $course, false, 0, true);
     if ($um->process_file_uploads('temp/block_student_gradeviewer')) {
         $rtn[] = $um->get_new_filename();
         $rtn[] = 'temp/block_student_gradeviewer/' . $um->get_new_filename();
     } else {
         $rtn = array('', '');
     }
     return $rtn;
 }
コード例 #10
0
ファイル: profile.class.php プロジェクト: pzingg/saugus_elgg
 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;
 }
コード例 #11
0
 function upload_team_responsefile()
 {
     global $CFG;
     $teamid = required_param('teamid', PARAM_INT);
     $userrep = required_param('userrep', PARAM_INT);
     $mode = required_param('mode', PARAM_ALPHA);
     $id = required_param('id', PARAM_INT);
     $teammembers = $this->get_members_from_team($teamid);
     if ($teammembers) {
         $returnurl = "submissions.php?id={$id}&amp;teamid={$teamid}&amp;userrep={$userrep}&amp;mode={$mode}";
         if (data_submitted('nomatch') and $this->can_manage_responsefiles()) {
             //team responses folder dirs
             $teamdir = $this->team_file_area_name($teamid) . '/responses';
             check_dir_exists($CFG->dataroot . '/' . $teamdir, true, true);
             require_once $CFG->dirroot . '/lib/uploadlib.php';
             $um = new upload_manager('newfile', false, true, $this->course, false, 0, true);
             if (!$um->process_file_uploads($teamdir)) {
                 print_error('uploaderror', 'assignment', $returnurl);
             }
         }
         redirect($returnurl);
     }
 }
コード例 #12
0
 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;
 }
コード例 #13
0
 function upload()
 {
     global $CFG, $USER;
     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) {
                 notify(get_string('alreadygraded', 'assignment'));
             }
         }
         $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->process_file_uploads($dir) and confirm_sesskey()) {
             $newfile_name = $um->get_new_filename();
             if ($submission) {
                 $submission->timemodified = time();
                 $submission->numfiles = 1;
                 $submission->submissioncomment = addslashes($submission->submissioncomment);
                 unset($submission->data1);
                 // Don't need to update this.
                 unset($submission->data2);
                 // Don't need to update this.
                 if (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);
                     $submission = $this->get_submission($USER->id);
                     $this->update_grade($submission);
                     $this->email_teachers($submission);
                     print_heading(get_string('uploadedfile'));
                 } else {
                     notify(get_string("uploadfailnoupdate", "assignment"));
                 }
             } else {
                 $newsubmission = $this->prepare_new_submission($USER->id);
                 $newsubmission->timemodified = time();
                 $newsubmission->numfiles = 1;
                 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);
                     $submission = $this->get_submission($USER->id);
                     $this->update_grade($submission);
                     $this->email_teachers($newsubmission);
                     print_heading(get_string('uploadedfile'));
                 } else {
                     notify(get_string("uploadnotregistered", "assignment", $newfile_name));
                 }
             }
         }
     } else {
         notify(get_string("uploaderror", "assignment"));
         //submitting not allowed!
     }
     print_continue('view.php?id=' . $this->cm->id);
     $this->view_footer();
 }
コード例 #14
0
 function upload()
 {
     global $CFG, $USER;
     require_capability('mod/assignment:submit', get_context_instance(CONTEXT_MODULE, $this->cm->id));
     // $this->view_header(get_string('upload'));
     echo "<center>";
     $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) {
                 notify(get_string('alreadygraded', 'assignment'));
             }
         }
         $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->process_file_uploads($dir)) {
             $newfile_name = $um->get_new_filename();
             if ($submission) {
                 $submission->timemodified = time();
                 $submission->numfiles = 1;
                 $submission->submissioncomment = addslashes($submission->submissioncomment);
                 unset($submission->data1);
                 // Don't need to update this.
                 unset($submission->data2);
                 // Don't need to update this.
                 if (update_record("assignment_submissions", $submission)) {
                     add_to_log($this->course->id, 'assignment', 'upload', 'view-embedded.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
                     $submission = $this->get_submission($USER->id);
                     $this->update_grade($submission);
                     $this->email_teachers($submission);
                     echo "Hands-on exams will be graded within 10 business days. Results will be provided via email. If you do not receive your results within 10 business days of submitting your answer file, please open a ticket with Kaseya University at helpdesk.kaseya.com.";
                     print_heading(get_string('uploadedfile'));
                 } else {
                     notify(get_string("uploadfailnoupdate", "assignment"));
                 }
             } else {
                 $newsubmission = $this->prepare_new_submission($USER->id);
                 $newsubmission->timemodified = time();
                 $newsubmission->numfiles = 1;
                 if (insert_record('assignment_submissions', $newsubmission)) {
                     add_to_log($this->course->id, 'assignment', 'upload', 'view-embedded.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
                     $submission = $this->get_submission($USER->id);
                     $this->update_grade($submission);
                     $this->email_teachers($newsubmission);
                     print_heading(get_string('uploadedfile'));
                 } else {
                     notify(get_string("uploadnotregistered", "assignment", $newfile_name));
                 }
             }
         }
     } else {
         notify(get_string("uploaderror", "assignment"));
         //submitting not allowed!
     }
     print_continue('view-embedded.php?id=' . $this->cm->id);
     echo "</center>";
     // $this->view_footer();
 }
コード例 #15
0
ファイル: email.class.php プロジェクト: henriquecrang/e-UNI
 /**
  * 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;
 }
コード例 #16
0
 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;
 }
コード例 #17
0
ファイル: lib.php プロジェクト: BackupTheBerlios/tulipan-svn
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;
}
コード例 #18
0
ファイル: email.php プロジェクト: henriquecrang/e-UNI
     $form->attachment = trim($form->attachment);
     if (isset($form->attachment) and !empty($form->attachment)) {
         $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
     }
コード例 #19
0
    echo 'ng';
}
// セクションデータを取得
if (!($section = get_record("course_sections", "id", $sectionid))) {
    echo 'ng';
}
// 保存するディレクトリの取得
if (!($basedir = make_upload_directory($course->id))) {
    echo 'ng';
}
// ファイルのアップロード処理
$course->maxbytes = 0;
// We are ignoring course limits
$um = new upload_manager('Filedata', false, false, $course, false, 0);
$dir = "{$basedir}/{$sectiontitle->directoryname}";
if (!$um->process_file_uploads($dir)) {
    echo 'ng';
}
// セクションにファイルを登録
if ($isregister) {
    // モジュールを追加する
    if (!($module = get_record("modules", "name", 'resource'))) {
        echo 'ng';
    }
    //$context = get_context_instance(CONTEXT_COURSE, $course->id);
    //require_capability('moodle/course:manageactivities', $context);
    //require_login($course->id); // needed to setup proper $COURSE
    // resourceモジュールを読み込む
    require_once "{$CFG->dirroot}/mod/resource/mod_form.php";
    include_once "{$CFG->dirroot}/mod/resource/lib.php";
    //
コード例 #20
0
     $numicons = count_records('icons', 'owner', $page_owner);
     if ($numicons >= $_SESSION['icon_quota']) {
         $ok = false;
         $messages[] = gettext("You have already met your icon quota. You must delete some icons before you can upload any new ones.");
     }
 }
 require_once $CFG->dirroot . 'lib/uploadlib.php';
 // TODO passing 0 as maxbytes here as icon_quota is based on number of icons
 // so upload_manager will look at PHP settings instead.
 // not ideal but as good as it can be for the now.
 $um = new upload_manager('iconfile', false, true, false, 0, true);
 $messages[] = gettext("Attempting to upload icon file ...");
 $ul_username = run("users:id_to_name", $page_owner);
 $upload_folder = $textlib->substr($ul_username, 0, 1);
 $dir = $CFG->dataroot . "icons/" . $upload_folder . "/" . $ul_username . "/";
 if ($ok = $um->process_file_uploads($dir)) {
     if (!($imageattr = @getimagesize($um->get_new_filepath()))) {
         $ok = false;
         $messages[] = gettext("The uploaded icon file was invalid. Please ensure you are using JPEG, GIF or PNG files.");
     }
 }
 if ($ok == true) {
     if ($imageattr[0] > 100 || $imageattr[1] > 100) {
         // $ok = false;
         // $messages[] = gettext("The uploaded icon file was too large. Files must have maximum dimensions of 100x100.");
         require_once $CFG->dirroot . 'lib/iconslib.php';
         $phpThumb = new phpThumb();
         // import default config
         if (!empty($PHPTHUMB_CONFIG)) {
             foreach ($PHPTHUMB_CONFIG as $key => $value) {
                 $keyname = 'config_' . $key;
コード例 #21
0
ファイル: compose.php プロジェクト: henriquecrang/e-UNI
         $newmessage->archivo = "";
     }
 }
 $newmessage->leido = 1;
 $newmessage->responded = 0;
 $newmessage->borrado = 0;
 $newmessage->timemodified = time();
 if (!($newmessageid = insert_record('mail_messages', $newmessage))) {
     error('Could not create new message');
 } else {
     add_to_log($course->id, "mail", "send message", "compose.php?id={$cm->id}", $mail->id, $cm->id);
 }
 if (!empty($_FILES['newfile']['name'])) {
     if ($basedir = file_area($course->id, $mail->id, $newmessageid)) {
         $filearea = file_area_name($course->id, $mail->id, $newmessageid);
         if (!($res = $um->process_file_uploads($filearea))) {
             //borrar el mensaje insertado
             delete_records('mail_messages', 'id', $newmessageid);
             error(get_string("filenotvalid", "mail"));
         } else {
             $updatemessage = new object();
             $updatemessage->id = $newmessageid;
             $updatemessage->archivo = $um->get_new_filename();
             $_FILES['newfile']['name'] = $um->get_new_filename();
             update_record('mail_messages', $updatemessage);
         }
     } else {
         error(get_string("filenotvalid", "mail"));
     }
 }
 if ($forward and !empty($message->archivo)) {