summaryrefslogtreecommitdiff
path: root/includes/planner.inc
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2023-01-10 14:54:04 +0100
committerMinteck <contact@minteck.org>2023-01-10 14:54:04 +0100
commit99c1d9af689e5325f3cf535c4007b3aeb8325229 (patch)
treee663b3c2ebdbd67c818ac0c5147f0ce1d2463cda /includes/planner.inc
parent9871b03912fc28ad38b4037ebf26a78aa937baba (diff)
downloadpluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.gz
pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.bz2
pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.zip
Update - This is an automated commit
Diffstat (limited to 'includes/planner.inc')
-rw-r--r--includes/planner.inc66
1 files changed, 64 insertions, 2 deletions
diff --git a/includes/planner.inc b/includes/planner.inc
index 2234b84..003d3cc 100644
--- a/includes/planner.inc
+++ b/includes/planner.inc
@@ -8,6 +8,7 @@ require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.inc"; global $isLogg
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/banner.inc";
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/rainbow.inc";
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/functions.inc";
+global $_PROFILE;
$cloudburst = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/planner/ynmuc.json"), true);
$raindrops = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/planner/gdapd.json"), true);
@@ -70,6 +71,67 @@ foreach ($raindrops as $id => $day) {
}
}
+$school = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/school.json"), true);
+
+function formatTime($time) {
+ if ($time === "0:00") return "midnight";
+ if ($time === "12:00") return "noon";
+
+ $parts = explode(":", $time);
+ $hours = (int)$parts[0];
+ $ampm = "";
+
+ if ($hours === 0 || $hours === 12) {
+ $ampm = ($hours === 0 ? "am" : "pm");
+ $hours = 12;
+ } else {
+ if ($hours > 12) {
+ $ampm = "pm";
+ $hours = $hours - 12;
+ } else {
+ $ampm = "am";
+ }
+ }
+
+ if ((int)$parts[1] > 0) {
+ return $hours . ":" . $parts[1] . $ampm;
+ } else {
+ return $hours . $ampm;
+ }
+}
+
+function school($time, $first = false) {
+ global $school;
+ global $_PROFILE;
+
+ $day = date('Y-m-d', $time);
+ $parts = [];
+
+ if (isset($school[$day])) {
+ if (isset($school[$day]["wakeUp"]["timestamp"])) {
+ $parts[] = "waking up at " . formatTime($school[$day]["wakeUp"][$_PROFILE["login"]]) . " (your time)";
+ }
+
+ if (isset($school[$day]["sleep"]["timestamp"])) {
+ $parts[] = "sleeping at " . formatTime($school[$day]["sleep"][$_PROFILE["login"]]) . " (your time)";
+ }
+ }
+
+ if (count($parts) > 0) {
+ if ($first) {
+ return ucfirst(implode(", ", $parts));
+ } else {
+ return " ยท " . implode(", ", $parts);
+ }
+ } else {
+ if ($first) {
+ return "-";
+ } else {
+ return "";
+ }
+ }
+}
+
function day($display, $diff): void { if ($diff < 0) $disabled = true; else $disabled = false; global $cloudburst; global $raindrops; ?>
<?php if (!isset($display)) {
$display = date('l', time() + (86400 * $diff));
@@ -201,9 +263,9 @@ function day($display, $diff): void { if ($diff < 0) $disabled = true; else $dis
<td colspan="10" style="padding: 0;border:none;">
<div style="padding: 5px 10px;border: 1px solid #404040;margin:-1px;border-bottom-left-radius: 10px;border-bottom-right-radius: 10px;">
<?php if (count($dayCloudburst) > 0 && count($dayRaindrops) > 0): ?>
- <?= 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"]) ?>
+ <?= 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"]) ?><?= school(time() + 86400 * $diff, false) ?>
<?php else: ?>
- Unable to calculate who will sleep with who
+ <?= school(time() + 86400 * $diff, true) ?>
<?php endif; ?>
</div>
</td>