Add a flash redirect system for admin pages to redirect and display a success message
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 10 Jan 2009 20:34:18 +0000 (15:34 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 10 Jan 2009 20:34:18 +0000 (15:34 -0500)
* 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
admin/templates/settings.html
docs/schema_changes.sql
includes/functions_admin.php

index 2421406816352f501dec2f3071e2d5ac1b907b4c..10be6973dfb8bc4e2565ad5223efb1e82bdb2247 100755 (executable)
@@ -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.');
 }
 
 // ###################################################################
index 48fd2f852ef139a1ee0e066b17d9cc45b0c8dc72..e01f9262f0c58bf5097d43db725081af8a4292a0 100644 (file)
@@ -13,6 +13,8 @@
 
 <div id="body">
 
+<%- admin_flash() %>
+
 <form action="settings.php" method="post">
 <input type="hidden" name="do" value="update" />
 
index 9de1d44968b68dc784bdae5bbcdbaebd5dbff705..3682f942e22bf732162d1c86f227ef44d92dc372 100644 (file)
@@ -1,2 +1,3 @@
 ## SVN $Id$
 
+ALTER TABLE /*PREFIX*/adminsession ADD flashmessage varchar(255) DEFAULT NULL;
index 6778235ed0e1859fda965435012292b311b70957..48ea1e007506079596f00b5c39210561b955f038 100644 (file)
@@ -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