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 sloodleregenrol
  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.     require_once(SLOODLE_LIBROOT.'/general.php');
  41.     
  42.  
  43.     // Make sure the user has permission to register their avatar
  44.     require_capability('mod/sloodle:registeravatar'get_context_instance(CONTEXT_SYSTEM));
  45.     
  46.     /** Include the Sloodle API. */
  47.     require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  48.     
  49.     // Display the page header
  50.     print_header_simple(get_string('welcometosloodle''sloodle')""get_string('welcometosloodle''sloodle')""""true);
  51.     
  52.     
  53.     // Process the request data
  54.     $sloodle new SloodleSession();
  55.     
  56.     // Check parameters
  57.     $sloodleuuid required_param('sloodleuuid'PARAM_TEXT);
  58.     $sloodlelst required_param('sloodlelst'PARAM_TEXT);
  59.     $sloodlechannel optional_param('sloodlechannel'NULLPARAM_RAW);
  60.     $sloodlecourseid optional_param('sloodlecourseid'NULLPARAM_INT);
  61.     
  62.     // Attempt to find a pending avatar entry which matches the given details
  63.     $pa get_record('sloodle_pending_avatars''uuid'$sloodleuuid'lst'$sloodlelst);
  64.     if (!$pa{
  65.         ?>
  66.         <div style="text-align:center;">
  67.          <h3><?php print_string('error''sloodle')?></h3>
  68.          <p><?php print_string('pendingavatarnotfound''sloodle')?></p>
  69.         </div>
  70.         <?php
  71.         print_footer();
  72.         exit();
  73.     }
  74.     
  75.     // Add the new avatar
  76.     if (!$sloodle->user->add_linked_avatar($USER->id$sloodleuuid$pa->avname)) {
  77.         // Failed
  78.         ?>
  79.         <div style="text-align:center;">
  80.          <h3><?php print_string('error''sloodle')?></h3>
  81.          <p><?php print_string('failedcreatesloodleuser''sloodle')?></p>
  82.         </div>
  83.         <?php
  84.         print_footer();
  85.         exit();
  86.     }
  87.  
  88. /// /// MOODLE-SPECIFIC /// ///
  89.  
  90.     // This is a slightly dirty hack, but is needed just now to prevent multiple avatar registrations.
  91.     // Delete any avatar belonging to this user, which doesn't match the one just registered.
  92.     delete_records_select('sloodle_users'"userid = {$USER->id} AND uuid <> '{$sloodleuuid}'");
  93.  
  94. /// /// END MOODLE-SPECIFIC /// ///
  95.     
  96.     echo "<div style=\"text-align:center; font-size:140%;\">\n";
  97.     echo get_string('welcometosloodle','sloodle').', '.$pa->avname.'<br /><br />'.get_string('userlinksuccessful','sloodle');
  98.     echo "</div>\n";
  99.     
  100.     // If the object passed us a channel parameter, we'll use it to tell the object that the authentication is done.
  101.     // (Parameter name: sloodlechannel)
  102.     if (is_string($sloodlechannel&& !empty($sloodlechannel)) {
  103.         flush();
  104.         
  105.         // XMLRPC messages going into SL strip \n, so we use \\n instead
  106.         $sloodle->response->set_line_separator("\\n");
  107.         // Prepare a response as a string
  108.         $str '';
  109.         $sloodle->response->set_status_code(1);
  110.         $sloodle->response->set_status_descriptor('USER_AUTH');
  111.         $sloodle->response->add_data_line('User has been successfully registered.');
  112.         $sloodle->response->render_to_string($str);
  113.         
  114.         // Send the message
  115.         $xmlrpcresult sloodle_send_xmlrpc_message($channel0$str);
  116.         if (!$xmlrpcresult{
  117.             echo '<div style="text-align:center;">';
  118.             echo 'ERROR: Unable to tell the object that sent you here that you have been authenticated.';
  119.             echo '</div>';
  120.         }
  121.     }
  122.     
  123.     
  124.     // We we asked to enrol the user as well?
  125.     if ($sloodlecourseid != NULL{
  126.         echo "<br/><br/><br/>";
  127.         redirect("{$CFG->wwwroot}/course/enrol.php?id=$sloodlecourseid"get_string('nowenrol','sloodle')3);
  128.     }
  129.     
  130.     
  131.     print_footer();
  132.     exit();
  133.  
  134. ?>

Documentation generated on Fri, 17 Jul 2009 11:02:32 +0100 by phpDocumentor 1.4.0