Compare commits
13 Commits
master
...
random-puz
Author | SHA1 | Date | |
---|---|---|---|
806271e6b2 | |||
4491a5c7ef | |||
cd84b319e7 | |||
bd8275f7ae | |||
6e063e4ce1 | |||
2de91ad8a3 | |||
d0a515df65 | |||
f655529f31 | |||
559d42fff1 | |||
a0e3ba8c09 | |||
fabc5e55fd | |||
b2bdc6350f | |||
d2ea5ebbcd |
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
localhost-key.pem
|
||||
localhost.pem
|
||||
localhost.pem
|
||||
data/teams.db
|
||||
data/article.db
|
@ -2,6 +2,8 @@
|
||||
|
||||
**Auteur :** Antoine WAEHREN
|
||||
|
||||
Sur cette version, la liste des énigmes n'affiche pas immédiatement toutes les énigmes, uniquement celles qui ont été résolues. L'énigme suivante est choisie aléatoirement.
|
||||
|
||||
## Crédits
|
||||
|
||||
Ce projet utilise le module QR Scanner de NIMIQ : https://github.com/nimiq/qr-scanner
|
||||
Ce projet utilise le module QR Scanner de NIMIQ : https://github.com/nimiq/qr-scanner
|
||||
|
56
answer.php
56
answer.php
@ -1,30 +1,17 @@
|
||||
<?php
|
||||
require_once "require/base.php";
|
||||
|
||||
$team_id = -1;
|
||||
$art_id = -1;
|
||||
$article = array();
|
||||
|
||||
$database = new Database();
|
||||
$bonus = $database->getArticleNb(); // L'énigme bonus est la dernière
|
||||
|
||||
if (isset($_GET["code"]) && isset($_GET["team"]) && isset($_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->fetch())) {
|
||||
if ($database->checkTeamExists($team_id)) {
|
||||
$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);
|
||||
$stmt->bindValue(":code", htmlspecialchars($_GET["code"]));
|
||||
$stmt->execute();
|
||||
$article = $stmt->fetch();
|
||||
$code = htmlspecialchars($_GET["code"]);
|
||||
$article = $database->getArticle($art_id);
|
||||
|
||||
// Données renvoyées :
|
||||
$data = [
|
||||
@ -33,40 +20,27 @@
|
||||
];
|
||||
|
||||
// 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();
|
||||
if (!$database->checkPuzzle($art_id, $code)) {
|
||||
$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);
|
||||
// Vérification que ce n'est pas déjà enregistré
|
||||
// Si ce n'est pas le cas, on enregistre :
|
||||
if (!$database->isPuzzleSolved($art_id, $team_id)) {
|
||||
$database->solvePuzzle($art_id, $team_id);
|
||||
}
|
||||
|
||||
// On ajoute l'énigme bonus si toutes les autres sont résolues :
|
||||
$stmt = $database->pdo_teams->prepare("SELECT COUNT(*) FROM solved WHERE team_id == :team_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);
|
||||
if ($stmt->fetchAll()[0]["COUNT(*)"] == $bonus - 1) {
|
||||
$stmt = $database->pdo_teams->prepare("UPDATE teams SET bonus = 1 WHERE id = :team_id");
|
||||
$stmt->bindValue(":team_id", $team_id);
|
||||
$stmt->execute();
|
||||
|
||||
// On ajoute l'énigme bonus si toutes les autres sont résolues :
|
||||
$stmt = $database->pdo_teams->prepare("SELECT COUNT(*) FROM solved WHERE team_id == :team_id");
|
||||
$stmt->bindValue(":team_id", $team_id);
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->fetchAll()[0]["COUNT(*)"] == "12") { // Il y a 12 énigmes sans compter la bonus
|
||||
$stmt = $database->pdo_teams->prepare("UPDATE teams SET bonus = 1 WHERE id = :team_id");
|
||||
$stmt->bindValue(":team_id", $team_id);
|
||||
$stmt->execute();
|
||||
}
|
||||
}
|
||||
|
||||
$data["valid_qr"] = true;
|
||||
|
60
article.php
60
article.php
@ -1,50 +1,43 @@
|
||||
<?php
|
||||
require_once "require/base.php";
|
||||
|
||||
$article = array();
|
||||
$solved = false;
|
||||
$team_id = -1;
|
||||
$art_id = -1;
|
||||
|
||||
$database = new Database();
|
||||
|
||||
$max_art = $database->getArticleNb();
|
||||
$bonus = $database->getArticleNb(); // L'énigme bonus est la dernière
|
||||
|
||||
if (isset($_GET["id"]) && isset($_GET["team"])) {
|
||||
$art_id = htmlspecialchars($_GET["id"]);
|
||||
$team_id = htmlspecialchars($_GET["team"]);
|
||||
|
||||
// Recherche de l'énigme indiquée dans la base :
|
||||
$stmt = $database->pdo_article->prepare("SELECT * FROM puzzles WHERE id == :id");
|
||||
$stmt->bindValue(":id", $art_id);
|
||||
$stmt->execute();
|
||||
$article = $stmt->fetch();
|
||||
|
||||
// Vérification de l'existence du groupe et de l'énigme :
|
||||
if (empty($article) || !$database->checkTeamExists($team_id)) {
|
||||
header("Location: index.php");
|
||||
die();
|
||||
if (!$database->checkArticleExists($art_id)) {
|
||||
if (!$database->checkTeamExists($team_id)) {
|
||||
header("Location: index.php");
|
||||
die();
|
||||
}
|
||||
else if ($art_id == -1) {
|
||||
header("Location: puzzles.php?team=" . $team_id);
|
||||
die();
|
||||
}
|
||||
else {
|
||||
header("Location: index.php");
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
// On vérifie si l'énigme bonus n'est pas débloquée :
|
||||
if (!$database->checkTeamBonus($team_id)) {
|
||||
// Si c'est celle qui est sélectionnée, on retourne à la liste des énigmes :
|
||||
if ($art_id == $max_art) {
|
||||
header("Location: puzzles.php?team=" . $team_id);
|
||||
// Si c'est celle qui est sélectionnée, on choisit une autre énigme :
|
||||
if ($art_id == $bonus) {
|
||||
$next_art = $database->getNextPuzzle($team_id);
|
||||
header("Location: article.php?team=" . $team_id . "&id=" . $next_art);
|
||||
die();
|
||||
}
|
||||
|
||||
// On retire l'énigme bonus du total :
|
||||
$max_art--;
|
||||
}
|
||||
|
||||
// On indique si l'énigme est résolue :
|
||||
$stmt = $database->pdo_teams->prepare("SELECT * FROM solved WHERE (team_id == :team_id AND puzzle_id == :puzzle_id)");
|
||||
$stmt->bindValue(":team_id", $team_id);
|
||||
$stmt->bindValue(":puzzle_id", $art_id);
|
||||
$stmt->execute();
|
||||
$solved = !empty($stmt->fetch());
|
||||
$article = $database->getArticle($art_id);
|
||||
$next_art = $database->getNextPuzzle($team_id);
|
||||
$solved = $database->isPuzzleSolved($art_id, $team_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,15 +66,10 @@
|
||||
<header>
|
||||
<h1><?= $tr["page_title"]["article"] . $art_id . " : " . $article["title"] ?></h1>
|
||||
<h2><?= $article["text"] ?></h2>
|
||||
<section>
|
||||
<a href="puzzles.php?team=<?= $team_id ?>">
|
||||
<button><?= $tr["article"]["back_but"] ?></button>
|
||||
</a>
|
||||
<!-- <a href="article.php?team=<?= $team_id ?>&id=<?= ($art_id % $max_art) + 1 ?>">
|
||||
<button><?= $tr["article"]["next_but"] ?></button>
|
||||
</a> -->
|
||||
</section>
|
||||
<?php if ($solved) : ?>
|
||||
<a href="article.php?team=<?= $team_id ?>&id=<?= $next_art ?>">
|
||||
<button><?= $tr["article"]["next_but"] ?></button>
|
||||
</a>
|
||||
<p><?= $tr["article"]["success"] ?></p>
|
||||
<?php else : ?>
|
||||
<p><?= $tr["article"]["message"] ?></p>
|
||||
|
BIN
data/article.db
BIN
data/article.db
Binary file not shown.
BIN
data/teams.db
BIN
data/teams.db
Binary file not shown.
16
index.php
16
index.php
@ -2,8 +2,9 @@
|
||||
require_once "require/base.php";
|
||||
|
||||
$database = new Database();
|
||||
$teams = $database->getTeams();
|
||||
|
||||
// Si l'appareil a déjà choisi une équipe, on le redirige vers la bonne page :
|
||||
// Si l'appareil a déjà choisi une équipe, on le redirige vers une énigme :
|
||||
if (isset($_COOKIE["team"])) {
|
||||
$team_id = htmlspecialchars($_COOKIE["team"]);
|
||||
|
||||
@ -11,19 +12,6 @@
|
||||
header("Location: puzzles.php?team=" . $team_id);
|
||||
die();
|
||||
}
|
||||
|
||||
else {
|
||||
$stmt = $database->pdo_teams->prepare("SELECT * FROM teams");
|
||||
$stmt->execute();
|
||||
$teams = $stmt->fetchAll();
|
||||
}
|
||||
}
|
||||
|
||||
// Sinon, on affiche la liste des équipes :
|
||||
else {
|
||||
$stmt = $database->pdo_teams->prepare("SELECT * FROM teams");
|
||||
$stmt->execute();
|
||||
$teams = $stmt->fetchAll();
|
||||
}
|
||||
?>
|
||||
|
||||
|
74
puzzles.php
74
puzzles.php
@ -1,53 +1,36 @@
|
||||
<?php
|
||||
require_once "require/base.php";
|
||||
|
||||
$puzzles = array();
|
||||
$team_id = -1;
|
||||
|
||||
$database = new Database();
|
||||
|
||||
if (isset($_GET["team"])) {
|
||||
$team_id = htmlspecialchars($_GET["team"]);
|
||||
|
||||
// Vérification de l'existence du groupe :
|
||||
$stmt = $database->pdo_teams->prepare("SELECT * FROM teams WHERE id == :id");
|
||||
$stmt->bindValue(":id", $team_id);
|
||||
$stmt->execute();
|
||||
|
||||
if (empty($stmt->fetch())) {
|
||||
if (!$database->checkTeamExists($team_id)) {
|
||||
header("Location: index.php");
|
||||
die();
|
||||
}
|
||||
|
||||
else {
|
||||
// On crée un cookie pour enregistrer l'équipe sélectionnée :
|
||||
setcookie(
|
||||
"team",
|
||||
$team_id,
|
||||
time() + (365 * 24 * 60 * 60),
|
||||
"/",
|
||||
"",
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
// On vérifie si l'équipe a débloqué l'énigme bonus :
|
||||
$stmt = $database->pdo_teams->prepare("SELECT * FROM teams WHERE id = :id");
|
||||
$stmt->bindValue(":id", $team_id);
|
||||
$stmt->execute();
|
||||
|
||||
// Si c'est le cas, on affiche toutes les énigmes :
|
||||
if ($stmt->fetchAll()[0][1] == 1) {
|
||||
$stmt = $database->pdo_article->prepare("SELECT * FROM puzzles");
|
||||
if (!isset($_COOKIE["team"])) {
|
||||
// On crée un cookie pour enregistrer l'équipe sélectionnée :
|
||||
setcookie(
|
||||
"team",
|
||||
$team_id,
|
||||
time() + (365 * 24 * 60 * 60),
|
||||
"/",
|
||||
"",
|
||||
false,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
// Sinon, on cache la bonus :
|
||||
else {
|
||||
$stmt = $database->pdo_article->prepare("SELECT * FROM puzzles WHERE id <> 13");
|
||||
$solved = $database->getSolvedPuzzles($team_id);
|
||||
$puzzles = [];
|
||||
foreach ($solved as $p) {
|
||||
array_push($puzzles, $database->getArticle($p));
|
||||
}
|
||||
|
||||
$stmt->execute();
|
||||
$puzzles = $stmt->fetchAll();
|
||||
$next_art = $database->getNextPuzzle($team_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,12 +59,23 @@
|
||||
<h1><?= $tr["page_title"]["puzzles"] . $team_id ?></h1>
|
||||
</header>
|
||||
<article>
|
||||
<p><?= $tr["puzzles"]["message"]?></p>
|
||||
<ul>
|
||||
<?php foreach ($puzzles as $puzzle) : ?>
|
||||
<li><a href="article.php?team=<?= $team_id ?>&id=<?= $puzzle["id"] ?>"><?= $tr["page_title"]["article"] . $puzzle["id"] . " : " . $puzzle["title"] ?></a></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php if ($next_art != -1) : ?>
|
||||
<a href="article.php?team=<?= $team_id ?>&id=<?= $next_art ?>">
|
||||
<button><?= $tr["puzzles"]["pz_but"] ?></button>
|
||||
</a>
|
||||
<?php if (!empty($puzzles)) : ?>
|
||||
<p><?= $tr["puzzles"]["message"]?></p>
|
||||
<?php endif; ?>
|
||||
<?php else : ?>
|
||||
<p><?= $tr["puzzles"]["success"]?></p>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($puzzles)) : ?>
|
||||
<ul>
|
||||
<?php foreach ($puzzles as $puzzle) : ?>
|
||||
<li><a href="article.php?team=<?= $team_id ?>&id=<?= $puzzle["id"] ?>"><?= $tr["page_title"]["article"] . $puzzle["id"] . " : " . $puzzle["title"] ?></a></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</article>
|
||||
</main>
|
||||
<footer>
|
||||
|
@ -24,7 +24,7 @@
|
||||
$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,
|
||||
"bonus" INTEGER NOT NULL,
|
||||
"bonus" INTEGER NOT NULL,
|
||||
PRIMARY KEY("id" AUTOINCREMENT)
|
||||
)');
|
||||
|
||||
@ -45,11 +45,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
public function checkTeamExists(int $id) {
|
||||
$stmt = $this->pdo_teams->prepare("SELECT * FROM teams WHERE id == :id");
|
||||
public function getArticle(int $id) {
|
||||
$stmt = $this->pdo_article->prepare("SELECT * FROM puzzles WHERE id == :id");
|
||||
$stmt->bindValue(":id", $id);
|
||||
$stmt->execute();
|
||||
return !empty($stmt->fetch());
|
||||
return $stmt->fetch();
|
||||
}
|
||||
|
||||
public function getArticleNb() {
|
||||
@ -57,10 +57,85 @@
|
||||
return $query->fetch()["COUNT(*)"];
|
||||
}
|
||||
|
||||
function checkTeamBonus(int $team) {
|
||||
public function checkTeamExists(int $id) {
|
||||
$stmt = $this->pdo_teams->prepare("SELECT * FROM teams WHERE id == :id");
|
||||
$stmt->bindValue(":id", $id);
|
||||
$stmt->execute();
|
||||
return !empty($stmt->fetch());
|
||||
}
|
||||
|
||||
public function checkArticleExists(int $id) {
|
||||
return !empty($this->getArticle($id));
|
||||
}
|
||||
|
||||
public function checkPuzzle(int $id, string $code) {
|
||||
$stmt = $this->pdo_article->prepare("SELECT * FROM puzzles WHERE (id == :id AND code == :code)");
|
||||
$stmt->bindValue(":id", $id);
|
||||
$stmt->bindValue(":code", $code);
|
||||
$stmt->execute();
|
||||
return !empty($stmt->fetch());
|
||||
}
|
||||
|
||||
public function isPuzzleSolved(int $id, int $team) {
|
||||
$stmt = $this->pdo_teams->prepare("SELECT * FROM solved WHERE (team_id == :team_id AND puzzle_id == :puzzle_id)");
|
||||
$stmt->bindValue(":team_id", $team);
|
||||
$stmt->bindValue(":puzzle_id", $id);
|
||||
$stmt->execute();
|
||||
return !empty($stmt->fetch());
|
||||
}
|
||||
|
||||
public function solvePuzzle(int $id, int $team) {
|
||||
$stmt = $this->pdo_teams->prepare("INSERT INTO solved VALUES (:puzzle_id, :team_id)");
|
||||
$stmt->bindValue(":puzzle_id", $id);
|
||||
$stmt->bindValue(":team_id", $team);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
public function getSolvedPuzzles(int $team) {
|
||||
// $team doit être une équipe existante :
|
||||
$query = $this->pdo_teams->query("SELECT bonus FROM teams WHERE id = " . $team);
|
||||
return $query->fetch()[0] == 1;
|
||||
$stmt = $this->pdo_teams->prepare("SELECT * FROM solved WHERE team_id == :id");
|
||||
$stmt->bindValue(":id", $team);
|
||||
$stmt->execute();
|
||||
$res = $stmt->fetchAll();
|
||||
$solved = [];
|
||||
foreach ($res as $r) {
|
||||
array_push($solved, $r["puzzle_id"]);
|
||||
}
|
||||
return $solved;
|
||||
}
|
||||
|
||||
function getUnsolvedPuzzles(int $team) {
|
||||
$solved = $this->getSolvedPuzzles($team);
|
||||
$unsolved = range(1, $this->getArticleNb());
|
||||
// On supprime les énigmes résolues :
|
||||
foreach ($solved as $p) {
|
||||
$key = array_search($p, $unsolved);
|
||||
array_splice($unsolved, $key, 1);
|
||||
}
|
||||
return $unsolved;
|
||||
}
|
||||
|
||||
public function getNextPuzzle(int $team) {
|
||||
$unsolved = $this->getUnsolvedPuzzles($team);
|
||||
$next = -1; // Quand il n'y a plus d'autre énigme à résoudre
|
||||
if (!empty($unsolved)) {
|
||||
$next = $unsolved[array_rand($unsolved)];
|
||||
}
|
||||
return $next;
|
||||
}
|
||||
|
||||
public function checkTeamBonus(int $team) {
|
||||
// $team doit être une équipe existante :
|
||||
$stmt = $this->pdo_teams->prepare("SELECT bonus FROM teams WHERE id == :id");
|
||||
$stmt->bindValue(":id", $team);
|
||||
$stmt->execute();
|
||||
return $stmt->fetch()[0] == 1;
|
||||
}
|
||||
|
||||
public function getTeams() {
|
||||
$stmt = $this->pdo_teams->prepare("SELECT * FROM teams");
|
||||
$stmt->execute();
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
// public function getTeamsNb() {
|
||||
|
@ -35,6 +35,8 @@
|
||||
],
|
||||
"puzzles" => [
|
||||
"message" => "Select a puzzle in the list below :",
|
||||
"success" => "Congratulations, you solved all the puzzles ! You can now select a specific puzzle in the list below :",
|
||||
"pz_but" => "Solve a puzzle",
|
||||
"map_desc" => "Here is a map showing the location of the puzzles you already solved :"
|
||||
],
|
||||
"nav" => [
|
||||
@ -45,4 +47,4 @@
|
||||
"text" => "Lycée Jean de Pange Sarreguemines<br><a href='https://forge.chapril.org/antux18/ChasseTresorPange'>Source code</a>"
|
||||
]
|
||||
];
|
||||
?>
|
||||
?>
|
||||
|
@ -35,6 +35,8 @@
|
||||
],
|
||||
"puzzles" => [
|
||||
"message" => "Choisissez une énigme dans la liste ci-dessous :",
|
||||
"success" => "Félicitations, vous avez résolu toutes les énigmes ! Vous pouvez maintenant sélectionner une énigme en particulier dans la liste ci-dessous :",
|
||||
"pz_but" => "Résoudre une énigme",
|
||||
"map_desc" => "Voici la carte des emplacements des énigmes que vous avez résolues :"
|
||||
],
|
||||
"nav" => [
|
||||
@ -45,4 +47,4 @@
|
||||
"text" => "Lycée Jean de Pange Sarreguemines<br><a href='https://forge.chapril.org/antux18/ChasseTresorPange'>Code source</a>"
|
||||
]
|
||||
];
|
||||
?>
|
||||
?>
|
||||
|
@ -149,6 +149,7 @@ main header section {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
<?php
|
||||
require_once "require/base.php";
|
||||
|
||||
$team_id = -1;
|
||||
|
||||
$database = new Database();
|
||||
|
||||
if (isset($_GET["team"])) {
|
||||
|
Loading…
Reference in New Issue
Block a user