summaryrefslogtreecommitdiff
path: root/pages/evening.inc
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-06-11 16:47:34 +0200
committerRaindropsSys <contact@minteck.org>2023-06-11 16:47:34 +0200
commit6679588e43b0f694421d48e4ddb071972a127dca (patch)
tree2c25b58acd6f29d299d212b4db3f9dae8fdd19ad /pages/evening.inc
parent2e7294c83c6388e3855ce787f0a18c20ed652131 (diff)
downloadpluralconnect-6679588e43b0f694421d48e4ddb071972a127dca.tar.gz
pluralconnect-6679588e43b0f694421d48e4ddb071972a127dca.tar.bz2
pluralconnect-6679588e43b0f694421d48e4ddb071972a127dca.zip
Updated 11 files and added 2 files (automated)
Diffstat (limited to 'pages/evening.inc')
-rw-r--r--pages/evening.inc262
1 files changed, 262 insertions, 0 deletions
diff --git a/pages/evening.inc b/pages/evening.inc
new file mode 100644
index 0000000..6f9e7b8
--- /dev/null
+++ b/pages/evening.inc
@@ -0,0 +1,262 @@
+<?php
+
+$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", "[]");
+
+$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);
+
+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();
+}
+
+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>
+
+<br>
+<div class="container">
+ <div>
+ <h2><?= $pages["evening"]["name"][$lang["_name"]] ?><?= time() >= 1686787200 ? "" : " (Beta)" ?></h2>
+
+ <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>
+
+ <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) {
+ $times[] = getLastFronted($members, $id);
+ }
+ foreach ($a[1] as $id) {
+ $times[] = getLastFronted($members, $id);
+ }
+
+ $timeA = time() - min(...$times);
+ $times = [];
+
+ foreach ($b[0] as $id) {
+ $times[] = getLastFronted($members, $id);
+ }
+ foreach ($b[1] as $id) {
+ $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]; 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: 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">
+ <?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">
+ <?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) {
+ $times[] = getLastFronted($members, $id);
+ }
+ foreach ($pair[1] as $id) {
+ $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 (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 (!in_array(date('Y-m-d', time() + 86400 * $i), $ignored)) $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/components/footer.inc'; ?>