1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-26 07:42:26 +00:00
plateforme-tfjm2/server_files/equipe.php

174 lines
6.6 KiB
PHP
Raw Normal View History

2019-08-21 20:56:46 +00:00
<?php
include "config.php";
$trigram = htmlspecialchars($_GET["trigram"]);
if (isset($_POST["validate"])) {
$DB->exec("UPDATE `teams` SET `validation_status` = 'VALIDATED' WHERE `trigram` = '$trigram' AND `year` = $YEAR;");
}
$team_data = $DB->query("SELECT * FROM `teams` WHERE `trigram` = '$trigram' AND `year` = $YEAR;")->fetch();
2019-08-21 20:56:46 +00:00
2019-09-02 22:01:54 +00:00
if (isset($_POST["select"])) {
$DB->exec("UPDATE `teams` SET `final_selection` = true, `validation_status` = 'NOT_READY' WHERE `trigram` = '$trigram' AND `year` = $YEAR;");
$team_data["validation_status"] = "NOT_READY";
$team_data["final_selection"] = true;
$final_id = $_SESSION["final_id"];
$team_id = $team_data["id"];
$sols_req = $DB->prepare("SELECT `file_id`, `problem`, COUNT(`problem`) AS `version` FROM `solutions` WHERE `team` = ? AND `tournament` = ? GROUP BY `problem`, `uploaded_at` ORDER BY `problem`, `uploaded_at` DESC;");
$sols_req->execute([$team_data["id"], $team_data["tournament"]]);
while (($sol_data = $sols_req->fetch()) !== false) {
$old_id = $sol_data["file_id"];
$alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
do {
$id = "";
for ($i = 0; $i < 64; ++$i) {
$id .= $alphabet[rand(0, strlen($alphabet) - 1)];
}
}
while (file_exists("$LOCAL_PATH/files/$id"));
copy("$LOCAL_PATH/files/$old_id", "$LOCAL_PATH/files/$id");
$req = $DB->prepare("INSERT INTO `solutions`(`file_id`, `team`, `tournament`, `problem`)
VALUES (?, ?, ?, ?);");
$req->execute([$id, $team_id, $_SESSION["final_id"], $sol_data["problem"]]);
}
$syntheses_req = $DB->prepare("SELECT `file_id`, `dest`, COUNT(`dest`) AS `version` FROM `syntheses` WHERE `team` = ? AND `tournament` = ? GROUP BY `dest`, `uploaded_at` ORDER BY `dest`, `uploaded_at` DESC;");
$syntheses_req->execute([$team_data["id"], $team_data["tournament"]]);
while (($synthese_data = $syntheses_req->fetch()) !== false) {
$old_id = $synthese_data["file_id"];
$alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
do {
$id = "";
for ($i = 0; $i < 64; ++$i) {
$id .= $alphabet[rand(0, strlen($alphabet) - 1)];
}
}
while (file_exists("$LOCAL_PATH/files/$id"));
copy("$LOCAL_PATH/files/$old_id", "$LOCAL_PATH/files/$id");
$req = $DB->prepare("INSERT INTO `syntheses`(`file_id`, `team`, `tournament`, `dest`) VALUES (?, ?, ?, ?);");
$req->execute([$id, $team_id, $_SESSION["final_id"], $synthese_data["dest"]]);
}
}
2019-09-02 17:56:41 +00:00
if ($team_data === false)
2019-09-02 19:19:21 +00:00
include "404.php";
2019-09-02 17:56:41 +00:00
2019-08-21 20:56:46 +00:00
$tournament_data = $DB->query("SELECT `name`, `date_start` FROM `tournaments` WHERE `id` = '" . $team_data["tournament"] . "' AND `year` = '$YEAR';")->fetch();
2019-09-02 22:01:54 +00:00
$documents_req = $DB->prepare("SELECT `file_id`, `user`, `type`, COUNT(`type`) AS `version` FROM `documents` WHERE `team` = ? AND `tournament` = ? GROUP BY `user`, `type` ORDER BY `user`, `type` ASC, MAX(`uploaded_at`) DESC;");
$documents_req->execute([$team_data["id"], $team_data["tournament"]]);
if ($team_data["final_selection"]) {
$documents_final_req = $DB->prepare("SELECT `file_id`, `user`, `type`, COUNT(`type`) AS `version` FROM `documents` WHERE `team` = ? AND `tournament` != ? GROUP BY `user`, `type` ORDER BY `user`, `type` ASC, MAX(`uploaded_at`) DESC;");
$documents_final_req->execute([$team_data["id"], $_SESSION["final_id"]]);
}
2019-08-21 20:56:46 +00:00
?>
<?php include "header.php" ?>
<h2>Informations sur l'équipe</h2>
2019-09-02 17:56:41 +00:00
Nom de l'équipe : <?= $team_data["name"] ?><br />
Trigramme : <?= $team_data["trigram"] ?><br />
Tournoi : <a href="<?= $URL_BASE . "/tournoi/" . $tournament_data["name"] ?>"><?= $tournament_data["name"] ?></a><br />
2019-08-21 20:56:46 +00:00
<?php
for ($i = 1; $i <= 2; ++$i) {
if ($team_data["encadrant_" . $i] == NULL)
continue;
$user_data = $DB->query("SELECT `id`, `surname`, `first_name` FROM `users` WHERE `id` = " . $team_data["encadrant_" . $i] . " AND `year` = '$YEAR';")->fetch();
$id = $user_data["id"];
echo "Encadrant $i : <a href=\"$URL_BASE/informations/$id/" . $user_data["first_name"] . " " . $user_data["surname"] . "\">" . $user_data["first_name"] . " " . $user_data["surname"] . "</a><br />";
2019-08-21 20:56:46 +00:00
}
for ($i = 1; $i <= 6; ++$i) {
if ($team_data["participant_" . $i] == NULL)
continue;
$user_data = $DB->query("SELECT `id`, `surname`, `first_name` FROM `users` WHERE `id` = " . $team_data["participant_" . $i] . " AND `year` = '$YEAR';")->fetch();
$id = $user_data["id"];
echo "Participant $i : <a href=\"$URL_BASE/informations/$id/" . $user_data["first_name"] . " " . $user_data["surname"] . "\">" . $user_data["first_name"] . " " . $user_data["surname"] . "</a><br />";
2019-08-21 20:56:46 +00:00
}
2019-09-02 22:01:54 +00:00
if ($team_data["final_selection"]) {
$final_name = $_SESSION["final_name"];
echo "<strong>Équipe sélectionnée pour la <a href=\"$URL_BASE/tournoi/$final_name\">finale nationale</a>.</strong>";
}
2019-08-21 20:56:46 +00:00
?>
2019-08-26 14:51:07 +00:00
<hr />
2019-08-21 20:56:46 +00:00
<h2>Autorisations</h2>
<?php
while (($data = $documents_req->fetch()) !== false) {
$file_id = $data["file_id"];
$type = $data["type"];
$user_id = $data["user"];
$user_data = $DB->query("SELECT `surname`, `first_name` FROM `users` WHERE `id` = '$user_id';")->fetch();
$surname = $user_data["surname"];
$first_name = $user_data["first_name"];
$version = $data["version"];
switch ($data["type"]) {
case "PARENTAL_CONSENT":
$name = "Autorisation parentale";
break;
case "PHOTO_CONSENT":
$name = "Autorisation de droit à l'image";
break;
case "SANITARY_PLUG":
$name = "Fiche sanitaire";
break;
}
echo "$name de $first_name $surname : <a href=\"$URL_BASE/file/$file_id\">Télécharger</a><br />";
}
?>
2019-09-02 22:01:54 +00:00
<?php if ($team_data["final_selection"]) { ?>
<hr />
<h2>Autorisations pour la finale</h2>
<?php
while (($data = $documents_req->fetch()) !== false) {
$file_id = $data["file_id"];
$type = $data["type"];
$user_id = $data["user"];
$user_data = $DB->query("SELECT `surname`, `first_name` FROM `users` WHERE `id` = '$user_id';")->fetch();
$surname = $user_data["surname"];
$first_name = $user_data["first_name"];
$version = $data["version"];
switch ($data["type"]) {
case "PARENTAL_CONSENT":
$name = "Autorisation parentale";
break;
case "PHOTO_CONSENT":
$name = "Autorisation de droit à l'image";
break;
case "SANITARY_PLUG":
$name = "Fiche sanitaire";
break;
}
echo "$name de $first_name $surname : <a href=\"$URL_BASE/file/$file_id\">Télécharger</a><br />";
}
}
if ($team_data["validation_status"] == "WAITING" && $_SESSION["role"] == "ADMIN") { ?>
<form method="POST">
2019-09-02 22:01:54 +00:00
<input style="width: 100%;" type="submit" name="validate" value="Valider l'équipe" />
</form>
<?php
}
if (!$team_data["final_selection"]) { ?>
<form method="POST">
<input style="width: 100%;" type="submit" name="select" value="Sélectionner pour la finale nationale" />
</form>
<?php } ?>
2019-08-21 20:56:46 +00:00
<?php include "footer.php" ?>