summaryrefslogtreecommitdiff
path: root/includes/system/subsystem.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/system/subsystem.inc')
-rw-r--r--includes/system/subsystem.inc100
1 files changed, 100 insertions, 0 deletions
diff --git a/includes/system/subsystem.inc b/includes/system/subsystem.inc
new file mode 100644
index 0000000..b7d73f1
--- /dev/null
+++ b/includes/system/subsystem.inc
@@ -0,0 +1,100 @@
+<?php global $system; global $systemCommonName; global $parts; global $systemID;
+
+if (str_ends_with($_GET['_'], "/subsystem")) header("Location: /?error=Invalid subsystem ID") and die();
+
+$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/subsystems/$systemID.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;
+}
+
+if (getSubsystemByID($subsystemID) === null) header("Location: /?error=Invalid subsystem ID") and die();
+$subsystemData = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/subsystems/$systemID-$subsystemID.json"), true);
+
+global $subsystem;
+$subsystem = getSubsystemByID($subsystemID);
+
+$title = $subsystemData["name"] . " ยท " . $systemCommonName; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc';
+
+?>
+
+ <br>
+ <div class="container">
+ <?php require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/subsysbanner.inc"; ?>
+ <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/subsystems/$systemID-$subsystemID.html") ?>
+ </div>
+ <?php showSubsystem(getSubsystemByID($subsystemID), $systemID); ?>
+ </div>
+
+<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/footer.inc'; ?> \ No newline at end of file