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

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

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

$out = fopen('php://output', 'w');
fputcsv($out, ['Name', 'Email', 'Phone', 'Budget Min', 'Budget Max', 'Property Type', 'District', 'Joined']);
foreach ($subscribers as $s) {
    fputcsv($out, [$s['name'], $s['email'], $s['phone'], $s['budget_min'], $s['budget_max'], $s['property_type'], $s['district'], $s['created_at']]);
}
fclose($out);
