2019-09-06 11:48:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (isset($_POST["leave_team"])) {
|
|
|
|
quitTeam();
|
2019-09-06 23:33:05 +00:00
|
|
|
exit();
|
2019-09-06 11:48:50 +00:00
|
|
|
}
|
|
|
|
|
2019-09-07 23:35:05 +00:00
|
|
|
$tournaments = Tournament::getAllTournaments(false, true);
|
2019-09-06 11:48:50 +00:00
|
|
|
|
2019-09-09 21:28:03 +00:00
|
|
|
$has_error = false;
|
|
|
|
$error_message = null;
|
|
|
|
|
|
|
|
if (isset($_POST["team_edit"])) {
|
|
|
|
$my_team = new MyTeam($_POST);
|
|
|
|
try {
|
|
|
|
$my_team->makeVerifications();
|
|
|
|
$my_team->updateTeam();
|
|
|
|
}
|
|
|
|
catch (AssertionError $e) {
|
|
|
|
$has_error = true;
|
|
|
|
$error_message = $e->getMessage();
|
|
|
|
}
|
2019-09-06 11:48:50 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 23:33:05 +00:00
|
|
|
if (isset($_SESSION["user_id"]) && isset($_SESSION["team"]) && $_SESSION["team"] !== null) {
|
2019-09-07 23:35:05 +00:00
|
|
|
/**
|
|
|
|
* @var User $user
|
|
|
|
* @var Team $team
|
|
|
|
*/
|
|
|
|
$user = $_SESSION["user"];
|
2019-09-06 23:33:05 +00:00
|
|
|
$team = $_SESSION["team"];
|
|
|
|
|
|
|
|
$tournament = Tournament::fromId($team->getTournamentId());
|
2020-01-16 21:04:29 +00:00
|
|
|
$documents = $tournament->getAllDocuments($team->getId());
|
2019-09-07 23:35:05 +00:00
|
|
|
if ($team->isSelectedForFinal())
|
2020-01-16 21:04:29 +00:00
|
|
|
$documents_final = $FINAL->getAllDocuments($team->getId());
|
2019-09-06 11:48:50 +00:00
|
|
|
}
|
|
|
|
else
|
2019-09-09 21:28:03 +00:00
|
|
|
require_once "server_files/403.php";
|
2019-09-06 11:48:50 +00:00
|
|
|
|
2020-01-16 21:04:29 +00:00
|
|
|
if (isset($_POST["request_validation"])) {
|
|
|
|
if (!canValidate($team, $tournament))
|
|
|
|
$error_message = "Votre équipe ne peut pas demander la validation : il manque soit des participants, soit des documents.";
|
2020-01-16 22:00:31 +00:00
|
|
|
else {
|
2020-01-16 21:04:29 +00:00
|
|
|
$team->setValidationStatus(ValidationStatus::WAITING);
|
2020-01-16 22:00:31 +00:00
|
|
|
Mailer::sendRequestValidationMail($team, $team->isSelectedForFinal() ? $FINAL : $tournament);
|
|
|
|
}
|
2020-01-16 21:04:29 +00:00
|
|
|
}
|
|
|
|
|
2020-05-04 23:06:57 +00:00
|
|
|
$DUMPS = [
|
|
|
|
["TKT", 6, "PGA", 3, "IRD", 1],
|
|
|
|
["OUI", 8, "LEP", 1, "REX", 7],
|
|
|
|
["ASP", 1, "ABC", 3, "TDP", 6],
|
|
|
|
["GIF", 8, "ETM", 1, "LPC", 3],
|
|
|
|
["MST", 6, "LQF", 1, "WAL", 2],
|
|
|
|
];
|
|
|
|
|
|
|
|
$DUMPS_2 = [
|
|
|
|
["TKT", 4, "PGA", 1, "IRD", 6],
|
|
|
|
["LEP", 6, "OUI", 5, "REX", 8],
|
|
|
|
["ASP", 5, "ABC", 8, "TDP", 4],
|
|
|
|
["ETM", 8, "LPC", 4, "GIF", 6],
|
|
|
|
["MST", 5, "LQF", 4, "WAL", 8],
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($DUMPS as $dump) {
|
|
|
|
$team1 = Team::fromTrigram($dump[0]);
|
|
|
|
$team2 = Team::fromTrigram($dump[2]);
|
|
|
|
$team3 = Team::fromTrigram($dump[4]);
|
|
|
|
$problem1 = $dump[1];
|
|
|
|
$problem2 = $dump[3];
|
|
|
|
$problem3 = $dump[5];
|
|
|
|
|
|
|
|
$req1 = $DB->prepare("SELECT * FROM `solutions` WHERE `team` = ? AND `problem` = ? ORDER BY uploaded_at DESC LIMIT 1");
|
|
|
|
$req1->execute([$team1->getId(), $problem1]);
|
|
|
|
$data1 = $req1->fetch();
|
|
|
|
$sol1 = Solution::fromData($data1);
|
|
|
|
$req2 = $DB->prepare("SELECT * FROM `solutions` WHERE `team` = ? AND `problem` = ? ORDER BY uploaded_at DESC LIMIT 1");
|
|
|
|
$req2->execute([$team2->getId(), $problem2]);
|
|
|
|
$data2 = $req2->fetch();
|
|
|
|
$sol2 = Solution::fromData($data2);
|
|
|
|
$req3 = $DB->prepare("SELECT * FROM `solutions` WHERE `team` = ? AND `problem` = ? ORDER BY uploaded_at DESC LIMIT 1");
|
|
|
|
$req3->execute([$team3->getId(), $problem3]);
|
|
|
|
$data3 = $req3->fetch();
|
|
|
|
$sol3 = Solution::fromData($data3);
|
|
|
|
|
|
|
|
$req1 = $DB->prepare("UPDATE `teams` SET `opposed_problem` = ?, `rapported_problem` = ? WHERE `id` = ?;");
|
|
|
|
$req1->execute([$sol2->getFileId(), $sol3->getFileId(), $team1->getId()]);
|
|
|
|
|
|
|
|
$req2 = $DB->prepare("UPDATE `teams` SET `opposed_problem` = ?, `rapported_problem` = ? WHERE `id` = ?;");
|
|
|
|
$req2->execute([$sol3->getFileId(), $sol1->getFileId(), $team2->getId()]);
|
|
|
|
|
|
|
|
$req3 = $DB->prepare("UPDATE `teams` SET `opposed_problem` = ?, `rapported_problem` = ? WHERE `id` = ?;");
|
|
|
|
$req3->execute([$sol1->getFileId(), $sol2->getFileId(), $team3->getId()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($DUMPS_2 as $dump) {
|
|
|
|
$team1 = Team::fromTrigram($dump[0]);
|
|
|
|
$team2 = Team::fromTrigram($dump[2]);
|
|
|
|
$team3 = Team::fromTrigram($dump[4]);
|
|
|
|
$problem1 = $dump[1];
|
|
|
|
$problem2 = $dump[3];
|
|
|
|
$problem3 = $dump[5];
|
|
|
|
|
|
|
|
$req1 = $DB->prepare("SELECT * FROM `solutions` WHERE `team` = ? AND `problem` = ? ORDER BY uploaded_at DESC LIMIT 1");
|
|
|
|
$req1->execute([$team1->getId(), $problem1]);
|
|
|
|
$data1 = $req1->fetch();
|
|
|
|
$sol1 = Solution::fromData($data1);
|
|
|
|
$req2 = $DB->prepare("SELECT * FROM `solutions` WHERE `team` = ? AND `problem` = ? ORDER BY uploaded_at DESC LIMIT 1");
|
|
|
|
$req2->execute([$team2->getId(), $problem2]);
|
|
|
|
$data2 = $req2->fetch();
|
|
|
|
$sol2 = Solution::fromData($data2);
|
|
|
|
$req3 = $DB->prepare("SELECT * FROM `solutions` WHERE `team` = ? AND `problem` = ? ORDER BY uploaded_at DESC LIMIT 1");
|
|
|
|
$req3->execute([$team3->getId(), $problem3]);
|
|
|
|
$data3 = $req3->fetch();
|
|
|
|
$sol3 = Solution::fromData($data3);
|
|
|
|
|
|
|
|
$req1 = $DB->prepare("UPDATE `teams` SET `opposed_problem_2` = ?, `rapported_problem_2` = ? WHERE `id` = ?;");
|
|
|
|
$req1->execute([$sol2->getFileId(), $sol3->getFileId(), $team1->getId()]);
|
|
|
|
|
|
|
|
$req2 = $DB->prepare("UPDATE `teams` SET `opposed_problem_2` = ?, `rapported_problem_2` = ? WHERE `id` = ?;");
|
|
|
|
$req2->execute([$sol3->getFileId(), $sol1->getFileId(), $team2->getId()]);
|
|
|
|
|
|
|
|
$req3 = $DB->prepare("UPDATE `teams` SET `opposed_problem_2` = ?, `rapported_problem_2` = ? WHERE `id` = ?;");
|
|
|
|
$req3->execute([$sol1->getFileId(), $sol2->getFileId(), $team3->getId()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$req = $DB->prepare("SELECT opposed_problem, rapported_problem, opposed_problem_2, rapported_problem_2 FROM teams WHERE id = ?;");
|
|
|
|
$req->execute([$team->getId()]);
|
|
|
|
$data = $req->fetch();
|
|
|
|
|
|
|
|
$opposed_solution = Solution::fromId($data["opposed_problem"]);
|
|
|
|
$rapported_solution = Solution::fromId($data["rapported_problem"]);
|
|
|
|
$opposed_solution_2 = Solution::fromId($data["opposed_problem_2"]);
|
|
|
|
$rapported_solution_2 = Solution::fromId($data["rapported_problem_2"]);
|
|
|
|
|
2019-09-09 21:28:03 +00:00
|
|
|
class MyTeam
|
2019-09-06 11:48:50 +00:00
|
|
|
{
|
2019-09-09 21:28:03 +00:00
|
|
|
public $name;
|
|
|
|
public $trigram;
|
|
|
|
public $tournament_id;
|
|
|
|
private $team;
|
|
|
|
private $tournament;
|
|
|
|
|
|
|
|
public function __construct($data)
|
|
|
|
{
|
|
|
|
foreach ($data as $key => $value)
|
|
|
|
$this->$key = htmlspecialchars($value);
|
|
|
|
|
|
|
|
$this->trigram = strtoupper($this->trigram);
|
|
|
|
$this->team = $_SESSION["team"];
|
|
|
|
$this->tournament = Tournament::fromId($this->tournament_id);
|
|
|
|
}
|
2019-09-06 11:48:50 +00:00
|
|
|
|
2019-09-09 21:28:03 +00:00
|
|
|
public function makeVerifications()
|
|
|
|
{
|
|
|
|
ensure($this->name != "" && $this->name != null, "Veuillez spécifier un nom d'équipe.");
|
|
|
|
ensure($this->name == $this->team->getName() || !teamExists($this->name), "Une équipe existe déjà avec ce nom.");
|
|
|
|
ensure(preg_match("#^[A-Z]{3}$#", $this->trigram), "Le trigramme n'est pas valide.");
|
|
|
|
ensure($this->trigram == $this->team->getTrigram() || !trigramExists($this->trigram), "Une équipe a déjà choisi ce trigramme.");
|
|
|
|
ensure($this->tournament != null, "Le tournoi indiqué n'existe pas.");
|
2020-01-01 21:41:08 +00:00
|
|
|
ensure(date("Y-m-d H:i:s") <= $this->tournament->getInscriptionDate(), "Les inscriptions sont terminées.");
|
2019-09-09 21:28:03 +00:00
|
|
|
ensure($this->team->getValidationStatus() == ValidationStatus::NOT_READY, "Votre équipe est déjà validée ou en cours de validation.");
|
2019-09-06 11:48:50 +00:00
|
|
|
}
|
2019-09-09 21:28:03 +00:00
|
|
|
|
|
|
|
public function updateTeam()
|
|
|
|
{
|
2020-04-13 01:41:15 +00:00
|
|
|
global $URL_BASE, $DB;
|
2019-09-09 21:28:03 +00:00
|
|
|
|
|
|
|
$this->team->setName($this->name);
|
|
|
|
$this->team->setTrigram($this->trigram);
|
|
|
|
$this->team->setTournamentId($this->tournament_id);
|
|
|
|
|
2020-04-13 01:41:15 +00:00
|
|
|
$DB->prepare("UPDATE `documents` SET `tournament` = ? WHERE `team` = ?;")->execute([$this->tournament_id, $this->team->getId()]);
|
|
|
|
$DB->prepare("UPDATE `solutions` SET `tournament` = ? WHERE `team` = ?;")->execute([$this->tournament_id, $this->team->getId()]);
|
|
|
|
$DB->prepare("UPDATE `syntheses` SET `tournament` = ? WHERE `team` = ?;")->execute([$this->tournament_id, $this->team->getId()]);
|
|
|
|
foreach ($this->team->getParticipants() as $user) {
|
|
|
|
if ($user != null)
|
|
|
|
$DB->prepare("UPDATE `payments` SET `tournament` = ? WHERE `user` = ?;")->execute([$this->tournament_id, $user]);
|
|
|
|
}
|
|
|
|
foreach ($this->team->getEncadrants() as $user) {
|
|
|
|
if ($user != null)
|
|
|
|
$DB->prepare("UPDATE `payments` SET `tournament` = ? WHERE `user` = ?;")->execute([$this->tournament_id, $user]);
|
|
|
|
}
|
|
|
|
|
2019-09-09 21:28:03 +00:00
|
|
|
$_SESSION["tournament"] = $this->tournament;
|
|
|
|
|
2019-12-19 12:02:01 +00:00
|
|
|
header("Location: $URL_BASE/mon-equipe");
|
2019-09-06 11:48:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-07 11:42:36 +00:00
|
|
|
require_once "server_files/views/mon_equipe.php";
|