location_add_note.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * @var int $id
  4. */
  5. $user = Core::$user;
  6. $location = Location::get($id);
  7. if(!$location) throw new Exception("Location not found.");
  8. if(!Core::$user->hasPermission($location)) throw new Exception("You do not have have permission to access this page.");
  9. $submit = http::value("submit");
  10. if($submit) {
  11. try {
  12. Core::validateCSRFToken($submit);
  13. $form_exception = new FormException;
  14. $note = new LocationNote;
  15. $note->location_id = $location->id;
  16. $note->user_id = $user->id;
  17. $note->content = HTTP::value("content", "trim");
  18. $note->dts_created = DB::dts();
  19. if(empty($note->content)) $form_exception->addError("Note is required.");
  20. if($form_exception->hasErrors()) throw $form_exception;
  21. $success = $note->commit();
  22. if(!$success) throw new Exception("Failed to add note at this time. Please try again later.");
  23. Core::addAlert("success", "Note added successfully.");
  24. }
  25. catch(FormException $e) {
  26. $e->generateAlerts();
  27. }
  28. catch(Exception $e) {
  29. Core::addAlert("danger", $e->getMessage());
  30. }
  31. HTTP::redirect("/account/locations/$location->id");
  32. }