delete.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * CRUD -- Delete action
  4. *
  5. * @package Lorea
  6. * @subpackage CRUD
  7. *
  8. * Copyright 2012-2013 Lorea Faeries <federation@lorea.org>
  9. *
  10. * This program is free software: you can redistribute it and/or
  11. * modify it under the terms of the GNU Affero General Public License
  12. * as published by the Free Software Foundation, either version 3 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public
  21. * License along with this program. If not, see
  22. * <http://www.gnu.org/licenses/>.
  23. */
  24. $entity_guid = get_input('guid');
  25. $entity = get_entity($entity_guid);
  26. $crud_type = $entity->getSubtype();
  27. $crud = crud_get_handler($crud_type);
  28. $module = $crud->module;
  29. if (elgg_instanceof($entity, 'object', $crud_type) && $entity->canEdit()) {
  30. $parent = get_entity($entity->parent_guid);
  31. $container = get_entity($entity->container_guid);
  32. if ($entity->delete()) {
  33. system_message(elgg_echo("$module:message:deleted_$crud_type"));
  34. if ($parent) {
  35. $parent_type = $parent->getSubtype();
  36. forward("$parent_type/view/$parent->guid");
  37. } else {
  38. forward("$crud_type/owner/$container->guid");
  39. }
  40. } else {
  41. register_error(elgg_echo("$module:error:cannot_delete_$crud_type"));
  42. }
  43. } else {
  44. register_error(elgg_echo("$module:error:$crud_type"."_not_found"));
  45. }
  46. forward(REFERER);