diff options
author | Minteck <contact@minteck.org> | 2022-10-10 20:51:39 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-10-10 20:51:39 +0200 |
commit | 108525534c28013cfe1897c30e4565f9893f3766 (patch) | |
tree | dd3e5132971f96ab5f05e7f3f8f6dbbf379a19bd /includes/system/subsystem.inc | |
parent | 2162eaa06f7e4764eb3dcfe130ec2c711d0c62ab (diff) | |
download | pluralconnect-108525534c28013cfe1897c30e4565f9893f3766.tar.gz pluralconnect-108525534c28013cfe1897c30e4565f9893f3766.tar.bz2 pluralconnect-108525534c28013cfe1897c30e4565f9893f3766.zip |
Update
Diffstat (limited to 'includes/system/subsystem.inc')
-rw-r--r-- | includes/system/subsystem.inc | 100 |
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 |