edit.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * save a site announcement
  4. */
  5. site_announcements_editor_gatekeeper();
  6. elgg_make_sticky_form("site_announcement_edit");
  7. $guid = (int) get_input("guid");
  8. $description = get_input("description");
  9. $access_id = (int) get_input("access_id");
  10. $announcement_type = get_input("announcement_type");
  11. $startdate = (int) get_input("startdate");
  12. $starthour = (int) get_input("starthour");
  13. $startmins = (int) get_input("startmins");
  14. $enddate = (int) get_input("enddate");
  15. $endhour = (int) get_input("endhour");
  16. $endmins = (int) get_input("endmins");
  17. $realstartdate = mktime($starthour, $startmins, 0, date("n", $startdate), date("j", $startdate), date("Y", $startdate));
  18. $realenddate = mktime($endhour, $endmins, 0, date("n", $enddate), date("j", $enddate), date("Y", $enddate));
  19. $forward_url = REFERER;
  20. if (!empty($description) && !empty($realstartdate) && !empty($realenddate)) {
  21. if ($realenddate > $realstartdate) {
  22. if (!empty($guid)) {
  23. $entity = get_entity($guid);
  24. if (empty($entity) || !elgg_instanceof($entity, "object", SITE_ANNOUNCEMENT_SUBTYPE)) {
  25. unset($entity);
  26. register_error(elgg_echo("noaccess"));
  27. }
  28. } else {
  29. $entity = new ElggObject();
  30. $entity->subtype = SITE_ANNOUNCEMENT_SUBTYPE;
  31. $entity->access_id = $access_id;
  32. $entity->owner_guid = elgg_get_site_entity()->getGUID();
  33. $entity->container_guid = elgg_get_site_entity()->getGUID();
  34. if (!$entity->save()) {
  35. unset($entity);
  36. register_error(elgg_echo("save:fail"));
  37. }
  38. }
  39. if (!empty($entity)) {
  40. $entity->description = $description;
  41. $entity->access_id = $access_id;
  42. $entity->save();
  43. $entity->startdate = $realstartdate;
  44. $entity->enddate = $realenddate;
  45. $entity->announcement_type = $announcement_type;
  46. if ($entity->save()) {
  47. elgg_clear_sticky_form("site_announcement_edit");
  48. $forward_url = "announcements/all";
  49. system_message(elgg_echo("site_announcement:action:edit:success"));
  50. } else {
  51. register_error(elgg_echo("site_announcement:action:edit:error:save"));
  52. }
  53. }
  54. } else {
  55. register_error(elgg_echo("site_announcement:action:edit:error:time"));
  56. }
  57. } else {
  58. register_error(elgg_echo("site_announcement:action:edit:error:input"));
  59. }
  60. forward($forward_url);