92 lines
3.3 KiB
PHP
92 lines
3.3 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../includes/auth.php';
|
|
require_login();
|
|
|
|
$contacts = get_contacts();
|
|
$isExport = isset($_GET['export']);
|
|
if ($isExport) {
|
|
header('Content-Type: text/csv');
|
|
header('Content-Disposition: attachment; filename="contacts.csv"');
|
|
$out = fopen('php://output', 'w');
|
|
fputcsv($out, ['Name', 'Email', 'Organization', 'Message', 'Received']);
|
|
foreach ($contacts as $c) {
|
|
fputcsv($out, [
|
|
$c['name'] ?? '',
|
|
$c['email'] ?? '',
|
|
$c['organization'] ?? '',
|
|
$c['message'] ?? '',
|
|
$c['created_at'] ?? '',
|
|
]);
|
|
}
|
|
fclose($out);
|
|
exit;
|
|
}
|
|
$assetPathPrefix = '../';
|
|
$pageTitle = 'Contact Entries';
|
|
$currentPage = 'contact';
|
|
$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; vertical-align: top; }
|
|
.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">Contact Entries</p>
|
|
<h2>Messages from the contact form</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($contacts)): ?>
|
|
<p class="body muted">No messages yet.</p>
|
|
<?php else: ?>
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Email</th>
|
|
<th>Organization</th>
|
|
<th>Message</th>
|
|
<th>Received</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($contacts as $contact): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($contact['name']); ?></td>
|
|
<td><?php echo htmlspecialchars($contact['email']); ?></td>
|
|
<td><?php echo htmlspecialchars($contact['organization'] ?? ''); ?></td>
|
|
<td><?php echo nl2br(htmlspecialchars($contact['message'])); ?></td>
|
|
<td><?php echo htmlspecialchars($contact['created_at']); ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php endif; ?>
|
|
</div>
|
|
</main>
|
|
|
|
<?php require __DIR__ . '/../includes/admin-footer.php'; ?>
|