Add a flash redirect system for admin pages to redirect and display a success message
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
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 @@
<div id="body">
+<%- admin_flash() %>
+
<form action="settings.php" method="post">
<input type="hidden" name="do" value="update" />
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 '<div style="margin-top: 15px; float: ' . $stylevar['right'] . '">' . $return . '</div>';
}
+/**
+ * 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 = '<div class="' . ($error ? 'error' : 'message') . '-box">' . $message . '</div>';
+ 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