Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/registration/register.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  * This page displays the site registration form.
00031  * It handles redirection to the hub to continue the registration workflow process.
00032  * It also handles update operation by web service.
00033  */
00034 
00035 
00036 require_once('../../config.php');
00037 require_once($CFG->libdir . '/adminlib.php');
00038 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/forms.php');
00039 require_once($CFG->dirroot . '/webservice/lib.php');
00040 require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
00041 
00042 admin_externalpage_setup('registrationindex');
00043 
00044 $huburl = required_param('huburl', PARAM_URL);
00045 $huburl = rtrim($huburl, "/");
00046 $password = optional_param('password', '', PARAM_TEXT);
00047 $hubname = optional_param('hubname', '', PARAM_TEXT);
00048 if (!confirm_sesskey()) {
00049     throw new moodle_exception('missingparameter');
00050 }
00051 
00052 $registrationmanager = new registration_manager();
00053 
00054 $registeredhub = $registrationmanager->get_registeredhub($huburl);
00055 
00056 $siteregistrationform = new site_registration_form('',
00057                 array('alreadyregistered' => !empty($registeredhub->token),
00058                     'huburl' => $huburl, 'hubname' => $hubname,
00059                     'password' => $password));
00060 $fromform = $siteregistrationform->get_data();
00061 
00062 if (!empty($fromform) and confirm_sesskey()) {
00063     //save the settings
00064     $cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
00065     set_config('site_name_' . $cleanhuburl, $fromform->name, 'hub');
00066     set_config('site_description_' . $cleanhuburl, $fromform->description, 'hub');
00067     set_config('site_contactname_' . $cleanhuburl, $fromform->contactname, 'hub');
00068     set_config('site_contactemail_' . $cleanhuburl, $fromform->contactemail, 'hub');
00069     set_config('site_contactphone_' . $cleanhuburl, $fromform->contactphone, 'hub');
00070     set_config('site_imageurl_' . $cleanhuburl, $fromform->imageurl, 'hub');
00071     set_config('site_privacy_' . $cleanhuburl, $fromform->privacy, 'hub');
00072     set_config('site_address_' . $cleanhuburl, $fromform->address, 'hub');
00073     set_config('site_region_' . $cleanhuburl, $fromform->regioncode, 'hub');
00074     set_config('site_country_' . $cleanhuburl, $fromform->countrycode, 'hub');
00075     set_config('site_language_' . $cleanhuburl, $fromform->language, 'hub');
00076     set_config('site_geolocation_' . $cleanhuburl, $fromform->geolocation, 'hub');
00077     set_config('site_contactable_' . $cleanhuburl, $fromform->contactable, 'hub');
00078     set_config('site_emailalert_' . $cleanhuburl, $fromform->emailalert, 'hub');
00079     set_config('site_coursesnumber_' . $cleanhuburl, $fromform->courses, 'hub');
00080     set_config('site_usersnumber_' . $cleanhuburl, $fromform->users, 'hub');
00081     set_config('site_roleassignmentsnumber_' . $cleanhuburl, $fromform->roleassignments, 'hub');
00082     set_config('site_postsnumber_' . $cleanhuburl, $fromform->posts, 'hub');
00083     set_config('site_questionsnumber_' . $cleanhuburl, $fromform->questions, 'hub');
00084     set_config('site_resourcesnumber_' . $cleanhuburl, $fromform->resources, 'hub');
00085     set_config('site_modulenumberaverage_' . $cleanhuburl, $fromform->modulenumberaverage, 'hub');
00086     set_config('site_participantnumberaverage_' . $cleanhuburl, $fromform->participantnumberaverage, 'hub');
00087 }
00088 
00090 
00091 // update the hub registration
00092 $update = optional_param('update', 0, PARAM_INT);
00093 if ($update and confirm_sesskey()) {
00094 
00095     //update the registration
00096     $function = 'hub_update_site_info';
00097     $siteinfo = $registrationmanager->get_site_info($huburl);
00098     $params = array('siteinfo' => $siteinfo);
00099     $serverurl = $huburl . "/local/hub/webservice/webservices.php";
00100     require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
00101     $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token);
00102     try {
00103         $result = $xmlrpcclient->call($function, $params);
00104     } catch (Exception $e) {
00105         $error = $OUTPUT->notification(get_string('errorregistration', 'hub', $e->getMessage()));
00106     }
00107 }
00108 
00110 
00111 if (!empty($fromform) and empty($update) and confirm_sesskey()) {
00112 
00113     if (!empty($fromform) and confirm_sesskey()) { // if the register button has been clicked
00114         $params = (array) $fromform; //we are using the form input as the redirection parameters (token, url and name)
00115 
00116         $unconfirmedhub = $registrationmanager->get_unconfirmedhub($huburl);
00117         if (empty($unconfirmedhub)) {
00118             //we save the token into the communication table in order to have a reference
00119             $unconfirmedhub = new stdClass();
00120             $unconfirmedhub->token = $registrationmanager->get_site_secret_for_hub($huburl);
00121             $unconfirmedhub->secret = $unconfirmedhub->token;
00122             $unconfirmedhub->huburl = $huburl;
00123             $unconfirmedhub->hubname = $hubname;
00124             $unconfirmedhub->confirmed = 0;
00125             $unconfirmedhub->id = $registrationmanager->add_registeredhub($unconfirmedhub);
00126         }
00127 
00128         $params['token'] = $unconfirmedhub->token;
00129         $params['url'] = $CFG->wwwroot;
00130         redirect(new moodle_url($huburl . '/local/hub/siteregistration.php', $params));
00131     }
00132 }
00133 
00135 
00136 echo $OUTPUT->header();
00137 //Display update notification result
00138 if (!empty($registeredhub->confirmed)) {
00139     if (!empty($result)) {
00140         echo $OUTPUT->notification(get_string('siteregistrationupdated', 'hub'), 'notifysuccess');
00141     }
00142 }
00143 
00144 if (!empty($error)) {
00145     echo $error;
00146 }
00147 
00148 $siteregistrationform->display();
00149 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations