Source for file sl_object_auth.php

Documentation is available at sl_object_auth.php

  1. <?php
  2.     /**
  3.     * Sloodle object authorization page.
  4.     *
  5.     * Allows users in Moodle to authorize or deny in-world objects' access to Moodle.
  6.     *
  7.     * @package sloodleclassroom
  8.     * @copyright Copyright (c) 2008 Sloodle (various contributors)
  9.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  10.     *
  11.     * @contributor Edmund Edgar
  12.     * @contributor Peter R. Bloomfield
  13.     *
  14.     */
  15.     
  16.     // This script should be accessed from a web-browser.
  17.     // There are two modes of operation.
  18.     // Confirmation mode, and auth mode.
  19.     //
  20.     // In confirmation mode, the user is asked to confirm that they want to authorise a certain object.
  21.     // These are the standard parameters:
  22.     //
  23.     //   sloodleobjuuid = UUID of the object to be validated
  24.     //   sloodleobjname = name of the object to be validated (optional)
  25.     //   sloodlechannel = channel for the XMLRPC response to the object
  26.     //
  27.     // Auth mode is used after the user has confirmed that they want to authorise it.
  28.     // The is where the authorisation as carried out.
  29.     // The following additional parameter is required to use auth mode (in addition to those above):
  30.     //
  31.     //   auth = the status of the authorisation ('no' = denied, 'yes' = successful)
  32.     //
  33.     
  34.     // Since the script is viewed in a browser, the response is HTML format
  35.     
  36.     require_once('../config.php');
  37.     
  38.     // Make sure the user is logged-in as an administrator
  39.     // TODO: this will need to change to apply to individual virtual classroom instances (i.e. check for teacher status)
  40.     require_login();
  41.     if (!isadmin()) {
  42.         error(get_string('needadmin''sloodle'));
  43.         exit();
  44.     }
  45.  
  46.     // This is a weird way of doing things
  47.     if (isset($_REQUEST['sloodledebug'])) require_once(SLOODLE_DIRROOT.'/sl_debug.php');
  48.     
  49.     // Get our Sloodle classroom library
  50.     require_once(SLOODLE_DIRROOT.'/lib/sl_classroomlib.php');
  51.     
  52.     // Check for our optional parameters
  53.     $auth optional_param('auth'''PARAM_RAW);
  54.     $auth strtolower($auth);
  55.     
  56.     // Check the special case that the authorization has been cancelled
  57.     if ($auth == 'no'{
  58.         redirect($CFG->wwwrootget_string('objectauthcancelled','sloodle')5);
  59.         exit();
  60.     }
  61.     
  62.     // Check for our required parameters
  63.     $sloodleobjuuid required_param('sloodleobjuuid'PARAM_RAW);
  64.     $sloodleobjname optional_param('sloodleobjname'''PARAM_RAW);
  65.     $sloodlechannel required_param('sloodlechannel'PARAM_RAW);
  66.     
  67.     // Construct a breadcrumb navigation menu
  68.     $nav '';
  69.     $nav .= "<a href=\"{$CFG->wwwroot}/admin/module.php?module=sloodle\">Sloodle</a> -> "// Sloodle config page
  70.     $nav .= get_string('objectauth','sloodle')// This page
  71.     
  72.     // Display the page header
  73.     print_header(get_string('objectauth','sloodle')get_string('objectauth','sloodle')$nav''''FALSE);
  74.     //print_heading(get_string('objectauth','sloodle'));
  75.     
  76.     // Check which mode we're in
  77.     switch ($auth{
  78.     case 'yes':
  79.         // Authorization confirmed - do it
  80.         $userid $USER->id;
  81.         $result sloodle_authorize_object($sloodleobjuuid$sloodleobjname$userid$sloodlechannel);
  82.         if ($result{
  83.             print_heading('<span style="color:green;">'.get_string('objectauthsent','sloodle').'</span>');
  84.         else {
  85.             print_heading('<span style="color:red;">'.get_string('objectauthfailed','sloodle').'</span>');
  86.         }
  87.         break;
  88.         
  89.     default:
  90.         // Authorization needs confirmed
  91.         ?>
  92. <div style="text-align:center;">
  93.  <h4>
  94.   <?php
  95.    print_string('confirmobjectauth','sloodle');
  96.    echo ' ';
  97.    helpbutton('object_authorization',get_string('objectauth','sloodle'),'sloodle');
  98.   ?>
  99.  </h4>
  100.  <p>
  101.   <?php echo get_string('objectname','sloodle'.': '$sloodleobjname?><br/>
  102.   <?php echo get_string('objectuuid','sloodle'.': '$sloodleobjuuid?>
  103.  </p>
  104.  <form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
  105.   <input type="hidden" name="sloodleobjuuid" value="<?php echo $sloodleobjuuid?>" />
  106.   <input type="hidden" name="sloodleobjname" value="<?php echo $sloodleobjname?>" />
  107.   <input type="hidden" name="sloodlechannel" value="<?php echo $sloodlechannel?>" />
  108.  
  109. <?php
  110. if (defined('SLOODLE_DEBUG'&& SLOODLE_DEBUG{
  111.    echo "<input type=\"hidden\" name=\"sloodledebug\" value=\"true\" />";
  112. }
  113. ?>
  114.  
  115.   <input type="submit" name="auth" value="<?php print_string('Yes','sloodle')?>" />
  116.   &nbsp;&nbsp;
  117.   <input type="submit" name="auth" value="<?php print_string('No','sloodle')?>" />
  118.  </form>
  119. </div>
  120.         <?php
  121.         break;
  122.     }
  123.     
  124.  
  125.     print_footer();
  126.     exit();
  127. ?>

Documentation generated on Tue, 04 Mar 2008 15:08:49 +0000 by phpDocumentor 1.4.0