customer_add.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. $page_title = "Add Customer";
  3. Core::addBreadcrumb("/account", "Account");
  4. Core::addBreadcrumb("/account/customers", "Customers");
  5. Core::addBreadcrumb("/account/customers/add", $page_title);
  6. $customer = new Customer;
  7. $customer->country = DEFAULT_COUNTRY;
  8. $customer->show_in_map_overview = 1;
  9. $customer->email_after_test = 1;
  10. $customer->email_locations_after_test = 1;
  11. $submit = http::value("submit");
  12. if($submit) {
  13. try {
  14. Core::validateCSRFToken($submit);
  15. $form_exception = new FormException;
  16. $customer->name = http::value("name", "trim");
  17. $customer->address_1 = http::value("address_1", "trim");
  18. $customer->address_2 = http::value("address_2", "trim");
  19. $customer->city = http::value("city", "trim");
  20. $customer->county = http::value("county", "trim");
  21. $customer->postal_code = http::value("postal_code", "trim");
  22. $customer->country = http::value("country", "trim");
  23. $customer->email = http::value("email", "email");
  24. $customer->phone = http::value("phone", "trim");
  25. $customer->email_after_test = (int) http::value("email_after_test", "int");
  26. $customer->email_locations_after_test = (int) http::value("email_locations_after_test", "int");
  27. $customer->year_cycle_month = http::value("year_cycle_month", "int");
  28. $customer->show_in_map_overview = (int) http::value("show_in_map_overview", "int");
  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 added successfully.");
  33. HTTP::redirect("/account/customers");
  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");