linker.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Sloodle distributor linker (for Sloodle 0.3).
  4. * Allows a Sloodle Vending Machine to update its inventory and XMLRPC channel details.
  5. *
  6. * @package sloodledistributor
  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 Edmund Edgar
  11. * @contributor Peter R. Bloomfield
  12. */
  13. // This script should be called with the following parameters:
  14. // sloodlecontrollerid = ID of a Sloodle Controller through which to access Moodle
  15. // sloodlepwd = the prim password or object-specific session key to authenticate the request
  16. // sloodlemoduleid = ID of a chatroom
  17. // sloodleinventory = a pipe-separated list of names of items in the obect's inventory
  18. // sloodlechannel = the UUID of an XMLRPC channel which can be used to request object distribution
  19. //
  20. // The following parameter is optional:
  21. // sloodledebug = if 'true', then Sloodle debugging mode is activated
  22. /** Lets Sloodle know we are in a linker script. */
  23. define('SLOODLE_LINKER_SCRIPT', true);
  24. /** Grab the Sloodle/Moodle configuration. */
  25. require_once('../../init.php');
  26. /** Include the Sloodle PHP API. */
  27. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  28. // Authenticate the request, and load a chat module
  29. $sloodle = new SloodleSession();
  30. $sloodle->authenticate_request();
  31. $sloodle->load_module('distributor', true);
  32. // Fetch the required additional parameters
  33. $sloodleinventory = $sloodle->request->required_param('sloodleinventory');
  34. $sloodlechannel = $sloodle->request->required_param('sloodlechannel');
  35. // Attempt to update the inventory
  36. $objects = explode('|', $sloodleinventory);
  37. if (!$sloodle->module->set_objects($objects)) {
  38. // Update failed
  39. $sloodle->response->quick_output(-101, 'SYSTEM', 'Failed to update list of objects', false);
  40. exit();
  41. }
  42. // Attempt to update the channel
  43. if (!$sloodle->module->set_channel($sloodlechannel)) {
  44. // Update failed
  45. $sloodle->response->quick_output(-101, 'SYSTEM', 'Failed to update XMLRPC channel UUID', false);
  46. exit();
  47. }
  48. // Everything seems fine
  49. $sloodle->response->set_status_code(1);
  50. $sloodle->response->set_status_descriptor('OK');
  51. // Output our response
  52. $sloodle->response->render_to_output();
  53. ?>