getCustomer(); $page_title = "Edit Template"; Core::addBreadcrumb("/account", "Account"); Core::addBreadcrumb("/account/templates", "Templates"); Core::addBreadcrumb("/account/templates?customer_id=$customer->id", "$customer->name Templates"); Core::addBreadcrumb("/account/templates/$id", $template->name); Core::addBreadcrumb($_SERVER["REQUEST_URI"], $page_title); $submit = http::value("submit"); if($submit) { try { Core::validateCSRFToken($submit); $form_exception = new FormException; $template->name = http::value("name", "trim"); $template->json = http::value("json", "trim"); $template->practice = http::value("practice", "int"); if(empty($template->name)) $form_exception->addError("Name is required."); if(empty($template->json)) $form_exception->addError("JSON is required."); $json = json_decode($template->json); if(!$json) { $form_exception->addError("JSON error: " . json_last_error_msg()); } if($form_exception->hasErrors()) throw $form_exception; $success = $template->commit(); Core::addAlert("success", "Template updated successfully."); HTTP::redirect("/account/templates/$id/edit"); } catch(FormException $e) { $e->generateAlerts(); } catch(Exception $e) { Core::addAlert("danger", $e->getMessage()); } } View::includeOnce("header", compact("page_title")); View::include("template_form", compact("page_title", "template")); View::includeOnce("footer"); ?>