1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-11-27 11:33:02 +00:00
plateforme-tfjm2/server_files/controllers/syntheses_orga.php

71 lines
3.1 KiB
PHP

<?php if (!isset($_SESSION["role"]) || $_SESSION["role"] != Role::ADMIN && $_SESSION["role"] != Role::ORGANIZER)
require_once "server_files/403.php";
if (isset($_POST["download_zip"])) {
$id = $_POST["tournament"];
$tournament_name = $_POST["tournament_name"];
/** @noinspection SqlAggregates */
$files_req = $DB->query("SELECT *, COUNT(`dest`) AS `version` FROM `syntheses` WHERE `tournament` = '$id' GROUP BY `team`, `dest` ORDER BY `team`, `dest`, `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"];
$dest = $data_file["dest"];
$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", "Note de synthèse $team_trigram pour " . ($dest == "OPPOSANT" ? "l'opposant" : "le rapporteur") . ".pdf");
}
$zip->close();
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=\"Notes de syntèses du tournoi de $tournament_name.zip\"");
header("Content-Length: " . strval(filesize($temp) + 1));
readfile($temp);
exit();
}
require_once "server_files/views/header.php";
$req = $DB->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`, `name` ORDER BY `name`;");
while (($data_tournament = $req->fetch()) !== false) {
echo "<h1>Tournoi de " . $data_tournament["name"] . "</h1>\n";
$id = $data_tournament["id"];
$files_req = $DB->query("SELECT *, COUNT(`dest`) AS `version` FROM `syntheses` WHERE `tournament` = '$id' GROUP BY `team`, `dest`, `uploaded_at` ORDER BY `team`, `dest`, `uploaded_at` DESC;");
while (($data_file = $files_req->fetch()) !== false) {
$file_id = $data_file["file_id"];
$dest = $data_file["dest"];
$version = $data_file["version"];
$team_id = $data_file["team"];
$team = Team::fromId($team_id);
$team_name = $team->getName();
$team_trigram = $team->getTrigram();
echo "Note de synthèse de l'équipe $team_name ($team_trigram) pour " . ($dest == "OPPOSANT" ? "l'opposant" : "le rapporteur")
. ", version $version : <a href=\"$URL_BASE/file/$file_id\">Télécharger</a><br />";
}
echo "<form method=\"POST\">\n";
echo "<input type=\"hidden\" name=\"tournament\" value=\"$id\" />\n";
echo "<input type=\"hidden\" name=\"tournament_name\" value=\"" . $data_tournament["name"] . "\" />\n";
echo "<input style=\"width: 100%\" type=\"submit\" name=\"download_zip\" value=\"Télécharger l'archive\" />\n";
echo "</form><hr />\n";
}
require_once "server_files/views/footer.php";