diff options
Diffstat (limited to 'includes/planner.php')
-rw-r--r-- | includes/planner.php | 379 |
1 files changed, 361 insertions, 18 deletions
diff --git a/includes/planner.php b/includes/planner.php index 8644b25..f98d83b 100644 --- a/includes/planner.php +++ b/includes/planner.php @@ -12,12 +12,70 @@ require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/functions.php"; $cloudburst = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc-planner.json"), true); $raindrops = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd-planner.json"), true); +foreach ($cloudburst as $id => $day) { + foreach ($day as $index => $fronter) { + if (is_string($fronter)) { + $cloudburst[$id][$index] = [$fronter]; + } else if (is_array($fronter)) { + if (count($fronter) < 2) { + if (!isset($cloudburst[$id][$index][0])) $cloudburst[$id][$index][0] = null; + $cloudburst[$id][$index][1] = null; + } else if (count($fronter) > 2) { + $array = []; + + if (isset($cloudburst[$id][$index][0])) { + $array[0] = $cloudburst[$id][$index][0]; + } else { + $array[0] = null; + } + + if (isset($cloudburst[$id][$index][1])) { + $array[1] = $cloudburst[$id][$index][1]; + } else { + $array[1] = null; + } + + $cloudburst[$id][$index] = $array; + } + } + } +} + +foreach ($raindrops as $id => $day) { + foreach ($day as $index => $fronter) { + if (is_string($fronter)) { + $raindrops[$id][$index] = [$fronter]; + } else if (is_array($fronter)) { + if (count($fronter) < 2) { + if (!isset($raindrops[$id][$index][0])) $raindrops[$id][$index][0] = null; + $raindrops[$id][$index][1] = null; + } else if (count($fronter) > 2) { + $array = []; + + if (isset($raindrops[$id][$index][0])) { + $array[0] = $raindrops[$id][$index][0]; + } else { + $array[0] = null; + } + + if (isset($raindrops[$id][$index][1])) { + $array[1] = $raindrops[$id][$index][1]; + } else { + $array[1] = null; + } + + $raindrops[$id][$index] = $array; + } + } + } +} + function day($display, $diff): void { global $cloudburst; global $raindrops; ?> <?php if (!isset($display)) { $display = date('l', time() + (86400 * $diff)); }?> - <tr class="planner-day" id="planner-header-1"> - <td colspan="4"><?= $display ?></td> + <tr class="planner-day" id="planner-header-<?= $diff ?>"> + <td colspan="10"><?= $display ?></td> <?php if (!isset($cloudburst[date('Y-m-d', time() + (86400 * $diff))])) $cloudburst[date('Y-m-d', time() + (86400 * $diff))] = []; @@ -33,8 +91,8 @@ function day($display, $diff): void { global $cloudburst; global $raindrops; ?> ?> </tr> <tr class="planner-header"> - <td colspan="2">Cloudburst System</td> - <td colspan="2">Raindrops System</td> + <td colspan="5">Cloudburst System</td> + <td colspan="5">Raindrops System</td> </tr> <?php for ($i = 0; $i <= $biggest; $i++): ?> <tr class="planner-member"> @@ -42,52 +100,84 @@ function day($display, $diff): void { global $cloudburst; global $raindrops; ?> <td class="planner-member-id"> <?= $index + 1 ?> </td> - <td class="planner-link"> - <?php $member = getMemberWithoutSystem($dayCloudburst[$index]); ?> + <td class="planner-link" style="width:50vw;" <?php if (!isset($dayCloudburst[$index][1])): ?>colspan="3" <?php else: ?>colspan="2"<?php endif; ?>> + <?php $member = getMemberWithoutSystem($dayCloudburst[$index][0]); ?> <?php if ($member["name"] === "fusion"): ?> <a class="member-link" onclick="openEditFronter('cloudburst', <?= $index ?>, '<?= date('Y-m-d', time() + (86400 * $diff)) ?>')"><img src="/assets/logo/logo.png" style="width:24px;"> <span class="text-muted merge-desktop">Multiple merged members</span><span class="text-muted merge-mobile">Merge</span></a> <?php else: ?> <a class="member-link" onclick="openEditFronter('cloudburst', <?= $index ?>, '<?= date('Y-m-d', time() + (86400 * $diff)) ?>')"><img src="/assets/uploads/pt<?= file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . resolveMember($member['name']) . ".png") ? "-" . $member['name'] : "" ?>.png" style="width:24px;"> <?= getMiniName($member["display_name"] ?? $member["name"]) ?></a> <?php endif; ?> </td> + <?php if (!isset($dayCloudburst[$index][1])): ?> + <td class="planner-cofronter-inner planner-link" style="width:5%;text-align:center;"> + <a href="#" onclick="addCofronter('cloudburst', <?= $diff ?>, <?= $index ?>);" class="planner-add-link"> + <img src="/assets/icons/add.svg" alt="" class="planner-add-icon"> + </a> + </td> + <?php else: ?> + <td class="planner-link" style="width:41.35vw;" colspan="2"> + <?php $member = getMemberWithoutSystem($dayCloudburst[$index][1]); ?> + <?php if ($member["name"] === "fusion"): ?> + <a class="member-link" onclick="openEditCofronter('cloudburst', <?= $index ?>, '<?= date('Y-m-d', time() + (86400 * $diff)) ?>')"><img src="/assets/logo/logo.png" style="width:24px;"> <span class="text-muted merge-desktop">Multiple merged members</span><span class="text-muted merge-mobile">Merge</span></a> + <?php else: ?> + <a class="member-link" onclick="openEditCofronter('cloudburst', <?= $index ?>, '<?= date('Y-m-d', time() + (86400 * $diff)) ?>')"><img src="/assets/uploads/pt<?= file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . resolveMember($member['name']) . ".png") ? "-" . $member['name'] : "" ?>.png" style="width:24px;"> <?= getMiniName($member["display_name"] ?? $member["name"]) ?></a> + <?php endif; ?> + </td> + <?php endif; ?> <?php elseif ($index === count($dayCloudburst)): ?> - <td class="planner-add-inner planner-link" colspan="2"> - <a href="#" onclick="addFronter('cloudburst', <?= $diff ?>);" class="planner-add-link"> + <td class="planner-add-inner planner-link" colspan="5"> + <a href="#" onclick="addFronter('cloudburst', <?= $diff ?>, <?= $index ?>);" class="planner-add-link"> <img src="/assets/icons/add.svg" alt="" class="planner-add-icon"> <span class="planner-add-text">Add new fronter</span> </a> </td> <?php else: ?> - <td colspan="2" class="planner-empty"></td> + <td colspan="5" class="planner-empty"></td> <?php endif; ?> <?php if (isset($dayRaindrops[$index])): ?> <td class="planner-member-id"> <?= $index + 1 ?> </td> - <?php $member = getMemberWithoutSystem($dayRaindrops[$index]); ?> - <td class="planner-link"> + <?php $member = getMemberWithoutSystem($dayRaindrops[$index][0]); ?> + <td class="planner-link" style="width:50vw;" <?php if (!isset($dayRaindrops[$index][1])): ?>colspan="3" <?php else: ?>colspan="2"<?php endif; ?>> <?php if ($member["name"] === "fusion"): ?> <a class="member-link" onclick="openEditFronter('raindrops', <?= $index ?>, '<?= date('Y-m-d', time() + (86400 * $diff)) ?>')"><img src="/assets/logo/logo.png" style="width:24px;"> <span class="text-muted merge-desktop">Multiple merged members</span><span class="text-muted merge-mobile">Merge</span></a> <?php else: ?> <a class="member-link" onclick="openEditFronter('raindrops', <?= $index ?>, '<?= date('Y-m-d', time() + (86400 * $diff)) ?>')"><img src="/assets/uploads/pt<?= file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . resolveMember($member['name']) . ".png") ? "-" . $member['name'] : "" ?>.png" style="width:24px;"> <?= getMiniName($member["display_name"] ?? $member["name"]) ?></a> <?php endif; ?> </td> + <?php if (!isset($dayRaindrops[$index][1])): ?> + <td class="planner-cofronter-inner planner-link" style="width:5%;text-align:center;"> + <a href="#" onclick="addCofronter('raindrops', <?= $diff ?>, <?= $index ?>);" class="planner-add-link"> + <img src="/assets/icons/add.svg" alt="" class="planner-add-icon"> + </a> + </td> + <?php else: ?> + <td class="planner-link" style="width:41.35vw;" colspan="2"> + <?php $member = getMemberWithoutSystem($dayRaindrops[$index][1]); ?> + <?php if ($member["name"] === "fusion"): ?> + <a class="member-link" onclick="openEditCofronter('raindrops', <?= $index ?>, '<?= date('Y-m-d', time() + (86400 * $diff)) ?>')"><img src="/assets/logo/logo.png" style="width:24px;"> <span class="text-muted merge-desktop">Multiple merged members</span><span class="text-muted merge-mobile">Merge</span></a> + <?php else: ?> + <a class="member-link" onclick="openEditCofronter('raindrops', <?= $index ?>, '<?= date('Y-m-d', time() + (86400 * $diff)) ?>')"><img src="/assets/uploads/pt<?= file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . resolveMember($member['name']) . ".png") ? "-" . $member['name'] : "" ?>.png" style="width:24px;"> <?= getMiniName($member["display_name"] ?? $member["name"]) ?></a> + <?php endif; ?> + </td> + <?php endif; ?> <?php elseif ($index === count($dayRaindrops)): ?> - <td class="planner-add-inner planner-link" colspan="2"> + <td class="planner-add-inner planner-link" colspan="5"> <a href="#" onclick="addFronter('raindrops', <?= $diff ?>);" class="planner-add-link"> <img src="/assets/icons/add.svg" alt="" class="planner-add-icon"> <span class="planner-add-text">Add new fronter</span> </a> </td> <?php else: ?> - <td colspan="2" class="planner-empty"></td> + <td colspan="5" class="planner-empty"></td> <?php endif; ?> </tr> <?php $index++; endfor; ?> <tr class="planner-day planner-end-of-day"> - <td colspan="4"> + <td colspan="10"> <?php if (count($dayCloudburst) > 0 && count($dayRaindrops) > 0): ?> - <?= getMiniName(getMemberWithoutSystem($dayCloudburst[count($dayCloudburst) - 1])["display_name"] ?? getMemberWithoutSystem($dayCloudburst[count($dayCloudburst) - 1])["name"]) ?> will sleep with <?= getMiniName(getMemberWithoutSystem($dayRaindrops[count($dayRaindrops) - 1])["display_name"] ?? getMemberWithoutSystem($dayRaindrops[count($dayRaindrops) - 1])["name"]) ?> + <?= getMiniName(getMemberWithoutSystem($dayCloudburst[count($dayCloudburst) - 1][0])["display_name"] ?? getMemberWithoutSystem($dayCloudburst[count($dayCloudburst) - 1][0])["name"]) ?> will sleep with <?= getMiniName(getMemberWithoutSystem($dayRaindrops[count($dayRaindrops) - 1][0])["display_name"] ?? getMemberWithoutSystem($dayRaindrops[count($dayRaindrops) - 1][0])["name"]) ?> <?php else: ?> Unable to calculate who will sleep with who <?php endif; ?> @@ -312,10 +402,10 @@ function day($display, $diff): void { global $cloudburst; global $raindrops; ?> index: id } - if (fronting[system][date][id] === "lzlaq" || fronting[system][date][id] === "irxyh") { + if (fronting[system][date][id][0] === "lzlaq" || fronting[system][date][id][0] === "irxyh") { document.getElementById("edit-fronter-name").innerText = "merged members"; } else { - document.getElementById("edit-fronter-name").innerText = names[fronting[system][date][id]] ?? fronting[system][date][id]; + document.getElementById("edit-fronter-name").innerText = names[fronting[system][date][id][0]] ?? fronting[system][date][id][0]; } document.getElementById("edit-fronter-date").innerText = display; @@ -326,6 +416,123 @@ function day($display, $diff): void { global $cloudburst; global $raindrops; ?> modal.show(); } + function openEditCofronter(system, id, date) { + let display; + + switch (date) { + case "<?= date('Y-m-d') ?>": + display = "today"; + break; + + case "<?= date('Y-m-d', time() + 86400) ?>": + display = "tomorrow"; + break; + + case "<?= date('Y-m-d', time() + (86400 * 2)) ?>": + display = "on <?= date('l', time() + (86400 * 2)) ?>"; + break; + + case "<?= date('Y-m-d', time() + (86400 * 3)) ?>": + display = "on <?= date('l', time() + (86400 * 3)) ?>"; + break; + + case "<?= date('Y-m-d', time() + (86400 * 4)) ?>": + display = "on <?= date('l', time() + (86400 * 4)) ?>"; + break; + + case "<?= date('Y-m-d', time() + (86400 * 5)) ?>": + display = "on <?= date('l', time() + (86400 * 5)) ?>"; + break; + + case "<?= date('Y-m-d', time() + (86400 * 6)) ?>": + display = "on <?= date('l', time() + (86400 * 6)) ?>"; + break; + } + + window.selectedFronting = { + system: system === "cloudburst" ? "ynmuc" : "gdapd", + date: date, + index: id + } + + document.getElementById("edit-cofronter-name").innerText = names[fronting[system][date][id][1]] ?? fronting[system][date][id][1]; + document.getElementById("edit-cofronter-name2").innerText = names[fronting[system][date][id][0]] ?? fronting[system][date][id][0]; + + document.getElementById("edit-cofronter-date").innerText = display; + document.getElementById("edit-cofronter-pos").innerText = ordinal(id + 1); + document.getElementById("edit-cofronter-system").innerText = system === "cloudburst" ? "Cloudburst System" : "Raindrops System"; + + let modal = new bootstrap.Modal(document.getElementById('edit-cofronter')); + modal.show(); + } + + function addCofronter(system, offset, index) { + let date; + let display; + + switch (offset) { + case 0: + date = "<?= date('Y-m-d') ?>"; + display = "today"; + break; + + case 1: + date = "<?= date('Y-m-d', time() + 86400) ?>"; + display = "tomorrow"; + break; + + case 2: + date = "<?= date('Y-m-d', time() + (86400 * 2)) ?>"; + display = "on <?= date('l', time() + (86400 * 2)) ?>"; + break; + + case 3: + date = "<?= date('Y-m-d', time() + (86400 * 3)) ?>"; + display = "on <?= date('l', time() + (86400 * 3)) ?>"; + break; + + case 4: + date = "<?= date('Y-m-d', time() + (86400 * 4)) ?>"; + display = "on <?= date('l', time() + (86400 * 4)) ?>"; + break; + + case 5: + date = "<?= date('Y-m-d', time() + (86400 * 5)) ?>"; + display = "on <?= date('l', time() + (86400 * 5)) ?>"; + break; + + case 6: + date = "<?= date('Y-m-d', time() + (86400 * 6)) ?>"; + display = "on <?= date('l', time() + (86400 * 6)) ?>"; + break; + } + + window.selectedFronting = { + system: system === "cloudburst" ? "ynmuc" : "gdapd", + date: date, + index: index + } + + window.currentWorkingDate = date; + document.getElementById("new-cofronter-date").innerText = display; + document.getElementById("new-cofronter-system").innerText = system === "cloudburst" ? "Cloudburst System" : "Raindrops System"; + window.addSystem = system === "raindrops" ? "gdapd" : "ynmuc"; + + if (fronting[system][date][index][0] === "lzlaq" || fronting[system][date][index][0] === "irxyh") { + document.getElementById("new-cofronter-main").innerText = "merged members"; + } else { + document.getElementById("new-cofronter-main").innerText = names[fronting[system][date][index][0]] ?? fronting[system][date][index][0]; + } + + document.getElementById("list2").style.display = "block"; + document.getElementById("search2-results").style.display = "none"; + document.getElementById("search2").value = ""; + + let modal = new bootstrap.Modal(document.getElementById('new-cofronter')); + modal.show(); + document.getElementById("search2").focus(); + } + function addFronter(system, offset) { let date; let display; @@ -393,6 +600,18 @@ function day($display, $diff): void { global $cloudburst; global $raindrops; ?> }); } + function confirmCofronterAdd(system, id) { + Array.from(document.getElementsByClassName("new-cofronter-link")).forEach((i) => { + i.classList.add("disabled"); + }); + + document.getElementById("new-cofronter-close").classList.add("disabled"); + + window.fetch("/api/fronter?t=cofront&d=" + window.selectedFronting["date"] + "&m=" + id + "&s=" + system + "&i=" + window.selectedFronting["index"]).then(() => { + location.reload(); + }); + } + function deleteFronter() { Array.from(document.getElementsByClassName("edit-fronter-link")).forEach((i) => { i.classList.add("disabled"); @@ -405,6 +624,18 @@ function day($display, $diff): void { global $cloudburst; global $raindrops; ?> }); } + function deleteCofronter() { + Array.from(document.getElementsByClassName("edit-cofronter-link")).forEach((i) => { + i.classList.add("disabled"); + }); + + document.getElementById("edit-cofronter-close").classList.add("disabled"); + + window.fetch("/api/fronter?t=codelete&d=" + window.selectedFronting["date"] + "&i=" + window.selectedFronting["index"] + "&s=" + window.selectedFronting["system"]).then(() => { + location.reload(); + }); + } + function moveFronterDown() { Array.from(document.getElementsByClassName("edit-fronter-link")).forEach((i) => { i.classList.add("disabled"); @@ -418,7 +649,12 @@ function day($display, $diff): void { global $cloudburst; global $raindrops; ?> } function viewFronterPage() { - let id = fronting[window.selectedFronting["system"] === "ynmuc" ? "cloudburst" : "raindrops"][window.selectedFronting["date"]][window.selectedFronting["index"]]; + let id = fronting[window.selectedFronting["system"] === "ynmuc" ? "cloudburst" : "raindrops"][window.selectedFronting["date"]][window.selectedFronting["index"]][0]; + location.href = "/" + id; + } + + function viewCofronterPage() { + let id = fronting[window.selectedFronting["system"] === "ynmuc" ? "cloudburst" : "raindrops"][window.selectedFronting["date"]][window.selectedFronting["index"]][1]; location.href = "/" + id; } @@ -465,6 +701,35 @@ function day($display, $diff): void { global $cloudburst; global $raindrops; ?> </div> </div> +<div class="modal" id="new-cofronter" data-bs-backdrop="static" data-bs-keyboard="false"> + <div class="modal-dialog"> + <div class="modal-content"> + + <div class="modal-header"> + <h4 class="modal-title">Add new co-fronter <span id="new-cofronter-date">n/a</span> with <span id="new-cofronter-main">n/a</span></h4> + <button id="new-cofronter-close" type="button" class="btn-close" data-bs-dismiss="modal"></button> + </div> + + <div class="modal-body"> + <p class="text-muted">Adding for the <span id="new-cofronter-system">n/a</span></p> + + <input type="text" placeholder="Search for a pony..." class="form-control" style="margin-bottom:15px;color:white;background:#111;border-color:#222;" id="search2"> + + <div id="list2"> + <div class="list-group"> + <?php foreach (scoreOrderGlobal() as $member): ?> + <a id="list2-pony-<?= $member['id'] ?>" onclick="confirmCofronterAdd(window.addSystem, '<?= $member['id'] ?>');" class="new-cofronter-link member-link list-group-item list-group-item-action" href="#"><img src="/assets/uploads/pt<?= file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . resolveMember($member['name']) . ".png") ? "-" . $member['name'] : "" ?>.png" style="width:24px;"> <?= getMiniName($member["display_name"] ?? $member["name"]) ?><peh-schedule-add></peh-schedule-add></a> + <?php endforeach; $member = getSystemMember("gdapd", "irxyh") ?> + </div> + </div> + + <div id="search2-results" class="list-group"></div> + </div> + + </div> + </div> +</div> + <div class="modal" id="edit-fronter" data-bs-backdrop="static" data-bs-keyboard="false"> <div class="modal-dialog"> <div class="modal-content"> @@ -501,6 +766,38 @@ function day($display, $diff): void { global $cloudburst; global $raindrops; ?> </div> </div> +<div class="modal" id="edit-cofronter" data-bs-backdrop="static" data-bs-keyboard="false"> + <div class="modal-dialog"> + <div class="modal-content"> + + <div class="modal-header"> + <h4 class="modal-title">Edit <span id="edit-cofronter-name">n/a</span> fronting with <span id="edit-cofronter-name2">n/a</span> in <span id="edit-cofronter-pos">n/a</span> <span id="edit-cofronter-date">n/a</span></h4> + <button id="edit-cofronter-close" type="button" class="btn-close" data-bs-dismiss="modal"></button> + </div> + + <div class="modal-body"> + <p class="text-muted">Editing for the <span id="edit-cofronter-system">n/a</span></p> + + <div class="list-group" id="list-cloudburst"> + <a class="list-group-item list-group-item-action edit-cofronter-link" onclick="deleteCofronter();"> + <img src="/assets/icons/delete.svg" style="width:24px;filter:invert(1);vertical-align: middle;"> + <span style="vertical-align: middle;">Delete</span> + </a> + <!--<a class="list-group-item list-group-item-action edit-fronter-link" onclick="invertCofronter();"> + <img src="/assets/icons/invert.svg" style="width:24px;filter:invert(1);vertical-align: middle;"> + <span style="vertical-align: middle;">Invert main and secondary fronters</span> + </a>--> + <a class="list-group-item list-group-item-action edit-cofronter-link" onclick="viewCofronterPage();"> + <img src="/assets/icons/page.svg" style="width:24px;filter:invert(1);vertical-align: middle;"> + <span style="vertical-align: middle;">View page</span> + </a> + </div> + </div> + + </div> + </div> +</div> + <script src="/assets/editor/fuse.js"></script> <!--suppress JSUnresolvedFunction --> <script> @@ -573,6 +870,52 @@ function day($display, $diff): void { global $cloudburst; global $raindrops; ?> event.preventDefault(); } }); + + function search2(event) { + if (event.key === "Enter") { + return; + } + + let query = document.getElementById("search2").value; + let results = fuse.search(query).map((i) => { + return { + id: i.item.id, + score: i.score + }; + }); + + let unfiltered = results; + + results = results.filter((i) => { + return i.score < 0.7; + }); + + console.log("Before:", unfiltered, "After:", results); + + document.getElementById("list2").style.display = "none"; + document.getElementById("search2-results").style.display = "block"; + document.getElementById("search2-results").innerHTML = ""; + + for (let result of results) { + document.getElementById("search2-results").innerHTML += document.getElementById("list2-pony-" + result.id).outerHTML; + } + + console.log(results); + + if (query.trim() === "") { + document.getElementById("list2").style.display = "block"; + document.getElementById("search2-results").style.display = "none"; + } + } + + document.getElementById("search2").onchange = document.getElementById("search2").onkeyup = document.getElementById("search2").onkeydown = search2; + + document.getElementById("search2").addEventListener("keydown", (event) => { + if (event.key === "Enter") { + document.querySelector("#search2-results .new-cofronter-link").click(); + event.preventDefault(); + } + }); </script> <?php |