function set_data($defaults) { if (empty($entry->id)) { $entry = new stdClass(); $entry->id = null; } $draftitemid = file_get_submitted_draft_itemid('config_attachments'); file_prepare_draft_area($draftitemid, $this->block->context->id, 'block_slider', 'content', 0, array('subdirs' => true)); $entry->attachments = $draftitemid; parent::set_data($defaults); if ($data = parent::get_data()) { file_save_draft_area_files($data->config_attachments, $this->block->context->id, 'block_slider', 'content', 0, array('subdirs' => true)); } }
public function data_preprocessing($question) { $question = parent::data_preprocessing($question); $question = $this->data_preprocessing_combined_feedback($question, true); $question = $this->data_preprocessing_hints($question, true, true); $dragids = array(); // drag no -> dragid if (!empty($question->options)) { $question->shuffleanswers = $question->options->shuffleanswers; $question->drags = array(); foreach ($question->options->drags as $drag) { $dragindex = $drag->no - 1; $question->drags[$dragindex] = array(); $question->drags[$dragindex]['draglabel'] = $drag->label; $question->drags[$dragindex]['infinite'] = $drag->infinite; $question->drags[$dragindex]['draggroup'] = $drag->draggroup; $dragids[$dragindex] = $drag->id; } $question->drops = array(); foreach ($question->options->drops as $drop) { $question->drops[$drop->no - 1] = array(); $question->drops[$drop->no - 1]['choice'] = $drop->choice; $question->drops[$drop->no - 1]['droplabel'] = $drop->label; $question->drops[$drop->no - 1]['xleft'] = $drop->xleft; $question->drops[$drop->no - 1]['ytop'] = $drop->ytop; } } //initialise file picker for bgimage $draftitemid = file_get_submitted_draft_itemid('bgimage'); file_prepare_draft_area($draftitemid, $this->context->id, 'qtype_ddimageortext', 'bgimage', !empty($question->id) ? (int) $question->id : null, self::file_picker_options()); $question->bgimage = $draftitemid; //initialise file picker for dragimages list(, $imagerepeats) = $this->get_drag_item_repeats(); $draftitemids = optional_param_array('dragitem', array(), PARAM_INT); for ($imageindex = 0; $imageindex < $imagerepeats; $imageindex++) { $draftitemid = isset($draftitemids[$imageindex]) ? $draftitemids[$imageindex] : 0; //numbers not allowed in filearea name $itemid = isset($dragids[$imageindex]) ? $dragids[$imageindex] : null; file_prepare_draft_area($draftitemid, $this->context->id, 'qtype_ddimageortext', 'dragimage', $itemid, self::file_picker_options()); $question->dragitem[$imageindex] = $draftitemid; } if (!empty($question->options)) { foreach ($question->options->drags as $drag) { $dragindex = $drag->no - 1; if (!isset($question->dragitem[$dragindex])) { $fileexists = false; } else { $fileexists = self::file_uploaded($question->dragitem[$dragindex]); } $labelexists = trim($question->drags[$dragindex]['draglabel']) != ''; if ($labelexists && !$fileexists) { $question->dragitemtype[$dragindex] = 'word'; } else { $question->dragitemtype[$dragindex] = 'image'; } } } $this->js_call(); return $question; }
protected function data_preprocessing($question) { $question = parent::data_preprocessing($question); $question = $this->data_preprocessing_combined_feedback($question, true); $question = $this->data_preprocessing_hints($question, true, true); if (empty($question->options)) { return $question; } $question->shuffleanswers = $question->options->shuffleanswers; $key = 0; foreach ($question->options->subquestions as $subquestion) { $question->subanswers[$key] = $subquestion->answertext; $draftid = file_get_submitted_draft_itemid('subquestions[' . $key . ']'); $question->subquestions[$key] = array(); $question->subquestions[$key]['text'] = file_prepare_draft_area($draftid, $this->context->id, 'qtype_ddmatch', 'subquestion', !empty($subquestion->id) ? (int) $subquestion->id : null, $this->fileoptions, $subquestion->questiontext); $question->subquestions[$key]['format'] = $subquestion->questiontextformat; $question->subquestions[$key]['itemid'] = $draftid; $draftid = file_get_submitted_draft_itemid('subanswers[' . $key . ']'); $question->subanswers[$key] = array(); $question->subanswers[$key]['text'] = file_prepare_draft_area($draftid, $this->context->id, 'qtype_ddmatch', 'subanswer', !empty($subquestion->id) ? (int) $subquestion->id : null, $this->fileoptions, $subquestion->answertext); $question->subanswers[$key]['format'] = $subquestion->answertextformat; $question->subanswers[$key]['itemid'] = $draftid; $key++; } return $question; }
protected function data_preprocessing($question) { $question = parent::data_preprocessing($question); if (empty($question->options)) { return $question; } $question->responseformat = $question->options->responseformat; $question->responsefieldlines = $question->options->responsefieldlines; $question->attachments = $question->options->attachments; $question->boardsize = $question->options->boardsize; //Set backimage details, and configure a draft area to accept any uploaded pictures //all this and this whole method does, is to load existing files into a filearea //so it is not called when creating a new question, only when editing an existing one //best to use file_get_submitted_draft_itemid - because copying questions gets weird otherwise //$draftitemid =$question->options->backimage; $draftitemid = file_get_submitted_draft_itemid('backimage'); file_prepare_draft_area($draftitemid, $this->context->id, 'qtype_poodllrecording', 'backimage', !empty($question->id) ? (int) $question->id : null, array('subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 1)); $question->backimage = $draftitemid; $draftid = file_get_submitted_draft_itemid('graderinfo'); $question->graderinfo = array(); $question->graderinfo['text'] = file_prepare_draft_area($draftid, $this->context->id, 'qtype_poodllrecording', 'graderinfo', !empty($question->id) ? (int) $question->id : null, $this->fileoptions, $question->options->graderinfo); $question->graderinfo['format'] = $question->options->graderinfoformat; $question->graderinfo['itemid'] = $draftid; return $question; }
public function test_get_unused_filename() { global $USER; $this->resetAfterTest(true); $this->setAdminUser(); $fs = get_file_storage(); $draftitemid = null; $context = context_user::instance($USER->id); file_prepare_draft_area($draftitemid, $context->id, 'phpunit', 'test_get_unused_filename', 1); $dummy = array('contextid' => $context->id, 'component' => 'user', 'filearea' => 'draft', 'itemid' => $draftitemid, 'filepath' => '/', 'filename' => ''); // Create some files. $existingfiles = array('test', 'test.txt', 'test (1).txt', 'test1.txt', 'test1 (1).txt', 'test1 (2).txt', 'test1 (3).txt', 'test1 (My name is Bob).txt', 'test2 (555).txt', 'test3 (1000).txt', 'test3 (1000MB).txt'); foreach ($existingfiles as $filename) { $dummy['filename'] = $filename; $file = $fs->create_file_from_string($dummy, 'blah! ' . $filename); $this->assertTrue(repository::draftfile_exists($draftitemid, '/', $filename)); } // Actual testing. $this->assertEquals('free.txt', repository::get_unused_filename($draftitemid, '/', 'free.txt')); $this->assertEquals('test (1)', repository::get_unused_filename($draftitemid, '/', 'test')); $this->assertEquals('test (2).txt', repository::get_unused_filename($draftitemid, '/', 'test.txt')); $this->assertEquals('test1 (4).txt', repository::get_unused_filename($draftitemid, '/', 'test1.txt')); $this->assertEquals('test1 (8).txt', repository::get_unused_filename($draftitemid, '/', 'test1 (8).txt')); $this->assertEquals('test1 ().txt', repository::get_unused_filename($draftitemid, '/', 'test1 ().txt')); $this->assertEquals('test2 (556).txt', repository::get_unused_filename($draftitemid, '/', 'test2 (555).txt')); $this->assertEquals('test3 (1001).txt', repository::get_unused_filename($draftitemid, '/', 'test3 (1000).txt')); $this->assertEquals('test3 (1000MB) (1).txt', repository::get_unused_filename($draftitemid, '/', 'test3 (1000MB).txt')); $this->assertEquals('test4 (1).txt', repository::get_unused_filename($draftitemid, '/', 'test4 (1).txt')); }
/** * */ protected function definition_appearance() { global $COURSE; // We want to hide that when using the singleactivity course format because it is confusing. if (!$this->courseformat->has_view_page()) { return; } $mform =& $this->_form; $mform->addElement('header', 'coursedisplayhdr', get_string('appearance')); // Activity icon. $options = array('subdirs' => 0, 'maxbytes' => $COURSE->maxbytes, 'maxfiles' => 1, 'accepted_types' => array('image')); $draftitemid = file_get_submitted_draft_itemid('activityicon'); file_prepare_draft_area($draftitemid, $this->context->id, 'mod_dataform', 'activityicon', 0, $options); $mform->addElement('filemanager', 'activityicon', get_string('activityicon', 'dataform'), null, $options); $mform->setDefault('activityicon', $draftitemid); $mform->addHelpButton('activityicon', 'activityicon', 'mod_dataform'); // Displayed view. $options = array(0 => get_string('choosedots')); if ($this->_instance) { if ($views = mod_dataform_view_manager::instance($this->_instance)->views_menu) { $options = $options + $views; } } $mform->addElement('select', 'inlineview', get_string('inlineview', 'mod_dataform'), $options); $mform->addHelpButton('inlineview', 'inlineview', 'mod_dataform'); // Embedded. $mform->addElement('selectyesno', 'embedded', get_string('embedded', 'mod_dataform')); $mform->addHelpButton('embedded', 'embedded', 'mod_dataform'); $mform->disabledIf('embedded', 'inlineview', 'eq', 0); }
function data_preprocessing($question) { if (isset($question->options)) { $answers = $question->options->answers; $answers_ids = array(); if (count($answers)) { $key = 0; foreach ($answers as $answer) { $answers_ids[] = $answer->id; $default_values['answer[' . $key . ']'] = $answer->answer; $default_values['fraction[' . $key . ']'] = $answer->fraction; $default_values['feedback[' . $key . ']'] = array(); // prepare feedback editor to display files in draft area $draftid_editor = file_get_submitted_draft_itemid('feedback[' . $key . ']'); $default_values['feedback[' . $key . ']']['text'] = file_prepare_draft_area($draftid_editor, $this->context->id, 'question', 'answerfeedback', !empty($answer->id) ? (int) $answer->id : null, $this->fileoptions, $answer->feedback); $default_values['feedback[' . $key . ']']['itemid'] = $draftid_editor; // prepare files code block ends $default_values['feedback[' . $key . ']']['format'] = $answer->feedbackformat; $key++; } } $default_values['usecase'] = $question->options->usecase; $question = (object) ((array) $question + $default_values); } return $question; }
function set_data($question) { if (!empty($question->options->trueanswer)) { $trueanswer = $question->options->answers[$question->options->trueanswer]; $draftid = file_get_submitted_draft_itemid('trueanswer'); $answerid = $question->options->trueanswer; $text = $trueanswer->feedback; $question->correctanswer = $trueanswer->fraction != 0; $question->feedbacktrue = array(); $question->feedbacktrue['text'] = $trueanswer->feedback; $question->feedbacktrue['format'] = $trueanswer->feedbackformat; $question->feedbacktrue['text'] = file_prepare_draft_area($draftid, $this->context->id, 'question', 'answerfeedback', !empty($answerid) ? (int) $answerid : null, $this->fileoptions, $text); $question->feedbacktrue['itemid'] = $draftid; } if (!empty($question->options->falseanswer)) { $falseanswer = $question->options->answers[$question->options->falseanswer]; $draftid = file_get_submitted_draft_itemid('falseanswer'); $answerid = $question->options->falseanswer; $text = $falseanswer->feedback; $question->feedbackfalse = array(); $question->feedbackfalse['text'] = $falseanswer->feedback; $question->feedbackfalse['format'] = $falseanswer->feedbackformat; $question->feedbackfalse['text'] = file_prepare_draft_area($draftid, $this->context->id, 'question', 'answerfeedback', !empty($answerid) ? (int) $answerid : null, $this->fileoptions, $text); $question->feedbackfalse['itemid'] = $draftid; } parent::set_data($question); }
function data_preprocessing(&$default_values) { // Aaah.. we meet again h5pfile! $draftitemid = file_get_submitted_draft_itemid('h5pfile'); file_prepare_draft_area($draftitemid, $this->context->id, 'mod_hvp', 'package', 0); $default_values['h5pfile'] = $draftitemid; }
public function test_upgrade_fix_missing_root_folders_draft() { global $DB, $SITE; $this->resetAfterTest(true); $user = $this->getDataGenerator()->create_user(); $usercontext = context_user::instance($user->id); $this->setUser($user); $resource1 = $this->getDataGenerator()->get_plugin_generator('mod_resource')->create_instance(array('course' => $SITE->id)); $context = context_module::instance($resource1->cmid); $draftitemid = 0; file_prepare_draft_area($draftitemid, $context->id, 'mod_resource', 'content', 0); $queryparams = array('component' => 'user', 'contextid' => $usercontext->id, 'filearea' => 'draft', 'itemid' => $draftitemid); // Make sure there are two records in files for the draft file area and one of them has filename '.'. $records = $DB->get_records_menu('files', $queryparams, '', 'id, filename'); $this->assertEquals(2, count($records)); $this->assertTrue(in_array('.', $records)); $originalhash = $DB->get_field('files', 'pathnamehash', $queryparams + array('filename' => '.')); // Delete record with filename '.' and make sure it does not exist any more. $DB->delete_records('files', $queryparams + array('filename' => '.')); $records = $DB->get_records_menu('files', $queryparams, '', 'id, filename'); $this->assertEquals(1, count($records)); $this->assertFalse(in_array('.', $records)); // Run upgrade script and make sure the record is restored. upgrade_fix_missing_root_folders_draft(); $records = $DB->get_records_menu('files', $queryparams, '', 'id, filename'); $this->assertEquals(2, count($records)); $this->assertTrue(in_array('.', $records)); $newhash = $DB->get_field('files', 'pathnamehash', $queryparams + array('filename' => '.')); $this->assertEquals($originalhash, $newhash); }
protected function data_preprocessing($question) { $question = parent::data_preprocessing($question); if (empty($question->options)) { return $question; } $question->responseformat = $question->options->responseformat; $question->responsefieldlines = $question->options->responsefieldlines; $question->attachments = $question->options->attachments; $draftid = file_get_submitted_draft_itemid('graderinfo'); $question->graderinfo = array(); $question->graderinfo['text'] = file_prepare_draft_area( $draftid, // draftid $this->context->id, // context 'qtype_essay', // component 'graderinfo', // filarea !empty($question->id) ? (int) $question->id : null, // itemid $this->fileoptions, // options $question->options->graderinfo // text ); $question->graderinfo['format'] = $question->options->graderinfoformat; $question->graderinfo['itemid'] = $draftid; return $question; }
function set_data($defaults) { if (!empty($this->block->config) && is_object($this->block->config)) { $whatshot = $this->block->config->whatshot; $draftid_editor = file_get_submitted_draft_itemid('config_whatshot'); if (empty($whatshot)) { $currenttext = ''; } else { $currenttext = $whatshot; } $defaults->config_whatshot['text'] = file_prepare_draft_area($draftid_editor, $this->block->context->id, 'block_dashboard', 'content', 0, array('subdirs' => true), $currenttext); $defaults->config_whatshot['itemid'] = $draftid_editor; $defaults->config_whatshot['format'] = $this->block->config->format; } else { $whatshot = ''; } if (!$this->block->user_can_edit() && !empty($this->block->config->title)) { // If a title has been set but the user cannot edit it format it nicely $title = $this->block->config->title; $defaults->config_title = format_string($title, true, $this->page->context); // Remove the title from the config so that parent::set_data doesn't set it. unset($this->block->config->title); } // have to delete text here, otherwise parent::set_data will empty content // of editor unset($this->block->config->whatshot); parent::set_data($defaults); // restore $text $this->block->config->whatshot = $whatshot; if (isset($title)) { // Reset the preserved title $this->block->config->title = $title; } }
function data_preprocessing(&$default_values) { if ($this->current->instance) { // editing existing instance - copy existing files into draft area $draftitemid = file_get_submitted_draft_itemid('files'); file_prepare_draft_area($draftitemid, $this->context->id, 'mod_folder', 'content', 0, array('subdirs'=>true)); $default_values['files'] = $draftitemid; } }
public function prepare_message_for_edit($cm, $post) { $this->append_edited_by($post); $context = \context_module::instance($cm->id); $post = trusttext_pre_edit($post, 'message', $context); $itemid = file_get_submitted_draft_itemid('message'); $message = file_prepare_draft_area($itemid, $context->id, 'mod_hsuforum', 'post', $post->id, \mod_hsuforum_post_form::editor_options($context, $post->id), $post->message); return array($message, $itemid); }
/** * Fill in the current page data for this customcert. */ public function definition_after_data() { $mform = $this->_form; // Editing existing instance - copy existing files into draft area. $draftitemid = file_get_submitted_draft_itemid('customcertimage'); file_prepare_draft_area($draftitemid, context_system::instance()->id, 'mod_customcert', 'image', 0, $this->filemanageroptions); $element = $mform->getElement('customcertimage'); $element->setValue($draftitemid); }
function set_data($defaults) { global $COURSE; if (!$this->block->user_can_edit()) { if (!empty($this->block->config->title)) { // If a title has been set but the user cannot edit it format it nicely $title = $this->block->config->title; $defaults->config_title = format_string($title, true, $this->page->context); // Remove the title from the config so that parent::set_data doesn't set it. unset($this->block->config->title); } if (!empty($this->block->config->imagespot)) { $fileoptions = array('subdirs' => false, 'maxfiles' => 1, 'maxbytes' => $COURSE->maxbytes, 'accepted_types' => 'web_image', 'return_types' => FILE_INTERNAL); $draftitemid = ''; file_prepare_draft_area($draftitemid, $this->block->context->id, 'block_informationspot', 'image', 0, $fileoptions); $defaults->config_imagespot = $draftitemid; unset($this->block->config->imagespot); } if (!empty($this->block->config->text)) { $text = $this->block->config->text; $defaults->config_text = format_text($text, true, $this->page->context); unset($this->block->config->text); } if (!empty($this->block->config->buttontext)) { $buttontext = $this->block->config->buttontext; $defaults->config_buttontext = format_string($buttontext, true, $this->page->context); unset($this->block->config->buttontext); } if (!empty($this->block->config->buttonlink)) { $buttonlink = $this->block->config->buttonlink; $defaults->config_buttonlink = $buttonlink; unset($this->block->config->buttonlink); } } parent::set_data($defaults); if (!isset($this->block->config)) { $this->block->config = new stdClass(); } if (isset($title)) { $this->block->config->title = $title; } if (isset($draftitemid)) { $this->block->config->imagespot = $draftitemid; } if (isset($title)) { $this->block->config->title = $title; } if (isset($text)) { $this->block->config->text = $text; } if (isset($buttontext)) { $this->block->config->buttontext = $buttontext; } if (isset($buttonlink)) { $this->block->config->buttonlink = $title; } }
function display_add_field($recordid = 0) { global $CFG, $DB, $OUTPUT, $PAGE, $USER; $file = false; $content = false; $displayname = ''; $fs = get_file_storage(); $context = $PAGE->context; $itemid = null; // editing an existing database entry if ($recordid) { if ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) { file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id); if (!empty($content->content)) { if ($file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) { $usercontext = context_user::instance($USER->id); if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $itemid, 'id DESC', false))) { return false; } if (empty($content->content1)) { // Print icon if file already exists $src = moodle_url::make_draftfile_url($itemid, '/', $file->get_filename()); $displayname = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')) . '<a href="' . $src . '" >' . s($file->get_filename()) . '</a>'; } else { $displayname = 'no file added'; } } } } } else { $itemid = file_get_unused_draft_itemid(); } $html = ''; // database entry label $html .= '<div title="' . s($this->field->description) . '">'; $html .= '<fieldset><legend><span class="accesshide">' . $this->field->name . '</span></legend>'; // itemid element $html .= '<input type="hidden" name="field_' . $this->field->id . '_file" value="' . $itemid . '" />'; $options = new stdClass(); $options->maxbytes = $this->field->param3; $options->maxfiles = 1; // Limit to one file for the moment, this may be changed if requested as a feature in the future. $options->itemid = $itemid; $options->accepted_types = '*'; $options->return_types = FILE_INTERNAL; $options->context = $PAGE->context; $fm = new form_filemanager($options); // Print out file manager. $output = $PAGE->get_renderer('core', 'files'); $html .= $output->render($fm); $html .= '</fieldset>'; $html .= '</div>'; $module = array('name' => 'form_filemanager', 'fullpath' => '/lib/form/filemanager.js', 'requires' => array('core_filepicker', 'base', 'io-base', 'node', 'json', 'core_dndupload', 'panel', 'resize-plugin', 'dd-plugin'), 'strings' => array(array('error', 'moodle'), array('info', 'moodle'), array('confirmdeletefile', 'repository'), array('draftareanofiles', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'), array('invalidjson', 'repository'), array('popupblockeddownload', 'repository'), array('unknownoriginal', 'repository'), array('confirmdeletefolder', 'repository'), array('confirmdeletefilewithhref', 'repository'), array('confirmrenamefolder', 'repository'), array('confirmrenamefile', 'repository'), array('edit', 'moodle'))); $PAGE->requires->js_init_call('M.form_filemanager.init', array($fm->options), true, $module); return $html; }
/** * Returns an XHTML string for the editor * * @param string $data * @param string $query * @return string XHTML string for the editor */ public function output_html($data, $query = '') { global $USER; $default = $this->get_defaultsetting(); $defaultinfo = $default; if (!is_null($default) and $default !== '') { $defaultinfo = "\n" . $default; } $ctx = context_user::instance($USER->id); $editor = editors_get_preferred_editor(FORMAT_HTML); $options = $this->get_options(); $draftitemid = file_get_unused_draft_itemid(); $component = is_null($this->plugin) ? 'core' : $this->plugin; $data = file_prepare_draft_area($draftitemid, $options['context']->id, $component, $this->get_full_name() . '_draftitemid', $draftitemid, $options, $data); $fpoptions = array(); $args = new stdClass(); // need these three to filter repositories list $args->accepted_types = array('web_image'); $args->return_types = $options['return_types']; $args->context = $ctx; $args->env = 'filepicker'; // advimage plugin $image_options = initialise_filepicker($args); $image_options->context = $ctx; $image_options->client_id = uniqid(); $image_options->maxbytes = $options['maxbytes']; $image_options->areamaxbytes = $options['areamaxbytes']; $image_options->env = 'editor'; $image_options->itemid = $draftitemid; // moodlemedia plugin $args->accepted_types = array('video', 'audio'); $media_options = initialise_filepicker($args); $media_options->context = $ctx; $media_options->client_id = uniqid(); $media_options->maxbytes = $options['maxbytes']; $media_options->areamaxbytes = $options['areamaxbytes']; $media_options->env = 'editor'; $media_options->itemid = $draftitemid; // advlink plugin $args->accepted_types = '*'; $link_options = initialise_filepicker($args); $link_options->context = $ctx; $link_options->client_id = uniqid(); $link_options->maxbytes = $options['maxbytes']; $link_options->areamaxbytes = $options['areamaxbytes']; $link_options->env = 'editor'; $link_options->itemid = $draftitemid; $fpoptions['image'] = $image_options; $fpoptions['media'] = $media_options; $fpoptions['link'] = $link_options; $editor->use_editor($this->get_id(), $options, $fpoptions); return format_admin_setting($this, $this->visiblename, '<div class="form-textarea"><textarea rows="' . $this->rows . '" cols="' . $this->cols . '" id="' . $this->get_id() . '" name="' . $this->get_full_name() . '" spellcheck="true">' . s($data) . '</textarea></div> <input value="' . $draftitemid . '" name="' . $this->get_full_name() . '_draftitemid" type="hidden" />', $this->description, true, '', $defaultinfo, $query); }
function display_add_field($recordid = 0) { global $CFG, $DB, $OUTPUT, $PAGE, $USER; $file = false; $content = false; $displayname = ''; $fs = get_file_storage(); $context = $PAGE->context; $itemid = null; // editing an existing database entry if ($recordid) { if ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) { file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id); if (!empty($content->content)) { if ($file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) { $usercontext = context_user::instance($USER->id); if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $itemid, 'id DESC', false))) { return false; } if (empty($content->content1)) { // Print icon if file already exists $src = moodle_url::make_draftfile_url($itemid, '/', $file->get_filename()); $displayname = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')) . '<a href="' . $src . '" >' . s($file->get_filename()) . '</a>'; } else { $displayname = 'no file added'; } } } } } else { $itemid = file_get_unused_draft_itemid(); } $html = ''; // database entry label $html .= '<div title="' . s($this->field->description) . '">'; $html .= '<fieldset><legend><span class="accesshide">' . $this->field->name . '</span></legend>'; // itemid element $html .= '<input type="hidden" name="field_' . $this->field->id . '_file" value="' . $itemid . '" />'; $options = new stdClass(); $options->maxbytes = $this->field->param3; $options->maxfiles = 1; // Limit to one file for the moment, this may be changed if requested as a feature in the future. $options->itemid = $itemid; $options->accepted_types = '*'; $options->return_types = FILE_INTERNAL; $options->context = $PAGE->context; $fm = new form_filemanager($options); // Print out file manager. $output = $PAGE->get_renderer('core', 'files'); $html .= $output->render($fm); $html .= '</fieldset>'; $html .= '</div>'; return $html; }
function display_add_field($recordid = 0) { global $CFG, $DB, $OUTPUT, $PAGE, $USER; $file = false; $content = false; $displayname = ''; $fs = get_file_storage(); $context = $PAGE->context; $itemid = null; // editing an existing database entry if ($recordid) { if ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) { file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id); if (!empty($content->content)) { if ($file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) { $usercontext = get_context_instance(CONTEXT_USER, $USER->id); if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $itemid, 'id DESC', false))) { return false; } if (empty($content->content1)) { // Print icon if file already exists $src = moodle_url::make_draftfile_url($itemid, '/', $file->get_filename()); $displayname = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')) . '<a href="' . $src . '" >' . s($file->get_filename()) . '</a>'; } else { $displayname = 'no file added'; } } } } } else { $itemid = file_get_unused_draft_itemid(); } $html = ''; // database entry label $html .= '<div title="' . s($this->field->description) . '">'; $html .= '<fieldset><legend><span class="accesshide">' . $this->field->name . '</span></legend>'; // itemid element $html .= '<input type="hidden" name="field_' . $this->field->id . '_file" value="' . $itemid . '" />'; $options = new stdClass(); $options->maxbytes = $this->field->param3; $options->itemid = $itemid; $options->accepted_types = '*'; $options->return_types = FILE_INTERNAL; $options->context = $PAGE->context; $fp = new file_picker($options); // print out file picker $html .= $OUTPUT->render($fp); $html .= '</fieldset>'; $html .= '</div>'; $module = array('name' => 'data_filepicker', 'fullpath' => '/mod/data/data.js', 'requires' => array('core_filepicker')); $PAGE->requires->js_init_call('M.data_filepicker.init', array($fp->options), true, $module); return $html; }
function data_preprocessing($question) { if (!empty($question->options) && !empty($question->options->answers)) { $answer = reset($question->options->answers); $question->feedback = array(); $draftid = file_get_submitted_draft_itemid('feedback'); $question->feedback['text'] = file_prepare_draft_area($draftid, $this->context->id, 'question', 'answerfeedback', !empty($answer->id) ? (int) $answer->id : null, $this->fileoptions, $answer->feedback); $question->feedback['format'] = $answer->feedbackformat; $question->feedback['itemid'] = $draftid; } $question->penalty = 0; return $question; }
protected function data_preprocessing($question) { $question = parent::data_preprocessing($question); if (empty($question->options)) { return $question; } $question->responseformat = $question->options->responseformat; $question->responsefieldlines = $question->options->responsefieldlines; $question->attachments = $question->options->attachments; $draftid = file_get_submitted_draft_itemid('graderinfo'); $question->graderinfo = array(); $question->graderinfo['text'] = file_prepare_draft_area($draftid, $this->context->id, 'qtype_poodllrecording', 'graderinfo', !empty($question->id) ? (int) $question->id : null, $this->fileoptions, $question->options->graderinfo); $question->graderinfo['format'] = $question->options->graderinfoformat; $question->graderinfo['itemid'] = $draftid; return $question; }
function flashcard_filepicker($elname, $value, $contextid, $filearea, $cardid, $maxbytes, $accepted_types = '*') { global $COURSE, $PAGE, $OUTPUT, $USER; $html = ''; $usercontext = context_user::instance($USER->id); $fs = get_file_storage(); // no existing area info provided - let's use fresh new draft area if ($value) { $draftitemid = file_get_submitted_draft_itemid($filearea); $maxbytes = 100000; file_prepare_draft_area($draftitemid, $contextid, 'mod_flashcard', $filearea, $cardid, array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => 1)); } else { $draftitemid = file_get_unused_draft_itemid(); } if ($COURSE->id == SITEID) { $context = get_context_instance(CONTEXT_SYSTEM); } else { $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); } $client_id = uniqid(); $args = new stdClass(); // need these three to filter repositories list $args->accepted_types = $accepted_types; $args->return_types = FILE_INTERNAL; $args->itemid = $draftitemid; $args->maxbytes = $maxbytes; $args->buttonname = $elname . 'choose'; $args->elementname = $elname; $id = $elname; $fp = new file_picker($args); $options = $fp->options; $options->context = $PAGE->context; $html .= $OUTPUT->render($fp); $html .= '<input type="hidden" name="' . $elname . '" id="' . $id . '" value="' . $draftitemid . '" class="filepickerhidden"/>'; $module = array('name' => 'form_filepicker', 'fullpath' => '/lib/form/filepicker.js', 'requires' => array('core_filepicker', 'node', 'node-event-simulate')); $PAGE->requires->js_init_call('M.form_filepicker.init', array($fp->options), true, $module); $nonjsfilepicker = new moodle_url('/repository/draftfiles_manager.php', array('env' => 'filepicker', 'action' => 'browse', 'itemid' => $draftitemid, 'subdirs' => 0, 'maxbytes' => $options->maxbytes, 'maxfiles' => 1, 'ctx_id' => $PAGE->context->id, 'course' => $PAGE->course->id, 'sesskey' => sesskey())); // non js file picker $html .= '<noscript>'; $html .= "<div><object type='text/html' data='{$nonjsfilepicker}' height='160' width='600' style='border:1px solid #000'></object></div>"; $html .= '</noscript>'; return $html; }
function display_add_field($recordid = 0) { global $CFG, $DB, $OUTPUT, $PAGE, $USER; $text = ''; $format = 0; $str = '<div title="' . $this->field->description . '">'; editors_head_setup(); $options = $this->get_options(); $itemid = $this->field->id; $field = 'field_' . $itemid; if ($recordid && ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid)))) { $format = $content->content1; $text = clean_text($content->content, $format); $text = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_data', 'content', $content->id, $options, $text); } else { $draftitemid = file_get_unused_draft_itemid(); } $updatecontrol = $field; $idcontrol = $field . '_itemid'; $str .= '<input type="hidden" id="' . $updatecontrol . '" name="' . $updatecontrol . '" value="empty" />'; $str .= '<input type="hidden" name="' . $idcontrol . '" value="' . $draftitemid . '" />'; // $type = DBP_AUDIOMP3; $usercontextid = context_user::instance($USER->id)->id; switch ($this->field->param4) { case DBP_AUDIO: $str .= fetchAudioRecorderForSubmission('auto', 'ignore', $updatecontrol, $usercontextid, "user", "draft", $draftitemid); break; case DBP_VIDEO: $str .= fetchVideoRecorderForSubmission('auto', 'ignore', $updatecontrol, $usercontextid, "user", "draft", $draftitemid); break; case DBP_AUDIOMP3: $str .= fetchMP3RecorderForSubmission($updatecontrol, $usercontextid, "user", "draft", $draftitemid); break; case DBP_WHITEBOARDSIMPLE: case DBP_WHITEBOARDFULL: $str .= fetchWhiteboardForSubmission($updatecontrol, $usercontextid, "user", "draft", $draftitemid); break; case DBP_SNAPSHOT: $str .= fetchSnapshotCameraForSubmission($updatecontrol, 'apic.jpg', 350, 400, $usercontextid, "user", "draft", $draftitemid); break; } return $str; }
public function initialise_form() { global $CFG, $USER; require_once $CFG->dirroot . '/mod/dialogue/formlib.php'; $cm = $this->dialogue->cm; $context = $this->dialogue->context; $dialogueid = $this->dialogue->dialogueid; $conversationid = $this->conversation->conversationid; $form = new \mod_dialogue_reply_form('reply.php'); // point specifically // setup important hiddens $form->set_data(array('id' => $cm->id)); $form->set_data(array('dialogueid' => $dialogueid)); $form->set_data(array('conversationid' => $conversationid)); $form->set_data(array('messageid' => $this->_messageid)); if (is_null($this->_messageid)) { $form->set_data(array('action' => 'create')); } else { $form->set_data(array('action' => 'edit')); } // setup body, set new $draftitemid directly on _bodydraftid and rewritten // html on _body $this->_body = file_prepare_draft_area($this->_bodydraftid, $context->id, 'mod_dialogue', 'message', $this->_messageid, \mod_dialogue_reply_form::editor_options(), $this->_body); $form->set_data(array('body' => array('text' => $this->_body, 'format' => $this->_bodyformat, 'itemid' => $this->_bodydraftid))); // setup attachments, set new $draftitemid directly on _attachmentsdraftid file_prepare_draft_area($this->_attachmentsdraftid, $context->id, 'mod_dialogue', 'attachment', $this->_messageid, \mod_dialogue_reply_form::attachment_options()); // using a post array for attachments $form->set_data(array('attachments[itemid]' => $this->_attachmentsdraftid)); // remove any form buttons the user shouldn't have if ($this->conversation->state == dialogue::STATE_CLOSED) { $form->remove_from_group('send', 'actionbuttongroup'); } // remove any unecessary buttons if ($USER->id != $this->author->id or is_null($this->messageid)) { $form->remove_from_group('delete', 'actionbuttongroup'); } // remove any unecessary buttons if ($USER->id != $this->author->id or is_null($this->messageid)) { $form->remove_from_group('trash', 'actionbuttongroup'); } return $this->_form = $form; }
/** * Form definition: creates the file manager interface using standard Moodle code, then * stores the session draft ID so that it can be retrieved. This draft ID is new for * every session, but does not change as files are picked. * */ public function definition() { $mform =& $this->_form; // Grab max attachment size from config. $maxbytes = get_config('course_message', 'Attachment_Size'); $elementname = 'attachments' . $this->idmodifier; // Create a filemanager interface - label is now set since behat testing uses this parameter. $mform->addElement('filemanager', $elementname, $this->idmodifier . ' files', null, array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => BLOCK_CM_MAX_FILES)); // Setup the "entry" object. $entry = new stdClass(); $entry->id = null; // Setup the session (not sure why bytes, files are specified twice). $draftitemid = file_get_submitted_draft_itemid($elementname); file_prepare_draft_area($draftitemid, $this->context->id, BLOCK_CM_COMPONENT_NAME, BLOCK_CM_FILE_AREA_NAME, $entry->id, array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => BLOCK_CM_MAX_FILES)); $entry->{$elementname} = $draftitemid; // Setup the form with the entry. $this->set_data($entry); // Store the draft ID so it can be retrieved. $this->draftid = $draftitemid; }
function data_preprocessing($question) { if (isset($question->options)) { $subquestions = $question->options->subquestions; if (count($subquestions)) { $key = 0; foreach ($subquestions as $subquestion) { $default_values['subanswers[' . $key . ']'] = $subquestion->answertext; $draftid = file_get_submitted_draft_itemid('subquestions[' . $key . ']'); $default_values['subquestions[' . $key . ']'] = array(); $default_values['subquestions[' . $key . ']']['format'] = $subquestion->questiontextformat; $default_values['subquestions[' . $key . ']']['text'] = file_prepare_draft_area($draftid, $this->context->id, 'qtype_match', 'subquestion', !empty($subquestion->id) ? (int) $subquestion->id : null, $this->fileoptions, $subquestion->questiontext); $default_values['subquestions[' . $key . ']']['itemid'] = $draftid; $key++; } } $default_values['shuffleanswers'] = $question->options->shuffleanswers; $question = (object) ((array) $question + $default_values); } return $question; }
function set_data($defaults) { if (!empty($this->block->config) && is_object($this->block->config)) { $text = $this->block->config->text; $draftid_editor = file_get_submitted_draft_itemid('config_text'); if (empty($text)) { $currenttext = ''; } else { $currenttext = $text; } $defaults->config_text['text'] = file_prepare_draft_area($draftid_editor, $this->block->context->id, 'block_html', 'content', 0, array('subdirs' => true), $currenttext); $defaults->config_text['itemid'] = $draftid_editor; $defaults->config_text['format'] = $this->block->config->format; } else { $text = ''; } // have to delete text here, otherwise parent::set_data will empty content // of editor unset($this->block->config->text); parent::set_data($defaults); // restore $text $this->block->config->text = $text; }
function data_preprocessing($question) { global $QTYPES; if (isset($question->options)) { $answers = $question->options->answers; if (count($answers)) { $key = 0; foreach ($answers as $answer) { $draftid = file_get_submitted_draft_itemid('feedback[' . $key . ']'); $default_values['answer[' . $key . ']'] = $answer->answer; $default_values['fraction[' . $key . ']'] = $answer->fraction; $default_values['tolerance[' . $key . ']'] = $answer->tolerance; $default_values['feedback[' . $key . ']'] = array(); $default_values['feedback[' . $key . ']']['format'] = $answer->feedbackformat; $default_values['feedback[' . $key . ']']['text'] = file_prepare_draft_area($draftid, $this->context->id, 'question', 'answerfeedback', !empty($answer->id) ? (int) $answer->id : null, $this->fileoptions, $answer->feedback); $default_values['feedback[' . $key . ']']['itemid'] = $draftid; $key++; } } $QTYPES['numerical']->set_numerical_unit_data($this, $question, $default_values); $question = (object) ((array) $question + $default_values); } return $question; }
// Process email change cancellation. if ($cancelemailchange) { cancel_email_update($user->id); } // Load user preferences. useredit_load_preferences($user); // Load custom profile fields data. profile_load_data($user); // Prepare the editor and create form. $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'maxbytes' => $CFG->maxbytes, 'trusttext' => false, 'forcehttps' => false, 'context' => $personalcontext); $user = file_prepare_standard_editor($user, 'description', $editoroptions, $personalcontext, 'user', 'profile', 0); // Prepare filemanager draft area. $draftitemid = 0; $filemanagercontext = $editoroptions['context']; $filemanageroptions = array('maxbytes' => $CFG->maxbytes, 'subdirs' => 0, 'maxfiles' => 1, 'accepted_types' => 'web_image'); file_prepare_draft_area($draftitemid, $filemanagercontext->id, 'user', 'newicon', 0, $filemanageroptions); $user->imagefile = $draftitemid; // Create form. $userform = new user_edit_form(new moodle_url($PAGE->url, array('returnto' => $returnto)), array('editoroptions' => $editoroptions, 'filemanageroptions' => $filemanageroptions, 'user' => $user)); $emailchanged = false; if ($usernew = $userform->get_data()) { // Deciding where to send the user back in most cases. if ($returnto === 'profile') { if ($course->id != SITEID) { $returnurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)); } else { $returnurl = new moodle_url('/user/profile.php', array('id' => $user->id)); } } else { // $returnurl = new moodle_url('/user/preferences.php', array('userid' => $user->id)); // Changed redirect to Dashboard