summaryrefslogtreecommitdiff
path: root/lib/alert.php
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-06-08 02:15:49 +0400
committerilotterytea <iltsu@alright.party>2025-06-08 02:15:49 +0400
commit738bc1f237923806902fa2755b85566a4a845717 (patch)
tree6d0762995522e42bdc6103ade1bc1f9ee07860e9 /lib/alert.php
parent9a58eaae53bdd2a4fcdd66b1eb852c7db7970de9 (diff)
feat: display alert
Diffstat (limited to 'lib/alert.php')
-rw-r--r--lib/alert.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/alert.php b/lib/alert.php
new file mode 100644
index 0000000..76ca523
--- /dev/null
+++ b/lib/alert.php
@@ -0,0 +1,30 @@
+<?php
+include_once $_SERVER['DOCUMENT_ROOT'] . '/../lib/utils.php';
+
+function generate_alert(string $redirect, string|null $message, int $code = 200, mixed $data = null)
+{
+ if (IS_JSON_REQUEST) {
+ json_response($data, $message, $code);
+ } else if (isset($message)) {
+ header("Location: $redirect" . (str_contains($redirect, "?") ? "&" : "?") . "es=$code&er=" . urlencode($message));
+ } else {
+ header("Location: $redirect");
+ }
+}
+
+function display_alert()
+{
+ if (!isset($_GET["es"], $_GET["er"])) {
+ return;
+ }
+
+ $status = $_GET["es"];
+ $reason = urldecode($_GET['er']);
+ $ok = substr($status, 0, 1) == '2';
+
+ echo '' ?>
+ <section class="box alert<?= !$ok ? ' red' : '' ?>">
+ <p><?= $reason ?></p>
+ </section>
+ <?php ;
+} \ No newline at end of file