confirm_active_objects.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Sloodle active object confirm.
  4. * Allows the rezzer to check for any objects that are no longer there, because they have been manually derezzed.
  5. * With sloodlecmd=requestconfirmable, expects a list of uuids of objects that haven't checked in recently.
  6. * With sloodlecmd=reportdisappeared, supplies a list of uuids of objects that have been found to be absent.
  7. * If an object is found to be absent, its rezzer uuid will be removed.
  8. * The object is left in the active object table in case it has been taken into inventory rather than deleted.
  9. *
  10. * @package sloodleclassroom
  11. * @copyright Copyright (c) 2008 Sloodle (various contributors)
  12. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  13. *
  14. * @contributor Peter R. Bloomfield
  15. * @contributor Edmund Edgar
  16. *
  17. */
  18. // The following parameters are required:
  19. //
  20. // sloodlecontrollerid = the ID of the controller through which the current object may access Sloodle
  21. // sloodlepwd = the prim password or object-specific session key to authenticate access
  22. // sloodleobjuuid = the UUID of the object which is active
  23. // sloodlecmd = the task - either requestconfirmable or reportdisappeared
  24. //
  25. // If the check is successful, the status code will be 1.
  26. // If the object was not found, status code -103 is returned.
  27. //
  28. //
  29. /** Lets Sloodle know we are in a linker script. */
  30. define('SLOODLE_LINKER_SCRIPT', true);
  31. /** Grab the Sloodle/Moodle configuration. */
  32. require_once('../init.php');
  33. /** Include the Sloodle PHP API. */
  34. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  35. $task = required_param('sloodlecmd', PARAM_TEXT);
  36. // Authenticate the request
  37. $sloodle = new SloodleSession();
  38. // The access record happens when we authenticate.
  39. // If it fails, it should error out and exit.
  40. $sloodle->authenticate_request();
  41. $rezzer = $sloodle->active_object;
  42. if ($task == 'requestconfirmable') {
  43. $uuids = $rezzer->uuids_of_children_missing_since( 0, time() + 900 );
  44. $sloodle->response->set_status_code(1);
  45. $sloodle->response->set_status_descriptor('OK');
  46. $sloodle->response->set_refresh_seconds(SLOODLE_REZZER_STATUS_CONFIRM_INTERVAL);
  47. if (count($uuids) > 0) {
  48. foreach($uuids as $uuid) {
  49. $sloodle->response->add_data_line(array($uuid));
  50. }
  51. }
  52. } else {
  53. $uuidstr = required_param('sloodlemissinguuids', PARAM_TEXT);
  54. if ($uuidstr != '') {
  55. $uuids = explode('|', $uuidstr);
  56. if (count($uuids) > 0) {
  57. foreach($uuids as $uuid) {
  58. if ($uuid == '') {
  59. continue;
  60. }
  61. $ao = new SloodleActiveObject();
  62. if ( $ao->loadByUUID( $uuid ) ) {
  63. if ($ao->rezzeruuid == $rezzer->uuid) {
  64. $ao->rezzeruuid = '';
  65. $ao->save();
  66. }
  67. }
  68. }
  69. }
  70. }
  71. $sloodle->response->set_status_code(1);
  72. $sloodle->response->set_status_descriptor('OK');
  73. }
  74. // Output the response
  75. $sloodle->response->render_to_output();
  76. ?>