Source for file sl_welcome_reg.php

Documentation is available at sl_welcome_reg.php

  1. <?php
  2.     /**
  3.     * Sloodle avatar registration page.
  4.     *
  5.     * Allows users who have clicked an in-world registration booth to complete their
  6.     *  avatar registration by logging-in to their Moodle account (or creating one).
  7.     *
  8.     * @package sloodlelogin
  9.     * @copyright Copyright (c) 2007 Sloodle (various contributors)
  10.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  11.     *
  12.     * @contributor Edmund Edgar
  13.     * @contributor Peter R. Bloomfield
  14.     *
  15.     */
  16.     
  17.     // This script is expected to be visited by a user with a web browser.
  18.     // The following request parameters (GET or POST) are required for an initial page view:
  19.     //
  20.     //  sloodleuuid - the UUID of the avatar which is being registered
  21.     //  sloodlelst - the login security token generated for the registration attempt
  22.     //
  23.     // Optionally, objects which need to know when registration has been accomplished can provide the following:
  24.     //
  25.     //  sloodlechannel - UUID of an XMLRPC channel
  26.     //
  27.     // In most cases, after login, the above parameters will be sufficient.
  28.     // However, where the same avatar is already registered to another Moodle user,
  29.     //  the user will be asked for confirmation. At this point, an additional
  30.     //  parameter will be added:
  31.     //
  32.     //  sloodleconfirm - 'true' if the change/overwrite of existing details is confirmed
  33.     //
  34.     // A new optional parameter is the following:
  35.     //
  36.     //  sloodlecourseid - the integer ID of the course which the user should be enrolled in after registration
  37.     
  38.     /** Include Sloodle/Moodle configuration. */
  39.     require_once('../sl_config.php');
  40.     
  41.     // Make sure the Moodle user is logged-in
  42.     require_login();
  43.     
  44.     /** Include the Sloodle API. */
  45.     require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  46.     
  47.     print_header('Welcome to sloodle'''''''false''''false'');
  48.     print_heading('Welcome to sloodle');
  49.     
  50.     // Make sure it's not a guest who is logged in
  51.     if (isguest()) {
  52.         ?>
  53.         <div style="text-align:center;">
  54.          <h3><?php print_string('error''sloodle')?></h3>
  55.          <p><?php print_string('noguestaccess''sloodle')?></p>
  56.         </div>
  57.         <?php
  58.         print_footer();
  59.         exit();
  60.     }
  61.     
  62.     // Process the request data
  63.     $sloodle new SloodleSession();
  64.     
  65.     // Check parameters
  66.     $sloodleuuid required_param('sloodleuuid'PARAM_TEXT);
  67.     $sloodlelst required_param('sloodlelst'PARAM_TEXT);
  68.     $sloodlechannel optional_param('sloodlechannel'NULLPARAM_RAW);
  69.     $sloodlecourseid optional_param('sloodlecourseid'NULLPARAM_INT);
  70.     
  71.     // Attempt to find a pending avatar entry which matches the given details
  72.     $pa get_record('sloodle_pending_avatars''uuid'$sloodleuuid'lst'$sloodlelst);
  73.     if (!$pa{
  74.         ?>
  75.         <div style="text-align:center;">
  76.          <h3><?php print_string('error''sloodle')?></h3>
  77.          <p><?php print_string('pendingavatarnotfound''sloodle')?></p>
  78.         </div>
  79.         <?php
  80.         print_footer();
  81.         exit();
  82.     }
  83.     
  84.     // Add the new avatar
  85.     if (!$sloodle->user->add_linked_avatar($USER->id$sloodleuuid$pa->avname)) {
  86.         // Failed
  87.         ?>
  88.         <div style="text-align:center;">
  89.          <h3><?php print_string('error''sloodle')?></h3>
  90.          <p><?php print_string('failedcreatesloodleuser''sloodle')?></p>
  91.         </div>
  92.         <?php
  93.         print_footer();
  94.         exit();
  95.     }
  96.     
  97.     echo "<div style=\"text-align:center\">\n";
  98.     echo get_string('welcometosloodle','sloodle').', '.$pa->avname.'<br /><br />'.get_string('userlinksuccessful','sloodle');
  99.     echo "</div>\n";
  100.     
  101.     // If the object passed us a channel parameter, we'll use it to tell the object that the authentication is done.
  102.     // (Parameter name: sloodlechannel)
  103.     if (is_string($sloodlechannel&& !empty($sloodlechannel)) {
  104.         flush();
  105.         
  106.         // XMLRPC messages going into SL strip \n, so we use \\n instead
  107.         $sloodle->response->set_line_separator("\\n");
  108.         // Prepare a response as a string
  109.         $str '';
  110.         $sloodle->response->set_status_code(1);
  111.         $sloodle->response->set_status_descriptor('USER_AUTH');
  112.         $sloodle->response->add_data_line('User has been successfully registered.');
  113.         $sloodle->response->render_to_string($str);
  114.         
  115.         // Send the message
  116.         $xmlrpcresult sloodle_send_xmlrpc_message($channel0$str);
  117.         if (!$xmlrpcresult{
  118.             echo '<div style="text-align:center;">';
  119.             echo 'ERROR: Unable to tell the object that sent you here that you have been authenticated.';
  120.             echo '</div>';
  121.         }
  122.     }
  123.     
  124.     
  125.     // We we asked to enrol the user as well?
  126.     if ($sloodlecourseid != NULL{
  127.         echo "<br/><br/><br/>";
  128.         redirect("{$CFG->wwwroot}/course/enrol.php?id=$sloodlecourseid"get_string('nowenrol','sloodle')3);
  129.     }
  130.     
  131.     
  132.     print_footer();
  133.     exit();
  134.  
  135. ?>

Documentation generated on Mon, 16 Jun 2008 15:57:02 +0100 by phpDocumentor 1.4.0