| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- $customer = Customer::get($id);
- if(!$customer) throw new Exception("Customer not found.");
- $page_title = "Edit Customer";
- 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");
- 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");
- ?>
|