mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-26 09:53:20 +01:00
fixed timezone handling in addressbook:
- db stores now server-time as everywhere in eGW - contacts-class in the api and bocontacts in addressbook take and deliver user-time - xmlrpc gives user-time as the other apps too
This commit is contained in:
parent
c383d17d3a
commit
15c845e0de
@ -34,11 +34,30 @@ class bocontacts extends socontacts
|
|||||||
*/
|
*/
|
||||||
var $user;
|
var $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int $tz_offset_s offset in secconds between user and server-time,
|
||||||
|
* it need to be add to a server-time to get the user-time or substracted from a user-time to get the server-time
|
||||||
|
*/
|
||||||
|
var $tz_offset_s;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int $now_su actual user (!) time
|
||||||
|
*/
|
||||||
|
var $now_su;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array $timestamps timestamps
|
||||||
|
*/
|
||||||
|
var $timestamps = array('last_mod');
|
||||||
|
|
||||||
function bocontacts($contact_app='addressbook')
|
function bocontacts($contact_app='addressbook')
|
||||||
{
|
{
|
||||||
$this->socontacts($contact_app);
|
$this->socontacts($contact_app);
|
||||||
$this->grants = $GLOBALS['egw']->acl->get_grants($contact_app);
|
$this->grants = $GLOBALS['egw']->acl->get_grants($contact_app);
|
||||||
$this->user = $GLOBALS['egw_info']['user']['account_id'];
|
$this->user = $GLOBALS['egw_info']['user']['account_id'];
|
||||||
|
$this->tz_offset_s = 3600 * $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset'];
|
||||||
|
$this->now_su = time() + $this->tz_offset_s;
|
||||||
|
|
||||||
/* foreach(array(
|
/* foreach(array(
|
||||||
'so' => $appname. 'soadb',
|
'so' => $appname. 'soadb',
|
||||||
) as $my => $app_class)
|
) as $my => $app_class)
|
||||||
@ -54,6 +73,48 @@ class bocontacts extends socontacts
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* changes the data from the db-format to your work-format
|
||||||
|
*
|
||||||
|
* it gets called everytime when data is read from the db
|
||||||
|
* This function needs to be reimplemented in the derived class
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
*/
|
||||||
|
function db2data($data)
|
||||||
|
{
|
||||||
|
// convert timestamps from server-time in the db to user-time
|
||||||
|
foreach($this->timestamps as $name)
|
||||||
|
{
|
||||||
|
if(isset($data[$name]))
|
||||||
|
{
|
||||||
|
$data[$name] += $this->tz_offset_s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* changes the data from your work-format to the db-format
|
||||||
|
*
|
||||||
|
* It gets called everytime when data gets writen into db or on keys for db-searches
|
||||||
|
* this needs to be reimplemented in the derived class
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
*/
|
||||||
|
function data2db($data)
|
||||||
|
{
|
||||||
|
// convert timestamps from user-time to server-time in the db
|
||||||
|
foreach($this->timestamps as $name)
|
||||||
|
{
|
||||||
|
if(isset($data[$name]))
|
||||||
|
{
|
||||||
|
$data[$name] -= $this->tz_offset_s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deletes contact in db
|
* deletes contact in db
|
||||||
*
|
*
|
||||||
@ -133,7 +194,7 @@ class bocontacts extends socontacts
|
|||||||
// convert categories
|
// convert categories
|
||||||
$contact['cat_id'] = $contact['cat_id'] ? implode(',',$contact['cat_id']) : '';
|
$contact['cat_id'] = $contact['cat_id'] ? implode(',',$contact['cat_id']) : '';
|
||||||
// last modified
|
// last modified
|
||||||
$contact['last_mod'] = time();
|
$contact['last_mod'] = $this->now_su;
|
||||||
// only owner can set access status
|
// only owner can set access status
|
||||||
$contact['access'] = $contact['owner'] == $this->user ? ($contact['private'] ? 'private': 'public') : $contact['access'];
|
$contact['access'] = $contact['owner'] == $this->user ? ($contact['private'] ? 'private': 'public') : $contact['access'];
|
||||||
// create fullname
|
// create fullname
|
||||||
|
@ -76,6 +76,36 @@ class socontacts
|
|||||||
if (!$this->customfields) $this->customfields = array();
|
if (!$this->customfields) $this->customfields = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* changes the data from the db-format to your work-format
|
||||||
|
*
|
||||||
|
* it gets called everytime when data is read from the db
|
||||||
|
* This function needs to be reimplemented in the derived class
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
*/
|
||||||
|
function db2data($data)
|
||||||
|
{
|
||||||
|
// do the necessare changes here
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* changes the data from your work-format to the db-format
|
||||||
|
*
|
||||||
|
* It gets called everytime when data gets writen into db or on keys for db-searches
|
||||||
|
* this needs to be reimplemented in the derived class
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
*/
|
||||||
|
function data2db($data)
|
||||||
|
{
|
||||||
|
// do the necessary changes here
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deletes contact entry including custom fields
|
* deletes contact entry including custom fields
|
||||||
*
|
*
|
||||||
@ -102,7 +132,7 @@ class socontacts
|
|||||||
function save(&$contact)
|
function save(&$contact)
|
||||||
{
|
{
|
||||||
// save mainfields
|
// save mainfields
|
||||||
$this->somain->data = $contact;
|
$this->somain->data = $this->data2db($contact);
|
||||||
$error_nr = $this->somain->save();
|
$error_nr = $this->somain->save();
|
||||||
$contact['id'] = $this->somain->data['id'];
|
$contact['id'] = $this->somain->data['id'];
|
||||||
if($error_nr) return $error_nr_main;
|
if($error_nr) return $error_nr_main;
|
||||||
@ -133,7 +163,10 @@ class socontacts
|
|||||||
function read($contact_id)
|
function read($contact_id)
|
||||||
{
|
{
|
||||||
// read main data
|
// read main data
|
||||||
$contact = $this->somain->read($contact_id);
|
if (!($contact = $this->somain->read($contact_id)))
|
||||||
|
{
|
||||||
|
return $contact;
|
||||||
|
}
|
||||||
|
|
||||||
// read customfilds
|
// read customfilds
|
||||||
$keys = array(
|
$keys = array(
|
||||||
@ -145,7 +178,7 @@ class socontacts
|
|||||||
{
|
{
|
||||||
$contact['#'.$field[$this->extra_key]] = $field[$this->extra_value];
|
$contact['#'.$field[$this->extra_key]] = $field[$this->extra_value];
|
||||||
}
|
}
|
||||||
return $contact;
|
return $this->db2data($contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -334,6 +367,10 @@ class socontacts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
foreach($result as $num => $contact)
|
||||||
|
{
|
||||||
|
$result[$num] = $this->db2data($contact);
|
||||||
|
}
|
||||||
return $need_full_no_count ? count($result) : $result;
|
return $need_full_no_count ? count($result) : $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,9 @@
|
|||||||
* Syntax: CreateObject('phpgwapi.contacts');
|
* Syntax: CreateObject('phpgwapi.contacts');
|
||||||
* Example1: $contacts = CreateObject('phpgwapi.contacts');
|
* Example1: $contacts = CreateObject('phpgwapi.contacts');
|
||||||
*
|
*
|
||||||
|
* The contacts class now uses user-time in all param- and return-values.
|
||||||
|
* The time stored in the DB is in server-time, as in all other eGW apps.
|
||||||
|
*
|
||||||
* Last Editor: $Author$
|
* Last Editor: $Author$
|
||||||
* @class contacts_
|
* @class contacts_
|
||||||
* @abstract Contact Management System
|
* @abstract Contact Management System
|
||||||
@ -47,6 +50,12 @@
|
|||||||
var $std_table='egw_addressbook';
|
var $std_table='egw_addressbook';
|
||||||
var $ext_table='egw_addressbook_extra';
|
var $ext_table='egw_addressbook_extra';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int $tz_offset_s offset in secconds between user and server-time,
|
||||||
|
* it need to be add to a server-time to get the user-time or substracted from a user-time to get the server-time
|
||||||
|
*/
|
||||||
|
var $tz_offset_s;
|
||||||
|
|
||||||
var $account_id = 0;
|
var $account_id = 0;
|
||||||
var $total_records = 0;
|
var $total_records = 0;
|
||||||
var $grants = '';
|
var $grants = '';
|
||||||
@ -167,6 +176,11 @@
|
|||||||
'parcel' => lang('Parcel'),
|
'parcel' => lang('Parcel'),
|
||||||
'postal' => lang('Postal')
|
'postal' => lang('Postal')
|
||||||
);
|
);
|
||||||
|
if (!is_object($GLOBALS['egw']->datetime))
|
||||||
|
{
|
||||||
|
$GLOBALS['egw']->datetime =& CreateObject('phpgwapi.datetime');
|
||||||
|
}
|
||||||
|
$this->tz_offset_s = $GLOBALS['egw']->datetime->tz_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* send this the id and whatever fields you want to see */
|
/* send this the id and whatever fields you want to see */
|
||||||
@ -402,19 +416,16 @@
|
|||||||
echo "<br>DEBUG - $ordermethod";
|
echo "<br>DEBUG - $ordermethod";
|
||||||
}
|
}
|
||||||
|
|
||||||
if($lastmod >= 0 && $fwhere)
|
if($lastmod >= 0)
|
||||||
{
|
{
|
||||||
$fwhere .= " AND last_mod > ".(int)$lastmod.' ';
|
if (!$fwhere) $fwhere = ' WHERE ';
|
||||||
}
|
$fwhere .= " AND last_mod > ".(int)($lastmod - $this->tz_offset_s).' ';
|
||||||
elseif($lastmod >= 0)
|
|
||||||
{
|
|
||||||
$fwhere = " WHERE last_mod > ".(int)$lastmod.' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($DEBUG && $last_mod_filter && $fwhere)
|
if ($DEBUG)
|
||||||
{
|
{
|
||||||
echo "<br>DEBUG - last_mod_filter added to fwhere: $fwhere";
|
echo "<br>DEBUG - last_mod_filter added to fwhere: $fwhere";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$filtermethod = '';
|
$filtermethod = '';
|
||||||
|
|
||||||
@ -551,7 +562,7 @@
|
|||||||
$return_fields[$i]['owner'] = $this->db->f('owner');
|
$return_fields[$i]['owner'] = $this->db->f('owner');
|
||||||
$return_fields[$i]['access'] = $this->db->f('access');
|
$return_fields[$i]['access'] = $this->db->f('access');
|
||||||
$return_fields[$i]['cat_id'] = $this->db->f('cat_id');
|
$return_fields[$i]['cat_id'] = $this->db->f('cat_id');
|
||||||
$return_fields[$i]['last_mod'] = $this->db->f('last_mod');
|
$return_fields[$i]['last_mod'] = $this->db->f('last_mod')+$this->tz_offset_s;
|
||||||
$return_fields[$i]['rights'] = (int)$this->grants[$this->db->f('owner')];
|
$return_fields[$i]['rights'] = (int)$this->grants[$this->db->f('owner')];
|
||||||
|
|
||||||
if(@is_array($stock_fieldnames))
|
if(@is_array($stock_fieldnames))
|
||||||
@ -599,7 +610,7 @@
|
|||||||
|
|
||||||
//this is added here so it is never tainted
|
//this is added here so it is never tainted
|
||||||
$this->stock_contact_fields['last_mod'] = 'last_mod';
|
$this->stock_contact_fields['last_mod'] = 'last_mod';
|
||||||
$stock_fields['last_mod'] = $GLOBALS['egw']->datetime->gmtnow;
|
$stock_fields['last_mod'] = time();
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'owner' => $owner,
|
'owner' => $owner,
|
||||||
@ -609,6 +620,7 @@
|
|||||||
);
|
);
|
||||||
if (isset($fields['lid'])) $data['lid'] = $fields['lid'];
|
if (isset($fields['lid'])) $data['lid'] = $fields['lid'];
|
||||||
|
|
||||||
|
|
||||||
$this->db->insert($this->std_table,array_merge($data,$stock_fields),False,__LINE__,__FILE__);
|
$this->db->insert($this->std_table,array_merge($data,$stock_fields),False,__LINE__,__FILE__);
|
||||||
|
|
||||||
$id = $this->db->get_last_insert_id($this->std_table, 'id');
|
$id = $this->db->get_last_insert_id($this->std_table, 'id');
|
||||||
@ -682,7 +694,7 @@
|
|||||||
|
|
||||||
if (count($stock_fields))
|
if (count($stock_fields))
|
||||||
{
|
{
|
||||||
$stock_fields['last_mod'] = $GLOBALS['egw']->datetime->gmtnow;
|
$stock_fields['last_mod'] = time();
|
||||||
$this->db->update($this->std_table,$stock_fields,array('id'=>$id),__LINE__,__FILE__);
|
$this->db->update($this->std_table,$stock_fields,array('id'=>$id),__LINE__,__FILE__);
|
||||||
}
|
}
|
||||||
if (is_array($extra_fields))
|
if (is_array($extra_fields))
|
||||||
|
Loading…
Reference in New Issue
Block a user