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"); }