summaryrefslogtreecommitdiff
path: root/includes/system/subsystem.inc
blob: b7d73f134c117808875462ab9f481d8165ac0db3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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'; ?>