CrestRoad/website/admin/newsletter.php

86 lines
2.9 KiB
PHP

<?php
require_once __DIR__ . '/../includes/auth.php';
require_login();
$subs = get_subscriptions();
$isExport = isset($_GET['export']);
if ($isExport) {
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="newsletter.csv"');
$out = fopen('php://output', 'w');
fputcsv($out, ['First Name', 'Email', 'Subscribed']);
foreach ($subs as $s) {
fputcsv($out, [
$s['first_name'] ?? '',
$s['email'] ?? '',
$s['created_at'] ?? '',
]);
}
fclose($out);
exit;
}
$assetPathPrefix = '../';
$pageTitle = 'Newsletter Subscribers';
$currentPage = 'news';
$extraStyles = <<<CSS
<style>
body { background: #f6faf7; }
.admin-shell { padding: 40px 0; }
.table { width: 100%; border-collapse: collapse; margin-top: 20px; }
.table th, .table td { text-align: left; padding: 12px 10px; border-bottom: 1px solid #e1ede7; }
.table th { color: #0f4333; }
</style>
CSS;
require __DIR__ . '/../includes/admin-header.php';
?>
<main class="admin-shell">
<div class="container">
<div class="topbar" style="display:flex; justify-content:space-between; align-items:center; margin-bottom:16px;">
<div>
<p class="eyebrow">Newsletter</p>
<h2>Subscription list</h2>
</div>
<div class="btn ghost" style="pointer-events:none;">Read-only</div>
</div>
<div class="admin-nav">
<a href="/admin/tutorials.php">Tutorials</a>
<a href="/admin/sessions.php">Upcoming Sessions</a>
<a href="/admin/contacts.php">Contact Entries</a>
<a href="/admin/newsletter.php">Newsletter</a>
<a href="/admin/admins.php">Admins</a>
<a href="/admin/logout.php">Logout (<?php echo htmlspecialchars(current_admin_email() ?? ''); ?>)</a>
</div>
<div style="margin:10px 0;">
<a class="btn outline small" href="?export=1">Export CSV</a>
</div>
<?php if (empty($subs)): ?>
<p class="body muted">No subscribers yet.</p>
<?php else: ?>
<table class="table">
<thead>
<tr>
<th>First Name</th>
<th>Email</th>
<th>Subscribed</th>
</tr>
</thead>
<tbody>
<?php foreach ($subs as $sub): ?>
<tr>
<td><?php echo htmlspecialchars($sub['first_name'] ?? ''); ?></td>
<td><?php echo htmlspecialchars($sub['email']); ?></td>
<td><?php echo htmlspecialchars($sub['created_at']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</main>
<?php require __DIR__ . '/../includes/admin-footer.php'; ?>