Merge branch 'install_26_STABLE' of https://git.in.moodle.com/amosbot/moodle-install...
[moodle.git] / mod / page / mod_form.php
blobd982d7ac9fecf9c7924570912372e39e43533750
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 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
51 $this->add_intro_editor($config->requiremodintro);
53 //-------------------------------------------------------
54 $mform->addElement('header', 'contentsection', get_string('contentheader', 'page'));
55 $mform->addElement('editor', 'page', get_string('content', 'page'), null, page_get_editor_options($this->context));
56 $mform->addRule('page', get_string('required'), 'required', null, 'client');
58 //-------------------------------------------------------
59 $mform->addElement('header', 'appearancehdr', get_string('appearance'));
61 if ($this->current->instance) {
62 $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions), $this->current->display);
63 } else {
64 $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions));
66 if (count($options) == 1) {
67 $mform->addElement('hidden', 'display');
68 $mform->setType('display', PARAM_INT);
69 reset($options);
70 $mform->setDefault('display', key($options));
71 } else {
72 $mform->addElement('select', 'display', get_string('displayselect', 'page'), $options);
73 $mform->setDefault('display', $config->display);
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);
84 $mform->addElement('text', 'popupheight', get_string('popupheight', 'page'), array('size'=>3));
85 if (count($options) > 1) {
86 $mform->disabledIf('popupheight', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
88 $mform->setType('popupheight', PARAM_INT);
89 $mform->setDefault('popupheight', $config->popupheight);
92 $mform->addElement('advcheckbox', 'printintro', get_string('printintro', 'page'));
93 $mform->setDefault('printintro', $config->printintro);
95 // add legacy files flag only if used
96 if (isset($this->current->legacyfiles) and $this->current->legacyfiles != RESOURCELIB_LEGACYFILES_NO) {
97 $options = array(RESOURCELIB_LEGACYFILES_DONE => get_string('legacyfilesdone', 'page'),
98 RESOURCELIB_LEGACYFILES_ACTIVE => get_string('legacyfilesactive', 'page'));
99 $mform->addElement('select', 'legacyfiles', get_string('legacyfiles', 'page'), $options);
100 $mform->setAdvanced('legacyfiles', 1);
103 //-------------------------------------------------------
104 $this->standard_coursemodule_elements();
106 //-------------------------------------------------------
107 $this->add_action_buttons();
109 //-------------------------------------------------------
110 $mform->addElement('hidden', 'revision');
111 $mform->setType('revision', PARAM_INT);
112 $mform->setDefault('revision', 1);
115 function data_preprocessing(&$default_values) {
116 if ($this->current->instance) {
117 $draftitemid = file_get_submitted_draft_itemid('page');
118 $default_values['page']['format'] = $default_values['contentformat'];
119 $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']);
120 $default_values['page']['itemid'] = $draftitemid;
122 if (!empty($default_values['displayoptions'])) {
123 $displayoptions = unserialize($default_values['displayoptions']);
124 if (isset($displayoptions['printintro'])) {
125 $default_values['printintro'] = $displayoptions['printintro'];
127 if (!empty($displayoptions['popupwidth'])) {
128 $default_values['popupwidth'] = $displayoptions['popupwidth'];
130 if (!empty($displayoptions['popupheight'])) {
131 $default_values['popupheight'] = $displayoptions['popupheight'];