ChasseTresorPange/puzzles.php

102 lines
3.0 KiB
PHP
Raw Normal View History

<?php
require_once "require/base.php";
$puzzles = array();
$order = 0;
$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())) {
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
);
$stmt = $database->pdo_article->prepare("SELECT * FROM puzzles");
$stmt->execute();
$puzzles = $stmt->fetchAll();
// Recherche de l'ordre des énigmes :
$stmt = $database->pdo_teams->prepare("SELECT pzorder FROM teams WHERE id == :id");
$stmt->bindValue(":id", $team_id);
$stmt->execute();
$result = $stmt->fetch();
$order = $result["pzorder"];
// Si un ordre d'énigmes n'a pas été défini au préalable pour cette équipe, on en choisit un au hasard :
if (is_null($order)) {
$order = rand(0, sizeof($pzorder));
$stmt = $database->pdo_teams->prepare("UPDATE teams SET pzorder = :order WHERE id == :id");
$stmt->bindValue(":id", $team_id);
$stmt->bindValue(":order", $order);
$stmt->execute();
}
}
}
else {
header("Location: index.php");
die();
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<?php
require_once $rq_path . "head.php";
?>
<title><?= $tr["tab_title"]["puzzles"]?></title>
</head>
<body>
<header>
<?php
require_once $rq_path . "nav.php";
?>
</header>
<main>
<header>
<h1><?= $tr["page_title"]["puzzles"] . $team_id ?></h1>
</header>
<article>
<p><?= $tr["puzzles"]["message"]?></p>
<ul>
<?php foreach ($pzorder[$order] as $pzid) : ?>
<?php foreach ($puzzles as $puzzle) : ?>
<?php if ($puzzle["id"] == $pzid) : ?>
<li><a href="article.php?team=<?= $team_id ?>&id=<?= $puzzle["id"] ?>"><?= $tr["page_title"]["article"] . $puzzle["id"] ?></a></li>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</ul>
</article>
</main>
<footer>
<?php
require_once $rq_path . "footer.php";
?>
</footer>
</body>
</html>