From 2162eaa06f7e4764eb3dcfe130ec2c711d0c62ab Mon Sep 17 00:00:00 2001 From: Minteck Date: Thu, 22 Sep 2022 19:47:05 +0200 Subject: Cofronting support and stuff like that --- includes/planner.php | 379 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 361 insertions(+), 18 deletions(-) (limited to 'includes') 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; ?> - - + + ?> - Cloudburst System - Raindrops System + Cloudburst System + Raindrops System @@ -42,52 +100,84 @@ function day($display, $diff): void { global $cloudburst; global $raindrops; ?> - - + colspan="3" colspan="2"> + Multiple merged membersMerge .png" style="width:24px;"> + + + + + + + + + + + Multiple merged membersMerge + + .png" style="width:24px;"> + + + - - + + Add new fronter - + - - + + colspan="3" colspan="2"> Multiple merged membersMerge .png" style="width:24px;"> + + + + + + + + + + + Multiple merged membersMerge + + .png" style="width:24px;"> + + + - + Add new fronter - + - + 0 && count($dayRaindrops) > 0): ?> - will sleep with + will sleep with Unable to calculate who will sleep with who @@ -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 "": + display = "today"; + break; + + case "": + display = "tomorrow"; + break; + + case "": + display = "on "; + break; + + case "": + display = "on "; + break; + + case "": + display = "on "; + break; + + case "": + display = "on "; + break; + + case "": + display = "on "; + 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 = ""; + display = "today"; + break; + + case 1: + date = ""; + display = "tomorrow"; + break; + + case 2: + date = ""; + display = "on "; + break; + + case 3: + date = ""; + display = "on "; + break; + + case 4: + date = ""; + display = "on "; + break; + + case 5: + date = ""; + display = "on "; + break; + + case 6: + date = ""; + display = "on "; + 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; ?> + +