customer_edit.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. $customer = Customer::get($id);
  3. if(!$customer) throw new Exception("Customer not found.");
  4. $page_title = "Edit Customer";
  5. Core::addBreadcrumb("/account", "Account");
  6. Core::addBreadcrumb("/account/customers", "Customers");
  7. Core::addBreadcrumb("/account/customers/$id", $customer->name);
  8. Core::addBreadcrumb("/account/customers/$id/edit", $page_title);
  9. $submit = http::value("submit");
  10. if($submit) {
  11. try {
  12. Core::validateCSRFToken($submit);
  13. $form_exception = new FormException;
  14. $customer->name = http::value("name", "trim");
  15. $customer->address_1 = http::value("address_1", "trim");
  16. $customer->address_2 = http::value("address_2", "trim");
  17. $customer->city = http::value("city", "trim");
  18. $customer->county = http::value("county", "trim");
  19. $customer->postal_code = http::value("postal_code", "trim");
  20. $customer->country = http::value("country", "trim");
  21. $customer->email = http::value("email", "email");
  22. $customer->phone = http::value("phone", "trim");
  23. $customer->invoice_contact_name = http::value("invoice_contact_name", "trim");
  24. $customer->email_after_test = http::value("email_after_test", "int");
  25. $customer->email_locations_after_test = http::value("email_locations_after_test", "int");
  26. $customer->year_cycle_month = http::value("year_cycle_month", "int");
  27. $customer->show_in_map_overview = (int) http::value("show_in_map_overview", "int");
  28. $customer->config_json = http::value("config_json", "trim");
  29. if(empty($customer->name)) $form_exception->addError("Name is required.");
  30. if($form_exception->hasErrors()) throw $form_exception;
  31. $success = $customer->commit();
  32. Core::addAlert("success", "Customer updated successfully.");
  33. HTTP::redirect("/account/customers/$id/edit");
  34. }
  35. catch(FormException $e) {
  36. $e->generateAlerts();
  37. }
  38. catch(Exception $e) {
  39. Core::addAlert("danger", $e->getMessage());
  40. }
  41. }
  42. View::includeOnce("header", compact("page_title"));
  43. View::include("customer_form", compact("page_title", "customer"));
  44. View::includeOnce("footer");