summaryrefslogtreecommitdiff
path: root/pages/api/schedule.php
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-05-02 18:59:49 +0200
committerRaindropsSys <contact@minteck.org>2023-05-02 18:59:49 +0200
commit8cdbff7146e81546143f1f54e75bfd0eb34d17a0 (patch)
tree47cd0d41c8b34676982d30cec934d5e2080ea9ff /pages/api/schedule.php
parent59b56c2283c12c8a82144a836faee4f12b15e5c1 (diff)
downloadpluralconnect-8cdbff7146e81546143f1f54e75bfd0eb34d17a0.tar.gz
pluralconnect-8cdbff7146e81546143f1f54e75bfd0eb34d17a0.tar.bz2
pluralconnect-8cdbff7146e81546143f1f54e75bfd0eb34d17a0.zip
Updated 3 files and added 2 files (automated)
Diffstat (limited to 'pages/api/schedule.php')
-rw-r--r--pages/api/schedule.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/pages/api/schedule.php b/pages/api/schedule.php
new file mode 100644
index 0000000..489e28f
--- /dev/null
+++ b/pages/api/schedule.php
@@ -0,0 +1,69 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $_PROFILE;
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc";
+if (!$isLoggedIn) header("Location: /-/login") and die();
+
+header("Content-Type: application/json");
+
+$obj = [
+ "today" => [],
+ "tomorrow" => []
+];
+
+$raindrops = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/planner/gdapd.json"), true);
+$cloudburst = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/planner/ynmuc.json"), true);
+
+if (isset($raindrops[date('Y-m-d', time())]) || isset($cloudburst[date('Y-m-d', time())])) {
+ $rd = $raindrops[date('Y-m-d', time())];
+ $cb = $cloudburst[date('Y-m-d', time())];
+ $longest = max(count($rd), count($cb));
+
+ for ($x = 0; $x < $longest; $x++) {
+ $item = [];
+ $item["raindrops"] = null;
+ $item["cloudburst"] = null;
+
+ if (isset($rd[$x])) {
+ $item["raindrops"] = array_map(function ($i) { return getMemberWithoutSystem($i)["display_name"] ?? getMemberWithoutSystem($i)["name"]; }, array_filter($rd[$x], function ($i) { return isset($i); }));
+ } else if (isset($obj["today"][$x - 1]["raindrops"])) {
+ $item["raindrops"] = $obj["today"][$x - 1]["raindrops"];
+ }
+
+ if (isset($cb[$x])) {
+ $item["cloudburst"] = array_map(function ($i) { return getMemberWithoutSystem($i)["display_name"] ?? getMemberWithoutSystem($i)["name"]; }, array_filter($cb[$x], function ($i) { return isset($i); }));
+ } else if (isset($obj["today"][$x - 1]["cloudburst"])) {
+ $item["cloudburst"] = $obj["today"][$x - 1]["cloudburst"];
+ }
+
+ $obj["today"][] = $item;
+ }
+}
+
+if (isset($raindrops[date('Y-m-d', time() + 86400)]) || isset($cloudburst[date('Y-m-d', time() + 86400)])) {
+ $rd = $raindrops[date('Y-m-d', time() + 86400)];
+ $cb = $cloudburst[date('Y-m-d', time() + 86400)];
+ $longest = max(count($rd), count($cb));
+
+ for ($x = 0; $x < $longest; $x++) {
+ $item = [];
+ $item["raindrops"] = null;
+ $item["cloudburst"] = null;
+
+ if (isset($rd[$x])) {
+ $item["raindrops"] = array_map(function ($i) { return getMemberWithoutSystem($i)["display_name"] ?? getMemberWithoutSystem($i)["name"]; }, array_filter($rd[$x], function ($i) { return isset($i); }));
+ } else if (isset($obj["today"][$x - 1]["raindrops"])) {
+ $item["raindrops"] = $obj["today"][$x - 1]["raindrops"];
+ }
+
+ if (isset($cb[$x])) {
+ $item["cloudburst"] = array_map(function ($i) { return getMemberWithoutSystem($i)["display_name"] ?? getMemberWithoutSystem($i)["name"]; }, array_filter($cb[$x], function ($i) { return isset($i); }));
+ } else if (isset($obj["today"][$x - 1]["cloudburst"])) {
+ $item["cloudburst"] = $obj["today"][$x - 1]["cloudburst"];
+ }
+
+ $obj["tomorrow"][] = $item;
+ }
+}
+
+die(json_encode($obj, JSON_PRETTY_PRINT)); \ No newline at end of file