[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/registration/ -> register.php (source)

   1  <?php
   2  
   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   * This page displays the site registration form for Moodle.org/MOOCH or for a different hub.
  31   * It handles redirection to the hub to continue the registration workflow process.
  32   * It also handles update operation by web service.
  33   */
  34  
  35  
  36  require_once('../../config.php');
  37  require_once($CFG->libdir . '/adminlib.php');
  38  require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/forms.php');
  39  require_once($CFG->dirroot . '/webservice/lib.php');
  40  require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
  41  
  42  require_sesskey();
  43  
  44  $huburl = required_param('huburl', PARAM_URL);
  45  $huburl = rtrim($huburl, "/");
  46  
  47  if ($huburl == HUB_MOODLEORGHUBURL) { // register to Moodle.org
  48      admin_externalpage_setup('registrationmoodleorg');
  49  } else { //register to a hub
  50      admin_externalpage_setup('registrationhub');
  51  }
  52  
  53  $password = optional_param('password', '', PARAM_TEXT);
  54  $hubname = optional_param('hubname', '', PARAM_TEXT);
  55  
  56  $registrationmanager = new registration_manager();
  57  
  58  $registeredhub = $registrationmanager->get_registeredhub($huburl);
  59  
  60  $siteregistrationform = new site_registration_form('',
  61                  array('alreadyregistered' => !empty($registeredhub->token),
  62                      'huburl' => $huburl, 'hubname' => $hubname,
  63                      'password' => $password));
  64  $fromform = $siteregistrationform->get_data();
  65  
  66  if (!empty($fromform) and confirm_sesskey()) {
  67  
  68      // Set to -1 all optional data marked as "don't send" by the admin.
  69      // The function get_site_info() will not calculate the optional data if config is set to -1.
  70      $inputnames = array('courses', 'users', 'roleassignments', 'posts', 'questions', 'resources',
  71          'badges', 'issuedbadges', 'modulenumberaverage', 'participantnumberaverage');
  72      foreach ($inputnames as $inputname) {
  73          if (empty($fromform->{$inputname})) {
  74              $fromform->{$inputname} = -1;
  75          }
  76      }
  77  
  78      // Save the settings.
  79      $cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
  80      set_config('site_name_' . $cleanhuburl, $fromform->name, 'hub');
  81      set_config('site_description_' . $cleanhuburl, $fromform->description, 'hub');
  82      set_config('site_contactname_' . $cleanhuburl, $fromform->contactname, 'hub');
  83      set_config('site_contactemail_' . $cleanhuburl, $fromform->contactemail, 'hub');
  84      set_config('site_contactphone_' . $cleanhuburl, $fromform->contactphone, 'hub');
  85      set_config('site_imageurl_' . $cleanhuburl, $fromform->imageurl, 'hub');
  86      set_config('site_privacy_' . $cleanhuburl, $fromform->privacy, 'hub');
  87      set_config('site_address_' . $cleanhuburl, $fromform->address, 'hub');
  88      set_config('site_region_' . $cleanhuburl, $fromform->regioncode, 'hub');
  89      set_config('site_country_' . $cleanhuburl, $fromform->countrycode, 'hub');
  90      set_config('site_language_' . $cleanhuburl, $fromform->language, 'hub');
  91      set_config('site_geolocation_' . $cleanhuburl, $fromform->geolocation, 'hub');
  92      set_config('site_contactable_' . $cleanhuburl, $fromform->contactable, 'hub');
  93      set_config('site_emailalert_' . $cleanhuburl, $fromform->emailalert, 'hub');
  94      set_config('site_coursesnumber_' . $cleanhuburl, $fromform->courses, 'hub');
  95      set_config('site_usersnumber_' . $cleanhuburl, $fromform->users, 'hub');
  96      set_config('site_roleassignmentsnumber_' . $cleanhuburl, $fromform->roleassignments, 'hub');
  97      set_config('site_postsnumber_' . $cleanhuburl, $fromform->posts, 'hub');
  98      set_config('site_questionsnumber_' . $cleanhuburl, $fromform->questions, 'hub');
  99      set_config('site_resourcesnumber_' . $cleanhuburl, $fromform->resources, 'hub');
 100      set_config('site_badges_' . $cleanhuburl, $fromform->badges, 'hub');
 101      set_config('site_issuedbadges_' . $cleanhuburl, $fromform->issuedbadges, 'hub');
 102      set_config('site_modulenumberaverage_' . $cleanhuburl, $fromform->modulenumberaverage, 'hub');
 103      set_config('site_participantnumberaverage_' . $cleanhuburl, $fromform->participantnumberaverage, 'hub');
 104  }
 105  
 106  /////// UPDATE ACTION ////////
 107  
 108  // update the hub registration
 109  $update = optional_param('update', 0, PARAM_INT);
 110  if ($update and confirm_sesskey()) {
 111  
 112      //update the registration
 113      $function = 'hub_update_site_info';
 114      $siteinfo = $registrationmanager->get_site_info($huburl);
 115      $params = array('siteinfo' => $siteinfo);
 116      $serverurl = $huburl . "/local/hub/webservice/webservices.php";
 117      require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
 118      $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token);
 119      try {
 120          $result = $xmlrpcclient->call($function, $params);
 121          $registrationmanager->update_registeredhub($registeredhub); // To update timemodified.
 122      } catch (Exception $e) {
 123          $error = $OUTPUT->notification(get_string('errorregistration', 'hub', $e->getMessage()));
 124      }
 125  }
 126  
 127  /////// FORM REGISTRATION ACTION //////
 128  
 129  if (!empty($fromform) and empty($update) and confirm_sesskey()) {
 130  
 131      if (!empty($fromform) and confirm_sesskey()) { // if the register button has been clicked
 132  
 133          // Retrieve the optional info (specially course number, user number, module number average...).
 134          $siteinfo = $registrationmanager->get_site_info($huburl);
 135          $fromform->courses = $siteinfo['courses'];
 136          $fromform->users = $siteinfo['users'];
 137          $fromform->enrolments = $siteinfo['enrolments'];
 138          $fromform->posts = $siteinfo['posts'];
 139          $fromform->questions = $siteinfo['questions'];
 140          $fromform->resources = $siteinfo['resources'];
 141          $fromform->badges = $siteinfo['badges'];
 142          $fromform->issuedbadges = $siteinfo['issuedbadges'];
 143          $fromform->modulenumberaverage = $siteinfo['modulenumberaverage'];
 144          $fromform->participantnumberaverage = $siteinfo['participantnumberaverage'];
 145          $fromform->street = $siteinfo['street'];
 146  
 147          $params = (array) $fromform; //we are using the form input as the redirection parameters (token, url and name)
 148  
 149          $unconfirmedhub = $registrationmanager->get_unconfirmedhub($huburl);
 150          if (empty($unconfirmedhub)) {
 151              //we save the token into the communication table in order to have a reference
 152              $unconfirmedhub = new stdClass();
 153              $unconfirmedhub->token = $registrationmanager->get_site_secret_for_hub($huburl);
 154              $unconfirmedhub->secret = $unconfirmedhub->token;
 155              $unconfirmedhub->huburl = $huburl;
 156              $unconfirmedhub->hubname = $hubname;
 157              $unconfirmedhub->confirmed = 0;
 158              $unconfirmedhub->id = $registrationmanager->add_registeredhub($unconfirmedhub);
 159          }
 160  
 161          $params['token'] = $unconfirmedhub->token;
 162          $params['url'] = $CFG->wwwroot;
 163          redirect(new moodle_url($huburl . '/local/hub/siteregistration.php', $params));
 164      }
 165  }
 166  
 167  /////// OUTPUT SECTION /////////////
 168  
 169  echo $OUTPUT->header();
 170  //Display update notification result
 171  if (!empty($registeredhub->confirmed)) {
 172      if (!empty($result)) {
 173          echo $OUTPUT->notification(get_string('siteregistrationupdated', 'hub'), 'notifysuccess');
 174      }
 175  }
 176  
 177  if (!empty($error)) {
 178      echo $error;
 179  }
 180  
 181  // Some Moodle.org registration explanation.
 182  if ($huburl == HUB_MOODLEORGHUBURL) {
 183      if (!empty($registeredhub->token)) {
 184          if ($registeredhub->timemodified == 0) {
 185              $registrationmessage = get_string('pleaserefreshregistrationunknown', 'admin');
 186          } else {
 187              $lastupdated = userdate($registeredhub->timemodified, get_string('strftimedate', 'langconfig'));
 188              $registrationmessage = get_string('pleaserefreshregistration', 'admin', $lastupdated);
 189          }
 190      } else {
 191          $registrationmessage = get_string('registrationwarning', 'admin');
 192      }
 193      echo $OUTPUT->notification($registrationmessage);
 194  
 195      echo $OUTPUT->heading(get_string('registerwithmoodleorg', 'admin'));
 196      $renderer = $PAGE->get_renderer('core', 'register');
 197      echo $renderer->moodleorg_registration_message();
 198  }
 199  
 200  $siteregistrationform->display();
 201  echo $OUTPUT->footer();


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1