<?php
require __DIR__ . '/lib.php';
require_auth();

$slug = slugify($_GET['form'] ?? '');
$file = $slug ? responses_file($slug) : '';
if (!$slug || !is_file($file)) {
    http_response_code(404);
    echo 'Export introuvable';
    exit;
}

header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="' . $slug . '-responses.csv"');
readfile($file);
