forked from moodlebox/moodle-tool_moodlebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforms.php
236 lines (207 loc) · 8.83 KB
/
forms.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
235
236
<?php
// This file is part of Moodle - https://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/>.
/**
* MoodleBox dashboard form definition.
*
* @package tool_moodlebox
* @copyright 2018 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/lib/formslib.php');
/**
* Class datetimeset_form
*
* Form class to set time and date.
*
* @package tool_moodlebox
* @copyright 2016 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class datetimeset_form extends moodleform {
/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;
$mform->addElement('date_time_selector', 'currentdatetime', get_string('datetime', 'tool_moodlebox'),
array(
'startyear' => date("Y") - 2,
'stopyear' => date("Y") + 2,
'timezone' => 99,
'step' => 1,
'optional' => true)
);
$mform->addHelpButton('currentdatetime', 'datetime', 'tool_moodlebox');
$this->add_action_buttons(false, get_string('datetimeset', 'tool_moodlebox'));
}
}
/**
* Class changepassword_form
*
* Form class to change MoodleBox password.
*
* @package tool_moodlebox
* @copyright 2016 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class changepassword_form extends moodleform {
/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;
$mform->addElement('passwordunmask', 'newpassword1', get_string('newpassword'));
$mform->addRule('newpassword1', get_string('required'), 'required', null, 'client');
$mform->setType('newpassword1', PARAM_RAW_TRIMMED);
$mform->addElement('passwordunmask', 'newpassword2', get_string('newpassword').' ('.get_string('again').')');
$mform->addRule('newpassword2', get_string('required'), 'required', null, 'client');
$mform->setType('newpassword2', PARAM_RAW_TRIMMED);
$this->add_action_buttons(false, get_string('changepassword'));
}
/**
* Validate the form.
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param array $data submitted data
* @param array $files not used
* @return array errors
*/
public function validation($data, $files) {
$errors = array();
if ($data['newpassword1'] <> $data['newpassword2']) {
$errors['newpassword1'] = get_string('passwordsdiffer');
$errors['newpassword2'] = get_string('passwordsdiffer');
}
return $errors;
}
}
/**
* Class wifisettings_form
*
* Form class to change MoodleBox Wi-Fi settings.
*
* @package tool_moodlebox
* @copyright 2016 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class wifisettings_form extends moodleform {
/**
* Define the form.
*
* @SuppressWarnings(PHPMD.LongVariable)
*
*/
public function definition() {
global $currentwifissid;
global $currentwifissidhiddenstate;
global $currentwifichannel;
global $currentwifipassword;
global $currentwificountry;
$mform = $this->_form;
// SSID setting.
$mform->addElement('text', 'wifissid', get_string('wifissid', 'tool_moodlebox'));
$mform->addRule('wifissid', get_string('required'), 'required', null, 'client');
$mform->setType('wifissid', PARAM_RAW_TRIMMED);
$mform->setDefault('wifissid', $currentwifissid);
$mform->addHelpButton('wifissid', 'wifissid', 'tool_moodlebox');
// SSID hiding setting.
$mform->addElement('checkbox', 'wifissidhiddenstate', get_string('wifissidhiddenstate', 'tool_moodlebox'),
' ' . get_string('wifissidhidden', 'tool_moodlebox'));
$mform->setDefault('wifissidhiddenstate', ($currentwifissidhiddenstate == 0) ? 0 : 1);
$mform->setType('wifissidhiddenstate', PARAM_INT);
$mform->addHelpButton('wifissidhiddenstate', 'wifissidhiddenstate', 'tool_moodlebox');
// Channel setting.
if ($currentwificountry == 'US' or $currentwificountry == 'CA') {
$wifichannelrange = range(1, 11);
} else {
$wifichannelrange = range(1, 13);
}
$mform->addElement('select', 'wifichannel', get_string('wifichannel', 'tool_moodlebox'),
array_combine($wifichannelrange, $wifichannelrange));
$mform->addRule('wifichannel', get_string('required'), 'required', null, 'client');
$mform->setType('wifichannel', PARAM_INT);
$mform->setDefault('wifichannel', $currentwifichannel);
$mform->addHelpButton('wifichannel', 'wifichannel', 'tool_moodlebox');
// Regulatory country setting.
$mform->addElement('select', 'wificountry', get_string('wificountry', 'tool_moodlebox'),
get_string_manager()->get_list_of_countries(true));
$mform->addRule('wificountry', get_string('required'), 'required', null, 'client');
$mform->setType('wificountry', PARAM_RAW);
$mform->setDefault('wificountry', $currentwificountry);
$mform->addHelpButton('wificountry', 'wificountry', 'tool_moodlebox');
// Password protection setting.
$mform->addElement('checkbox', 'wifipasswordon', get_string('wifipasswordon', 'tool_moodlebox'),
' ' . get_string('passwordprotected', 'tool_moodlebox'));
$mform->setDefault('wifipasswordon', ($currentwifipassword == null) ? 0 : 1);
$mform->setType('wifipasswordon', PARAM_INT);
$mform->addHelpButton('wifipasswordon', 'wifipasswordon', 'tool_moodlebox');
// Password setting.
$mform->addElement('text', 'wifipassword', get_string('wifipassword', 'tool_moodlebox'));
$mform->disabledIf('wifipassword', 'wifipasswordon');
$mform->setType('wifipassword', PARAM_RAW_TRIMMED);
$mform->setDefault('wifipassword', ($currentwifipassword == null) ? 'moodlebox' : $currentwifipassword);
$mform->addHelpButton('wifipassword', 'wifipassword', 'tool_moodlebox');
$this->add_action_buttons(false, get_string('changewifisettings', 'tool_moodlebox'));
}
}
/**
* Class resizepartition_form
*
* Form class to resize the partition of the MoodleBox.
*
* @package tool_moodlebox
* @copyright 2018 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class resizepartition_form extends moodleform {
/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;
$buttonarray = array();
$buttonarray[] = & $mform->createElement('submit', 'resizepartitionbutton',
get_string('resizepartition', 'tool_moodlebox'));
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$mform->closeHeaderBefore('buttonar');
}
}
/**
* Class restartshutdown_form
*
* Form class to restart and shutdown the MoodleBox.
*
* @package tool_moodlebox
* @copyright 2016 onwards Nicolas Martignoni {@link mailto:[email protected]}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class restartshutdown_form extends moodleform {
/**
* Define the form.
*/
public function definition() {
$mform = $this->_form;
$buttonarray = array();
$buttonarray[] = & $mform->createElement('submit', 'restartbutton',
get_string('restart', 'tool_moodlebox'));
$buttonarray[] = & $mform->createElement('submit', 'shutdownbutton',
get_string('shutdown', 'tool_moodlebox'));
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$mform->closeHeaderBefore('buttonar');
}
}