location_form.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. namespace App;
  3. use RuntimeException;
  4. /**
  5. * @var int $id
  6. */
  7. $request = Request::fromRequest();
  8. $core = Core::getInstance();
  9. $core->addBreadcrumb("/locations", __("Locations"));
  10. $user = $core->getUser();
  11. if(isset($id)) {
  12. $location = Location::require($id);
  13. $location->dts_updated = Database::dts();
  14. $core->addBreadcrumb($location->getUrl(), $location->name);
  15. $title = __("Update Location");
  16. }
  17. else {
  18. $customer_id = $request->int("customer_id");
  19. $location = new Location();
  20. $location->customer_id = $customer_id;
  21. $location->dts_created = Database::dts();
  22. $title = __("Add Location");
  23. }
  24. $core->addBreadcrumb($_SERVER["REQUEST_URI"], $title);
  25. $submit = $request->int("submit");
  26. if($submit) {
  27. try {
  28. $user->requireValidCsrfToken();
  29. Location::updateFromRequest($request, $location);
  30. Session::addAlert("success", __("Location saved successfully."));
  31. Http::redirect($location->getUrl());
  32. }
  33. catch(RuntimeException $e) {
  34. Session::addAlert("danger", $e->getMessage());
  35. }
  36. }
  37. View::include("header");
  38. View::include("entity_form", [
  39. "title" => $title,
  40. "model" => $location,
  41. "address" => $location->getAddress()
  42. ]);
  43. View::include("footer");