Quelques vérifications temporelles et autres

This commit is contained in:
Yohann 2019-09-02 20:57:26 +02:00
parent 35aed16e10
commit 273bd05944
8 changed files with 320 additions and 220 deletions

View File

@ -2,7 +2,7 @@
include 'config.php'; include 'config.php';
$tournaments_response = $DB->query("SELECT `id`, `name` FROM `tournaments` WHERE `year` = '$YEAR';"); $tournaments_response = $DB->query("SELECT `id`, `name` FROM `tournaments` WHERE `date_inscription` > CURRENT_DATE AND `year` = '$YEAR';");
if (isset($_POST["submitted"])) { if (isset($_POST["submitted"])) {
$error_message = registerTeam(); $error_message = registerTeam();

View File

@ -57,4 +57,12 @@ function echo_date($date = NULL, $with_time = false) {
return strftime("%d %B %G" . ($with_time ? " %H:%M" : ""), strtotime($date)); return strftime("%d %B %G" . ($with_time ? " %H:%M" : ""), strtotime($date));
} }
function error403() {
include "../403.php";
}
function error404() {
include "../404.php";
}
?> ?>

View File

@ -11,7 +11,7 @@ if (isset($_POST["validate"])) {
$team_data = $DB->query("SELECT * FROM `teams` WHERE `trigram` = '$trigram' AND `year` = $YEAR;")->fetch(); $team_data = $DB->query("SELECT * FROM `teams` WHERE `trigram` = '$trigram' AND `year` = $YEAR;")->fetch();
if ($team_data === false) if ($team_data === false)
include "../404.php"; error404();
$tournament_data = $DB->query("SELECT `name`, `date_start` FROM `tournaments` WHERE `id` = '" . $team_data["tournament"] . "' AND `year` = '$YEAR';")->fetch(); $tournament_data = $DB->query("SELECT `name`, `date_start` FROM `tournaments` WHERE `id` = '" . $team_data["tournament"] . "' AND `year` = '$YEAR';")->fetch();

View File

@ -3,3 +3,4 @@
</div> </div>
</body> </body>
</html> </html>
<?php exit() ?>

View File

@ -3,14 +3,14 @@
include "config.php"; include "config.php";
if (!isset($_SESSION["role"]) || $_SESSION["role"] != "ORGANIZER" && $_SESSION["role"] != "ADMIN") { if (!isset($_SESSION["role"]) || $_SESSION["role"] != "ORGANIZER" && $_SESSION["role"] != "ADMIN") {
include "../403.php"; error403();
} }
$id = $_GET["id"]; $id = $_GET["id"];
$user_data = $DB->query("SELECT * FROM `users` WHERE `id` = $id;")->fetch(); $user_data = $DB->query("SELECT * FROM `users` WHERE `id` = $id;")->fetch();
if ($user_data === false) { if ($user_data === false) {
include "../404.php"; error404();
} }
$team_data = false; $team_data = false;

View File

@ -38,12 +38,16 @@ if (isset($_POST["leave_team"])) {
$tournaments_response = $DB->query("SELECT `id`, `name` FROM `tournaments` WHERE `year` = '$YEAR';"); $tournaments_response = $DB->query("SELECT `id`, `name` FROM `tournaments` WHERE `year` = '$YEAR';");
if (isset($_POST["send_document"])) { if (isset($_POST["send_document"])) {
sendDocument(); $error_message = sendDocument();
} }
if (isset($_POST["request_validation"])) { 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"] . ";"); $DB->exec("UPDATE `teams` SET `validation_status` = 'WAITING' WHERE `id` = " . $_SESSION["team_id"] . ";");
$_SESSION["team_validation_status"] = "WAITING"; $_SESSION["team_validation_status"] = "WAITING";
}
} }
if (isset($_SESSION["user_id"]) && isset($_SESSION["team_id"])) { if (isset($_SESSION["user_id"]) && isset($_SESSION["team_id"])) {
@ -52,7 +56,7 @@ if (isset($_SESSION["user_id"]) && isset($_SESSION["team_id"])) {
$tournament_data = $DB->query("SELECT `name`, `date_start` FROM `tournaments` WHERE `id` = '" . $team_data["tournament"] . "' AND `year` = '$YEAR';")->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 = $DB->prepare("SELECT `file_id`, `type`, COUNT(`type`) AS `version` FROM `documents` WHERE `user` = ? GROUP BY `type`, `uploaded_at` ORDER BY `type`, `uploaded_at` DESC;");
$documents_req->execute([$_SESSION["user_id"]]); $documents_req->execute([$_SESSION["user_id"]]);
} }
@ -60,7 +64,8 @@ if (isset($_POST["team_edit"])) {
$error_message = updateTeam(); $error_message = updateTeam();
} }
function sendDocument() { function sendDocument()
{
global $LOCAL_PATH, $DB; global $LOCAL_PATH, $DB;
$type = strtoupper(htmlspecialchars($_POST["type"])); $type = strtoupper(htmlspecialchars($_POST["type"]));
@ -85,8 +90,7 @@ function sendDocument() {
for ($i = 0; $i < 64; ++$i) { for ($i = 0; $i < 64; ++$i) {
$id .= $alphabet[rand(0, strlen($alphabet) - 1)]; $id .= $alphabet[rand(0, strlen($alphabet) - 1)];
} }
} } while (file_exists("$LOCAL_PATH/files/$id"));
while (file_exists("$LOCAL_PATH/files/$id"));
if (!rename($file["tmp_name"], "$LOCAL_PATH/files/$id")) if (!rename($file["tmp_name"], "$LOCAL_PATH/files/$id"))
return "Une erreur est survenue lors de l'envoi du fichier."; return "Une erreur est survenue lors de l'envoi du fichier.";
@ -98,8 +102,9 @@ function sendDocument() {
return false; return false;
} }
function updateTeam() { function updateTeam()
global $DB, $YEAR, $URL_BASE, $MAIL_ADDRESS, $team_data; {
global $DB, $YEAR, $URL_BASE, $team_data;
if ($_SESSION["team_id"] == NULL) if ($_SESSION["team_id"] == NULL)
return "Vous n'êtes pas dans une équipe."; return "Vous n'êtes pas dans une équipe.";
@ -138,6 +143,51 @@ function updateTeam() {
return false; return false;
} }
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;
for ($i = 1; $i <= 2; ++$i) {
if ($team_data["encadrant_$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["encadrant_$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["encadrant_$i"], "SANITARY_PLUG"]);
$d = $req->fetch();
$can_validate &= $d["version"] > 0;
}
for ($i = 1; $i <= 6; ++$i) {
if ($team_data["participant_$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"]);
$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"]);
$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)) {
$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"]);
$d = $req->fetch();
$can_validate &= $d["version"] > 0;
}
}
return $can_validate;
}
?> ?>
<?php include "header.php" ?> <?php include "header.php" ?>
@ -151,17 +201,16 @@ function updateTeam() {
<?php if (isset($error_message)) { <?php if (isset($error_message)) {
if ($error_message !== false) { if ($error_message !== false) {
echo "<h2>Erreur : " . $error_message . "</h2>"; echo "<h2>Erreur : " . $error_message . "</h2>";
} } else {
else {
echo "<h2>Le fichier a été correctement envoyé !</h2>"; echo "<h2>Le fichier a été correctement envoyé !</h2>";
} }
}?> } ?>
<h2>Informations sur l'équipe</h2> <h2>Informations sur l'équipe</h2>
Nom de l'équipe : <?php echo $team_data["name"] ?><br /> Nom de l'équipe : <?= $team_data["name"] ?><br/>
Trigramme : <?php echo $team_data["trigram"] ?><br /> Trigramme : <?= $team_data["trigram"] ?><br/>
Tournoi : <?php echo $tournament_data["name"] ?><br /> Tournoi : <a href="<?= $tournament_data["name"] ?>"><?= $tournament_data["name"] ?></a><br/>
<?php <?php
for ($i = 1; $i <= 2; ++$i) { for ($i = 1; $i <= 2; ++$i) {
if ($team_data["encadrant_" . $i] == NULL) if ($team_data["encadrant_" . $i] == NULL)
@ -176,12 +225,12 @@ for ($i = 1; $i <= 6; ++$i) {
echo "Participant $i : " . $user_data["first_name"] . " " . $user_data["surname"] . "<br />"; echo "Participant $i : " . $user_data["first_name"] . " " . $user_data["surname"] . "<br />";
} }
?> ?>
Code d'accès : <strong><?php echo $team_data["access_code"] ?></strong><br /> Code d'accès : <strong><?php echo $team_data["access_code"] ?></strong><br/>
<?php if (isset($_GET["modifier"])) { ?> <?php if (isset($_GET["modifier"])) { ?>
<form method="POST"> <form method="POST">
<input type="hidden" name="team_edit" value="true" /> <input type="hidden" name="team_edit" value="true"/>
<table style="width: 100%;"> <table style="width: 100%;">
<tbody> <tbody>
<tr> <tr>
@ -189,7 +238,7 @@ Code d'accès : <strong><?php echo $team_data["access_code"] ?></strong><br />
<label for="name">Nom :</label> <label for="name">Nom :</label>
</td> </td>
<td style="width: 70%;"> <td style="width: 70%;">
<input style="width: 100%;" type="text" id="name" name="name" value="<?= $team_data["name"] ?>" /> <input style="width: 100%;" type="text" id="name" name="name" value="<?= $team_data["name"] ?>"/>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -197,7 +246,8 @@ Code d'accès : <strong><?php echo $team_data["access_code"] ?></strong><br />
<label for="trigram">Trigramme :</label> <label for="trigram">Trigramme :</label>
</td> </td>
<td> <td>
<input style="width: 100%;" type="text" id="trigram" name="trigram" value="<?= $team_data["trigram"] ?>" /> <input style="width: 100%;" type="text" id="trigram" name="trigram"
value="<?= $team_data["trigram"] ?>"/>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -216,7 +266,7 @@ Code d'accès : <strong><?php echo $team_data["access_code"] ?></strong><br />
</tr> </tr>
<tr> <tr>
<td colspan="2"> <td colspan="2">
<input style="width: 100%;" type="submit" value="Modifier l'équipe" /> <input style="width: 100%;" type="submit" value="Modifier l'équipe"/>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -225,9 +275,10 @@ Code d'accès : <strong><?php echo $team_data["access_code"] ?></strong><br />
<?php } else { ?> <?php } else { ?>
<?php if ($_SESSION["team_validation_status"] == "NOT_READY") { ?> <?php if ($_SESSION["team_validation_status"] == "NOT_READY") { ?>
<!--suppress HtmlUnknownTarget -->
<a href="<?= $URL_BASE ?>/mon_equipe/modifier">Modifier mon équipe</a> <a href="<?= $URL_BASE ?>/mon_equipe/modifier">Modifier mon équipe</a>
<hr /> <hr/>
<h2>Mes autorisations</h2> <h2>Mes autorisations</h2>
<?php <?php
while (($data = $documents_req->fetch()) !== false) { while (($data = $documents_req->fetch()) !== false) {
@ -250,15 +301,15 @@ Code d'accès : <strong><?php echo $team_data["access_code"] ?></strong><br />
?> ?>
<form method="post" enctype="multipart/form-data"> <form method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="5000000" /> <input type="hidden" name="MAX_FILE_SIZE" value="5000000"/>
<table> <table style="width: 100%;">
<tbody> <tbody>
<tr> <tr>
<td> <td>
<label for="type">Type de document :</label> <label for="type">Type de document :</label>
</td> </td>
<td> <td>
<select id="type" name="type"> <select style="width: 100%;" id="type" name="type">
<?php if ($_SESSION["birth_date"] > strval($YEAR - 18) . substr($tournament_data["date_start"], 4)) { ?> <?php if ($_SESSION["birth_date"] > strval($YEAR - 18) . substr($tournament_data["date_start"], 4)) { ?>
<option value="parental_consent">Autorisation parentale</option> <option value="parental_consent">Autorisation parentale</option>
<?php } ?> <?php } ?>
@ -272,24 +323,40 @@ Code d'accès : <strong><?php echo $team_data["access_code"] ?></strong><br />
<label for="file">Fichier :</label> <label for="file">Fichier :</label>
</td> </td>
<td> <td>
<input type="file" id="file" name="document" /> <input style="width: 100%;" type="file" id="file" name="document"/>
</td> </td>
</tr> </tr>
<tr> <tr>
<td colspan="2"> <td colspan="2">
<input style="width: 100%;" type="submit" name="send_document" value="Envoyer" /> <input style="width: 100%;" type="submit" name="send_document" value="Envoyer le document"/>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</form> </form>
<hr/>
<?php if ($team_data["validation_status"] == "NOT_READY") { ?>
<table style="width: 100%;">
<tr>
<td style="width: 50%;">
<form method="post"> <form method="post">
<input type="submit" name="leave_team" value="Quitter l'équipe" /> <input style="width: 100%;" type="submit" name="leave_team" value="Quitter l'équipe"/>
</form> </form>
</td>
<?php
$can_validate = checkCanValidate();
if ($can_validate) { ?>
<td style="width: 50%;">
<form method="post"> <form method="post">
<input type="submit" name="request_validation" value="Demander la validation" /> <input style="width: 100%;" type="submit" name="request_validation"
value="Demander la validation"/>
</form> </form>
<?php } ?> </td>
<?php } ?>
</tr>
</table>
<?php } ?>
<?php } ?>
<?php } ?> <?php } ?>
<?php include "footer.php" ?> <?php include "footer.php" ?>

View File

@ -2,13 +2,20 @@
include 'config.php'; include 'config.php';
if (!isset($_SESSION["team_id"]))
error403();
if (isset($_POST["send_solution"])) { if (isset($_POST["send_solution"])) {
$error_message = saveSolution(); $error_message = saveSolution();
} }
$solutions_req = $DB->prepare("SELECT `file_id`, `problem`, COUNT(`problem`) AS `version` FROM `solutions` WHERE `team` = ? GROUP BY `problem` ORDER BY `problem` ASC, `uploaded_at` DESC;"); $solutions_req = $DB->prepare("SELECT `file_id`, `problem`, COUNT(`problem`) AS `version` FROM `solutions` WHERE `team` = ? GROUP BY `problem`, `uploaded_at` ORDER BY `problem`, `uploaded_at` DESC;");
$solutions_req->execute([$_SESSION["team_id"]]); $solutions_req->execute([$_SESSION["team_id"]]);
$tournament_req = $DB->prepare("SELECT `date_solutions` FROM `tournaments` WHERE `id` = ?;");
$tournament_req->execute([$_SESSION["tournament_id"]]);
$tournament_data = $tournament_req->fetch();
function saveSolution() { function saveSolution() {
global $LOCAL_PATH, $DB; global $LOCAL_PATH, $DB;
@ -64,7 +71,8 @@ function saveSolution() {
} }
}?> }?>
<form method="post" enctype="multipart/form-data"> <?php if (date("yyyy-mm-dd") < $tournament_data["date_solutions"]) { ?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="5000000" /> <input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
<table> <table>
<tbody> <tbody>
@ -97,9 +105,10 @@ function saveSolution() {
</tr> </tr>
</tbody> </tbody>
</table> </table>
</form> </form>
<?php } ?>
<div style="padding: 20px"></div> <hr />
<h2>Solutions soumises :</h2> <h2>Solutions soumises :</h2>

View File

@ -2,13 +2,20 @@
include 'config.php'; include 'config.php';
if (!isset($_SESSION["team_id"]))
error403();
if (isset($_POST["send_synthese"])) { if (isset($_POST["send_synthese"])) {
$error_message = saveSynthese(); $error_message = saveSynthese();
} }
$syntheses_req = $DB->prepare("SELECT `file_id`, `dest`, COUNT(`dest`) AS `version` FROM `syntheses` WHERE `team` = ? GROUP BY `dest` ORDER BY `dest` ASC, `uploaded_at` DESC;"); $syntheses_req = $DB->prepare("SELECT `file_id`, `dest`, COUNT(`dest`) AS `version` FROM `syntheses` WHERE `team` = ? GROUP BY `dest`, `uploaded_at` ORDER BY `dest`, `uploaded_at` DESC;");
$syntheses_req->execute([$_SESSION["team_id"]]); $syntheses_req->execute([$_SESSION["team_id"]]);
$tournament_req = $DB->prepare("SELECT `date_solutions`, `date_syntheses` FROM `tournaments` WHERE `id` = ?;");
$tournament_req->execute([$_SESSION["tournament_id"]]);
$tournament_data = $tournament_req->fetch();
function saveSynthese() { function saveSynthese() {
global $LOCAL_PATH, $DB; global $LOCAL_PATH, $DB;
@ -52,7 +59,13 @@ function saveSynthese() {
<?php include 'header.php' ?> <?php include 'header.php' ?>
<?php if (isset($error_message)) { <?php
if (date("yyyy-mm-dd") < $tournament_data["date_solutions"]) {
echo "<h3>Il est trop tôt pour se préoccuper des notes de synthèse, attendez le tirage des poules.</h3>";
include "footer.php";
}
if (isset($error_message)) {
if ($error_message !== false) { if ($error_message !== false) {
echo "<h2>Erreur : " . $error_message . "</h2>"; echo "<h2>Erreur : " . $error_message . "</h2>";
} }
@ -61,7 +74,8 @@ function saveSynthese() {
} }
}?> }?>
<form method="post" enctype="multipart/form-data"> <?php if (date("yyyy-mm-dd") < $tournament_data["date_syntheses"]) { ?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="5000000" /> <input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
<table> <table>
<tbody> <tbody>
@ -91,7 +105,8 @@ function saveSynthese() {
</tr> </tr>
</tbody> </tbody>
</table> </table>
</form> </form>
<?php } ?>
<div style="padding: 20px"></div> <div style="padding: 20px"></div>