From ccfda8966dc09337e642b246341f25ea7fe3d9ef Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Tue, 01 Nov 2005 16:52:01 -0500
Subject: [PATCH] Fixed session expiration issue with SQLite

---
 index.php                      |    4 +-
 program/include/rcube_db.inc   |   12 ++---
 program/include/rcube_mdb2.inc |   47 ++++++++++++++++++++---
 3 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/index.php b/index.php
index 7dbfd80..dcb6566 100644
--- a/index.php
+++ b/index.php
@@ -98,7 +98,7 @@
 if ($_framed)
   {
   $COMM_PATH .= '&_framed=1';
-  $SESS_HIDDEN_FIELD = "\n".'<input type="hidden" name="_framed" value="1" />';
+  $SESS_HIDDEN_FIELD .= "\n".'<input type="hidden" name="_framed" value="1" />';
   }
 
 
@@ -146,7 +146,7 @@
 else if ($_action!='login' && $sess_auth && $_SESSION['user_id'])
   {
   if ($_auth !== $sess_auth || $_auth != rcmail_auth_hash($_SESSION['client_id'], $_SESSION['auth_time']) ||
-      ($CONFIG['session_lifetime'] && $SESS_CHANGED + $CONFIG['session_lifetime']*60 < mktime()))
+      ($CONFIG['session_lifetime'] && isset($SESS_CHANGED) && $SESS_CHANGED + $CONFIG['session_lifetime']*60 < mktime()))
     {
     $message = show_message('sessionerror', 'error');
     rcmail_kill_session();
diff --git a/program/include/rcube_db.inc b/program/include/rcube_db.inc
index a987d2e..684ed49 100755
--- a/program/include/rcube_db.inc
+++ b/program/include/rcube_db.inc
@@ -139,7 +139,7 @@
 			$result = $this->db_handle->limitQuery($query,$offset,$numrows,$params);
 			}
         else    
-			$result = $this->db_handle->query($query,$params);
+			$result = $this->db_handle->query($query, $params);
 
         if (DB::isError($result))
 			{
@@ -147,7 +147,7 @@
                               'type' => 'db',
                               'line' => __LINE__, 
                               'file' => __FILE__, 
-                              'message' => $result->getMessage()), TRUE, FALSE);
+                              'message' => $result->getMessage().'; QUERY: '.$query), TRUE, FALSE);
              return false;
             }
 
@@ -292,11 +292,9 @@
     {
         if (!is_string($query))
             return ($query);
-
-        $search = array('/NOW\(\)/',
-                        '/`/');
-        $replace = array("datetime('now')",
-                         '"');
+            
+        $search = array('/NOW\(\)/i', '/`/');
+        $replace = array("datetime('now')", '"');
         $query = preg_replace($search, $replace, $query);
 
         return ($query);
diff --git a/program/include/rcube_mdb2.inc b/program/include/rcube_mdb2.inc
index 4637bed..f87a9c0 100755
--- a/program/include/rcube_mdb2.inc
+++ b/program/include/rcube_mdb2.inc
@@ -104,21 +104,37 @@
     // Query database
     
     function query()
+
     {
+
 		$params = func_get_args();
+
 		$query = array_shift($params);
+
 		
+
 		return $this->_query($query, 0, 0, $params);
+
     }
+
    
+
 	function limitquery()
+
     {
+
 		$params = func_get_args();
+
 		$query = array_shift($params);
+
 		$offset = array_shift($params);
+
 		$numrows = array_shift($params);
+
 		
+
 		return $this->_query($query, $offset, $numrows, $params);
+
     }
     
     function _query($query, $offset, $numrows, $params)
@@ -133,12 +149,15 @@
 
         if ($this->db_provider == 'sqlite')
             $query = $this->_sqlite_prepare_query($query);
-            
+
         $this->db_handle->row_offset = $offset;
 		$this->db_handle->row_limit = $numrows;
-		
+
         $result = $this->db_handle->query($query,$params);
-        
+        //$q = $this->db_handle->prepare($query);
+        //$q->bindParamArray($params);
+        //$result = $q->execute();
+
         if (PEAR::isError($result))
             raise_error(array('code' => 500,
                               'type' => 'db',
@@ -194,23 +213,39 @@
     }
 
 	function quoteIdentifier ( $str )
+
 	{
+
 		if (!$this->db_handle)
+
 			$this->db_connect('r');
+
 			
+
 		return $this->db_handle->quoteIdentifier($str);
+
 	}
 	
 	function unixtimestamp($field)
+
 	{
+
 		switch($this->db_provider)
+
 			{
+
 			case 'pgsql':
+
 				return "EXTRACT (EPOCH FROM $field)";
+
 				break;
+
 			default:
+
 				return "UNIX_TIMESTAMP($field)";
+
 			}
+
 	}
 	
     function _add_result($res, $query)
@@ -266,10 +301,8 @@
         if (!is_string($query))
             return ($query);
 
-        $search = array('/NOW\(\)/',
-                        '/`/');
-        $replace = array("datetime('now')",
-                         '"');
+        $search = array('/NOW\(\)/i', '/`/');
+        $replace = array("datetime('now')", '"');
         $query = preg_replace($search, $replace, $query);
 
         return ($query);

--
Gitblit v1.9.1