From cc5b1c8040855a5b3ba9241e9ca6b71233adaeb6 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Fri, 1 Aug 2025 15:51:29 -0400 Subject: [PATCH] Add new function called flash_alert() to repace the alerting in posts, updated accounts post to use new function --- functions.php | 7 +++++++ user/post/account.php | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/functions.php b/functions.php index c33cdd38..53c87c2e 100644 --- a/functions.php +++ b/functions.php @@ -1672,6 +1672,7 @@ function sanitize_url($url) { return htmlspecialchars($url ?? '', ENT_QUOTES, 'UTF-8'); } +// Redirect Function function redirect($url = null, $permanent = false) { // Use referer if no URL is provided if (!$url) { @@ -1687,4 +1688,10 @@ function redirect($url = null, $permanent = false) { echo ''; exit; } +} + +//Flash Alert Function +function flash_alert(string $message, string $type = 'success'): void { + $_SESSION['alert_type'] = $type; + $_SESSION['alert_message'] = $message; } \ No newline at end of file diff --git a/user/post/account.php b/user/post/account.php index dfdd894b..3bacab76 100644 --- a/user/post/account.php +++ b/user/post/account.php @@ -20,7 +20,7 @@ if (isset($_POST['add_account'])) { // Logging logAction("Account", "Create", "$session_name created account $name"); - $_SESSION['alert_message'] = "Account $name created "; + flash_alert("Account $name created"); redirect(); @@ -39,7 +39,7 @@ if (isset($_POST['edit_account'])) { // Logging logAction("Account", "Edit", "$session_name edited account $name"); - $_SESSION['alert_message'] = "Account $name edited"; + flash_alert("Account $name edited"); redirect(); @@ -61,7 +61,7 @@ if (isset($_GET['archive_account'])) { // Logging logAction("Account", "Archive", "$session_name archived account $account_name"); - $_SESSION['alert_message'] = "Account $account_name archived"; + flash_alert("Account $account_name archived"); redirect(); @@ -83,7 +83,7 @@ if (isset($_GET['delete_account'])) { //Logging logAction("Account", "Delete", "$session_name deleted account $account_name"); - $_SESSION['alert_message'] = "Account $account_name deleted"; + flash_alert("Account $account_name deleted", 'error'); redirect();