Mise en place de la réponse du site au scan du QR code.

This commit is contained in:
antux18 2023-06-28 21:20:16 +02:00
parent 0dd6af01d5
commit 13fa1824da
3 changed files with 36 additions and 3 deletions

View File

@ -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);
}
}

View File

@ -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) {

View File

@ -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);