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