<?php
require_once __DIR__ . '/../includes/auth.php';
require_login();
$pageTitle = 'Test Preparation Programs';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'delete' && csrf_verify()) {
$id = (int) ($_POST['id'] ?? 0);
$find = db()->prepare('SELECT slug FROM test_preparations WHERE id = ?');
$find->execute([$id]);
if ($slug = $find->fetchColumn()) {
$stub = __DIR__ . '/../test-preparation-' . $slug . '.php';
if (is_file($stub)) @unlink($stub);
}
$stmt = db()->prepare('DELETE FROM test_preparations WHERE id = ?');
$stmt->execute([$id]);
flash_set('success', 'Program deleted.');
redirect('test_preparations.php');
}
$programs = db()->query('SELECT * FROM test_preparations ORDER BY sort_order ASC')->fetchAll();
require __DIR__ . '/partials/header.php';
require __DIR__ . '/partials/sidebar.php';
require __DIR__ . '/partials/topbar.php';
?>
<div class="flex items-center justify-between mb-5">
<p class="text-gray-500 text-sm"><?= count($programs) ?> programs</p>
<a href="program_form.php" class="bg-gradient-to-r from-brand-red to-brand-green text-white text-sm font-semibold px-5 py-2.5 rounded-xl hover:brightness-110 transition">
<i class="fa-solid fa-plus mr-1"></i> Add New Program
</a>
</div>
<div class="bg-white rounded-2xl shadow-sm overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead class="bg-gray-50"><tr class="text-left text-gray-400">
<th class="px-5 py-3 font-medium">Program</th>
<th class="px-5 py-3 font-medium">Duration</th>
<th class="px-5 py-3 font-medium">Fee</th>
<th class="px-5 py-3 font-medium">Status</th>
<th class="px-5 py-3 font-medium text-right">Actions</th>
</tr></thead>
<tbody>
<?php foreach ($programs as $p): ?>
<tr class="border-t border-gray-100 hover:bg-gray-50/60">
<td class="px-5 py-3 font-medium"><?= e($p['name']) ?></td>
<td class="px-5 py-3 text-gray-500"><?= e($p['duration']) ?></td>
<td class="px-5 py-3 text-gray-500"><?= e($p['fee']) ?></td>
<td class="px-5 py-3"><span class="px-2.5 py-1 rounded-full text-xs font-medium <?= $p['status'] === 'active' ? 'bg-brand-green/10 text-brand-green' : 'bg-gray-200 text-gray-500' ?>"><?= e(ucfirst($p['status'])) ?></span></td>
<td class="px-5 py-3 text-right whitespace-nowrap">
<a href="../test-preparation-<?= e($p['slug']) ?>.php" target="_blank" class="text-gray-400 hover:text-gray-600 mr-3"><i class="fa-solid fa-eye"></i></a>
<a href="program_form.php?id=<?= (int) $p['id'] ?>" class="text-brand-green hover:text-green-700 mr-3"><i class="fa-solid fa-pen-to-square"></i></a>
<form method="post" class="inline" onsubmit="return confirm('Delete this program?');">
<?= csrf_field() ?>
<input type="hidden" name="action" value="delete">
<input type="hidden" name="id" value="<?= (int) $p['id'] ?>">
<button type="submit" class="text-brand-red hover:text-red-700"><i class="fa-solid fa-trash"></i></button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php require __DIR__ . '/partials/footer.php'; ?>