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
 /**
  * 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();
 }
Пример #3
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;
}
Пример #4
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;
}
/**
* stores in database the element values
* @uses $CFG
* @param object $issue
*/
function tracker_recordelements(&$issue)
{
    global $CFG, $COURSE;
    $keys = array_keys($_POST);
    // get the key value of all the fields submitted
    $keys = preg_grep('/element./', $keys);
    // filter out only the element keys
    $filekeys = array_keys($_FILES);
    // get the key value of all the fields submitted
    $filekeys = preg_grep('/element./', $filekeys);
    // filter out only the element keys
    $keys = array_merge($keys, $filekeys);
    foreach ($keys as $key) {
        preg_match('/element(.*)$/', $key, $elementid);
        $elementname = $elementid[1];
        $sql = "\n            SELECT \n              e.id as elementid,\n              e.type as type\n            FROM\n                {$CFG->prefix}tracker_elementused eu,\n                {$CFG->prefix}tracker_element e\n            WHERE\n                eu.elementid = e.id AND\n                e.name = '{$elementname}' AND\n                eu.trackerid = {$issue->trackerid} \n        ";
        $attribute = get_record_sql($sql);
        $attribute->timemodified = $issue->datereported;
        $values = optional_param($key, '', PARAM_CLEANHTML);
        $attribute->issueid = $issue->id;
        $attribute->trackerid = $issue->trackerid;
        /// For those elements where more than one option can be selected
        if (is_array($values)) {
            foreach ($values as $value) {
                $attribute->elementitemid = $value;
                $attributeid = insert_record('tracker_issueattribute', $attribute);
                if (!$attributeid) {
                    error("Could not submit issue(s) attribute(s): issue:{$issue->id} issueid:{$elementid['1']} elementitemid:{$attribute->elementitemid}");
                }
            }
        } else {
            //For the rest of the elements that can only support one answer
            if ($attribute->type != 'file') {
                require_once $CFG->libdir . '/uploadlib.php';
                $attribute->elementitemid = $values;
                $attributeid = insert_record('tracker_issueattribute', $attribute);
            } else {
                $uploader = new upload_manager($key, false, false, $COURSE->id, true, 0, true);
                $uploader->preprocess_files();
                $newfilename = $uploader->get_new_filename();
                $encodedfilename = '';
                if (!empty($newfilename)) {
                    $encodedfilename = md5(time()) . '_' . $newfilename;
                    $storebase = "{$COURSE->id}/moddata/tracker/{$issue->trackerid}/{$issue->id}";
                    if (!filesystem_is_dir($storebase)) {
                        filesystem_create_dir($storebase, FS_RECURSIVE);
                    }
                    $uploader->save_files($storebase);
                    filesystem_move_file($storebase . '/' . $newfilename, $storebase . '/' . $encodedfilename);
                    $attribute->elementitemid = $encodedfilename;
                    $attributeid = insert_record('tracker_issueattribute', $attribute);
                }
            }
            if (empty($attributeid)) {
                error("Could not submit issue attribute: issue:{$issue->id} elementid:{$elementid['1']} elementitemid:{$attribute->elementitemid}");
            }
        }
    }
}
Пример #6
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;
 }
            notify(get_string("uploadnotregistered", "assignment", $newfile_name));
        }
    } else {
        // Process the resubmission
        $dir = $assignmentinstance->file_area_name($userid);
        require_once $CFG->dirroot . '/lib/uploadlib.php';
        $um = new upload_manager('newfile', true, false, $assignmentinstance->course, false, $assignmentinstance->assignment->maxbytes);
        if ($um->preprocess_files()) {
            //Check the file extension
            $submittedFilename = $um->get_original_filename();
            $extension = $assignmentinstance->assignment->fileextension;
            if (strtolower(substr($submittedFilename, strlen($submittedFilename) - strlen($extension))) != $extension) {
                notify(get_string("incorrectfileextension", "assignment_peerreview", $extension));
            } else {
                if ($um->save_files($dir)) {
                    $newfile_name = $um->get_new_filename();
                    $um->config->silent = true;
                    $um->delete_other_files($dir, $dir . '/' . $newfile_name);
                    $submission = $assignmentinstance->get_submission($userid);
                    if (set_field('assignment_submissions', 'timemodified', time(), 'id', $submission->id)) {
                        add_to_log($assignmentinstance->course->id, 'assignment', 'upload', 'view.php?a=' . $assignmentinstance->assignment->id, $assignmentinstance->assignment->id, $assignmentinstance->cm->id);
                        notify(get_string('resubmissionsuccessful', 'assignment_peerreview'), 'notifysuccess');
                    } else {
                        notify(get_string("uploadnotregistered", "assignment", $newfile_name));
                    }
                }
            }
        }
    }
    print_continue($CFG->wwwroot . '/mod/assignment/submissions.php?id=' . $assignmentinstance->cm->id);
} else {
Пример #8
0
        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;
        }
        if (!($newsubmission->id = insert_record("exercise_submissions", $newsubmission))) {
            error("exercise upload: Failure to create new submission record!");
        }
        $dir = exercise_file_area_name($exercise, $newsubmission);
        if ($um->save_files($dir)) {
            add_to_log($course->id, "exercise", "submit", "view.php?id={$cm->id}", "{$exercise->id}");
            print_heading(get_string("uploadsuccess", "assignment", $um->get_new_filename()));
        }
        // upload manager will print errors.
        // clear resubmit flags
        if (!set_field("exercise_submissions", "resubmit", 0, "exerciseid", $exercise->id, "userid", $USER->id)) {
            error("Exercise Upload: unable to reset resubmit flag");
        }
    }
    // upload manager will print errors.
}
print_continue("view.php?id={$cm->id}");
print_footer($course);
 /**
  * Team members should have same files in their  folder.
  * This method will handle the team submission files.
  */
 function upload_file()
 {
     global $CFG, $USER;
     $mode = optional_param('mode', '', PARAM_ALPHA);
     $offset = optional_param('offset', 0, PARAM_INT);
     $teamid = optional_param('teamid', '', PARAM_INT);
     $returnurl = 'view.php?id=' . $this->cm->id;
     $submission = $this->get_submission($USER->id);
     if (!$this->can_upload_file($submission, $teamid) || !confirm_sesskey()) {
         $this->view_header(get_string('upload'));
         notify(get_string('uploaderror', 'assignment'));
         print_continue($returnurl);
         $this->view_footer();
         die;
     }
     //team can not be empty
     $members = $this->get_members_from_team($teamid);
     if ($members && is_array($members)) {
         require_once $CFG->dirroot . '/lib/uploadlib.php';
         $currenttime = time();
         $um = new upload_manager('newfile', false, true, $this->course, false, $this->assignment->maxbytes, true);
         $dir = $this->team_file_area_name($teamid);
         check_dir_exists($CFG->dataroot . '/' . $dir, true, true);
         if ($um->process_file_uploads($dir)) {
             // if file was uploaded successfully, update members' assignment_submission records.
             foreach ($members as $member) {
                 //update all team members's assignment_submission records.
                 $submission = $this->get_submission($member->student, true);
                 //create new submission if needed
                 $updated = new object();
                 $updated->id = $submission->id;
                 $updated->timemodified = $currenttime;
                 if (update_record('assignment_submissions', $updated)) {
                     add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
                     $submission = $this->get_submission($member->student);
                     $this->update_grade($submission);
                     if (!$this->drafts_tracked()) {
                         $this->email_teachers($submission);
                     }
                 } else {
                     $new_filename = $um->get_new_filename();
                     $this->view_header(get_string('upload'));
                     notify(get_string('uploadnotregistered', 'assignment', $new_filename));
                     print_continue($returnurl);
                     $this->view_footer();
                     die;
                 }
             }
             // Start Optional Turnitin code
             //                       $plagiarismvalues = get_records_menu('plagiarism_config', 'cm',$this->cm->id,'','name,value');
             //                        if (!empty($plagiarismvalues['use_turnitin']) &&
             //                             (empty($this->assignment->tii_draft_submit) or !$this->drafts_tracked()) ) {
             //                         if ($tii_file = get_record_select('tii_files', "course='".$this->course->id.
             //                                         "' AND module='".$this->cm->module.
             //                                         "' AND instance='".$this->assignment->id.
             //                                         "' AND userid = '".$USER->id.
             //                                         "' AND filename = '".$um->get_new_filename()."'")) {
             //update record.
             //                             $tii_file->tiicode = 'pending';
             //                             $tii_file->tiiscore ='0';
             //                             if (!update_record('tii_files', $tii_file)) {
             //                                 debugging("update tii_files failed!");
             //                             }
             //                         } else {
             //                             $tii_file = new object();
             //                             $tii_file->course = $this->course->id;
             //                             $tii_file->module = $this->cm->module;
             //                             $tii_file->instance = $this->assignment->id;
             //                             $tii_file->userid = $USER->id;
             //                             $tii_file->filename = $um->get_new_filename();
             //                             $tii_file->tiicode = 'pending';
             //                             if (!insert_record('tii_files', $tii_file)) {
             //                                 debugging("insert into tii_files failed");
             //                             }
             //                          }
             //                        }
             // End Optional Turnitin code
         } else {
             $this->view_header(get_string('upload'));
             notify('upload process fail');
             print_continue($returnurl);
             $this->view_footer();
         }
         redirect('view.php?id=' . $this->cm->id);
     }
     $this->view_header(get_string('upload'));
     notify(get_string('uploaderror', 'assignment'));
     echo $um->get_errors();
     print_continue($returnurl);
     $this->view_footer();
     die;
 }
Пример #10
0
 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;
 }
 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;
 }
 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();
 }
 /**
  * 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;
 }
 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();
 }
            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)
    if ($templateid != -1) {
        $template = get_record('assignment_uploadpdf_tmpl', 'id', $templateid);
// 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";
                if ($wdir == '/') {
                    $wdir = '';
                }
                $image->dir = addslashes($wdir);
                $image->fullpath = $CFG->dataroot . '/' . $image->path;
                $image->timemodified = time();
                $image->owner = (int) $USER->id;
                // Resize image if necessary
Пример #17
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;
}
Пример #18
0
 $maxbytes = $max_quota - $tota_quota;
 $um = new upload_manager('new_file', false, true, false, $maxbytes, true);
 $reldir = "files/" . $upload_folder . "/" . $ul_username . "/";
 $dir = $CFG->dataroot . $reldir;
 if ($um->process_file_uploads($dir)) {
     $f = new StdClass();
     $f->owner = $USER->ident;
     $f->files_owner = $page_owner;
     $f->folder = $folderid;
     $f->originalname = $um->get_original_filename();
     if (empty($title)) {
         $title = $um->get_original_filename();
     }
     $f->title = $title;
     $f->description = $description;
     $f->location = $reldir . '/' . $um->get_new_filename();
     $f->access = $access;
     $f->size = $um->get_filesize();
     $f->time_uploaded = time();
     $file_id = insert_record('files', $f);
     $value = trim(optional_param('new_file_keywords'));
     insert_tags_from_string($value, 'file', $file_id, $access, $page_owner);
     $metadata = optional_param('metadata');
     if (is_array($metadata)) {
         foreach ($metadata as $name => $value) {
             $m = new StdClass();
             $m->name = trim($name);
             $m->value = trim($value);
             $m->file_id = $file_id;
             insert_record('file_metadata', $m);
         }
 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();
 }
Пример #20
0
             $attachname = $pathparts['basename'];
         } else {
             $form->error = get_string('attachmenterror', 'block_quickmail', $form->attachment);
         }
     }
 } else {
     require_once $CFG->libdir . '/uploadlib.php';
     $um = new upload_manager('attachment', false, true, $course, false, 0, true);
     // process the student posted attachment if it exists
     if ($um->process_file_uploads('temp/block_quickmail')) {
         // original name gets saved in the database
         $form->attachment = $um->get_original_filename();
         // check if file is there
         if (file_exists($um->get_new_filepath())) {
             // get path to the file without $CFG->dataroot
             $attachment = 'temp/block_quickmail/' . $um->get_new_filename();
             // get the new name (name may change due to filename collisions)
             $attachname = $um->get_new_filename();
         } else {
             $form->error = get_string("attachmenterror", "block_quickmail", $form->attachment);
         }
     } else {
         $form->attachment = '';
         // no attachment
     }
 }
 // no errors, then email
 if (!isset($form->error)) {
     $mailedto = array();
     // holds all the userid of successful emails
     // get the correct formating for the emails
Пример #21
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;
     }
 }
Пример #22
0
        $message[] = gettext("The uploaded icon file was in an image format other than JPEG, GIF or PNG. These are unsupported at present.");
    } else {
        if ($ok == true) {
            switch ($imageattr[2]) {
                case "1":
                    $file_extension = ".gif";
                    break;
                case "2":
                    $file_extension = ".jpg";
                    break;
                case "3":
                    $file_extension = ".png";
                    break;
            }
            $i = new StdClass();
            $i->filename = $um->get_new_filename();
            $i->owner = $page_owner;
            $i->description = $description;
            $ident = insert_record('icons', $i);
            if ($icondefault == "yes") {
                set_field('users', 'icon', $ident, 'ident', $page_owner);
                $_SESSION['icon'] = $save_file;
                $USER->icon = $save_file;
            }
            $messages[] = gettext("Your icon was uploaded successfully.");
        } else {
            $messages[] = gettext("An unknown error occurred when saving your icon. If this problem persists, please let us know and we'll do all we can to fix it quickly.");
        }
    }
    // }
}
Пример #23
0
 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)) {
     $filearea = file_area_name($course->id, $mail->id, $message->id);
     if ($basedir = file_area($course->id, $mail->id, $newmessageid)) {
         $filearea2 = file_area_name($course->id, $mail->id, $newmessageid);
         $origen = $CFG->dataroot . "/" . $filearea . "/" . $message->archivo;
         $destino = $CFG->dataroot . "/" . $filearea2 . "/" . $message->archivo;
         copy($origen, $destino);
     }