1
0

customer_add.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  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->email_after_test = 1;
  9. $customer->email_locations_after_test = 1;
  10. $submit = http::value("submit");
  11. if($submit) {
  12. try {
  13. Core::validateCSRFToken($submit);
  14. $form_exception = new FormException;
  15. $customer->name = http::value("name", "trim");
  16. $customer->address_1 = http::value("address_1", "trim");
  17. $customer->address_2 = http::value("address_2", "trim");
  18. $customer->city = http::value("city", "trim");
  19. $customer->county = http::value("county", "trim");
  20. $customer->postal_code = http::value("postal_code", "trim");
  21. $customer->country = http::value("country", "trim");
  22. $customer->email = http::value("email", "email");
  23. $customer->phone = http::value("phone", "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. if(empty($customer->name)) $form_exception->addError("Name is required.");
  27. if($form_exception->hasErrors()) throw $form_exception;
  28. $success = $customer->commit();
  29. Core::addAlert("success", "Customer added successfully.");
  30. HTTP::redirect("/account/customers");
  31. }
  32. catch(FormException $e) {
  33. $e->generateAlerts();
  34. }
  35. catch(Exception $e) {
  36. Core::addAlert("danger", $e->getMessage());
  37. }
  38. }
  39. View::includeOnce("header", compact("page_title"));
  40. View::include("customer_form", compact("page_title", "customer"));
  41. View::includeOnce("footer");
  42. ?>