query("SELECT `tournaments`.`id`, `name` FROM `tournaments` JOIN `organizers` ON `tournament` = `tournaments`.`id` WHERE " . ($_SESSION["role"] == Role::ADMIN ? "" : "`organizer` = '" . $_SESSION["user_id"] . "' AND ") . "`year` = $YEAR GROUP BY `tournament` ORDER BY `name`;"); if (isset($_POST["download_zip"])) { $id = $_POST["tournament"]; $tournament_name = $_POST["tournament_name"]; /** @noinspection SqlAggregates */ $files_req = $DB->query("SELECT *, COUNT(`problem`) AS `version` FROM `solutions` WHERE `tournament` = '$id' GROUP BY `team`, `problem` ORDER BY `team`, `problem`, `uploaded_at` DESC;"); $zip = new ZipArchive(); $temp = tempnam("tmp", "tfjm-"); if ($zip->open($temp, ZipArchive::CREATE) !== true) { die("Impossible de créer le fichier zip."); } while (($data_file = $files_req->fetch()) !== false) { $file_id = $data_file["file_id"]; $problem = $data_file["problem"]; $version = $data_file["version"]; $team_id = $data_file["team"]; $team = Team::fromId($team_id); $team_name = $team->getName(); $team_trigram = $team->getTrigram(); $zip->addFile("$LOCAL_PATH/files/$file_id", "Problème $problem $team_trigram.pdf"); } $zip->close(); header("Content-Type: application/zip"); header("Content-Disposition: attachment; filename=\"Solutions du tournoi de $tournament_name.zip\""); header("Content-Length: " . strval(filesize($temp))); readfile($temp); exit(); } require_once "server_files/views/header.php"; while (($data_tournament = $req->fetch()) !== false) { echo "