forked from antux18/ChasseTresorPange
Ajout de l'affichage de l'indice si mauvais qr.
This commit is contained in:
parent
74710556f7
commit
d5a1c77d4f
41
answer.php
41
answer.php
@ -8,9 +8,17 @@
|
||||
$database = new Database();
|
||||
|
||||
if (isset($_GET["code"]) && isset($_GET["team"]) && isset($_GET["id"])) {
|
||||
$art_id = htmlspecialchars($_GET["id"]);
|
||||
$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 :
|
||||
$stmt = $database->pdo_article->prepare("SELECT * FROM puzzles WHERE (id == :id AND code == :code)");
|
||||
$stmt->bindValue(":id", $art_id);
|
||||
@ -18,14 +26,20 @@
|
||||
$stmt->execute();
|
||||
$article = $stmt->fetch();
|
||||
|
||||
// Recherche du groupe :
|
||||
$stmt = $database->pdo_teams->prepare("SELECT * FROM teams WHERE id == :id");
|
||||
$stmt->bindValue(":id", $team_id);
|
||||
$stmt->execute();
|
||||
// Données renvoyées :
|
||||
$data = [
|
||||
"valid_qr" => false,
|
||||
"hint" => ""
|
||||
];
|
||||
|
||||
// Vérification de l'existence du groupe, et de la combinaison ID énigme + code :
|
||||
if (empty($article) || empty($stmt->fetchAll())) {
|
||||
echo 0;
|
||||
// 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"];
|
||||
}
|
||||
|
||||
else {
|
||||
@ -44,14 +58,17 @@
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
$data = [
|
||||
"answer" => $article["answer"],
|
||||
"location" => $article["location"]
|
||||
];
|
||||
$data["valid_qr"] = true;
|
||||
}
|
||||
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
else {
|
||||
header("Location: index.php");
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
|
@ -15,22 +15,23 @@ if (lg == null) {
|
||||
}
|
||||
|
||||
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") {
|
||||
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) {
|
||||
try {
|
||||
const response = await fetch(url.origin + "/answer.php?lg=" + lg + "&team=" + team_id + "&code=" + code + "&id=" + art_id);
|
||||
const data = await response.text();
|
||||
if (data == 0) {
|
||||
alert(qr_error);
|
||||
const data = await response.json();
|
||||
console.log(data["hint"]);
|
||||
if (data["valid_qr"]) {
|
||||
location.reload();
|
||||
}
|
||||
else {
|
||||
location.reload();
|
||||
alert(qr_error + data["hint"]);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
|
Loading…
Reference in New Issue
Block a user