コード例 #1
2
ファイル: locallib.php プロジェクト: janeklb/moodle
 /**
  * Save the files and trigger plagiarism plugin, if enabled,
  * to scan the uploaded files via events trigger
  *
  * @param stdClass $submission
  * @param stdClass $data
  * @return bool
  */
 public function save(stdClass $submission, stdClass $data)
 {
     global $USER, $DB;
     $fileoptions = $this->get_file_options();
     $data = file_postupdate_standard_filemanager($data, 'files', $fileoptions, $this->assignment->get_context(), 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id);
     $filesubmission = $this->get_file_submission($submission->id);
     // Plagiarism code event trigger when files are uploaded.
     $fs = get_file_storage();
     $files = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id, 'id', false);
     $count = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA);
     $params = array('context' => context_module::instance($this->assignment->get_course_module()->id), 'courseid' => $this->assignment->get_course()->id, 'objectid' => $submission->id, 'other' => array('content' => '', 'pathnamehashes' => array_keys($files)));
     if (!empty($submission->userid) && $submission->userid != $USER->id) {
         $params['relateduserid'] = $submission->userid;
     }
     $event = \assignsubmission_file\event\assessable_uploaded::create($params);
     $event->set_legacy_files($files);
     $event->trigger();
     $groupname = null;
     $groupid = 0;
     // Get the group name as other fields are not transcribed in the logs and this information is important.
     if (empty($submission->userid) && !empty($submission->groupid)) {
         $groupname = $DB->get_field('groups', 'name', array('id' => $submission->groupid), '*', MUST_EXIST);
         $groupid = $submission->groupid;
     } else {
         $params['relateduserid'] = $submission->userid;
     }
     // Unset the objectid and other field from params for use in submission events.
     unset($params['objectid']);
     unset($params['other']);
     $params['other'] = array('submissionid' => $submission->id, 'submissionattempt' => $submission->attemptnumber, 'submissionstatus' => $submission->status, 'filesubmissioncount' => $count, 'groupid' => $groupid, 'groupname' => $groupname);
     if ($filesubmission) {
         $filesubmission->numfiles = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA);
         $updatestatus = $DB->update_record('assignsubmission_file', $filesubmission);
         $params['objectid'] = $filesubmission->id;
         $event = \assignsubmission_file\event\submission_updated::create($params);
         $event->set_assign($this->assignment);
         $event->trigger();
         return $updatestatus;
     } else {
         $filesubmission = new stdClass();
         $filesubmission->numfiles = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA);
         $filesubmission->submission = $submission->id;
         $filesubmission->assignment = $this->assignment->get_instance()->id;
         $filesubmission->id = $DB->insert_record('assignsubmission_file', $filesubmission);
         $params['objectid'] = $filesubmission->id;
         $event = \assignsubmission_file\event\submission_created::create($params);
         $event->set_assign($this->assignment);
         $event->trigger();
         return $filesubmission->id > 0;
     }
 }
コード例 #2
0
 /**
  * Saves the data coming from form
  * @param   mixed   data coming from the form
  * @param   string  name of the prefix (ie, competency)
  * @return  mixed   returns data id if success of db insert/update, false on fail, 0 if not permitted
  */
 function edit_save_data($itemnew)
 {
     // , $prefix){ //, $tableprefix) {
     global $DB;
     //, $FILEPICKER_OPTIONS;
     $options = filepicker_options();
     $formelement = $this->inputname . "_filemanager";
     if (!isset($itemnew->{$formelement})) {
         // field not present in form, probably locked and invisible - skip it
         return;
     }
     // if no existing stored data for this object, make a record so we can use its row id
     if (!$DB->get_field('course_meta_info_data', 'id', array('courseid' => $itemnew->id, 'fieldid' => $this->field->id))) {
         $data = new stdClass();
         $data->courseid = $itemnew->id;
         $data->fieldid = $this->field->id;
         $data->data = $itemnew->id . "," . $this->field->id;
         // the value in the view will contain reference to this row; we dont know our id yet
         $DB->insert_record('course_meta_info_data', $data);
     }
     // look up possibly new row id of course_meta_info_data - this will be the itemid in the file store
     $dataid = $DB->get_field('course_meta_info_data', 'id', array('courseid' => $itemnew->id, 'fieldid' => $this->field->id));
     // set the form data to contain the filemanager instance data for this file
     $itemnew = file_postupdate_standard_filemanager($itemnew, $this->inputname, $options, $options['context'], 'course_meta_customfield', 'course_meta_filemanager', $dataid);
 }
コード例 #3
0
$sc_obj->fetch($opencast->id);
// Display
$PAGE->set_title(format_string($opencast->name));
$PAGE->set_heading($course->fullname);
$maxbytes = min(mod_opencast_series::getValueForKey('userupload_maxfilesize'), $opencast->userupload_maxfilesize);
$usercontext = context_user::instance($USER->id);
$data = new stdClass();
$data->returnurl = $return_channel;
$options = ['subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => 1, 'accepted_types' => ['video'], 'areamaxbytes' => $maxbytes];
file_prepare_standard_filemanager($data, 'files', $options, $usercontext, 'mod_opencast', 'userfiles', $id);
$mform = new mod_opencast_upload_form($url, ['data' => $data, 'options' => $options]);
if ($mform->is_cancelled()) {
    redirect($return_channel);
} else {
    if ($formdata = $mform->get_data()) {
        $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $usercontext, 'mod_opencast', 'userfiles', $id);
        $fs = get_file_storage();
        $files = $fs->get_area_files($usercontext->id, 'mod_opencast', 'userfiles', $id);
        foreach ($files as $file) {
            $filesize = $file->get_filesize();
            if (!$filesize) {
                $file->delete();
                continue;
            }
            if ($file->get_mimetype() && substr($file->get_mimetype(), 0, 5) !== 'video') {
                $file->delete();
                print_error('fileis_notavideo', 'opencast', $url, $file->get_mimetype());
            }
            $filename = $file->get_filename();
            preg_match('/\\.([^.]+)$/', $filename, $extension);
            if (!in_array(strtolower($extension[1]), mod_opencast_series::getAllowedFileExtensions())) {
コード例 #4
0
ファイル: locallib.php プロジェクト: nfreear/moodle
 /**
  * Updates this entry in the database. Access control checks must be done by calling code.
  *
  * @param mform $form Used for attachments
  * @return void
  */
 public function edit($params = array(), $form = null, $summaryoptions = array(), $attachmentoptions = array())
 {
     global $CFG, $USER, $DB, $PAGE;
     $sitecontext = get_context_instance(CONTEXT_SYSTEM);
     $entry = $this;
     $this->form = $form;
     foreach ($params as $var => $val) {
         $entry->{$var} = $val;
     }
     $entry = file_postupdate_standard_editor($entry, 'summary', $summaryoptions, $sitecontext, 'blog', 'post', $entry->id);
     $entry = file_postupdate_standard_filemanager($entry, 'attachment', $attachmentoptions, $sitecontext, 'blog', 'attachment', $entry->id);
     if (!empty($CFG->useblogassociations)) {
         $entry->add_associations();
     }
     $entry->lastmodified = time();
     // Update record
     $DB->update_record('post', $entry);
     tag_set('post', $entry->id, $entry->tags);
     add_to_log(SITEID, 'blog', 'update', 'index.php?userid=' . $USER->id . '&entryid=' . $entry->id, $entry->subject);
 }
コード例 #5
0
ファイル: edit.php プロジェクト: saurabh947/MoodleLearning
// Course module ID
$cm = get_coursemodule_from_id('folder', $id, 0, false, MUST_EXIST);
$context = get_context_instance(CONTEXT_MODULE, $cm->id, MUST_EXIST);
$folder = $DB->get_record('folder', array('id' => $cm->instance), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
require_login($course, false, $cm);
require_capability('mod/folder:managefiles', $context);
add_to_log($course->id, 'folder', 'edit', 'edit.php?id=' . $cm->id, $folder->id, $cm->id);
$PAGE->set_url('/mod/folder/edit.php', array('id' => $cm->id));
$PAGE->set_title($course->shortname . ': ' . $folder->name);
$PAGE->set_heading($course->fullname);
$PAGE->set_activity_record($folder);
$data = new stdClass();
$data->id = $cm->id;
$options = array('subdirs' => 1, 'maxbytes' => $CFG->maxbytes, 'maxfiles' => -1, 'accepted_types' => '*');
file_prepare_standard_filemanager($data, 'files', $options, $context, 'mod_folder', 'content', 0);
$mform = new mod_folder_edit_form(null, array('data' => $data, 'options' => $options));
if ($mform->is_cancelled()) {
    redirect(new moodle_url('/mod/folder/view.php', array('id' => $cm->id)));
} else {
    if ($formdata = $mform->get_data()) {
        $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'mod_folder', 'content', 0);
        $DB->set_field('folder', 'revision', $folder->revision + 1, array('id' => $folder->id));
        redirect(new moodle_url('/mod/folder/view.php', array('id' => $cm->id)));
    }
}
echo $OUTPUT->header();
echo $OUTPUT->box_start('generalbox foldertree');
$mform->display();
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
コード例 #6
0
ファイル: lib.php プロジェクト: EmmanuelYupit/educursos
/**
 * Update a course.
 *
 * Please note this functions does not verify any access control,
 * the calling code is responsible for all validation (usually it is the form definition).
 *
 * @param object $data  - all the data needed for an entry in the 'course' table
 * @param array $editoroptions course description editor options
 * @return void
 */
function update_course($data, $editoroptions = NULL)
{
    global $DB;
    $data->timemodified = time();
    $oldcourse = course_get_format($data->id)->get_course();
    $context = context_course::instance($oldcourse->id);
    if ($editoroptions) {
        $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'summary', 0);
    }
    if ($overviewfilesoptions = course_overviewfiles_options($data->id)) {
        $data = file_postupdate_standard_filemanager($data, 'overviewfiles', $overviewfilesoptions, $context, 'course', 'overviewfiles', 0);
    }
    // Check we don't have a duplicate shortname.
    if (!empty($data->shortname) && $oldcourse->shortname != $data->shortname) {
        if ($DB->record_exists_sql('SELECT id from {course} WHERE shortname = ? AND id <> ?', array($data->shortname, $data->id))) {
            throw new moodle_exception('shortnametaken', '', '', $data->shortname);
        }
    }
    // Check we don't have a duplicate idnumber.
    if (!empty($data->idnumber) && $oldcourse->idnumber != $data->idnumber) {
        if ($DB->record_exists_sql('SELECT id from {course} WHERE idnumber = ? AND id <> ?', array($data->idnumber, $data->id))) {
            throw new moodle_exception('courseidnumbertaken', '', '', $data->idnumber);
        }
    }
    if (!isset($data->category) or empty($data->category)) {
        // prevent nulls and 0 in category field
        unset($data->category);
    }
    $changesincoursecat = $movecat = (isset($data->category) and $oldcourse->category != $data->category);
    if (!isset($data->visible)) {
        // data not from form, add missing visibility info
        $data->visible = $oldcourse->visible;
    }
    if ($data->visible != $oldcourse->visible) {
        // reset the visibleold flag when manually hiding/unhiding course
        $data->visibleold = $data->visible;
        $changesincoursecat = true;
    } else {
        if ($movecat) {
            $newcategory = $DB->get_record('course_categories', array('id' => $data->category));
            if (empty($newcategory->visible)) {
                // make sure when moving into hidden category the course is hidden automatically
                $data->visible = 0;
            }
        }
    }
    // Update with the new data
    $DB->update_record('course', $data);
    // make sure the modinfo cache is reset
    rebuild_course_cache($data->id);
    // update course format options with full course data
    course_get_format($data->id)->update_course_format_options($data, $oldcourse);
    $course = $DB->get_record('course', array('id' => $data->id));
    if ($movecat) {
        $newparent = context_coursecat::instance($course->category);
        $context->update_moved($newparent);
    }
    $fixcoursesortorder = $movecat || isset($data->sortorder) && $oldcourse->sortorder != $data->sortorder;
    if ($fixcoursesortorder) {
        fix_course_sortorder();
    }
    // purge appropriate caches in case fix_course_sortorder() did not change anything
    cache_helper::purge_by_event('changesincourse');
    if ($changesincoursecat) {
        cache_helper::purge_by_event('changesincoursecat');
    }
    // Test for and remove blocks which aren't appropriate anymore
    blocks_remove_inappropriate($course);
    // Save any custom role names.
    save_local_role_names($course->id, $data);
    // update enrol settings
    enrol_course_updated(false, $course, $data);
    // Trigger a course updated event.
    $event = \core\event\course_updated::create(array('objectid' => $course->id, 'context' => context_course::instance($course->id), 'other' => array('shortname' => $course->shortname, 'fullname' => $course->fullname)));
    $event->set_legacy_logdata(array($course->id, 'course', 'update', 'edit.php?id=' . $course->id, $course->id));
    $event->trigger();
    if ($oldcourse->format !== $course->format) {
        // Remove all options stored for the previous format
        // We assume that new course format migrated everything it needed watching trigger
        // 'course_updated' and in method format_XXX::update_course_format_options()
        $DB->delete_records('course_format_options', array('courseid' => $course->id, 'format' => $oldcourse->format));
    }
}
コード例 #7
0
ファイル: locallib.php プロジェクト: gabrielrosset/moodle
 /**
  * Updates this entry in the database. Access control checks must be done by calling code.
  *
  * @param array       $params            Entry parameters.
  * @param moodleform  $form              Used for attachments.
  * @param array       $summaryoptions    Summary options.
  * @param array       $attachmentoptions Attachment options.
  *
  * @return void
  */
 public function edit($params = array(), $form = null, $summaryoptions = array(), $attachmentoptions = array())
 {
     global $CFG, $DB;
     $sitecontext = context_system::instance();
     $entry = $this;
     $this->form = $form;
     foreach ($params as $var => $val) {
         $entry->{$var} = $val;
     }
     $entry = file_postupdate_standard_editor($entry, 'summary', $summaryoptions, $sitecontext, 'blog', 'post', $entry->id);
     $entry = file_postupdate_standard_filemanager($entry, 'attachment', $attachmentoptions, $sitecontext, 'blog', 'attachment', $entry->id);
     if (!empty($CFG->useblogassociations)) {
         $entry->add_associations();
     }
     $entry->lastmodified = time();
     // Update record.
     $DB->update_record('post', $entry);
     core_tag_tag::set_item_tags('core', 'post', $entry->id, context_user::instance($this->userid), $entry->tags);
     $event = \core\event\blog_entry_updated::create(array('objectid' => $entry->id, 'relateduserid' => $entry->userid));
     $event->set_blog_entry($entry);
     $event->trigger();
 }
 /**
  * Saves any files that the teacher may have attached or embedded.
  *
  * @param $assignment
  * @param $submission
  * @param $data
  * @global $PAGE
  * @global $CFG
  * @return string
  */
 private function save_files($assignment, $submission, $data)
 {
     global $PAGE, $CFG;
     $isupload = $assignment->assignmenttype == 'upload';
     $isuploadsingle = $assignment->assignmenttype == 'uploadsingle';
     if ($isupload || $isuploadsingle) {
         $fileui_options = array();
         if ($isupload) {
             $fileui_options = array('subdirs' => 1, 'maxbytes' => $assignment->maxbytes, 'maxfiles' => $assignment->var1, 'accepted_types' => '*', 'return_types' => FILE_INTERNAL);
         } else {
             if ($isuploadsingle) {
                 $fileui_options = array('subdirs' => 0, 'maxbytes' => $CFG->userquota, 'maxfiles' => 1, 'accepted_types' => '*', 'return_types' => FILE_INTERNAL);
             }
         }
         file_postupdate_standard_filemanager($data, 'files', $fileui_options, $PAGE->context, 'mod_assignment', 'response', $submission->id);
     }
     return '';
 }
コード例 #9
0
ファイル: assignment.class.php プロジェクト: JP-Git/moodle
    function upload_file($mform, $options) {
        global $CFG, $USER, $DB, $OUTPUT;

        $returnurl  = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id));
        $submission = $this->get_submission($USER->id);

        if (!$this->can_upload_file($submission)) {
            $this->view_header(get_string('upload'));
            echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
            echo $OUTPUT->continue_button($returnurl);
            $this->view_footer();
            die;
        }

        if ($formdata = $mform->get_data()) {
            $fs = get_file_storage();
            $submission = $this->get_submission($USER->id, true); //create new submission if needed
            $fs->delete_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id);
            $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $this->context, 'mod_assignment', 'submission', $submission->id);
            $updates = new stdClass();
            $updates->id = $submission->id;
            $updates->numfiles = count($fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, 'sortorder', false));
            $updates->timemodified = time();
            $DB->update_record('assignment_submissions', $updates);
            add_to_log($this->course->id, 'assignment', 'upload',
                    'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
            $this->update_grade($submission);
            if (!$this->drafts_tracked()) {
                $this->email_teachers($submission);
            }

            // send files to event system
            $files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id);
            // Let Moodle know that assessable files were  uploaded (eg for plagiarism detection)
            $eventdata = new stdClass();
            $eventdata->modulename   = 'assignment';
            $eventdata->cmid         = $this->cm->id;
            $eventdata->itemid       = $submission->id;
            $eventdata->courseid     = $this->course->id;
            $eventdata->userid       = $USER->id;
            if ($files) {
                $eventdata->files        = $files; // This is depreceated - please use pathnamehashes instead!
            }
            $eventdata->pathnamehashes = array_keys($files);
            events_trigger('assessable_file_uploaded', $eventdata);
            $returnurl  = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id));
            redirect($returnurl);
        }

        $this->view_header(get_string('upload'));
        echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
        echo $OUTPUT->continue_button($returnurl);
        $this->view_footer();
        die;
    }
コード例 #10
0
 function upload_file($mform, $options)
 {
     global $CFG, $USER, $DB, $OUTPUT;
     $returnurl = new moodle_url('/mod/assignment/view.php', array('id' => $this->cm->id));
     $submission = $this->get_submission($USER->id);
     if (!$this->can_upload_file($submission)) {
         $this->view_header(get_string('upload'));
         echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
         echo $OUTPUT->continue_button($returnurl);
         $this->view_footer();
         die;
     }
     if ($formdata = $mform->get_data()) {
         $fs = get_file_storage();
         $submission = $this->get_submission($USER->id, true);
         //create new submission if needed
         $fs->delete_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id);
         $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $this->context, 'mod_assignment', 'submission', $submission->id);
         $updates = new stdClass();
         $updates->id = $submission->id;
         $updates->numfiles = count($fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, 'sortorder', false));
         $updates->timemodified = time();
         $DB->update_record('assignment_submissions', $updates);
         $this->update_grade($submission);
         if (!$this->drafts_tracked()) {
             $this->email_teachers($submission);
         }
         // send files to event system
         $files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id);
         // Let Moodle know that assessable files were  uploaded (eg for plagiarism detection)
         $params = array('context' => $this->context, 'objectid' => $submission->id, 'other' => array('assignmentid' => $this->assignment->id, 'content' => '', 'pathnamehashes' => array_keys($files)));
         $event = \assignment_upload\event\assessable_uploaded::create($params);
         $event->set_legacy_files($files);
         $event->trigger();
         $returnurl = new moodle_url('/mod/assignment/view.php', array('id' => $this->cm->id));
         redirect($returnurl);
     }
     $this->view_header(get_string('upload'));
     echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
     echo $OUTPUT->continue_button($returnurl);
     $this->view_footer();
     die;
 }
コード例 #11
0
ファイル: exsubmission.php プロジェクト: Gavinthisisit/Moodle
        $formdata->content = '';
        // updated later
        $formdata->contentformat = FORMAT_HTML;
        // updated later
        $formdata->contenttrust = 0;
        // updated later
        if (is_null($example->id)) {
            $example->id = $formdata->id = $DB->insert_record('teamwork_submissions', $formdata);
        } else {
            if (empty($formdata->id) or empty($example->id) or $formdata->id != $example->id) {
                throw new moodle_exception('err_examplesubmissionid', 'teamwork');
            }
        }
        // save and relink embedded images and save attachments
        $formdata = file_postupdate_standard_editor($formdata, 'content', $contentopts, $teamwork->context, 'mod_teamwork', 'submission_content', $example->id);
        $formdata = file_postupdate_standard_filemanager($formdata, 'attachment', $attachmentopts, $teamwork->context, 'mod_teamwork', 'submission_attachment', $example->id);
        if (empty($formdata->attachment)) {
            // explicit cast to zero integer
            $formdata->attachment = 0;
        }
        // store the updated values or re-save the new example (re-saving needed because URLs are now rewritten)
        $DB->update_record('teamwork_submissions', $formdata);
        redirect($teamwork->exsubmission_url($formdata->id));
    }
}
// Output starts here
echo $output->header();
echo $output->heading(format_string($teamwork->name), 2);
// show instructions for submitting as they may contain some list of questions and we need to know them
// while reading the submitted answer
if (trim($teamwork->instructauthors)) {
コード例 #12
0
 /**
  * Save & preprocess the files and trigger plagiarism plugin, if enabled, to scan the uploaded files via events trigger
  *
  * @global stdClass $USER
  * @global moodle_database $DB
  * @param stdClass $submission
  * @param stdClass $data
  * @return bool
  */
 public function save(stdClass $submission, stdClass $data)
 {
     global $USER, $DB, $SESSION;
     // Pre-process all files to convert to useful PDF format.
     $fileoptions = $this->get_file_options();
     file_postupdate_standard_filemanager($data, 'pdfs', $fileoptions, $this->assignment->get_context(), 'assignsubmission_pdf', ASSIGNSUBMISSION_PDF_FA_DRAFT, $submission->id);
     $pdfsubmission = $this->get_pdf_submission($submission->id);
     // Plagiarism code event trigger when files are uploaded.
     $fs = get_file_storage();
     $files = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_pdf', ASSIGNSUBMISSION_PDF_FA_DRAFT, $submission->id, "id", false);
     // Check all files are PDF v1.4 or less.
     $submissionok = true;
     foreach ($files as $key => $file) {
         if (!AssignPDFLib::ensure_pdf_compatible($file)) {
             $filename = $file->get_filename();
             $file->delete();
             unset($files[$key]);
             if (!isset($SESSION->assignsubmission_pdf_invalid)) {
                 $SESSION->assignsubmission_pdf_invalid = array();
             }
             $SESSION->assignsubmission_pdf_invalid[] = $filename;
             $submissionok = false;
         }
     }
     if (!$submissionok) {
         return false;
     }
     $templatedata = null;
     if (isset($data->pdf_template)) {
         $templatedata = serialize($data->pdf_template);
     }
     $count = $this->count_files($submission->id, ASSIGNSUBMISSION_PDF_FA_DRAFT);
     // Send files to event system.
     // Let Moodle know that an assessable file was uploaded (eg for plagiarism detection).
     $eventdata = new stdClass();
     $eventdata->modulename = 'assign';
     $eventdata->cmid = $this->assignment->get_course_module()->id;
     $eventdata->itemid = $submission->id;
     $eventdata->courseid = $this->assignment->get_course()->id;
     $eventdata->userid = $USER->id;
     if ($count > 1) {
         $eventdata->files = $files;
         // This is depreceated - please use pathnamehashes instead!
     }
     $eventdata->file = $files;
     // This is depreceated - please use pathnamehashes instead!
     $eventdata->pathnamehashes = array_keys($files);
     events_trigger('assessable_file_uploaded', $eventdata);
     if ($pdfsubmission) {
         $pdfsubmission->numpages = 0;
         $pdfsubmission->templatedata = $templatedata;
         $DB->update_record('assignsubmission_pdf', $pdfsubmission);
     } else {
         $pdfsubmission = new stdClass();
         $pdfsubmission->submission = $submission->id;
         $pdfsubmission->assignment = $this->assignment->get_instance()->id;
         $pdfsubmission->numpages = 0;
         $pdfsubmission->templatedata = $templatedata;
         $DB->insert_record('assignsubmission_pdf', $pdfsubmission);
     }
     if (!$this->assignment->get_instance()->submissiondrafts) {
         // No 'submit assignment' button - need to submit immediately.
         $this->submit_for_grading($submission);
     }
     return true;
 }
コード例 #13
0
ファイル: exsubmission.php プロジェクト: evltuma/moodle
        $formdata->content = '';
        // updated later
        $formdata->contentformat = FORMAT_HTML;
        // updated later
        $formdata->contenttrust = 0;
        // updated later
        if (is_null($example->id)) {
            $example->id = $formdata->id = $DB->insert_record('workshop_submissions', $formdata);
        } else {
            if (empty($formdata->id) or empty($example->id) or $formdata->id != $example->id) {
                throw new moodle_exception('err_examplesubmissionid', 'workshop');
            }
        }
        // Save and relink embedded images and save attachments.
        $formdata = file_postupdate_standard_editor($formdata, 'content', $workshop->submission_content_options(), $workshop->context, 'mod_workshop', 'submission_content', $example->id);
        $formdata = file_postupdate_standard_filemanager($formdata, 'attachment', $workshop->submission_attachment_options(), $workshop->context, 'mod_workshop', 'submission_attachment', $example->id);
        if (empty($formdata->attachment)) {
            // explicit cast to zero integer
            $formdata->attachment = 0;
        }
        // store the updated values or re-save the new example (re-saving needed because URLs are now rewritten)
        $DB->update_record('workshop_submissions', $formdata);
        redirect($workshop->exsubmission_url($formdata->id));
    }
}
// Output starts here
echo $output->header();
echo $output->heading(format_string($workshop->name), 2);
// show instructions for submitting as they may contain some list of questions and we need to know them
// while reading the submitted answer
if (trim($workshop->instructauthors)) {
コード例 #14
0
    redirect($redir);
} else {
    if ($data = $mform->get_data()) {
        $sendnotification = false;
        if (!$contributionid) {
            // Create new contribution.
            $ins = (object) array('chapterid' => $chapter->id, 'giportfolioid' => $giportfolio->id, 'pagenum' => 0, 'subchapter' => 0, 'title' => '', 'content' => '', 'contentformat' => FORMAT_HTML, 'hidden' => 0, 'timecreated' => time(), 'timemodified' => 0, 'userid' => $USER->id);
            $contributionid = $DB->insert_record('giportfolio_contributions', $ins);
            if ($giportfolio->notifyaddentry) {
                $sendnotification = true;
            }
        }
        $data->id = $contributionid;
        $data->timemodified = time();
        $data = file_postupdate_standard_editor($data, 'content', $editoroptions, $context, 'mod_giportfolio', 'contribution', $contributionid);
        $data = file_postupdate_standard_filemanager($data, 'attachment', $attachmentoptions, $context, 'mod_giportfolio', 'attachment', $contributionid);
        $DB->update_record('giportfolio_contributions', $data);
        if ($sendnotification) {
            $graders = get_users_by_capability($context, 'mod/giportfolio:gradegiportfolios');
            if ($graders) {
                $url = new moodle_url('/mod/giportfolio/viewcontribute.php', array('id' => $cm->id, 'chapterid' => $chapter->id, 'userid' => $USER->id));
                $subj = get_string('notifyaddentry_subject', 'mod_giportfolio', fullname($USER));
                $info = (object) array('course' => format_string($course->fullname), 'portfolio' => format_string($giportfolio->name), 'username' => fullname($USER), 'chapter' => format_string($chapter->title), 'link' => $url->out(false));
                $messagetext = get_string('notifyaddentry_body', 'mod_giportfolio', $info);
                $info->link = html_writer::link($url, $url->out(false));
                $messagehtml = nl2br(get_string('notifyaddentry_body', 'mod_giportfolio', $info));
                $eventdata = (object) array('component' => 'mod_giportfolio', 'name' => 'addentry', 'userfrom' => get_admin(), 'userto' => null, 'subject' => $subj, 'fullmessage' => $messagetext, 'fullmessageformat' => FORMAT_PLAIN, 'fullmessagehtml' => $messagehtml, 'smallmessage' => $messagetext);
                foreach ($graders as $grader) {
                    $eventdata->userto = $grader;
                    message_send($eventdata);
                }
コード例 #15
0
 /**
  * Save the files and trigger plagiarism plugin, if enabled,
  * to scan the uploaded files via events trigger
  *
  * @param stdClass $submission
  * @param stdClass $data
  * @return bool
  */
 public function save(stdClass $submission, stdClass $data)
 {
     global $USER, $DB;
     $fileoptions = $this->get_file_options();
     $data = file_postupdate_standard_filemanager($data, 'files', $fileoptions, $this->assignment->get_context(), 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id);
     $filesubmission = $this->get_file_submission($submission->id);
     // Plagiarism code event trigger when files are uploaded.
     $fs = get_file_storage();
     $files = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id, 'id', false);
     $count = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA);
     $params = array('context' => context_module::instance($this->assignment->get_course_module()->id), 'objectid' => $submission->id, 'other' => array('content' => '', 'pathnamehashes' => array_keys($files)));
     $event = \assignsubmission_file\event\assessable_uploaded::create($params);
     $event->set_legacy_files($files);
     $event->trigger();
     if ($filesubmission) {
         $filesubmission->numfiles = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA);
         return $DB->update_record('assignsubmission_file', $filesubmission);
     } else {
         $filesubmission = new stdClass();
         $filesubmission->numfiles = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA);
         $filesubmission->submission = $submission->id;
         $filesubmission->assignment = $this->assignment->get_instance()->id;
         return $DB->insert_record('assignsubmission_file', $filesubmission) > 0;
     }
 }
コード例 #16
0
ファイル: lib.php プロジェクト: EsdrasCaleb/moodle
/**
 * Creates or updates a glossary entry
 *
 * @param  stdClass $entry entry data
 * @param  stdClass $course course object
 * @param  stdClass $cm course module object
 * @param  stdClass $glossary glossary object
 * @param  stdClass $context context object
 * @return stdClass the complete new or updated entry
 * @since  Moodle 3.2
 */
function glossary_edit_entry($entry, $course, $cm, $glossary, $context) {
    global $DB, $USER;

    list($definitionoptions, $attachmentoptions) = glossary_get_editor_and_attachment_options($course, $context, $entry);

    $timenow = time();

    $categories = empty($entry->categories) ? array() : $entry->categories;
    unset($entry->categories);
    $aliases = trim($entry->aliases);
    unset($entry->aliases);

    if (empty($entry->id)) {
        $entry->glossaryid       = $glossary->id;
        $entry->timecreated      = $timenow;
        $entry->userid           = $USER->id;
        $entry->timecreated      = $timenow;
        $entry->sourceglossaryid = 0;
        $entry->teacherentry     = has_capability('mod/glossary:manageentries', $context);
        $isnewentry              = true;
    } else {
        $isnewentry              = false;
    }

    $entry->concept          = trim($entry->concept);
    $entry->definition       = '';          // Updated later.
    $entry->definitionformat = FORMAT_HTML; // Updated later.
    $entry->definitiontrust  = 0;           // Updated later.
    $entry->timemodified     = $timenow;
    $entry->approved         = 0;
    $entry->usedynalink      = isset($entry->usedynalink) ? $entry->usedynalink : 0;
    $entry->casesensitive    = isset($entry->casesensitive) ? $entry->casesensitive : 0;
    $entry->fullmatch        = isset($entry->fullmatch) ? $entry->fullmatch : 0;

    if ($glossary->defaultapproval or has_capability('mod/glossary:approve', $context)) {
        $entry->approved = 1;
    }

    if ($isnewentry) {
        // Add new entry.
        $entry->id = $DB->insert_record('glossary_entries', $entry);
    } else {
        // Update existing entry.
        $DB->update_record('glossary_entries', $entry);
    }

    // Save and relink embedded images and save attachments.
    if (!empty($entry->definition_editor)) {
        $entry = file_postupdate_standard_editor($entry, 'definition', $definitionoptions, $context, 'mod_glossary', 'entry',
            $entry->id);
    }
    if (!empty($entry->attachment_filemanager)) {
        $entry = file_postupdate_standard_filemanager($entry, 'attachment', $attachmentoptions, $context, 'mod_glossary',
            'attachment', $entry->id);
    }

    // Store the updated value values.
    $DB->update_record('glossary_entries', $entry);

    // Refetch complete entry.
    $entry = $DB->get_record('glossary_entries', array('id' => $entry->id));

    // Update entry categories.
    $DB->delete_records('glossary_entries_categories', array('entryid' => $entry->id));
    // TODO: this deletes cats from both both main and secondary glossary :-(.
    if (!empty($categories) and array_search(0, $categories) === false) {
        foreach ($categories as $catid) {
            $newcategory = new stdClass();
            $newcategory->entryid    = $entry->id;
            $newcategory->categoryid = $catid;
            $DB->insert_record('glossary_entries_categories', $newcategory, false);
        }
    }

    // Update aliases.
    $DB->delete_records('glossary_alias', array('entryid' => $entry->id));
    if ($aliases !== '') {
        $aliases = explode("\n", $aliases);
        foreach ($aliases as $alias) {
            $alias = trim($alias);
            if ($alias !== '') {
                $newalias = new stdClass();
                $newalias->entryid = $entry->id;
                $newalias->alias   = $alias;
                $DB->insert_record('glossary_alias', $newalias, false);
            }
        }
    }

    // Trigger event and update completion (if entry was created).
    $eventparams = array(
        'context' => $context,
        'objectid' => $entry->id,
        'other' => array('concept' => $entry->concept)
    );
    if ($isnewentry) {
        $event = \mod_glossary\event\entry_created::create($eventparams);
    } else {
        $event = \mod_glossary\event\entry_updated::create($eventparams);
    }
    $event->add_record_snapshot('glossary_entries', $entry);
    $event->trigger();
    if ($isnewentry) {
        // Update completion state.
        $completion = new completion_info($course);
        if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $glossary->completionentries && $entry->approved) {
            $completion->update_state($cm, COMPLETION_COMPLETE);
        }
    }

    // Reset caches.
    if ($isnewentry) {
        if ($entry->usedynalink and $entry->approved) {
            \mod_glossary\local\concept_cache::reset_glossary($glossary);
        }
    } else {
        // So many things may affect the linking, let's just purge the cache always on edit.
        \mod_glossary\local\concept_cache::reset_glossary($glossary);
    }
    return $entry;
}
コード例 #17
0
ファイル: lib.php プロジェクト: Jtgadbois/Pedadida
/**
 * Update a course.
 *
 * Please note this functions does not verify any access control,
 * the calling code is responsible for all validation (usually it is the form definition).
 *
 * @param object $data  - all the data needed for an entry in the 'course' table
 * @param array $editoroptions course description editor options
 * @return void
 */
function update_course($data, $editoroptions = NULL)
{
    global $CFG, $DB;
    $data->timemodified = time();
    $oldcourse = course_get_format($data->id)->get_course();
    $context = context_course::instance($oldcourse->id);
    if ($editoroptions) {
        $data = file_postupdate_standard_editor($data, 'summary', $editoroptions, $context, 'course', 'summary', 0);
    }
    if ($overviewfilesoptions = course_overviewfiles_options($data->id)) {
        $data = file_postupdate_standard_filemanager($data, 'overviewfiles', $overviewfilesoptions, $context, 'course', 'overviewfiles', 0);
    }
    if (!isset($data->category) or empty($data->category)) {
        // prevent nulls and 0 in category field
        unset($data->category);
    }
    $changesincoursecat = $movecat = (isset($data->category) and $oldcourse->category != $data->category);
    if (!isset($data->visible)) {
        // data not from form, add missing visibility info
        $data->visible = $oldcourse->visible;
    }
    if ($data->visible != $oldcourse->visible) {
        // reset the visibleold flag when manually hiding/unhiding course
        $data->visibleold = $data->visible;
        $changesincoursecat = true;
    } else {
        if ($movecat) {
            $newcategory = $DB->get_record('course_categories', array('id' => $data->category));
            if (empty($newcategory->visible)) {
                // make sure when moving into hidden category the course is hidden automatically
                $data->visible = 0;
            }
        }
    }
    // Update with the new data
    $DB->update_record('course', $data);
    // make sure the modinfo cache is reset
    rebuild_course_cache($data->id);
    // update course format options with full course data
    course_get_format($data->id)->update_course_format_options($data, $oldcourse);
    $course = $DB->get_record('course', array('id' => $data->id));
    if ($movecat) {
        $newparent = context_coursecat::instance($course->category);
        context_moved($context, $newparent);
    }
    fix_course_sortorder();
    // purge appropriate caches in case fix_course_sortorder() did not change anything
    cache_helper::purge_by_event('changesincourse');
    if ($changesincoursecat) {
        cache_helper::purge_by_event('changesincoursecat');
    }
    // Test for and remove blocks which aren't appropriate anymore
    blocks_remove_inappropriate($course);
    // Save any custom role names.
    save_local_role_names($course->id, $data);
    // update enrol settings
    enrol_course_updated(false, $course, $data);
    add_to_log($course->id, "course", "update", "edit.php?id={$course->id}", $course->id);
    // Trigger events
    events_trigger('course_updated', $course);
    if ($oldcourse->format !== $course->format) {
        // Remove all options stored for the previous format
        // We assume that new course format migrated everything it needed watching trigger
        // 'course_updated' and in method format_XXX::update_course_format_options()
        $DB->delete_records('course_format_options', array('courseid' => $course->id, 'format' => $oldcourse->format));
    }
}
コード例 #18
0
 public function get_data()
 {
     $data = parent::get_data();
     if ($data) {
         $editoroptions = $this->get_editor_options();
         switch ($this->_customdata->assignment->assignmenttype) {
             case 'team':
             case 'upload':
             case 'uploadsingle':
                 $data = file_postupdate_standard_filemanager($data, 'files', $editoroptions, $this->_customdata->context, 'mod_assignment', 'response', $this->_customdata->teamid);
                 break;
             default:
                 break;
         }
         $data = file_postupdate_standard_editor($data, 'submissioncomment', $editoroptions, $this->_customdata->context, $editoroptions['component'], $editoroptions['filearea'], $this->_customdata->teamid);
     }
     return $data;
 }
コード例 #19
0
ファイル: filesedit.php プロジェクト: alanaipe2015/moodle
$title = get_string('editfiles', 'wiki');
$struser = get_string('user');
$url = new moodle_url('/mod/wiki/filesedit.php', array('subwiki' => $subwiki->id, 'pageid' => $pageid));
$PAGE->set_url($url);
$PAGE->set_context($context);
$PAGE->set_title($title);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add(format_string(get_string('wikifiles', 'wiki')), $CFG->wwwroot . '/mod/wiki/files.php?pageid=' . $pageid);
$PAGE->navbar->add(format_string($title));
$data = new stdClass();
$data->returnurl = $returnurl;
$data->subwikiid = $subwiki->id;
$maxbytes = get_max_upload_file_size($CFG->maxbytes, $COURSE->maxbytes);
$options = array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => -1, 'accepted_types' => '*', 'return_types' => FILE_INTERNAL | FILE_REFERENCE);
file_prepare_standard_filemanager($data, 'files', $options, $context, 'mod_wiki', 'attachments', $subwiki->id);
$mform = new mod_wiki_filesedit_form(null, array('data' => $data, 'options' => $options));
if ($mform->is_cancelled()) {
    redirect($returnurl);
} else {
    if ($formdata = $mform->get_data()) {
        $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'mod_wiki', 'attachments', $subwiki->id);
        redirect($returnurl);
    }
}
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($wiki->name));
echo $OUTPUT->box(format_module_intro('wiki', $wiki, $PAGE->cm->id), 'generalbox', 'intro');
echo $OUTPUT->box_start('generalbox');
$mform->display();
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
コード例 #20
0
ファイル: locallib.php プロジェクト: Burick/moodle
    /**
     * Upload files and send them to multiple users.
     *
     * @param array $users - An array of user ids
     * @return string - The response html
     */
    public function view_batch_upload_files($users) {
        global $CFG, $DB, $USER;

        require_capability('mod/assign:grade', $this->assignment->get_context());
        require_once($CFG->dirroot . '/mod/assign/feedback/file/batchuploadfilesform.php');
        require_once($CFG->dirroot . '/mod/assign/renderable.php');

        $formparams = array('cm'=>$this->assignment->get_course_module()->id,
                            'users'=>$users,
                            'context'=>$this->assignment->get_context());

        $usershtml = '';

        $usercount = 0;
        foreach ($users as $userid) {
            if ($usercount >= ASSIGNFEEDBACK_FILE_MAXSUMMARYUSERS) {
                $moreuserscount = count($users) - ASSIGNFEEDBACK_FILE_MAXSUMMARYUSERS;
                $usershtml .= get_string('moreusers', 'assignfeedback_file', $moreuserscount);
                break;
            }
            $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);

            $usersummary = new assign_user_summary($user,
                                                   $this->assignment->get_course()->id,
                                                   has_capability('moodle/site:viewfullnames',
                                                   $this->assignment->get_course_context()),
                                                   $this->assignment->is_blind_marking(),
                                                   $this->assignment->get_uniqueid_for_user($user->id));
            $usershtml .= $this->assignment->get_renderer()->render($usersummary);
            $usercount += 1;
        }

        $formparams['usershtml'] = $usershtml;

        $mform = new assignfeedback_file_batch_upload_files_form(null, $formparams);

        if ($mform->is_cancelled()) {
            redirect(new moodle_url('view.php',
                                    array('id'=>$this->assignment->get_course_module()->id,
                                          'action'=>'grading')));
            return;
        } else if ($data = $mform->get_data()) {
            // Copy the files from the draft area to a temporary import area.
            $data = file_postupdate_standard_filemanager($data,
                                                         'files',
                                                         $this->get_file_options(),
                                                         $this->assignment->get_context(),
                                                         'assignfeedback_file',
                                                         ASSIGNFEEDBACK_FILE_BATCH_FILEAREA,
                                                         $USER->id);
            $fs = get_file_storage();

            // Now copy each of these files to the users feedback file area.
            foreach ($users as $userid) {
                $grade = $this->assignment->get_user_grade($userid, true);
                $this->assignment->notify_grade_modified($grade);

                $this->copy_area_files($fs,
                                       $this->assignment->get_context()->id,
                                       'assignfeedback_file',
                                       ASSIGNFEEDBACK_FILE_BATCH_FILEAREA,
                                       $USER->id,
                                       $this->assignment->get_context()->id,
                                       'assignfeedback_file',
                                       ASSIGNFEEDBACK_FILE_FILEAREA,
                                       $grade->id);

                $filefeedback = $this->get_file_feedback($grade->id);
                if ($filefeedback) {
                    $filefeedback->numfiles = $this->count_files($grade->id,
                                                                 ASSIGNFEEDBACK_FILE_FILEAREA);
                    $DB->update_record('assignfeedback_file', $filefeedback);
                } else {
                    $filefeedback = new stdClass();
                    $filefeedback->numfiles = $this->count_files($grade->id,
                                                                 ASSIGNFEEDBACK_FILE_FILEAREA);
                    $filefeedback->grade = $grade->id;
                    $filefeedback->assignment = $this->assignment->get_instance()->id;
                    $DB->insert_record('assignfeedback_file', $filefeedback);
                }
            }

            // Now delete the temporary import area.
            $fs->delete_area_files($this->assignment->get_context()->id,
                                   'assignfeedback_file',
                                   ASSIGNFEEDBACK_FILE_BATCH_FILEAREA,
                                   $USER->id);

            redirect(new moodle_url('view.php',
                                    array('id'=>$this->assignment->get_course_module()->id,
                                          'action'=>'grading')));
            return;
        } else {

            $header = new assign_header($this->assignment->get_instance(),
                                        $this->assignment->get_context(),
                                        false,
                                        $this->assignment->get_course_module()->id,
                                        get_string('batchuploadfiles', 'assignfeedback_file'));
            $o = '';
            $o .= $this->assignment->get_renderer()->render($header);
            $o .= $this->assignment->get_renderer()->render(new assign_form('batchuploadfiles', $mform));
            $o .= $this->assignment->get_renderer()->render_footer();
        }

        return $o;
    }
コード例 #21
0
require_login($course);
require_capability('moodle/course:managefiles', $context);
$PAGE->set_url($url);
$heading = get_string('coursefiles') . ': ' . format_string($course->fullname, true, array('context' => $context));
$strfiles = get_string("files");
if ($node = $PAGE->settingsnav->find('coursefiles', navigation_node::TYPE_SETTING)) {
    $node->make_active();
} else {
    $PAGE->navbar->add($strfiles);
}
$PAGE->set_context($context);
$PAGE->set_title($heading);
$PAGE->set_heading($heading);
$PAGE->set_pagelayout('incourse');
$data = new stdClass();
$options = array('subdirs' => 1, 'maxfiles' => -1, 'accepted_types' => '*', 'return_types' => FILE_INTERNAL);
file_prepare_standard_filemanager($data, 'files', $options, $context, $component, $filearea, $itemid);
$form = new coursefiles_edit_form(null, array('data' => $data, 'contextid' => $contextid));
$returnurl = new moodle_url('/files/index.php', array('contextid' => $contextid));
if ($form->is_cancelled()) {
    redirect($returnurl);
}
if ($data = $form->get_data()) {
    $data = file_postupdate_standard_filemanager($data, 'files', $options, $context, $component, $filearea, $itemid);
    redirect($returnurl);
}
echo $OUTPUT->header();
echo $OUTPUT->container_start();
$form->display();
echo $OUTPUT->container_end();
echo $OUTPUT->footer();
コード例 #22
0
 function upload_file($mform, $options)
 {
     global $CFG, $USER, $DB, $OUTPUT;
     $mode = optional_param('mode', '', PARAM_ALPHA);
     $offset = optional_param('offset', 0, PARAM_INT);
     $returnurl = 'view.php?id=' . $this->cm->id;
     $submission = $this->get_submission($USER->id);
     if (!$this->can_upload_file($submission)) {
         $this->view_header(get_string('upload'));
         echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
         echo $OUTPUT->continue_button($returnurl);
         $this->view_footer();
         die;
     }
     if ($formdata = $mform->get_data()) {
         $fs = get_file_storage();
         $submission = $this->get_submission($USER->id, true);
         //create new submission if needed
         $fs->delete_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id);
         $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $this->context, 'mod_assignment', 'submission', $submission->id);
         // Make sure all submitted PDFs are compatible with FPDI
         /** @var $files stored_file[] */
         if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, 'timemodified', false)) {
             foreach ($files as $file) {
                 if ($file->get_mimetype() == 'application/pdf') {
                     if (!MyPDFLib::ensure_pdf_compatible($file)) {
                         // Uses ghostscript to convert any PDFs > v1.4
                         throw new moodle_exception('invalidpdf', 'uploadpdf', $file->get_filename());
                     }
                 }
             }
         }
         $updates = new object();
         $updates->id = $submission->id;
         $updates->timemodified = time();
         if ($DB->update_record('assignment_submissions', $updates)) {
             add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a=' . $this->assignment->id, $this->assignment->id, $this->cm->id);
             $this->update_grade($submission);
             // send files to event system
             $files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id);
             // Let Moodle know that assessable files were  uploaded (eg for plagiarism detection)
             $eventdata = new object();
             $eventdata->modulename = 'assignment';
             $eventdata->cmid = $this->cm->id;
             $eventdata->itemid = $submission->id;
             $eventdata->courseid = $this->course->id;
             $eventdata->userid = $USER->id;
             if ($files) {
                 $eventdata->files = $files;
             }
             events_trigger('assessable_file_uploaded', $eventdata);
         }
         $returnurl = new moodle_url('/mod/assignment/view.php', array('id' => $this->cm->id));
         redirect($returnurl);
     }
     $this->view_header(get_string('upload'));
     echo $OUTPUT->notification(get_string('uploaderror', 'assignment'));
     echo $OUTPUT->continue_button($returnurl);
     $this->view_footer();
     die;
 }
コード例 #23
0
ファイル: files.php プロジェクト: rama1712/moodle
    $returnbutton = false;
    $returnurl = new moodle_url('/user/files.php');
}
$context = get_context_instance(CONTEXT_USER, $USER->id);
require_capability('moodle/user:manageownfiles', $context);
$title = get_string('myfiles');
$struser = get_string('user');
$PAGE->set_url('/user/files.php');
$PAGE->set_context($context);
$PAGE->set_title($title);
$PAGE->set_heading($title);
$PAGE->set_pagelayout('mydashboard');
$PAGE->set_pagetype('user-files');
$data = new stdClass();
$data->returnurl = $returnurl;
$options = array('subdirs' => 1, 'maxbytes' => $CFG->userquota, 'maxfiles' => -1, 'accepted_types' => '*');
file_prepare_standard_filemanager($data, 'files', $options, $context, 'user', 'private', 0);
$mform = new user_files_form(null, array('data' => $data, 'options' => $options, 'cancelbutton' => $returnbutton));
if ($mform->is_cancelled()) {
    redirect($returnurl);
} else {
    if ($formdata = $mform->get_data()) {
        $formdata = file_postupdate_standard_filemanager($formdata, 'files', $options, $context, 'user', 'private', 0);
        redirect($returnurl);
    }
}
echo $OUTPUT->header();
echo $OUTPUT->box_start('generalbox');
$mform->display();
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
コード例 #24
0
ファイル: locallib.php プロジェクト: Jtgadbois/Pedadida
    /**
     * Save the files and trigger plagiarism plugin, if enabled,
     * to scan the uploaded files via events trigger
     *
     * @param stdClass $submission
     * @param stdClass $data
     * @return bool
     */
    public function save(stdClass $submission, stdClass $data) {
        global $USER, $DB;

        $fileoptions = $this->get_file_options();

        $data = file_postupdate_standard_filemanager($data,
                                                     'files',
                                                     $fileoptions,
                                                     $this->assignment->get_context(),
                                                     'assignsubmission_file',
                                                     ASSIGNSUBMISSION_FILE_FILEAREA,
                                                     $submission->id);

        $filesubmission = $this->get_file_submission($submission->id);

        // Plagiarism code event trigger when files are uploaded.

        $fs = get_file_storage();
        $files = $fs->get_area_files($this->assignment->get_context()->id,
                                     'assignsubmission_file',
                                     ASSIGNSUBMISSION_FILE_FILEAREA,
                                     $submission->id,
                                     'id',
                                     false);

        $count = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA);

        // Send files to event system.
        // This lets Moodle know that an assessable file was uploaded (eg for plagiarism detection).
        $eventdata = new stdClass();
        $eventdata->modulename = 'assign';
        $eventdata->cmid = $this->assignment->get_course_module()->id;
        $eventdata->itemid = $submission->id;
        $eventdata->courseid = $this->assignment->get_course()->id;
        $eventdata->userid = $USER->id;
        if ($count > 1) {
            $eventdata->files = $files;
        }
        $eventdata->file = $files;
        $eventdata->pathnamehashes = array_keys($files);
        events_trigger('assessable_file_uploaded', $eventdata);

        if ($filesubmission) {
            $filesubmission->numfiles = $this->count_files($submission->id,
                                                           ASSIGNSUBMISSION_FILE_FILEAREA);
            return $DB->update_record('assignsubmission_file', $filesubmission);
        } else {
            $filesubmission = new stdClass();
            $filesubmission->numfiles = $this->count_files($submission->id,
                                                           ASSIGNSUBMISSION_FILE_FILEAREA);
            $filesubmission->submission = $submission->id;
            $filesubmission->assignment = $this->assignment->get_instance()->id;
            return $DB->insert_record('assignsubmission_file', $filesubmission) > 0;
        }
    }
コード例 #25
0
ファイル: exassessment.php プロジェクト: verbazend/AWFA
    // Let the grading strategy subplugin save its data.
    $rawgrade = $strategy->save_assessment($assessment, $data);

    // Store the data managed by the workshop core.
    $coredata = (object)array('id' => $assessment->id);
    if (isset($data->feedbackauthor_editor)) {
        $coredata->feedbackauthor_editor = $data->feedbackauthor_editor;
        $coredata = file_postupdate_standard_editor($coredata, 'feedbackauthor', $workshop->overall_feedback_content_options(),
            $workshop->context, 'mod_workshop', 'overallfeedback_content', $assessment->id);
        unset($coredata->feedbackauthor_editor);
    }
    if (isset($data->feedbackauthorattachment_filemanager)) {
        $coredata->feedbackauthorattachment_filemanager = $data->feedbackauthorattachment_filemanager;
        $coredata = file_postupdate_standard_filemanager($coredata, 'feedbackauthorattachment',
            $workshop->overall_feedback_attachment_options(), $workshop->context, 'mod_workshop', 'overallfeedback_attachment',
            $assessment->id);
        unset($coredata->feedbackauthorattachment_filemanager);
        if (empty($coredata->feedbackauthorattachment)) {
            $coredata->feedbackauthorattachment = 0;
        }
    }
    if ($canmanage) {
        // Remember the last one who edited the reference assessment.
        $coredata->reviewerid = $USER->id;
    }
    // Update the assessment data if there is something other than just the 'id'.
    if (count((array)$coredata) > 1 ) {
        $DB->update_record('workshop_assessments', $coredata);
    }
コード例 #26
0
ファイル: locallib.php プロジェクト: rama1712/moodle
 /**
  * Save the feedback files
  *
  * @param stdClass $grade
  * @param stdClass $data
  * @return bool
  */
 public function save(stdClass $grade, stdClass $data)
 {
     global $DB;
     $fileoptions = $this->get_file_options();
     $data = file_postupdate_standard_filemanager($data, 'files', $fileoptions, $this->assignment->get_context(), 'assignfeedback_file', ASSIGNFEEDBACK_FILE_FILEAREA, $grade->id);
     $filefeedback = $this->get_file_feedback($grade->id);
     if ($filefeedback) {
         $filefeedback->numfiles = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA);
         return $DB->update_record('assignfeedback_file', $filefeedback);
     } else {
         $filefeedback = new stdClass();
         $filefeedback->numfiles = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA);
         $filefeedback->grade = $grade->id;
         $filefeedback->assignment = $this->assignment->get_instance()->id;
         return $DB->insert_record('assignfeedback_file', $filefeedback) > 0;
     }
 }
コード例 #27
0
ファイル: lib.php プロジェクト: nuckey/moodle
    public function get_data() {
        $data = parent::get_data();

        if (!empty($this->_customdata->submission->id)) {
            $itemid = $this->_customdata->submission->id;
        } else {
            $itemid = null; //TODO: this is wrong, itemid MUST be known when saving files!! (skodak)
        }

        if ($data) {
            $editoroptions = $this->get_editor_options();
            switch ($this->_customdata->assignment->assignmenttype) {
                case 'upload' :
                case 'uploadsingle' :
                    $data = file_postupdate_standard_filemanager($data, 'files', $editoroptions, $this->_customdata->context, 'mod_assignment', 'response', $itemid);
                    break;
                default :
                    break;
            }
            $data = file_postupdate_standard_editor($data, 'submissioncomment', $editoroptions, $this->_customdata->context, $editoroptions['component'], $editoroptions['filearea'], $itemid);
        }
        return $data;
    }
コード例 #28
0
ファイル: edit.php プロジェクト: abhilash1994/moodle
 $entry->usedynalink = isset($entry->usedynalink) ? $entry->usedynalink : 0;
 $entry->casesensitive = isset($entry->casesensitive) ? $entry->casesensitive : 0;
 $entry->fullmatch = isset($entry->fullmatch) ? $entry->fullmatch : 0;
 if ($glossary->defaultapproval or has_capability('mod/glossary:approve', $context)) {
     $entry->approved = 1;
 }
 if ($isnewentry) {
     // Add new entry.
     $entry->id = $DB->insert_record('glossary_entries', $entry);
 } else {
     // Update existing entry.
     $DB->update_record('glossary_entries', $entry);
 }
 // save and relink embedded images and save attachments
 $entry = file_postupdate_standard_editor($entry, 'definition', $definitionoptions, $context, 'mod_glossary', 'entry', $entry->id);
 $entry = file_postupdate_standard_filemanager($entry, 'attachment', $attachmentoptions, $context, 'mod_glossary', 'attachment', $entry->id);
 // store the updated value values
 $DB->update_record('glossary_entries', $entry);
 //refetch complete entry
 $entry = $DB->get_record('glossary_entries', array('id' => $entry->id));
 // update entry categories
 $DB->delete_records('glossary_entries_categories', array('entryid' => $entry->id));
 // TODO: this deletes cats from both both main and secondary glossary :-(
 if (!empty($categories) and array_search(0, $categories) === false) {
     foreach ($categories as $catid) {
         $newcategory = new stdClass();
         $newcategory->entryid = $entry->id;
         $newcategory->categoryid = $catid;
         $DB->insert_record('glossary_entries_categories', $newcategory, false);
     }
 }
コード例 #29
0
ファイル: submission.php プロジェクト: alanaipe2015/moodle
 $params = array('context' => $workshop->context, 'courseid' => $workshop->course->id, 'other' => array('submissiontitle' => $formdata->title));
 $logdata = null;
 if (is_null($submission->id)) {
     $submission->id = $formdata->id = $DB->insert_record('workshop_submissions', $formdata);
     $params['objectid'] = $submission->id;
     $event = \mod_workshop\event\submission_created::create($params);
     $event->trigger();
 } else {
     if (empty($formdata->id) or empty($submission->id) or $formdata->id != $submission->id) {
         throw new moodle_exception('err_submissionid', 'workshop');
     }
 }
 $params['objectid'] = $submission->id;
 // save and relink embedded images and save attachments
 $formdata = file_postupdate_standard_editor($formdata, 'content', $contentopts, $workshop->context, 'mod_workshop', 'submission_content', $submission->id);
 $formdata = file_postupdate_standard_filemanager($formdata, 'attachment', $attachmentopts, $workshop->context, 'mod_workshop', 'submission_attachment', $submission->id);
 if (empty($formdata->attachment)) {
     // explicit cast to zero integer
     $formdata->attachment = 0;
 }
 // store the updated values or re-save the new submission (re-saving needed because URLs are now rewritten)
 $DB->update_record('workshop_submissions', $formdata);
 $event = \mod_workshop\event\submission_updated::create($params);
 $event->add_record_snapshot('workshop', $workshoprecord);
 $event->trigger();
 // send submitted content for plagiarism detection
 $fs = get_file_storage();
 $files = $fs->get_area_files($workshop->context->id, 'mod_workshop', 'submission_attachment', $submission->id);
 $params['other']['content'] = $formdata->content;
 $params['other']['pathnamehashes'] = array_keys($files);
 $event = \mod_workshop\event\assessable_uploaded::create($params);
コード例 #30
0
ファイル: create.php プロジェクト: anilch/Personel
$mform = new resource_central_form(null, array('definitionoptions' => $definitionoptions, 'attachmentoptions' => $attachmentoptions, 'id' => $id, 'courseid' => $courseid));
$mform->set_data($tool);
$data = $mform->get_data();
$mform->display();
if ($mform->is_cancelled()) {
    $returnurl = new moodle_url('/local/resourcecentral/index.php?id=' . $courseid . '');
    redirect($returnurl);
}

if ($data) {
    if ($data->id > 0) {
        $data->description = $data->description['text'];
        $data->timecreated = time();
        $data->usermodified = $USER->id;
        $data->id = $DB->update_record('local_resourcecentral', $data);
        $data = file_postupdate_standard_editor($data, 'definition', $definitionoptions, $context, 'user', 'draft', $data->id);
        $data = file_postupdate_standard_filemanager($data, 'itemid', $attachmentoptions, $context, 'user', 'draft', $data->id);
        $returnurl = new moodle_url('/local/resourcecentral/index.php?id=' . $data->courseid . '');
    } else {
        $data->description = $data->description['text'];
        $data->timecreated = time();
        $data->usermodified = $USER->id;
        $data->id = $DB->insert_record('local_resourcecentral', $data);
        $data = file_postupdate_standard_editor($data, 'definition', $definitionoptions, $context, 'user', 'draft', $data->id);
        $data = file_postupdate_standard_filemanager($data, 'itemid', $attachmentoptions, $context, 'user', 'draft', $data->id);
        $returnurl = new moodle_url('/local/resourcecentral/index.php?id=' . $data->courseid . '');
    }
    redirect($returnurl);
}
echo $OUTPUT->footer();