prepare("SELECT * FROM onboarding_templates WHERE id = ? AND msp_id = ?"); $stmt->execute([$template_id, $msp_id]); $template = $stmt->fetch(); if (!$template) { header('Location: templates.php'); exit; } // Handle Form Submissions if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { if ($_POST['action'] === 'add_step') { $title = $_POST['title']; $description = $_POST['description']; $stmt = db()->prepare("SELECT MAX(order_index) FROM onboarding_template_steps WHERE template_id = ?"); $stmt->execute([$template_id]); $max_order = $stmt->fetchColumn() ?: 0; $stmt = db()->prepare("INSERT INTO onboarding_template_steps (template_id, title, description, order_index) VALUES (?, ?, ?, ?)"); $stmt->execute([$template_id, $title, $description, $max_order + 1]); header("Location: edit_template.php?id=$template_id"); exit; } if ($_POST['action'] === 'add_field') { $step_id = $_POST['step_id']; $type = $_POST['type']; $label = $_POST['label']; $content = $_POST['content'] ?? ''; $is_required = isset($_POST['is_required']) ? 1 : 0; $stmt = db()->prepare("SELECT MAX(order_index) FROM onboarding_template_fields WHERE step_id = ?"); $stmt->execute([$step_id]); $max_order = $stmt->fetchColumn() ?: 0; $stmt = db()->prepare("INSERT INTO onboarding_template_fields (step_id, type, label, content, is_required, order_index) VALUES (?, ?, ?, ?, ?, ?)"); $stmt->execute([$step_id, $type, $label, $content, $is_required, $max_order + 1]); header("Location: edit_template.php?id=$template_id"); exit; } if ($_POST['action'] === 'delete_step') { $step_id = $_POST['step_id']; $stmt = db()->prepare("DELETE FROM onboarding_template_steps WHERE id = ? AND template_id = ?"); $stmt->execute([$step_id, $template_id]); header("Location: edit_template.php?id=$template_id"); exit; } } // Fetch all steps and their fields $stmt = db()->prepare("SELECT * FROM onboarding_template_steps WHERE template_id = ? ORDER BY order_index ASC"); $stmt->execute([$template_id]); $steps = $stmt->fetchAll(); foreach ($steps as &$step) { $stmt = db()->prepare("SELECT * FROM onboarding_template_fields WHERE step_id = ? ORDER BY order_index ASC"); $stmt->execute([$step['id']]); $step['fields'] = $stmt->fetchAll(); } include 'header.php'; ?>
Start by adding a new page to your onboarding flow.