Index: trunk/include/calendar_monthly.class.php
===================================================================
--- trunk/include/calendar_monthly.class.php	(revision 1062)
+++ trunk/include/calendar_monthly.class.php	(revision 1063)
@@ -453,4 +453,5 @@
         $ratio_h = $tn_height/$cell_height;
 
+
         $pos_top=$pos_left=0;
         $img_width=$img_height='';
@@ -462,5 +463,5 @@
             $img_height = 'height="'.$cell_height.'"';
             $browser_img_width = $cell_height*$tn_width/$tn_height;
-            $pos_left = ($tn_width-$browser_img_width)/2;
+            $pos_left = ($browser_img_width-$cell_width)/2;
           }
           else
@@ -468,5 +469,5 @@
             $img_width = 'width="'.$cell_width.'"';
             $browser_img_height = $cell_width*$tn_height/$tn_width;
-            $pos_top = ($tn_height-$browser_img_height)/2;
+            $pos_top = ($browser_img_height-$cell_height)/2;
           }
         }
Index: trunk/include/functions_session.inc.php
===================================================================
--- trunk/include/functions_session.inc.php	(revision 1062)
+++ trunk/include/functions_session.inc.php	(revision 1063)
@@ -55,9 +55,9 @@
 }
 
-if (isset($conf['session_save_handler']) 
+if (isset($conf['session_save_handler'])
   and ($conf['session_save_handler'] == 'db')
-  and defined('PHPWG_INSTALLED')) 
+  and defined('PHPWG_INSTALLED'))
 {
-  session_set_save_handler('pwg_session_open', 
+  session_set_save_handler('pwg_session_open',
     'pwg_session_close',
     'pwg_session_read',
@@ -80,5 +80,5 @@
 {
   if ( isset($_SERVER['REDIRECT_URL']) )
-  { // mod_rewrite is activated for upper level directories. we must set the 
+  { // mod_rewrite is activated for upper level directories. we must set the
     // cookie to the path shown in the browser otherwise it will be discarded.
     $scr = $_SERVER['REDIRECT_URL'];
@@ -96,5 +96,5 @@
  * @params not use but useful for php engine
  */
-function pwg_session_open($path, $name) 
+function pwg_session_open($path, $name)
 {
   return true;
@@ -105,5 +105,5 @@
  *
  */
-function pwg_session_close() 
+function pwg_session_close()
 {
   return true;
@@ -112,23 +112,23 @@
 /**
  * this function returns
- * a string corresponding to the value of the variable save in the session 
+ * a string corresponding to the value of the variable save in the session
  * or an empty string when the variable doesn't exist
- * 
+ *
  * @param string session id
  */
-function pwg_session_read($session_id) 
+function pwg_session_read($session_id)
 {
   $query = '
-SELECT data 
+SELECT data
   FROM '.SESSIONS_TABLE.'
   WHERE id = \''.$session_id.'\'
 ;';
   $result = pwg_query($query);
-  if ($result) 
+  if ($result)
   {
     $row = mysql_fetch_assoc($result);
     return $row['data'];
-  } 
-  else 
+  }
+  else
   {
     return '';
@@ -137,35 +137,26 @@
 
 /**
- * returns true; writes set a variable in the active session 
- * 
+ * returns true; writes set a variable in the active session
+ *
  * @param string session id
  * @data string value of date to be saved
  */
-function pwg_session_write($session_id, $data) 
+function pwg_session_write($session_id, $data)
 {
   $query = '
-SELECT id 
-  FROM '.SESSIONS_TABLE.'
-  WHERE id = \''.$session_id.'\'
-;';
-  $result = pwg_query($query);
-  if (mysql_num_rows($result)) 
-  {
-    $query = '
-UPDATE '.SESSIONS_TABLE.' 
+UPDATE '.SESSIONS_TABLE.'
   SET expiration = now(),
   data = \''.$data.'\'
   WHERE id = \''.$session_id.'\'
-;';    
-    pwg_query($query);
-  } 
-  else 
+;';
+  pwg_query($query);
+  if ( mysql_affected_rows()==0 )
   {
     $query = '
-INSERT INTO '.SESSIONS_TABLE.' 
+INSERT INTO '.SESSIONS_TABLE.'
   (id,data,expiration)
   VALUES(\''.$session_id.'\',\''.$data.'\',now())
 ;';
-    pwg_query($query);    
+    pwg_query($query);
   }
   return true;
@@ -173,12 +164,12 @@
 
 /**
- * returns true; delete the active session 
- * 
+ * returns true; delete the active session
+ *
  * @param string session id
  */
-function pwg_session_destroy($session_id) 
+function pwg_session_destroy($session_id)
 {
   $query = '
-DELETE 
+DELETE
   FROM '.SESSIONS_TABLE.'
   WHERE id = \''.$session_id.'\'
@@ -192,10 +183,10 @@
  * called each time a session is closed.
  */
-function pwg_session_gc() 
+function pwg_session_gc()
 {
   global $conf;
 
   $query = '
-DELETE 
+DELETE
   FROM '.SESSIONS_TABLE.'
   WHERE UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(expiration) > '
