| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- $customer = Customer::get($id);
- if(!$customer) throw new Exception("Customer not found.");
- $page_title = "Edit Customer";
- Core::addScript("public/js/app-customer-form.js");
- Core::addBreadcrumb("/account", "Account");
- Core::addBreadcrumb("/account/customers", "Customers");
- Core::addBreadcrumb("/account/customers/$id", $customer->name);
- Core::addBreadcrumb("/account/customers/$id/edit", $page_title);
- $submit = http::value("submit");
- if($submit) {
- try {
- Core::validateCSRFToken($submit);
- $form_exception = new FormException();
- $customer->name = http::value("name", "trim");
- $customer->address_1 = http::value("address_1", "trim");
- $customer->address_2 = http::value("address_2", "trim");
- $customer->city = http::value("city", "trim");
- $customer->county = http::value("county", "trim");
- $customer->postal_code = http::value("postal_code", "trim");
- $customer->country = http::value("country", "trim");
- $customer->email = http::value("email", "email");
- $customer->phone = http::value("phone", "trim");
- $customer->invoice_contact_name = http::value("invoice_contact_name", "trim");
- $customer->email_after_test = http::value("email_after_test", "int");
- $customer->email_locations_after_test = http::value("email_locations_after_test", "int");
- $customer->year_cycle_month = http::value("year_cycle_month", "int");
- $customer->show_in_map_overview = (int) http::value("show_in_map_overview", "int");
- $customer->config_json = http::value("config_json", "trim");
- $cc_email_addresses = HTTP::value("cc_email_addresses", "trim");
- if($cc_email_addresses) {
- try {
- $customer->setCcEmailAddresses($cc_email_addresses);
- }
- catch(Exception $e) {
- $form_exception->addError($e->getMessage());
- }
- }
- if(empty($customer->name)) $form_exception->addError("Name is required.");
- if($form_exception->hasErrors()) throw $form_exception;
- $success = $customer->commit();
- Core::addAlert("success", "Customer updated successfully.");
- HTTP::redirect("/account/customers/$id/edit");
- }
- catch(FormException $e) {
- $e->generateAlerts();
- }
- catch(Exception $e) {
- Core::addAlert("danger", $e->getMessage());
- }
- }
- View::includeOnce("header", compact("page_title"));
- View::include("customer_form", compact("page_title", "customer"));
- View::includeOnce("footer");
|