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,50 +8,67 @@
$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 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 : // Recherche du groupe :
$stmt = $database->pdo_teams->prepare("SELECT * FROM teams WHERE id == :id"); $stmt = $database->pdo_teams->prepare("SELECT * FROM teams WHERE id == :id");
$stmt->bindValue(":id", $team_id); $stmt->bindValue(":id", $team_id);
$stmt->execute(); $stmt->execute();
// Vérification de l'existence du groupe, et de la combinaison ID énigme + code : // Vérification de l'existence du groupe :
if (empty($article) || empty($stmt->fetchAll())) { if (!empty($stmt->fetchAll())) {
echo 0; $art_id = htmlspecialchars($_GET["id"]);
}
else { // Recherche de l'énigme avec son code :
// On enregistre la réussite dans la table : $stmt = $database->pdo_article->prepare("SELECT * FROM puzzles WHERE (id == :id AND code == :code)");
// Vérification que ce n'est pas déjà enregistré : $stmt->bindValue(":id", $art_id);
$stmt = $database->pdo_teams->prepare("SELECT * FROM solved WHERE (puzzle_id == :puzzle_id AND team_id == :team_id)"); $stmt->bindValue(":code", htmlspecialchars($_GET["code"]));
$stmt->bindValue(":puzzle_id", $art_id);
$stmt->bindValue(":team_id", $team_id);
$stmt->execute(); $stmt->execute();
$article = $stmt->fetch();
// Si ce n'est pas le cas, on enregistre : // Données renvoyées :
if (empty($stmt->fetch())) { $data = [
$stmt = $database->pdo_teams->prepare("INSERT INTO solved VALUES (:puzzle_id, :team_id)"); "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(":puzzle_id", $art_id);
$stmt->bindValue(":team_id", $team_id); $stmt->bindValue(":team_id", $team_id);
$stmt->execute(); $stmt->execute();
}
$data = [ // Si ce n'est pas le cas, on enregistre :
"answer" => $article["answer"], if (empty($stmt->fetch())) {
"location" => $article["location"] $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"); 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) {