1
0
Fork 0
app.sixfold.org/www/games/index.php

118 lines
4.8 KiB
PHP

<?php
$title = "Games";
$description = "View previous games.";
if (!isset($_SESSION["account"])) {
$title = "Log In";
$description = "Login to view details about this vote.";
http_response_code(401);
} elseif (isset($_GET["game"])) {
$sql = "SELECT games.id, games.name, games.submitstart, games.status_id, games.submitend, games.onestart, games.twostart, games.threestart, games.gameend FROM games
JOIN game_status ON games.status_id = game_status.id
WHERE games.id = :id";
$stmt = $db["data"]->prepare($sql);
$stmt->execute([
"id" => $_GET["game"],
]);
$game = $stmt->fetch();
unset($stmt);
$title = "Game: " . $game["name"];
$description = "View details about the " . $game["name"] . " vote.";
}
include "partials/head.php";
?>
<body>
<?php include "partials/header.php"; ?>
<main id="main" class="flow">
<header>
<h1><?= $title ?></h1>
</header>
<div class="games">
<?php if (!LOGGED_IN) {
include "partials/login-form.php";
} else {
$sql = "SELECT games.id, games.name, games.submitstart, games.status_id, games.submitend, games.onestart, games.twostart, games.threestart, games.gameend
FROM games
JOIN game_status ON games.status_id = game_status.id
WHERE games.status_id != 8
ORDER BY games.id DESC";
$stmt = $db["data"]->prepare($sql);
$stmt->execute();
while ($game = $stmt->fetch()) {
static $one_second = new DateInterval("PT1S");
static $time_zone = new DateTimeZone("America/New_York");
$stmt2 = $db["data"]->prepare('SELECT rank_round_1 AS one, rank_round_2 AS two, rank_round_3 AS three, rank_final AS final FROM submissions
WHERE game_id = :game_id AND member_id = :member_id');
$stmt2->execute([
'game_id' => $game['id'],
'member_id' => $_SESSION['account']->id,
]);
$ranks = $stmt2->fetch(PDO::FETCH_OBJ);
$dates = [
"submitstart" => DateTimeImmutable::createFromFormat(
"U",
$game["submitstart"]
)->setTimezone($time_zone),
"submitend" => DateTimeImmutable::createFromFormat(
"U",
$game["submitend"]
)->setTimezone($time_zone),
"onestart" => DateTimeImmutable::createFromFormat(
"U",
$game["onestart"]
)->setTimezone($time_zone),
"twostart" => DateTimeImmutable::createFromFormat(
"U",
$game["twostart"]
)->setTimezone($time_zone),
"threestart" => DateTimeImmutable::createFromFormat(
"U",
$game["threestart"]
)->setTimezone($time_zone),
"gameend" => DateTimeImmutable::createFromFormat(
"U",
$game["gameend"]
)->setTimezone($time_zone),
];
?>
<article>
<div>
<h3><?= $game["name"] ?></h3>
<p><span>Status: </span><?= get_status_message(
$game["status_id"]
) ?></p>
<?php if (
$game["status_id"] === STATUS_DONE
) { ?><p><span>Your ranking: </span><?= $ranks->final ?? $ranks->three ?? $ranks->two ?? $ranks->one ?? 'N/A' ?></p><?php } ?>
</div>
<div class="flow">
<?php if ($game["status_id"] !== STATUS_DELAYED) { ?>
<p><a href="/games/<?= $game[
"id"
] ?>" class="call-to-action"><?= $game[
"name"
] ?> details</a></p>
<?php } ?>
<?php if ($game["status_id"] === STATUS_DONE) { ?>
<p><a href="/games/<?= $game[
"id"
] ?>/results" class="call-to-action"><?= $game[
"name"
] ?> results</a></p>
<?php } ?>
</div>
</article>
<?php
}
} ?>
</div>
</main>
<?php include "partials/footer.php"; ?>