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

$result = build_all_client_cards_zip();

if (empty($result['ok'])) {
    header('Location: list_dns.php?cards_error=' . urlencode($result['message'] ?? 'Erro ao gerar ZIP.'));
    exit;
}

$path = $result['path'];
$filename = $result['filename'];

header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Length: ' . filesize($path));
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Pragma: no-cache');

readfile($path);
@unlink($path);
exit;
