diff options
Diffstat (limited to 'pages/evening.inc')
-rw-r--r-- | pages/evening.inc | 308 |
1 files changed, 4 insertions, 304 deletions
diff --git a/pages/evening.inc b/pages/evening.inc index f40cb20..59c34e4 100644 --- a/pages/evening.inc +++ b/pages/evening.inc @@ -1,311 +1,11 @@ <?php -$emergencyHeader = true; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/evening.inc"; -if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/ignored.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/ignored.json", "[]"); -if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/locked.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/locked.json", "{}"); - -if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json")) unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json"); - -$pairs = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/pairs.json"), true); -$ignored = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/ignored.json"), true); -$locked = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/locked.json"), true); - -if (isset($_GET["ignore"]) && isset($_GET["day"])) { - if ($_GET["ignore"] === "1") { - if (preg_match("/^\d{4}-\d{2}-\d{2}$/m", $_GET["day"]) === false) { - header("Location: /-/evening"); - die(); - } - - if (!in_array($_GET["day"], $ignored)) { - $ignored[] = $_GET["day"]; - } - - if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json")) unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json"); - - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/ignored.json", json_encode($ignored)); - header("Location: /-/evening"); - die(); - } elseif ($_GET["ignore"] === "0") { - if (preg_match("/^\d{4}-\d{2}-\d{2}$/m", $_GET["day"]) === false) { - header("Location: /-/evening"); - die(); - } - - if (in_array($_GET["day"], $ignored)) { - unset($ignored[array_search($_GET["day"], $ignored)]); - } - - if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json")) unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json"); - - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/ignored.json", json_encode($ignored)); - header("Location: /-/evening"); - die(); - } - - die(); -} - -if (isset($_GET["lock"]) && isset($_GET["day"]) && isset($_GET["data"])) { - if (isset($locked[$_GET["day"]])) { - unset($locked[$_GET["day"]]); - - if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json")) unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json"); - - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/locked.json", json_encode($locked)); - header("Location: /-/evening"); - die(); - } else { - $locked[$_GET["day"]] = $_GET["data"]; - - if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json")) unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json"); - - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/locked.json", json_encode($locked)); - header("Location: /-/evening"); - die(); - } -} - -require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; - -if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json", "{}"); -$cache = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json"), true); - -if (!isset($cache["content"]) || date('Y-m-d') !== $cache["day"]) { - ob_start(); - - $members = $members = [ - ...array_map(function ($i) { - $system = "ynmuc"; - $i["_lastFronted"] = -1; - $id = $i["id"]; - $memberData = $i; - - $fronters = array_map(function ($item) { - return $item["id"]; - }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["members"]); - - if (in_array($id, $fronters)) { - $i["_lastFronted"] = time(); - } else { - $switches = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json"), true); - - $thisMember = array_filter($switches, function ($item) use ($memberData) { - return in_array($memberData["id"], $item["members"]); - }); - - $thisMember = array_values($thisMember); - $frontingEnd = null; - - if (count($thisMember) > 0) { - $thisIndex = array_search($thisMember[0], $switches); - - $frontingStart = $thisMember[0]; - $frontingEnd = $switches[$thisIndex - 1]; - } - - if ($frontingEnd !== null && isset($frontingStart)) { - $i["_lastFronted"] = strtotime($frontingEnd["timestamp"]); - } - } - - return $i; - }, array_values(array_filter(scoreOrderGlobal(), function ($i) { - return $i["_system"] === "ynmuc"; - }))), - ...array_map(function ($i) { - $system = "gdapd"; - $i["_lastFronted"] = -1; - $id = $i["id"]; - $memberData = $i; - - $fronters = array_map(function ($item) { - return $item["id"]; - }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["members"]); - - if (in_array($id, $fronters)) { - $i["_lastFronted"] = time(); - } else { - $switches = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json"), true); - - $thisMember = array_filter($switches, function ($item) use ($memberData) { - return in_array($memberData["id"], $item["members"]); - }); - - $thisMember = array_values($thisMember); - $frontingEnd = null; - - if (count($thisMember) > 0) { - $thisIndex = array_search($thisMember[0], $switches); - - $frontingStart = $thisMember[0]; - $frontingEnd = $switches[$thisIndex - 1]; - } - - if ($frontingEnd !== null && isset($frontingStart)) { - $i["_lastFronted"] = strtotime($frontingEnd["timestamp"]); - } - } - - return $i; - }, array_values(array_filter(scoreOrderGlobal(), function ($i) { - return $i["_system"] === "gdapd"; - }))) - ]; - - ?> - -<style> - @media (max-width: 767px) { - .member-name, .member-list-separator { - display: none; - } - - .member-collection { - width: 100%; - text-align: center; - } - } - - .member-link:hover { - opacity: .75; - } -</style> +require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; ?> <br> -<div class="container"> - <div> - <h2><?= $pages["evening"]["name"][$lang["_name"]] ?><?= time() >= 1686787200 ? "" : " (Beta)" ?></h2> - - <?php if (time() < 1686787200): ?> - <div class="alert alert-warning"> - <b>The evening schedule will replace the fronting schedule starting June 15<sup>th</sup>.</b> The fronting schedule page contains more information and shows the schedule up to that date. The evening schedule is experimental until then. - </div> - <?php endif; ?> - - <details> - <summary style="list-style: none; outline: none; cursor: text;"> - <p>Click on the "Ignore" button to mark an evening as ignored and shift the schedule one day after. You can revert this by clicking on "Unignore".</p> - </summary> - <ul> - <?php usort($pairs, function ($a, $b) use ($members) { - $times = []; - - foreach ($a[0] as $id) { - if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); - } - foreach ($a[1] as $id) { - if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); - } - - $timeA = time() - min($times); - $times = []; - - foreach ($b[0] as $id) { - if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); - } - foreach ($b[1] as $id) { - if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); - } - - $timeB = time() - min($times); - - return $timeB - $timeA; - }); $pairs = array_values($pairs); foreach ($pairs as $pair): $times = []; ?> - <li> - <?php foreach ($pair[0] as $id): ?> - <img style="width: 24px;" src="<?= getAsset("ynmuc", $id) ?>"> <?= getMemberWithoutSystem($id)["display_name"] ?> - <?php $times[] = getLastFronted($members, $id); endforeach; ?> - with - <?php foreach ($pair[1] as $id): ?> - <img style="width: 24px;" src="<?= getAsset("gdapd", $id) ?>"> <?= getMemberWithoutSystem($id)["display_name"] ?> - <?php $times[] = getLastFronted($members, $id); endforeach; ?> - (<?= time() - max($times) ?>) - </li> - <?php endforeach; ?> - </ul> - </details> - - <?php $listI = 0; for ($i = 0; $i < 15; $i++): $pair = $pairs[$listI]; - $realPair = $pair; - - if (isset($locked[date('Y-m-d', time() + 86400 * $i)])) { - $pair = array_map(function ($i) { - return explode(",", $i); - }, explode("|", $locked[date('Y-m-d', time() + 86400 * $i)])); - } - - if (time() + 86400 * $i >= 1686787200): ?> - <h4><?= date('l j', time() + 86400 * $i) ?></h4> - <div style="display: grid; grid-template-columns: repeat(2, 1fr) 100px 150px; grid-gap: 20px; margin-bottom: 10px;"> - <div style="display: flex; align-items: center;<?php if (in_array(date('Y-m-d', time() + 86400 * $i), $ignored)): ?>opacity: .75; filter: saturate(0);<?php endif; ?>"> - <div class="member-collection"> - <?php foreach ($pair[0] as $id): ?> - <a class="member-link <?php if (isset($locked[date('Y-m-d', time() + 86400 * $i)])): ?>text-warning" style="font-weight: bold;<?php endif; ?>" href="/<?= getMemberWithoutSystem($id)["name"] ?>"><img style="width: 24px;" src="<?= getAsset("ynmuc", $id, "heads") ?>"> <span class="member-name" style="<?php if (in_array(date('Y-m-d', time() + 86400 * $i), $ignored)): ?>text-decoration: line-through;<?php endif; ?>"><?= getMemberWithoutSystem($id)["display_name"] ?></span></a><br class="member-list-separator"> - <?php $times[] = getLastFronted($members, $id); endforeach; ?> - </div> - </div> - <div style="display: flex; align-items: center;<?php if (in_array(date('Y-m-d', time() + 86400 * $i), $ignored)): ?>opacity: .75; filter: saturate(0);<?php endif; ?>"> - <div class="member-collection"> - <?php foreach ($pair[1] as $id): ?> - <a class="member-link <?php if (isset($locked[date('Y-m-d', time() + 86400 * $i)])): ?>text-warning" style="font-weight: bold;<?php endif; ?>" href="/<?= getMemberWithoutSystem($id)["name"] ?>"><img style="width: 24px;" src="<?= getAsset("gdapd", $id, "heads") ?>"> <span class="member-name" style="<?php if (in_array(date('Y-m-d', time() + 86400 * $i), $ignored)): ?>text-decoration: line-through;<?php endif; ?>"><?= getMemberWithoutSystem($id)["display_name"] ?></span></a><br class="member-list-separator"> - <?php $times[] = getLastFronted($members, $id); endforeach; ?> - </div> - </div> - <div style="display: flex; align-items: center; justify-content: center;"> - <?php - - $times = []; - - foreach ($pair[0] as $id) { - if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); - } - foreach ($pair[1] as $id) { - if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); - } - - $time = time() - min($times); - echo(timeAgo(time() - $time)); - - ?> - </div> - <div style="display: flex; align-items: center; justify-content: center;"> - <?php if (isset($locked[date('Y-m-d', time() + 86400 * $i)])): ?> - <a href="?lock&day=<?= date('Y-m-d', time() + 86400 * $i) ?>&data=<?= implode(",", $pair[0]) . "|" . implode(",", $pair[1]) ?>" class="btn btn-outline-secondary">Unlock</a> - <?php else: ?> - <a href="?lock&day=<?= date('Y-m-d', time() + 86400 * $i) ?>&data=<?= implode(",", $pair[0]) . "|" . implode(",", $pair[1]) ?>" class="btn btn-outline-primary">Lock</a> - <?php endif; ?> - <?php if (in_array(date('Y-m-d', time() + 86400 * $i), $ignored)): ?> - <a href="?ignore=0&day=<?= date('Y-m-d', time() + 86400 * $i) ?>" class="btn btn-outline-success">Unignore</a> - <?php else: ?> - <a href="?ignore=1&day=<?= date('Y-m-d', time() + 86400 * $i) ?>" class="btn btn-outline-danger">Ignore</a> - <?php endif; ?> - </div> - </div> - <?= $i < 14 ? "<hr>" : "" ?> - <?php endif; - - if ( - (!isset($locked[date('Y-m-d', time() + 86400 * $i)]) && !in_array(date('Y-m-d', time() + 86400 * $i), $ignored)) - || (isset($locked[date('Y-m-d', time() + 86400 * $i)]) && $locked[date('Y-m-d', time() + 86400 * $i)] === implode(",", $realPair[0]) . "|" . implode(",", $realPair[1])) - ) { - $listI++; - } - - if ($listI === count($pairs)) $listI = 0; endfor; ?> - </div> -</div> -<?php - - $cache["content"] = ob_get_contents(); - $cache["day"] = date('Y-m-d'); - ob_end_clean(); -} - -echo($cache["content"]); -file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json", json_encode($cache)); - -?> +<?php require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/fragments/evening.inc"; ?> <?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/footer.inc'; ?> |