MDL-21249 improved php docs and adding copyright blocks in mod/imscp
[moodle.git] / mod / url / mod_form.php
CommitLineData
58a27a74 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 * URL configuration form
20 *
21 * @package mod-url
22 * @copyright 2009 Petr Skoda (http://skodak.org)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
bfebaf64
MD
26if (!defined('MOODLE_INTERNAL')) {
27 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
28}
29
58a27a74 30require_once ($CFG->dirroot.'/course/moodleform_mod.php');
31require_once($CFG->dirroot.'/mod/url/locallib.php');
32
33class mod_url_mod_form extends moodleform_mod {
34 function definition() {
35 global $CFG, $DB;
36 $mform = $this->_form;
37
38 $config = get_config('url');
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 {
46 $mform->setType('name', PARAM_CLEAN);
47 }
48 $mform->addRule('name', null, 'required', null, 'client');
49 $this->add_intro_editor($config->requiremodintro);
50
51 //-------------------------------------------------------
52 $mform->addElement('header', 'content', get_string('contentheader', 'url'));
e5dd8e3b 53 $mform->addElement('url', 'externalurl', get_string('externalurl', 'url'), array('size'=>'60'), array('usefilepicker'=>true));
58a27a74 54 //-------------------------------------------------------
55 $mform->addElement('header', 'optionssection', get_string('optionsheader', 'url'));
56
57 if ($this->current->instance) {
58 $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions), $this->current->display);
59 } else {
60 $options = resourcelib_get_displayoptions(explode(',', $config->displayoptions));
61 }
62 if (count($options) == 1) {
63 $mform->addElement('hidden', 'display');
d18e0fe6 64 $mform->setType('display', PARAM_INT);
58a27a74 65 reset($options);
66 $mform->setDefault('display', key($options));
67 } else {
68 $mform->addElement('select', 'display', get_string('displayselect', 'url'), $options);
69 $mform->setDefault('display', $config->display);
70 $mform->setAdvanced('display', $config->display_adv);
71 }
72
73 if (array_key_exists(RESOURCELIB_DISPLAY_POPUP, $options)) {
74 $mform->addElement('text', 'popupwidth', get_string('popupwidth', 'url'), array('size'=>3));
75 if (count($options) > 1) {
76 $mform->disabledIf('popupwidth', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
77 }
78 $mform->setType('popupwidth', PARAM_INT);
79 $mform->setDefault('popupwidth', $config->popupwidth);
80 $mform->setAdvanced('popupwidth', $config->popupwidth_adv);
81
82 $mform->addElement('text', 'popupheight', get_string('popupheight', 'url'), array('size'=>3));
83 if (count($options) > 1) {
84 $mform->disabledIf('popupheight', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
85 }
86 $mform->setType('popupheight', PARAM_INT);
87 $mform->setDefault('popupheight', $config->popupheight);
88 $mform->setAdvanced('popupheight', $config->popupheight_adv);
89 }
90
91 if (array_key_exists(RESOURCELIB_DISPLAY_AUTO, $options) or
92 array_key_exists(RESOURCELIB_DISPLAY_EMBED, $options) or
93 array_key_exists(RESOURCELIB_DISPLAY_FRAME, $options)) {
94 $mform->addElement('checkbox', 'printheading', get_string('printheading', 'url'));
95 $mform->disabledIf('printheading', 'display', 'eq', RESOURCELIB_DISPLAY_POPUP);
96 $mform->disabledIf('printheading', 'display', 'eq', RESOURCELIB_DISPLAY_OPEN);
97 $mform->disabledIf('printheading', 'display', 'eq', RESOURCELIB_DISPLAY_NEW);
98 $mform->setDefault('printheading', $config->printheading);
99 $mform->setAdvanced('printheading', $config->printheading_adv);
100
101 $mform->addElement('checkbox', 'printintro', get_string('printintro', 'url'));
102 $mform->disabledIf('printintro', 'display', 'eq', RESOURCELIB_DISPLAY_POPUP);
103 $mform->disabledIf('printintro', 'display', 'eq', RESOURCELIB_DISPLAY_OPEN);
104 $mform->disabledIf('printintro', 'display', 'eq', RESOURCELIB_DISPLAY_NEW);
105 $mform->setDefault('printintro', $config->printintro);
106 $mform->setAdvanced('printintro', $config->printintro_adv);
107 }
108
109 //-------------------------------------------------------
110 $mform->addElement('header', 'parameterssection', get_string('parametersheader', 'url'));
111
112
113 if (empty($this->current->parameters)) {
114 $parcount = 5;
115 } else {
116 $parcount = 5 + count(unserialize($this->current->parameters));
117 $parcount = ($parcount > 100) ? 100 : $parcount;
118 }
119 $options = url_get_variable_options($config);
120
121 for ($i=0; $i < $parcount; $i++) {
122 $parameter = "parameter_$i";
123 $variable = "variable_$i";
124 $pargroup = "pargoup_$i";
125 $group = array(
126 $mform->createElement('text', $parameter, '', array('size'=>'12')),
127 $mform->createElement('selectgroups', $variable, '', $options),
128 );
129 $mform->addGroup($group, $pargroup, get_string('parameterinfo', 'url'), ' ', false);
130 $mform->setAdvanced($pargroup);
131 }
132
133 //-------------------------------------------------------
134 $this->standard_coursemodule_elements();
135
136 //-------------------------------------------------------
137 $this->add_action_buttons();
138 }
139
140 function data_preprocessing(&$default_values) {
141 if (!empty($default_values['displayoptions'])) {
142 $displayoptions = unserialize($default_values['displayoptions']);
143 if (isset($displayoptions['printintro'])) {
144 $default_values['printintro'] = $displayoptions['printintro'];
145 }
146 if (isset($displayoptions['printheading'])) {
147 $default_values['printheading'] = $displayoptions['printheading'];
148 }
149 if (!empty($displayoptions['popupwidth'])) {
150 $default_values['popupwidth'] = $displayoptions['popupwidth'];
151 }
152 if (!empty($displayoptions['popupheight'])) {
153 $default_values['popupheight'] = $displayoptions['popupheight'];
154 }
155 }
156 if (!empty($default_values['parameters'])) {
157 $parameters = unserialize($default_values['parameters']);
158 $i = 0;
159 foreach ($parameters as $parameter=>$variable) {
160 $default_values['parameter_'.$i] = $parameter;
161 $default_values['variable_'.$i] = $variable;
162 $i++;
163 }
164 }
165 }
166
167}