| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- /**
- * @var int $id
- */
- $user = Core::$user;
- $location = Location::get($id);
- if(!$location) throw new Exception("Location not found.");
- if(!Core::$user->hasPermission($location)) throw new Exception("You do not have have permission to access this page.");
- $submit = http::value("submit");
- if($submit) {
- try {
- Core::validateCSRFToken($submit);
- $form_exception = new FormException;
- $note = new LocationNote;
- $note->location_id = $location->id;
- $note->user_id = $user->id;
- $note->content = HTTP::value("content", "trim");
- $note->dts_created = DB::dts();
- if(empty($note->content)) $form_exception->addError("Note is required.");
- if($form_exception->hasErrors()) throw $form_exception;
- $success = $note->commit();
- if(!$success) throw new Exception("Failed to add note at this time. Please try again later.");
- Core::addAlert("success", "Note added successfully.");
- }
- catch(FormException $e) {
- $e->generateAlerts();
- }
- catch(Exception $e) {
- Core::addAlert("danger", $e->getMessage());
- }
- HTTP::redirect("/account/locations/$location->id");
- }
|