| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- namespace App;
- use RuntimeException;
- /**
- * @var int $id
- */
- $request = Request::fromRequest();
- $core = Core::getInstance();
- $core->addBreadcrumb("/locations", __("Locations"));
- $user = $core->getUser();
- if(isset($id)) {
- $location = Location::require($id);
- $location->dts_updated = Database::dts();
- $core->addBreadcrumb($location->getUrl(), $location->name);
- $title = __("Update Location");
- }
- else {
- $customer_id = $request->int("customer_id");
- $location = new Location();
- $location->customer_id = $customer_id;
- $location->dts_created = Database::dts();
- $title = __("Add Location");
- }
- $core->addBreadcrumb($_SERVER["REQUEST_URI"], $title);
- $submit = $request->int("submit");
- if($submit) {
- try {
- $user->requireValidCsrfToken();
- Location::updateFromRequest($request, $location);
- Session::addAlert("success", __("Location saved successfully."));
- Http::redirect($location->getUrl());
- }
- catch(RuntimeException $e) {
- Session::addAlert("danger", $e->getMessage());
- }
- }
- View::include("header");
- View::include("entity_form", [
- "title" => $title,
- "model" => $location,
- "address" => $location->getAddress()
- ]);
- View::include("footer");
|