diff options
| author | ilotterytea <iltsu@alright.party> | 2025-04-20 17:47:30 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-04-20 18:02:05 +0500 |
| commit | 99e2edb45abd9987c6526ba9be3ac301e03af713 (patch) | |
| tree | 911e0abdfd9b8969e6d6e932d73c45213a89f049 | |
| parent | 4add65a71cbf5993ddc298511f46e701d2de091f (diff) | |
feat: alerts
| -rw-r--r-- | public/static/img/icons/no.png | bin | 0 -> 587 bytes | |||
| -rw-r--r-- | public/static/img/icons/yes.png | bin | 0 -> 781 bytes | |||
| -rw-r--r-- | public/static/style.css | 6 | ||||
| -rw-r--r-- | src/alert.php | 33 |
4 files changed, 39 insertions, 0 deletions
diff --git a/public/static/img/icons/no.png b/public/static/img/icons/no.png Binary files differnew file mode 100644 index 0000000..c149c2b --- /dev/null +++ b/public/static/img/icons/no.png diff --git a/public/static/img/icons/yes.png b/public/static/img/icons/yes.png Binary files differnew file mode 100644 index 0000000..89c8129 --- /dev/null +++ b/public/static/img/icons/yes.png diff --git a/public/static/style.css b/public/static/style.css index 1687616..933e46e 100644 --- a/public/static/style.css +++ b/public/static/style.css @@ -237,6 +237,7 @@ button.purple:hover, } .row { + display: flex; flex-direction: row; align-items: center; } @@ -324,6 +325,11 @@ a.box:hover { margin: 32px 0; } +.alert.red { + background: #e27777; + border-color: #9f5050; +} + /** ------------- ACCOUNTS diff --git a/src/alert.php b/src/alert.php new file mode 100644 index 0000000..eb67f77 --- /dev/null +++ b/src/alert.php @@ -0,0 +1,33 @@ +<?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") { + echo json_encode([ + "status_code" => $status, + "message" => $error, + "data" => null + ]); + } else { + header("Location: $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"], 50); + $ok = substr($status, 0, 1) == '2'; + + echo '' ?> + <div class="box row alert <?php echo $ok ? '' : 'red' ?>" style="gap:8px;"> + <img src="/static/img/icons/<?php echo $ok ? 'yes' : 'no' ?>.png" alt=""> + <p><b><?php echo $reason ?></b></p> + </div> + <?php +}
\ No newline at end of file |
