Merge branch 'MDL-59005-master' of git://github.com/lameze/moodle
[moodle.git] / admin / registration / forms.php
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 ///////////////////////////////////////////////////////////////////////////
23 /*
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
29  *
30  * The forms needed by registration pages.
31  */
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.
39  */
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->setType('unpublishalladvertisedcourses', PARAM_INT);
53         $mform->addElement('checkbox', 'unpublishalluploadedcourses', '',
54                 ' ' . get_string('unpublishalluploadedcourses', 'hub'));
55         $mform->setType('unpublishalluploadedcourses', PARAM_INT);
57         $mform->addElement('hidden', 'confirm', 1);
58         $mform->setType('confirm', PARAM_INT);
59         $mform->addElement('hidden', 'unregistration', 1);
60         $mform->setType('unregistration', PARAM_INT);
61         $mform->addElement('hidden', 'huburl', $huburl);
62         $mform->setType('huburl', PARAM_URL);
63         $mform->addElement('hidden', 'hubname', $hubname);
64         $mform->setType('hubname', PARAM_TEXT);
66         $this->add_action_buttons(true, $unregisterlabel);
67     }
69 }
71 /**
72  * This form display a clean registration data form.
73  */
74 class site_clean_registration_data_form extends moodleform {
76     public function definition() {
77         $mform = & $this->_form;
78         $mform->addElement('header', 'site', get_string('unregister', 'hub'));
80         $huburl = $this->_customdata['huburl'];
81         $hubname = $this->_customdata['hubname'];
84         $unregisterlabel = get_string('forceunregister', 'hub');
85         $mform->addElement('static', '', get_string('warning', 'hub'), get_string('forceunregisterconfirmation', 'hub', $hubname));
87         $mform->addElement('hidden', 'confirm', 1);
88         $mform->setType('confirm', PARAM_INT);
89         $mform->addElement('hidden', 'unregistration', 1);
90         $mform->setType('unregistration', PARAM_INT);
91         $mform->addElement('hidden', 'cleanregdata', 1);
92         $mform->setType('cleanregdata', PARAM_INT);
93         $mform->addElement('hidden', 'huburl', $huburl);
94         $mform->setType('huburl', PARAM_URL);
95         $mform->addElement('hidden', 'hubname', $hubname);
96         $mform->setType('hubname', PARAM_TEXT);
98         $this->add_action_buttons(true, $unregisterlabel);
99     }
103 /**
104  * This form display a hub selector.
105  * The hub list is retrieved from Moodle.org hub directory.
106  * Also displayed, a text field to enter private hub url + its password
107  */
108 class hub_selector_form extends moodleform {
110     public function definition() {
111         global $CFG, $OUTPUT;
112         $mform = & $this->_form;
113         $mform->addElement('header', 'site', get_string('selecthub', 'hub'));
115         //retrieve the hub list on the hub directory by web service
116         $function = 'hubdirectory_get_hubs';
117         $params = array();
118         $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php";
119         require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
120         $xmlrpcclient = new webservice_xmlrpc_client($serverurl, 'publichubdirectory');
121         try {
122             $hubs = $xmlrpcclient->call($function, $params);
123         } catch (Exception $e) {
124             $error = $OUTPUT->notification(get_string('errorhublisting', 'hub', $e->getMessage()));
125             $mform->addElement('static', 'errorhub', '', $error);
126             $hubs = array();
127         }
129         //remove moodle.org from the hub list
130         foreach ($hubs as $key => $hub) {
131             if ($hub['url'] == HUB_MOODLEORGHUBURL) {
132                 unset($hubs[$key]);
133             }
134         }
136         //Public hub list
137         $options = array();
138         foreach ($hubs as $hub) {
139             //to not display a name longer than 100 character (too big)
140             if (core_text::strlen($hub['name']) > 100) {
141                 $hubname = core_text::substr($hub['name'], 0, 100);
142                 $hubname = $hubname . "...";
143             } else {
144                 $hubname = $hub['name'];
145             }
146             $options[$hub['url']] = $hubname;
147             $mform->addElement('hidden', clean_param($hub['url'], PARAM_ALPHANUMEXT), $hubname);
148             $mform->setType(clean_param($hub['url'], PARAM_ALPHANUMEXT), PARAM_ALPHANUMEXT);
149         }
150         if (!empty($hubs)) {
151             $mform->addElement('select', 'publichub', get_string('publichub', 'hub'),
152                     $options, array("size" => 15));
153             $mform->setType('publichub', PARAM_URL);
154         }
156         $mform->addElement('static', 'or', '', get_string('orenterprivatehub', 'hub'));
158         //Private hub
159         $mform->addElement('text', 'unlistedurl', get_string('privatehuburl', 'hub'),
160                 array('class' => 'registration_textfield'));
161         $mform->setType('unlistedurl', PARAM_URL);
162         $mform->addElement('text', 'password', get_string('password'),
163                 array('class' => 'registration_textfield'));
164         $mform->setType('password', PARAM_RAW);
166         $this->add_action_buttons(false, get_string('selecthub', 'hub'));
167     }
169     /**
170      * Check the unlisted URL is a URL
171      */
172     function validation($data, $files) {
173         global $CFG;
174         $errors = parent::validation($data, $files);
176         $unlistedurl = $this->_form->_submitValues['unlistedurl'];
178         if (empty($unlistedurl)) {
179             $errors['unlistedurl'] = get_string('badurlformat', 'hub');
180         }
182         return $errors;
183     }
187 /**
188  * The site registration form. Information will be sent to a given hub.
189  */
190 class site_registration_form extends moodleform {
192     public function definition() {
193         global $CFG, $DB;
195         $strrequired = get_string('required');
196         $mform = & $this->_form;
197         $huburl = $this->_customdata['huburl'];
198         $hubname = $this->_customdata['hubname'];
199         $password = $this->_customdata['password'];
200         $admin = get_admin();
201         $site = get_site();
203         //retrieve config for this hub and set default if they don't exist
204         $cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
205         $sitename = get_config('hub', 'site_name_' . $cleanhuburl);
206         if ($sitename === false) {
207             $sitename = format_string($site->fullname, true, array('context' => context_course::instance(SITEID)));
208         }
209         $sitedescription = get_config('hub', 'site_description_' . $cleanhuburl);
210         if ($sitedescription === false) {
211             $sitedescription = $site->summary;
212         }
213         $contactname = get_config('hub', 'site_contactname_' . $cleanhuburl);
214         if ($contactname === false) {
215             $contactname = fullname($admin, true);
216         }
217         $contactemail = get_config('hub', 'site_contactemail_' . $cleanhuburl);
218         if ($contactemail === false) {
219             $contactemail = $admin->email;
220         }
221         $contactphone = get_config('hub', 'site_contactphone_' . $cleanhuburl);
222         if ($contactphone === false) {
223             $contactphone = $admin->phone1;
224         }
225         $imageurl = get_config('hub', 'site_imageurl_' . $cleanhuburl);
226         $privacy = get_config('hub', 'site_privacy_' . $cleanhuburl);
227         $address = get_config('hub', 'site_address_' . $cleanhuburl);
228         $region = get_config('hub', 'site_region_' . $cleanhuburl);
229         $country = get_config('hub', 'site_country_' . $cleanhuburl);
230         if ($country === false) {
231             $country = $admin->country;
232         }
233         $language = get_config('hub', 'site_language_' . $cleanhuburl);
234         if ($language === false) {
235             $language = current_language();
236         }
237         $geolocation = get_config('hub', 'site_geolocation_' . $cleanhuburl);
238         $contactable = get_config('hub', 'site_contactable_' . $cleanhuburl);
239         $emailalert = get_config('hub', 'site_emailalert_' . $cleanhuburl);
240         $emailalert = ($emailalert === 0) ? 0 : 1;
241         $coursesnumber = get_config('hub', 'site_coursesnumber_' . $cleanhuburl);
242         $usersnumber = get_config('hub', 'site_usersnumber_' . $cleanhuburl);
243         $roleassignmentsnumber = get_config('hub', 'site_roleassignmentsnumber_' . $cleanhuburl);
244         $postsnumber = get_config('hub', 'site_postsnumber_' . $cleanhuburl);
245         $questionsnumber = get_config('hub', 'site_questionsnumber_' . $cleanhuburl);
246         $resourcesnumber = get_config('hub', 'site_resourcesnumber_' . $cleanhuburl);
247         $badgesnumber = get_config('hub', 'site_badges_' . $cleanhuburl);
248         $issuedbadgesnumber = get_config('hub', 'site_issuedbadges_' . $cleanhuburl);
249         $mediancoursesize = get_config('hub', 'site_mediancoursesize_' . $cleanhuburl);
250         $participantnumberaveragecfg = get_config('hub', 'site_participantnumberaverage_' . $cleanhuburl);
251         $modulenumberaveragecfg = get_config('hub', 'site_modulenumberaverage_' . $cleanhuburl);
252         // Mobile related information.
253         $mobileservicesenabled = get_config('hub', 'site_mobileservicesenabled_' . $cleanhuburl);
254         $mobilenotificacionsenabled = get_config('hub', 'site_mobilenotificacionsenabled_' . $cleanhuburl);
255         $registereduserdevices = get_config('hub', 'site_registereduserdevices_' . $cleanhuburl);
256         $registeredactiveuserdevices = get_config('hub', 'site_registeredactiveuserdevices_' . $cleanhuburl);
258         //hidden parameters
259         $mform->addElement('hidden', 'huburl', $huburl);
260         $mform->setType('huburl', PARAM_URL);
261         $mform->addElement('hidden', 'hubname', $hubname);
262         $mform->setType('hubname', PARAM_TEXT);
263         $mform->addElement('hidden', 'password', $password);
264         $mform->setType('password', PARAM_RAW);
266         //the input parameters
267         $mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub'));
269         $mform->addElement('text', 'name', get_string('sitename', 'hub'),
270                 array('class' => 'registration_textfield'));
271         $mform->addRule('name', $strrequired, 'required', null, 'client');
272         $mform->setType('name', PARAM_TEXT);
273         $mform->setDefault('name', $sitename);
274         $mform->addHelpButton('name', 'sitename', 'hub');
276         $options = array();
277         $registrationmanager = new registration_manager();
278         $options[HUB_SITENOTPUBLISHED] = $registrationmanager->get_site_privacy_string(HUB_SITENOTPUBLISHED);
279         $options[HUB_SITENAMEPUBLISHED] = $registrationmanager->get_site_privacy_string(HUB_SITENAMEPUBLISHED);
280         $options[HUB_SITELINKPUBLISHED] = $registrationmanager->get_site_privacy_string(HUB_SITELINKPUBLISHED);
281         $mform->addElement('select', 'privacy', get_string('siteprivacy', 'hub'), $options);
282         $mform->setDefault('privacy', $privacy);
283         $mform->setType('privacy', PARAM_ALPHA);
284         $mform->addHelpButton('privacy', 'privacy', 'hub');
285         unset($options);
287         $mform->addElement('textarea', 'description', get_string('sitedesc', 'hub'),
288                 array('rows' => 8, 'cols' => 41));
289         $mform->addRule('description', $strrequired, 'required', null, 'client');
290         $mform->setDefault('description', $sitedescription);
291         $mform->setType('description', PARAM_TEXT);
292         $mform->addHelpButton('description', 'sitedesc', 'hub');
294         $languages = get_string_manager()->get_list_of_languages();
295         core_collator::asort($languages);
296         $mform->addElement('select', 'language', get_string('sitelang', 'hub'),
297                 $languages);
298         $mform->setType('language', PARAM_ALPHANUMEXT);
299         $mform->addHelpButton('language', 'sitelang', 'hub');
300         $mform->setDefault('language', $language);
302         $mform->addElement('textarea', 'address', get_string('postaladdress', 'hub'),
303                 array('rows' => 4, 'cols' => 41));
304         $mform->setType('address', PARAM_TEXT);
305         $mform->setDefault('address', $address);
306         $mform->addHelpButton('address', 'postaladdress', 'hub');
308         //TODO: use the region array I generated
309 //        $mform->addElement('select', 'region', get_string('selectaregion'), array('-' => '-'));
310 //        $mform->setDefault('region', $region);
311         $mform->addElement('hidden', 'regioncode', '-');
312         $mform->setType('regioncode', PARAM_ALPHANUMEXT);
314         $countries = get_string_manager()->get_list_of_countries();
315         $mform->addElement('select', 'countrycode', get_string('sitecountry', 'hub'), $countries);
316         $mform->setDefault('countrycode', $country);
317         $mform->setType('countrycode', PARAM_ALPHANUMEXT);
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->setType('geolocation', PARAM_RAW);
324         $mform->addHelpButton('geolocation', 'sitegeolocation', 'hub');
326         $mform->addElement('text', 'contactname', get_string('siteadmin', 'hub'),
327                 array('class' => 'registration_textfield'));
328         $mform->addRule('contactname', $strrequired, 'required', null, 'client');
329         $mform->setType('contactname', PARAM_TEXT);
330         $mform->setDefault('contactname', $contactname);
331         $mform->addHelpButton('contactname', 'siteadmin', 'hub');
333         $mform->addElement('text', 'contactphone', get_string('sitephone', 'hub'),
334                 array('class' => 'registration_textfield'));
335         $mform->setType('contactphone', PARAM_TEXT);
336         $mform->addHelpButton('contactphone', 'sitephone', 'hub');
337         $mform->setForceLtr('contactphone');
339         $mform->addElement('text', 'contactemail', get_string('siteemail', 'hub'),
340                 array('class' => 'registration_textfield'));
341         $mform->addRule('contactemail', $strrequired, 'required', null, 'client');
342         $mform->setType('contactemail', PARAM_EMAIL);
343         $mform->setDefault('contactemail', $contactemail);
344         $mform->addHelpButton('contactemail', 'siteemail', 'hub');
346         $options = array();
347         $options[0] = get_string("registrationcontactno");
348         $options[1] = get_string("registrationcontactyes");
349         $mform->addElement('select', 'contactable', get_string('siteregistrationcontact', 'hub'), $options);
350         $mform->setDefault('contactable', $contactable);
351         $mform->setType('contactable', PARAM_INT);
352         $mform->addHelpButton('contactable', 'siteregistrationcontact', 'hub');
353         unset($options);
355         $options = array();
356         $options[0] = get_string("registrationno");
357         $options[1] = get_string("registrationyes");
358         $mform->addElement('select', 'emailalert', get_string('siteregistrationemail', 'hub'), $options);
359         $mform->setDefault('emailalert', $emailalert);
360         $mform->setType('emailalert', PARAM_INT);
361         $mform->addHelpButton('emailalert', 'siteregistrationemail', 'hub');
362         unset($options);
364         //TODO site logo
365         $mform->addElement('hidden', 'imageurl', ''); //TODO: temporary
366         $mform->setType('imageurl', PARAM_URL);
368         $mform->addElement('static', 'urlstring', get_string('siteurl', 'hub'), $CFG->wwwroot);
369         $mform->addHelpButton('urlstring', 'siteurl', 'hub');
371         $mform->addElement('static', 'versionstring', get_string('siteversion', 'hub'), $CFG->version);
372         $mform->addElement('hidden', 'moodleversion', $CFG->version);
373         $mform->setType('moodleversion', PARAM_INT);
374         $mform->addHelpButton('versionstring', 'siteversion', 'hub');
376         $mform->addElement('static', 'releasestring', get_string('siterelease', 'hub'), $CFG->release);
377         $mform->addElement('hidden', 'moodlerelease', $CFG->release);
378         $mform->setType('moodlerelease', PARAM_TEXT);
379         $mform->addHelpButton('releasestring', 'siterelease', 'hub');
381         /// Display statistic that are going to be retrieve by the hub
382         $coursecount = $DB->count_records('course') - 1;
383         $usercount = $DB->count_records('user', array('deleted' => 0));
384         $roleassigncount = $DB->count_records('role_assignments');
385         $postcount = $DB->count_records('forum_posts');
386         $questioncount = $DB->count_records('question');
387         $resourcecount = $DB->count_records('resource');
388         require_once($CFG->dirroot . "/course/lib.php");
389         $participantnumberaverage = number_format(average_number_of_participants(), 2);
390         $modulenumberaverage = number_format(average_number_of_courses_modules(), 2);
391         require_once($CFG->libdir . '/badgeslib.php');
392         $badges = $DB->count_records_select('badge', 'status <> ' . BADGE_STATUS_ARCHIVED);
393         $issuedbadges = $DB->count_records('badge_issued');
394         // Mobile related information.
395         $ismobileenabled = false;
396         $aremobilenotificationsenabled = false;
397         $registereduserdevicescount = 0;
398         $registeredactiveuserdevicescount = 0;
399         if (!empty($CFG->enablewebservices) && !empty($CFG->enablemobilewebservice)) {
400             $ismobileenabled = true;
401             $registereduserdevicescount = $DB->count_records('user_devices');
402             $airnotifierextpath = $CFG->dirroot . '/message/output/airnotifier/externallib.php';
403             if (file_exists($airnotifierextpath)) { // Maybe some one uninstalled the plugin.
404                 require_once($airnotifierextpath);
405                 $aremobilenotificationsenabled = (bool) message_airnotifier_external::is_system_configured();
406                 $registeredactiveuserdevicescount = $DB->count_records('message_airnotifier_devices', array('enable' => 1));
407             }
408         }
410         if (HUB_MOODLEORGHUBURL != $huburl) {
411             $mform->addElement('checkbox', 'courses', get_string('sendfollowinginfo', 'hub'),
412                     " " . get_string('coursesnumber', 'hub', $coursecount));
413             $mform->setDefault('courses', $coursesnumber != -1);
414             $mform->setType('courses', PARAM_INT);
415             $mform->addHelpButton('courses', 'sendfollowinginfo', 'hub');
417             $mform->addElement('checkbox', 'users', '',
418                     " " . get_string('usersnumber', 'hub', $usercount));
419             $mform->setDefault('users', $usersnumber != -1);
420             $mform->setType('users', PARAM_INT);
422             $mform->addElement('checkbox', 'roleassignments', '',
423                     " " . get_string('roleassignmentsnumber', 'hub', $roleassigncount));
424             $mform->setDefault('roleassignments', $roleassignmentsnumber != -1);
425             $mform->setType('roleassignments', PARAM_INT);
427             $mform->addElement('checkbox', 'posts', '',
428                     " " . get_string('postsnumber', 'hub', $postcount));
429             $mform->setDefault('posts', $postsnumber != -1);
430             $mform->setType('posts', PARAM_INT);
432             $mform->addElement('checkbox', 'questions', '',
433                     " " . get_string('questionsnumber', 'hub', $questioncount));
434             $mform->setDefault('questions', $questionsnumber != -1);
435             $mform->setType('questions', PARAM_INT);
437             $mform->addElement('checkbox', 'resources', '',
438                     " " . get_string('resourcesnumber', 'hub', $resourcecount));
439             $mform->setDefault('resources', $resourcesnumber != -1);
440             $mform->setType('resources', PARAM_INT);
442             $mform->addElement('checkbox', 'badges', '',
443                     " " . get_string('badgesnumber', 'hub', $badges));
444             $mform->setDefault('badges', $badgesnumber != -1);
445             $mform->setType('badges', PARAM_INT);
447             $mform->addElement('checkbox', 'issuedbadges', '',
448                     " " . get_string('issuedbadgesnumber', 'hub', $issuedbadges));
449             $mform->setDefault('issuedbadges', $issuedbadgesnumber != -1);
450             $mform->setType('issuedbadges', PARAM_INT);
452             $mform->addElement('checkbox', 'participantnumberaverage', '',
453                     " " . get_string('participantnumberaverage', 'hub', $participantnumberaverage));
454             $mform->setDefault('participantnumberaverage', $participantnumberaveragecfg != -1);
455             $mform->setType('participantnumberaverage', PARAM_FLOAT);
457             $mform->addElement('checkbox', 'modulenumberaverage', '',
458                     " " . get_string('modulenumberaverage', 'hub', $modulenumberaverage));
459             $mform->setDefault('modulenumberaverage', $modulenumberaveragecfg != -1);
460             $mform->setType('modulenumberaverage', PARAM_FLOAT);
462             $mobileservicestatus = $ismobileenabled ? 'yes' : 'no';
463             $mform->addElement('checkbox', 'mobileservicesenabled', '',
464                     " " . get_string('mobileservicesenabled', 'hub', $mobileservicestatus));
465             $mform->setDefault('mobileservicesenabled', $mobileservicesenabled != -1);
466             $mform->setType('mobileservicesenabled', PARAM_INT);
468             $mobilenotificationsstatus = $aremobilenotificationsenabled ? 'yes' : 'no';
469             $mform->addElement('checkbox', 'mobilenotificacionsenabled', '',
470                     " " . get_string('mobilenotificacionsenabled', 'hub', $mobilenotificationsstatus));
471             $mform->setDefault('mobilenotificacionsenabled', $mobilenotificacionsenabled != -1);
472             $mform->setType('mobilenotificacionsenabled', PARAM_INT);
474             $mform->addElement('checkbox', 'registereduserdevices', '',
475                     " " . get_string('registereduserdevices', 'hub', $registereduserdevicescount));
476             $mform->setDefault('registereduserdevices', $registereduserdevices != -1);
477             $mform->setType('registereduserdevices', PARAM_INT);
479             $mform->addElement('checkbox', 'registeredactiveuserdevices', '',
480                     " " . get_string('registeredactiveuserdevices', 'hub', $registeredactiveuserdevicescount));
481             $mform->setDefault('registeredactiveuserdevices', $registeredactiveuserdevices != -1);
482             $mform->setType('registeredactiveuserdevices', PARAM_INT);
483         } else {
484             $mform->addElement('static', 'courseslabel', get_string('sendfollowinginfo', 'hub'),
485                     " " . get_string('coursesnumber', 'hub', $coursecount));
486             $mform->addElement('hidden', 'courses', 1);
487             $mform->setType('courses', PARAM_INT);
488             $mform->addHelpButton('courseslabel', 'sendfollowinginfo', 'hub');
490             $mform->addElement('static', 'userslabel', '',
491                     " " . get_string('usersnumber', 'hub', $usercount));
492             $mform->addElement('hidden', 'users', 1);
493             $mform->setType('users', PARAM_INT);
495             $mform->addElement('static', 'roleassignmentslabel', '',
496                     " " . get_string('roleassignmentsnumber', 'hub', $roleassigncount));
497             $mform->addElement('hidden', 'roleassignments', 1);
498             $mform->setType('roleassignments', PARAM_INT);
500             $mform->addElement('static', 'postslabel', '',
501                     " " . get_string('postsnumber', 'hub', $postcount));
502             $mform->addElement('hidden', 'posts', 1);
503             $mform->setType('posts', PARAM_INT);
505             $mform->addElement('static', 'questionslabel', '',
506                     " " . get_string('questionsnumber', 'hub', $questioncount));
507             $mform->addElement('hidden', 'questions', 1);
508             $mform->setType('questions', PARAM_INT);
510             $mform->addElement('static', 'resourceslabel', '',
511                     " " . get_string('resourcesnumber', 'hub', $resourcecount));
512             $mform->addElement('hidden', 'resources', 1);
513             $mform->setType('resources', PARAM_INT);
515             $mform->addElement('static', 'badgeslabel', '',
516                     " " . get_string('badgesnumber', 'hub', $badges));
517             $mform->addElement('hidden', 'badges', 1);
518             $mform->setType('badges', PARAM_INT);
520             $mform->addElement('static', 'issuedbadgeslabel', '',
521                     " " . get_string('issuedbadgesnumber', 'hub', $issuedbadges));
522             $mform->addElement('hidden', 'issuedbadges', true);
523             $mform->setType('issuedbadges', PARAM_INT);
525             $mform->addElement('static', 'participantnumberaveragelabel', '',
526                     " " . get_string('participantnumberaverage', 'hub', $participantnumberaverage));
527             $mform->addElement('hidden', 'participantnumberaverage', 1);
528             $mform->setType('participantnumberaverage', PARAM_FLOAT);
530             $mform->addElement('static', 'modulenumberaveragelabel', '',
531                     " " . get_string('modulenumberaverage', 'hub', $modulenumberaverage));
532             $mform->addElement('hidden', 'modulenumberaverage', 1);
533             $mform->setType('modulenumberaverage', PARAM_FLOAT);
535             $mobileservicestatus = $ismobileenabled ? 'yes' : 'no';
536             $mform->addElement('static', 'mobileservicesenabledlabel', '',
537                     " " . get_string('mobileservicesenabled', 'hub', $mobileservicestatus));
538             $mform->addElement('hidden', 'mobileservicesenabled', 1);
539             $mform->setType('mobileservicesenabled', PARAM_INT);
541             $mobilenotificationsstatus = $aremobilenotificationsenabled ? 'yes' : 'no';
542             $mform->addElement('static', 'mobilenotificacionsenabledlabel', '',
543                     " " . get_string('mobilenotificacionsenabled', 'hub', $mobilenotificationsstatus));
544             $mform->addElement('hidden', 'mobilenotificacionsenabled', 1);
545             $mform->setType('mobilenotificacionsenabled', PARAM_INT);
547             $mform->addElement('static', 'registereduserdeviceslabel', '',
548                     " " . get_string('registereduserdevices', 'hub', $registereduserdevicescount));
549             $mform->addElement('hidden', 'registereduserdevices', 1);
550             $mform->setType('registereduserdevices', PARAM_INT);
552             $mform->addElement('static', 'registeredactiveuserdeviceslabel', '',
553                     " " . get_string('registeredactiveuserdevices', 'hub', $registeredactiveuserdevicescount));
554             $mform->addElement('hidden', 'registeredactiveuserdevices', 1);
555             $mform->setType('registeredactiveuserdevices', PARAM_INT);
556         }
558         //check if it's a first registration or update
559         $hubregistered = $registrationmanager->get_registeredhub($huburl);
561         if (!empty($hubregistered)) {
562             $buttonlabel = get_string('updatesite', 'hub',
563                             !empty($hubname) ? $hubname : $huburl);
564             $mform->addElement('hidden', 'update', true);
565             $mform->setType('update', PARAM_BOOL);
566         } else {
567             $buttonlabel = get_string('registersite', 'hub',
568                             !empty($hubname) ? $hubname : $huburl);
569         }
571         $this->add_action_buttons(false, $buttonlabel);
572     }