forked from antux18/ChasseTresorPange
Ajout de l'affichage de l'indice si mauvais qr.
This commit is contained in:
parent
74710556f7
commit
d5a1c77d4f
69
answer.php
69
answer.php
@ -8,50 +8,67 @@
|
||||
$database = new Database();
|
||||
|
||||
if (isset($_GET["code"]) && isset($_GET["team"]) && isset($_GET["id"])) {
|
||||
$art_id = htmlspecialchars($_GET["id"]);
|
||||
$team_id = htmlspecialchars($_GET["team"]);
|
||||
|
||||
// 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"]));
|
||||
$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();
|
||||
|
||||
// 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 l'existence du groupe :
|
||||
if (!empty($stmt->fetchAll())) {
|
||||
$art_id = htmlspecialchars($_GET["id"]);
|
||||
|
||||
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)");
|
||||
$stmt->bindValue(":puzzle_id", $art_id);
|
||||
$stmt->bindValue(":team_id", $team_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);
|
||||
$stmt->bindValue(":code", htmlspecialchars($_GET["code"]));
|
||||
$stmt->execute();
|
||||
$article = $stmt->fetch();
|
||||
|
||||
// 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)");
|
||||
// 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"];
|
||||
}
|
||||
|
||||
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)");
|
||||
$stmt->bindValue(":puzzle_id", $art_id);
|
||||
$stmt->bindValue(":team_id", $team_id);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
$data = [
|
||||
"answer" => $article["answer"],
|
||||
"location" => $article["location"]
|
||||
];
|
||||
// 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;
|
||||
}
|
||||
|
||||
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