139 lines
4.0 KiB
PHP

<?php
include "include.php";
// === LOAD SCORE FILE ===
try {
$teamQuestionDates = loadScoreFile();
} catch (Exception $e) {
showError($e->getMessage());
}
// === PROCESS FORM DATA ===
if (isset($_POST['team']) && isset(QUESTION_POINTS[$_POST['question']])) {
$team = $_POST['team'];
$question = $_POST['question'];
$date = (new DateTime())->format("Y-m-d");
if (isset($teamQuestionDates[$team][$question])) {
unset($teamQuestionDates[$team][$question]);
} else {
$teamQuestionDates[$team][$question] = $date;
}
try {
updateScoreFile($teamQuestionDates);
} catch (Exception $e) {
showError($e->getMessage());
}
}
$teamPoints = array_map("calculatePoints", $teamQuestionDates);
arsort($teamPoints);
$allQuestions = array_keys(QUESTION_POINTS);
?>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel='stylesheet' href='https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap'>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="w3.css">
<script src="script.js"></script>
<script src='https://kit.fontawesome.com/ac98b28c26.js' crossorigin='anonymous'></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<title>AIVD Kerstpuzzel Scorebord - Home</title>
</head>
<body>
<div class="w3-card w3-sidebar w3-collapse w3-bar-block w3-blue-gray w3-text-white">
<a href="#" class="w3-bar-item w3-button">Home</a>
<a href="history.php" class="w3-bar-item w3-button">Scoreverloop</a>
<a href="info.php" class="w3-bar-item w3-button">Informatie</a>
</div>
<div id="overlay" class="overlay w3-container w3-bar-block w3-hide w3-hide-large w3-top w3-blue-gray w3-text-white">
<header class="w3-container w3-border-bottom w3-border-white">
<h1>&nbsp;<i id="overlay-close" class="fas fa-times w3-button w3-right"></i></h1>
</header>
<a href="#" class="w3-bar-item w3-button w3-center">Home</a>
<a href="history.php" class="w3-bar-item w3-button w3-center">Scoreverloop</a>
<a href="info.php" class="w3-bar-item w3-button w3-center">Informatie</a>
</div>
<div class="main w3-container w3-main">
<header class="w3-container w3-border-bottom w3-border-blue-gray">
<h1>AIVD Kerstpuzzel Scorebord<i id="overlay-open" class="fas fa-bars w3-hide-large w3-button w3-right"></i></h1>
</header>
<div class="w3-container">
<h2>Huidige stand</h2>
<ul class="w3-ul">
<?php
$i = 0;
foreach ($teamPoints as $team => $points) {
$class = "w3-badge";
if ($i < 3) {
$class .= " w3-".MEDAL_COLORS[$i];
}
echo "<li class='w3-border-blue-gray'><span class='".$class."'>".($i + 1)."</span> ".$team." (".$points.")</li>\n";
$i++;
}
?>
</ul>
<h2>Opgeloste vragen</h2>
<p>Klik in het kaartje van jouw team op het nummer van een opgave om deze als (on)opgelost te markeren, dan
wordt de ranglijst meteen bijgewerkt.</p>
<div class="w3-row-padding">
<?php
$i = 0;
$n = count($teamQuestionDates);
foreach ($teamQuestionDates as $team => $questionDates) {
echo "<form class='w3-card w3-col m6 l3' action='' method='post'>\n";
echo "<input type='hidden' name='team' value='".$team."'>\n";
echo "<header class='w3-container w3-border-bottom w3-border-blue-gray'>\n";
echo "<h3>".$team."</h3>\n";
echo "</header>\n";
echo "<div class='w3-container'>\n";
echo "<p>\n";
foreach ($allQuestions as $question) {
$color = isset($questionDates[$question]) ? "blue-gray" : "light-gray";
echo "<button class='question-tag w3-button w3-".$color." w3-padding-small w3-round-large' name='question' value='".$question."'>".$question."</button>\n";
}
echo "</p>\n";
echo "</div>\n";
echo "</form>\n";
$i++;
if ($i % 4 == 0 && $i < $n) {
echo "</div>\n";
echo "<div class='w3-row-padding'>\n";
}
}
?>
<div class="w3-rest"></div>
</div>
</div>
</div>
</body>
</html>