delete_layout_entry.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. // Simulates an ajax object-rezzing request
  3. /** Grab the Sloodle/Moodle configuration. */
  4. require_once('../../../init.php');
  5. /** Include the Sloodle PHP API. */
  6. /** Sloodle core library functionality */
  7. require_once(SLOODLE_DIRROOT.'/lib.php');
  8. /** General Sloodle functions. */
  9. require_once(SLOODLE_LIBROOT.'/io.php');
  10. /** Sloodle course data. */
  11. require_once(SLOODLE_LIBROOT.'/course.php');
  12. require_once(SLOODLE_LIBROOT.'/layout_profile.php');
  13. require_once(SLOODLE_LIBROOT.'/active_object.php');
  14. require_once(SLOODLE_LIBROOT.'/user.php');
  15. require_once '../../../lib/json/json_encoding.inc.php';
  16. $configVars = array();
  17. $layoutentryid = null;
  18. if (isset($_POST['layoutentryid'])) {
  19. $layoutentryid = intval($_POST['layoutentryid']);
  20. }
  21. //$rezzeruuid = optional_param( 'rezzeruuid', null, PARAM_SAFEDIR );
  22. if (!$layoutentryid) {
  23. error_output( 'Layout entry ID missing');
  24. }
  25. $result = '';
  26. $layoutentry = new SloodleLayoutEntry();
  27. // Already gone - return that it's deleted.
  28. if (!$layoutentry->load($layoutentryid)) {
  29. $result = 'deleted';
  30. }
  31. if (!$result) {
  32. $layout = new SloodleLayout();
  33. if (!$layout->load($layoutentry->layout)) {
  34. error_output('Layout not found');
  35. }
  36. $controller_context = get_context_instance( CONTEXT_MODULE, $layout->controllerid);
  37. if (!has_capability('mod/sloodle:uselayouts', $controller_context)) {
  38. error_output( 'Access denied');
  39. }
  40. if (!$layoutentry->delete()) {
  41. error_output('Layout entry deletion failed');
  42. }
  43. $result = 'deleted';
  44. }
  45. /*
  46. // FOR NOW: Leaving this for later
  47. // If we have a rezzer, derez any outstanding objects
  48. if ($rezzeruuid) {
  49. $active_objects = $controller->get_active_objects( $rezzeruuid, $layoutentryid );
  50. foreach($active_objects as $ao) {
  51. if (!$ao->deRez()) {
  52. $failures[] = $ao;
  53. }
  54. }
  55. }
  56. */
  57. $content = array(
  58. 'result' => $result,
  59. 'layoutentryid' => $layoutentryid,
  60. 'layoutid' => $_REQUEST['layoutid']
  61. );
  62. $rand = rand(0,10);
  63. //sleep($rand);
  64. print json_encode($content);
  65. exit;
  66. function error_output($error) {
  67. $content = array(
  68. 'result' => 'failed',
  69. 'error' => $error,
  70. );
  71. print json_encode($content);
  72. exit;
  73. }
  74. ?>