From 86f1721926af3b2b4ab0b82f9a0904ad3d2c0733 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Thu, 13 Apr 2006 14:23:48 -0400
Subject: [PATCH] Added sort order saving patch by Jacob Brunson

---
 program/include/main.inc              |   40 ++++++++++++++++++--
 config/main.inc.php.dist              |   12 +++---
 program/steps/settings/save_prefs.inc |   16 -------
 3 files changed, 43 insertions(+), 25 deletions(-)

diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index af27851..8a60bc6 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -128,12 +128,6 @@
 // display these folders separately in the mailbox list
 $rcmail_config['default_imap_folders'] = array('INBOX', 'Drafts', 'Sent', 'Junk', 'Trash');
 
-// default sort col
-$rcmail_config['message_sort_col'] = 'date';
-
-// default sort order
-$rcmail_config['message_sort_order'] = 'DESC';
-
 // Set TRUE if deleted messages should not be displayed
 // This will make the application run slower
 $rcmail_config['skip_deleted'] = FALSE;
@@ -180,6 +174,12 @@
 // show pretty dates as standard
 $rcmail_config['prettydate'] = TRUE;
 
+// default sort col
+$rcmail_config['message_sort_col'] = 'date';
+
+// default sort order
+$rcmail_config['message_sort_order'] = 'DESC';
+
 
 /***** try to load host-specific configuration *****/
 
diff --git a/program/include/main.inc b/program/include/main.inc
index a3a3913..c0dd71e 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -219,10 +219,19 @@
 // destroy session data and remove cookie
 function rcmail_kill_session()
   {
-/* $sess_name = session_name();
-  if (isset($_COOKIE[$sess_name]))
-   setcookie($sess_name, '', time()-42000, '/');
-*/
+  // save user preferences
+  $a_user_prefs = $_SESSION['user_prefs'];
+  if (!is_array($a_user_prefs))
+    $a_user_prefs = array();
+    
+  if ((isset($_SESSION['sort_col']) && $_SESSION['sort_col']!=$a_user_prefs['message_sort_col']) ||
+      (isset($_SESSION['sort_order']) && $_SESSION['sort_order']!=$a_user_prefs['message_sort_order']))
+    {
+    $a_user_prefs['message_sort_col'] = $_SESSION['sort_col'];
+    $a_user_prefs['message_sort_order'] = $_SESSION['sort_order'];
+    rcmail_save_user_prefs($a_user_prefs);
+    }
+
   $_SESSION = array();
   session_destroy();
   }
@@ -617,6 +626,29 @@
   } 
 
 
+function rcmail_save_user_prefs($a_user_prefs)
+  {
+  global $DB, $CONFIG, $sess_user_lang;
+  
+  $DB->query("UPDATE ".get_table_name('users')."
+              SET    preferences=?,
+                     language=?
+              WHERE  user_id=?",
+              serialize($a_user_prefs),
+              $sess_user_lang,
+              $_SESSION['user_id']);
+
+  if ($DB->affected_rows())
+    {
+    $_SESSION['user_prefs'] = $a_user_prefs;  
+    $CONFIG = array_merge($CONFIG, $a_user_prefs);
+    return TRUE;
+    }
+    
+  return FALSE;
+  }
+
+
 // overwrite action variable  
 function rcmail_overwrite_action($action)
   {
diff --git a/program/steps/settings/save_prefs.inc b/program/steps/settings/save_prefs.inc
index 81ffbe8..98912da 100644
--- a/program/steps/settings/save_prefs.inc
+++ b/program/steps/settings/save_prefs.inc
@@ -38,22 +38,8 @@
   rcmail_set_locale($sess_user_lang);
   }
 
-
-$DB->query("UPDATE ".get_table_name('users')."
-            SET    preferences=?,
-                   language=?
-            WHERE  user_id=?",
-            serialize($a_user_prefs),
-            $sess_user_lang,
-            $_SESSION['user_id']);
-
-if ($DB->affected_rows())
-  {
+if (rcmail_save_user_prefs($a_user_prefs))
   show_message('successfullysaved', 'confirmation');
-  
-  $_SESSION['user_prefs'] = $a_user_prefs;  
-  $CONFIG = array_merge($CONFIG, $a_user_prefs);
-  }
 
 
 // go to next step

--
Gitblit v1.9.1