MDL-50015 mod_imscp: New WS mod_imscp_view_imscp
[moodle.git] / mod / page / mod_form.php
CommitLineData
1ad9ff57 1<?php
2
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.
14//
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/>.
17
18/**
19 * Page configuration form
20 *
96930d5b 21 * @package mod_page
2c49daf7
PS
22 * @copyright 2009 Petr Skoda (http://skodak.org)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1ad9ff57 24 */
25
2c49daf7 26defined('MOODLE_INTERNAL') || die;
bfebaf64 27
1ad9ff57 28require_once($CFG->dirroot.'/course/moodleform_mod.php');
29require_once($CFG->dirroot.'/mod/page/locallib.php');
30require_once($CFG->libdir.'/filelib.php');
31
32class mod_page_mod_form extends moodleform_mod {
33 function definition() {
34 global $CFG, $DB;
2c49daf7
PS
35
36 $mform = $this->_form;
1ad9ff57 37
38 $config = get_config('page');
39
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 {
b8ea3041 46 $mform->setType('name', PARAM_CLEANHTML);
1ad9ff57 47 }
48 $mform->addRule('name', null, 'required', null, 'client');
a74cd331 49 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
6398ff53 50 $this->standard_intro_elements();
1ad9ff57 51
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));
2eab29bd 55 $mform->addRule('page', get_string('required'), 'required', null, 'client');
1ad9ff57 56
57 //-------------------------------------------------------
a59bbb6e 58 $mform->addElement('header', 'appearancehdr', get_string('appearance'));
1ad9ff57 59
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));
64 }
65 if (count($options) == 1) {
66 $mform->addElement('hidden', 'display');
d18e0fe6 67 $mform->setType('display', PARAM_INT);
1ad9ff57 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);
1ad9ff57 73 }
74
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);
79 }
80 $mform->setType('popupwidth', PARAM_INT);
81 $mform->setDefault('popupwidth', $config->popupwidth);
1ad9ff57 82
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);
86 }
87 $mform->setType('popupheight', PARAM_INT);
88 $mform->setDefault('popupheight', $config->popupheight);
1ad9ff57 89 }
90
846ffe60
JC
91 $mform->addElement('advcheckbox', 'printheading', get_string('printheading', 'page'));
92 $mform->setDefault('printheading', $config->printheading);
1ad9ff57 93 $mform->addElement('advcheckbox', 'printintro', get_string('printintro', 'page'));
94 $mform->setDefault('printintro', $config->printintro);
1ad9ff57 95
96 // add legacy files flag only if used
97 if (isset($this->current->legacyfiles) and $this->current->legacyfiles != RESOURCELIB_LEGACYFILES_NO) {
42439c05 98 $options = array(RESOURCELIB_LEGACYFILES_DONE => get_string('legacyfilesdone', 'page'),
1ad9ff57 99 RESOURCELIB_LEGACYFILES_ACTIVE => get_string('legacyfilesactive', 'page'));
100 $mform->addElement('select', 'legacyfiles', get_string('legacyfiles', 'page'), $options);
101 $mform->setAdvanced('legacyfiles', 1);
102 }
103
104 //-------------------------------------------------------
105 $this->standard_coursemodule_elements();
106
107 //-------------------------------------------------------
108 $this->add_action_buttons();
109
110 //-------------------------------------------------------
111 $mform->addElement('hidden', 'revision');
112 $mform->setType('revision', PARAM_INT);
113 $mform->setDefault('revision', 1);
114 }
115
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'];
64f93798 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']);
1ad9ff57 121 $default_values['page']['itemid'] = $draftitemid;
122 }
123 if (!empty($default_values['displayoptions'])) {
124 $displayoptions = unserialize($default_values['displayoptions']);
125 if (isset($displayoptions['printintro'])) {
126 $default_values['printintro'] = $displayoptions['printintro'];
127 }
846ffe60
JC
128 if (isset($displayoptions['printheading'])) {
129 $default_values['printheading'] = $displayoptions['printheading'];
130 }
1ad9ff57 131 if (!empty($displayoptions['popupwidth'])) {
132 $default_values['popupwidth'] = $displayoptions['popupwidth'];
133 }
134 if (!empty($displayoptions['popupheight'])) {
135 $default_values['popupheight'] = $displayoptions['popupheight'];
136 }
137 }
138 }
139}
140