| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?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);
- $address = $location->getAddress();
- $title = __("Update Location");
- }
- else {
- $location = new Location();
- $customer_id = $request->int("customer_id");
- if($customer_id) {
- $customer = Customer::require($customer_id);
- $location->customer_id = $customer_id;
- $location->name = $customer->name;
- $location->phone = $customer->phone;
- $location->email = $customer->email;
- $core->addBreadcrumb($customer->getUrl(), $customer->name);
- $address = $customer->getAddress();
- }
- else {
- $address = $location->getAddress();
- }
- $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" => $address
- ]);
- View::include("footer");
|