edit.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. $guid = (int) get_input("guid");
  3. $title = get_input("title");
  4. $owner_guid = (int) get_input("page_owner");
  5. $description = get_input("description");
  6. $parent_guid = (int) get_input("file_tools_parent_guid", 0); // 0 is top_level
  7. $access_id = (int) get_input("access_id", ACCESS_DEFAULT);
  8. $change_children_access = get_input("change_children_access", false);
  9. $change_files_access = get_input("change_files_access", false);
  10. if (!empty($title) && !empty($owner_guid)) {
  11. if (($owner = get_entity($owner_guid)) && (elgg_instanceof($owner, "user") || elgg_instanceof($owner, "group"))) {
  12. if (!empty($guid)) {
  13. // check if editing existing
  14. if ($folder = get_entity($guid)) {
  15. if (!elgg_instanceof($folder, "object", FILE_TOOLS_SUBTYPE)) {
  16. unset($folder);
  17. }
  18. }
  19. } else {
  20. // create a new folder
  21. $folder = new ElggObject();
  22. $folder->subtype = FILE_TOOLS_SUBTYPE;
  23. $folder->owner_guid = elgg_get_logged_in_user_guid();
  24. $folder->container_guid = $owner_guid;
  25. $folder->access_id = $access_id;
  26. $order = elgg_get_entities_from_metadata(array(
  27. "type" => "object",
  28. "subtype" => FILE_TOOLS_SUBTYPE,
  29. "metadata_name_value_pairs" => array(
  30. "name" => "parent_guid",
  31. "value" => $parent_guid
  32. ),
  33. "count" => true
  34. ));
  35. $folder->order = $order;
  36. if (!$folder->save()) {
  37. unset($folder);
  38. }
  39. }
  40. if (!empty($folder)) {
  41. // check for the correct parent_guid
  42. if (($parent_guid === 0) || ($parent_guid != $folder->getGUID())) {
  43. $folder->title = $title;
  44. $folder->description = $description;
  45. $folder->access_id = $access_id;
  46. if (!empty($change_children_access)) {
  47. $folder->save();
  48. file_tools_change_children_access($folder, !empty($change_files_access));
  49. } elseif (!empty($change_files_access)) {
  50. $folder->save();
  51. file_tools_change_files_access($folder);
  52. }
  53. // check if we have a correct parent_guid
  54. if ($parent_guid == $folder->getGUID()) {
  55. // set parent to 0 (main level)
  56. $parent_guid = 0;
  57. }
  58. $folder->parent_guid = $parent_guid;
  59. if ($folder->save()) {
  60. $forward_url = $folder->getURL();
  61. system_message(elgg_echo("file_tools:action:edit:success"));
  62. } else {
  63. register_error(elgg_echo("file_tools:action:edit:error:save"));
  64. }
  65. } else {
  66. register_error(elgg_echo("file_tools:action:edit:error:parent_guid"));
  67. }
  68. } else {
  69. register_error(elgg_echo("file_tools:action:edit:error:folder"));
  70. }
  71. } else {
  72. register_error(elgg_echo("file_tools:action:edit:error:owner"));
  73. }
  74. } else {
  75. register_error(elgg_echo("file_tools:action:edit:error:input"));
  76. }
  77. if (!empty($forward_url)) {
  78. forward($forward_url);
  79. }
  80. forward(REFERER);