129 lines
7.2 KiB
PHP
129 lines
7.2 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
$customer_id = $_GET['id'] ?? null;
|
|
$step_index = (int)($_GET['step'] ?? 0);
|
|
|
|
if (!$customer_id) {
|
|
die("Invalid access.");
|
|
}
|
|
|
|
$stmt = db()->prepare("SELECT c.*, m.name as msp_name FROM customers c JOIN msps m ON c.msp_id = m.id WHERE c.id = ?");
|
|
$stmt->execute([$customer_id]);
|
|
$customer = $stmt->fetch();
|
|
|
|
if (!$customer || !$customer['template_id']) {
|
|
die("No onboarding template assigned to this customer.");
|
|
}
|
|
|
|
// Fetch steps
|
|
$stmt = db()->prepare("SELECT * FROM onboarding_template_steps WHERE template_id = ? ORDER BY order_index ASC");
|
|
$stmt->execute([$customer['template_id']]);
|
|
$steps = $stmt->fetchAll();
|
|
|
|
if (empty($steps)) {
|
|
die("This onboarding flow has no steps.");
|
|
}
|
|
|
|
$current_step = $steps[$step_index] ?? null;
|
|
if (!$current_step) {
|
|
$step_index = 0;
|
|
$current_step = $steps[0];
|
|
}
|
|
|
|
// Fetch fields for current step
|
|
$stmt = db()->prepare("SELECT * FROM onboarding_template_fields WHERE step_id = ? ORDER BY order_index ASC");
|
|
$stmt->execute([$current_step['id']]);
|
|
$fields = $stmt->fetchAll();
|
|
|
|
$is_last_step = ($step_index === count($steps) - 1);
|
|
|
|
include 'header.php'; // We use the same header for simplicity, but we could make a "customer header"
|
|
?>
|
|
|
|
<div class="container py-5 mt-4">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-9">
|
|
<div class="text-center mb-5">
|
|
<h6 class="text-primary fw-bold text-uppercase mb-2">Welcome to <?php echo htmlspecialchars($customer['msp_name']); ?></h6>
|
|
<h1>Customer Onboarding</h1>
|
|
<div class="d-flex justify-content-center mt-4">
|
|
<?php foreach ($steps as $idx => $step): ?>
|
|
<div class="px-2">
|
|
<div class="rounded-pill <?php echo $idx === $step_index ? 'bg-primary' : ($idx < $step_index ? 'bg-success' : 'bg-light'); ?>" style="width: 40px; height: 10px;"></div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card shadow border-0 overflow-hidden">
|
|
<div class="card-body p-5">
|
|
<h2 class="fw-bold mb-3"><?php echo htmlspecialchars($current_step['title']); ?></h2>
|
|
<p class="text-muted mb-5 lead"><?php echo nl2br(htmlspecialchars($current_step['description'])); ?></p>
|
|
|
|
<form method="POST" action="customer_view.php?id=<?php echo $customer_id; ?>&step=<?php echo $step_index + 1; ?>">
|
|
<div class="row g-4">
|
|
<?php foreach ($fields as $field): ?>
|
|
<div class="col-12">
|
|
<?php if ($field['type'] === 'text'): ?>
|
|
<div class="p-4 bg-light rounded-3 mb-3">
|
|
<?php echo nl2br($field['content']); ?>
|
|
</div>
|
|
<?php elseif ($field['type'] === 'form_input'): ?>
|
|
<label class="form-label fw-bold"><?php echo htmlspecialchars($field['label']); ?><?php echo $field['is_required'] ? ' <span class="text-danger">*</span>' : ''; ?></label>
|
|
<input type="text" class="form-control form-control-lg" <?php echo $field['is_required'] ? 'required' : ''; ?>>
|
|
<?php elseif ($field['type'] === 'form_textarea'): ?>
|
|
<label class="form-label fw-bold"><?php echo htmlspecialchars($field['label']); ?><?php echo $field['is_required'] ? ' <span class="text-danger">*</span>' : ''; ?></label>
|
|
<textarea class="form-control" rows="4" <?php echo $field['is_required'] ? 'required' : ''; ?>></textarea>
|
|
<?php elseif ($field['type'] === 'form_select'): ?>
|
|
<label class="form-label fw-bold"><?php echo htmlspecialchars($field['label']); ?><?php echo $field['is_required'] ? ' <span class="text-danger">*</span>' : ''; ?></label>
|
|
<select class="form-select form-select-lg" <?php echo $field['is_required'] ? 'required' : ''; ?>>
|
|
<option value="">Select an option...</option>
|
|
<?php foreach (explode(',', $field['content']) as $opt): ?>
|
|
<option value="<?php echo trim($opt); ?>"><?php echo trim($opt); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<?php elseif ($field['type'] === 'download'): ?>
|
|
<div class="d-flex align-items-center p-3 border rounded-3 bg-light">
|
|
<i class="bi bi-file-earmark-pdf display-6 text-danger me-3"></i>
|
|
<div class="flex-grow-1">
|
|
<div class="fw-bold"><?php echo htmlspecialchars($field['label']); ?></div>
|
|
<small class="text-muted">Please download and review this document.</small>
|
|
</div>
|
|
<a href="<?php echo htmlspecialchars($field['content']); ?>" target="_blank" class="btn btn-primary btn-sm"><i class="bi bi-download"></i> Download</a>
|
|
</div>
|
|
<?php elseif ($field['type'] === 'upload'): ?>
|
|
<label class="form-label fw-bold"><?php echo htmlspecialchars($field['label']); ?><?php echo $field['is_required'] ? ' <span class="text-danger">*</span>' : ''; ?></label>
|
|
<input type="file" class="form-control" <?php echo $field['is_required'] ? 'required' : ''; ?>>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<div class="mt-5 d-flex justify-content-between">
|
|
<?php if ($step_index > 0): ?>
|
|
<a href="customer_view.php?id=<?php echo $customer_id; ?>&step=<?php echo $step_index - 1; ?>" class="btn btn-outline-secondary btn-lg px-5">Back</a>
|
|
<?php else: ?>
|
|
<div></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($is_last_step): ?>
|
|
<button type="submit" class="btn btn-success btn-lg px-5 fw-bold">Finish Onboarding</button>
|
|
<?php else: ?>
|
|
<button type="submit" class="btn btn-primary btn-lg px-5 fw-bold">Next Step</button>
|
|
<?php endif; ?>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
body { background-color: #f8fafc; }
|
|
.card { border-radius: 1rem; }
|
|
</style>
|
|
|
|
<?php include 'footer.php'; ?>
|