509318396
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php
declare(strict_types=1);
require __DIR__ . '/auth.php';
requireLogin();
require dirname(__DIR__) . '/db.php';
$page = max(1, (int)($_GET['page'] ?? 1));
$perPage = 50;
$total = (int)db()->query('SELECT COUNT(*) FROM leads')->fetchColumn();
$pages = max(1, (int)ceil($total / $perPage));
$page = min($page, $pages);
$offset = ($page - 1) * $perPage;
$statement = db()->prepare('SELECT id, full_name, company, phone, email, city, vehicle, fleet_requirement, created_at FROM leads ORDER BY created_at DESC, id DESC LIMIT :limit OFFSET :offset');
$statement->bindValue(':limit', $perPage, PDO::PARAM_INT);
$statement->bindValue(':offset', $offset, PDO::PARAM_INT);
$statement->execute();
$leads = $statement->fetchAll();
function e(?string $value): string { return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); }
?>
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Lead Submissions</title><link rel="stylesheet" href="admin.css"></head><body><header><div><h1>Lead submissions</h1><p><?= number_format($total) ?> total leads</p></div><nav><form action="export.php" method="post"><input type="hidden" name="csrf" value="<?= e(csrfToken()) ?>"><button>Download CSV</button></form><a href="logout.php">Sign out</a></nav></header><main class="table-wrap"><table><thead><tr><th>Date</th><th>Name</th><th>Company</th><th>Phone</th><th>Email</th><th>City</th><th>Vehicle</th><th>Requirement</th></tr></thead><tbody><?php if (!$leads): ?><tr><td colspan="8" class="empty">No leads submitted yet.</td></tr><?php endif; ?><?php foreach ($leads as $lead): ?><tr><td><?= e($lead['created_at']) ?></td><td><?= e($lead['full_name']) ?></td><td><?= e($lead['company']) ?></td><td dir="ltr"><?= e($lead['phone']) ?></td><td><?= e($lead['email']) ?></td><td><?= e($lead['city']) ?></td><td><?= e($lead['vehicle']) ?></td><td class="requirement"><?= e($lead['fleet_requirement']) ?></td></tr><?php endforeach; ?></tbody></table></main><?php if ($pages > 1): ?><footer class="pagination"><span>Page <?= $page ?> of <?= $pages ?></span><div><?php if ($page > 1): ?><a href="?page=<?= $page - 1 ?>">Previous</a><?php endif; ?><?php if ($page < $pages): ?><a href="?page=<?= $page + 1 ?>">Next</a><?php endif; ?></div></footer><?php endif; ?></body></html>
