function gwfontform_validate(Pieform $form, $values)
{
    global $USER, $SESSION;
    require_once 'file.php';
    require_once 'uploadmanager.php';
    $valid = false;
    if ($values['gwfzipfile'] != null) {
        $filetype = $values['gwfzipfile']['type'];
        // Ensures that the correct file was chosen
        $accepted = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/s-compressed');
        foreach ($accepted as $mimetype) {
            if ($mimetype == $filetype) {
                $valid = true;
                break;
            }
        }
        // Safari and Chrome don't register zip mime types. Something better could be used here.
        // Check if file extension, that is the last 4 characters in file name, equals '.zip'...
        $valid = substr($values['gwfzipfile']['name'], -4) == '.zip' ? true : false;
        if (!$valid) {
            $form->set_error('gwfzipfile', get_string('notvalidzipfile', 'skin'));
        }
        // pass it through the virus checker
        $um = new upload_manager('gwfzipfile');
        if ($error = $um->preprocess_file()) {
            $form->set_error($inputname, $error);
        }
    }
}
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;
}
function addvariantform_validate(Pieform $form, $values)
{
    global $USER, $SESSION;
    require_once 'file.php';
    require_once 'uploadmanager.php';
    // Make sure they didn't hack the hidden variable to have the name of
    // a font that doesn't exist
    if (!record_exists('skin_fonts', 'name', $values['fontname'])) {
        $form->set_error('fontname', get_string('nosuchfont', 'skin'));
    }
    $uploadfiles = array('fontfileEOT' => array('required' => true, 'suffix' => 'eot'), 'fontfileSVG' => array('required' => true, 'suffix' => 'svg'), 'fontfileTTF' => array('required' => true, 'suffix' => 'ttf'), 'fontfileWOFF' => array('required' => true, 'suffix' => 'woff'));
    foreach ($uploadfiles as $inputname => $details) {
        $um = new upload_manager($inputname, false, null, $details['required']);
        if ($error = $um->preprocess_file()) {
            $form->set_error($inputname, $error);
        }
        if ($details['suffix']) {
            $reqext = ".{$details['suffix']}";
            $fileext = substr($values[$inputname]['name'], -1 * strlen($reqext));
            if ($fileext != $reqext) {
                $form->set_error($inputname, get_string('notvalidfontfile', 'skin', strtoupper($details['suffix'])));
            }
        }
    }
}
function wiki_upload_deldir(&$WS)
{
    //cheack if the folder exists
    if (file_exists($WS->dfdir->name)) {
        //delete all folder files
        $upd = new upload_manager();
        $upd->delete_other_files($WS->dfdir->name);
        rmdir($WS->dfdir->name);
        return true;
    } else {
        return true;
    }
}
Exemple #5
0
function importskinform_validate(Pieform $form, $values)
{
    global $USER, $SESSION;
    $filetype = $values['file']['type'];
    if (!$filetype || $filetype != 'text/xml') {
        $form->set_error('file', get_string('notvalidxmlfile', 'skin'));
    }
    require_once 'file.php';
    require_once 'uploadmanager.php';
    $um = new upload_manager('file');
    if ($error = $um->preprocess_file()) {
        $form->set_error('file', $error);
    }
}
/**
 * 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');
}
}
require_login($course->id);
$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, ' ', 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;
Exemple #8
0
    if (!has_capability('mod/data:manageentries', $context) or !data_isowner($rid) or !confirm_sesskey()) {
        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);
 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;
 }
        foreach ($submissions as $submission) {
            if ($submission->timecreated > $timenow - $CFG->maxeditingtime) {
                // ignore this submission
                redirect("view.php?id={$cm->id}");
                print_footer($course);
                exit;
            }
        }
    }
}
// check existence of title
if ($title == '') {
    notify(get_string("notitlegiven", "exercise"));
} else {
    require_once $CFG->dirroot . '/lib/uploadlib.php';
    $um = new upload_manager('newfile', false, false, $course, false, $exercise->maxbytes);
    if ($um->preprocess_files()) {
        $newsubmission->exerciseid = $exercise->id;
        if (isteacher($course->id)) {
            // it's an exercise submission, flag it as such
            $newsubmission->userid = 0;
            $newsubmission->isexercise = 1;
            // it's a description of an exercise
        } else {
            $newsubmission->userid = $USER->id;
        }
        $newsubmission->title = $title;
        $newsubmission->timecreated = $timenow;
        if ($timenow > $exercise->deadline) {
            $newsubmission->late = 1;
        }
Exemple #11
0
 if (empty($copyright)) {
     $redirect_url = url . $USER->username . "/files/";
     if ($folderid > -1) {
         $redirect_url .= $folderid;
     }
     define('redirect_url', $redirect_url);
     $messages[] = gettext("Upload unsuccessful. You must check the copyright box for a file to be uploaded.");
     break;
 }
 $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;
 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();
 }
    //Check proposal owner
    $proposal = get_proposal($proposal_id, $USER->id);
} elseif (Context == 'admin') {
    preg_match('#^admin/proposals/(\\d+)/files#', $q, $matches);
    $proposal_id = !empty($matches) ? (int) $matches[1] : 0;
    $proposal = get_proposal($proposal_id);
}
require $CFG->comdir . 'prop_files_optional_params.php';
//check owner and status, dont delete acepted, scheduled or deleted¿?
// can delete canceled proposal
if (!empty($proposal) && ($proposal->id_status < 5 || ($proposal->id_status = 6))) {
    if (!empty($submit)) {
        if (empty($errmsg)) {
            //upload manager
            require_once $CFG->incdir . 'uploadlib.php';
            $um = new upload_manager('S_filename', false, true);
            $uploaddir = 'proposals/' . $proposal->id;
            if ($um->process_file_uploads($uploaddir)) {
                $f = new StdClass();
                $f->id_propuesta = $proposal->id;
                $f->name = $filename;
                $f->title = $title;
                $f->descr = $descr;
                $f->public = $public;
                $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();
Exemple #14
0
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;
}
 $description = optional_param('icondescription');
 $icondefault = optional_param('icondefault');
 // if (!empty($description)) {
 $ok = true;
 if ($ok == true) {
     $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';
Exemple #16
0
/**
 * 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;
}
Exemple #17
0
                    $newassessment = workshop_copy_assessment($assessment, $newsubmission, true);
                    // set the resubmission flag so student can be emailed/told about
                    // this assessment
                    set_field("workshop_assessments", "resubmission", 1, "id", $newassessment->id);
                }
            } else {
                // a hot assessment, was not used, just dump it
                delete_records("workshop_assessments", "id", $assessment->id);
            }
        }
    }
    add_to_log($course->id, "workshop", "resubmit", "view.php?id={$cm->id}", "{$workshop->id}", "{$cm->id}");
}
// do something about the attachments, if there are any
if ($workshop->nattachments) {
    require_once $CFG->dirroot . '/lib/uploadlib.php';
    $um = new upload_manager(null, false, false, $course, false, $workshop->maxbytes);
    if ($um->preprocess_files()) {
        $dir = workshop_file_area_name($workshop, $newsubmission);
        if ($um->save_files($dir)) {
            print_heading(get_string("uploadsuccess", "workshop"));
        }
        // um will take care of printing errors.
    }
}
if (!$workshop->nattachments) {
    print_heading(get_string("submitted", "workshop") . " " . get_string("ok"));
}
add_to_log($course->id, "workshop", "submit", "view.php?id={$cm->id}", "{$workshop->id}", "{$cm->id}");
print_continue("view.php?id={$cm->id}");
print_footer($course);
 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
     //	}
 }
Exemple #19
0
 /**
  * Processes a newly uploaded file, copies it to disk, and creates
  * a new artefact object.
  * Takes the name of a file input.
  * Returns false for no errors, or a string describing the error.
  */
 public static function save_uploaded_file($inputname, $data)
 {
     require_once 'uploadmanager.php';
     $um = new upload_manager($inputname);
     if ($error = $um->preprocess_file()) {
         throw new UploadException($error);
     }
     $size = $um->file['size'];
     if (!empty($data->owner)) {
         global $USER;
         if ($data->owner == $USER->get('id')) {
             $owner = $USER;
         } else {
             $owner = new User();
             $owner->find_by_id($data->owner);
         }
         if (!$owner->quota_allowed($size)) {
             throw new QuotaExceededException(get_string('uploadexceedsquota', 'artefact.file'));
         }
     }
     $data->size = $size;
     $data->filetype = $um->file['type'];
     $data->oldextension = $um->original_filename_extension();
     $f = self::new_file($um->file['tmp_name'], $data);
     $f->commit();
     $id = $f->get('id');
     // Save the file using its id as the filename, and use its id modulo
     // the number of subdirectories as the directory name.
     if ($error = $um->save_file(self::get_file_directory($id), $id)) {
         $f->delete();
         throw new UploadException($error);
     } else {
         if ($owner) {
             $owner->quota_add($size);
             $owner->commit();
         }
     }
     return $id;
 }
Exemple #20
0
 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;
     }
 }
Exemple #21
0
 $attachment = $attachname = '';
 if (has_capability('moodle/course:managefiles', $context)) {
     $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 = '';
Exemple #22
0
 /**
  * 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;
 }
Exemple #23
0
/**
 *
 */
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;
}
Exemple #24
0
function add_feedback_form_submit(Pieform $form, $values)
{
    global $view, $artefact, $USER;
    $data = new StdClass();
    $data->view = $view->get('id');
    if ($artefact) {
        $data->artefact = $artefact->get('id');
        $table = 'artefact_feedback';
    } else {
        $table = 'view_feedback';
    }
    $data->message = $values['message'];
    $data->public = (int) $values['ispublic'];
    $data->author = $USER->get('id');
    if (!$data->author) {
        unset($data->author);
        $data->authorname = $values['authorname'];
    }
    $data->ctime = db_format_timestamp(time());
    db_begin();
    if (is_array($values['attachment'])) {
        require_once get_config('libroot') . 'group.php';
        require_once get_config('libroot') . 'uploadmanager.php';
        safe_require('artefact', 'file');
        $groupid = $view->get('submittedgroup');
        if (group_user_can_assess_submitted_views($groupid, $USER->get('id'))) {
            $um = new upload_manager('attachment');
            if ($error = $um->preprocess_file()) {
                throw new UploadException($error);
            }
            $owner = $view->get('owner');
            $ownerlang = get_user_language($owner);
            $folderid = ArtefactTypeFolder::get_folder_id(get_string_from_language($ownerlang, 'feedbackattachdirname', 'view'), get_string_from_language($ownerlang, 'feedbackattachdirdesc', 'view'), null, true, $owner);
            $attachment = (object) array('owner' => $owner, 'parent' => $folderid, 'title' => ArtefactTypeFileBase::get_new_file_title($values['attachment']['name'], $folderid, $owner), 'size' => $values['attachment']['size'], 'filetype' => $values['attachment']['type'], 'oldextensin' => $um->original_filename_extension(), 'description' => get_string_from_language($ownerlang, 'feedbackonviewbytutorofgroup', 'view', $view->get('title'), display_name($USER), get_field('group', 'name', 'id', $groupid)));
            try {
                $data->attachment = ArtefactTypeFile::save_uploaded_file('attachment', $attachment);
            } catch (QuotaExceededException $e) {
            }
        }
    }
    insert_record($table, $data, 'id', true);
    require_once 'activity.php';
    unset($data->id);
    activity_occurred('feedback', $data);
    db_commit();
    if ($artefact) {
        $goto = get_config('wwwroot') . 'view/artefact.php?artefact=' . $artefact->get('id') . '&view=' . $view->get('id');
    } else {
        $goto = get_config('wwwroot') . 'view/view.php?id=' . $view->get('id');
    }
    $form->reply(PIEFORM_OK, array('message' => get_string('feedbacksubmitted', 'view'), 'goto' => $goto));
}
Exemple #25
0
/**
 * 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;
}
 /**
  * If we're only handling one file (if inputname was given in the constructor)
  * this will return the (possibly changed) filename of the file.
  * @return mixed false in case of failure, string if ok
  */
 function get_new_filename()
 {
     return $this->_upload_manager->get_new_filename();
 }
Exemple #27
0
        <?php 
}
if (!($basedir = make_upload_directory("{$course->id}"))) {
    error("The site administrator needs to fix the file permissions");
}
$baseweb = $CFG->wwwroot;
//  End of configuration and access control
if ($wdir == '') {
    $wdir = '/';
}
switch ($action) {
    case "upload":
        html_header($course, $wdir);
        require_once $CFG->dirroot . '/lib/uploadlib.php';
        if ($save and confirm_sesskey()) {
            $um = new upload_manager('userfile', false, false, $course, false, 0);
            $dir = "{$basedir}{$wdir}";
            if ($um->process_file_uploads($dir)) {
                notify(get_string('uploadedfile'));
            }
            // um will take care of error reporting.
            displaydir($wdir);
        } else {
            $upload_max_filesize = get_max_upload_file_size($CFG->maxbytes);
            $filesize = display_size($upload_max_filesize);
            $struploadafile = get_string("uploadafile");
            $struploadthisfile = get_string("uploadthisfile");
            $strmaxsize = get_string("maxsize", "", $filesize);
            $strcancel = get_string("cancel");
            echo "<p>{$struploadafile} ({$strmaxsize}) --> <strong>{$wdir}</strong>";
            echo "<table border=\"0\"><tr><td colspan=\"2\">\n";
 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();
 }
$csv_encode = '/\\&\\#44/';
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);
if (!$wdir) {
    $wdir = "/";
}
if ($wdir != '/' and detect_munged_arguments($wdir, 0) or $file != '' and detect_munged_arguments($file, 0)) {
    $message = "Error: Directories can not contain \"..\"";
    $wdir = "/";
    $action = "";
}
// ARRRGHHHH &%¤%¤%?###
$CFG->framename = 'ibrowser';
switch ($action) {
    case "upload":
        html_header($course, $wdir);
        require_once $CFG->dirroot . '/lib/uploadlib.php';
        if (!empty($save) and confirm_sesskey()) {
            $um = new upload_manager('userfile', false, false, $course, false, 0);
            $dir = "{$basedir}/tmp";
            if ($um->process_file_uploads($dir)) {
                // copy and resize file to its real
                // location and add info to database
                $image = new stdClass();
                $image->mimetype = $_FILES['userfile']['type'];
                $image->size = $_FILES['userfile']['size'];
                $image->name = $um->get_new_filename();
                $image->temp = "{$basedir}/tmp/" . $image->name;
                $image->info = getimagesize("{$basedir}/tmp/" . $image->name);
                $image->width = (int) $image->info[0];
                $image->height = (int) $image->info[1];
                $image->type = (int) $image->info[2];
                $image->course = (int) $course->id;
                $image->path = "netpublish_images/nbimg_" . time() . ".image";