configure_rezzer.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // Simulates an ajax object-rezzing request
  3. require_once '../../../lib/json/json_encoding.inc.php';
  4. /** Grab the Sloodle/Moodle configuration. */
  5. require_once('../../../init.php');
  6. /** Include the Sloodle PHP API. */
  7. /** Sloodle core library functionality */
  8. require_once(SLOODLE_DIRROOT.'/lib.php');
  9. /** General Sloodle functions. */
  10. require_once(SLOODLE_LIBROOT.'/io.php');
  11. /** Sloodle course data. */
  12. require_once(SLOODLE_LIBROOT.'/course.php');
  13. require_once(SLOODLE_LIBROOT.'/layout_profile.php');
  14. require_once(SLOODLE_LIBROOT.'/active_object.php');
  15. require_once(SLOODLE_LIBROOT.'/user.php');
  16. require_once(SLOODLE_LIBROOT.'/object_configs.php');
  17. $object_configs = SloodleObjectConfig::AllAvailableAsArray();
  18. if (!$USER->id) {
  19. error_output( 'User not logged in' );
  20. }
  21. $rezzer = new SloodleActiveObject();
  22. $sloodleuser = new SloodleUser();
  23. $sloodleuser->user_data = $USER;
  24. if (!$controllerid = optional_param('controllerid', 0, PARAM_INT)) {
  25. error_output( 'Controller ID missing' );
  26. }
  27. if ( !$rezzeruuid = optional_param('rezzeruuid', '', PARAM_SAFEDIR) ) {
  28. error_output( 'Rezzer UUID missing or incorrect' );
  29. }
  30. if ( !$rezzer->loadByUUID($rezzeruuid) ) {
  31. error_output( 'Controller ID missing' );
  32. }
  33. $controller_context = get_context_instance( CONTEXT_MODULE, $controllerid);
  34. if (!has_capability('mod/sloodle:uselayouts', $controller_context)) {
  35. error_output( 'Access denied');
  36. }
  37. // TODO: Make this check for a change in the site name, then remove the "true" to avoid pointless reconfiguration
  38. if (true || ($rezzer->controllerid != $controllerid) || ($rezzer->userid != $USER->id) ) {
  39. //if ( ($rezzer->controllerid != $controllerid) || ($rezzer->userid != $USER->id) ) {
  40. $rezzer->controllerid = $controllerid;
  41. if (!$rezzer->save()) {
  42. error_output('Updating rezzer failed');
  43. }
  44. if (!$result = $rezzer->sendConfig()) {
  45. error_output('Sending config failed');
  46. }
  47. if ($result['info']['http_code'] == 404) {
  48. error_output('HTTP-in URL not found');
  49. }
  50. if ($result['info']['http_code'] != 200) {
  51. error_output('HTTP-in request failed');
  52. }
  53. }
  54. $info = $result['info'];
  55. $result = 'configured';
  56. $content = array(
  57. 'result' => $result,
  58. 'error' => '',
  59. 'info' => $info,
  60. );
  61. print json_encode($content);
  62. function error_output($error) {
  63. $content = array(
  64. 'result' => 'failed',
  65. 'error' => $error,
  66. );
  67. print json_encode($content);
  68. exit;
  69. }
  70. ?>