Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/registration/forms.php
Go to the documentation of this file.
00001 <?php
00002 
00004 //                                                                       //
00005 // This file is part of Moodle - http://moodle.org/                      //
00006 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
00007 //                                                                       //
00008 // Moodle is free software: you can redistribute it and/or modify        //
00009 // it under the terms of the GNU General Public License as published by  //
00010 // the Free Software Foundation, either version 3 of the License, or     //
00011 // (at your option) any later version.                                   //
00012 //                                                                       //
00013 // Moodle is distributed in the hope that it will be useful,             //
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
00016 // GNU General Public License for more details.                          //
00017 //                                                                       //
00018 // You should have received a copy of the GNU General Public License     //
00019 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.       //
00020 //                                                                       //
00022 
00023 /*
00024  * @package    moodle
00025  * @subpackage registration
00026  * @author     Jerome Mouneyrac <jerome@mouneyrac.com>
00027  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
00028  * @copyright  (C) 1999 onwards Martin Dougiamas  http://dougiamas.com
00029  *
00030  * The forms needed by registration pages.
00031  */
00032 
00033 
00034 require_once($CFG->libdir . '/formslib.php');
00035 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
00036 
00040 class site_unregistration_form extends moodleform {
00041 
00042     public function definition() {
00043         $mform = & $this->_form;
00044         $mform->addElement('header', 'site', get_string('unregister', 'hub'));
00045 
00046         $huburl = $this->_customdata['huburl'];
00047         $hubname = $this->_customdata['hubname'];
00048 
00049         $unregisterlabel = get_string('unregister', 'hub');
00050         $mform->addElement('checkbox', 'unpublishalladvertisedcourses', '',
00051                 ' ' . get_string('unpublishalladvertisedcourses', 'hub'));
00052         $mform->addElement('checkbox', 'unpublishalluploadedcourses', '',
00053                 ' ' . get_string('unpublishalluploadedcourses', 'hub'));
00054 
00055         $mform->addElement('hidden', 'confirm', 1);
00056         $mform->setType('confirm', PARAM_INT);
00057         $mform->addElement('hidden', 'unregistration', 1);
00058         $mform->setType('unregistration', PARAM_INT);
00059         $mform->addElement('hidden', 'huburl', $huburl);
00060         $mform->setType('huburl', PARAM_URL);
00061         $mform->addElement('hidden', 'hubname', $hubname);
00062         $mform->setType('hubname', PARAM_TEXT);
00063 
00064         $this->add_action_buttons(true, $unregisterlabel);
00065     }
00066 
00067 }
00068 
00072 class site_clean_registration_data_form extends moodleform {
00073 
00074     public function definition() {
00075         $mform = & $this->_form;
00076         $mform->addElement('header', 'site', get_string('unregister', 'hub'));
00077 
00078         $huburl = $this->_customdata['huburl'];
00079         $hubname = $this->_customdata['hubname'];
00080 
00081 
00082         $unregisterlabel = get_string('forceunregister', 'hub');
00083         $mform->addElement('static', '', get_string('warning', 'hub'), get_string('forceunregisterconfirmation', 'hub', $hubname));
00084 
00085 
00086         $mform->addElement('hidden', 'confirm', 1);
00087         $mform->setType('confirm', PARAM_INT);
00088         $mform->addElement('hidden', 'unregistration', 1);
00089         $mform->setType('unregistration', PARAM_INT);
00090         $mform->addElement('hidden', 'cleanregdata', 1);
00091         $mform->setType('cleanregdata', PARAM_INT);
00092         $mform->addElement('hidden', 'huburl', $huburl);
00093         $mform->setType('huburl', PARAM_URL);
00094         $mform->addElement('hidden', 'hubname', $hubname);
00095         $mform->setType('hubname', PARAM_TEXT);
00096 
00097         $this->add_action_buttons(true, $unregisterlabel);
00098     }
00099 
00100 }
00101 
00107 class hub_selector_form extends moodleform {
00108 
00109     public function definition() {
00110         global $CFG, $OUTPUT;
00111         $mform = & $this->_form;
00112         $mform->addElement('header', 'site', get_string('selecthub', 'hub'));
00113 
00114         //retrieve the hub list on the hub directory by web service
00115         $function = 'hubdirectory_get_hubs';
00116         $params = array();
00117         $serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php";
00118         require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
00119         $xmlrpcclient = new webservice_xmlrpc_client($serverurl, 'publichubdirectory');
00120         try {
00121             $hubs = $xmlrpcclient->call($function, $params);
00122         } catch (Exception $e) {
00123             $error = $OUTPUT->notification(get_string('errorhublisting', 'hub', $e->getMessage()));
00124             $mform->addElement('static', 'errorhub', '', $error);
00125             $hubs = array();
00126         }
00127 
00128         //remove moodle.org from the hub list
00129         foreach ($hubs as $key => $hub) {
00130             if ($hub['url'] == HUB_MOODLEORGHUBURL) {
00131                 unset($hubs[$key]);
00132             }
00133         }
00134 
00135         //Public hub list
00136         $options = array();
00137         foreach ($hubs as $hub) {
00138             //to not display a name longer than 100 character (too big)
00139             if (textlib::strlen($hub['name']) > 100) {
00140                 $hubname = textlib::substr($hub['name'], 0, 100);
00141                 $hubname = $hubname . "...";
00142             } else {
00143                 $hubname = $hub['name'];
00144             }
00145             $options[$hub['url']] = $hubname;
00146             $mform->addElement('hidden', clean_param($hub['url'], PARAM_ALPHANUMEXT), $hubname);
00147             $mform->setType(clean_param($hub['url'], PARAM_ALPHANUMEXT), PARAM_ALPHANUMEXT);
00148         }
00149         if (!empty($hubs)) {
00150             $mform->addElement('select', 'publichub', get_string('publichub', 'hub'),
00151                     $options, array("size" => 15));
00152         }
00153 
00154         $mform->addElement('static', 'or', '', get_string('orenterprivatehub', 'hub'));
00155 
00156         //Private hub
00157         $mform->addElement('text', 'unlistedurl', get_string('privatehuburl', 'hub'),
00158                 array('class' => 'registration_textfield'));
00159         $mform->addElement('text', 'password', get_string('password'),
00160                 array('class' => 'registration_textfield'));
00161 
00162         $this->add_action_buttons(false, get_string('selecthub', 'hub'));
00163     }
00164 
00168     function validation($data, $files) {
00169         global $CFG;
00170         $errors = parent::validation($data, $files);
00171 
00172         $unlistedurl = $this->_form->_submitValues['unlistedurl'];
00173 
00174         if (!empty($unlistedurl)) {
00175             $unlistedurltotest = clean_param($unlistedurl, PARAM_URL);
00176             if (empty($unlistedurltotest)) {
00177                 $errors['unlistedurl'] = get_string('badurlformat', 'hub');
00178             }
00179         }
00180 
00181         return $errors;
00182     }
00183 
00184 }
00185 
00189 class site_registration_form extends moodleform {
00190 
00191     public function definition() {
00192         global $CFG, $DB;
00193 
00194         $strrequired = get_string('required');
00195         $mform = & $this->_form;
00196         $huburl = $this->_customdata['huburl'];
00197         $hubname = $this->_customdata['hubname'];
00198         $password = $this->_customdata['password'];
00199         $admin = get_admin();
00200         $site = get_site();
00201 
00202         //retrieve config for this hub and set default if they don't exist
00203         $cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
00204         $sitename = get_config('hub', 'site_name_' . $cleanhuburl);
00205         if ($sitename === false) {
00206             $sitename = format_string($site->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
00207         }
00208         $sitedescription = get_config('hub', 'site_description_' . $cleanhuburl);
00209         if ($sitedescription === false) {
00210             $sitedescription = $site->summary;
00211         }
00212         $contactname = get_config('hub', 'site_contactname_' . $cleanhuburl);
00213         if ($contactname === false) {
00214             $contactname = fullname($admin, true);
00215         }
00216         $contactemail = get_config('hub', 'site_contactemail_' . $cleanhuburl);
00217         if ($contactemail === false) {
00218             $contactemail = $admin->email;
00219         }
00220         $contactphone = get_config('hub', 'site_contactphone_' . $cleanhuburl);
00221         if ($contactphone === false) {
00222             $contactphone = $admin->phone1;
00223         }
00224         $imageurl = get_config('hub', 'site_imageurl_' . $cleanhuburl);
00225         $privacy = get_config('hub', 'site_privacy_' . $cleanhuburl);
00226         $address = get_config('hub', 'site_address_' . $cleanhuburl);
00227         $region = get_config('hub', 'site_region_' . $cleanhuburl);
00228         $country = get_config('hub', 'site_country_' . $cleanhuburl);
00229         if ($country === false) {
00230             $country = $admin->country;
00231         }
00232         $language = get_config('hub', 'site_language_' . $cleanhuburl);
00233         if ($language === false) {
00234             $language = current_language();
00235         }
00236         $geolocation = get_config('hub', 'site_geolocation_' . $cleanhuburl);
00237         $contactable = get_config('hub', 'site_contactable_' . $cleanhuburl);
00238         $emailalert = get_config('hub', 'site_emailalert_' . $cleanhuburl);
00239         $coursesnumber = get_config('hub', 'site_coursesnumber_' . $cleanhuburl);
00240         $usersnumber = get_config('hub', 'site_usersnumber_' . $cleanhuburl);
00241         $roleassignmentsnumber = get_config('hub', 'site_roleassignmentsnumber_' . $cleanhuburl);
00242         $postsnumber = get_config('hub', 'site_postsnumber_' . $cleanhuburl);
00243         $questionsnumber = get_config('hub', 'site_questionsnumber_' . $cleanhuburl);
00244         $resourcesnumber = get_config('hub', 'site_resourcesnumber_' . $cleanhuburl);
00245         $mediancoursesize = get_config('hub', 'site_mediancoursesize_' . $cleanhuburl);
00246 
00247         //hidden parameters
00248         $mform->addElement('hidden', 'huburl', $huburl);
00249         $mform->setType('huburl', PARAM_URL);
00250         $mform->addElement('hidden', 'hubname', $hubname);
00251         $mform->setType('hubname', PARAM_TEXT);
00252         $mform->addElement('hidden', 'password', $password);
00253         $mform->setType('password', PARAM_RAW);
00254 
00255         //the input parameters
00256         $mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub'));
00257 
00258         $mform->addElement('text', 'name', get_string('sitename', 'hub'),
00259                 array('class' => 'registration_textfield'));
00260         $mform->addRule('name', $strrequired, 'required', null, 'client');
00261         $mform->setType('name', PARAM_TEXT);
00262         $mform->setDefault('name', $sitename);
00263         $mform->addHelpButton('name', 'sitename', 'hub');
00264 
00265         $options = array();
00266         $registrationmanager = new registration_manager();
00267         $options[HUB_SITENOTPUBLISHED] = $registrationmanager->get_site_privacy_string(HUB_SITENOTPUBLISHED);
00268         $options[HUB_SITENAMEPUBLISHED] = $registrationmanager->get_site_privacy_string(HUB_SITENAMEPUBLISHED);
00269         $options[HUB_SITELINKPUBLISHED] = $registrationmanager->get_site_privacy_string(HUB_SITELINKPUBLISHED);
00270         $mform->addElement('select', 'privacy', get_string('siteprivacy', 'hub'), $options);
00271         $mform->setDefault('privacy', $privacy);
00272         $mform->addHelpButton('privacy', 'privacy', 'hub');
00273         unset($options);
00274 
00275         $mform->addElement('textarea', 'description', get_string('sitedesc', 'hub'),
00276                 array('rows' => 8, 'cols' => 41));
00277         $mform->addRule('description', $strrequired, 'required', null, 'client');
00278         $mform->setDefault('description', $sitedescription);
00279         $mform->setType('description', PARAM_TEXT);
00280         $mform->addHelpButton('description', 'sitedesc', 'hub');
00281 
00282         $mform->addElement('static', 'urlstring', get_string('siteurl', 'hub'), $CFG->wwwroot);
00283         $mform->addHelpButton('urlstring', 'siteurl', 'hub');
00284 
00285         $languages = get_string_manager()->get_list_of_languages();
00286         collatorlib::asort($languages);
00287         $mform->addElement('select', 'language', get_string('sitelang', 'hub'),
00288                 $languages);
00289         $mform->setType('language', PARAM_ALPHANUMEXT);
00290         $mform->addHelpButton('language', 'sitelang', 'hub');
00291         $mform->setDefault('language', $language);
00292 
00293         $mform->addElement('static', 'versionstring', get_string('siteversion', 'hub'), $CFG->version);
00294         $mform->addElement('hidden', 'moodleversion', $CFG->version);
00295         $mform->setType('moodleversion', PARAM_INT);
00296         $mform->addHelpButton('versionstring', 'siteversion', 'hub');
00297 
00298         $mform->addElement('static', 'releasestring', get_string('siterelease', 'hub'), $CFG->release);
00299         $mform->addElement('hidden', 'moodlerelease', $CFG->release);
00300         $mform->setType('moodlerelease', PARAM_TEXT);
00301         $mform->addHelpButton('releasestring', 'siterelease', 'hub');
00302 
00303         $mform->addElement('textarea', 'address', get_string('postaladdress', 'hub'),
00304                 array('rows' => 4, 'cols' => 41));
00305         $mform->setType('address', PARAM_TEXT);
00306         $mform->setDefault('address', $address);
00307         $mform->addHelpButton('address', 'postaladdress', 'hub');
00308 
00309         //TODO: use the region array I generated
00310 //        $mform->addElement('select', 'region', get_string('selectaregion'), array('-' => '-'));
00311 //        $mform->setDefault('region', $region);
00312         $mform->addElement('hidden', 'regioncode', '-');
00313         $mform->setType('regioncode', PARAM_ALPHANUMEXT);
00314 
00315         $countries = get_string_manager()->get_list_of_countries();
00316         $mform->addElement('select', 'countrycode', get_string('sitecountry', 'hub'), $countries);
00317         $mform->setDefault('countrycode', $country);
00318         $mform->addHelpButton('countrycode', 'sitecountry', 'hub');
00319 
00320         $mform->addElement('text', 'geolocation', get_string('sitegeolocation', 'hub'),
00321                 array('class' => 'registration_textfield'));
00322         $mform->setDefault('geolocation', $geolocation);
00323         $mform->addHelpButton('geolocation', 'sitegeolocation', 'hub');
00324 
00325         $mform->addElement('text', 'contactname', get_string('siteadmin', 'hub'),
00326                 array('class' => 'registration_textfield'));
00327         $mform->addRule('contactname', $strrequired, 'required', null, 'client');
00328         $mform->setType('contactname', PARAM_TEXT);
00329         $mform->setDefault('contactname', $contactname);
00330         $mform->addHelpButton('contactname', 'siteadmin', 'hub');
00331 
00332         $mform->addElement('text', 'contactphone', get_string('sitephone', 'hub'),
00333                 array('class' => 'registration_textfield'));
00334         $mform->setType('contactphone', PARAM_TEXT);
00335         $mform->addHelpButton('contactphone', 'sitephone', 'hub');
00336 
00337         $mform->addElement('text', 'contactemail', get_string('siteemail', 'hub'),
00338                 array('class' => 'registration_textfield'));
00339         $mform->addRule('contactemail', $strrequired, 'required', null, 'client');
00340         $mform->setType('contactemail', PARAM_TEXT);
00341         $mform->setDefault('contactemail', $contactemail);
00342         $mform->addHelpButton('contactemail', 'siteemail', 'hub');
00343 
00344         $options = array();
00345         $options[0] = get_string("registrationcontactno");
00346         $options[1] = get_string("registrationcontactyes");
00347         $mform->addElement('select', 'contactable', get_string('siteregistrationcontact', 'hub'), $options);
00348         $mform->setDefault('contactable', $contactable);
00349         $mform->addHelpButton('contactable', 'siteregistrationcontact', 'hub');
00350         unset($options);
00351 
00352         $options = array();
00353         $options[0] = get_string("registrationno");
00354         $options[1] = get_string("registrationyes");
00355         $mform->addElement('select', 'emailalert', get_string('siteregistrationemail', 'hub'), $options);
00356         $mform->setDefault('emailalert', $emailalert);
00357         $mform->addHelpButton('emailalert', 'siteregistrationemail', 'hub');
00358         unset($options);
00359 
00360         //TODO site logo
00361         $mform->addElement('hidden', 'imageurl', ''); //TODO: temporary
00362         $mform->setType('imageurl', PARAM_URL);
00364         $coursecount = $DB->count_records('course') - 1;
00365         $usercount = $DB->count_records('user', array('deleted' => 0));
00366         $roleassigncount = $DB->count_records('role_assignments');
00367         $postcount = $DB->count_records('forum_posts');
00368         $questioncount = $DB->count_records('question');
00369         $resourcecount = $DB->count_records('resource');
00370         require_once($CFG->dirroot . "/course/lib.php");
00371         $participantnumberaverage = number_format(average_number_of_participants(), 2);
00372         $modulenumberaverage = number_format(average_number_of_courses_modules(), 2);
00373 
00374         if (HUB_MOODLEORGHUBURL != $huburl) {
00375             $mform->addElement('checkbox', 'courses', get_string('sendfollowinginfo', 'hub'),
00376                     " " . get_string('coursesnumber', 'hub', $coursecount));
00377             $mform->setDefault('courses', true);
00378             $mform->addHelpButton('courses', 'sendfollowinginfo', 'hub');
00379 
00380             $mform->addElement('checkbox', 'users', '',
00381                     " " . get_string('usersnumber', 'hub', $usercount));
00382             $mform->setDefault('users', true);
00383 
00384             $mform->addElement('checkbox', 'roleassignments', '',
00385                     " " . get_string('roleassignmentsnumber', 'hub', $roleassigncount));
00386             $mform->setDefault('roleassignments', true);
00387 
00388             $mform->addElement('checkbox', 'posts', '',
00389                     " " . get_string('postsnumber', 'hub', $postcount));
00390             $mform->setDefault('posts', true);
00391 
00392             $mform->addElement('checkbox', 'questions', '',
00393                     " " . get_string('questionsnumber', 'hub', $questioncount));
00394             $mform->setDefault('questions', true);
00395 
00396             $mform->addElement('checkbox', 'resources', '',
00397                     " " . get_string('resourcesnumber', 'hub', $resourcecount));
00398             $mform->setDefault('resources', true);
00399 
00400             $mform->addElement('checkbox', 'participantnumberaverage', '',
00401                     " " . get_string('participantnumberaverage', 'hub', $participantnumberaverage));
00402             $mform->setDefault('participantnumberaverage', true);
00403 
00404             $mform->addElement('checkbox', 'modulenumberaverage', '',
00405                     " " . get_string('modulenumberaverage', 'hub', $modulenumberaverage));
00406             $mform->setDefault('modulenumberaverage', true);
00407         } else {
00408             $mform->addElement('static', 'courseslabel', get_string('sendfollowinginfo', 'hub'),
00409                     " " . get_string('coursesnumber', 'hub', $coursecount));
00410             $mform->addElement('hidden', 'courses', true);
00411             $mform->setType('courses', PARAM_FLOAT);
00412             $mform->addHelpButton('courseslabel', 'sendfollowinginfo', 'hub');
00413 
00414             $mform->addElement('static', 'userslabel', '',
00415                     " " . get_string('usersnumber', 'hub', $usercount));
00416             $mform->addElement('hidden', 'users', true);
00417             $mform->setType('users', PARAM_FLOAT);
00418 
00419             $mform->addElement('static', 'roleassignmentslabel', '',
00420                     " " . get_string('roleassignmentsnumber', 'hub', $roleassigncount));
00421             $mform->addElement('hidden', 'roleassignments', true);
00422             $mform->setType('roleassignments', PARAM_FLOAT);
00423 
00424             $mform->addElement('static', 'postslabel', '',
00425                     " " . get_string('postsnumber', 'hub', $postcount));
00426             $mform->addElement('hidden', 'posts', true);
00427             $mform->setType('posts', PARAM_FLOAT);
00428 
00429             $mform->addElement('static', 'questionslabel', '',
00430                     " " . get_string('questionsnumber', 'hub', $questioncount));
00431             $mform->addElement('hidden', 'questions', true);
00432             $mform->setType('questions', PARAM_FLOAT);
00433 
00434             $mform->addElement('static', 'resourceslabel', '',
00435                     " " . get_string('resourcesnumber', 'hub', $resourcecount));
00436             $mform->addElement('hidden', 'resources', true);
00437             $mform->setType('resources', PARAM_FLOAT);
00438 
00439             $mform->addElement('static', 'participantnumberaveragelabel', '',
00440                     " " . get_string('participantnumberaverage', 'hub', $participantnumberaverage));
00441             $mform->addElement('hidden', 'participantnumberaverage', true);
00442             $mform->setType('participantnumberaverage', PARAM_FLOAT);
00443 
00444             $mform->addElement('static', 'modulenumberaveragelabel', '',
00445                     " " . get_string('modulenumberaverage', 'hub', $modulenumberaverage));
00446             $mform->addElement('hidden', 'modulenumberaverage', true);
00447             $mform->setType('modulenumberaverage', PARAM_FLOAT);
00448         }
00449 
00450         //check if it's a first registration or update
00451         $hubregistered = $registrationmanager->get_registeredhub($huburl);
00452 
00453         if (!empty($hubregistered)) {
00454             $buttonlabel = get_string('updatesite', 'hub',
00455                             !empty($hubname) ? $hubname : $huburl);
00456             $mform->addElement('hidden', 'update', true);
00457             $mform->setType('update', PARAM_BOOL);
00458         } else {
00459             $buttonlabel = get_string('registersite', 'hub',
00460                             !empty($hubname) ? $hubname : $huburl);
00461         }
00462 
00463         $this->add_action_buttons(false, $buttonlabel);
00464     }
00465 
00466 }
00467 
 All Data Structures Namespaces Files Functions Variables Enumerations