<?php
include 'auth.php';

if (empty($_GET['ids'])) {
    die('Nenhuma resposta selecionada!');
}

$ids = array_values(array_filter(array_map('intval', explode(',', (string) $_GET['ids']))));
$formId = isset($_GET['formId']) ? (int) $_GET['formId'] : 0;

if ($ids === []) {
    die('IDs inválidos!');
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <title>Gerando fichas</title>
</head>
<body>
<script>
const ids = <?= json_encode($ids) ?>;
ids.forEach((id) => window.open(`gerar_ficha.php?id=${id}`, '_blank'));
<?php if ($formId > 0): ?>
window.location = 'formulario_Resposta.php?id=<?= $formId ?>';
<?php else: ?>
window.history.back();
<?php endif; ?>
</script>
</body>
</html>
