mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-27 21:02:22 +00:00
201 lines
7.7 KiB
PHP
201 lines
7.7 KiB
PHP
|
<?php
|
||
|
|
||
|
include 'config.php';
|
||
|
|
||
|
if (isset($_POST["leave_team"])) {
|
||
|
for ($i = 1; $i <= ($_SESSION["role"] == "PARTICIPANT" ? 6 : 2); ++$i)
|
||
|
/** @noinspection SqlResolve */
|
||
|
$DB->exec("UPDATE `teams` SET `" . strtolower($_SESSION["role"]) . "_$i` = NULL WHERE `" . strtolower($_SESSION["role"]) . "_$i` = " . $_SESSION["user_id"] . ";");
|
||
|
$DB->exec("UPDATE `users` SET `team_id` = NULL WHERE `id` = " . $_SESSION["user_id"] . ";");
|
||
|
$DB->exec("UPDATE `teams` SET `encadrant_1` = `encadrant_2`, `encadrant_2` = NULL WHERE `encadrant_1` IS NULL;");
|
||
|
for ($i = 1; $i <= 5; ++$i) {
|
||
|
/** @noinspection SqlResolve */
|
||
|
$DB->exec("UPDATE `teams` SET `participant_$i` = `participant_" . strval($i + 1) . "`, `participant_" . strval($i + 1) . "` = NULL WHERE `participant_$i` IS NULL;");
|
||
|
}
|
||
|
|
||
|
$req = $DB->query("SELECT `file_id` FROM `documents` WHERE `user` = '" . $_SESSION["user_id"] . "';");
|
||
|
while (($data = $req->fetch()) !== false)
|
||
|
unlink("$URL_BASE/files/" . $data["file_id"]);
|
||
|
$DB->exec("DELETE FROM `documents` WHERE `user` = '" . $_SESSION["user_id"] . "';");
|
||
|
|
||
|
if ($DB->exec("DELETE FROM `teams` WHERE `encadrant_1` IS NULL AND `participant_1` IS NULL;") > 0) {
|
||
|
$req = $DB->query("SELECT `file_id` FROM `solutions` WHERE `team` = '" . $_SESSION["team_id"] . "';");
|
||
|
while (($data = $req->fetch()) !== false)
|
||
|
unlink("$URL_BASE/files/" . $data["file_id"]);
|
||
|
$DB->exec("DELETE FROM `solutions` WHERE `team` = " . $_SESSION["team_id"] . ";");
|
||
|
|
||
|
$req = $DB->query("SELECT `file_id` FROM `syntheses` WHERE `team` = '" . $_SESSION["team_id"] . "';");
|
||
|
while (($data = $req->fetch()) !== false)
|
||
|
unlink("$URL_BASE/files/" . $data["file_id"]);
|
||
|
$DB->exec("DELETE FROM `syntheses` WHERE `team` = " . $_SESSION["team_id"] . ";");
|
||
|
}
|
||
|
unset($_SESSION["team_id"]);
|
||
|
unset($_SESSION["team_validation_status"]);
|
||
|
header("Location: $URL_BASE");
|
||
|
exit();
|
||
|
}
|
||
|
|
||
|
if (isset($_POST["send_document"])) {
|
||
|
sendDocument();
|
||
|
}
|
||
|
|
||
|
if (isset($_POST["request_validation"])) {
|
||
|
$DB->exec("UPDATE `teams` SET `validation_status` = 'WAITING' WHERE `id` = " . $_SESSION["team_id"] . ";");
|
||
|
$_SESSION["team_validation_status"] = "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();
|
||
|
|
||
|
$documents_req = $DB->prepare("SELECT `file_id`, `type`, COUNT(`type`) AS `version` FROM `documents` WHERE `user` = ? GROUP BY `type` ORDER BY `type` ASC, `uploaded_at` DESC;");
|
||
|
$documents_req->execute([$_SESSION["user_id"]]);
|
||
|
}
|
||
|
|
||
|
function sendDocument() {
|
||
|
global $LOCAL_PATH, $DB;
|
||
|
|
||
|
$type = strtoupper(htmlspecialchars($_POST["type"]));
|
||
|
if (!isset($type) || ($type != "PARENTAL_CONSENT" && $type != "PHOTO_CONSENT" && $type != "SANITARY_PLUG"))
|
||
|
return "Le type de document est invalide. Merci de ne pas formuler vos propres requêtes.";
|
||
|
|
||
|
$file = $_FILES["document"];
|
||
|
|
||
|
if ($file["size"] > 5000000 || $file["error"])
|
||
|
return "Une erreur est survenue. Merci de vérifier que le fichier pèse moins que 5 Mo.";
|
||
|
|
||
|
if (finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file["tmp_name"]) != 'application/pdf')
|
||
|
return "Le fichier doit être au format PDF.";
|
||
|
|
||
|
if (!is_dir("$LOCAL_PATH/files") && !mkdir("$LOCAL_PATH/files"))
|
||
|
return "Les droits sont insuffisants. Veuillez contacter l'administrateur du serveur.";
|
||
|
|
||
|
$alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||
|
|
||
|
do {
|
||
|
$id = "";
|
||
|
for ($i = 0; $i < 64; ++$i) {
|
||
|
$id .= $alphabet[rand(0, strlen($alphabet) - 1)];
|
||
|
}
|
||
|
}
|
||
|
while (file_exists("$LOCAL_PATH/files/$id"));
|
||
|
|
||
|
if (!rename($file["tmp_name"], "$LOCAL_PATH/files/$id"))
|
||
|
return "Une erreur est survenue lors de l'envoi du fichier.";
|
||
|
|
||
|
$req = $DB->prepare("INSERT INTO `documents`(`file_id`, `user`, `team`, `tournament`, `type`)
|
||
|
VALUES (?, ?, ?, ?, ?);");
|
||
|
$req->execute([$id, $_SESSION["user_id"], $_SESSION["team_id"], $_SESSION["tournament_id"], $type]);
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
?>
|
||
|
|
||
|
<?php include "header.php" ?>
|
||
|
|
||
|
<?php if (!isset($_SESSION["user_id"]) || !isset($_SESSION["team_id"]) || $_SESSION["team_id"] == NULL) {
|
||
|
echo "<h2>Vous devez être dans une équipe pour afficher cette page.</h2>";
|
||
|
include "footer.php";
|
||
|
return;
|
||
|
} ?>
|
||
|
|
||
|
<?php if (isset($error_message)) {
|
||
|
if ($error_message !== false) {
|
||
|
echo "<h2>Erreur : " . $error_message . "</h2>";
|
||
|
}
|
||
|
else {
|
||
|
echo "<h2>Le fichier a été correctement envoyé !</h2>";
|
||
|
}
|
||
|
}?>
|
||
|
|
||
|
<h2>Informations sur l'équipe</h2>
|
||
|
|
||
|
Nom de l'équipe : <?php echo $team_data["name"] ?><br />
|
||
|
Trigramme : <?php echo $team_data["trigram"] ?><br />
|
||
|
Tournoi : <?php echo $tournament_data["name"] ?><br />
|
||
|
<?php
|
||
|
for ($i = 1; $i <= 2; ++$i) {
|
||
|
if ($team_data["encadrant_" . $i] == NULL)
|
||
|
continue;
|
||
|
$user_data = $DB->query("SELECT `surname`, `first_name` FROM `users` WHERE `id` = " . $team_data["encadrant_" . $i] . " AND `year` = '$YEAR';")->fetch();
|
||
|
echo "Encadrant $i : " . $user_data["first_name"] . " " . $user_data["surname"] . "<br />";
|
||
|
}
|
||
|
for ($i = 1; $i <= 6; ++$i) {
|
||
|
if ($team_data["participant_" . $i] == NULL)
|
||
|
continue;
|
||
|
$user_data = $DB->query("SELECT `surname`, `first_name` FROM `users` WHERE `id` = " . $team_data["participant_" . $i] . " AND `year` = '$YEAR';")->fetch();
|
||
|
echo "Participant $i : " . $user_data["first_name"] . " " . $user_data["surname"] . "<br />";
|
||
|
}
|
||
|
?>
|
||
|
Code d'accès : <strong><?php echo $team_data["access_code"] ?></strong>
|
||
|
|
||
|
<?php if ($_SESSION["team_validation_status"] == "NOT_READY") { ?>
|
||
|
<hr />
|
||
|
<h2>Mes autorisations</h2>
|
||
|
<?php
|
||
|
while (($data = $documents_req->fetch()) !== false) {
|
||
|
$file_id = $data["file_id"];
|
||
|
$type = $data["type"];
|
||
|
$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 : <a href=\"$URL_BASE/file/$file_id\">Télécharger</a><br />";
|
||
|
}
|
||
|
?>
|
||
|
|
||
|
<form method="post" enctype="multipart/form-data">
|
||
|
<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
|
||
|
<table>
|
||
|
<tbody>
|
||
|
<tr>
|
||
|
<td>
|
||
|
<label for="type">Type de document :</label>
|
||
|
</td>
|
||
|
<td>
|
||
|
<select id="type" name="type">
|
||
|
<?php if ($_SESSION["birth_date"] > strval($YEAR - 18) . substr($tournament_data["date_start"], 4)) { ?>
|
||
|
<option value="parental_consent">Autorisation parentale</option>
|
||
|
<?php } ?>
|
||
|
<option value="photo_consent">Autorisation de droit à l'image</option>
|
||
|
<option value="sanitary_plug">Fiche sanitaire</option>
|
||
|
</select>
|
||
|
</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td>
|
||
|
<label for="file">Fichier :</label>
|
||
|
</td>
|
||
|
<td>
|
||
|
<input type="file" id="file" name="document" />
|
||
|
</td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td colspan="2">
|
||
|
<input style="width: 100%;" type="submit" name="send_document" value="Envoyer" />
|
||
|
</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</form>
|
||
|
<form method="post">
|
||
|
<input type="submit" name="leave_team" value="Quitter l'équipe" />
|
||
|
</form>
|
||
|
<form method="post">
|
||
|
<input type="submit" name="request_validation" value="Demander la validation" />
|
||
|
</form>
|
||
|
<?php } ?>
|
||
|
|
||
|
<?php include "footer.php" ?>
|