summaryrefslogtreecommitdiff
path: root/includes/system/subsystem.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/system/subsystem.php')
-rw-r--r--includes/system/subsystem.php124
1 files changed, 124 insertions, 0 deletions
diff --git a/includes/system/subsystem.php b/includes/system/subsystem.php
new file mode 100644
index 0000000..5d28cba
--- /dev/null
+++ b/includes/system/subsystem.php
@@ -0,0 +1,124 @@
+<?php global $system; global $systemCommonName; global $parts; global $systemID;
+
+$members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$systemID-members.json"), true);
+
+$subsystemID = $parts[3];
+
+$subsystems = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$systemID-subsystems.json"), true) ?? [];
+
+function getMember(string $id) {
+ global $systemID;
+ global $members;
+
+ $member = null;
+
+ foreach ($members as $m) {
+ if ($m["id"] === $id) $member = $m;
+ }
+
+ return $member;
+}
+
+function memberHasSubsystem(array $member) {
+ global $subsystems;
+ $has = false;
+
+ foreach ($subsystems as $subsystem) {
+ if ($subsystem["source_type"] === "member" && $subsystem["source"] === $member["id"]) {
+ $has = true;
+ }
+ }
+
+ return $has;
+}
+
+function memberPartOfSubsystem(array $member) {
+ global $subsystems;
+ $is = false;
+
+ foreach ($subsystems as $subsystem) {
+ if (in_array($member["id"], $subsystem["members"])) {
+ $is = true;
+ }
+ }
+
+ return $is;
+}
+
+function getMemberSubsystem(array $member) {
+ global $subsystems;
+ $subsystem = null;
+
+ foreach ($subsystems as $ss) {
+ if ($ss["source_type"] === "member" && $ss["source"] === $member["id"]) {
+ $subsystem = $ss;
+ }
+ }
+
+ return $subsystem;
+}
+
+function getSubsystemByID(string $id) {
+ global $subsystems;
+ $subsystem = null;
+
+ foreach ($subsystems as $ss) {
+ if ($ss["source"] === $id) {
+ $subsystem = $ss;
+ }
+ }
+
+ return $subsystem;
+}
+
+function timeAgo($time): string {
+ if (!is_numeric($time)) {
+ $time = strtotime($time);
+ }
+
+ $periods = ["second", "minute", "hour", "day", "week", "month", "year", "age"];
+ $lengths = array("60", "60", "24", "7", "4.35", "12", "100");
+
+ $now = time();
+
+ $difference = $now - $time;
+ if ($difference <= 10 && $difference >= 0) {
+ return $tense = "now";
+ } elseif ($difference > 0) {
+ $tense = "ago";
+ } else {
+ $tense = "later";
+ }
+
+ for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
+ $difference /= $lengths[$j];
+ }
+
+ $difference = round($difference);
+
+ $period = $periods[$j] . ($difference >1 ? "s" :'');
+ return "{$difference} {$period} {$tense} ";
+}
+
+if (getSubsystemByID($subsystemID) === null) header("Location: /?error=Invalid subsystem ID") and die();
+$subsystemData = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$systemID-subsystem-$subsystemID.json"), true);
+
+$title = $subsystemData["name"] . " ยท " . $systemCommonName; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.php';
+
+?>
+
+ <br>
+ <div class="container">
+ <?php require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/subsysbanner.php"; ?>
+ <br>
+
+ <div id="page-content">
+ <?php global $isLoggedIn; if ($isLoggedIn): ?>
+ <small style="opacity:.5;display:block;">(<a href="/edit/<?= $system ?>/<?= $subsystemID ?>">edit</a>)</small>
+ <?php endif; ?>
+ <?= file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$systemID-subsystem-$subsystemID.html") ?>
+ </div>
+ <?php showSubsystem(getSubsystemByID($subsystemID), $systemID); ?>
+ </div>
+
+<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/footer.php'; ?> \ No newline at end of file