course_info_linker.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Course information linker.
  4. * Allows objects in-world to query for information about a particular course.
  5. *
  6. * @package sloodleclassroom
  7. * @copyright Copyright (c) 2008 Sloodle (various contributors)
  8. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  9. *
  10. * @contributor Peter R. Bloomfield
  11. *
  12. */
  13. // The following parameters are required:
  14. //
  15. // sloodlecontrollerid = the ID of the controller through which the current object may access Sloodle
  16. // sloodlepwd = the prim password or object-specific session key to authenticate access
  17. //
  18. // If everything is OK, the script will return status code, with the following information on the data lines:
  19. // coursename_short|coursename_full
  20. // autoreg_enabled|autoenrol_enabled
  21. //
  22. // The information will relate to whatever course the accessed controller belongs to.
  23. // (This is for security, to ensure course data cannot be retrieved unauthorised).
  24. // The autoreg and autoenrol values will be 0 or 1, indicate whether each feature is disabled or enabled on the course.
  25. /** Lets Sloodle know we are in a linker script. */
  26. define('SLOODLE_LINKER_SCRIPT', true);
  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. // Authenticate the request
  32. $sloodle = new SloodleSession();
  33. $sloodle->authenticate_request();
  34. // Make sure Sloodle is actually installed
  35. $moduleinfo = sloodle_get_record('modules', 'name', 'sloodle');
  36. if (!$moduleinfo) {
  37. sloodle_debug('ERROR: Sloodle not installed<br/>');
  38. $sloodle->response->quick_output(-106, 'SYSTEM', 'The Sloodle module is not installed on this Moodle site.', false);
  39. exit();
  40. }
  41. // Check out autoreg and autoenrol settings
  42. $autoreg = '0';
  43. $autoenrol = '0';
  44. if ($sloodle->course->check_autoreg()) $autoreg = '1';
  45. if ($sloodle->course->check_autoenrol()) $autoenrol = '1';
  46. // Prepare the output
  47. $sloodle->response->set_status_code(1);
  48. $sloodle->response->set_status_descriptor('OK');
  49. $sloodle->response->add_data_line(array($sloodle->course->get_short_name(), $sloodle->course->get_full_name()));
  50. $sloodle->response->add_data_line(array($autoreg, $autoenrol));
  51. // Render the output
  52. $sloodle->response->render_to_output();
  53. exit();
  54. ?>