2019-09-09 23:48:52 +00:00
|
|
|
<?php
|
|
|
|
|
2019-09-19 22:02:01 +00:00
|
|
|
if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::ADMIN)
|
|
|
|
require_once "server_files/403.php";
|
2019-09-09 23:48:52 +00:00
|
|
|
|
|
|
|
$trigram = htmlspecialchars($_GET["trigram"]);
|
|
|
|
|
|
|
|
$team = Team::fromTrigram($trigram);
|
|
|
|
|
|
|
|
if ($team === null)
|
|
|
|
require_once "server_files/404.php";
|
|
|
|
|
|
|
|
if (isset($_POST["validate"])) {
|
2019-09-25 21:47:02 +00:00
|
|
|
$team->setValidationStatus(ValidationStatus::VALIDATED);
|
2019-10-21 21:48:24 +00:00
|
|
|
Mailer::sendValidateTeam($team, $_POST["message"]);
|
2019-09-25 21:47:02 +00:00
|
|
|
}
|
|
|
|
elseif (isset($_POST["unvalidate"])) {
|
|
|
|
$team->setValidationStatus(ValidationStatus::NOT_READY);
|
2019-10-21 21:48:24 +00:00
|
|
|
Mailer::sendUnvalidateTeam($team, $_POST["message"]);
|
2019-09-09 23:48:52 +00:00
|
|
|
}
|
2019-10-06 11:29:20 +00:00
|
|
|
elseif (isset($_POST["select_problem"])) {
|
|
|
|
if ($team->getValidationStatus() == ValidationStatus::NOT_READY) {
|
|
|
|
$problem = $_POST["select_problem"];
|
|
|
|
if (preg_match("#[0-4]#", $problem)) {
|
|
|
|
$team->setProblem($problem);
|
|
|
|
$DB->prepare("UPDATE `documents` SET `problem` = ? WHERE `team` = ?;")->execute([$problem, $team->getId()]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$has_error = true;
|
|
|
|
$error_message = "Le problème indiqué n'existe pas.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$has_error = true;
|
|
|
|
$error_message = "Cette équipe est déjà validée ou en cours de validation.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif (isset($_POST["delete_team"])) {
|
|
|
|
if ($team->getValidationStatus() == ValidationStatus::NOT_READY) {
|
|
|
|
$documents = Document::getAllDocuments($team->getProblem(), $team->getId());
|
|
|
|
/** @var Document $doc */
|
|
|
|
foreach ($documents as $doc)
|
|
|
|
unlink($LOCAL_PATH . "/files/" . $doc->getFileId());
|
|
|
|
$DB->prepare("DELETE FROM `documents` WHERE `team` = ?;")->execute([$team->getId()]);
|
|
|
|
$DB->prepare("DELETE FROM `teams` WHERE `id` = ?;")->execute([$team->getId()]);
|
|
|
|
$DB->prepare("UPDATE `users` SET `team_id` = NULL WHERE `team_id` = ?;")->execute([$team->getId()]);
|
|
|
|
header("Location: /");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$has_error = true;
|
|
|
|
$error_message = "Cette équipe est déjà validée ou en cours de validation.";
|
|
|
|
}
|
|
|
|
}
|
2019-09-09 23:48:52 +00:00
|
|
|
|
|
|
|
if (isset($_POST["download_zip"])) {
|
2019-09-12 14:01:40 +00:00
|
|
|
$file_name = getZipFile($team->getProblem(), $team->getId());
|
2019-09-09 23:48:52 +00:00
|
|
|
|
|
|
|
header("Content-Type: application/zip");
|
|
|
|
header("Content-Disposition: attachment; filename=\"Documents de l'équipe " . $team->getTrigram() . ".zip\"");
|
|
|
|
header("Content-Length: " . strval(filesize($file_name)));
|
|
|
|
|
|
|
|
readfile($file_name);
|
|
|
|
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2019-09-19 22:02:01 +00:00
|
|
|
if (isset($_POST["update_video_teams"])) {
|
|
|
|
$update_video_teams = new UpdateVideoTeams($_POST);
|
|
|
|
try {
|
|
|
|
$update_video_teams->makeVerifications();
|
|
|
|
$update_video_teams->update();
|
|
|
|
} catch (AssertionError $e) {
|
|
|
|
$has_error = true;
|
|
|
|
$error_message = $e->getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class UpdateVideoTeams
|
|
|
|
{
|
|
|
|
private $other_teams;
|
|
|
|
|
|
|
|
public function __construct($data)
|
|
|
|
{
|
|
|
|
foreach ($data as $key => $value)
|
|
|
|
$this->$key = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function makeVerifications()
|
|
|
|
{
|
2020-01-01 20:41:22 +00:00
|
|
|
global $team;
|
|
|
|
|
|
|
|
ensure(Phase::getCurrentPhase() > Phase::PHASE2, "Il est trop tard pour réaffecter les vidéos aux équipes.");
|
|
|
|
ensure($team->getSolution() != null, "L'équipe doit avoir soumis une vidéo.");
|
|
|
|
ensure($team->getSolution()->getValidation() == ValidationStatus::VALIDATED - 1, "L'équipe doit avoir soumis une vidéo validée.");
|
2019-09-19 22:02:01 +00:00
|
|
|
ensure(sizeof($this->other_teams) == 2, "L'équipe doit recevoir exactement deux vidéos.");
|
|
|
|
ensure(Team::fromId($this->other_teams[0]) != null, "La première équipe n'existe pas.");
|
|
|
|
ensure(Team::fromId($this->other_teams[1]) != null, "La seconde équipe n'existe pas.");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function update()
|
|
|
|
{
|
|
|
|
global $team;
|
|
|
|
|
|
|
|
$team->setVideoTeamIds($this->other_teams);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-01 20:41:22 +00:00
|
|
|
$other_teams = Team::getAllTeams($team->getProblem(), true, true);
|
2019-09-12 14:01:40 +00:00
|
|
|
$documents = Document::getAllDocuments($team->getProblem(), $team->getId());
|
2019-09-09 23:48:52 +00:00
|
|
|
|
|
|
|
require_once "server_files/views/equipe.php";
|