2023-06-28 20:38:52 +02:00
|
|
|
<?php
|
|
|
|
require_once "require/base.php";
|
|
|
|
|
2023-06-28 20:59:12 +02:00
|
|
|
$team_id = -1;
|
|
|
|
$art_id = -1;
|
|
|
|
$article = array();
|
|
|
|
|
2023-06-28 20:38:52 +02:00
|
|
|
$database = new Database();
|
|
|
|
|
|
|
|
if (isset($_GET["code"]) && isset($_GET["team"]) && isset($_GET["id"])) {
|
|
|
|
$team_id = htmlspecialchars($_GET["team"]);
|
|
|
|
|
2023-06-28 20:59:12 +02:00
|
|
|
// Recherche du groupe :
|
2023-06-28 20:38:52 +02:00
|
|
|
$stmt = $database->pdo_teams->prepare("SELECT * FROM teams WHERE id == :id");
|
|
|
|
$stmt->bindValue(":id", $team_id);
|
|
|
|
$stmt->execute();
|
|
|
|
|
2023-07-27 12:47:06 +02:00
|
|
|
// Vérification de l'existence du groupe :
|
2023-09-02 01:00:27 +02:00
|
|
|
if (!empty($stmt->fetch())) {
|
2023-07-27 12:47:06 +02:00
|
|
|
$art_id = htmlspecialchars($_GET["id"]);
|
2023-06-28 20:38:52 +02:00
|
|
|
|
2023-07-27 12:47:06 +02:00
|
|
|
// Recherche de l'énigme avec son code :
|
|
|
|
$stmt = $database->pdo_article->prepare("SELECT * FROM puzzles WHERE (id == :id AND code == :code)");
|
|
|
|
$stmt->bindValue(":id", $art_id);
|
|
|
|
$stmt->bindValue(":code", htmlspecialchars($_GET["code"]));
|
2023-06-28 21:20:16 +02:00
|
|
|
$stmt->execute();
|
2023-07-27 12:47:06 +02:00
|
|
|
$article = $stmt->fetch();
|
|
|
|
|
|
|
|
// Données renvoyées :
|
|
|
|
$data = [
|
|
|
|
"valid_qr" => false,
|
|
|
|
"hint" => ""
|
|
|
|
];
|
|
|
|
|
|
|
|
// Vérification de la combinaison ID énigme + code :
|
|
|
|
if (empty($article)) {
|
|
|
|
// Si la combinaison ne fonctionne pas, affichage de l'indice :
|
|
|
|
$stmt = $database->pdo_article->prepare("SELECT * FROM puzzles WHERE id == :id");
|
|
|
|
$stmt->bindValue(":id", $art_id);
|
|
|
|
$stmt->execute();
|
|
|
|
$article = $stmt->fetch();
|
|
|
|
$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 :
|
|
|
|
// Vérification que ce n'est pas déjà enregistré :
|
|
|
|
$stmt = $database->pdo_teams->prepare("SELECT * FROM solved WHERE (puzzle_id == :puzzle_id AND team_id == :team_id)");
|
2023-06-28 21:20:16 +02:00
|
|
|
$stmt->bindValue(":puzzle_id", $art_id);
|
|
|
|
$stmt->bindValue(":team_id", $team_id);
|
|
|
|
$stmt->execute();
|
|
|
|
|
2023-07-27 12:47:06 +02:00
|
|
|
// Si ce n'est pas le cas, on enregistre :
|
|
|
|
if (empty($stmt->fetch())) {
|
|
|
|
$stmt = $database->pdo_teams->prepare("INSERT INTO solved VALUES (:puzzle_id, :team_id)");
|
|
|
|
$stmt->bindValue(":puzzle_id", $art_id);
|
|
|
|
$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();
|
|
|
|
}
|
|
|
|
?>
|