<?php
require_once __DIR__ . '/includes/auth.php';
require_admin();

$subscribers = db()->query('SELECT * FROM newsletter_subscribers ORDER BY created_at DESC')->fetchAll();

header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="newsletter-subscribers.csv"');

$out = fopen('php://output', 'w');
fputcsv($out, ['Email', 'Joined']);
foreach ($subscribers as $s) {
    fputcsv($out, [$s['email'], $s['created_at']]);
}
fclose($out);
