Ajout de l'affichage de l'indice si mauvais qr.

This commit is contained in:
antux18 2023-07-27 12:47:06 +02:00
parent 74710556f7
commit d5a1c77d4f
2 changed files with 50 additions and 32 deletions

View File

@ -8,9 +8,17 @@
$database = new Database(); $database = new Database();
if (isset($_GET["code"]) && isset($_GET["team"]) && isset($_GET["id"])) { if (isset($_GET["code"]) && isset($_GET["team"]) && isset($_GET["id"])) {
$art_id = htmlspecialchars($_GET["id"]);
$team_id = htmlspecialchars($_GET["team"]); $team_id = htmlspecialchars($_GET["team"]);
// Recherche du groupe :
$stmt = $database->pdo_teams->prepare("SELECT * FROM teams WHERE id == :id");
$stmt->bindValue(":id", $team_id);
$stmt->execute();
// Vérification de l'existence du groupe :
if (!empty($stmt->fetchAll())) {
$art_id = htmlspecialchars($_GET["id"]);
// Recherche de l'énigme avec son code : // Recherche de l'énigme avec son code :
$stmt = $database->pdo_article->prepare("SELECT * FROM puzzles WHERE (id == :id AND code == :code)"); $stmt = $database->pdo_article->prepare("SELECT * FROM puzzles WHERE (id == :id AND code == :code)");
$stmt->bindValue(":id", $art_id); $stmt->bindValue(":id", $art_id);
@ -18,14 +26,20 @@
$stmt->execute(); $stmt->execute();
$article = $stmt->fetch(); $article = $stmt->fetch();
// Recherche du groupe : // Données renvoyées :
$stmt = $database->pdo_teams->prepare("SELECT * FROM teams WHERE id == :id"); $data = [
$stmt->bindValue(":id", $team_id); "valid_qr" => false,
$stmt->execute(); "hint" => ""
];
// Vérification de l'existence du groupe, et de la combinaison ID énigme + code : // Vérification de la combinaison ID énigme + code :
if (empty($article) || empty($stmt->fetchAll())) { if (empty($article)) {
echo 0; // 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"];
} }
else { else {
@ -44,14 +58,17 @@
$stmt->execute(); $stmt->execute();
} }
$data = [ $data["valid_qr"] = true;
"answer" => $article["answer"], }
"location" => $article["location"]
];
header("Content-Type: application/json; charset=utf-8"); header("Content-Type: application/json; charset=utf-8");
echo json_encode($data); echo json_encode($data);
} }
else {
header("Location: index.php");
die();
}
} }
else { else {

View File

@ -15,22 +15,23 @@ if (lg == null) {
} }
if (lg == "en") { if (lg == "en") {
var qr_error = "Sorry, wrong QR code, please try another one !"; var qr_error = "Sorry, wrong QR code, please try another one !\n\nHint : ";
} }
if (lg == "fr") { if (lg == "fr") {
var qr_error = "Désolé, ce n'est pas le bon QR code, veuillez en essayer un autre !"; var qr_error = "Désolé, ce n'est pas le bon QR code, veuillez en essayer un autre !\n\nIndice : ";
} }
export async function puzzleSolve(code, team_id, art_id) { export async function puzzleSolve(code, team_id, art_id) {
try { try {
const response = await fetch(url.origin + "/answer.php?lg=" + lg + "&team=" + team_id + "&code=" + code + "&id=" + art_id); const response = await fetch(url.origin + "/answer.php?lg=" + lg + "&team=" + team_id + "&code=" + code + "&id=" + art_id);
const data = await response.text(); const data = await response.json();
if (data == 0) { console.log(data["hint"]);
alert(qr_error); if (data["valid_qr"]) {
location.reload();
} }
else { else {
location.reload(); alert(qr_error + data["hint"]);
} }
} }
catch (error) { catch (error) {