From 28b0f5c3f2daed8a50bef662b8197ddba1182fa3 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 10 Jan 2009 15:34:18 -0500 Subject: [PATCH] Add a flash redirect system for admin pages to redirect and display a success message * admin/settings.php: Use new flash redirect * admin/templates/settings.html: Print flash message * docs/schema_changes.sql: Create the adminsession.flashmessage field * includes/functions_admin.php: (admin_flash_redirect): New function (admin_flash): New function to display the flash --- admin/settings.php | 2 +- admin/templates/settings.html | 2 ++ docs/schema_changes.sql | 1 + includes/functions_admin.php | 47 +++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/admin/settings.php b/admin/settings.php index 2421406..10be697 100755 --- a/admin/settings.php +++ b/admin/settings.php @@ -65,7 +65,7 @@ if ($_POST['do'] == 'update') build_settings(); - $admin->redirect('settings.php'); + admin_flash_redirect('settings.php', 'All the settings have been updated successfully.'); } // ################################################################### diff --git a/admin/templates/settings.html b/admin/templates/settings.html index 48fd2f8..e01f926 100644 --- a/admin/templates/settings.html +++ b/admin/templates/settings.html @@ -13,6 +13,8 @@
+<%- admin_flash() %> +
diff --git a/docs/schema_changes.sql b/docs/schema_changes.sql index 9de1d44..3682f94 100644 --- a/docs/schema_changes.sql +++ b/docs/schema_changes.sql @@ -1,2 +1,3 @@ ## SVN $Id$ +ALTER TABLE /*PREFIX*/adminsession ADD flashmessage varchar(255) DEFAULT NULL; diff --git a/includes/functions_admin.php b/includes/functions_admin.php index 6778235..48ea1e0 100644 --- a/includes/functions_admin.php +++ b/includes/functions_admin.php @@ -100,4 +100,51 @@ function AdminPageNavigatorCallback($baselink, $nextpage, $prevpage, $show, $pag return '
' . $return . '
'; } +/** + * Redirects the user to a given page and stores the flash message for later display + * + * @param string URL to redireect to + * @param string Flash message + * @param bool Whether or not this is an error + */ +function admin_flash_redirect($url, $message = '', $error = false) +{ + $sessionID = BSApp::$input->inputEscape(COOKIE_PREFIX . 'adminsession'); + if (!$sessionID) + { + return; + } + + if ($message) + { + $msg = '
' . $message . '
'; + BSApp::$db->query("UPDATE " . TABLE_PREFIX . "adminsession SET flashmessage = '" . BSApp::$db->escapeString($msg) . "' WHERE sessionid = '$sessionID'"); + } + + header("Location: $url"); +} + +/** + * Returns the admin flash message and then proceeds o clear it + * + * @return string + */ +function admin_flash() +{ + $sessionID = BSApp::$input->inputEscape(COOKIE_PREFIX . 'adminsession'); + if (!$sessionID) + { + return; + } + + $msg = BSApp::$db->queryFirst("SELECT flashmessage FROM " . TABLE_PREFIX . "adminsession WHERE sessionid = '$sessionID'"); + if (!$msg['flashmessage']) + { + return; + } + + BSApp::$db->query("UPDATE " . TABLE_PREFIX . "adminsession SET flashmessage = '' WHERE sessionid = '$sessionID'"); + return $msg['flashmessage']; +} + ?> \ No newline at end of file -- 2.22.5