mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 07:42:11 +01:00 
			
		
		
		
	Utilisation des nouvelles classes, amélioration du code
This commit is contained in:
		@@ -4,6 +4,7 @@ require_once "../config.php";
 | 
			
		||||
 | 
			
		||||
if (isset($_POST["leave_team"])) {
 | 
			
		||||
	quitTeam();
 | 
			
		||||
	exit();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$tournaments_response = $DB->query("SELECT `id`, `name` FROM `tournaments` WHERE `year` = '$YEAR';");
 | 
			
		||||
@@ -15,20 +16,18 @@ if (isset($_POST["send_document"])) {
 | 
			
		||||
if (isset($_POST["request_validation"])) {
 | 
			
		||||
	if (!checkCanValidate())
 | 
			
		||||
		$error_message = "Votre équipe ne peut pas demander la validation : il manque soit des participants, soit des documents.";
 | 
			
		||||
	else {
 | 
			
		||||
		$DB->exec("UPDATE `teams` SET `validation_status` = 'WAITING' WHERE `id` = " . $_SESSION["team_id"] . ";");
 | 
			
		||||
		$_SESSION["team_validation_status"] = "WAITING";
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
		$_SESSION["team"]->setValidationStatus(ValidationStatus::WAITING);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if (isset($_SESSION["user_id"]) && isset($_SESSION["team_id"])) {
 | 
			
		||||
	$result = $DB->query("SELECT * FROM `teams` WHERE `id` = '" . $_SESSION["team_id"] . "' AND `year` = '$YEAR';");
 | 
			
		||||
	$team_data = $result->fetch();
 | 
			
		||||
	
 | 
			
		||||
	$tournament_data = $DB->query("SELECT `name`, `date_start` FROM `tournaments` WHERE `id` = '" . $team_data["tournament"] . "' AND `year` = '$YEAR';")->fetch();
 | 
			
		||||
	
 | 
			
		||||
if (isset($_SESSION["user_id"]) && isset($_SESSION["team"]) && $_SESSION["team"] !== null) {
 | 
			
		||||
	/** @var Team $team */
 | 
			
		||||
	$team = $_SESSION["team"];
 | 
			
		||||
 | 
			
		||||
	$tournament = Tournament::fromId($team->getTournamentId());
 | 
			
		||||
 | 
			
		||||
	$documents_req = $DB->prepare("SELECT `file_id`, `type`, COUNT(`type`) AS `version` FROM `documents` WHERE `user` = ? AND `tournament` = ? GROUP BY `type`, `uploaded_at` ORDER BY `type`, `uploaded_at` DESC;");
 | 
			
		||||
	$documents_req->execute([$_SESSION["user_id"], $_SESSION[isset($_SESSION["final_id"]) ? "final_id" : "tournament_id"]]);
 | 
			
		||||
	$documents_req->execute([$_SESSION["user_id"], $_SESSION[$team->isSelectedForFinal() ? $_SESSION["final"]->getId() : $tournament->getId()]]);
 | 
			
		||||
}
 | 
			
		||||
else
 | 
			
		||||
    require_once "../403.php";
 | 
			
		||||
@@ -77,39 +76,35 @@ function sendDocument()
 | 
			
		||||
 | 
			
		||||
function updateTeam()
 | 
			
		||||
{
 | 
			
		||||
	global $DB, $YEAR, $URL_BASE, $team_data;
 | 
			
		||||
	
 | 
			
		||||
	if ($_SESSION["team_id"] == NULL)
 | 
			
		||||
		return "Vous n'êtes pas dans une équipe.";
 | 
			
		||||
	
 | 
			
		||||
	global $DB, $YEAR, $URL_BASE, $team;
 | 
			
		||||
 | 
			
		||||
	$name = htmlspecialchars($_POST["name"]);
 | 
			
		||||
	
 | 
			
		||||
	if (!isset($name) || $name == "")
 | 
			
		||||
		return "Vous devez spécifier un nom d'équipe.";
 | 
			
		||||
	
 | 
			
		||||
	echo $team_data["id"];
 | 
			
		||||
	$result = $DB->query("SELECT `id` FROM `teams` WHERE `name` = '" . $name . "' AND `id` != " . $team_data["id"] . " AND `year` = '$YEAR';");
 | 
			
		||||
 | 
			
		||||
	$result = $DB->query("SELECT `id` FROM `teams` WHERE `name` = '" . $name . "' AND `id` != " . $team->getId() . " AND `year` = '$YEAR';");
 | 
			
		||||
	if ($result->fetch())
 | 
			
		||||
		return "Une équipe existe déjà avec ce nom." . $team_data["id"];
 | 
			
		||||
		return "Une équipe existe déjà avec ce nom.";
 | 
			
		||||
	
 | 
			
		||||
	$trigram = strtoupper(htmlspecialchars($_POST["trigram"]));
 | 
			
		||||
	
 | 
			
		||||
	if (!preg_match("#^[A-Z][A-Z][A-Z]$#", $trigram))
 | 
			
		||||
		return "Le trigramme entré n'est pas valide.";
 | 
			
		||||
	
 | 
			
		||||
	$result = $DB->query("SELECT `id` FROM `teams` WHERE `trigram` = '" . $trigram . "' AND `id` != '" . $team_data["id"] . "' AND `year` = '$YEAR';");
 | 
			
		||||
	$result = $DB->query("SELECT `id` FROM `teams` WHERE `trigram` = '" . $trigram . "' AND `id` != '" . $team->getId() . "' AND `year` = '$YEAR';");
 | 
			
		||||
	if ($result->fetch())
 | 
			
		||||
		return "Une équipe a déjà choisi ce trigramme.";
 | 
			
		||||
	
 | 
			
		||||
	$tournament_id = intval(htmlspecialchars($_POST["tournament"]));
 | 
			
		||||
	
 | 
			
		||||
	$result = $DB->query("SELECT `id`, `name` FROM `tournaments` WHERE `id` = '" . $tournament_id . "' AND `year` = '$YEAR';");
 | 
			
		||||
	$data = $result->fetch();
 | 
			
		||||
	if ($data === FALSE)
 | 
			
		||||
	$tournament = Tournament::fromId($tournament_id);
 | 
			
		||||
	if ($tournament === null)
 | 
			
		||||
		return "Le tournoi spécifié n'existe pas.";
 | 
			
		||||
	
 | 
			
		||||
	$req = $DB->prepare("UPDATE `teams` SET `name` = ?, `trigram` = ?, `tournament` = ? WHERE `id` = ?;");
 | 
			
		||||
	$req->execute([$name, $trigram, $tournament_id, $team_data["id"]]);
 | 
			
		||||
 | 
			
		||||
	$team->setName($name);
 | 
			
		||||
	$team->setTrigram($trigram);
 | 
			
		||||
	$team->setTournamentId($tournament_id);
 | 
			
		||||
	$_SESSION["tournament"] = $tournament;
 | 
			
		||||
	
 | 
			
		||||
	header("Location: $URL_BASE/mon_equipe");
 | 
			
		||||
	
 | 
			
		||||
@@ -118,42 +113,43 @@ function updateTeam()
 | 
			
		||||
 | 
			
		||||
function checkCanValidate()
 | 
			
		||||
{
 | 
			
		||||
	global $DB, $team_data, $tournament_data, $YEAR;
 | 
			
		||||
	$can_validate = $team_data["validation_status"] == "NOT_READY";
 | 
			
		||||
	$can_validate &= $team_data["encadrant_1"] != NULL;
 | 
			
		||||
	$can_validate &= $team_data["participant_4"] != NULL;
 | 
			
		||||
	global $DB, $team, $tournament, $YEAR;
 | 
			
		||||
 | 
			
		||||
	$can_validate = $team->getValidationStatus() == ValidationStatus::NOT_READY;
 | 
			
		||||
	$can_validate &= $team->getEncadrants()[0] != NULL;
 | 
			
		||||
	$can_validate &= $team->getParticipants()[3] != NULL;
 | 
			
		||||
	for ($i = 1; $i <= 2; ++$i) {
 | 
			
		||||
		if ($team_data["encadrant_$i"] === NULL)
 | 
			
		||||
		if ($team->getEncadrants()[$i - 1] === NULL)
 | 
			
		||||
			continue;
 | 
			
		||||
		
 | 
			
		||||
		$req = $DB->prepare("SELECT COUNT(`type`) AS `version` FROM `documents` WHERE `user` = ? AND `type` = ? GROUP BY `uploaded_at` ORDER BY `uploaded_at` DESC;");
 | 
			
		||||
		$req->execute([$team_data["encadrant_$i"], "PHOTO_CONSENT"]);
 | 
			
		||||
		$req->execute([$team->getEncadrants()[$i - 1], "PHOTO_CONSENT"]);
 | 
			
		||||
		$d = $req->fetch();
 | 
			
		||||
		$can_validate &= $d["version"] > 0;
 | 
			
		||||
		
 | 
			
		||||
		$req = $DB->prepare("SELECT COUNT(`type`) AS `version` FROM `documents` WHERE `user` = ? AND `type` = ? GROUP BY `uploaded_at` ORDER BY `uploaded_at` DESC;");
 | 
			
		||||
		$req->execute([$team_data["encadrant_$i"], "SANITARY_PLUG"]);
 | 
			
		||||
		$req->execute([$team->getEncadrants()[$i - 1], "SANITARY_PLUG"]);
 | 
			
		||||
		$d = $req->fetch();
 | 
			
		||||
		$can_validate &= $d["version"] > 0;
 | 
			
		||||
	}
 | 
			
		||||
	for ($i = 1; $i <= 6; ++$i) {
 | 
			
		||||
		if ($team_data["participant_$i"] === NULL)
 | 
			
		||||
		if ($team->getParticipants()[$i] === NULL)
 | 
			
		||||
			continue;
 | 
			
		||||
		
 | 
			
		||||
		$req = $DB->prepare("SELECT COUNT(`type`) AS `version` FROM `documents` WHERE `user` = ? AND `type` = ? GROUP BY `uploaded_at` ORDER BY `uploaded_at` DESC;");
 | 
			
		||||
		$req->execute([$team_data["participant_$i"], "PHOTO_CONSENT"]);
 | 
			
		||||
		$req->execute([$team->getParticipants()[$i], "PHOTO_CONSENT"]);
 | 
			
		||||
		$d = $req->fetch();
 | 
			
		||||
		$can_validate &= $d["version"] > 0;
 | 
			
		||||
		
 | 
			
		||||
		$req = $DB->prepare("SELECT COUNT(`type`) AS `version` FROM `documents` WHERE `user` = ? AND `type` = ? GROUP BY `uploaded_at` ORDER BY `uploaded_at` DESC;");
 | 
			
		||||
		$req->execute([$team_data["participant_$i"], "SANITARY_PLUG"]);
 | 
			
		||||
		$req->execute([$team->getParticipants()[$i], "SANITARY_PLUG"]);
 | 
			
		||||
		$d = $req->fetch();
 | 
			
		||||
		$can_validate &= $d["version"] > 0;
 | 
			
		||||
		
 | 
			
		||||
		$birth_date = $DB->query("SELECT `birth_date` FROM `users` WHERE `id` = " . $team_data["participant_$i"] . ";")->fetch()["birth_date"];
 | 
			
		||||
		if ($birth_date > strval($YEAR - 18) . substr($tournament_data["date_start"], 4)) {
 | 
			
		||||
		$birth_date = $DB->query("SELECT `birth_date` FROM `users` WHERE `id` = " . $team->getParticipants()[$i] . ";")->fetch()["birth_date"];
 | 
			
		||||
		if ($birth_date > strval($YEAR - 18) . substr($tournament->getStartDate(), 4)) {
 | 
			
		||||
			$req = $DB->prepare("SELECT COUNT(`type`) AS `version` FROM `documents` WHERE `user` = ? AND `type` = ? GROUP BY `uploaded_at` ORDER BY `uploaded_at` DESC;");
 | 
			
		||||
			$req->execute([$team_data["participant_$i"], "PARENTAL_CONSENT"]);
 | 
			
		||||
			$req->execute([$team->getParticipants()[$i], "PARENTAL_CONSENT"]);
 | 
			
		||||
			$d = $req->fetch();
 | 
			
		||||
			$can_validate &= $d["version"] > 0;
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user