1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-11-27 12:13:01 +00:00
plateforme-tfjm2/server_files/controllers/equipe.php

79 lines
3.1 KiB
PHP
Raw Normal View History

2019-09-06 11:48:50 +00:00
<?php
require_once "../config.php";
if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::ORGANIZER && $_SESSION["role"] != Role::ADMIN)
require_once "../403.php";
2019-09-06 11:48:50 +00:00
$trigram = htmlspecialchars($_GET["trigram"]);
$team = Team::fromTrigram($trigram);
if ($team === null)
require_once "../404.php";
2019-09-06 11:48:50 +00:00
if (isset($_POST["validate"])) {
$team->setValidationStatus(ValidationStatus::VALIDATED);
2019-09-06 11:48:50 +00:00
}
if (isset($_POST["select"])) {
$team->selectForFinal(true);
$team->setValidationStatus(ValidationStatus::NOT_READY);
$_SESSION["final"] = Tournament::getFinalTournament();
2019-09-06 11:48:50 +00:00
$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->getId(), $team->getTournamentId()]);
2019-09-06 11:48:50 +00:00
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->getId(), $_SESSION["final_id"], $sol_data["problem"]]);
2019-09-06 11:48:50 +00:00
}
$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->getId(), $team->getTournamentId()]);
2019-09-06 11:48:50 +00:00
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->getId(), $_SESSION["final"]->getId(), $synthese_data["dest"]]);
2019-09-06 11:48:50 +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->getId(), $team->getId()]);
2019-09-06 11:48:50 +00:00
if ($team->isSelectedForFinal()) {
2019-09-06 11:48:50 +00:00
$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->getId(), $_SESSION["final"]->getId()]);
2019-09-06 11:48:50 +00:00
}
$tournament = Tournament::fromId($team->getTournamentId());
2019-09-06 11:48:50 +00:00
require_once "../views/header.php";
require_once "../views/equipe.php";
require_once "../views/footer.php";