<?php
// admin/export_phones.php - Export mpesa_stk_queue phone numbers as CSV
require_once '../src/Database.php';
require_once '../src/Auth.php';

$auth = new Auth();
$auth->requireLogin();

$db = new Database();
$conn = $db->getConnection();

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

$output = fopen('php://output', 'w');
fputcsv($output, ['phone']);

$stmt = $conn->query('SELECT phone FROM mpesa_stk_queue');
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    fputcsv($output, [$row['phone']]);
}
fclose($output);
exit;
