ChasseTresorPange/puzzles.php

88 lines
2.6 KiB
PHP
Raw Normal View History

<?php
require_once "require/base.php";
$database = new Database();
if (isset($_GET["team"])) {
$team_id = htmlspecialchars($_GET["team"]);
if (!$database->checkTeamExists($team_id)) {
header("Location: index.php");
die();
}
else {
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
);
}
$solved = $database->getSolvedPuzzles($team_id);
$puzzles = [];
foreach ($solved as $p) {
array_push($puzzles, $database->getArticle($p));
}
$next_art = $database->getNextPuzzle($team_id);
}
}
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>
<?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>
<?php
require_once $rq_path . "footer.php";
?>
</footer>
</body>
</html>