diff options
Diffstat (limited to 'pages')
-rw-r--r-- | pages/api/evening.php | 37 | ||||
-rw-r--r-- | pages/evening.inc | 81 |
2 files changed, 91 insertions, 27 deletions
diff --git a/pages/api/evening.php b/pages/api/evening.php index 9884e05..4d420ab 100644 --- a/pages/api/evening.php +++ b/pages/api/evening.php @@ -9,6 +9,7 @@ if (!$isLoggedIn || $isLowerLoggedIn) { $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); $data = []; $members = $members = [ @@ -94,23 +95,23 @@ usort($pairs, function ($a, $b) use ($members) { $times = []; foreach ($a[0] as $id) { - $times[] = getLastFronted($members, $id); + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); } foreach ($a[1] as $id) { - $times[] = getLastFronted($members, $id); + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); } - $timeA = time() - min(...$times); + $timeA = time() - min($times); $times = []; foreach ($b[0] as $id) { - $times[] = getLastFronted($members, $id); + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); } foreach ($b[1] as $id) { - $times[] = getLastFronted($members, $id); + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); } - $timeB = time() - min(...$times); + $timeB = time() - min($times); return $timeB - $timeA; }); $pairs = array_values($pairs); foreach ($pairs as $pair): $times = []; @@ -118,21 +119,37 @@ usort($pairs, function ($a, $b) use ($members) { foreach ($pair[1] as $id): $times[] = getLastFronted($members, $id); endforeach; endforeach; -$listI = 0; for ($i = 0; $i < 2; $i++): $pair = $pairs[$listI]; +$listI = 0; for ($i = 0; $i < 7; $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)])); + } + $data[$i] = []; if (!in_array(date('Y-m-d', time() + 86400 * $i), $ignored)) { $data[$i][0] = []; $data[$i][1] = []; foreach ($pair[0] as $id): - $data[$i][0][] = getMemberWithoutSystem($id)["display_name"] ?? getMemberWithoutSystem($id)["name"]; + $data[$i][0][] = (getMemberWithoutSystem($id)["display_name"] ?? getMemberWithoutSystem($id)["name"]) . (isset($locked[date('Y-m-d', time() + 86400 * $i)]) ? "*" : ""); endforeach; foreach ($pair[1] as $id): - $data[$i][1][] = getMemberWithoutSystem($id)["display_name"] ?? getMemberWithoutSystem($id)["name"]; + $data[$i][1][] = (getMemberWithoutSystem($id)["display_name"] ?? getMemberWithoutSystem($id)["name"]) . (isset($locked[date('Y-m-d', time() + 86400 * $i)]) ? "*" : ""); endforeach; } else { $data[$i] = null; } -if (!in_array(date('Y-m-d', time() + 86400 * $i), $ignored)) $listI++; if ($listI === count($pairs)) $listI = 0; endfor; + + 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; header("Content-Type: application/json"); die(json_encode($data, JSON_PRETTY_PRINT));
\ No newline at end of file diff --git a/pages/evening.inc b/pages/evening.inc index c0b2818..f40cb20 100644 --- a/pages/evening.inc +++ b/pages/evening.inc @@ -3,9 +3,13 @@ $emergencyHeader = true; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages; 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") { @@ -43,6 +47,26 @@ if (isset($_GET["ignore"]) && isset($_GET["day"])) { 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", "{}"); @@ -169,23 +193,23 @@ if (!isset($cache["content"]) || date('Y-m-d') !== $cache["day"]) { $times = []; foreach ($a[0] as $id) { - $times[] = getLastFronted($members, $id); + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); } foreach ($a[1] as $id) { - $times[] = getLastFronted($members, $id); + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); } - $timeA = time() - min(...$times); + $timeA = time() - min($times); $times = []; foreach ($b[0] as $id) { - $times[] = getLastFronted($members, $id); + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); } foreach ($b[1] as $id) { - $times[] = getLastFronted($members, $id); + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); } - $timeB = time() - min(...$times); + $timeB = time() - min($times); return $timeB - $timeA; }); $pairs = array_values($pairs); foreach ($pairs as $pair): $times = []; ?> @@ -197,26 +221,35 @@ if (!isset($cache["content"]) || date('Y-m-d') !== $cache["day"]) { <?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) ?>) + (<?= time() - max($times) ?>) </li> <?php endforeach; ?> </ul> </details> - <?php $listI = 0; for ($i = 0; $i < 15; $i++): $pair = $pairs[$listI]; if (time() + 86400 * $i >= 1686787200): ?> + <?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 100px; grid-gap: 20px; margin-bottom: 10px;"> + <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" 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"> + <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" 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"> + <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> @@ -226,27 +259,41 @@ if (!isset($cache["content"]) || date('Y-m-d') !== $cache["day"]) { $times = []; foreach ($pair[0] as $id) { - $times[] = getLastFronted($members, $id); + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); } foreach ($pair[1] as $id) { - $times[] = getLastFronted($members, $id); + if (getLastFronted($members, $id) > 0) $times[] = getLastFronted($members, $id); } - $time = time() - min(...$times); + $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> + <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> + <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 (!in_array(date('Y-m-d', time() + 86400 * $i), $ignored)) $listI++; if ($listI === count($pairs)) $listI = 0; endfor; ?> + <?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 |