Commit | Line | Data |
---|---|---|
07ab0c80 | 1 | <?php |
2c9bb9c3 | 2 | |
07ab0c80 | 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 | /////////////////////////////////////////////////////////////////////////// | |
22 | ||
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. | |
2c9bb9c3 | 31 | */ |
07ab0c80 | 32 | |
33 | ||
a8e174cc | 34 | require_once($CFG->libdir . '/formslib.php'); |
35 | require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php'); | |
07ab0c80 | 36 | |
f57c4047 | 37 | /** |
38 | * This form display a unregistration form. | |
39 | */ | |
40 | class site_unregistration_form extends moodleform { | |
41 | ||
42 | public function definition() { | |
43 | $mform = & $this->_form; | |
44 | $mform->addElement('header', 'site', get_string('unregister', 'hub')); | |
45 | ||
46 | $huburl = $this->_customdata['huburl']; | |
47 | $hubname = $this->_customdata['hubname']; | |
48 | ||
49 | $unregisterlabel = get_string('unregister', 'hub'); | |
50 | $mform->addElement('checkbox', 'unpublishalladvertisedcourses', '', | |
51 | ' ' . get_string('unpublishalladvertisedcourses', 'hub')); | |
1fe56a2a | 52 | $mform->setType('unpublishalladvertisedcourses', PARAM_INT); |
f57c4047 | 53 | $mform->addElement('checkbox', 'unpublishalluploadedcourses', '', |
54 | ' ' . get_string('unpublishalluploadedcourses', 'hub')); | |
1fe56a2a | 55 | $mform->setType('unpublishalluploadedcourses', PARAM_INT); |
f57c4047 | 56 | |
57 | $mform->addElement('hidden', 'confirm', 1); | |
f8758d68 | 58 | $mform->setType('confirm', PARAM_INT); |
f57c4047 | 59 | $mform->addElement('hidden', 'unregistration', 1); |
f8758d68 | 60 | $mform->setType('unregistration', PARAM_INT); |
f57c4047 | 61 | $mform->addElement('hidden', 'huburl', $huburl); |
f8758d68 | 62 | $mform->setType('huburl', PARAM_URL); |
f57c4047 | 63 | $mform->addElement('hidden', 'hubname', $hubname); |
f8758d68 | 64 | $mform->setType('hubname', PARAM_TEXT); |
f57c4047 | 65 | |
66 | $this->add_action_buttons(true, $unregisterlabel); | |
67 | } | |
68 | ||
69 | } | |
70 | ||
71 | /** | |
72 | * This form display a clean registration data form. | |
73 | */ | |
74 | class site_clean_registration_data_form extends moodleform { | |
75 | ||
76 | public function definition() { | |
77 | $mform = & $this->_form; | |
78 | $mform->addElement('header', 'site', get_string('unregister', 'hub')); | |
79 | ||
80 | $huburl = $this->_customdata['huburl']; | |
81 | $hubname = $this->_customdata['hubname']; | |
82 | ||
83 | ||
84 | $unregisterlabel = get_string('forceunregister', 'hub'); | |
85 | $mform->addElement('static', '', get_string('warning', 'hub'), get_string('forceunregisterconfirmation', 'hub', $hubname)); | |
86 | ||
f57c4047 | 87 | $mform->addElement('hidden', 'confirm', 1); |
f8758d68 | 88 | $mform->setType('confirm', PARAM_INT); |
f57c4047 | 89 | $mform->addElement('hidden', 'unregistration', 1); |
f8758d68 | 90 | $mform->setType('unregistration', PARAM_INT); |
f57c4047 | 91 | $mform->addElement('hidden', 'cleanregdata', 1); |
f8758d68 | 92 | $mform->setType('cleanregdata', PARAM_INT); |
f57c4047 | 93 | $mform->addElement('hidden', 'huburl', $huburl); |
f8758d68 | 94 | $mform->setType('huburl', PARAM_URL); |
f57c4047 | 95 | $mform->addElement('hidden', 'hubname', $hubname); |
f8758d68 | 96 | $mform->setType('hubname', PARAM_TEXT); |
f57c4047 | 97 | |
98 | $this->add_action_buttons(true, $unregisterlabel); | |
99 | } | |
100 | ||
101 | } | |
102 | ||
07ab0c80 | 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 { | |
109 | ||
110 | public function definition() { | |
2c9bb9c3 | 111 | global $CFG, $OUTPUT; |
112 | $mform = & $this->_form; | |
07ab0c80 | 113 | $mform->addElement('header', 'site', get_string('selecthub', 'hub')); |
114 | ||
115 | //retrieve the hub list on the hub directory by web service | |
116 | $function = 'hubdirectory_get_hubs'; | |
117 | $params = array(); | |
2c9bb9c3 | 118 | $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php"; |
119 | require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php"); | |
001251f2 | 120 | $xmlrpcclient = new webservice_xmlrpc_client($serverurl, 'publichubdirectory'); |
2c9bb9c3 | 121 | try { |
001251f2 | 122 | $hubs = $xmlrpcclient->call($function, $params); |
2c9bb9c3 | 123 | } catch (Exception $e) { |
124 | $error = $OUTPUT->notification(get_string('errorhublisting', 'hub', $e->getMessage())); | |
125 | $mform->addElement('static', 'errorhub', '', $error); | |
126 | $hubs = array(); | |
127 | } | |
07ab0c80 | 128 | |
a33cc71f | 129 | //remove moodle.org from the hub list |
130 | foreach ($hubs as $key => $hub) { | |
06d4578c | 131 | if ($hub['url'] == HUB_MOODLEORGHUBURL) { |
a33cc71f | 132 | unset($hubs[$key]); |
133 | } | |
134 | } | |
135 | ||
07ab0c80 | 136 | //Public hub list |
137 | $options = array(); | |
138 | foreach ($hubs as $hub) { | |
139 | //to not display a name longer than 100 character (too big) | |
2f1e464a PS |
140 | if (core_text::strlen($hub['name']) > 100) { |
141 | $hubname = core_text::substr($hub['name'], 0, 100); | |
2c9bb9c3 | 142 | $hubname = $hubname . "..."; |
07ab0c80 | 143 | } else { |
144 | $hubname = $hub['name']; | |
145 | } | |
146 | $options[$hub['url']] = $hubname; | |
147 | $mform->addElement('hidden', clean_param($hub['url'], PARAM_ALPHANUMEXT), $hubname); | |
f8758d68 | 148 | $mform->setType(clean_param($hub['url'], PARAM_ALPHANUMEXT), PARAM_ALPHANUMEXT); |
07ab0c80 | 149 | } |
2c9bb9c3 | 150 | if (!empty($hubs)) { |
151 | $mform->addElement('select', 'publichub', get_string('publichub', 'hub'), | |
152 | $options, array("size" => 15)); | |
1fe56a2a | 153 | $mform->setType('publichub', PARAM_URL); |
2c9bb9c3 | 154 | } |
07ab0c80 | 155 | |
2c9bb9c3 | 156 | $mform->addElement('static', 'or', '', get_string('orenterprivatehub', 'hub')); |
07ab0c80 | 157 | |
158 | //Private hub | |
20e033bd | 159 | $mform->addElement('text', 'unlistedurl', get_string('privatehuburl', 'hub'), |
160 | array('class' => 'registration_textfield')); | |
1fe56a2a | 161 | $mform->setType('unlistedurl', PARAM_URL); |
20e033bd | 162 | $mform->addElement('text', 'password', get_string('password'), |
163 | array('class' => 'registration_textfield')); | |
1fe56a2a | 164 | $mform->setType('password', PARAM_RAW); |
07ab0c80 | 165 | |
166 | $this->add_action_buttons(false, get_string('selecthub', 'hub')); | |
167 | } | |
168 | ||
169 | /** | |
170 | * Check the unlisted URL is a URL | |
171 | */ | |
172 | function validation($data, $files) { | |
173 | global $CFG; | |
174 | $errors = parent::validation($data, $files); | |
175 | ||
176 | $unlistedurl = $this->_form->_submitValues['unlistedurl']; | |
177 | ||
1fe56a2a RT |
178 | if (empty($unlistedurl)) { |
179 | $errors['unlistedurl'] = get_string('badurlformat', 'hub'); | |
07ab0c80 | 180 | } |
181 | ||
182 | return $errors; | |
183 | } | |
184 | ||
185 | } | |
186 | ||
07ab0c80 | 187 | /** |
188 | * The site registration form. Information will be sent to a given hub. | |
189 | */ | |
190 | class site_registration_form extends moodleform { | |
191 | ||
192 | public function definition() { | |
193 | global $CFG, $DB; | |
194 | ||
195 | $strrequired = get_string('required'); | |
2c9bb9c3 | 196 | $mform = & $this->_form; |
07ab0c80 | 197 | $huburl = $this->_customdata['huburl']; |
198 | $hubname = $this->_customdata['hubname']; | |
4b1acb3a | 199 | $password = $this->_customdata['password']; |
07ab0c80 | 200 | $admin = get_admin(); |
201 | $site = get_site(); | |
202 | ||
203 | //retrieve config for this hub and set default if they don't exist | |
204 | $cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT); | |
2c9bb9c3 | 205 | $sitename = get_config('hub', 'site_name_' . $cleanhuburl); |
07ab0c80 | 206 | if ($sitename === false) { |
bf006d2c | 207 | $sitename = format_string($site->fullname, true, array('context' => context_course::instance(SITEID))); |
07ab0c80 | 208 | } |
2c9bb9c3 | 209 | $sitedescription = get_config('hub', 'site_description_' . $cleanhuburl); |
07ab0c80 | 210 | if ($sitedescription === false) { |
211 | $sitedescription = $site->summary; | |
212 | } | |
2c9bb9c3 | 213 | $contactname = get_config('hub', 'site_contactname_' . $cleanhuburl); |
07ab0c80 | 214 | if ($contactname === false) { |
215 | $contactname = fullname($admin, true); | |
216 | } | |
2c9bb9c3 | 217 | $contactemail = get_config('hub', 'site_contactemail_' . $cleanhuburl); |
07ab0c80 | 218 | if ($contactemail === false) { |
219 | $contactemail = $admin->email; | |
220 | } | |
2c9bb9c3 | 221 | $contactphone = get_config('hub', 'site_contactphone_' . $cleanhuburl); |
07ab0c80 | 222 | if ($contactphone === false) { |
223 | $contactphone = $admin->phone1; | |
224 | } | |
2c9bb9c3 | 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); | |
07ab0c80 | 230 | if ($country === false) { |
2c9bb9c3 | 231 | $country = $admin->country; |
07ab0c80 | 232 | } |
daff57fb | 233 | $language = get_config('hub', 'site_language_' . $cleanhuburl); |
234 | if ($language === false) { | |
c14e697e | 235 | $language = explode('_', current_language())[0]; |
daff57fb | 236 | } |
2c9bb9c3 | 237 | $geolocation = get_config('hub', 'site_geolocation_' . $cleanhuburl); |
238 | $contactable = get_config('hub', 'site_contactable_' . $cleanhuburl); | |
239 | $emailalert = get_config('hub', 'site_emailalert_' . $cleanhuburl); | |
b3245b75 | 240 | $emailalert = ($emailalert === 0) ? 0 : 1; |
2c9bb9c3 | 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); | |
669dee58 JM |
247 | $badgesnumber = get_config('hub', 'site_badges_' . $cleanhuburl); |
248 | $issuedbadgesnumber = get_config('hub', 'site_issuedbadges_' . $cleanhuburl); | |
2c9bb9c3 | 249 | $mediancoursesize = get_config('hub', 'site_mediancoursesize_' . $cleanhuburl); |
669dee58 JM |
250 | $participantnumberaveragecfg = get_config('hub', 'site_participantnumberaverage_' . $cleanhuburl); |
251 | $modulenumberaveragecfg = get_config('hub', 'site_modulenumberaverage_' . $cleanhuburl); | |
bf1babe5 JL |
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); | |
07ab0c80 | 257 | |
258 | //hidden parameters | |
259 | $mform->addElement('hidden', 'huburl', $huburl); | |
f8758d68 | 260 | $mform->setType('huburl', PARAM_URL); |
07ab0c80 | 261 | $mform->addElement('hidden', 'hubname', $hubname); |
f8758d68 | 262 | $mform->setType('hubname', PARAM_TEXT); |
4b1acb3a | 263 | $mform->addElement('hidden', 'password', $password); |
f8758d68 | 264 | $mform->setType('password', PARAM_RAW); |
07ab0c80 | 265 | |
266 | //the input parameters | |
267 | $mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub')); | |
268 | ||
2c9bb9c3 | 269 | $mform->addElement('text', 'name', get_string('sitename', 'hub'), |
139978e5 | 270 | array('class' => 'registration_textfield')); |
07ab0c80 | 271 | $mform->addRule('name', $strrequired, 'required', null, 'client'); |
272 | $mform->setType('name', PARAM_TEXT); | |
273 | $mform->setDefault('name', $sitename); | |
139978e5 | 274 | $mform->addHelpButton('name', 'sitename', 'hub'); |
07ab0c80 | 275 | |
276 | $options = array(); | |
94788de2 | 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); | |
07ab0c80 | 281 | $mform->addElement('select', 'privacy', get_string('siteprivacy', 'hub'), $options); |
282 | $mform->setDefault('privacy', $privacy); | |
1fe56a2a | 283 | $mform->setType('privacy', PARAM_ALPHA); |
4032415e | 284 | $mform->addHelpButton('privacy', 'privacy', 'hub'); |
07ab0c80 | 285 | unset($options); |
286 | ||
139978e5 | 287 | $mform->addElement('textarea', 'description', get_string('sitedesc', 'hub'), |
2c9bb9c3 | 288 | array('rows' => 8, 'cols' => 41)); |
07ab0c80 | 289 | $mform->addRule('description', $strrequired, 'required', null, 'client'); |
290 | $mform->setDefault('description', $sitedescription); | |
291 | $mform->setType('description', PARAM_TEXT); | |
139978e5 | 292 | $mform->addHelpButton('description', 'sitedesc', 'hub'); |
07ab0c80 | 293 | |
07ab0c80 | 294 | $languages = get_string_manager()->get_list_of_languages(); |
2f1e464a | 295 | core_collator::asort($languages); |
daff57fb | 296 | $mform->addElement('select', 'language', get_string('sitelang', 'hub'), |
297 | $languages); | |
f8758d68 | 298 | $mform->setType('language', PARAM_ALPHANUMEXT); |
daff57fb | 299 | $mform->addHelpButton('language', 'sitelang', 'hub'); |
300 | $mform->setDefault('language', $language); | |
07ab0c80 | 301 | |
2c9bb9c3 | 302 | $mform->addElement('textarea', 'address', get_string('postaladdress', 'hub'), |
303 | array('rows' => 4, 'cols' => 41)); | |
07ab0c80 | 304 | $mform->setType('address', PARAM_TEXT); |
305 | $mform->setDefault('address', $address); | |
139978e5 | 306 | $mform->addHelpButton('address', 'postaladdress', 'hub'); |
07ab0c80 | 307 | |
308 | //TODO: use the region array I generated | |
4032415e | 309 | // $mform->addElement('select', 'region', get_string('selectaregion'), array('-' => '-')); |
310 | // $mform->setDefault('region', $region); | |
311 | $mform->addElement('hidden', 'regioncode', '-'); | |
f8758d68 | 312 | $mform->setType('regioncode', PARAM_ALPHANUMEXT); |
07ab0c80 | 313 | |
314 | $countries = get_string_manager()->get_list_of_countries(); | |
139978e5 | 315 | $mform->addElement('select', 'countrycode', get_string('sitecountry', 'hub'), $countries); |
4032415e | 316 | $mform->setDefault('countrycode', $country); |
1fe56a2a | 317 | $mform->setType('countrycode', PARAM_ALPHANUMEXT); |
139978e5 | 318 | $mform->addHelpButton('countrycode', 'sitecountry', 'hub'); |
07ab0c80 | 319 | |
2c9bb9c3 | 320 | $mform->addElement('text', 'geolocation', get_string('sitegeolocation', 'hub'), |
139978e5 | 321 | array('class' => 'registration_textfield')); |
07ab0c80 | 322 | $mform->setDefault('geolocation', $geolocation); |
1fe56a2a | 323 | $mform->setType('geolocation', PARAM_RAW); |
139978e5 | 324 | $mform->addHelpButton('geolocation', 'sitegeolocation', 'hub'); |
07ab0c80 | 325 | |
139978e5 | 326 | $mform->addElement('text', 'contactname', get_string('siteadmin', 'hub'), |
327 | array('class' => 'registration_textfield')); | |
07ab0c80 | 328 | $mform->addRule('contactname', $strrequired, 'required', null, 'client'); |
329 | $mform->setType('contactname', PARAM_TEXT); | |
330 | $mform->setDefault('contactname', $contactname); | |
139978e5 | 331 | $mform->addHelpButton('contactname', 'siteadmin', 'hub'); |
07ab0c80 | 332 | |
2c9bb9c3 | 333 | $mform->addElement('text', 'contactphone', get_string('sitephone', 'hub'), |
139978e5 | 334 | array('class' => 'registration_textfield')); |
07ab0c80 | 335 | $mform->setType('contactphone', PARAM_TEXT); |
139978e5 | 336 | $mform->addHelpButton('contactphone', 'sitephone', 'hub'); |
525ef9c8 | 337 | $mform->setForceLtr('contactphone'); |
07ab0c80 | 338 | |
139978e5 | 339 | $mform->addElement('text', 'contactemail', get_string('siteemail', 'hub'), |
340 | array('class' => 'registration_textfield')); | |
07ab0c80 | 341 | $mform->addRule('contactemail', $strrequired, 'required', null, 'client'); |
1fe56a2a | 342 | $mform->setType('contactemail', PARAM_EMAIL); |
07ab0c80 | 343 | $mform->setDefault('contactemail', $contactemail); |
139978e5 | 344 | $mform->addHelpButton('contactemail', 'siteemail', 'hub'); |
07ab0c80 | 345 | |
346 | $options = array(); | |
347 | $options[0] = get_string("registrationcontactno"); | |
348 | $options[1] = get_string("registrationcontactyes"); | |
139978e5 | 349 | $mform->addElement('select', 'contactable', get_string('siteregistrationcontact', 'hub'), $options); |
07ab0c80 | 350 | $mform->setDefault('contactable', $contactable); |
1fe56a2a | 351 | $mform->setType('contactable', PARAM_INT); |
139978e5 | 352 | $mform->addHelpButton('contactable', 'siteregistrationcontact', 'hub'); |
07ab0c80 | 353 | unset($options); |
354 | ||
355 | $options = array(); | |
356 | $options[0] = get_string("registrationno"); | |
357 | $options[1] = get_string("registrationyes"); | |
139978e5 | 358 | $mform->addElement('select', 'emailalert', get_string('siteregistrationemail', 'hub'), $options); |
07ab0c80 | 359 | $mform->setDefault('emailalert', $emailalert); |
1fe56a2a | 360 | $mform->setType('emailalert', PARAM_INT); |
139978e5 | 361 | $mform->addHelpButton('emailalert', 'siteregistrationemail', 'hub'); |
07ab0c80 | 362 | unset($options); |
363 | ||
139978e5 | 364 | //TODO site logo |
e275f25e | 365 | $mform->addElement('hidden', 'imageurl', ''); //TODO: temporary |
f8758d68 | 366 | $mform->setType('imageurl', PARAM_URL); |
b3245b75 DP |
367 | |
368 | $mform->addElement('static', 'urlstring', get_string('siteurl', 'hub'), $CFG->wwwroot); | |
369 | $mform->addHelpButton('urlstring', 'siteurl', 'hub'); | |
370 | ||
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'); | |
375 | ||
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'); | |
380 | ||
07ab0c80 | 381 | /// Display statistic that are going to be retrieve by the hub |
2c9bb9c3 | 382 | $coursecount = $DB->count_records('course') - 1; |
383 | $usercount = $DB->count_records('user', array('deleted' => 0)); | |
07ab0c80 | 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'); | |
2c9bb9c3 | 388 | require_once($CFG->dirroot . "/course/lib.php"); |
ceac2af3 | 389 | $participantnumberaverage = number_format(average_number_of_participants(), 2); |
390 | $modulenumberaverage = number_format(average_number_of_courses_modules(), 2); | |
27806552 YB |
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'); | |
bf1babe5 JL |
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 | } | |
07ab0c80 | 409 | |
06d4578c | 410 | if (HUB_MOODLEORGHUBURL != $huburl) { |
2c9bb9c3 | 411 | $mform->addElement('checkbox', 'courses', get_string('sendfollowinginfo', 'hub'), |
412 | " " . get_string('coursesnumber', 'hub', $coursecount)); | |
669dee58 | 413 | $mform->setDefault('courses', $coursesnumber != -1); |
1fe56a2a | 414 | $mform->setType('courses', PARAM_INT); |
139978e5 | 415 | $mform->addHelpButton('courses', 'sendfollowinginfo', 'hub'); |
07ab0c80 | 416 | |
417 | $mform->addElement('checkbox', 'users', '', | |
2c9bb9c3 | 418 | " " . get_string('usersnumber', 'hub', $usercount)); |
669dee58 | 419 | $mform->setDefault('users', $usersnumber != -1); |
1fe56a2a | 420 | $mform->setType('users', PARAM_INT); |
07ab0c80 | 421 | |
422 | $mform->addElement('checkbox', 'roleassignments', '', | |
2c9bb9c3 | 423 | " " . get_string('roleassignmentsnumber', 'hub', $roleassigncount)); |
669dee58 | 424 | $mform->setDefault('roleassignments', $roleassignmentsnumber != -1); |
1fe56a2a | 425 | $mform->setType('roleassignments', PARAM_INT); |
07ab0c80 | 426 | |
427 | $mform->addElement('checkbox', 'posts', '', | |
2c9bb9c3 | 428 | " " . get_string('postsnumber', 'hub', $postcount)); |
669dee58 | 429 | $mform->setDefault('posts', $postsnumber != -1); |
1fe56a2a | 430 | $mform->setType('posts', PARAM_INT); |
07ab0c80 | 431 | |
432 | $mform->addElement('checkbox', 'questions', '', | |
2c9bb9c3 | 433 | " " . get_string('questionsnumber', 'hub', $questioncount)); |
669dee58 | 434 | $mform->setDefault('questions', $questionsnumber != -1); |
1fe56a2a | 435 | $mform->setType('questions', PARAM_INT); |
07ab0c80 | 436 | |
437 | $mform->addElement('checkbox', 'resources', '', | |
2c9bb9c3 | 438 | " " . get_string('resourcesnumber', 'hub', $resourcecount)); |
669dee58 | 439 | $mform->setDefault('resources', $resourcesnumber != -1); |
1fe56a2a | 440 | $mform->setType('resources', PARAM_INT); |
07ab0c80 | 441 | |
27806552 YB |
442 | $mform->addElement('checkbox', 'badges', '', |
443 | " " . get_string('badgesnumber', 'hub', $badges)); | |
669dee58 | 444 | $mform->setDefault('badges', $badgesnumber != -1); |
b44e4748 | 445 | $mform->setType('badges', PARAM_INT); |
27806552 YB |
446 | |
447 | $mform->addElement('checkbox', 'issuedbadges', '', | |
448 | " " . get_string('issuedbadgesnumber', 'hub', $issuedbadges)); | |
669dee58 | 449 | $mform->setDefault('issuedbadges', $issuedbadgesnumber != -1); |
b44e4748 | 450 | $mform->setType('issuedbadges', PARAM_INT); |
27806552 | 451 | |
07ab0c80 | 452 | $mform->addElement('checkbox', 'participantnumberaverage', '', |
ceac2af3 | 453 | " " . get_string('participantnumberaverage', 'hub', $participantnumberaverage)); |
669dee58 | 454 | $mform->setDefault('participantnumberaverage', $participantnumberaveragecfg != -1); |
1fe56a2a | 455 | $mform->setType('participantnumberaverage', PARAM_FLOAT); |
07ab0c80 | 456 | |
457 | $mform->addElement('checkbox', 'modulenumberaverage', '', | |
ceac2af3 | 458 | " " . get_string('modulenumberaverage', 'hub', $modulenumberaverage)); |
669dee58 | 459 | $mform->setDefault('modulenumberaverage', $modulenumberaveragecfg != -1); |
1fe56a2a | 460 | $mform->setType('modulenumberaverage', PARAM_FLOAT); |
bf1babe5 JL |
461 | |
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); | |
467 | ||
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); | |
473 | ||
474 | $mform->addElement('checkbox', 'registereduserdevices', '', | |
475 | " " . get_string('registereduserdevices', 'hub', $registereduserdevicescount)); | |
476 | $mform->setDefault('registereduserdevices', $registereduserdevices != -1); | |
477 | $mform->setType('registereduserdevices', PARAM_INT); | |
478 | ||
479 | $mform->addElement('checkbox', 'registeredactiveuserdevices', '', | |
480 | " " . get_string('registeredactiveuserdevices', 'hub', $registeredactiveuserdevicescount)); | |
481 | $mform->setDefault('registeredactiveuserdevices', $registeredactiveuserdevices != -1); | |
482 | $mform->setType('registeredactiveuserdevices', PARAM_INT); | |
07ab0c80 | 483 | } else { |
2c9bb9c3 | 484 | $mform->addElement('static', 'courseslabel', get_string('sendfollowinginfo', 'hub'), |
485 | " " . get_string('coursesnumber', 'hub', $coursecount)); | |
1fe56a2a RT |
486 | $mform->addElement('hidden', 'courses', 1); |
487 | $mform->setType('courses', PARAM_INT); | |
2c9bb9c3 | 488 | $mform->addHelpButton('courseslabel', 'sendfollowinginfo', 'hub'); |
07ab0c80 | 489 | |
490 | $mform->addElement('static', 'userslabel', '', | |
2c9bb9c3 | 491 | " " . get_string('usersnumber', 'hub', $usercount)); |
1fe56a2a RT |
492 | $mform->addElement('hidden', 'users', 1); |
493 | $mform->setType('users', PARAM_INT); | |
07ab0c80 | 494 | |
495 | $mform->addElement('static', 'roleassignmentslabel', '', | |
2c9bb9c3 | 496 | " " . get_string('roleassignmentsnumber', 'hub', $roleassigncount)); |
1fe56a2a RT |
497 | $mform->addElement('hidden', 'roleassignments', 1); |
498 | $mform->setType('roleassignments', PARAM_INT); | |
07ab0c80 | 499 | |
500 | $mform->addElement('static', 'postslabel', '', | |
2c9bb9c3 | 501 | " " . get_string('postsnumber', 'hub', $postcount)); |
1fe56a2a RT |
502 | $mform->addElement('hidden', 'posts', 1); |
503 | $mform->setType('posts', PARAM_INT); | |
07ab0c80 | 504 | |
505 | $mform->addElement('static', 'questionslabel', '', | |
2c9bb9c3 | 506 | " " . get_string('questionsnumber', 'hub', $questioncount)); |
1fe56a2a RT |
507 | $mform->addElement('hidden', 'questions', 1); |
508 | $mform->setType('questions', PARAM_INT); | |
07ab0c80 | 509 | |
510 | $mform->addElement('static', 'resourceslabel', '', | |
2c9bb9c3 | 511 | " " . get_string('resourcesnumber', 'hub', $resourcecount)); |
1fe56a2a RT |
512 | $mform->addElement('hidden', 'resources', 1); |
513 | $mform->setType('resources', PARAM_INT); | |
07ab0c80 | 514 | |
27806552 YB |
515 | $mform->addElement('static', 'badgeslabel', '', |
516 | " " . get_string('badgesnumber', 'hub', $badges)); | |
1fe56a2a | 517 | $mform->addElement('hidden', 'badges', 1); |
27806552 YB |
518 | $mform->setType('badges', PARAM_INT); |
519 | ||
520 | $mform->addElement('static', 'issuedbadgeslabel', '', | |
521 | " " . get_string('issuedbadgesnumber', 'hub', $issuedbadges)); | |
522 | $mform->addElement('hidden', 'issuedbadges', true); | |
523 | $mform->setType('issuedbadges', PARAM_INT); | |
524 | ||
07ab0c80 | 525 | $mform->addElement('static', 'participantnumberaveragelabel', '', |
2c9bb9c3 | 526 | " " . get_string('participantnumberaverage', 'hub', $participantnumberaverage)); |
1fe56a2a | 527 | $mform->addElement('hidden', 'participantnumberaverage', 1); |
f8758d68 | 528 | $mform->setType('participantnumberaverage', PARAM_FLOAT); |
07ab0c80 | 529 | |
530 | $mform->addElement('static', 'modulenumberaveragelabel', '', | |
2c9bb9c3 | 531 | " " . get_string('modulenumberaverage', 'hub', $modulenumberaverage)); |
1fe56a2a | 532 | $mform->addElement('hidden', 'modulenumberaverage', 1); |
f8758d68 | 533 | $mform->setType('modulenumberaverage', PARAM_FLOAT); |
bf1babe5 JL |
534 | |
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); | |
540 | ||
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); | |
546 | ||
547 | $mform->addElement('static', 'registereduserdeviceslabel', '', | |
548 | " " . get_string('registereduserdevices', 'hub', $registereduserdevicescount)); | |
549 | $mform->addElement('hidden', 'registereduserdevices', 1); | |
550 | $mform->setType('registereduserdevices', PARAM_INT); | |
551 | ||
552 | $mform->addElement('static', 'registeredactiveuserdeviceslabel', '', | |
553 | " " . get_string('registeredactiveuserdevices', 'hub', $registeredactiveuserdevicescount)); | |
554 | $mform->addElement('hidden', 'registeredactiveuserdevices', 1); | |
555 | $mform->setType('registeredactiveuserdevices', PARAM_INT); | |
07ab0c80 | 556 | } |
557 | ||
558 | //check if it's a first registration or update | |
94788de2 | 559 | $hubregistered = $registrationmanager->get_registeredhub($huburl); |
07ab0c80 | 560 | |
561 | if (!empty($hubregistered)) { | |
562 | $buttonlabel = get_string('updatesite', 'hub', | |
2c9bb9c3 | 563 | !empty($hubname) ? $hubname : $huburl); |
07ab0c80 | 564 | $mform->addElement('hidden', 'update', true); |
f8758d68 | 565 | $mform->setType('update', PARAM_BOOL); |
07ab0c80 | 566 | } else { |
567 | $buttonlabel = get_string('registersite', 'hub', | |
2c9bb9c3 | 568 | !empty($hubname) ? $hubname : $huburl); |
07ab0c80 | 569 | } |
570 | ||
571 | $this->add_action_buttons(false, $buttonlabel); | |
572 | } | |
573 | ||
07ab0c80 | 574 | } |
575 |