object_config_linker.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Sloodle object configuration linker.
  4. *
  5. * Allows objects in-world to download their configuration settings.
  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 Peter R. Bloomfield
  12. *
  13. */
  14. // This script should be called with the following parameters:
  15. //
  16. // sloodlepwd = password for authentication
  17. // sloodleauthid = the object whose configuration is being downloaded
  18. //
  19. // The controller is identified by the object's authorisation.
  20. // If succesful, status code 1 is returned, and each data line contains a name/value pair, like so:
  21. //
  22. // 1|OK
  23. // name|value
  24. //
  25. // Returns status code -103 if the object was not found or has not been configured yet.
  26. //
  27. /** Grab the Sloodle/Moodle configuration. */
  28. require_once('../init.php');
  29. /** Include the Sloodle PHP API. */
  30. require_once(SLOODLE_LIBROOT.'/sloodle_session.php');
  31. // Start a new Sloodle session
  32. $sloodle = new SloodleSession();
  33. // Get the object ID
  34. $sloodleauthid = (int)$sloodle->request->required_param('sloodleauthid');
  35. $auth_obj = SloodleController::get_object($sloodleauthid);
  36. if (!$auth_obj) {
  37. $sloodle->response->quick_output(-103, 'SYSTEM', 'Object not found', false);
  38. exit();
  39. }
  40. // Is the object authorised?
  41. if ($auth_obj->course->controller->is_loaded() == false) {
  42. $sloodle->response->quick_output(-103, 'SYSTEM', 'Object not authorised', false);
  43. exit();
  44. }
  45. // Authenticate the request
  46. $sloodle->course = $auth_obj->course; // The object doesn't know it's controller yet, but the database does.
  47. $_REQUEST['sloodlecontrollerid'] = $auth_obj->course->controller->get_id();
  48. $sloodle->authenticate_request();
  49. // Add a note of the controller and course names to the outgoing data
  50. $sloodle->response->add_data_line(array('sloodlecontrollerid', $auth_obj->course->controller->get_id()));
  51. $sloodle->response->add_data_line(array('sloodlecoursename_short', $auth_obj->course->get_short_name()));
  52. $sloodle->response->add_data_line(array('sloodlecoursename_full', $auth_obj->course->get_short_name()));//$auth_obj->course->get_full_name())); // Shortened... was causing memory errors!
  53. // Fetch all the configuration settings
  54. $settings = sloodle_get_records('sloodle_object_config', 'object', $sloodleauthid);
  55. if (!$settings) {
  56. // Error: no configuration settings... there should be at least one indicating the type
  57. $sloodle->response->quick_output(-103, 'SYSTEM', 'Object not configured yet.', false);
  58. exit();
  59. }
  60. // Output each setting
  61. foreach ($settings as $s) {
  62. $sloodle->response->add_data_line(array($s->name, $s->value));
  63. }
  64. $sloodle->response->set_status_code(1);
  65. $sloodle->response->set_status_descriptor('OK');
  66. $sloodle->response->render_to_output();
  67. exit();
  68. ?>