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)); } }
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; }
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); }
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; }
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; } }
/** * */ 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); }
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); 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; $question->responselimitpolicy = $question->options->responselimitpolicy; $question->wordlimit = $question->options->wordlimit; $question->charlimit = $question->options->charlimit; return $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; }
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 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; }
function set_data($defaults) { $block_config = new Object(); $block_config->notify_by_email = file_get_submitted_draft_itemid('notify_by_email'); $block_config->notify_by_sms = file_get_submitted_draft_itemid('notify_by_sms'); $block_config->notify_by_rss = file_get_submitted_draft_itemid('notify_by_rss'); $block_config->notification_frequency = file_get_submitted_draft_itemid('notification_frequency'); $block_config->email_notification_preset = file_get_submitted_draft_itemid('email_notification_preset'); $block_config->sms_notification_preset = file_get_submitted_draft_itemid('sms_notification_preset'); unset($this->block->config->text); parent::set_data($defaults); $this->block->config = $block_config; }
function slideshow_update_instance($data, $mform) { global $CFG, $DB; $cmid = $data->coursemodule; $draftitemid = $data->location; $data->timemodified = time(); $data->id = $data->instance; $DB->update_record("slideshow", $data); $context = get_context_instance(CONTEXT_MODULE, $cmid); if ($draftitemid = file_get_submitted_draft_itemid('location')) { file_save_draft_area_files($draftitemid, $context->id, 'mod_slideshow', 'content', 0, array('subdirs' => true)); } return true; }
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; }
public function data_preprocessing(&$defaultvalues) { global $DB; $content = null; if (!empty($defaultvalues['id'])) { // Load Content $core = \mod_hvp\framework::instance(); $content = $core->loadContent($defaultvalues['id']); if ($content === null) { print_error('invalidhvp'); } } // Aaah.. we meet again h5pfile! $draftitemid = file_get_submitted_draft_itemid('h5pfile'); file_prepare_draft_area($draftitemid, $this->context->id, 'mod_hvp', 'package', 0); $defaultvalues['h5pfile'] = $draftitemid; // Individual display options are not stored, must be extracted from disable. if (isset($defaultvalues['disable'])) { // Extract disable options. \mod_hvp\framework::instance(); foreach (\H5PCore::$disable as $bit => $option) { if ($defaultvalues['disable'] & $bit) { // Disable. $defaultvalues[$option] = 0; } else { // Enable. $defaultvalues[$option] = 1; } } } // Determine default action if ($content === null && $DB->get_field_sql("SELECT id FROM {hvp_libraries} WHERE runnable = 1", null, IGNORE_MULTIPLE) === false) { $defaultvalues['h5paction'] = 'upload'; } // Set editor defaults $defaultvalues['h5plibrary'] = $content === null ? 0 : H5PCore::libraryToString($content['library']); $defaultvalues['h5pparams'] = $content === null ? '{}' : $core->filterParameters($content); // Add required editor assets. require_once 'locallib.php'; \hvp_add_editor_assets($content === null ? null : $defaultvalues['id']); // Log editor opened if ($content === null) { new \mod_hvp\event('content', 'new'); } else { new \mod_hvp\event('content', 'edit', $content['id'], $content['title'], $content['library']['name'], $content['library']['majorVersion'] . '.' . $content['library']['minorVersion']); } }
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; }
/** * 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; }
/** * Prints default edit form fields and buttons * * @param string $format Edit form format (html, creole...) * @param integer $version Version number. A negative number means no versioning. */ function wiki_print_edit_form_default_fields($format, $pageid, $version = -1, $upload = false, $deleteuploads = array()) { global $CFG, $PAGE, $OUTPUT; echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />'; if ($version >= 0) { echo '<input type="hidden" name="version" value="' . $version . '" />'; } echo '<input type="hidden" name="format" value="' . $format . '"/>'; //attachments require_once $CFG->dirroot . '/lib/form/filemanager.php'; $filemanager = new MoodleQuickForm_filemanager('attachments', get_string('wikiattachments', 'wiki'), array('id' => 'attachments'), array('subdirs' => false, 'maxfiles' => 99, 'maxbytes' => $CFG->maxbytes)); $value = file_get_submitted_draft_itemid('attachments'); if (!empty($value) && !$upload) { $filemanager->setValue($value); } echo "<fieldset class=\"wiki-upload-section clearfix\"><legend class=\"ftoggler\">" . get_string("uploadtitle", 'wiki') . "</legend>"; echo $OUTPUT->container_start('mdl-align wiki-form-center aaaaa'); print $filemanager->toHtml(); echo $OUTPUT->container_end(); $cm = $PAGE->cm; $context = get_context_instance(CONTEXT_MODULE, $cm->id); echo $OUTPUT->container_start('mdl-align wiki-form-center wiki-upload-table'); wiki_print_upload_table($context, 'wiki_upload', $pageid, $deleteuploads); echo $OUTPUT->container_end(); echo "</fieldset>"; echo '<input class="wiki_button" type="submit" name="editoption" value="' . get_string('save', 'wiki') . '"/>'; echo '<input class="wiki_button" type="submit" name="editoption" value="' . get_string('upload', 'wiki') . '"/>'; echo '<input class="wiki_button" type="submit" name="editoption" value="' . get_string('preview') . '"/>'; echo '<input class="wiki_button" type="submit" name="editoption" value="' . get_string('cancel') . '" />'; }
/** * Given an object containing all the necessary data, * (defined by the form in mod_form.php) this function * will update an existing instance with new data. * * @global object * @param object $forum forum instance (with magic quotes) * @return bool success */ function forum_update_instance($forum, $mform) { global $DB, $OUTPUT, $USER; $forum->timemodified = time(); $forum->id = $forum->instance; if (empty($forum->assessed)) { $forum->assessed = 0; } if (empty($forum->ratingtime) or empty($forum->assessed)) { $forum->assesstimestart = 0; $forum->assesstimefinish = 0; } $oldforum = $DB->get_record('forum', array('id'=>$forum->id)); // MDL-3942 - if the aggregation type or scale (i.e. max grade) changes then recalculate the grades for the entire forum // if scale changes - do we need to recheck the ratings, if ratings higher than scale how do we want to respond? // for count and sum aggregation types the grade we check to make sure they do not exceed the scale (i.e. max score) when calculating the grade if (($oldforum->assessed<>$forum->assessed) or ($oldforum->scale<>$forum->scale)) { forum_update_grades($forum); // recalculate grades for the forum } if ($forum->type == 'single') { // Update related discussion and post. $discussions = $DB->get_records('forum_discussions', array('forum'=>$forum->id), 'timemodified ASC'); if (!empty($discussions)) { if (count($discussions) > 1) { echo $OUTPUT->notification(get_string('warnformorepost', 'forum')); } $discussion = array_pop($discussions); } else { // try to recover by creating initial discussion - MDL-16262 $discussion = new stdClass(); $discussion->course = $forum->course; $discussion->forum = $forum->id; $discussion->name = $forum->name; $discussion->assessed = $forum->assessed; $discussion->message = $forum->intro; $discussion->messageformat = $forum->introformat; $discussion->messagetrust = true; $discussion->mailnow = false; $discussion->groupid = -1; $message = ''; forum_add_discussion($discussion, null, $message); if (! $discussion = $DB->get_record('forum_discussions', array('forum'=>$forum->id))) { print_error('cannotadd', 'forum'); } } if (! $post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost))) { print_error('cannotfindfirstpost', 'forum'); } $cm = get_coursemodule_from_instance('forum', $forum->id); $modcontext = context_module::instance($cm->id, MUST_EXIST); $post = $DB->get_record('forum_posts', array('id'=>$discussion->firstpost), '*', MUST_EXIST); $post->subject = $forum->name; $post->message = $forum->intro; $post->messageformat = $forum->introformat; $post->messagetrust = trusttext_trusted($modcontext); $post->modified = $forum->timemodified; $post->userid = $USER->id; // MDL-18599, so that current teacher can take ownership of activities. if ($mform and $draftid = file_get_submitted_draft_itemid('introeditor')) { // Ugly hack - we need to copy the files somehow. $options = array('subdirs'=>true); // Use the same options as intro field! $post->message = file_save_draft_area_files($draftid, $modcontext->id, 'mod_forum', 'post', $post->id, $options, $post->message); } $DB->update_record('forum_posts', $post); $discussion->name = $forum->name; $DB->update_record('forum_discussions', $discussion); } $DB->update_record('forum', $forum); $modcontext = context_module::instance($forum->coursemodule); if (($forum->forcesubscribe == FORUM_INITIALSUBSCRIBE) && ($oldforum->forcesubscribe <> $forum->forcesubscribe)) { $users = forum_get_potential_subscribers($modcontext, 0, 'u.id, u.email', ''); foreach ($users as $user) { forum_subscribe($user->id, $forum->id); } } forum_grade_item_update($forum); return true; }
function data_preprocessing($question) { $default_values['multichoice'] = $this->editasmultichoice; //$this->editasmultichoice ; 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['tolerancetype[' . $key . ']'] = $answer->tolerancetype; $default_values['correctanswerlength[' . $key . ']'] = $answer->correctanswerlength; $default_values['correctanswerformat[' . $key . ']'] = $answer->correctanswerformat; $default_values['feedback[' . $key . ']'] = array(); // prepare draftarea $default_values['feedback[' . $key . ']']['text'] = file_prepare_draft_area($draftid, $this->context->id, 'question', 'answerfeedback', empty($answer->id) ? null : (int) $answer->id, $this->fileoptions, $answer->feedback); $default_values['feedback[' . $key . ']']['format'] = $answer->feedbackformat; $default_values['feedback[' . $key . ']']['itemid'] = $draftid; $key++; } } $default_values['synchronize'] = $question->options->synchronize; if (isset($question->options->units)) { $units = array_values($question->options->units); // make sure the default unit is at index 0 usort($units, create_function('$a, $b', 'if (1.0 === (float)$a->multiplier) { return -1; } else ' . 'if (1.0 === (float)$b->multiplier) { return 1; } else { return 0; }')); if (count($units)) { $key = 0; foreach ($units as $unit) { $default_values['unit[' . $key . ']'] = $unit->unit; $default_values['multiplier[' . $key . ']'] = $unit->multiplier; $key++; } } } } if (isset($question->options->single)) { $default_values['single'] = $question->options->single; $default_values['answernumbering'] = $question->options->answernumbering; $default_values['shuffleanswers'] = $question->options->shuffleanswers; } $default_values['submitbutton'] = get_string('nextpage', 'qtype_calculated'); $default_values['makecopy'] = get_string('makecopynextpage', 'qtype_calculated'); // prepare draft files foreach (array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback') as $feedbackname) { if (!isset($question->options->{$feedbackname})) { continue; } $text = $question->options->{$feedbackname}; $draftid = file_get_submitted_draft_itemid($feedbackname); $feedbackformat = $feedbackname . 'format'; $format = $question->options->{$feedbackformat}; $default_values[$feedbackname] = array(); $default_values[$feedbackname]['text'] = file_prepare_draft_area($draftid, $this->context->id, 'qtype_calculatedmulti', $feedbackname, !empty($question->id) ? (int) $question->id : null, $this->fileoptions, $text); $default_values[$feedbackname]['format'] = $format; $default_values[$feedbackname]['itemid'] = $draftid; } /** * set the wild cards category display given that on loading the category element is * unselected when processing this function but have a valid value when processing the * update category button. The value can be obtain by * $qu->category =$this->_form->_elements[$this->_form->_elementIndex['category']]->_values[0]; * but is coded using existing functions */ $qu = new stdClass(); $el = new stdClass(); /* no need to call elementExists() here */ if ($this->_form->elementExists('category')) { $el = $this->_form->getElement('category'); } else { $el = $this->_form->getElement('categorymoveto'); } if ($value = $el->getSelected()) { $qu->category = $value[0]; } else { $qu->category = $question->category; // on load $question->category is set by question.php } $html2 = $this->qtypeobj->print_dataset_definitions_category($qu); $this->_form->_elements[$this->_form->_elementIndex['listcategory']]->_text = $html2; $question = (object) ((array) $question + $default_values); return $question; }
function update_content($recordid, $value, $name='') { global $DB; $content = new stdClass(); $content->fieldid = $this->field->id; $content->recordid = $recordid; $names = explode('_', $name); if (!empty($names[2])) { if ($names[2] == 'itemid') { // the value will be retrieved by file_get_submitted_draft_itemid, do not need to save in DB return true; } else { $content->$names[2] = clean_param($value, PARAM_NOTAGS); // content[1-4] } } else { $content->content = clean_param($value, PARAM_CLEAN); } if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $content->id = $oldcontent->id; } else { $content->id = $DB->insert_record('data_content', $content); if (!$content->id) { return false; } } if (!empty($content->content)) { $draftitemid = file_get_submitted_draft_itemid('field_'. $this->field->id. '_itemid'); $options = $this->get_options(); $content->content = file_save_draft_area_files($draftitemid, $this->context->id, 'mod_data', 'content', $content->id, $options, $content->content); } $rv = $DB->update_record('data_content', $content); return $rv; }
public function output_html($data, $query = '') { global $PAGE, $CFG; $options = $this->get_options(); $id = $this->get_id(); $elname = $this->get_full_name(); $draftitemid = file_get_submitted_draft_itemid($elname); $component = is_null($this->plugin) ? 'core' : $this->plugin; file_prepare_draft_area($draftitemid, $options['context']->id, $component, $this->filearea, $this->itemid, $options); // Filemanager form element implementation is far from optimal, we need to rework this if we ever fix it... require_once "{$CFG->dirroot}/lib/form/filemanager.php"; $fmoptions = new stdClass(); $fmoptions->mainfile = $options['mainfile']; $fmoptions->maxbytes = $options['maxbytes']; $fmoptions->maxfiles = $options['maxfiles']; $fmoptions->client_id = uniqid(); $fmoptions->itemid = $draftitemid; $fmoptions->subdirs = $options['subdirs']; $fmoptions->target = $id; $fmoptions->accepted_types = $options['accepted_types']; $fmoptions->return_types = $options['return_types']; $fmoptions->context = $options['context']; $fmoptions->areamaxbytes = $options['areamaxbytes']; $fm = new form_filemanager($fmoptions); $output = $PAGE->get_renderer('core', 'files'); $html = $output->render($fm); $html .= '<input value="' . $draftitemid . '" name="' . $elname . '" type="hidden" />'; $html .= '<input value="" id="' . $id . '" type="hidden" />'; return format_admin_setting($this, $this->visiblename, '<div class="form-filemanager">' . $html . '</div>', $this->description, true, '', '', $query); }
/** * Enforce defaults here * * @param array $defaultvalues Form defaults * @return void **/ public function data_preprocessing(&$defaultvalues) { if (isset($defaultvalues['conditions'])) { $conditions = unserialize($defaultvalues['conditions']); $defaultvalues['timespent'] = $conditions->timespent; $defaultvalues['completed'] = $conditions->completed; $defaultvalues['gradebetterthan'] = $conditions->gradebetterthan; } // Set up the completion checkbox which is not part of standard data. $defaultvalues['completiontimespentenabled'] = !empty($defaultvalues['completiontimespent']) ? 1 : 0; if ($this->current->instance) { // Editing existing instance - copy existing files into draft area. $draftitemid = file_get_submitted_draft_itemid('mediafile'); file_prepare_draft_area($draftitemid, $this->context->id, 'mod_lesson', 'mediafile', 0, array('subdirs' => 0, 'maxbytes' => $this->course->maxbytes, 'maxfiles' => 1)); $defaultvalues['mediafile'] = $draftitemid; } }
function data_preprocessing(&$default_values) { global $CFG, $DB; if ($this->current->instance) { $options = $DB->get_records('tab_content', array('tabid' => $this->current->instance), 'tabcontentorder'); // print_object($options) $tabids = array_keys($options); $options = array_values($options); $context = $this->context; $editoroptions = array('subdirs' => 1, 'maxbytes' => $CFG->maxbytes, 'maxfiles' => -1, 'changeformat' => 1, 'context' => $context, 'noclean' => 1, 'trusttext' => 1); foreach (array_keys($options) as $key) { $default_values['tabname[' . $key . ']'] = $options[$key]->tabname; $draftitemid = file_get_submitted_draft_itemid('content[' . $key . ']'); $default_values['content[' . $key . ']']['format'] = $options[$key]->contentformat; $default_values['content[' . $key . ']']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_tab', 'content', $options[$key]->id, $editoroptions, $options[$key]->tabcontent); $default_values['content[' . $key . ']']['itemid'] = $draftitemid; //$default_values['format['.$key.']'] = $options[$key]->format; $default_values['externalurl[' . $key . ']'] = $options[$key]->externalurl; $default_values['tabcontentorder[' . $key . ']'] = $options[$key]->tabcontentorder; $default_values['optionid[' . $key . ']'] = $tabids[$key]; } } }