MDL-31558 add missing mimetype to send_temp_file()
[moodle.git] / mod / page / mod_form.php
blob9ec12872d8714b27e24ccbaf7545cc48f8afd3e3
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * Page configuration form
21 * @package mod
22 * @subpackage page
23 * @copyright 2009 Petr Skoda (http://skodak.org)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die;
29 require_once($CFG->dirroot.'/course/moodleform_mod.php');
30 require_once($CFG->dirroot.'/mod/page/locallib.php');
31 require_once($CFG->libdir.'/filelib.php');
33 class mod_page_mod_form extends moodleform_mod {
34 function definition() {
35 global $CFG, $DB;
37 $mform = $this->_form;
39 $config = get_config('page');
41 //-------------------------------------------------------
42 $mform->addElement('header', 'general', get_string('general', 'form'));
43 $mform->addElement('text', 'name', get_string('name'), array('size'=>'48'));
44 if (!empty($CFG->formatstringstriptags)) {
45 $mform->setType('name', PARAM_TEXT);
46 } else {
47 $mform->setType('name', PARAM_CLEANHTML);
49 $mform->addRule('name', null, 'required', null, 'client');
50 $this->add_intro_editor($config->requiremodintro);
52 //-------------------------------------------------------
53 $mform->addElement('header', 'contentsection', get_string('contentheader', 'page'));
54 $mform->addElement('editor', 'page', get_string('content', 'page'), null, page_get_editor_options($this->context));
55 $mform->addRule('page', get_string('required'), 'required', null, 'client');
57 //-------------------------------------------------------
58 $mform->addElement('header', 'optionssection', get_string('optionsheader', 'page'));
60 if ($this->current->instance) {
61 $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions), $this->current->display);
62 } else {
63 $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions));
65 if (count($options) == 1) {
66 $mform->addElement('hidden', 'display');
67 $mform->setType('display', PARAM_INT);
68 reset($options);
69 $mform->setDefault('display', key($options));
70 } else {
71 $mform->addElement('select', 'display', get_string('displayselect', 'page'), $options);
72 $mform->setDefault('display', $config->display);
73 $mform->setAdvanced('display', $config->display_adv);
76 if (array_key_exists(RESOURCELIB_DISPLAY_POPUP, $options)) {
77 $mform->addElement('text', 'popupwidth', get_string('popupwidth', 'page'), array('size'=>3));
78 if (count($options) > 1) {
79 $mform->disabledIf('popupwidth', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
81 $mform->setType('popupwidth', PARAM_INT);
82 $mform->setDefault('popupwidth', $config->popupwidth);
83 $mform->setAdvanced('popupwidth', $config->popupwidth_adv);
85 $mform->addElement('text', 'popupheight', get_string('popupheight', 'page'), array('size'=>3));
86 if (count($options) > 1) {
87 $mform->disabledIf('popupheight', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
89 $mform->setType('popupheight', PARAM_INT);
90 $mform->setDefault('popupheight', $config->popupheight);
91 $mform->setAdvanced('popupheight', $config->popupheight_adv);
94 $mform->addElement('advcheckbox', 'printheading', get_string('printheading', 'page'));
95 $mform->setDefault('printheading', $config->printheading);
96 $mform->setAdvanced('printintro', $config->printheading_adv);
97 $mform->addElement('advcheckbox', 'printintro', get_string('printintro', 'page'));
98 $mform->setDefault('printintro', $config->printintro);
99 $mform->setAdvanced('printintro', $config->printintro_adv);
101 // add legacy files flag only if used
102 if (isset($this->current->legacyfiles) and $this->current->legacyfiles != RESOURCELIB_LEGACYFILES_NO) {
103 $options = array(RESOURCELIB_LEGACYFILES_DONE => get_string('legacyfilesdone', 'page'),
104 RESOURCELIB_LEGACYFILES_ACTIVE => get_string('legacyfilesactive', 'page'));
105 $mform->addElement('select', 'legacyfiles', get_string('legacyfiles', 'page'), $options);
106 $mform->setAdvanced('legacyfiles', 1);
109 //-------------------------------------------------------
110 $this->standard_coursemodule_elements();
112 //-------------------------------------------------------
113 $this->add_action_buttons();
115 //-------------------------------------------------------
116 $mform->addElement('hidden', 'revision');
117 $mform->setType('revision', PARAM_INT);
118 $mform->setDefault('revision', 1);
121 function data_preprocessing(&$default_values) {
122 if ($this->current->instance) {
123 $draftitemid = file_get_submitted_draft_itemid('page');
124 $default_values['page']['format'] = $default_values['contentformat'];
125 $default_values['page']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_page', 'content', 0, page_get_editor_options($this->context), $default_values['content']);
126 $default_values['page']['itemid'] = $draftitemid;
128 if (!empty($default_values['displayoptions'])) {
129 $displayoptions = unserialize($default_values['displayoptions']);
130 if (isset($displayoptions['printintro'])) {
131 $default_values['printintro'] = $displayoptions['printintro'];
133 if (isset($displayoptions['printheading'])) {
134 $default_values['printheading'] = $displayoptions['printheading'];
136 if (!empty($displayoptions['popupwidth'])) {
137 $default_values['popupwidth'] = $displayoptions['popupwidth'];
139 if (!empty($displayoptions['popupheight'])) {
140 $default_values['popupheight'] = $displayoptions['popupheight'];