MDL-30639 mod_lesson: Used a consistent format for users display of answer
[moodle.git] / admin / registration / forms.php
blob48c2cd9dfe2d093e3f82bf5cf537f3c65975c99c
1 <?php
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // This file is part of Moodle - http://moodle.org/ //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // //
8 // Moodle is free software: you can redistribute it and/or modify //
9 // it under the terms of the GNU General Public License as published by //
10 // the Free Software Foundation, either version 3 of the License, or //
11 // (at your option) any later version. //
12 // //
13 // Moodle is distributed in the hope that it will be useful, //
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
16 // GNU General Public License for more details. //
17 // //
18 // You should have received a copy of the GNU General Public License //
19 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
20 // //
21 ///////////////////////////////////////////////////////////////////////////
24 * @package moodle
25 * @subpackage registration
26 * @author Jerome Mouneyrac <jerome@mouneyrac.com>
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
28 * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
30 * The forms needed by registration pages.
34 require_once($CFG->libdir . '/formslib.php');
35 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
37 /**
38 * This form display a unregistration form.
40 class site_unregistration_form extends moodleform {
42 public function definition() {
43 $mform = & $this->_form;
44 $mform->addElement('header', 'site', get_string('unregister', 'hub'));
46 $huburl = $this->_customdata['huburl'];
47 $hubname = $this->_customdata['hubname'];
49 $unregisterlabel = get_string('unregister', 'hub');
50 $mform->addElement('checkbox', 'unpublishalladvertisedcourses', '',
51 ' ' . get_string('unpublishalladvertisedcourses', 'hub'));
52 $mform->addElement('checkbox', 'unpublishalluploadedcourses', '',
53 ' ' . get_string('unpublishalluploadedcourses', 'hub'));
55 $mform->addElement('hidden', 'confirm', 1);
56 $mform->setType('confirm', PARAM_INT);
57 $mform->addElement('hidden', 'unregistration', 1);
58 $mform->setType('unregistration', PARAM_INT);
59 $mform->addElement('hidden', 'huburl', $huburl);
60 $mform->setType('huburl', PARAM_URL);
61 $mform->addElement('hidden', 'hubname', $hubname);
62 $mform->setType('hubname', PARAM_TEXT);
64 $this->add_action_buttons(true, $unregisterlabel);
69 /**
70 * This form display a clean registration data form.
72 class site_clean_registration_data_form extends moodleform {
74 public function definition() {
75 $mform = & $this->_form;
76 $mform->addElement('header', 'site', get_string('unregister', 'hub'));
78 $huburl = $this->_customdata['huburl'];
79 $hubname = $this->_customdata['hubname'];
82 $unregisterlabel = get_string('forceunregister', 'hub');
83 $mform->addElement('static', '', get_string('warning', 'hub'), get_string('forceunregisterconfirmation', 'hub', $hubname));
86 $mform->addElement('hidden', 'confirm', 1);
87 $mform->setType('confirm', PARAM_INT);
88 $mform->addElement('hidden', 'unregistration', 1);
89 $mform->setType('unregistration', PARAM_INT);
90 $mform->addElement('hidden', 'cleanregdata', 1);
91 $mform->setType('cleanregdata', PARAM_INT);
92 $mform->addElement('hidden', 'huburl', $huburl);
93 $mform->setType('huburl', PARAM_URL);
94 $mform->addElement('hidden', 'hubname', $hubname);
95 $mform->setType('hubname', PARAM_TEXT);
97 $this->add_action_buttons(true, $unregisterlabel);
103 * This form display a hub selector.
104 * The hub list is retrieved from Moodle.org hub directory.
105 * Also displayed, a text field to enter private hub url + its password
107 class hub_selector_form extends moodleform {
109 public function definition() {
110 global $CFG, $OUTPUT;
111 $mform = & $this->_form;
112 $mform->addElement('header', 'site', get_string('selecthub', 'hub'));
114 //retrieve the hub list on the hub directory by web service
115 $function = 'hubdirectory_get_hubs';
116 $params = array();
117 $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php";
118 require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
119 $xmlrpcclient = new webservice_xmlrpc_client($serverurl, 'publichubdirectory');
120 try {
121 $hubs = $xmlrpcclient->call($function, $params);
122 } catch (Exception $e) {
123 $error = $OUTPUT->notification(get_string('errorhublisting', 'hub', $e->getMessage()));
124 $mform->addElement('static', 'errorhub', '', $error);
125 $hubs = array();
128 //remove moodle.org from the hub list
129 foreach ($hubs as $key => $hub) {
130 if ($hub['url'] == HUB_MOODLEORGHUBURL) {
131 unset($hubs[$key]);
135 //Public hub list
136 $options = array();
137 foreach ($hubs as $hub) {
138 //to not display a name longer than 100 character (too big)
139 if (textlib::strlen($hub['name']) > 100) {
140 $hubname = textlib::substr($hub['name'], 0, 100);
141 $hubname = $hubname . "...";
142 } else {
143 $hubname = $hub['name'];
145 $options[$hub['url']] = $hubname;
146 $mform->addElement('hidden', clean_param($hub['url'], PARAM_ALPHANUMEXT), $hubname);
147 $mform->setType(clean_param($hub['url'], PARAM_ALPHANUMEXT), PARAM_ALPHANUMEXT);
149 if (!empty($hubs)) {
150 $mform->addElement('select', 'publichub', get_string('publichub', 'hub'),
151 $options, array("size" => 15));
154 $mform->addElement('static', 'or', '', get_string('orenterprivatehub', 'hub'));
156 //Private hub
157 $mform->addElement('text', 'unlistedurl', get_string('privatehuburl', 'hub'),
158 array('class' => 'registration_textfield'));
159 $mform->addElement('text', 'password', get_string('password'),
160 array('class' => 'registration_textfield'));
162 $this->add_action_buttons(false, get_string('selecthub', 'hub'));
166 * Check the unlisted URL is a URL
168 function validation($data, $files) {
169 global $CFG;
170 $errors = parent::validation($data, $files);
172 $unlistedurl = $this->_form->_submitValues['unlistedurl'];
174 if (!empty($unlistedurl)) {
175 $unlistedurltotest = clean_param($unlistedurl, PARAM_URL);
176 if (empty($unlistedurltotest)) {
177 $errors['unlistedurl'] = get_string('badurlformat', 'hub');
181 return $errors;
187 * The site registration form. Information will be sent to a given hub.
189 class site_registration_form extends moodleform {
191 public function definition() {
192 global $CFG, $DB;
194 $strrequired = get_string('required');
195 $mform = & $this->_form;
196 $huburl = $this->_customdata['huburl'];
197 $hubname = $this->_customdata['hubname'];
198 $password = $this->_customdata['password'];
199 $admin = get_admin();
200 $site = get_site();
202 //retrieve config for this hub and set default if they don't exist
203 $cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
204 $sitename = get_config('hub', 'site_name_' . $cleanhuburl);
205 if ($sitename === false) {
206 $sitename = format_string($site->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
208 $sitedescription = get_config('hub', 'site_description_' . $cleanhuburl);
209 if ($sitedescription === false) {
210 $sitedescription = $site->summary;
212 $contactname = get_config('hub', 'site_contactname_' . $cleanhuburl);
213 if ($contactname === false) {
214 $contactname = fullname($admin, true);
216 $contactemail = get_config('hub', 'site_contactemail_' . $cleanhuburl);
217 if ($contactemail === false) {
218 $contactemail = $admin->email;
220 $contactphone = get_config('hub', 'site_contactphone_' . $cleanhuburl);
221 if ($contactphone === false) {
222 $contactphone = $admin->phone1;
224 $imageurl = get_config('hub', 'site_imageurl_' . $cleanhuburl);
225 $privacy = get_config('hub', 'site_privacy_' . $cleanhuburl);
226 $address = get_config('hub', 'site_address_' . $cleanhuburl);
227 $region = get_config('hub', 'site_region_' . $cleanhuburl);
228 $country = get_config('hub', 'site_country_' . $cleanhuburl);
229 if ($country === false) {
230 $country = $admin->country;
232 $language = get_config('hub', 'site_language_' . $cleanhuburl);
233 if ($language === false) {
234 $language = current_language();
236 $geolocation = get_config('hub', 'site_geolocation_' . $cleanhuburl);
237 $contactable = get_config('hub', 'site_contactable_' . $cleanhuburl);
238 $emailalert = get_config('hub', 'site_emailalert_' . $cleanhuburl);
239 $coursesnumber = get_config('hub', 'site_coursesnumber_' . $cleanhuburl);
240 $usersnumber = get_config('hub', 'site_usersnumber_' . $cleanhuburl);
241 $roleassignmentsnumber = get_config('hub', 'site_roleassignmentsnumber_' . $cleanhuburl);
242 $postsnumber = get_config('hub', 'site_postsnumber_' . $cleanhuburl);
243 $questionsnumber = get_config('hub', 'site_questionsnumber_' . $cleanhuburl);
244 $resourcesnumber = get_config('hub', 'site_resourcesnumber_' . $cleanhuburl);
245 $mediancoursesize = get_config('hub', 'site_mediancoursesize_' . $cleanhuburl);
247 //hidden parameters
248 $mform->addElement('hidden', 'huburl', $huburl);
249 $mform->setType('huburl', PARAM_URL);
250 $mform->addElement('hidden', 'hubname', $hubname);
251 $mform->setType('hubname', PARAM_TEXT);
252 $mform->addElement('hidden', 'password', $password);
253 $mform->setType('password', PARAM_RAW);
255 //the input parameters
256 $mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub'));
258 $mform->addElement('text', 'name', get_string('sitename', 'hub'),
259 array('class' => 'registration_textfield'));
260 $mform->addRule('name', $strrequired, 'required', null, 'client');
261 $mform->setType('name', PARAM_TEXT);
262 $mform->setDefault('name', $sitename);
263 $mform->addHelpButton('name', 'sitename', 'hub');
265 $options = array();
266 $registrationmanager = new registration_manager();
267 $options[HUB_SITENOTPUBLISHED] = $registrationmanager->get_site_privacy_string(HUB_SITENOTPUBLISHED);
268 $options[HUB_SITENAMEPUBLISHED] = $registrationmanager->get_site_privacy_string(HUB_SITENAMEPUBLISHED);
269 $options[HUB_SITELINKPUBLISHED] = $registrationmanager->get_site_privacy_string(HUB_SITELINKPUBLISHED);
270 $mform->addElement('select', 'privacy', get_string('siteprivacy', 'hub'), $options);
271 $mform->setDefault('privacy', $privacy);
272 $mform->addHelpButton('privacy', 'privacy', 'hub');
273 unset($options);
275 $mform->addElement('textarea', 'description', get_string('sitedesc', 'hub'),
276 array('rows' => 8, 'cols' => 41));
277 $mform->addRule('description', $strrequired, 'required', null, 'client');
278 $mform->setDefault('description', $sitedescription);
279 $mform->setType('description', PARAM_TEXT);
280 $mform->addHelpButton('description', 'sitedesc', 'hub');
282 $mform->addElement('static', 'urlstring', get_string('siteurl', 'hub'), $CFG->wwwroot);
283 $mform->addHelpButton('urlstring', 'siteurl', 'hub');
285 $languages = get_string_manager()->get_list_of_languages();
286 collatorlib::asort($languages);
287 $mform->addElement('select', 'language', get_string('sitelang', 'hub'),
288 $languages);
289 $mform->setType('language', PARAM_ALPHANUMEXT);
290 $mform->addHelpButton('language', 'sitelang', 'hub');
291 $mform->setDefault('language', $language);
293 $mform->addElement('static', 'versionstring', get_string('siteversion', 'hub'), $CFG->version);
294 $mform->addElement('hidden', 'moodleversion', $CFG->version);
295 $mform->setType('moodleversion', PARAM_INT);
296 $mform->addHelpButton('versionstring', 'siteversion', 'hub');
298 $mform->addElement('static', 'releasestring', get_string('siterelease', 'hub'), $CFG->release);
299 $mform->addElement('hidden', 'moodlerelease', $CFG->release);
300 $mform->setType('moodlerelease', PARAM_TEXT);
301 $mform->addHelpButton('releasestring', 'siterelease', 'hub');
303 $mform->addElement('textarea', 'address', get_string('postaladdress', 'hub'),
304 array('rows' => 4, 'cols' => 41));
305 $mform->setType('address', PARAM_TEXT);
306 $mform->setDefault('address', $address);
307 $mform->addHelpButton('address', 'postaladdress', 'hub');
309 //TODO: use the region array I generated
310 // $mform->addElement('select', 'region', get_string('selectaregion'), array('-' => '-'));
311 // $mform->setDefault('region', $region);
312 $mform->addElement('hidden', 'regioncode', '-');
313 $mform->setType('regioncode', PARAM_ALPHANUMEXT);
315 $countries = get_string_manager()->get_list_of_countries();
316 $mform->addElement('select', 'countrycode', get_string('sitecountry', 'hub'), $countries);
317 $mform->setDefault('countrycode', $country);
318 $mform->addHelpButton('countrycode', 'sitecountry', 'hub');
320 $mform->addElement('text', 'geolocation', get_string('sitegeolocation', 'hub'),
321 array('class' => 'registration_textfield'));
322 $mform->setDefault('geolocation', $geolocation);
323 $mform->addHelpButton('geolocation', 'sitegeolocation', 'hub');
325 $mform->addElement('text', 'contactname', get_string('siteadmin', 'hub'),
326 array('class' => 'registration_textfield'));
327 $mform->addRule('contactname', $strrequired, 'required', null, 'client');
328 $mform->setType('contactname', PARAM_TEXT);
329 $mform->setDefault('contactname', $contactname);
330 $mform->addHelpButton('contactname', 'siteadmin', 'hub');
332 $mform->addElement('text', 'contactphone', get_string('sitephone', 'hub'),
333 array('class' => 'registration_textfield'));
334 $mform->setType('contactphone', PARAM_TEXT);
335 $mform->addHelpButton('contactphone', 'sitephone', 'hub');
337 $mform->addElement('text', 'contactemail', get_string('siteemail', 'hub'),
338 array('class' => 'registration_textfield'));
339 $mform->addRule('contactemail', $strrequired, 'required', null, 'client');
340 $mform->setType('contactemail', PARAM_TEXT);
341 $mform->setDefault('contactemail', $contactemail);
342 $mform->addHelpButton('contactemail', 'siteemail', 'hub');
344 $options = array();
345 $options[0] = get_string("registrationcontactno");
346 $options[1] = get_string("registrationcontactyes");
347 $mform->addElement('select', 'contactable', get_string('siteregistrationcontact', 'hub'), $options);
348 $mform->setDefault('contactable', $contactable);
349 $mform->addHelpButton('contactable', 'siteregistrationcontact', 'hub');
350 unset($options);
352 $options = array();
353 $options[0] = get_string("registrationno");
354 $options[1] = get_string("registrationyes");
355 $mform->addElement('select', 'emailalert', get_string('siteregistrationemail', 'hub'), $options);
356 $mform->setDefault('emailalert', $emailalert);
357 $mform->addHelpButton('emailalert', 'siteregistrationemail', 'hub');
358 unset($options);
360 //TODO site logo
361 $mform->addElement('hidden', 'imageurl', ''); //TODO: temporary
362 $mform->setType('imageurl', PARAM_URL);
363 /// Display statistic that are going to be retrieve by the hub
364 $coursecount = $DB->count_records('course') - 1;
365 $usercount = $DB->count_records('user', array('deleted' => 0));
366 $roleassigncount = $DB->count_records('role_assignments');
367 $postcount = $DB->count_records('forum_posts');
368 $questioncount = $DB->count_records('question');
369 $resourcecount = $DB->count_records('resource');
370 require_once($CFG->dirroot . "/course/lib.php");
371 $participantnumberaverage = number_format(average_number_of_participants(), 2);
372 $modulenumberaverage = number_format(average_number_of_courses_modules(), 2);
374 if (HUB_MOODLEORGHUBURL != $huburl) {
375 $mform->addElement('checkbox', 'courses', get_string('sendfollowinginfo', 'hub'),
376 " " . get_string('coursesnumber', 'hub', $coursecount));
377 $mform->setDefault('courses', true);
378 $mform->addHelpButton('courses', 'sendfollowinginfo', 'hub');
380 $mform->addElement('checkbox', 'users', '',
381 " " . get_string('usersnumber', 'hub', $usercount));
382 $mform->setDefault('users', true);
384 $mform->addElement('checkbox', 'roleassignments', '',
385 " " . get_string('roleassignmentsnumber', 'hub', $roleassigncount));
386 $mform->setDefault('roleassignments', true);
388 $mform->addElement('checkbox', 'posts', '',
389 " " . get_string('postsnumber', 'hub', $postcount));
390 $mform->setDefault('posts', true);
392 $mform->addElement('checkbox', 'questions', '',
393 " " . get_string('questionsnumber', 'hub', $questioncount));
394 $mform->setDefault('questions', true);
396 $mform->addElement('checkbox', 'resources', '',
397 " " . get_string('resourcesnumber', 'hub', $resourcecount));
398 $mform->setDefault('resources', true);
400 $mform->addElement('checkbox', 'participantnumberaverage', '',
401 " " . get_string('participantnumberaverage', 'hub', $participantnumberaverage));
402 $mform->setDefault('participantnumberaverage', true);
404 $mform->addElement('checkbox', 'modulenumberaverage', '',
405 " " . get_string('modulenumberaverage', 'hub', $modulenumberaverage));
406 $mform->setDefault('modulenumberaverage', true);
407 } else {
408 $mform->addElement('static', 'courseslabel', get_string('sendfollowinginfo', 'hub'),
409 " " . get_string('coursesnumber', 'hub', $coursecount));
410 $mform->addElement('hidden', 'courses', true);
411 $mform->setType('courses', PARAM_FLOAT);
412 $mform->addHelpButton('courseslabel', 'sendfollowinginfo', 'hub');
414 $mform->addElement('static', 'userslabel', '',
415 " " . get_string('usersnumber', 'hub', $usercount));
416 $mform->addElement('hidden', 'users', true);
417 $mform->setType('users', PARAM_FLOAT);
419 $mform->addElement('static', 'roleassignmentslabel', '',
420 " " . get_string('roleassignmentsnumber', 'hub', $roleassigncount));
421 $mform->addElement('hidden', 'roleassignments', true);
422 $mform->setType('roleassignments', PARAM_FLOAT);
424 $mform->addElement('static', 'postslabel', '',
425 " " . get_string('postsnumber', 'hub', $postcount));
426 $mform->addElement('hidden', 'posts', true);
427 $mform->setType('posts', PARAM_FLOAT);
429 $mform->addElement('static', 'questionslabel', '',
430 " " . get_string('questionsnumber', 'hub', $questioncount));
431 $mform->addElement('hidden', 'questions', true);
432 $mform->setType('questions', PARAM_FLOAT);
434 $mform->addElement('static', 'resourceslabel', '',
435 " " . get_string('resourcesnumber', 'hub', $resourcecount));
436 $mform->addElement('hidden', 'resources', true);
437 $mform->setType('resources', PARAM_FLOAT);
439 $mform->addElement('static', 'participantnumberaveragelabel', '',
440 " " . get_string('participantnumberaverage', 'hub', $participantnumberaverage));
441 $mform->addElement('hidden', 'participantnumberaverage', true);
442 $mform->setType('participantnumberaverage', PARAM_FLOAT);
444 $mform->addElement('static', 'modulenumberaveragelabel', '',
445 " " . get_string('modulenumberaverage', 'hub', $modulenumberaverage));
446 $mform->addElement('hidden', 'modulenumberaverage', true);
447 $mform->setType('modulenumberaverage', PARAM_FLOAT);
450 //check if it's a first registration or update
451 $hubregistered = $registrationmanager->get_registeredhub($huburl);
453 if (!empty($hubregistered)) {
454 $buttonlabel = get_string('updatesite', 'hub',
455 !empty($hubname) ? $hubname : $huburl);
456 $mform->addElement('hidden', 'update', true);
457 $mform->setType('update', PARAM_BOOL);
458 } else {
459 $buttonlabel = get_string('registersite', 'hub',
460 !empty($hubname) ? $hubname : $huburl);
463 $this->add_action_buttons(false, $buttonlabel);