-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmod_form.php
234 lines (196 loc) · 10.9 KB
/
mod_form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Echo360 Link configuration form
*
* @package mod
* @subpackage echolink
* @copyright (c) 2013, Echo360 Inc. www.echo360.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once ($CFG->dirroot.'/course/moodleform_mod.php');
require_once($CFG->dirroot.'/mod/echolink/locallib.php');
class mod_echolink_mod_form extends moodleform_mod {
function definition() {
global $CFG, $PAGE, $COURSE, $USER;
$mform = $this->_form;
$config = get_config('echolink');
$moodleCourse = "";
if($config->Moodle_External_ID == "moodle_short_name_course") {
$moodleCourse = $COURSE->shortname;
} else if($config->Moodle_External_ID == "moodle_full_name_course") {
$moodleCourse = $COURSE->fullname;
} else if($config->Moodle_External_ID == "moodle_id_number_course") {
$moodleCourse = $COURSE->idnumber;
} else if($config->Moodle_External_ID == "moodle_database_id_course") {
$moodleCourse = $COURSE->id;
}
$moodleUser = $USER->username;
//-------------------------------------------------------
if($config->Display_Label != "") {
$mform->addElement('header', 'general', $config->Display_Label);
} else {
$mform->addElement('header', 'general', get_string('echolink', 'echolink'));
}
$mform->addElement('text', 'name', get_string('name', 'echolink'), array('size'=>'48'));
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEANHTML);
}
//$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addElement('hidden', 'externalecholink', '', array('id'=>'externalecholink'));
$mform->setType('externalecholink', PARAM_URL);
$mform->addElement('hidden', 'previousecholink', '', array('id'=>'previousecholink'));
$mform->setType('previousecholink', PARAM_URL);
$this->standard_intro_elements($config->requiremodintro);
//-------------------------------------------------------
if($config->Display_Label != "") {
$mform->addElement('header', 'echosystemcontent', $config->Display_Label . " Options");
} else {
$mform->addElement('header', 'echosystemcontent', get_string('echosystemcontent', 'echolink'));
}
$defaultFilter = $config->Display_Listing;
if($defaultFilter == '0') { // Show All Courses
$mform->addElement('html', '<div>' . echolink_ess_get_rest_courses($moodleCourse, $defaultFilter) . '</div>');
} else if($defaultFilter == '1') { // Show Courses by Instructor Only
$mform->addElement('html', '<div>' . echolink_ess_get_rest_person_courses($moodleUser, $moodleCourse, $defaultFilter) . '</div>');
}
// Load this module's Javascript library for AJAX queries / event handlers to each of the ESS Courses displayed
$module = array('name'=>'mod_echolink',
'fullpath'=>'/mod/echolink/library/echolink.js',
);
$params = array(
array(
"essFilterEventURL" => $CFG->wwwroot."/mod/echolink/event-handler/echolink_request_courses.php?moodle_course=$moodleCourse&moodle_user=$moodleUser&defaultFilter=$defaultFilter",
"essCourseEventURL" => $CFG->wwwroot."/mod/echolink/event-handler/echolink_request_course_sections.php?course_uuid=",
"essSectionEventURL" => $CFG->wwwroot."/mod/echolink/event-handler/echolink_request_section_presentations.php?section_uuid=",
"essPresentationEventURL" => $CFG->wwwroot."/mod/echolink/event-handler/echolink_request_presentation.php?presentation_uuid=",
)
);
$PAGE->requires->js_init_call('M.mod_echolink.init', $params, false, $module);
// Only expand EchoSystem Content options in Moodle 2.7+ to overcome Moodle bug: https://tracker.moodle.org/browse/MDL-38435
if(floatval(substr($CFG->release, 0, 3)) >= 2.7) {
$mform->setExpanded('echosystemcontent');
}
//-------------------------------------------------------
$mform->addElement('header', 'optionssection', get_string('appearance'));
if ($this->current->instance) {
$options = resourcelib_get_displayoptions(explode(',', $config->displayoptions), $this->current->display);
} else {
$options = resourcelib_get_displayoptions(explode(',', $config->displayoptions));
}
if (count($options) == 1) {
$mform->addElement('hidden', 'display');
$mform->setType('display', PARAM_INT);
reset($options);
$mform->setDefault('display', key($options));
} else {
$mform->addElement('select', 'display', get_string('displayselect', 'url'), $options);
$mform->setDefault('display', $config->display);
$mform->addHelpButton('display', 'displayselect', 'url');
}
if (array_key_exists(RESOURCELIB_DISPLAY_POPUP, $options)) {
$mform->addElement('text', 'popupwidth', get_string('popupwidth', 'url'), array('size'=>3));
if (count($options) > 1) {
$mform->disabledIf('popupwidth', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
}
$mform->setType('popupwidth', PARAM_INT);
$mform->setDefault('popupwidth', $config->popupwidth);
$mform->addElement('text', 'popupheight', get_string('popupheight', 'url'), array('size'=>3));
if (count($options) > 1) {
$mform->disabledIf('popupheight', 'display', 'noteq', RESOURCELIB_DISPLAY_POPUP);
}
$mform->setType('popupheight', PARAM_INT);
$mform->setDefault('popupheight', $config->popupheight);
}
if (array_key_exists(RESOURCELIB_DISPLAY_AUTO, $options) or
array_key_exists(RESOURCELIB_DISPLAY_EMBED, $options) or
array_key_exists(RESOURCELIB_DISPLAY_FRAME, $options)) {
$mform->addElement('checkbox', 'printintro', get_string('printintro', 'url'));
$mform->disabledIf('printintro', 'display', 'eq', RESOURCELIB_DISPLAY_POPUP);
$mform->disabledIf('printintro', 'display', 'eq', RESOURCELIB_DISPLAY_OPEN);
$mform->disabledIf('printintro', 'display', 'eq', RESOURCELIB_DISPLAY_NEW);
$mform->setDefault('printintro', $config->printintro);
}
//-------------------------------------------------------
$this->standard_coursemodule_elements();
//-------------------------------------------------------
$this->add_action_buttons();
}
function data_preprocessing(&$default_values) {
if (!empty($default_values['displayoptions'])) {
$displayoptions = unserialize($default_values['displayoptions']);
if (isset($displayoptions['printintro'])) {
$default_values['printintro'] = $displayoptions['printintro'];
}
if (isset($displayoptions['printheading'])) {
$default_values['printheading'] = $displayoptions['printheading'];
}
if (!empty($displayoptions['popupwidth'])) {
$default_values['popupwidth'] = $displayoptions['popupwidth'];
}
if (!empty($displayoptions['popupheight'])) {
$default_values['popupheight'] = $displayoptions['popupheight'];
}
}
if (!empty($default_values['parameters'])) {
$parameters = unserialize($default_values['parameters']);
$i = 0;
foreach ($parameters as $parameter=>$variable) {
$default_values['parameter_'.$i] = $parameter;
$default_values['variable_'.$i] = $variable;
$i++;
}
}
}
function validation($data, $files) {
$errors = parent::validation($data, $files);
// Validating Entered echolink, we are looking for obvious problems only,
// teachers are responsible for testing if it actually works.
// This is not a security validation!! Teachers are allowed to enter "javascript:alert(666)" for example.
// NOTE: do not try to explain the difference between URL and URI, people would be only confused...
if (empty($data['name'])) {
$errors['name'] = get_string('nonameecholink', 'echolink');
} else if (empty($data['externalecholink'])) {
$errors['name'] = get_string('noselectedecholink', 'echolink');
} else {
$echolink = trim($data['externalecholink']);
if (empty($echolink)) {
$errors['name'] = get_string('noselectedecholink', 'echolink');
} else if (preg_match('|^/|', $echolink)) {
// links relative to server root are ok - no validation necessary
} else if (preg_match('|^[a-z]+://|i', $echolink) or preg_match('|^https?:|i', $echolink) or preg_match('|^ftp:|i', $echolink)) {
// normal URL
if (!echolink_appears_valid_echolink($echolink)) {
$errors['name'] = get_string('invalidecholink', 'echolink');
}
} else if (preg_match('|^[a-z]+:|i', $echolink)) {
// general URI such as teamspeak, mailto, etc. - it may or may not work in all browsers,
// we do not validate these at all, sorry
} else {
// invalid URI, we try to fix it by adding 'http://' prefix,
// relative links are NOT allowed because we display the link on different pages!
if (!echolink_appears_valid_echolink('http://'.$echolink)) {
$errors['name'] = get_string('invalidecholink', 'echolink');
}
}
}
return $errors;
}
}