diff options
| author | ilotterytea <iltsu@alright.party> | 2025-12-08 22:17:05 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-12-08 22:17:05 +0500 |
| commit | 95800ffe216a83bc0eba994ecc53ed22860fe90e (patch) | |
| tree | 69f1bcb85e63a5fc0fcbc6d70eb56e22940fd6fd /lib/alert.php | |
| parent | 57472eab3c7b035392c6a5aa240593ecaa7d1ccf (diff) | |
upd: include paths
Diffstat (limited to 'lib/alert.php')
| -rw-r--r-- | lib/alert.php | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/alert.php b/lib/alert.php new file mode 100644 index 0000000..823a97a --- /dev/null +++ b/lib/alert.php @@ -0,0 +1,40 @@ +<?php +function generate_alert(string $path, string $error, int $status = 400) +{ + http_response_code($status); + + if (isset($_SERVER["HTTP_ACCEPT"]) && $_SERVER["HTTP_ACCEPT"] == "application/json") { + header("Content-Type: application/json"); + echo json_encode([ + "status_code" => $status, + "message" => $error, + "data" => null + ]); + } else { + header("Location: $path" . (str_contains($path, "?") ? "&" : "?") . "error_status=$status&error_reason=$error"); + } +} + +function display_alert() +{ + if (!isset($_GET["error_status"], $_GET["error_reason"])) { + return; + } + + $status = $_GET["error_status"]; + $reason = str_safe($_GET["error_reason"], 100); + $ok = substr($status, 0, 1) == '2'; + + echo '' ?> + <div class="box row alert <?php echo $ok ? '' : 'red' ?>" style="gap:8px;" id="alert-box"> + <img src="/static/img/icons/<?php echo $ok ? 'yes' : 'no' ?>.png" alt=""> + <p><b><?php echo $reason ?></b></p> + </div> + <script> + setTimeout(() => { + const alertBox = document.getElementById("alert-box"); + alertBox.remove(); + }, 5000); + </script> + <?php +}
\ No newline at end of file |
