diff options
| author | ilotterytea <iltsu@alright.party> | 2025-08-18 11:21:23 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-08-18 11:21:23 +0500 |
| commit | d3f06ef7ce62a632c3f3323f1877729b5be8aca6 (patch) | |
| tree | d40543ee2296f774d68644380f7c1070a2743d0c /lib | |
| parent | 8fed544dcac0ab717ca98cca26753d0e9470e529 (diff) | |
feat: alerts
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/alert.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/alert.php b/lib/alert.php new file mode 100644 index 0000000..c481018 --- /dev/null +++ b/lib/alert.php @@ -0,0 +1,43 @@ +<?php +include_once $_SERVER['DOCUMENT_ROOT'] . '/lib/utils.php'; + +function create_alert(string $redirect, int $code, string|null $message, mixed $data) +{ + if (IS_JSON_REQUEST) { + return json_response($code, $message, $data); + } else { + http_response_code($code); + $loc = "Location: $redirect"; + if ($message) { + $loc .= "?e=$code%20$message"; + } + header($loc); + return "$code $message"; + } +} + +function display_alert() +{ + if (!isset($_GET['e']) || empty(trim($_GET['e']))) { + return; + } + + $message = $_GET['e']; + $parts = explode(' ', $message, 2); + + $code = intval($parts[0]); + + if (count($parts) > 1) { + $reason = $parts[1]; + } + + if (isset($reason)) { + echo '<div class="alert'; + if ($code > 299) { + echo ' red'; + } + echo '">'; + echo "<p>$reason</p>"; + echo '</div>'; + } +}
\ No newline at end of file |
