summaryrefslogtreecommitdiff
path: root/pages/debug.inc
blob: 1327af5dc28854571d6084c6f06b626e130263cd (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
<?php

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

function itemToName(string $item): string {
    global $lang; global $pages;

    if ($item === "docs_cleanup")     return $lang["debug"]["docs_cleanup"];
    if ($item === "important_backup") return $lang["debug"]["important_backup"];
    if ($item === "restore")          return $lang["debug"]["restore"];
    if ($item === "backups")          return $lang["debug"]["backups"];
    if ($item === "calendar")         return $lang["debug"]["calendar"];
    if ($item === "version")          return $lang["debug"]["version"];
    if ($item === "logo")             return $lang["debug"]["logo"];
    if ($item === "favicons")         return $lang["debug"]["favicons"];
    if ($item === "assets")           return $lang["debug"]["assets"];

    if (str_starts_with($item, "system-")) {
        $system = explode("-", $item)[2];
        $type = explode("-", $item)[1];
        $systemName = $system === "gdapd" ? "Raindrops System" : "Cloudburst System";

        return match ($type) {
            "general" => $lang["debug"]["general"] . " $systemName",
            "members" => $lang["debug"]["members"] . " $systemName",
            "fronters" => $lang["debug"]["fronters"] . " $systemName",
            "switches" => $lang["debug"]["switches"] . " $systemName",
            default => "$type " . $lang["debug"]["in"] . " $systemName",
        };
    }

    if (str_starts_with($item, "images-")) {
        $system = explode("-", $item)[1];
        $id = explode("-", $item)[2];
        $systemName = $system === "gdapd" ? "Raindrops" : "Cloudburst";
        $member = getSystemMember($system, $id) ?? [ "name" => $id, "display_name" => $id, "id" => $id ];

        if ($member["name"] === "unknown") {
            return str_replace("%1", $lang["debug"]["unknown"] . " (" . $systemName . ")", $lang["debug"]["images"]);
        } else {
            return str_replace("%1", getMiniName($member["display_name"] ?? $member["name"]), $lang["debug"]["images"]);
        }
    }

    return "<code>$item</code>";
}

?>

<br>
<div class="container">
    <?php $data = json_decode(file_get_contents($_SERVER["DOCUMENT_ROOT"] . "/includes/data/refresh.json"), true); ?>

    <div id="page-content">
        <h2><?= $pages["debug"]["name"][$lang["_name"]] ?></h2>
        <p><?= $lang["debug"]["description"] ?></p>

        <?php if (time() - $data["timestamp"] > 360): ?>
        <div class="alert alert-warning">
            <p>
                <b><?= $lang["debug"]["warning"]["title"] ?></b>
            </p>
            <?= $lang["debug"]["warning"]["intro"] ?>
            <ul>
                <li><?= $lang["debug"]["warning"]["list"][0] ?></li>
                <li><?= $lang["debug"]["warning"]["list"][1] ?></li>
                <li><?= $lang["debug"]["warning"]["list"][2] ?></li>
            </ul>
            <?= $lang["debug"]["warning"]["admin"] ?>
        </div>
        <?php endif; ?>

        <h4><?= $lang["debug"]["general_title"] ?></h4>
        <ul>
            <li><b><?= $lang["debug"]["time"] ?></b> <?php $dt = DateTime::createFromFormat('U.u', $data["timestamp"]); echo($dt->format("l j F Y, G:i:s.u T")); ?></li>
            <li><b><?= $lang["debug"]["duration"] ?></b> <?= round($data["duration"] * 1000) ?> ms</li>
            <li><b><?= $lang["debug"]["long"] ?></b> <?= itemToName(array_search(max(array_values($data["times"])), $data["times"])) ?? "-" ?> (<?= round(max(array_values($data["times"])) * 1000) ?> ms, <?= round((max(array_values($data["times"])) / $data["duration"]) * 100, 2) ?>%)</li>
        </ul>

        <h4 id="times"><?= $lang["debug"]["times"] ?></h4>
        <div>
            <?php foreach ($data["times"] as $item => $time): ?><span class="element tooltip-nohelp" title="<b><?= itemToName($item) ?></b><br>(<?= round($time * 1000) ?> ms)" data-bs-toggle="tooltip" data-bs-html="true" style="opacity:.75;display:inline-block;background:#<?= substr(md5($item), 0, 6) ?>;height:8px;margin:4px 0;width:<?= ($time / $data["duration"]) * 100 ?>%"></span><?php endforeach; ?>
        </div>
        <ul>
            <?php foreach ($data["times"] as $item => $time): ?>
                <li><b><?= itemToName($item) ?>:</b> <?= round($time * 1000) ?> ms</li>
            <?php endforeach; ?>
        </ul>

        <h4 id="failures"><?= $lang["debug"]["failures"] ?></h4>
        <?php if (count($data["restored"]) < 1): ?>
        <p><i><?= $lang["debug"]["no_failure"] ?></i></p>
        <?php else: ?>
        <p><?= $lang["debug"]["failure"] ?></p>
        <ul>
            <?php foreach ($data["restored"] as $item): ?>
            <li><code><?= $item ?></code></li>
            <?php endforeach; ?>
        </ul>
        <?php endif; ?>
    </div>
</div>

<style>
    .element:hover {
        margin: 0 !important;
        height: 16px !important;
        opacity: 1 !important;
    }

    .element {
        transition: margin 200ms, height 200ms, opacity 200ms;
    }
</style>

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