Source for file linker.php

Documentation is available at linker.php

  1. <?php
  2.     /**
  3.     * Sloodle PrimDrop linker (for Sloodle 0.3).
  4.     * Allows a Sloodle PrimDrop object to interact with a 'Sloodle Object' assignment type.
  5.     *
  6.     * @package sloodleprimdrop
  7.     * @copyright Copyright (c) 2007-8 Sloodle (various contributors)
  8.     * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  9.     *
  10.     * @contributor Jeremy Kemp
  11.     * @contributor Peter R. Bloomfield
  12.     */
  13.     
  14.     // This script should be called with the following parameters:
  15.     //  sloodlecontrollerid = ID of a Sloodle Controller through which to access Moodle
  16.     //  sloodlepwd = the prim password or object-specific session key to authenticate the request
  17.     //  sloodlemoduleid = cmID of an assignment
  18.     //
  19.     // If accessed with only the above paramters, then the script will return information about the assignment.
  20.     // Status code will be 1, and the first data line will contain the name of the assignment.
  21.     // The second data line will contain the description of the assignment.
  22.     //
  23.     // To check whether or not a user can submit an assignment, the following details should also be provided:
  24.     //  sloodleuuid = UUID of the avatar who created the submission
  25.     //  sloodleavname = name of the avatar who created the submission
  26.     //
  27.     // The status code returned will be as follows (no data):
  28.     //  1 = OK
  29.     //  -10201 = User is not authorised to submit assignments
  30.     //  -10202 = Assignment is not yet open for submissions
  31.     //  -10203 = Assignment due date has passed, and is closed for submissions
  32.     //  -10204 = Assignment due date has passed, but is still accepting submissions
  33.     //  -10205 = User has already submitted, and resubmissions are not being accepted
  34.     //
  35.     // To report a submission, the following parameters (in addition to all above) should be provided:
  36.     //  sloodleobjname = Name of the object being submitted
  37.     //  sloodleprimcount = Number of prims in the object being submitted
  38.     //  sloodleprimdropname = Name of the PrimDrop object being submitted to
  39.     //  sloodleprimdropuuid = UUID of the PrimDrop object being submitted to
  40.     //  sloodleregion = region in which the PrimDrop is located
  41.     //  sloodlepos = position of the PrimDrop (vector <x,y,z>)
  42.     //
  43.     // If the submission was successful, the status code will be 1.
  44.     // Otherwise, the codes above may be returned (although -10204 will only appear as a side effect).
  45.     // Status code -103 will appear if some assignment submission to the database fails.
  46.     //
  47.  
  48.     /** Lets Sloodle know we are in a linker script. */
  49.     define('SLOODLE_LINKER_SCRIPT'true);
  50.     
  51.     /** Grab the Sloodle/Moodle configuration. */
  52.     require_once('../../sl_config.php');
  53.     /** Include the Sloodle PHP API. */
  54.     require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  55.     
  56.     // Authenticate the request, load the Sloodle Object assignment module, and validate the user
  57.     $sloodle new SloodleSession();
  58.     $sloodle->authenticate_request();
  59.     $sloodle->load_module('sloodleobject'true);
  60.     
  61.     // Has user data been omitted?
  62.     $uuid $sloodle->request->get_avatar_uuid(false);
  63.     $avname $sloodle->request->get_avatar_name(false);
  64.     if ($uuid == null && $avname == null{
  65.         // Just query the assignment details
  66.         $sloodle->response->set_status_code(1);
  67.         $sloodle->response->set_status_descriptor('OK');
  68.         $sloodle->response->add_data_line($sloodle->module->get_name());
  69.         $sloodle->response->add_data_line(strip_tags($sloodle->module->get_intro()));
  70.         $sloodle->response->render_to_output();
  71.         exit();
  72.     }
  73.     
  74.     // Some user data has been provided, so make sure we can validate the user
  75.     $sloodle->validate_user();
  76.     
  77.     // Check the requirements for allowing submissions
  78.     $status 1// This means it's OK
  79.     if (!$sloodle->module->user_can_submit($sloodle->user)) $status = -10201;
  80.     else if ($sloodle->module->user_has_submitted($sloodle->user== true && $sloodle->module->resubmit_allowed(== false$status = -10205;
  81.     else if ($sloodle->module->is_too_early()) $status = -10202;
  82.     else {
  83.         $late $sloodle->module->is_too_late();
  84.         if ($late 0$status = -10203;
  85.         else if ($late 0$sloodle->response->add_side_effect(-10204)// Still OK... just late! :-)
  86.     }
  87.     
  88.     // If the status was bad, then report it
  89.     if ($status 1{
  90.         $sloodle->response->set_status_code($status);
  91.         $sloodle->response->set_status_descriptor('ASSIGNMENT');
  92.         $sloodle->response->render_to_output();
  93.         exit();
  94.     }
  95.     
  96.     // Has an object name been provided?
  97.     $sloodleobjname $sloodle->request->optional_param('sloodleobjname'null);
  98.     if ($sloodleobjname == null || empty($sloodleobjname)) {
  99.         // No - just checking if the user can submit
  100.         $sloodle->response->set_status_code(1);
  101.         $sloodle->response->set_status_descriptor('OK');
  102. $sloodle->response->add_data_line('Checked assignment status');
  103.         $sloodle->response->render_to_output();
  104.         exit();
  105.     }
  106.     
  107.     // Object being submitted - fetch our other data
  108.     $sloodleprimcount = (int)$sloodle->request->required_param('sloodleprimcount');
  109.     $sloodleprimdropname $sloodle->request->required_param('sloodleprimdropname');
  110.     $sloodleprimdropuuid $sloodle->request->required_param('sloodleprimdropuuid');
  111.     $sloodleregion $sloodle->request->required_param('sloodleregion');
  112.     $sloodlepos $sloodle->request->required_param('sloodlepos');
  113.     
  114.     // Make sure the position is valid
  115.     $arr sloodle_vector_to_array($sloodlepos);
  116.     if (!$arr$sloodlepos '<0,0,0>';
  117.     else $sloodlepos sloodle_round_vector($sloodlepos);
  118.     
  119.     // Submit all the data
  120.     if ($sloodle->module->submit($sloodle->user$sloodleobjname$sloodleprimcount$sloodleprimdropname$sloodleprimdropuuid$sloodleregion$sloodlepos)) {
  121.         // OK
  122.         $sloodle->response->set_status_code(1);
  123.         $sloodle->response->set_status_descriptor('OK');
  124. $sloodle->response->add_data_line('SUBMITTED OBJECT');
  125.     else {
  126.         // Error
  127.         $sloodle->response->set_status_code(-103);
  128.         $sloodle->response->set_status_descriptor('SYSTEM');
  129.         $sloodle->response->add_data_line('Failed to add assignment data into database.');
  130.     }
  131.     
  132.     // Render the response
  133.     $sloodle->response->render_to_output();
  134.     exit();    
  135. ?>

Documentation generated on Fri, 17 Jul 2009 11:01:44 +0100 by phpDocumentor 1.4.0