rename_layout.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /** Grab the Sloodle/Moodle configuration. */
  3. require_once('../../../init.php');
  4. /** Include the Sloodle PHP API. */
  5. /** Sloodle core library functionality */
  6. require_once(SLOODLE_DIRROOT.'/lib.php');
  7. /** General Sloodle functions. */
  8. require_once(SLOODLE_LIBROOT.'/io.php');
  9. /** Sloodle course data. */
  10. require_once(SLOODLE_LIBROOT.'/course.php');
  11. require_once(SLOODLE_LIBROOT.'/layout_profile.php');
  12. require_once(SLOODLE_LIBROOT.'/user.php');
  13. require_once '../../../lib/json/json_encoding.inc.php';
  14. $layoutid = optional_param('layoutid', 0, PARAM_INT);
  15. $layoutname = optional_param('layoutname', 0, PARAM_TEXT);
  16. if (!$layoutid) {
  17. error_output( 'Layout ID missing');
  18. }
  19. $layout = new SloodleLayout();
  20. if (!$layout->load( $layoutid )) {
  21. error_output('Could not load layout');
  22. }
  23. $controller_context = get_context_instance( CONTEXT_MODULE, $layout->controllerid);
  24. if (!has_capability('mod/sloodle:editlayouts', $controller_context)) {
  25. error_output( 'Access denied');
  26. }
  27. $layout->name = $layoutname;
  28. if (!sloodle_update_record('sloodle_layout', $layout)) {
  29. error_output('Could not save layout');
  30. }
  31. $content = array(
  32. 'result' => 'renamed',
  33. 'layoutname' => $layoutname, // TODO: Get this from the object_configs
  34. 'layoutid' => $layoutid,
  35. );
  36. print json_encode($content);
  37. exit;
  38. function error_output($error) {
  39. $content = array(
  40. 'result' => 'failed',
  41. 'error' => $error,
  42. );
  43. print json_encode($content);
  44. exit;
  45. }
  46. ?>