2023-06-28 20:38:52 +02:00
|
|
|
<?php
|
|
|
|
require_once "require/base.php";
|
|
|
|
|
|
|
|
$database = new Database();
|
2024-09-01 21:02:51 +02:00
|
|
|
$bonus = $database->getArticleNb(); // L'énigme bonus est la dernière
|
2023-06-28 20:38:52 +02:00
|
|
|
|
|
|
|
if (isset($_GET["code"]) && isset($_GET["team"]) && isset($_GET["id"])) {
|
|
|
|
$team_id = htmlspecialchars($_GET["team"]);
|
|
|
|
|
2023-07-27 12:47:06 +02:00
|
|
|
// Vérification de l'existence du groupe :
|
2024-09-01 21:02:51 +02:00
|
|
|
if ($database->checkTeamExists($team_id)) {
|
2023-07-27 12:47:06 +02:00
|
|
|
$art_id = htmlspecialchars($_GET["id"]);
|
2024-09-01 21:02:51 +02:00
|
|
|
$code = htmlspecialchars($_GET["code"]);
|
|
|
|
$article = $database->getArticle($art_id);
|
2023-07-27 12:47:06 +02:00
|
|
|
|
|
|
|
// Données renvoyées :
|
|
|
|
$data = [
|
|
|
|
"valid_qr" => false,
|
|
|
|
"hint" => ""
|
|
|
|
];
|
|
|
|
|
|
|
|
// Vérification de la combinaison ID énigme + code :
|
2024-09-01 21:02:51 +02:00
|
|
|
if (!$database->checkPuzzle($art_id, $code)) {
|
2023-07-27 12:47:06 +02:00
|
|
|
$data["hint"] = $article["hint"];
|
|
|
|
}
|
2023-06-28 21:20:16 +02:00
|
|
|
|
2023-07-27 12:47:06 +02:00
|
|
|
else {
|
|
|
|
// On enregistre la réussite dans la table :
|
2024-09-01 21:02:51 +02:00
|
|
|
// Vérification que ce n'est pas déjà enregistré
|
|
|
|
// Si ce n'est pas le cas, on enregistre :
|
|
|
|
if (!$database->isPuzzleSolved($art_id, $team_id)) {
|
|
|
|
$database->solvePuzzle($art_id, $team_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// On ajoute l'énigme bonus si toutes les autres sont résolues :
|
|
|
|
$stmt = $database->pdo_teams->prepare("SELECT COUNT(*) FROM solved WHERE team_id == :team_id");
|
2023-06-28 21:20:16 +02:00
|
|
|
$stmt->bindValue(":team_id", $team_id);
|
|
|
|
$stmt->execute();
|
|
|
|
|
2024-09-01 21:02:51 +02:00
|
|
|
if ($stmt->fetchAll()[0]["COUNT(*)"] == $bonus - 1) {
|
|
|
|
$stmt = $database->pdo_teams->prepare("UPDATE teams SET bonus = 1 WHERE id = :team_id");
|
2023-07-27 12:47:06 +02:00
|
|
|
$stmt->bindValue(":team_id", $team_id);
|
|
|
|
$stmt->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
$data["valid_qr"] = true;
|
|
|
|
}
|
2023-06-28 21:20:16 +02:00
|
|
|
|
|
|
|
header("Content-Type: application/json; charset=utf-8");
|
2023-06-28 20:38:52 +02:00
|
|
|
echo json_encode($data);
|
|
|
|
}
|
2023-07-27 12:47:06 +02:00
|
|
|
|
|
|
|
else {
|
|
|
|
header("Location: index.php");
|
|
|
|
die();
|
|
|
|
}
|
2023-06-28 20:38:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
header("Location: index.php");
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
?>
|