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.     
  41.     // Make sure the Moodle user is logged-in
  42.     require_login();
  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.     // Make sure it's not a guest who is logged in
  53.     if (isguest()) {
  54.         ?>
  55.         <div style="text-align:center;">
  56.          <h3><?php print_string('error''sloodle')?></h3>
  57.          <p><?php print_string('noguestaccess''sloodle')?></p>
  58.         </div>
  59.         <?php
  60.         print_footer();
  61.         exit();
  62.     }
  63.     
  64.     // Process the request data
  65.     $sloodle new SloodleSession();
  66.     
  67.     // Check parameters
  68.     $sloodleuuid required_param('sloodleuuid'PARAM_TEXT);
  69.     $sloodlelst required_param('sloodlelst'PARAM_TEXT);
  70.     $sloodlechannel optional_param('sloodlechannel'NULLPARAM_RAW);
  71.     $sloodlecourseid optional_param('sloodlecourseid'NULLPARAM_INT);
  72.     
  73.     // Attempt to find a pending avatar entry which matches the given details
  74.     $pa get_record('sloodle_pending_avatars''uuid'$sloodleuuid'lst'$sloodlelst);
  75.     if (!$pa{
  76.         ?>
  77.         <div style="text-align:center;">
  78.          <h3><?php print_string('error''sloodle')?></h3>
  79.          <p><?php print_string('pendingavatarnotfound''sloodle')?></p>
  80.         </div>
  81.         <?php
  82.         print_footer();
  83.         exit();
  84.     }
  85.     
  86.     // Add the new avatar
  87.     if (!$sloodle->user->add_linked_avatar($USER->id$sloodleuuid$pa->avname)) {
  88.         // Failed
  89.         ?>
  90.         <div style="text-align:center;">
  91.          <h3><?php print_string('error''sloodle')?></h3>
  92.          <p><?php print_string('failedcreatesloodleuser''sloodle')?></p>
  93.         </div>
  94.         <?php
  95.         print_footer();
  96.         exit();
  97.     }
  98.     
  99.     echo "<div style=\"text-align:center\">\n";
  100.     echo get_string('welcometosloodle','sloodle').', '.$pa->avname.'<br /><br />'.get_string('userlinksuccessful','sloodle');
  101.     echo "</div>\n";
  102.     
  103.     // If the object passed us a channel parameter, we'll use it to tell the object that the authentication is done.
  104.     // (Parameter name: sloodlechannel)
  105.     if (is_string($sloodlechannel&& !empty($sloodlechannel)) {
  106.         flush();
  107.         
  108.         // XMLRPC messages going into SL strip \n, so we use \\n instead
  109.         $sloodle->response->set_line_separator("\\n");
  110.         // Prepare a response as a string
  111.         $str '';
  112.         $sloodle->response->set_status_code(1);
  113.         $sloodle->response->set_status_descriptor('USER_AUTH');
  114.         $sloodle->response->add_data_line('User has been successfully registered.');
  115.         $sloodle->response->render_to_string($str);
  116.         
  117.         // Send the message
  118.         $xmlrpcresult sloodle_send_xmlrpc_message($channel0$str);
  119.         if (!$xmlrpcresult{
  120.             echo '<div style="text-align:center;">';
  121.             echo 'ERROR: Unable to tell the object that sent you here that you have been authenticated.';
  122.             echo '</div>';
  123.         }
  124.     }
  125.     
  126.     
  127.     // We we asked to enrol the user as well?
  128.     if ($sloodlecourseid != NULL{
  129.         echo "<br/><br/><br/>";
  130.         redirect("{$CFG->wwwroot}/course/enrol.php?id=$sloodlecourseid"get_string('nowenrol','sloodle')3);
  131.     }
  132.     
  133.     
  134.     print_footer();
  135.     exit();
  136.  
  137. ?>

Documentation generated on Mon, 07 Jul 2008 12:33:17 +0100 by phpDocumentor 1.4.0