<?php
$pageTitle = 'Database Backups';
require_once __DIR__ . '/../../app/includes/header.php';
require_admin();
require_once __DIR__ . '/../../app/services/DatabaseBackupService.php';
$backups = DatabaseBackupService::list();
?>
<div class="page-head"><div><h1>Database Backups</h1><p>Create and download secure database backups.</p></div><form method="post" action="<?= APP_BASE ?>/backups/create.php"><?= csrf_field() ?><button class="btn btn-primary" type="submit"><i class="bi bi-database-add me-1"></i>Create New Backup</button></form></div>
<div class="card app-card"><div class="table-responsive"><table class="table align-middle mb-0">
<thead><tr><th>SL</th><th>Backup File</th><th>Size</th><th>Created At</th><th>Action</th></tr></thead><tbody>
<?php foreach ($backups as $i => $backup): ?><tr><td><?= $i + 1 ?></td><td><?= e($backup['name']) ?></td><td><?= e(format_bytes((int)$backup['size'])) ?></td><td><?= e($backup['created_at']) ?></td><td><a class="btn btn-sm btn-outline-primary" href="<?= APP_BASE ?>/backups/download.php?file=<?= urlencode($backup['name']) ?>"><i class="bi bi-download me-1"></i>Download</a> <form class="d-inline" method="post" action="<?= APP_BASE ?>/backups/delete.php" onsubmit="return confirm('Delete this backup?')"><?= csrf_field() ?><input type="hidden" name="file" value="<?= e($backup['name']) ?>"><button class="btn btn-sm btn-outline-danger" type="submit"><i class="bi bi-trash me-1"></i>Delete</button></form></td></tr><?php endforeach; ?>
<?php if (!$backups): ?><tr><td colspan="5" class="text-center text-muted py-4">No backups found.</td></tr><?php endif; ?>
</tbody></table></div></div>
<?php require_once __DIR__ . '/../../app/includes/footer.php'; ?>
