Changeset 1063


Ignore:
Timestamp:
Mar 3, 2006, 5:32:21 AM (18 years ago)
Author:
rvelices
Message:

optimization: in sessions write 1 less sql query (except during login)

bug: corrected algorithm for pretty calendar month view

Location:
trunk/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/calendar_monthly.class.php

    r1062 r1063  
    453453        $ratio_h = $tn_height/$cell_height;
    454454
     455
    455456        $pos_top=$pos_left=0;
    456457        $img_width=$img_height='';
     
    462463            $img_height = 'height="'.$cell_height.'"';
    463464            $browser_img_width = $cell_height*$tn_width/$tn_height;
    464             $pos_left = ($tn_width-$browser_img_width)/2;
     465            $pos_left = ($browser_img_width-$cell_width)/2;
    465466          }
    466467          else
     
    468469            $img_width = 'width="'.$cell_width.'"';
    469470            $browser_img_height = $cell_width*$tn_height/$tn_width;
    470             $pos_top = ($tn_height-$browser_img_height)/2;
     471            $pos_top = ($browser_img_height-$cell_height)/2;
    471472          }
    472473        }
  • trunk/include/functions_session.inc.php

    r1034 r1063  
    5555}
    5656
    57 if (isset($conf['session_save_handler']) 
     57if (isset($conf['session_save_handler'])
    5858  and ($conf['session_save_handler'] == 'db')
    59   and defined('PHPWG_INSTALLED')) 
     59  and defined('PHPWG_INSTALLED'))
    6060{
    61   session_set_save_handler('pwg_session_open', 
     61  session_set_save_handler('pwg_session_open',
    6262    'pwg_session_close',
    6363    'pwg_session_read',
     
    8080{
    8181  if ( isset($_SERVER['REDIRECT_URL']) )
    82   { // mod_rewrite is activated for upper level directories. we must set the 
     82  { // mod_rewrite is activated for upper level directories. we must set the
    8383    // cookie to the path shown in the browser otherwise it will be discarded.
    8484    $scr = $_SERVER['REDIRECT_URL'];
     
    9696 * @params not use but useful for php engine
    9797 */
    98 function pwg_session_open($path, $name) 
     98function pwg_session_open($path, $name)
    9999{
    100100  return true;
     
    105105 *
    106106 */
    107 function pwg_session_close() 
     107function pwg_session_close()
    108108{
    109109  return true;
     
    112112/**
    113113 * this function returns
    114  * a string corresponding to the value of the variable save in the session 
     114 * a string corresponding to the value of the variable save in the session
    115115 * or an empty string when the variable doesn't exist
    116  * 
     116 *
    117117 * @param string session id
    118118 */
    119 function pwg_session_read($session_id) 
     119function pwg_session_read($session_id)
    120120{
    121121  $query = '
    122 SELECT data 
     122SELECT data
    123123  FROM '.SESSIONS_TABLE.'
    124124  WHERE id = \''.$session_id.'\'
    125125;';
    126126  $result = pwg_query($query);
    127   if ($result) 
     127  if ($result)
    128128  {
    129129    $row = mysql_fetch_assoc($result);
    130130    return $row['data'];
    131   } 
    132   else 
     131  }
     132  else
    133133  {
    134134    return '';
     
    137137
    138138/**
    139  * returns true; writes set a variable in the active session 
    140  * 
     139 * returns true; writes set a variable in the active session
     140 *
    141141 * @param string session id
    142142 * @data string value of date to be saved
    143143 */
    144 function pwg_session_write($session_id, $data) 
     144function pwg_session_write($session_id, $data)
    145145{
    146146  $query = '
    147 SELECT id
    148   FROM '.SESSIONS_TABLE.'
    149   WHERE id = \''.$session_id.'\'
    150 ;';
    151   $result = pwg_query($query);
    152   if (mysql_num_rows($result))
    153   {
    154     $query = '
    155 UPDATE '.SESSIONS_TABLE.'
     147UPDATE '.SESSIONS_TABLE.'
    156148  SET expiration = now(),
    157149  data = \''.$data.'\'
    158150  WHERE id = \''.$session_id.'\'
    159 ;';   
    160     pwg_query($query);
    161   }
    162   else
     151;';
     152  pwg_query($query);
     153  if ( mysql_affected_rows()==0 )
    163154  {
    164155    $query = '
    165 INSERT INTO '.SESSIONS_TABLE.' 
     156INSERT INTO '.SESSIONS_TABLE.'
    166157  (id,data,expiration)
    167158  VALUES(\''.$session_id.'\',\''.$data.'\',now())
    168159;';
    169     pwg_query($query);   
     160    pwg_query($query);
    170161  }
    171162  return true;
     
    173164
    174165/**
    175  * returns true; delete the active session 
    176  * 
     166 * returns true; delete the active session
     167 *
    177168 * @param string session id
    178169 */
    179 function pwg_session_destroy($session_id) 
     170function pwg_session_destroy($session_id)
    180171{
    181172  $query = '
    182 DELETE 
     173DELETE
    183174  FROM '.SESSIONS_TABLE.'
    184175  WHERE id = \''.$session_id.'\'
     
    192183 * called each time a session is closed.
    193184 */
    194 function pwg_session_gc() 
     185function pwg_session_gc()
    195186{
    196187  global $conf;
    197188
    198189  $query = '
    199 DELETE 
     190DELETE
    200191  FROM '.SESSIONS_TABLE.'
    201192  WHERE UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(expiration) > '
Note: See TracChangeset for help on using the changeset viewer.