| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?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);
- $customer = $location->getCustomer();
- $location->dts_updated = Database::dts();
- $core->addBreadcrumb($customer->getUrl(), $customer->name);
- $core->addBreadcrumb($location->getUrl(), $location->name);
- $title = __("Update Location");
- }
- else {
- $customer_id = $request->int("customer_id");
- $customer = Customer::require($customer_id);
- $location = new Location();
- $location->customer_id = $customer_id;
- $location->dts_created = Database::dts();
- $title = __("Add Location");
- $core->addBreadcrumb($customer->getUrl(), $customer->name);
- }
- $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");
|