|
|
@@ -0,0 +1,47 @@
|
|
|
+<?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->email = http::value("email", "email");
|
|
|
+ $customer->phone = http::value("phone", "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");
|
|
|
+
|
|
|
+?>
|