id", "$customer->name Templates"); Core::addBreadcrumb($_SERVER["REQUEST_URI"], $page_title); $template = new Template; $template->customer_id = $customer->id; $template->json = ""; $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->json_file = http::value("json_file", "trim"); $template->practice = http::value("practice", "int"); if(empty($template->name)) $form_exception->addError("Name is required."); if(empty($template->json) && empty($template->json_file)) $form_exception->addError("JSON or JSON File is required."); if($template->json) { $json = json_decode($template->json); if(!$json) { $form_exception->addError("JSON error: " . json_last_error_msg()); } } if($template->json_file) { $path = ROOT_DIR . "/json/" . $template->json_file; if(!file_exists($path)) $form_exception->addError("JSON file does not exist."); } if($form_exception->hasErrors()) throw $form_exception; $success = $template->commit(); Core::addAlert("success", "Template added successfully."); HTTP::redirect("/account/templates?customer_id=$customer->id"); } 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");