1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-25 17:37:25 +02:00

Améliorations du code

This commit is contained in:
Yohann
2019-09-08 01:35:05 +02:00
committed by galaxyoyo
parent 3cc66ef783
commit a25ec69ae9
23 changed files with 558 additions and 457 deletions

View File

@ -3,16 +3,10 @@
if (!isset($_SESSION["role"]) || $_SESSION["role"] != Role::ADMIN && $_SESSION["role"] != Role::ORGANIZER)
require_once "server_files/403.php";
/** @noinspection SqlAggregates */
$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` 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;");
$tournament = Tournament::fromId($id);
$sols = $tournament->getAllSolutions();
$zip = new ZipArchive();
@ -22,12 +16,12 @@ if (isset($_POST["download_zip"])) {
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);
/** @var Solution $sol */
foreach ($sols as $sol) {
$file_id = $sol->getFileId();
$problem = $sol->getProblem();
$version = $sol->getVersion();
$team = Team::fromId($sol->getTeamId());
$team_name = $team->getName();
$team_trigram = $team->getTrigram();
@ -37,7 +31,7 @@ if (isset($_POST["download_zip"])) {
$zip->close();
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=\"Solutions du tournoi de $tournament_name.zip\"");
header("Content-Disposition: attachment; filename=\"Solutions du tournoi de " . $tournament->getName() . ".zip\"");
header("Content-Length: " . strval(filesize($temp)));
readfile($temp);
@ -45,29 +39,7 @@ if (isset($_POST["download_zip"])) {
exit();
}
require_once "server_files/views/header.php";
$user = $_SESSION["user"];
$tournaments = $_SESSION["role"] == Role::ADMIN ? Tournament::getAllTournaments() : $user->getOrganizedTournaments();
while (($data_tournament = $req->fetch()) !== false) {
echo "<h1>Tournoi de " . $data_tournament["name"] . "</h1>\n";
$id = $data_tournament["id"];
/** @noinspection SqlAggregates */
$files_req = $DB->query("SELECT *, COUNT(`problem`) AS `version` FROM `solutions` WHERE `tournament` = '$id' GROUP BY `team` ORDER BY `team`, `problem`, `uploaded_at` DESC;");
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();
echo "Problème n°$problem de l'équipe $team_name ($team_trigram), 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";
require_once "server_files/views/solutions_orga.php";