MDL-57268 auth_db: Unit tests for deletion from a large user set
[moodle.git] / mod / page / mod_form.php
bloba411f1aa5555307d95af12e609d415d1f5cd6b1f
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_page
22 * @copyright 2009 Petr Skoda (http://skodak.org)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die;
28 require_once($CFG->dirroot.'/course/moodleform_mod.php');
29 require_once($CFG->dirroot.'/mod/page/locallib.php');
30 require_once($CFG->libdir.'/filelib.php');
32 class mod_page_mod_form extends moodleform_mod {
33 function definition() {
34 global $CFG, $DB;
36 $mform = $this->_form;
38 $config = get_config('page');
40 //-------------------------------------------------------
41 $mform->addElement('header', 'general', get_string('general', 'form'));
42 $mform->addElement('text', 'name', get_string('name'), array('size'=>'48'));
43 if (!empty($CFG->formatstringstriptags)) {
44 $mform->setType('name', PARAM_TEXT);
45 } else {
46 $mform->setType('name', PARAM_CLEANHTML);
48 $mform->addRule('name', null, 'required', null, 'client');
49 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
50 $this->standard_intro_elements();
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', 'appearancehdr', get_string('appearance'));
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);
75 if (array_key_exists(RESOURCELIB_DISPLAY_POPUP, $options)) {
76 $mform->addElement('text', 'popupwidth', get_string('popupwidth', 'page'), array('size'=>3));
77 if (count($options) > 1) {
78 $mform->disabledIf('popupwidth', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
80 $mform->setType('popupwidth', PARAM_INT);
81 $mform->setDefault('popupwidth', $config->popupwidth);
83 $mform->addElement('text', 'popupheight', get_string('popupheight', 'page'), array('size'=>3));
84 if (count($options) > 1) {
85 $mform->disabledIf('popupheight', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
87 $mform->setType('popupheight', PARAM_INT);
88 $mform->setDefault('popupheight', $config->popupheight);
91 $mform->addElement('advcheckbox', 'printheading', get_string('printheading', 'page'));
92 $mform->setDefault('printheading', $config->printheading);
93 $mform->addElement('advcheckbox', 'printintro', get_string('printintro', 'page'));
94 $mform->setDefault('printintro', $config->printintro);
96 // add legacy files flag only if used
97 if (isset($this->current->legacyfiles) and $this->current->legacyfiles != RESOURCELIB_LEGACYFILES_NO) {
98 $options = array(RESOURCELIB_LEGACYFILES_DONE => get_string('legacyfilesdone', 'page'),
99 RESOURCELIB_LEGACYFILES_ACTIVE => get_string('legacyfilesactive', 'page'));
100 $mform->addElement('select', 'legacyfiles', get_string('legacyfiles', 'page'), $options);
101 $mform->setAdvanced('legacyfiles', 1);
104 //-------------------------------------------------------
105 $this->standard_coursemodule_elements();
107 //-------------------------------------------------------
108 $this->add_action_buttons();
110 //-------------------------------------------------------
111 $mform->addElement('hidden', 'revision');
112 $mform->setType('revision', PARAM_INT);
113 $mform->setDefault('revision', 1);
116 function data_preprocessing(&$default_values) {
117 if ($this->current->instance) {
118 $draftitemid = file_get_submitted_draft_itemid('page');
119 $default_values['page']['format'] = $default_values['contentformat'];
120 $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']);
121 $default_values['page']['itemid'] = $draftitemid;
123 if (!empty($default_values['displayoptions'])) {
124 $displayoptions = unserialize($default_values['displayoptions']);
125 if (isset($displayoptions['printintro'])) {
126 $default_values['printintro'] = $displayoptions['printintro'];
128 if (isset($displayoptions['printheading'])) {
129 $default_values['printheading'] = $displayoptions['printheading'];
131 if (!empty($displayoptions['popupwidth'])) {
132 $default_values['popupwidth'] = $displayoptions['popupwidth'];
134 if (!empty($displayoptions['popupheight'])) {
135 $default_values['popupheight'] = $displayoptions['popupheight'];