-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplehtml_form.php
234 lines (209 loc) · 9.73 KB
/
simplehtml_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 the Moodle block "Remlab Manager"
//
// Remlab Manager 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.
//
// Remlab Manager 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/>.
//
// Remlab Manager has been developed by:
// - Luis de la Torre: [email protected]
//
// at the Computer Science and Automatic Control, Spanish Open University
// (UNED), Madrid, Spain.
/**
* Page for configuring the data needed by a non-ENLARGE remote lab application
*
* @package block_remlab_manager
* @copyright 2015 Luis de la Torre
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once("{$CFG->libdir}/formslib.php");
require_once("../../mod/ejsapp/locallib.php");
/**
* Class simplehtml_form
* @copyright 2015 Luis de la Torre
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class simplehtml_form extends moodleform {
/**
* Defines the form
*/
public function definition() {
global $DB, $PAGE;
$mform =& $this->_form;
$mform->addElement('header', 'rem_lab', get_string('rem_lab_conf', 'ejsapp'));
// First, hidden elements.
$mform->addElement('hidden', 'blockid');
$mform->setType('blockid', PARAM_INT);
$mform->addElement('hidden', 'courseid');
$mform->setType('courseid', PARAM_INT);
$mform->addElement('hidden', 'editingexperience');
$mform->setType('editingexperience', PARAM_INT);
$mform->addElement('hidden', 'originalpracticeintro');
$mform->setType('originalpracticeintro', PARAM_TEXT);
$mform->addElement('hidden', 'initialpracticeintro', null);
$mform->setType('initialpracticeintro', PARAM_TEXT);
// Get data if editing an already existing experience.
$editing = $this->_customdata[0];
$practiceintro = $this->_customdata[1];
$remlab = false;
$mform->addElement('hidden', 'editing', null);
$mform->setType('editing', PARAM_INT);
$mform->setDefault('editing', 0);
if ($editing) {
$mform->setDefault('editing', 1);
$remlab = $DB->get_record('block_remlab_manager_conf', array('practiceintro' => $practiceintro));
}
$mform->addElement('text', 'practiceintro',
get_string('practiceintro', 'block_remlab_manager'), array('size' => '25'));
$mform->setType('practiceintro', PARAM_TEXT);
$mform->addHelpButton('practiceintro', 'practiceintro', 'block_remlab_manager');
$mform->addElement('text', 'ip',
get_string('ip_lab', 'block_remlab_manager'), array('size' => '25'));
$mform->setType('ip', PARAM_TEXT);
$mform->addRule('ip',
get_string('maximumchars', ''), 'maxlength', 50, 'client');
$mform->addHelpButton('ip', 'ip_lab', 'block_remlab_manager');
$mform->addElement('text', 'port',
get_string('port', 'block_remlab_manager'), array('size' => '6'));
$mform->setType('port', PARAM_INT);
$mform->addRule('port',
get_string('maximumchars', ''), 'maxlength', 6, 'client');
$mform->addHelpButton('port', 'port', 'block_remlab_manager');
if ($remlab) {
$mform->setDefault('practiceintro', $remlab->practiceintro);
$mform->setDefault('initialpracticeintro', $remlab->practiceintro);
$mform->setDefault('ip', $remlab->ip);
$mform->setDefault('port', $remlab->port);
$enlargeinstance = is_practice_in_enlarge($remlab->practiceintro);
if ($enlargeinstance !== false) {
$PAGE->requires->js_call_amd('block_remlab_manager/disable', 'disable');
} else {
$mform->addRule('practiceintro',
get_string('practiceintro_required', 'block_remlab_manager'), 'required');
$mform->addRule('ip',
get_string('ip_lab_required', 'block_remlab_manager'), 'required');
$mform->addRule('port',
get_string('port_required', 'block_remlab_manager'), 'required');
}
} else {
$mform->addRule('practiceintro',
get_string('practiceintro_required', 'block_remlab_manager'), 'required');
$mform->addRule('ip',
get_string('ip_lab_required', 'block_remlab_manager'), 'required');
$mform->addRule('port',
get_string('port_required', 'block_remlab_manager'), 'required');
$mform->setDefault('initialpracticeintro', '');
$mform->setDefault('ip', '127.0.0.1');
$mform->setDefault('port', 443);
}
$mform->addElement('selectyesno', 'active',
get_string('active', 'block_remlab_manager'));
$mform->addHelpButton('active', 'active', 'block_remlab_manager');
$mform->disabledIf('active', 'is_rem_lab', 'eq', 0);
if ($remlab) {
$mform->setDefault('active', $remlab->active);
} else {
$mform->setDefault('active', '1');
}
$mform->addElement('selectyesno', 'free_access',
get_string('free_access', 'block_remlab_manager'));
$mform->addHelpButton('free_access', 'free_access', 'block_remlab_manager');
if ($remlab) {
$mform->setDefault('free_access', $remlab->free_access);
} else {
$mform->setDefault('free_access', '0');
}
$mform->addElement('select', 'slotsduration',
get_string('slotsduration', 'block_remlab_manager'), array('60', '30', '15', '5', '2'));
$mform->addHelpButton('slotsduration', 'slotsduration', 'block_remlab_manager');
if ($remlab) {
$mform->setDefault('slotsduration', $remlab->slotsduration);
} else {
$mform->setDefault('slotsduration', '60');
}
$mform->addElement('text', 'totalslots',
get_string('totalslots', 'block_remlab_manager'), array('size' => '2'));
$mform->setType('totalslots', PARAM_INT);
$mform->addRule('totalslots',
get_string('maximumchars', '', 5), 'maxlength', 5, 'client');
$mform->addHelpButton('totalslots', 'totalslots', 'block_remlab_manager');
$mform->disabledIf('totalslots', 'free_access', 'eq', 1);
if ($remlab) {
$mform->setDefault('totalslots', $remlab->totalslots);
} else {
$mform->setDefault('totalslots', 18);
}
$mform->addElement('text', 'weeklyslots',
get_string('weeklyslots', 'block_remlab_manager'), array('size' => '2'));
$mform->setType('weeklyslots', PARAM_INT);
$mform->addRule('weeklyslots',
get_string('maximumchars', '', 3), 'maxlength', 3, 'client');
$mform->addHelpButton('weeklyslots', 'weeklyslots', 'block_remlab_manager');
$mform->disabledIf('weeklyslots', 'free_access', 'eq', 1);
if ($remlab) {
$mform->setDefault('weeklyslots', $remlab->weeklyslots);
} else {
$mform->setDefault('weeklyslots', 9);
}
$mform->addElement('text', 'dailyslots',
get_string('dailyslots', 'block_remlab_manager'), array('size' => '2'));
$mform->setType('dailyslots', PARAM_INT);
$mform->addRule('dailyslots',
get_string('maximumchars', '', 2), 'maxlength', 2, 'client');
$mform->addHelpButton('dailyslots', 'dailyslots', 'block_remlab_manager');
$mform->disabledIf('dailyslots', 'is_rem_lab', 'eq', 0);
if ($remlab) {
$mform->setDefault('dailyslots', $remlab->dailyslots);
} else {
$mform->setDefault('dailyslots', 3);
}
$mform->addElement('text', 'reboottime',
get_string('reboottime', 'block_remlab_manager'), array('size' => '2'));
$mform->setType('reboottime', PARAM_INT);
$mform->addRule('reboottime',
get_string('maximumchars', '', 2), 'maxlength', 2, 'client');
$mform->addHelpButton('reboottime', 'reboottime', 'block_remlab_manager');
if ($remlab) {
$mform->setDefault('reboottime', $remlab->reboottime);
} else {
$mform->setDefault('reboottime', 2);
}
$this->add_action_buttons();
}
/**
* Performs minimal validation on the settings form
* @param array $data
* @param array $files
* @return array $errors
* @throws
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);
$editing = $data['editing'];
$showableexperiences = get_showable_experiences();
// Make sure the practice name or identifier does not exist locally nor remotely (in ENLARGE)
if ($editing == 0) { // New experience
if (in_array($data['practiceintro'], $showableexperiences)) {
$errors['practiceintro'] = get_string('existing_practice_id', 'block_remlab_manager');
}
} else { // Editing an existing experience
if (($data['practiceintro'] != $data['initialpracticeintro']) &&
in_array($data['practiceintro'], $showableexperiences)) {
$errors['practiceintro'] = get_string('existing_practice_id', 'block_remlab_manager');
}
}
return $errors;
}
}