11
This commit is contained in:
parent
7e5d56a6cf
commit
1a06383009
577
admin.php
577
admin.php
@ -1,53 +1,136 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once 'db/config.php'; // Assuming you have a db connection setup
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Check if user is admin
|
||||
if (!isset($_SESSION['user']) || $_SESSION['user'] !== 'admin') {
|
||||
// If not admin, redirect to login page
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check for messages
|
||||
function format_admin_datetime(?string $value): string {
|
||||
if (!$value) {
|
||||
return '—';
|
||||
}
|
||||
|
||||
try {
|
||||
return (new DateTime($value))->format('M j, Y • g:i A');
|
||||
} catch (Exception $e) {
|
||||
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
}
|
||||
|
||||
function bind_named_values(PDOStatement $stmt, array $params): void {
|
||||
foreach ($params as $name => $value) {
|
||||
$stmt->bindValue($name, $value, is_int($value) ? PDO::PARAM_INT : PDO::PARAM_STR);
|
||||
}
|
||||
}
|
||||
|
||||
$message = '';
|
||||
if (isset($_SESSION['message'])) {
|
||||
$message = $_SESSION['message'];
|
||||
$message = (string) $_SESSION['message'];
|
||||
unset($_SESSION['message']);
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
$records_per_page = 15;
|
||||
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? max(1, (int) $_GET['page']) : 1;
|
||||
$selected_webinar_id = isset($_GET['webinar_id']) && is_numeric($_GET['webinar_id']) ? max(0, (int) $_GET['webinar_id']) : 0;
|
||||
|
||||
// Pagination settings
|
||||
$records_per_page = 10;
|
||||
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int)$_GET['page'] : 1;
|
||||
$webinars = $pdo->query('SELECT id, title, scheduled_at FROM webinars ORDER BY scheduled_at DESC, id DESC')->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$where_parts = ['a.deleted_at IS NULL'];
|
||||
$params = [];
|
||||
if ($selected_webinar_id > 0) {
|
||||
$where_parts[] = 'a.webinar_id = :webinar_id';
|
||||
$params[':webinar_id'] = $selected_webinar_id;
|
||||
}
|
||||
$where_sql = 'WHERE ' . implode(' AND ', $where_parts);
|
||||
|
||||
$count_stmt = $pdo->prepare("SELECT COUNT(*) FROM attendees a {$where_sql}");
|
||||
bind_named_values($count_stmt, $params);
|
||||
$count_stmt->execute();
|
||||
$total_records = (int) $count_stmt->fetchColumn();
|
||||
|
||||
$total_pages = max(1, (int) ceil($total_records / $records_per_page));
|
||||
if ($page > $total_pages) {
|
||||
$page = $total_pages;
|
||||
}
|
||||
$offset = ($page - 1) * $records_per_page;
|
||||
|
||||
// Get total number of records
|
||||
$total_stmt = $pdo->query("SELECT COUNT(*) FROM attendees");
|
||||
$total_records = $total_stmt->fetchColumn();
|
||||
$total_pages = ceil($total_records / $records_per_page);
|
||||
$today_stmt = $pdo->prepare("SELECT COUNT(*) FROM attendees a {$where_sql} AND DATE(a.created_at) = CURDATE()");
|
||||
bind_named_values($today_stmt, $params);
|
||||
$today_stmt->execute();
|
||||
$today_count = (int) $today_stmt->fetchColumn();
|
||||
|
||||
// Get records for the current page
|
||||
$stmt = $pdo->prepare("SELECT id, first_name, last_name, email, created_at, how_did_you_hear, company FROM attendees ORDER BY first_name ASC, last_name ASC LIMIT :limit OFFSET :offset");
|
||||
$stmt->bindValue(':limit', $records_per_page, PDO::PARAM_INT);
|
||||
$stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$attendees = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$last7_stmt = $pdo->prepare("SELECT COUNT(*) FROM attendees a {$where_sql} AND a.created_at >= (NOW() - INTERVAL 7 DAY)");
|
||||
bind_named_values($last7_stmt, $params);
|
||||
$last7_stmt->execute();
|
||||
$last_7_days_count = (int) $last7_stmt->fetchColumn();
|
||||
|
||||
// Get data for the chart
|
||||
$chart_stmt = $pdo->query("SELECT DATE(created_at) as registration_day, COUNT(*) as user_count FROM attendees GROUP BY registration_day ORDER BY registration_day");
|
||||
$latest_stmt = $pdo->prepare("SELECT MAX(a.created_at) FROM attendees a {$where_sql}");
|
||||
bind_named_values($latest_stmt, $params);
|
||||
$latest_stmt->execute();
|
||||
$latest_registration_at = $latest_stmt->fetchColumn();
|
||||
|
||||
$company_stmt = $pdo->prepare("SELECT COUNT(DISTINCT NULLIF(TRIM(a.company), '')) FROM attendees a {$where_sql}");
|
||||
bind_named_values($company_stmt, $params);
|
||||
$company_stmt->execute();
|
||||
$unique_companies = (int) $company_stmt->fetchColumn();
|
||||
|
||||
$attendees_sql = "SELECT
|
||||
a.id,
|
||||
a.webinar_id,
|
||||
a.first_name,
|
||||
a.last_name,
|
||||
a.email,
|
||||
a.company,
|
||||
a.how_did_you_hear,
|
||||
a.timezone,
|
||||
a.consented,
|
||||
a.created_at,
|
||||
w.title AS webinar_title,
|
||||
w.scheduled_at AS webinar_scheduled_at
|
||||
FROM attendees a
|
||||
LEFT JOIN webinars w ON w.id = a.webinar_id
|
||||
{$where_sql}
|
||||
ORDER BY a.created_at DESC, a.id DESC
|
||||
LIMIT :limit OFFSET :offset";
|
||||
$attendees_stmt = $pdo->prepare($attendees_sql);
|
||||
bind_named_values($attendees_stmt, $params);
|
||||
$attendees_stmt->bindValue(':limit', $records_per_page, PDO::PARAM_INT);
|
||||
$attendees_stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
|
||||
$attendees_stmt->execute();
|
||||
$attendees = $attendees_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$chart_stmt = $pdo->prepare("SELECT DATE(a.created_at) AS registration_day, COUNT(*) AS user_count
|
||||
FROM attendees a
|
||||
{$where_sql}
|
||||
GROUP BY DATE(a.created_at)
|
||||
ORDER BY DATE(a.created_at)");
|
||||
bind_named_values($chart_stmt, $params);
|
||||
$chart_stmt->execute();
|
||||
$chart_data = $chart_stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$selected_webinar = null;
|
||||
foreach ($webinars as $webinar) {
|
||||
if ((int) $webinar['id'] === $selected_webinar_id) {
|
||||
$selected_webinar = $webinar;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$chart_labels = json_encode(array_column($chart_data, 'registration_day'));
|
||||
$chart_values = json_encode(array_column($chart_data, 'user_count'));
|
||||
|
||||
$export_link = 'export_csv.php' . ($selected_webinar_id > 0 ? '?webinar_id=' . urlencode((string) $selected_webinar_id) : '');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Admin Dashboard</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin Dashboard | Webinar Registrations</title>
|
||||
<meta name="description" content="Admin dashboard for webinar registrations, attendee management, CSV exports, and daily registration charts.">
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
@ -65,7 +148,6 @@ $chart_values = json_encode(array_column($chart_data, 'user_count'));
|
||||
--text-muted: #97acd0;
|
||||
--accent: #2c4bd1;
|
||||
--accent-strong: #1029a0;
|
||||
--accent-soft: #bbc8fb;
|
||||
--success: #18d1b3;
|
||||
--danger: #ff6b81;
|
||||
--font-body: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
@ -82,39 +164,36 @@ $chart_values = json_encode(array_column($chart_data, 'user_count'));
|
||||
color: var(--text-main);
|
||||
}
|
||||
.admin-shell {
|
||||
max-width: 1220px;
|
||||
max-width: 1380px;
|
||||
padding-top: 40px;
|
||||
padding-bottom: 40px;
|
||||
}
|
||||
h2, h3, .h5, p, label, th, td {
|
||||
color: var(--text-main);
|
||||
}
|
||||
h2, h3, .h5, th, .btn, .page-link {
|
||||
h1, h2, h3, .h5, .btn, .page-link, th, label {
|
||||
font-family: var(--font-display);
|
||||
}
|
||||
h2 {
|
||||
font-size: 2rem;
|
||||
h1 {
|
||||
font-size: 2.2rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.03em;
|
||||
letter-spacing: -0.04em;
|
||||
margin-bottom: 0.35rem;
|
||||
}
|
||||
h3, .h5 {
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
p.text-muted, .text-muted {
|
||||
.lead-copy,
|
||||
.text-muted {
|
||||
color: var(--text-muted) !important;
|
||||
}
|
||||
.panel-card,
|
||||
.table-shell {
|
||||
.table-shell,
|
||||
.summary-card,
|
||||
.toolbar-card {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 22px;
|
||||
box-shadow: 0 25px 60px rgba(3, 11, 25, 0.38);
|
||||
backdrop-filter: blur(16px);
|
||||
}
|
||||
.panel-card {
|
||||
margin-top: 1.5rem;
|
||||
.panel-card,
|
||||
.summary-card,
|
||||
.toolbar-card {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
.table-shell {
|
||||
@ -122,153 +201,275 @@ $chart_values = json_encode(array_column($chart_data, 'user_count'));
|
||||
padding: 0.35rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
.alert-info {
|
||||
background: rgba(34, 199, 255, 0.12);
|
||||
color: var(--text-main);
|
||||
border: 1px solid rgba(34, 199, 255, 0.28);
|
||||
.summary-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||
gap: 1rem;
|
||||
margin-top: 1.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
.btn,
|
||||
.page-link {
|
||||
.summary-label {
|
||||
color: var(--text-soft);
|
||||
font-size: 0.9rem;
|
||||
margin-bottom: 0.45rem;
|
||||
}
|
||||
.summary-value {
|
||||
font-size: 2rem;
|
||||
font-weight: 800;
|
||||
line-height: 1;
|
||||
}
|
||||
.summary-meta {
|
||||
margin-top: 0.6rem;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.toolbar-card {
|
||||
display: flex;
|
||||
align-items: end;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
.filter-form {
|
||||
display: flex;
|
||||
align-items: end;
|
||||
gap: 0.75rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.form-select,
|
||||
.form-control {
|
||||
min-width: 260px;
|
||||
background: rgba(221, 226, 253, 0.08);
|
||||
border-color: rgba(221, 226, 253, 0.18);
|
||||
color: var(--text-main);
|
||||
}
|
||||
.form-select:focus,
|
||||
.form-control:focus {
|
||||
background: rgba(221, 226, 253, 0.10);
|
||||
color: var(--text-main);
|
||||
border-color: rgba(44, 75, 209, 0.65);
|
||||
box-shadow: 0 0 0 0.2rem rgba(187, 200, 251, 0.18);
|
||||
}
|
||||
.table {
|
||||
--bs-table-bg: transparent;
|
||||
--bs-table-color: var(--text-main);
|
||||
--bs-table-striped-bg: rgba(255, 255, 255, 0.03);
|
||||
--bs-table-striped-color: var(--text-main);
|
||||
--bs-table-border-color: rgba(221, 226, 253, 0.12);
|
||||
margin-bottom: 0;
|
||||
}
|
||||
th {
|
||||
color: var(--text-soft);
|
||||
font-size: 0.85rem;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
white-space: nowrap;
|
||||
}
|
||||
td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
.tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0.32rem 0.7rem;
|
||||
border-radius: 999px;
|
||||
background: rgba(34, 199, 255, 0.14);
|
||||
color: var(--text-main);
|
||||
font-size: 0.84rem;
|
||||
border: 1px solid rgba(34, 199, 255, 0.18);
|
||||
}
|
||||
.attendee-name {
|
||||
font-weight: 700;
|
||||
}
|
||||
.attendee-meta,
|
||||
.webinar-meta {
|
||||
display: block;
|
||||
margin-top: 0.25rem;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.86rem;
|
||||
}
|
||||
.btn {
|
||||
border-radius: 14px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.02em;
|
||||
transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
|
||||
}
|
||||
.btn:hover,
|
||||
.page-link:hover {
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
.btn-outline-primary {
|
||||
color: var(--accent-soft, #bbc8fb);
|
||||
border-color: rgba(34, 199, 255, 0.35);
|
||||
background: rgba(221, 226, 253, 0.06);
|
||||
box-shadow: none;
|
||||
}
|
||||
.btn-outline-primary:hover {
|
||||
background: rgba(187, 200, 251, 0.18);
|
||||
border-color: rgba(34, 199, 255, 0.55);
|
||||
box-shadow: var(--button-shadow);
|
||||
}
|
||||
.btn-success,
|
||||
.btn-primary {
|
||||
background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
|
||||
border: 1px solid rgba(221, 226, 253, 0.12);
|
||||
border: 1px solid rgba(221, 226, 253, 0.14);
|
||||
box-shadow: var(--button-shadow);
|
||||
}
|
||||
.btn-success:hover,
|
||||
.btn-primary:hover {
|
||||
background: linear-gradient(135deg, #bbc8fb 0%, #2c4bd1 100%);
|
||||
box-shadow: 0 20px 34px rgba(11, 32, 131, 0.32);
|
||||
.btn-success {
|
||||
background: linear-gradient(135deg, #18d1b3 0%, #0b8f7a 100%);
|
||||
border-color: transparent;
|
||||
box-shadow: 0 16px 30px rgba(24, 209, 179, 0.18);
|
||||
}
|
||||
.btn-danger {
|
||||
background: linear-gradient(135deg, #ff7a8b 0%, #f04f74 100%);
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
box-shadow: 0 16px 30px rgba(72, 18, 36, 0.28);
|
||||
.btn-outline-light {
|
||||
border-color: rgba(221, 226, 253, 0.28);
|
||||
}
|
||||
.table {
|
||||
margin-bottom: 0;
|
||||
--bs-table-bg: transparent;
|
||||
--bs-table-striped-bg: rgba(221, 226, 253, 0.06);
|
||||
--bs-table-striped-color: var(--text-main);
|
||||
--bs-table-hover-bg: rgba(187, 200, 251, 0.12);
|
||||
--bs-table-hover-color: var(--text-main);
|
||||
.pagination .page-link {
|
||||
color: var(--text-main);
|
||||
background: rgba(221, 226, 253, 0.05);
|
||||
border-color: rgba(221, 226, 253, 0.14);
|
||||
}
|
||||
.table thead th {
|
||||
border-bottom-color: rgba(221, 226, 253, 0.18);
|
||||
color: var(--accent-soft);
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.08em;
|
||||
font-size: 0.78rem;
|
||||
background: rgba(255, 255, 255, 0.02);
|
||||
}
|
||||
.table td,
|
||||
.table th {
|
||||
border-color: rgba(143, 232, 255, 0.08);
|
||||
vertical-align: middle;
|
||||
}
|
||||
.page-link {
|
||||
background: rgba(255, 255, 255, 0.04);
|
||||
color: var(--text-main);
|
||||
border-color: rgba(143, 232, 255, 0.12);
|
||||
box-shadow: none;
|
||||
}
|
||||
.page-item.active .page-link {
|
||||
background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
|
||||
.pagination .page-item.active .page-link {
|
||||
background: var(--accent);
|
||||
border-color: transparent;
|
||||
}
|
||||
.page-link:hover {
|
||||
color: var(--text-main);
|
||||
background: rgba(34, 199, 255, 0.12);
|
||||
border-color: rgba(34, 199, 255, 0.24);
|
||||
.alert {
|
||||
border-radius: 16px;
|
||||
margin-top: 1.2rem;
|
||||
}
|
||||
canvas {
|
||||
filter: drop-shadow(0 10px 25px rgba(34, 199, 255, 0.08));
|
||||
code {
|
||||
color: var(--accent-soft, #bbc8fb);
|
||||
}
|
||||
@media (max-width: 991px) {
|
||||
.admin-shell {
|
||||
padding-top: 24px;
|
||||
}
|
||||
.summary-value {
|
||||
font-size: 1.7rem;
|
||||
}
|
||||
.form-select,
|
||||
.form-control {
|
||||
min-width: 210px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container admin-shell">
|
||||
<h2>Admin Dashboard</h2>
|
||||
<p>Welcome, <?php echo htmlspecialchars($_SESSION['user'] ?? 'Admin'); ?>!</p>
|
||||
<main class="container admin-shell">
|
||||
<header>
|
||||
<h1>Webinar registrations dashboard</h1>
|
||||
<p class="lead-copy mb-0">Welcome, <?php echo htmlspecialchars($_SESSION['user'] ?? 'Admin'); ?>. Review attendee data, edit registrations, export CSV, and monitor daily signup volume.</p>
|
||||
</header>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<div class="alert alert-info">
|
||||
<?php echo htmlspecialchars($message); ?>
|
||||
</div>
|
||||
<div class="alert alert-info"><?php echo htmlspecialchars($message); ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="panel-card">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h3 class="h5 mb-0">Daily Registrations</h3>
|
||||
<button id="downloadChartBtn" class="btn btn-sm btn-outline-primary">Save as Image</button>
|
||||
<section class="toolbar-card" aria-label="Dashboard filters and actions">
|
||||
<form class="filter-form" method="GET" action="admin.php">
|
||||
<div>
|
||||
<label for="webinar_id" class="form-label mb-2">Webinar filter</label>
|
||||
<select class="form-select" id="webinar_id" name="webinar_id">
|
||||
<option value="0">All webinars</option>
|
||||
<?php foreach ($webinars as $webinar): ?>
|
||||
<option value="<?php echo (int) $webinar['id']; ?>" <?php echo (int) $webinar['id'] === $selected_webinar_id ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars($webinar['title']); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="d-flex gap-2 flex-wrap">
|
||||
<button type="submit" class="btn btn-primary">Apply filter</button>
|
||||
<a href="admin.php" class="btn btn-outline-light">Reset</a>
|
||||
</div>
|
||||
</form>
|
||||
<div class="d-flex gap-2 flex-wrap">
|
||||
<a href="<?php echo htmlspecialchars($export_link); ?>" class="btn btn-success">Download CSV</a>
|
||||
</div>
|
||||
<div style="max-width: 600px; margin: auto;">
|
||||
</section>
|
||||
|
||||
<section class="summary-grid" aria-label="Registration summary">
|
||||
<article class="summary-card">
|
||||
<div class="summary-label">Total registrations</div>
|
||||
<div class="summary-value"><?php echo number_format($total_records); ?></div>
|
||||
<div class="summary-meta">Active attendees<?php echo $selected_webinar ? ' for the selected webinar' : ' across all webinars'; ?>.</div>
|
||||
</article>
|
||||
<article class="summary-card">
|
||||
<div class="summary-label">Registered today</div>
|
||||
<div class="summary-value"><?php echo number_format($today_count); ?></div>
|
||||
<div class="summary-meta">New signups recorded on <?php echo (new DateTime())->format('M j, Y'); ?>.</div>
|
||||
</article>
|
||||
<article class="summary-card">
|
||||
<div class="summary-label">Last 7 days</div>
|
||||
<div class="summary-value"><?php echo number_format($last_7_days_count); ?></div>
|
||||
<div class="summary-meta">Rolling weekly registrations based on <code>created_at</code>.</div>
|
||||
</article>
|
||||
<article class="summary-card">
|
||||
<div class="summary-label">Companies represented</div>
|
||||
<div class="summary-value"><?php echo number_format($unique_companies); ?></div>
|
||||
<div class="summary-meta">Unique non-empty company names among active attendees.</div>
|
||||
</article>
|
||||
<article class="summary-card">
|
||||
<div class="summary-label">Latest registration</div>
|
||||
<div class="summary-value" style="font-size: 1.15rem; line-height: 1.35;"><?php echo htmlspecialchars(format_admin_datetime($latest_registration_at)); ?></div>
|
||||
<div class="summary-meta">Most recent active attendee creation timestamp.</div>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section class="panel-card" aria-labelledby="daily-registrations-title">
|
||||
<div class="d-flex justify-content-between align-items-center mb-3 flex-wrap gap-2">
|
||||
<div>
|
||||
<h2 id="daily-registrations-title" class="h5 mb-1">Daily registrations</h2>
|
||||
<p class="text-muted mb-0">Chart based on attendee <code>created_at</code>, grouped by registration day<?php echo $selected_webinar ? ' for the selected webinar' : ''; ?>.</p>
|
||||
</div>
|
||||
<button id="downloadChartBtn" class="btn btn-sm btn-primary" type="button">Save as Image</button>
|
||||
</div>
|
||||
<div style="max-width: 840px; margin: auto;">
|
||||
<canvas id="registrationsChart"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<h3 class="mt-4">Registered Attendees</h3>
|
||||
<a href="export_csv.php" class="btn btn-success">Download CSV</a>
|
||||
</div>
|
||||
<section class="toolbar-card" aria-labelledby="registered-attendees-title">
|
||||
<div>
|
||||
<h2 id="registered-attendees-title" class="h5 mb-1">Registered attendees</h2>
|
||||
<p class="text-muted mb-0">
|
||||
<?php if ($selected_webinar): ?>
|
||||
Showing active records for <strong><?php echo htmlspecialchars($selected_webinar['title']); ?></strong>.
|
||||
<?php else: ?>
|
||||
Showing active records for all webinars, newest registrations first.
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="table-responsive table-shell">
|
||||
<table class="table table-striped">
|
||||
<table class="table table-striped align-middle">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>First Name</th>
|
||||
<th>Last Name</th>
|
||||
<th>Attendee</th>
|
||||
<th>Email</th>
|
||||
<th>Source</th>
|
||||
<th>Company</th>
|
||||
<th>Registered At</th>
|
||||
<th>Source</th>
|
||||
<th>Timezone</th>
|
||||
<th>Webinar</th>
|
||||
<th>Registered at</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($attendees)): ?>
|
||||
<tr>
|
||||
<td colspan="8" class="text-center">No attendees found.</td>
|
||||
<td colspan="9" class="text-center py-4">No attendees found for this filter yet.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($attendees as $attendee): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($attendee['id']); ?></td>
|
||||
<td><?php echo htmlspecialchars($attendee['first_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($attendee['last_name']); ?></td>
|
||||
<td><?php echo htmlspecialchars($attendee['email']); ?></td>
|
||||
<td><?php echo htmlspecialchars($attendee['how_did_you_hear'] ?? ''); ?></td>
|
||||
<td><?php echo htmlspecialchars($attendee['company'] ?? ''); ?></td>
|
||||
<td><?php echo htmlspecialchars($attendee['created_at']); ?></td>
|
||||
<td><?php echo (int) $attendee['id']; ?></td>
|
||||
<td>
|
||||
<a href="edit_attendee.php?id=<?php echo $attendee['id']; ?>" class="btn btn-sm btn-primary">Edit</a>
|
||||
<form action="delete_attendee.php" method="POST" style="display: inline-block;">
|
||||
<input type="hidden" name="id" value="<?php echo $attendee['id']; ?>">
|
||||
<button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure?')">Delete</button>
|
||||
</form>
|
||||
<span class="attendee-name"><?php echo htmlspecialchars(trim(($attendee['first_name'] ?? '') . ' ' . ($attendee['last_name'] ?? '')) ?: '—'); ?></span>
|
||||
<span class="attendee-meta">Consent: <?php echo !empty($attendee['consented']) ? 'Yes' : 'No'; ?></span>
|
||||
</td>
|
||||
<td><?php echo htmlspecialchars($attendee['email'] ?? ''); ?></td>
|
||||
<td><?php echo htmlspecialchars(($attendee['company'] ?? '') !== '' ? $attendee['company'] : '—'); ?></td>
|
||||
<td><span class="tag"><?php echo htmlspecialchars(($attendee['how_did_you_hear'] ?? '') !== '' ? $attendee['how_did_you_hear'] : '—'); ?></span></td>
|
||||
<td><?php echo htmlspecialchars(($attendee['timezone'] ?? '') !== '' ? $attendee['timezone'] : '—'); ?></td>
|
||||
<td>
|
||||
<strong><?php echo htmlspecialchars(($attendee['webinar_title'] ?? '') !== '' ? $attendee['webinar_title'] : '—'); ?></strong>
|
||||
<span class="webinar-meta"><?php echo htmlspecialchars(format_admin_datetime($attendee['webinar_scheduled_at'] ?? null)); ?></span>
|
||||
</td>
|
||||
<td><?php echo htmlspecialchars(format_admin_datetime($attendee['created_at'] ?? null)); ?></td>
|
||||
<td>
|
||||
<div class="d-flex gap-2 flex-wrap">
|
||||
<a href="edit_attendee.php?id=<?php echo (int) $attendee['id']; ?>" class="btn btn-sm btn-primary">Edit</a>
|
||||
<form action="delete_attendee.php" method="POST" class="m-0" onsubmit="return confirm('Soft-delete attendee #<?php echo (int) $attendee['id']; ?>?');">
|
||||
<input type="hidden" name="id" value="<?php echo (int) $attendee['id']; ?>">
|
||||
<button type="submit" class="btn btn-sm btn-outline-light">Archive</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
@ -277,74 +478,74 @@ $chart_values = json_encode(array_column($chart_data, 'user_count'));
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<nav aria-label="Page navigation">
|
||||
<ul class="pagination justify-content-center">
|
||||
<?php if ($page > 1): ?>
|
||||
<li class="page-item"><a class="page-link" href="?page=<?php echo $page - 1; ?>">Previous</a></li>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
|
||||
<li class="page-item <?php if ($i == $page) echo 'active'; ?>"><a class="page-link" href="?page=<?php echo $i; ?>"><?php echo $i; ?></a></li>
|
||||
<?php endfor; ?>
|
||||
|
||||
<?php if ($page < $total_pages): ?>
|
||||
<li class="page-item"><a class="page-link" href="?page=<?php echo $page + 1; ?>">Next</a></li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</div>
|
||||
<?php if ($total_pages > 1): ?>
|
||||
<nav class="mt-4" aria-label="Attendee pagination">
|
||||
<ul class="pagination justify-content-center">
|
||||
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
|
||||
<li class="page-item <?php echo $i === $page ? 'active' : ''; ?>">
|
||||
<a class="page-link" href="admin.php?page=<?php echo $i; ?><?php echo $selected_webinar_id > 0 ? '&webinar_id=' . urlencode((string) $selected_webinar_id) : ''; ?>"><?php echo $i; ?></a>
|
||||
</li>
|
||||
<?php endfor; ?>
|
||||
</ul>
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
const ctx = document.getElementById('registrationsChart');
|
||||
const registrationsChart = new Chart(ctx, {
|
||||
const chartLabels = <?php echo $chart_labels ?: '[]'; ?>;
|
||||
const chartValues = <?php echo $chart_values ?: '[]'; ?>;
|
||||
const chartCtx = document.getElementById('registrationsChart');
|
||||
|
||||
const registrationsChart = new Chart(chartCtx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: <?php echo $chart_labels; ?>,
|
||||
labels: chartLabels,
|
||||
datasets: [{
|
||||
label: 'Daily Registrations',
|
||||
data: <?php echo $chart_values; ?>,
|
||||
backgroundColor: 'rgba(187, 200, 251, 0.18)',
|
||||
borderColor: 'rgba(34, 199, 255, 1)',
|
||||
borderWidth: 2,
|
||||
tension: 0.4,
|
||||
fill: true
|
||||
label: 'Registrations per day',
|
||||
data: chartValues,
|
||||
fill: true,
|
||||
tension: 0.35,
|
||||
borderWidth: 3,
|
||||
borderColor: '#22c7ff',
|
||||
backgroundColor: 'rgba(34, 199, 255, 0.15)',
|
||||
pointBackgroundColor: '#f3f9ff',
|
||||
pointBorderColor: '#22c7ff',
|
||||
pointRadius: 4,
|
||||
pointHoverRadius: 6
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
x: {
|
||||
ticks: { color: '#dde2fd' },
|
||||
grid: { color: 'rgba(143, 232, 255, 0.08)' }
|
||||
},
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
grid: { color: 'rgba(143, 232, 255, 0.08)' },
|
||||
ticks: {
|
||||
stepSize: 1,
|
||||
maintainAspectRatio: true,
|
||||
plugins: {
|
||||
legend: {
|
||||
labels: {
|
||||
color: '#dde2fd'
|
||||
}
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false
|
||||
scales: {
|
||||
x: {
|
||||
ticks: { color: '#dde2fd' },
|
||||
grid: { color: 'rgba(221, 226, 253, 0.08)' }
|
||||
},
|
||||
title: {
|
||||
display: true,
|
||||
text: 'User Registrations per Day',
|
||||
color: '#f3f9ff'
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
ticks: {
|
||||
color: '#dde2fd',
|
||||
precision: 0
|
||||
},
|
||||
grid: { color: 'rgba(221, 226, 253, 0.08)' }
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('downloadChartBtn').addEventListener('click', function() {
|
||||
document.getElementById('downloadChartBtn').addEventListener('click', function () {
|
||||
const link = document.createElement('a');
|
||||
link.href = registrationsChart.toBase64Image();
|
||||
link.download = 'daily-registrations-chart.png';
|
||||
link.href = registrationsChart.toBase64Image('image/png', 1);
|
||||
link.download = 'registrations-per-day.png';
|
||||
link.click();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@ -7,11 +7,33 @@ define('DB_PASS', 'e45f2778-db1f-450c-99c6-29efb4601472');
|
||||
|
||||
function db() {
|
||||
static $pdo;
|
||||
|
||||
if (!$pdo) {
|
||||
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
try {
|
||||
$pdo = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
} catch (PDOException $e) {
|
||||
if ((int) $e->getCode() !== 1049 && stripos($e->getMessage(), 'Unknown database') === false) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$bootstrap = new PDO('mysql:host=' . DB_HOST . ';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
$bootstrap->exec('CREATE DATABASE IF NOT EXISTS `' . DB_NAME . '` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
|
||||
|
||||
$pdo = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4', DB_USER, DB_PASS, [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
]);
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/ensure_schema.php';
|
||||
ensure_app_schema($pdo);
|
||||
}
|
||||
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
121
db/ensure_schema.php
Normal file
121
db/ensure_schema.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
function schema_table_exists(PDO $pdo, string $table): bool {
|
||||
$stmt = $pdo->prepare('SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?');
|
||||
$stmt->execute([$table]);
|
||||
return (int) $stmt->fetchColumn() > 0;
|
||||
}
|
||||
|
||||
function schema_column_exists(PDO $pdo, string $table, string $column): bool {
|
||||
$stmt = $pdo->prepare('SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ?');
|
||||
$stmt->execute([$table, $column]);
|
||||
return (int) $stmt->fetchColumn() > 0;
|
||||
}
|
||||
|
||||
function ensure_app_schema(PDO $pdo): void {
|
||||
static $hasRun = false;
|
||||
if ($hasRun) {
|
||||
return;
|
||||
}
|
||||
$hasRun = true;
|
||||
|
||||
$pdo->exec('CREATE TABLE IF NOT EXISTS migrations (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
migration VARCHAR(255) NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4');
|
||||
|
||||
$pdo->exec('CREATE TABLE IF NOT EXISTS webinars (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
description TEXT,
|
||||
presenter VARCHAR(255),
|
||||
scheduled_at DATETIME NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4');
|
||||
|
||||
$pdo->exec('CREATE TABLE IF NOT EXISTS attendees (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
webinar_id INT NOT NULL,
|
||||
first_name VARCHAR(255) NOT NULL DEFAULT "",
|
||||
last_name VARCHAR(255) NOT NULL DEFAULT "",
|
||||
name VARCHAR(255) NULL,
|
||||
email VARCHAR(255) NOT NULL,
|
||||
company VARCHAR(255) DEFAULT NULL,
|
||||
timezone VARCHAR(255) DEFAULT NULL,
|
||||
how_did_you_hear VARCHAR(255) DEFAULT NULL,
|
||||
password VARCHAR(255) NOT NULL DEFAULT "",
|
||||
consented TINYINT(1) NOT NULL DEFAULT 0,
|
||||
deleted_at TIMESTAMP NULL DEFAULT NULL,
|
||||
created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT fk_attendees_webinar FOREIGN KEY (webinar_id) REFERENCES webinars(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4');
|
||||
|
||||
if (schema_table_exists($pdo, 'attendees')) {
|
||||
if (schema_column_exists($pdo, 'attendees', 'name')) {
|
||||
$pdo->exec('ALTER TABLE attendees MODIFY COLUMN name VARCHAR(255) NULL');
|
||||
}
|
||||
|
||||
if (!schema_column_exists($pdo, 'attendees', 'first_name')) {
|
||||
$pdo->exec('ALTER TABLE attendees ADD COLUMN first_name VARCHAR(255) NOT NULL DEFAULT "" AFTER webinar_id');
|
||||
}
|
||||
|
||||
if (!schema_column_exists($pdo, 'attendees', 'last_name')) {
|
||||
$pdo->exec('ALTER TABLE attendees ADD COLUMN last_name VARCHAR(255) NOT NULL DEFAULT "" AFTER first_name');
|
||||
}
|
||||
|
||||
if (!schema_column_exists($pdo, 'attendees', 'company')) {
|
||||
$pdo->exec('ALTER TABLE attendees ADD COLUMN company VARCHAR(255) DEFAULT NULL AFTER email');
|
||||
}
|
||||
|
||||
if (!schema_column_exists($pdo, 'attendees', 'timezone')) {
|
||||
$pdo->exec('ALTER TABLE attendees ADD COLUMN timezone VARCHAR(255) DEFAULT NULL AFTER company');
|
||||
}
|
||||
|
||||
if (!schema_column_exists($pdo, 'attendees', 'how_did_you_hear')) {
|
||||
$pdo->exec('ALTER TABLE attendees ADD COLUMN how_did_you_hear VARCHAR(255) DEFAULT NULL AFTER timezone');
|
||||
}
|
||||
|
||||
if (!schema_column_exists($pdo, 'attendees', 'password')) {
|
||||
$pdo->exec('ALTER TABLE attendees ADD COLUMN password VARCHAR(255) NOT NULL DEFAULT "" AFTER how_did_you_hear');
|
||||
}
|
||||
|
||||
if (!schema_column_exists($pdo, 'attendees', 'consented')) {
|
||||
$pdo->exec('ALTER TABLE attendees ADD COLUMN consented TINYINT(1) NOT NULL DEFAULT 0 AFTER password');
|
||||
}
|
||||
|
||||
if (!schema_column_exists($pdo, 'attendees', 'deleted_at')) {
|
||||
$pdo->exec('ALTER TABLE attendees ADD COLUMN deleted_at TIMESTAMP NULL DEFAULT NULL AFTER consented');
|
||||
}
|
||||
|
||||
if (!schema_column_exists($pdo, 'attendees', 'created_at')) {
|
||||
$pdo->exec('ALTER TABLE attendees ADD COLUMN created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP AFTER company');
|
||||
}
|
||||
|
||||
if (schema_column_exists($pdo, 'attendees', 'registered_at')) {
|
||||
$pdo->exec('UPDATE attendees SET created_at = COALESCE(created_at, registered_at)');
|
||||
}
|
||||
|
||||
if (schema_column_exists($pdo, 'attendees', 'name')) {
|
||||
$pdo->exec("UPDATE attendees SET first_name = TRIM(SUBSTRING_INDEX(name, ' ', 1)) WHERE (first_name = '' OR first_name IS NULL) AND name IS NOT NULL AND name <> ''");
|
||||
$pdo->exec("UPDATE attendees SET last_name = TRIM(SUBSTRING(name, CHAR_LENGTH(SUBSTRING_INDEX(name, ' ', 1)) + 1)) WHERE (last_name = '' OR last_name IS NULL) AND name IS NOT NULL AND name LIKE '% %'");
|
||||
}
|
||||
}
|
||||
|
||||
$desiredTitle = 'Building Scalable Apps with AppWizzy';
|
||||
$desiredDescription = 'The fastest way to go from an idea to a working app you own, running on your server, with your database, using real frameworks.';
|
||||
$desiredPresenter = 'AppWizzy Team';
|
||||
$desiredScheduledAt = '2026-03-25 18:00:00';
|
||||
|
||||
$stmt = $pdo->prepare('SELECT COUNT(*) FROM webinars WHERE id = 1');
|
||||
$stmt->execute();
|
||||
$hasPrimaryWebinar = (int) $stmt->fetchColumn() > 0;
|
||||
|
||||
if ($hasPrimaryWebinar) {
|
||||
$update = $pdo->prepare('UPDATE webinars SET title = ?, description = ?, presenter = ?, scheduled_at = ? WHERE id = 1');
|
||||
$update->execute([$desiredTitle, $desiredDescription, $desiredPresenter, $desiredScheduledAt]);
|
||||
} else {
|
||||
$insert = $pdo->prepare('INSERT INTO webinars (id, title, description, presenter, scheduled_at) VALUES (1, ?, ?, ?, ?)');
|
||||
$insert->execute([$desiredTitle, $desiredDescription, $desiredPresenter, $desiredScheduledAt]);
|
||||
}
|
||||
}
|
||||
@ -1 +1 @@
|
||||
ALTER TABLE `attendees` ADD `consented` TINYINT(1) NOT NULL DEFAULT 0;
|
||||
ALTER TABLE attendees ADD COLUMN IF NOT EXISTS consented TINYINT(1) NOT NULL DEFAULT 0;
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
ALTER TABLE attendees MODIFY COLUMN name VARCHAR(255) NULL;
|
||||
ALTER TABLE attendees ADD COLUMN IF NOT EXISTS first_name VARCHAR(255) NOT NULL DEFAULT '' AFTER webinar_id;
|
||||
ALTER TABLE attendees ADD COLUMN IF NOT EXISTS last_name VARCHAR(255) NOT NULL DEFAULT '' AFTER first_name;
|
||||
ALTER TABLE attendees ADD COLUMN IF NOT EXISTS created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP AFTER company;
|
||||
ALTER TABLE attendees ADD COLUMN IF NOT EXISTS deleted_at TIMESTAMP NULL DEFAULT NULL AFTER consented;
|
||||
ALTER TABLE attendees ADD COLUMN IF NOT EXISTS how_did_you_hear VARCHAR(255) DEFAULT NULL AFTER timezone;
|
||||
UPDATE attendees SET created_at = COALESCE(created_at, registered_at);
|
||||
UPDATE attendees
|
||||
SET first_name = TRIM(SUBSTRING_INDEX(name, ' ', 1))
|
||||
WHERE (first_name = '' OR first_name IS NULL)
|
||||
AND name IS NOT NULL
|
||||
AND name <> '';
|
||||
UPDATE attendees
|
||||
SET last_name = TRIM(SUBSTRING(name, CHAR_LENGTH(SUBSTRING_INDEX(name, ' ', 1)) + 1))
|
||||
WHERE (last_name = '' OR last_name IS NULL)
|
||||
AND name IS NOT NULL
|
||||
AND name LIKE '% %';
|
||||
INSERT INTO webinars (id, title, description, presenter, scheduled_at)
|
||||
SELECT 1,
|
||||
'Building Scalable Apps with AppWizzy',
|
||||
'The fastest way to go from an idea to a working app you own, running on your server, with your database, using real frameworks.',
|
||||
'AppWizzy Team',
|
||||
'2026-03-25 18:00:00'
|
||||
WHERE NOT EXISTS (SELECT 1 FROM webinars WHERE id = 1);
|
||||
UPDATE webinars
|
||||
SET title = 'Building Scalable Apps with AppWizzy',
|
||||
description = 'The fastest way to go from an idea to a working app you own, running on your server, with your database, using real frameworks.',
|
||||
presenter = 'AppWizzy Team',
|
||||
scheduled_at = '2026-03-25 18:00:00'
|
||||
WHERE id = 1;
|
||||
@ -7,22 +7,19 @@ if (!isset($_SESSION['user']) || $_SESSION['user'] !== 'admin') {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['id'])) {
|
||||
$id = $_POST['id'];
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['id']) && is_numeric($_POST['id'])) {
|
||||
$id = (int) $_POST['id'];
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare("DELETE FROM attendees WHERE id = ?");
|
||||
|
||||
if ($stmt->execute([$id])) {
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$_SESSION['message'] = "Attendee with ID $id has been deleted successfully.";
|
||||
} else {
|
||||
$_SESSION['message'] = "Error: No attendee found with ID $id. Nothing was deleted.";
|
||||
}
|
||||
$stmt = $pdo->prepare('UPDATE attendees SET deleted_at = NOW() WHERE id = ? AND deleted_at IS NULL');
|
||||
$stmt->execute([$id]);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$_SESSION['message'] = "Attendee #{$id} has been archived successfully.";
|
||||
} else {
|
||||
$_SESSION['message'] = "Error: Could not execute the delete statement.";
|
||||
$_SESSION['message'] = "No active attendee found for ID #{$id}.";
|
||||
}
|
||||
} else {
|
||||
$_SESSION['message'] = "Error: Invalid request.";
|
||||
$_SESSION['message'] = 'Error: Invalid archive request.';
|
||||
}
|
||||
|
||||
header('Location: admin.php');
|
||||
|
||||
@ -2,36 +2,78 @@
|
||||
session_start();
|
||||
require_once 'db/config.php';
|
||||
|
||||
// Check if user is admin
|
||||
if (!isset($_SESSION['user']) || $_SESSION['user'] !== 'admin') {
|
||||
http_response_code(403);
|
||||
echo "Forbidden";
|
||||
echo 'Forbidden';
|
||||
exit;
|
||||
}
|
||||
|
||||
$pdo = db();
|
||||
$stmt = $pdo->query("SELECT first_name, last_name, email, how_did_you_hear, company FROM attendees ORDER BY created_at DESC");
|
||||
$selected_webinar_id = isset($_GET['webinar_id']) && is_numeric($_GET['webinar_id']) ? max(0, (int) $_GET['webinar_id']) : 0;
|
||||
|
||||
$where_sql = 'WHERE a.deleted_at IS NULL';
|
||||
$params = [];
|
||||
if ($selected_webinar_id > 0) {
|
||||
$where_sql .= ' AND a.webinar_id = :webinar_id';
|
||||
$params[':webinar_id'] = $selected_webinar_id;
|
||||
}
|
||||
|
||||
$sql = "SELECT
|
||||
a.id,
|
||||
a.webinar_id,
|
||||
w.title AS webinar_title,
|
||||
a.first_name,
|
||||
a.last_name,
|
||||
a.email,
|
||||
a.company,
|
||||
a.how_did_you_hear,
|
||||
a.timezone,
|
||||
a.consented,
|
||||
a.created_at
|
||||
FROM attendees a
|
||||
LEFT JOIN webinars w ON w.id = a.webinar_id
|
||||
{$where_sql}
|
||||
ORDER BY a.created_at DESC, a.id DESC";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
foreach ($params as $name => $value) {
|
||||
$stmt->bindValue($name, $value, PDO::PARAM_INT);
|
||||
}
|
||||
$stmt->execute();
|
||||
$attendees = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
header('Content-Type: text/csv; charset=utf-8');
|
||||
header('Content-Disposition: attachment; filename=attendees.csv');
|
||||
|
||||
$output = fopen('php://output', 'w');
|
||||
|
||||
// Add BOM to fix UTF-8 in Excel
|
||||
fputs($output, "\xEF\xBB\xBF");
|
||||
|
||||
// Add header row
|
||||
fputcsv($output, ['First Name', 'Last Name', 'Email', 'Source', 'Company']);
|
||||
fputcsv($output, [
|
||||
'ID',
|
||||
'Webinar ID',
|
||||
'Webinar Title',
|
||||
'First Name',
|
||||
'Last Name',
|
||||
'Email',
|
||||
'Company',
|
||||
'Source',
|
||||
'Timezone',
|
||||
'Consented',
|
||||
'Registered At',
|
||||
]);
|
||||
|
||||
// Add data rows
|
||||
foreach ($attendees as $attendee) {
|
||||
fputcsv($output, [
|
||||
$attendee['id'],
|
||||
$attendee['webinar_id'],
|
||||
$attendee['webinar_title'] ?? '',
|
||||
$attendee['first_name'],
|
||||
$attendee['last_name'],
|
||||
$attendee['email'],
|
||||
$attendee['company'] ?? '',
|
||||
$attendee['how_did_you_hear'] ?? '',
|
||||
$attendee['company'] ?? ''
|
||||
$attendee['timezone'] ?? '',
|
||||
!empty($attendee['consented']) ? 'Yes' : 'No',
|
||||
$attendee['created_at'] ?? '',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
10
index.php
10
index.php
@ -325,6 +325,7 @@
|
||||
</select>
|
||||
</div>
|
||||
<input type="hidden" name="webinar_id" value="1">
|
||||
<input type="hidden" name="timezone" id="timezone-field" value="">
|
||||
<button type="submit" class="btn-register">Register Now</button>
|
||||
</form>
|
||||
<div class="what-you-learn">
|
||||
@ -353,6 +354,7 @@
|
||||
const messageDiv = document.getElementById('form-message');
|
||||
const rightColumn = document.getElementById('right-column-content');
|
||||
const emailInput = form.querySelector('input[name="email"]');
|
||||
const timezoneField = form.querySelector('#timezone-field');
|
||||
const emailValue = (emailInput.value || '').trim().toLowerCase();
|
||||
const blockedDomains = new Set([
|
||||
'10minutemail.com',
|
||||
@ -376,6 +378,14 @@
|
||||
|
||||
messageDiv.textContent = ''; // Clear previous messages
|
||||
|
||||
if (timezoneField) {
|
||||
try {
|
||||
timezoneField.value = Intl.DateTimeFormat().resolvedOptions().timeZone || '';
|
||||
} catch (error) {
|
||||
timezoneField.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
if (emailValue && emailValue.includes('@')) {
|
||||
const emailDomain = emailValue.split('@').pop();
|
||||
if (blockedDomains.has(emailDomain)) {
|
||||
|
||||
BIN
register.php
BIN
register.php
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user