38921-vm/templates.php
2026-03-01 22:53:30 +00:00

108 lines
4.7 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id']) || !isset($_SESSION['msp_id'])) {
header('Location: login.php');
exit;
}
require_once 'db/config.php';
$msp_id = $_SESSION['msp_id'];
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
if ($_POST['action'] === 'create_template') {
$name = $_POST['name'];
$description = $_POST['description'];
$stmt = db()->prepare("INSERT INTO onboarding_templates (msp_id, name, description) VALUES (?, ?, ?)");
$stmt->execute([$msp_id, $name, $description]);
$template_id = db()->lastInsertId();
header("Location: edit_template.php?id=$template_id");
exit;
}
}
$stmt = db()->prepare("SELECT * FROM onboarding_templates WHERE msp_id = ? ORDER BY created_at DESC");
$stmt->execute([$msp_id]);
$templates = $stmt->fetchAll();
include 'header.php';
?>
<div class="container py-5">
<div class="d-flex justify-content-between align-items-center mb-5">
<div>
<h1>Onboarding Templates</h1>
<p class="text-muted">Create multi-page onboarding flows for your customers.</p>
</div>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#createTemplateModal">
<i class="bi bi-plus-circle"></i> Create New Template
</button>
</div>
<div class="row g-4">
<?php foreach ($templates as $template): ?>
<div class="col-md-4">
<div class="card h-100 shadow-sm border-0 template-card">
<div class="card-body p-4">
<h4 class="fw-bold text-primary mb-2"><?php echo htmlspecialchars($template['name']); ?></h4>
<p class="text-muted small mb-4"><?php echo htmlspecialchars($template['description'] ?: 'No description provided.'); ?></p>
<?php
$stmt = db()->prepare("SELECT COUNT(*) FROM onboarding_template_steps WHERE template_id = ?");
$stmt->execute([$template['id']]);
$steps_count = $stmt->fetchColumn();
?>
<div class="d-flex justify-content-between align-items-center mt-auto">
<span class="badge bg-light text-dark border"><i class="bi bi-layers"></i> <?php echo $steps_count; ?> Steps</span>
<a href="edit_template.php?id=<?php echo $template['id']; ?>" class="btn btn-outline btn-sm">Manage Template</a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<?php if (empty($templates)): ?>
<div class="col-12 text-center py-5">
<div class="bg-light p-5 rounded-4 border">
<i class="bi bi-file-earmark-plus display-4 text-muted mb-3"></i>
<h3>No Templates Found</h3>
<p class="text-muted">You haven't created any onboarding templates yet. Click the button above to start.</p>
</div>
</div>
<?php endif; ?>
</div>
</div>
<!-- Create Template Modal -->
<div class="modal fade" id="createTemplateModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<form method="POST">
<div class="modal-header">
<h5 class="modal-title">New Onboarding Template</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<input type="hidden" name="action" value="create_template">
<div class="mb-3">
<label class="form-label">Template Name</label>
<input type="text" name="name" class="form-control" placeholder="e.g. Standard Customer Onboarding" required>
</div>
<div class="mb-3">
<label class="form-label">Description (Optional)</label>
<textarea name="description" class="form-control" rows="3" placeholder="Briefly describe what this template covers."></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Create & Continue</button>
</div>
</form>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<?php include 'footer.php'; ?>