From 13fa1824dad9f6f2a3f004ed418c51578c35d7cc Mon Sep 17 00:00:00 2001 From: antux18 Date: Wed, 28 Jun 2023 21:20:16 +0200 Subject: [PATCH] =?UTF-8?q?Mise=20en=20place=20de=20la=20r=C3=A9ponse=20du?= =?UTF-8?q?=20site=20au=20scan=20du=20QR=20code.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- answer.php | 18 +++++++++++++++++- require/database.php | 6 +++++- require/js/answer.js | 15 ++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/answer.php b/answer.php index 9e54e21..38a585b 100644 --- a/answer.php +++ b/answer.php @@ -29,11 +29,27 @@ } 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(); + + // 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 = [ "infos" => $article["infos"], "place" => $article["place"] ]; - header('Content-Type: application/json; charset=utf-8'); + + header("Content-Type: application/json; charset=utf-8"); echo json_encode($data); } } diff --git a/require/database.php b/require/database.php index 21c835b..24ab06c 100644 --- a/require/database.php +++ b/require/database.php @@ -20,9 +20,13 @@ $this->pdo_teams = new PDO("sqlite:" . dirname(__FILE__) . $data_path . "teams.db"); $this->pdo_teams->query('CREATE TABLE IF NOT EXISTS "teams" ( "id" INTEGER NOT NULL UNIQUE, - "solved_id" INTEGER[], PRIMARY KEY("id" AUTOINCREMENT) )'); + + $this->pdo_teams->query('CREATE TABLE IF NOT EXISTS "solved" ( + "puzzle_id" INTEGER NOT NULL, + "team_id" INTEGER NOT NULL + )'); } catch (PDOException $exception) { diff --git a/require/js/answer.js b/require/js/answer.js index 14ab452..7cfdbf5 100644 --- a/require/js/answer.js +++ b/require/js/answer.js @@ -14,11 +14,24 @@ if (lg == null) { } } +if (lg == "en") { + var qr_error = "Sorry, wrong QR code, please try another one !"; +} + +if (lg == "fr") { + var qr_error = "Désolé, ce n'est pas le bon QR code, veuillez en essayer un autre !"; +} + export async function puzzleSolve(code, team_id, art_id) { try { const response = await fetch("/answer.php?lg=" + lg + "&team=" + team_id + "&code=" + code + "&id=" + art_id); const data = await response.text(); - console.log(data); + if (data == 0) { + alert(qr_error); + } + else { + location.reload(); + } } catch (error) { console.log(error);