summaryrefslogtreecommitdiff
path: root/pages/byfront.inc
blob: beb9275f63a455893988122decb35d32a02351e7 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages;
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc';
global $app; global $_PROFILE;

?>

<br>
<div class="container">
    <div id="page-content">
        <h2>Members by last fronted</h2>
        <select id="selected-system" class="form-select" style="margin-bottom: 20px;" onchange="refreshList()">
            <option value="gdapd" <?= $_PROFILE["login"] === "raindrops" ? "select" : "" ?>>Raindrops System</option>
            <option value="hrbom" <?= $_PROFILE["login"] === "Moonwind" ? "select" : "" ?>>Moonglow</option>
            <option value="<?= $app["other"]["id"] ?>" <?= $_PROFILE["login"] !== "raindrops" && $_PROFILE["login"] !== "cloudburst" && $_PROFILE["login"] !== "Moonwind" ? "select" : "" ?>><?= $app["other"]["name"] ?></option>
            <option value="ynmuc" <?= $_PROFILE["login"] === "cloudburst" ? "select" : "" ?>>Cloudburst System</option>
            <option value="">(all systems)</option>
        </select>

        <?php $members = [
            ...array_map(function ($i) {
                $system = "ynmuc";
                $i["_lastFronted"] = -1;
                $id = $i["id"];
                $memberData = $i;

                $fronters = array_map(function ($item) {
                    return $item["id"];
                }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["members"]);

                if (in_array($id, $fronters)) {
                    $i["_lastFronted"] = time();
                } else {
                    $switches = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json"), true);

                    $thisMember = array_filter($switches, function ($item) use ($memberData) {
                        return in_array($memberData["id"], $item["members"]);
                    });

                    $thisMember = array_values($thisMember);
                    $frontingEnd = null;

                    if (count($thisMember) > 0) {
                        $thisIndex = array_search($thisMember[0], $switches);

                        $frontingStart = $thisMember[0];
                        $frontingEnd = $switches[$thisIndex - 1];
                    }

                    if ($frontingEnd !== null && isset($frontingStart)) {
                        $i["_lastFronted"] = strtotime($frontingEnd["timestamp"]);
                    }
                }

                return $i;
            }, array_values(array_filter(scoreOrderGlobal(), function ($i) {
                return $i["_system"] === "ynmuc";
            }))),
            ...array_map(function ($i) {
                $system = "gdapd";
                $i["_lastFronted"] = -1;
                $id = $i["id"];
                $memberData = $i;

                $fronters = array_map(function ($item) {
                    return $item["id"];
                }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["members"]);

                if (in_array($id, $fronters)) {
                    $i["_lastFronted"] = time();
                } else {
                    $switches = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json"), true);

                    $thisMember = array_filter($switches, function ($item) use ($memberData) {
                        return in_array($memberData["id"], $item["members"]);
                    });

                    $thisMember = array_values($thisMember);
                    $frontingEnd = null;

                    if (count($thisMember) > 0) {
                        $thisIndex = array_search($thisMember[0], $switches);

                        $frontingStart = $thisMember[0];
                        $frontingEnd = $switches[$thisIndex - 1];
                    }

                    if ($frontingEnd !== null && isset($frontingStart)) {
                        $i["_lastFronted"] = strtotime($frontingEnd["timestamp"]);
                    }
                }

                return $i;
            }, array_values(array_filter(scoreOrderGlobal(), function ($i) {
                return $i["_system"] === "gdapd";
            }))),
            ...array_map(function ($i) {
                $system = "hrbom";
                $i["_lastFronted"] = -1;
                $id = $i["id"];
                $memberData = $i;

                $fronters = array_map(function ($item) {
                    return $item["id"];
                }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["members"]);

                if (in_array($id, $fronters)) {
                    $i["_lastFronted"] = time();
                } else {
                    $switches = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json"), true);

                    $thisMember = array_filter($switches, function ($item) use ($memberData) {
                        return in_array($memberData["id"], $item["members"]);
                    });

                    $thisMember = array_values($thisMember);
                    $frontingEnd = null;

                    if (count($thisMember) > 0) {
                        $thisIndex = array_search($thisMember[0], $switches);

                        $frontingStart = $thisMember[0];
                        $frontingEnd = $switches[$thisIndex - 1];
                    }

                    if ($frontingEnd !== null && isset($frontingStart)) {
                        $i["_lastFronted"] = strtotime($frontingEnd["timestamp"]);
                    }
                }

                return $i;
            }, array_values(array_filter(scoreOrderGlobal(), function ($i) {
                return $i["_system"] === "hrbom";
            }))),
            ...array_map(function ($i) {
                global $app;
                $system = $app["other"]["id"];
                $i["_lastFronted"] = -1;
                $id = $i["id"];
                $memberData = $i;

                $fronters = array_map(function ($item) {
                    return $item["id"];
                }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["members"]);

                if (in_array($id, $fronters)) {
                    $i["_lastFronted"] = time();
                } else {
                    $switches = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json"), true);

                    $thisMember = array_filter($switches, function ($item) use ($memberData) {
                        return in_array($memberData["id"], $item["members"]);
                    });

                    $thisMember = array_values($thisMember);
                    $frontingEnd = null;

                    if (count($thisMember) > 0) {
                        $thisIndex = array_search($thisMember[0], $switches);

                        $frontingStart = $thisMember[0];
                        $frontingEnd = $switches[$thisIndex - 1];
                    }

                    if ($frontingEnd !== null && isset($frontingStart)) {
                        $i["_lastFronted"] = strtotime($frontingEnd["timestamp"]);
                    }
                }

                return $i;
            }, array_values(array_filter(scoreOrderGlobal(), function ($i) {
                global $app;
                return $i["_system"] === $app["other"]["id"];
            })))
        ]; uasort($members, function ($a, $b) {
            return $b["_lastFronted"] - $a["_lastFronted"];
        }); $members = array_reverse($members); foreach ($members as $member):

            $metadata = $member["_metadata"];?>
            <div data-relation-system="<?= $member["_system"] ?>" class="relation" style="display: none; margin-bottom:10px;padding:10px;border-radius:10px;grid-template-columns: 1fr 2fr max-content;">
                <a class="relation-intro" style="background-color:rgba(255, 255, 255, .05);border-right:1px solid rgba(255, 255, 255, .1);margin:-10px;padding:10px;border-top-left-radius:10px;border-bottom-left-radius:10px;color: white;display:flex;align-items:center;text-decoration: none;" href="/<?= $member["name"] ?>">
                    <img src="<?= getAsset($member['system'], $member["id"], "heads") ?>" style="width:24px;">&nbsp;<?= $member["display_name"] ?? $member["name"] ?>
                </a>

                <div class="relation-item" style="display:flex;align-items:center;margin-left:10px;padding:0 20px;">
                    <?php if ($member["_lastFronted"] === -1): ?>
                    Never fronted
                    <?php else: ?>
                    Last fronted <?= timeAgo($member["_lastFronted"]) ?><?php if ($member["_lastFronted"] !== time()): ?> (<?= date('l j F Y', $member["_lastFronted"]) ?>)<?php endif; ?>
                    <?php endif; ?>
                </div>
            </div>
        <?php endforeach; ?>

    <script>
        function refreshList() {
            let system = document.getElementById("selected-system").value;

            for (let relation of document.getElementsByClassName("relation")) {
                if (relation.getAttribute("data-relation-system") === system || system === "") {
                    relation.style.display = "grid";
                } else {
                    relation.style.display = "none";
                }
            }
        }

        refreshList();
    </script>

    <style>
        @media (max-width: 991px) {
            .relation {
                grid-template-columns: 1fr !important;
            }

            .relation-intro {
                text-align: center;
                border-bottom-left-radius: 0 !important;
                border-top-right-radius: 10px;
                border-right: none !important;
                border-bottom: 1px solid rgba(255, 255, 255, .1);
            }

            .relation-item-marefriends {
                margin-top: 20px !important;
            }

            .relation-item {
                margin-top: 10px;
                margin-left: 0 !important;
                padding: 10px 0 !important;
                text-align: center;
            }
        }
    </style>
</div>

<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/footer.inc'; ?>