Major SyncML Calendar update

- SIFE support improved
  - various vCalendar 1.0 issues fixed
  - device specific timezone support for recurring events
  - pseudo exception handling improvements
This commit is contained in:
Jörg Lehrke 2010-01-29 21:42:54 +00:00
parent 61d26df913
commit 32639bd47e
12 changed files with 2362 additions and 782 deletions

View File

@ -525,7 +525,7 @@ class calendar_bo
/**
* Get integration data for a given app of a part (value for a certain key) of it
*
*
* @param string $app
* @param string $part
* @return array
@ -533,23 +533,23 @@ class calendar_bo
static function integration_get_data($app,$part=null)
{
static $integration_data;
if (!isset($integration_data))
{
$integration_data = calendar_so::get_integration_data();
}
if (!isset($integration_data[$app])) return null;
return $part ? $integration_data[$app][$part] : $integration_data[$app];
}
/**
* Get private attribute for an integration event
*
*
* Attribute 'is_private' is either a boolean value, eg. false to make all events of $app public
* or an ExecMethod callback with parameters $id,$event
*
*
* @param string $app
* @param int|string $id
* @return string
@ -557,7 +557,7 @@ class calendar_bo
static function integration_get_private($app,$id,$event)
{
$app_data = self::integration_get_data($app,'is_private');
// no method, fall back to link title
if (is_null($app_data))
{
@ -660,22 +660,23 @@ class calendar_bo
*/
function set_recurrences($event,$start=0)
{
if ($this->debug && ((int) $this->debug >= 2 || $this->debug == 'set_recurrences' || $this->debug == 'check_move_horizont'))
if ($this->debug && ((int) $this->debug >= 2 || $this->debug == 'set_recurrences' || $this->debug == 'check_move_horizont'))
{
$this->debug_message('bocal::set_recurrences(%1,%2)',true,$event,$start);
}
// check if the caller gave the event start and end times and if not read them from the DB
if (!isset($event['start']) || !isset($event['end']))
{
$event_read=$this->read($event['id']);
$event['start'] = $event_read['start'];
$event['end'] = $event_read['end'];
}
// check if the caller gave the participants and if not read them from the DB
if (!isset($event['participants']))
// check if the caller gave us enough information and if not read it from the DB
if (!isset($event['participants']) || !isset($event['start']) || !isset($event['end']))
{
list(,$event_read) = each($this->so->read($event['id']));
$event['participants'] = $event_read['participants'];
if (!isset($event['participants']))
{
$event['participants'] = $event_read['participants'];
}
if (!isset($event['start']) || !isset($event['end']))
{
$event['start'] = $event_read['start'];
$event['end'] = $event_read['end'];
}
}
if (!$start) $start = $event['start'];
@ -708,7 +709,6 @@ class calendar_bo
foreach($events as $id => &$event)
{
// convert timezone id of event to tzid (iCal id like 'Europe/Berlin')
unset($event_timezone);
if (!$event['tz_id'] || !($event['tzid'] = calendar_timezones::id2tz($event['tz_id'])))
{
$event['tzid'] = egw_time::$server_timezone->getName();

View File

@ -61,9 +61,11 @@ class calendar_boupdate extends calendar_bo
var $debug;
/**
* @var string|boolean $log_file filename to enable the login or false for no update-logging
* Set Logging
*
* @var boolean
*/
var $log_file = false;
var $log = false;
/**
* Constructor
@ -1042,6 +1044,11 @@ class calendar_boupdate extends calendar_bo
return false;
}
calendar_so::split_status($status, $quantity, $role);
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
"($cal_id, $uid, $status, $recur_date)");
}
if (($Ok = $this->so->set_status($cal_id,is_numeric($uid)?'u':$uid[0],is_numeric($uid)?$uid:substr($uid,1),$status,$recur_date ? $this->date2ts($recur_date,true) : 0,$role)))
{
if ($updateTS) $GLOBALS['egw']->contenthistory->updateTimeStamp('calendar',$cal_id,'modify',time());
@ -1407,111 +1414,430 @@ class calendar_boupdate extends calendar_bo
* Try to find a matching db entry
*
* @param array $event the vCalendar data we try to find
* @param boolean $relax=false if asked to relax, we only match against some key fields
* @return the calendar_id of the matching entry or false (if none matches)
* @param string filter='exact' exact -> check for identical matches
* relax -> be more tolerant
* master -> try to find a releated series master
* @return array calendar_id's of matching entries
*/
function find_event($event, $relax=false)
function find_event($event, $filter='exact')
{
$matchingEvents = array();
$query = array();
if (isset($event['start']))
// unset($event['uid']);
if ($this->log)
{
$query[] = 'cal_start='.$event['start'];
}
if (isset($event['end']))
{
$query[] = 'cal_end='.$event['end'];
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
"($filter)[EVENT]:" . array2string($event));
}
foreach (array('title', 'location',
'public', 'non_blocking', 'category') as $key)
if ($filter == 'master')
{
if (!empty($event[$key])) $query['cal_'.$key] = $event[$key];
$recur_date = 0;
$event['recurrence'] = 0;
}
if ($event['uid'] && ($uidmatch = $this->read($event['uid'])))
else
{
if ($event['recurrence'])
if ($event['recur_type'] == MCAL_RECUR_NONE)
{
// Let's try to find a real exception first
$query['cal_uid'] = $event['uid'];
$query['cal_recurrence'] = $event['recurrence'];
if ($foundEvents = parent::search(array(
'query' => $query,
)))
if (empty($event['uid']) || !isset($event['recurrence']))
{
if(is_array($foundEvents))
{
$event = array_shift($foundEvents);
return $event['id'];
}
}
// Let's try the "status only" (pseudo) exceptions now
if (($egw_event = $this->read($uidmatch['id'], $event['recurrence'])))
{
// Do we work with a pseudo exception here?
$match = true;
foreach (array('start', 'end', 'title', 'priority',
'location', 'public', 'non_blocking') as $key)
{
if (isset($event[$key])
&& $event[$key] != $egw_event[$key])
{
$match = false;
break;
}
}
if ($match && is_array($event['participants']))
{
foreach ($event['participants'] as $attendee => $status)
{
if (!isset($egw_event['participants'][$attendee])
|| $egw_event['participants'][$attendee] != $status)
{
$match = false;
break;
}
else
{
unset($egw_event['participants'][$attendee]);
}
}
if ($match && !empty($egw_event['participants'])) $match = false;
}
if ($match) return ($uidmatch['id'] . ':' . $event['recurrence']);
return false; // We need to create a new pseudo exception
$event['recurrence'] = $event['start'];
}
$recur_date = $event['recurrence'];
}
else
{
return $uidmatch['id'];
$event['recurrence'] = 0;
$recur_date = $event['start'];
}
$recur_date = $this->date2usertime($recur_date);
}
if ($event['id'] && ($found = $this->read($event['id'])))
if ($event['id'])
{
// We only do a simple consistency check
if ($found['title'] == $event['title']
&& $found['start'] == $event['start']
&& $found['end'] == $event['end'])
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'(' . $event['id'] . ")[EventID]");
}
if (($egwEvent = $this->read($event['id'], $recur_date, false, 'server')))
{
if ($this->log)
{
return $found['id'];
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'()[FOUND]:' . array2string($egwEvent));
}
// Just a simple consistency check
if ($filter == 'master' && $egwEvent['recur_type'] != MCAL_RECUR_NONE ||
$egwEvent['title'] == $event['title'] &&
abs($egwEvent['start'] - $event['start']) < 60 &&
abs($egwEvent['end'] - $event['end']) < 120)
{
$retval = $egwEvent['id'];
if ($egwEvent['recur_type'] != MCAL_RECUR_NONE &&
$event['recur_type'] == MCAL_RECUR_NONE && $event['recurrence'] != 0)
{
$retval .= ':' . (int)$event['recurrence'];
}
$matchingEvents[] = $retval;
return $matchingEvents;
}
}
if ($filter == 'exact') return array();
}
unset($event['id']);
if($foundEvents = parent::search(array(
'query' => $query,
)))
if (isset($event['whole_day']) && $event['whole_day'])
{
if(is_array($foundEvents))
if ($filter == 'relax')
{
$event = array_shift($foundEvents);
return $event['id'];
$delta = 1800;
}
else
{
$delta = 60;
}
// check length with some tolerance
$length = $event['end'] - $event['start'] - $delta;
$query[] = ('(cal_end-cal_start)>' . $length);
$length += 2 * $delta;
$query[] = ('(cal_end-cal_start)<' . $length);
}
elseif (isset($event['start']))
{
if ($filter != 'master')
{
if ($filter == 'relax')
{
$query[] = ('cal_start>' . ($event['start'] - 3600));
$query[] = ('cal_start<' . ($event['start'] + 3600));
}
else
{
// we accept a tiny tolerance
$query[] = ('cal_start>' . ($event['start'] - 2));
$query[] = ('cal_start<' . ($event['start'] + 2));
}
}
}
return false;
if ($filter == 'master')
{
$query[] = 'recur_type!='. MCAL_RECUR_NONE;
}
// only query calendars of users, we have READ-grants from
$users = array();
foreach(array_keys($this->grants) as $user)
{
$user = trim($user);
if ($this->check_perms(EGW_ACL_READ|EGW_ACL_READ_FOR_PARTICIPANTS|EGW_ACL_FREEBUSY,0,$user))
{
if ($user && !in_array($user,$users)) // already added?
{
$users[] = $user;
}
}
elseif ($GLOBALS['egw']->accounts->get_type($user) != 'g')
{
continue; // for non-groups (eg. users), we stop here if we have no read-rights
}
// the further code is only for real users
if (!is_numeric($user)) continue;
// for groups we have to include the members
if ($GLOBALS['egw']->accounts->get_type($user) == 'g')
{
$members = $GLOBALS['egw']->accounts->member($user);
if (is_array($members))
{
foreach($members as $member)
{
// use only members which gave the user a read-grant
if (!in_array($member['account_id'],$users) &&
$this->check_perms(EGW_ACL_READ|EGW_ACL_FREEBUSY,0,$member['account_id']))
{
$users[] = $member['account_id'];
}
}
}
}
else // for users we have to include all the memberships, to get the group-events
{
$memberships = $GLOBALS['egw']->accounts->membership($user);
if (is_array($memberships))
{
foreach($memberships as $group)
{
if (!in_array($group['account_id'],$users))
{
$users[] = $group['account_id'];
}
}
}
}
}
if (empty($event['uid']))
{
$matchFields = array('title', 'priority', 'public', 'non_blocking');
switch ($filter)
{
case 'relax':
$matchFields[] = 'location';
case 'master':
break;
default:
$matchFields[] = 'description';
$matchFields[] = 'location';
}
foreach ($matchFields as $key)
{
if (!empty($event[$key])) $query['cal_'.$key] = $event[$key];
}
}
else
{
$query['cal_uid'] = $event['uid'];
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'(' . $event['uid'] . ')[EventUID]');
}
}
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'[QUERY]: ' . array2string($query));
}
if (!count($users) || !($foundEvents =
$this->so->search(null, null, $users, 0, 'owner', $query)))
{
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'[NO MATCH]');
}
return $matchingEvents;
}
$pseudos = array();
foreach($foundEvents as $egwEvent)
{
if (in_array($egwEvent['id'], $matchingEvents)) continue;
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'[FOUND]: ' . array2string($egwEvent));
}
// convert timezone id of event to tzid (iCal id like 'Europe/Berlin')
if (!$egwEvent['tz_id'] || !($egwEvent['tzid'] = calendar_timezones::id2tz($egwEvent['tz_id'])))
{
$egwEvent['tzid'] = egw_time::$server_timezone->getName();
}
// check times
if ($filter != 'relax')
{
if (isset($event['whole_day'])&& $event['whole_day'])
{
if (!$this->so->isWholeDay($egwEvent))
{
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'() egwEvent is not a whole-day event!');
}
continue;
}
}
elseif ($filter != 'master')
{
if (abs($event['end'] - $egwEvent['end']) >= 120)
{
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'() egwEvent length does not match!');
}
continue;
}
}
}
if ($filter != 'master')
{
// check categories
if (!is_array($event['category'])) $event['category'] = array();
$egwCategories = explode(',', $egwEvent['category']);
foreach ($egwCategories as $cat_id)
{
if ($this->categories->check_perms(EGW_ACL_READ, $cat_id) &&
!in_array($cat_id, $event['category']))
{
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
"() egwEvent category $cat_id is missing!");
}
continue 2;
}
}
$newCategories = array_diff($event['category'], $egwCategories);
if (!empty($newCategories))
{
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'() event has additional categories:' . array2string($newCategories));
}
continue;
}
}
/*
// check information
$matchFields = array();
foreach ($matchFields as $key)
{
if (isset($event[$key])
&& $event[$key] != $egwEvent[$key])
{
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
"() events[$key] differ: " . $event[$key] .
' <> ' . $egwEvent[$key]);
}
continue 2; // next foundEvent
}
}
*/
if ($filter != 'relax' && $filter != 'master')
{
// check participants
if (is_array($event['participants']))
{
foreach ($event['participants'] as $attendee => $status)
{
if (!isset($egwEvent['participants'][$attendee]) &&
$attendee != $egwEvent['owner']) // ||
//(!$relax && $egw_event['participants'][$attendee] != $status))
{
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
"() additional event['participants']: $attendee");
}
continue 2;
}
else
{
unset($egwEvent['participants'][$attendee]);
}
}
// ORGANIZER is maybe missing
unset($egwEvent['participants'][$egwEvent['owner']]);
if (!empty($egwEvent['participants']))
{
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'() missing event[participants]: ' .
array2string($egwEvent['participants']));
}
continue;
}
}
}
if ($filter != 'master')
{
if ($event['recur_type'] == MCAL_RECUR_NONE)
{
if ($egwEvent['recur_type'] != MCAL_RECUR_NONE)
{
// We found a pseudo Exception
$pseudos[] = $egwEvent['id'] . ':' . $event['start'];
continue;
}
}
elseif ($filter != 'relax')
{
// check exceptions
// $exceptions[$remote_ts] = $egw_ts
$exceptions = $this->so->get_recurrence_exceptions($egwEvent, $event['$tzid'], 0, 0, 'map');
// remove leading exceptions
foreach ($exceptions as $key => $day)
{
if ($day <= $event['start']) unset($exceptions['key']);
}
if (is_array($event['recur_excpetion']))
{
foreach ($event['recur_excpetion'] as $key => $day)
{
if (isset($exceptions[$day]))
{
unset($exceptions[$day]);
}
else
{
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
"() additional event['recur_exception']: $day");
}
continue 2;
}
}
if (!empty($exceptions))
{
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'() missing event[recur_exception]: ' .
array2string($event['recur_excpetion']));
}
continue;
}
}
// check recurrence information
foreach (array('recur_type', 'recur_interval') as $key)
{
if (isset($event[$key])
&& $event[$key] != $egwEvent[$key])
{
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
"() events[$key] differ: " . $event[$key] .
' <> ' . $egwEvent[$key]);
}
continue 2;
}
}
}
}
$matchingEvents[] = $egwEvent['id']; // exact match
}
// append pseudos as last entries
$matchingEvents = array_merge($matchingEvents, $pseudos);
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'[MATCHES]:' . array2string($matchingEvents));
}
return $matchingEvents;
}
/**
@ -1528,17 +1854,19 @@ class calendar_boupdate extends calendar_bo
* SINGLE a single event
* SERIES-MASTER the series master
* SERIES-EXCEPTION event is a real exception
* SERIES-EXCEPTION-STATUS event is a status only exception
* SERIES-PSEUDO-EXCEPTION event is a status only exception
* SERIES-EXCEPTION-PROPAGATE event was a status only exception in the past and is now a real exception
* stored_event => if event already exists in the database array with event data or false
* master_event => for event type SERIES-EXCEPTION, SERIES-EXCEPTION-STATUS or SERIES-EXCEPTION-PROPAGATE
* master_event => for event type SERIES-EXCEPTION, SERIES-PSEUDO-EXCEPTION or SERIES-EXCEPTION-PROPAGATE
* the corresponding series master event array
* NOTE: this param is false if event is of type SERIES-MASTER
*/
function get_event_info($event)
{
$type = 'SINGLE'; // default
$return_master = false; //default
$master_event = false; //default
$stored_event = false;
$recurrence_event = false;
if ($event['recur_type'] != MCAL_RECUR_NONE)
{
@ -1547,68 +1875,126 @@ class calendar_boupdate extends calendar_bo
else
{
// SINGLE, SERIES-EXCEPTION OR SERIES-EXCEPTON-STATUS
if (empty($event['uid']) && $event['id'] > 0 && ($stored_event = $this->read($event['id'])))
if (($foundEvents = $this->find_event($event, 'exact')))
{
$event['uid'] = $stored_event['uid']; // restore the UID if it was not delivered
}
if (isset($event['uid'])
&& $event['recurrence']
&& ($master_event = $this->read($event['uid']))
&& isset($master_event['recur_type'])
&& $master_event['recur_type'] != MCAL_RECUR_NONE)
{
// SERIES-EXCEPTION OR SERIES-EXCEPTON-STATUS
$return_master = true; // we have a valid master and can return it
if (isset($event['id']) && $master_event['id'] != $event['id'])
// We found the exact match
$eventID = array_shift($foundEvents);
if ($this->log)
{
$type = 'SERIES-EXCEPTION'; // this is an existing exception
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
"()[EVENT]: $eventID");
}
if (strstr($eventID, ':'))
{
$type = 'SERIES-PSEUDO-EXCEPTION';
list($eventID, $recur_date) = explode(':', $eventID);
$recur_date = $this->date2usertime($recur_date);
$stored_event = $this->read($eventID, $recur_date, false, 'server');
$master_event = $this->read($eventID, 0, false, 'server');
$recurrence_event = $stored_event;
}
else
{
$type = 'SERIES-EXCEPTION-STATUS'; // default if we cannot find a proof for a fundamental change
// the recurrence_event is the master event with start and end adjusted to the recurrence
$recurrence_event = $master_event;
$recurrence_event['start'] = $event['recurrence'];
$recurrence_event['end'] = $event['recurrence'] + ($master_event['end'] - $master_event['start']);
// check for changed data
foreach (array('start','end','uid','title','location',
'priority','public','special','non_blocking') as $key)
{
if (!empty($event[$key]) && $recurrence_event[$key] != $event[$key])
{
if (isset($event['id']))
{
$type = 'SERIES-EXCEPTION-PROPAGATE';
}
else
{
$type = 'SERIES-EXCEPTION'; // this is a new exception
}
break;
}
}
// the event id here is always the id of the master event
// unset it to prevent confusion of stored event and master event
unset($event['id']);
$stored_event = $this->read($eventID, 0, false, 'server');
}
if (empty($event['uid']))
{
$event['uid'] = $stored_event['uid']; // restore the UID if it was not delivered
}
}
else
if ($type == 'SINGLE' &&
($foundEvents = $this->find_event($event, 'master')))
{
// SINGLE
$type = 'SINGLE';
// Let's try to find a related series
foreach ($foundEvents as $eventID)
{
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
"()[MASTER]: $eventID");
}
if (($master_event = $this->read($eventID, 0, false, 'server')))
{
if (isset($stored_event['id']) && $master_event['id'] != $stored_event['id'])
{
$type = 'SERIES-EXCEPTION'; // this is an existing exception
}
elseif (in_array($event['start'], $master_event['recur_exception']))
{
$type='SERIES-PSEUDO-EXCEPTION'; // new pseudo exception?
$recurrence_event = $event;
break;
}
elseif (isset($event['recurrence']) &&
in_array($event['recurrence'], $master_event['recur_exception']))
{
$type = 'SERIES-EXCEPTION';
break;
}
else
{
// try to find a suitable pseudo exception date
$egw_rrule = calendar_rrule::event2rrule($master_event, false);
$egw_rrule->rewind();
while ($egw_rrule->valid())
{
$occurrence = egw_time::to($egw_rrule->current(), 'server');
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'() try occurrence ' . $egw_rrule->current() . " ($occurrence)");
}
if ($event['start'] == $occurrence)
{
$type = 'SERIES-PSEUDO-EXCEPTION'; // let's try a pseudo exception
$recurrence_event = $event;
break 2;
}
if (isset($event['recurrence']) && $event['recurrence'] == $occurrence)
{
$type = 'SERIES-EXCEPTION-PROPAGATE';
if ($stored_event)
{
unset($stored_event['id']); // signal the true exception
$stored_event['recur_type'] = MCAL_RECUR_NONE;
}
break 2;
}
$egw_rrule->next_no_exception();
}
}
}
}
}
}
// read existing event
if (isset($event['id']))
{
$stored_event = $this->read($event['id']);
// check pseudo exception propagation
if ($recurrence_event)
{
// default if we cannot find a proof for a fundamental change
// the recurrence_event is the master event with start and end adjusted to the recurrence
// check for changed data
foreach (array('start','end','uid','title','location','description',
'priority','public','special','non_blocking') as $key)
{
if (!empty($event[$key]) && $recurrence_event[$key] != $event[$key])
{
$type = 'SERIES-EXCEPTION-PROPAGATE';
if ($stored_event)
{
unset($stored_event['id']); // signal the true exception
$stored_event['recur_type'] = MCAL_RECUR_NONE;
}
break;
}
}
// the event id here is always the id of the master event
// unset it to prevent confusion of stored event and master event
unset($event['id']);
}
}
// check ACL
if ($return_master)
if (is_array($master_event))
{
$acl_edit = $this->check_perms(EGW_ACL_EDIT, $master_event['id']);
}
@ -1627,8 +2013,40 @@ class calendar_boupdate extends calendar_bo
return array(
'type' => $type,
'acl_edit' => $acl_edit,
'stored_event' => is_array($stored_event) ? $stored_event : false,
'master_event' => $return_master ? $master_event : false,
'stored_event' => $stored_event,
'master_event' => $master_event,
);
}
/*
* Translates all timestamps for a given event from servert-ime to user-time.
* The update() and save() methods expect timestamps in user-time.
* @param &$event the event we are working on
*
*/
function server2usertime (&$event)
{
// we run all dates through date2usertime, to adjust to user-time
foreach(array('start','end','recur_enddate','recurrence') as $ts)
{
// we convert here from server-time to timestamps in user-time!
if (isset($event[$ts])) $event[$ts] = $event[$ts] ? $this->date2usertime($event[$ts]) : 0;
}
// same with the recur exceptions
if (isset($event['recur_exception']) && is_array($event['recur_exception']))
{
foreach($event['recur_exception'] as $n => $date)
{
$event['recur_exception'][$n] = $this->date2usertime($date);
}
}
// same with the alarms
if (isset($event['alarm']) && is_array($event['alarm']))
{
foreach($event['alarm'] as $id => $alarm)
{
$event['alarm'][$id]['time'] = $this->date2usertime($alarm['time']);
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,7 @@
* @link http://www.egroupware.org
* @package calendar
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @author Joerg Lehrke <jlehrke@noc.de>
* @copyright (c) 2009 by RalfBecker-At-outdoor-training.de
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
@ -192,6 +193,12 @@ class calendar_rrule implements Iterator
*/
protected $lastdayofweek;
/**
* Cached timezone data
*
* @var array id => data
*/
protected static $tz_cache = array();
/**
* Constructor
@ -426,6 +433,12 @@ class calendar_rrule implements Iterator
public function rewind()
{
$this->current = clone $this->time;
while ($this->valid() &&
$this->exceptions &&
in_array($this->current->format('Ymd'),$this->exceptions))
{
$this->next_no_exception();
}
}
/**
@ -517,18 +530,21 @@ class calendar_rrule implements Iterator
/**
* Generate a VEVENT RRULE
* @param string $version='1.0' could be '2.0', too
*
* $return array vCalendar RRULE
*/
public function generate_rrule($version='1.0')
{
static $utc;
$repeat_days = array();
$rrule = array();
if (is_null($utc))
if (!isset(self::$tz_cache['UTC']))
{
$utc = calendar_timezones::DateTimeZone('UTC');
self::$tz_cache['UTC'] = calendar_timezones::DateTimeZone('UTC');
}
$utc = self::$tz_cache['UTC'];
if ($this->type == self::NONE) return false; // no recuring event
if ($version == '1.0')
@ -609,13 +625,24 @@ class calendar_rrule implements Iterator
*
* @param array $event
* @param boolean $usertime=true true: event timestamps are usertime (default for calendar_bo::(read|search), false: servertime
* @param string $to_tz timezone for exports (null for event's timezone)
*
* @return calendar_rrule
*/
public static function event2rrule(array $event,$usertime=true)
public static function event2rrule(array $event,$usertime=true,$to_tz=null)
{
if (!$to_tz) $to_tz = $event['tzid'];
$timestamp_tz = $usertime ? egw_time::$user_timezone : egw_time::$server_timezone;
$time = is_a($event['start'],'DateTime') ? $event['start'] : new egw_time($event['start'],$timestamp_tz);
$time->setTimezone(new DateTimeZone($event['tzid']));
if (!isset(self::$tz_cache[$to_tz]))
{
self::$tz_cache[$to_tz] = calendar_timezones::DateTimeZone($to_tz);
}
self::rrule2tz($event, $time, $to_tz);
$time->setTimezone(self::$tz_cache[$to_tz]);
if ($event['recur_enddate'])
{
@ -646,6 +673,64 @@ class calendar_rrule implements Iterator
'recur_exception' => $this->exceptions,
);
}
/**
* Shift a recurrence rule to a new timezone
*
* @param array $event recurring event
* @param DateTime/string starttime of the event (in servertime)
* @param string $to_tz new timezone
*/
public static function rrule2tz(array &$event,$starttime,$to_tz)
{
// We assume that the difference between timezones can result
// in a maximum of one day
if (!is_array($event) ||
!isset($event['recur_type']) ||
$event['recur_type'] == MCAL_RECUR_NONE ||
empty($event['recur_data']) || $event['recur_data'] == ALLDAYS ||
empty($event['tzid']) || empty($to_tz) ||
$event['tzid'] == $to_tz) return;
if (!isset(self::$tz_cache[$event['tzid']]))
{
self::$tz_cache[$event['tzid']] = calendar_timezones::DateTimeZone($event['tzid']);
}
if (!isset(self::$tz_cache[$to_tz]))
{
self::$tz_cache[$to_tz] = calendar_timezones::DateTimeZone($to_tz);
}
$time = is_a($starttime,'DateTime') ?
$starttime : new egw_time($starttime, egw_time::$server_timezone);
$time->setTimezone(self::$tz_cache[$event['tzid']]);
$remote = clone $time;
$remote->setTimezone(self::$tz_cache[$to_tz]);
$delta = (int)$remote->format('w') - (int)$time->format('w');
if ($delta)
{
// We have to generate a shifted rrule
switch ($event['recur_type'])
{
case self::MONTHLY_WDAY:
case self::WEEKLY:
$mask = (int)$event['recur_data'];
if ($delta == 1 || $delta == -6)
{
$mask = $mask << 1;
if ($mask & 128) $mask = $mask - 127; // overflow
}
else
{
if ($mask & 1) $mask = $mask + 128; // underflow
$mask = $mask >> 1;
}
$event['recur_data'] = $mask;
}
}
}
}
if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) // some tests

File diff suppressed because it is too large Load Diff

View File

@ -157,6 +157,7 @@ class calendar_so
// We want only the parents to match
$where['cal_uid'] = $ids;
$where['cal_reference'] = 0;
$where['cal_recurrence'] = 0;
}
if ((int) $recur_date)
{
@ -358,7 +359,7 @@ class calendar_so
'cal_user_type' => $type,
'cal_user_id' => $ids,
));
if ($type == 'u' && ($filter == 'owner' || $filter == 'all'))
if ($type == 'u' && ($filter == 'owner'))
{
$cal_table_def = $this->db->get_table_definitions('calendar',$this->cal_table);
$to_or[] = $this->db->expression($cal_table_def,array('cal_owner' => $ids));
@ -377,6 +378,7 @@ class calendar_so
case 'rejected':
$where[] = "cal_status='R'"; break;
case 'all':
case 'owner':
break;
default:
//if (!$show_rejected) // not longer used
@ -458,22 +460,22 @@ class calendar_so
$recur_dates[] = $row['cal_recur_date'];
}
if ($row['participants'])
{
$row['participants'] = explode(',',$row['participants']);
$row['participants'] = array_combine($row['participants'],
array_fill(0,count($row['participants']),''));
}
else
{
$row['participants'] = array();
}
$row['alarm'] = array();
{
$row['participants'] = explode(',',$row['participants']);
$row['participants'] = array_combine($row['participants'],
array_fill(0,count($row['participants']),''));
}
else
{
$row['participants'] = array();
}
$row['alarm'] = array();
$row['recur_exception'] = $row['recur_exception'] ? explode(',',$row['recur_exception']) : array();
$events[$id] = egw_db::strip_array_keys($row,'cal_');
}
//_debug_array($events);
if (count($ids))
if (count($events))
{
// now ready all users with the given cal_id AND (cal_recur_date=0 or the fitting recur-date)
// This will always read the first entry of each recuring event too, we eliminate it later
@ -537,7 +539,7 @@ class calendar_so
//echo "<p>socal::search\n"; _debug_array($events);
return $events;
}
/**
* Data returned by calendar_search_union hook
*/
@ -558,11 +560,11 @@ class calendar_so
{
if (in_array(basename($_SERVER['SCRIPT_FILENAME']),array('groupdav.php','rpc.php','xmlrpc.php')))
{
return; // disable integration for GroupDAV, SyncML, ...
return; // disable integration for GroupDAV, SyncML, ...
}
self::$integration_data = $GLOBALS['egw']->hooks->process(array(
'location' => 'calendar_search_union',
'cols' => $selects[0]['cols'], // cols to return
'cols' => $selects[0]['cols'], // cols to return
'start' => $start,
'end' => $end,
'users' => $users,
@ -579,17 +581,17 @@ class calendar_so
}
}
}
/**
* Get data from last 'calendar_search_union' hook call
*
*
* @return array
*/
public static function get_integration_data()
{
return self::$integration_data;
}
/**
* Checks for conflicts
*/
@ -669,7 +671,19 @@ ORDER BY cal_user_type, cal_usre_id
unset($event[$col]);
}
}
if (is_array($event['cal_category'])) $event['cal_category'] = implode(',',$event['cal_category']);
// ensure that we find mathing entries later on
if (!is_array($event['cal_category']))
{
$categories = array_unique(explode(',',$event['cal_category']));
sort($categories);
}
else
{
$categories = array_unique($event['cal_category']);
}
sort($categories, SORT_NUMERIC);
$event['cal_category'] = implode(',',$categories);
if ($cal_id)
{
@ -1565,95 +1579,334 @@ ORDER BY cal_user_type, cal_usre_id
* @param array $event Recurring Event.
* @param string tz_id=null timezone for exports (null for event's timezone)
* @param int $start=0 if != 0: startdate of the search/list (servertime)
* @param int $end=0 if != 0: enddate of the search/list (servertime)
* @param string $filter='all' string filter-name: all (not rejected), accepted, unknown, tentative,
* rejected, tz_transitions (return only by timezone transition affected entries)
* @param int $end=0 if != 0: enddate of the search/list (servertime)
* @param string $filter='all' string filter-name: all (not rejected),
* accepted, unknown, tentative, rejected,
* rrule return array of remote exceptions in servertime
* tz_rrule/tz_only, return (only by) timezone transition affected entries
* map return array of dates with no pseudo exception
* key remote occurrence date
* tz_map return array of all dates with no tz pseudo exception
*
* @return array Array of exception days (false for non-recurring events).
*/
function get_recurrence_exceptions(&$event, $tz_id=null, $start=0, $end=0, $filter='all')
function get_recurrence_exceptions($event, $tz_id=null, $start=0, $end=0, $filter='all')
{
if (!is_array($event)) return false;
$cal_id = (int) $event['id'];
//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
// "($cal_id, $tz_id, $filter): " . $event['tzid']);
if (!$cal_id || $event['recur_type'] == MCAL_RECUR_NONE) return false;
$days = array();
$first_start = $recur_start = '';
if (!empty($tz_id))
$expand_all = (!$this->isWholeDay($event) && $tz_id && $tz_id != $event['tzid']);
if ($filter == 'tz_only' && !$expand_all) return $days;
$remote = in_array($filter, array('tz_rrule', 'rrule'));
$egw_rrule = calendar_rrule::event2rrule($event, false);
$egw_rrule->rewind();
if ($expand_all)
{
// set export timezone
if(!isset(self::$tz_cache[$tz_id]))
unset($event['recur_excpetion']);
$remote_rrule = calendar_rrule::event2rrule($event, false, $tz_id);
$remote_rrule->rewind();
}
while ($egw_rrule->valid())
{
$day = $egw_rrule->current();
$locts = (int)egw_time::to($day,'server');
$tz_exception = ($filter == 'tz_rrule');
//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
// '()[EVENT Server]: ' . $day->format('Ymd\THis') . " ($locts)");
if ($expand_all)
{
self::$tz_cache[$tz_id] = calendar_timezones::DateTimeZone($tz_id);
$remote_day = $remote_rrule->current();
$remts = (int)egw_time::to($remote_day,'server');
// error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
// '()[EVENT Device]: ' . $remote_day->format('Ymd\THis') . " ($remts)");
}
$starttime = new egw_time($event['start'], egw_time::$server_timezone);
$starttime->setTimezone(self::$tz_cache[$tz_id]);
$first_start = $starttime->format('His');
if (!($end && $end < $locts) && $start <= $locts)
{
// we are within the relevant time period
if ($expand_all && $day->format('U') != $remote_day->format('U'))
{
$tz_exception = true;
if ($filter != 'map' && $filter != 'tz_map')
{
// timezone pseudo exception
//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
// '() tz exception: ' . $day->format('Ymd\THis'));
if ($remote)
{
$days[$locts]= $remts;
}
else
{
$days[$remts]= $locts;
}
}
}
if ($filter != 'tz_map' && (!$tz_exception || $filter == 'tz_only') &&
$this->status_pseudo_exception($event['id'], $locts, $filter))
{
// status pseudo exception
//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
// '() status exception: ' . $day->format('Ymd\THis'));
if ($expand_all)
{
$remts = (int)egw_time::to($remote_day,'server');
if ($filter == 'tz_only')
{
unset($days[$remts]);
}
else
{
if ($filter != 'map')
{
if ($remote)
{
$days[$locts]= $remts;
}
else
{
$days[$remts]= $locts;
}
}
}
}
elseif ($filter != 'map')
{
$days[$locts]= $locts;
}
}
elseif (($filter == 'map' || filter == 'tz_map') &&
!$tz_exception)
{
// no pseudo exception date
if ($expand_all)
{
$days[$remts]= $locts;
}
else
{
$days[$locts]= $locts;
}
}
}
do
{
$egw_rrule->next_no_exception();
$day = $egw_rrule->current();
if ($expand_all)
{
$remote_rrule->next_no_exception();
$remts = (int)egw_time::to($remote_rrule->current(),'server');
}
$exception = $egw_rrule->exceptions &&
in_array($day->format('Ymd'),$egw_rrule->exceptions);
if (in_array($filter, array('map','tz_map','rrule','tz_rrule'))
&& $exception)
{
// real exception
$locts = (int)egw_time::to($day,'ts');
if ($expand_all)
{
if ($remote)
{
$days[$locts]= $remts;
}
else
{
$days[$remts]= $locts;
}
}
else
{
$days[$locts]= $locts;
}
}
}
while ($exception);
}
return $days;
}
/**
* Checks for status only pseudo exceptions
*
* @param int $cal_id event id
* @param int $recur_date occurrence to check
* @param string $filter status filter criteria for user
*
* @return boolean true, if stati don't match with defaults
*/
function status_pseudo_exception($cal_id, $recur_date, $filter)
{
static $recurrence_zero;
static $cached_id;
static $user;
if (!isset($cached_id) || $cached_id != $cal_id)
{
// get default stati
$recurrence_zero = array();
$user = $GLOBALS['egw_info']['user']['account_id'];
$where = array('cal_id' => $cal_id,
'cal_recur_date' => 0);
foreach ($this->db->select($this->user_table,'cal_user_id,cal_user_type,cal_status',$where,
__LINE__,__FILE__,false,'','calendar') as $row)
{
switch ($row['cal_user_type'])
{
case 'u': // account
case 'c': // contact
case 'e': // email address
$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id']);
$recurrence_zero[$uid] = $row['cal_status'];
}
}
$cached_id = $cal_id;
}
$participants = $this->get_participants($event['id'], 0);
//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
// "($cal_id, $recur_date, $filter)[DEFAULTS]: " .
// array2string($recurrence_zero));
// Check if the stati for all participants are identical for all recurrences
foreach ($participants as $uid => $attendee)
$participants = array();
$where = array('cal_id' => $cal_id,
'cal_recur_date' => $recur_date);
foreach ($this->db->select($this->user_table,'cal_user_id,cal_user_type,cal_status',$where,
__LINE__,__FILE__,false,'','calendar') as $row)
{
switch ($attendee['type'])
switch ($row['cal_user_type'])
{
case 'u': // account
case 'c': // contact
case 'e': // email address
$recurrences = $this->get_recurrences($event['id'], $uid, $start, $end);
foreach ($recurrences as $recur_date => $recur_status)
{
if ($recur_date)
{
if (!empty($tz_id))
{
$time = new egw_time($recur_date, egw_time::$server_timezone);
$time->setTimezone(self::$tz_cache[$tz_id]);
$recur_start = $time->format('His');
//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
// "() first=$first_start <> current=$recur_start");
}
if ($attendee['type'] = 'u' &&
$attendee['id'] == $GLOBALS['egw_info']['user']['account_id'])
{
// handle filter for current user
switch ($filter)
{
case 'unknown':
if ($recur_status != 'U') continue;
break;
case 'accepted':
if ($recur_status != 'A') continue;
break;
case 'tentative':
if ($recur_status != 'T') continue;
break;
case 'rejected':
if ($recur_status != 'R') continue;
break;
case 'default':
if ($recur_status == 'R') continue;
break;
default:
// All entries
}
}
if (($filter != 'tz_transitions' && $recur_status != $recurrences[0])
|| !empty($tz_id) && $first_start != $recur_start)
{
// Every distinct status or starttime results in an exception
$days[] = $recur_date;
}
}
}
break;
default: // We don't handle the rest
break;
$uid = self::combine_user($row['cal_user_type'], $row['cal_user_id']);
$participants[$uid] = $row['cal_status'];
}
}
$days = array_unique($days);
sort($days);
return $days;
if (empty($participants)) return false; // occurrence does not exist at all yet
foreach ($recurrence_zero as $uid => $status)
{
if ($uid == $user)
{
// handle filter for current user
switch ($filter)
{
case 'unknown':
if ($status != 'U')
{
unset($participants[$uid]);
continue;
}
break;
case 'accepted':
if ($status != 'A')
{
unset($participants[$uid]);
continue;
}
break;
case 'tentative':
if ($status != 'T')
{
unset($participants[$uid]);
continue;
}
break;
case 'rejected':
if ($status != 'R')
{
unset($participants[$uid]);
continue;
}
break;
case 'default':
if ($status == 'R')
{
unset($participants[$uid]);
continue;
}
break;
default:
// All entries
}
}
if (!isset($participants[$uid])
|| $participants[$uid] != $status)
return true;
unset($participants[$uid]);
}
return (!empty($participants));
}
/**
* Check if the event is the whole day
*
* @param array $event event (all timestamps in servertime)
* @return boolean true if whole day event within its timezone, false othwerwise
*/
function isWholeDay($event)
{
if (!isset($event['start']) || !isset($event['end'])) return false;
if (empty($event['tzid']))
{
$timezone = egw_time::$server_timezone;
}
else
{
if (!isset(self::$tz_cache[$event['tzid']]))
{
self::$tz_cache[$event['tzid']] = calendar_timezones::DateTimeZone($event['tzid']);
}
$timezone = self::$tz_cache[$event['tzid']];
}
$start = new egw_time($event['start'],egw_time::$server_timezone);
$start->setTimezone($timezone);
$end = new egw_time($event['end'],egw_time::$server_timezone);
$end->setTimezone($timezone);
//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
// '(): ' . $start . '-' . $end);
$start = egw_time::to($start,'array');
$end = egw_time::to($end,'array');
return !$start['hour'] && !$start['minute'] && $end['hour'] == 23 && $end['minute'] == 59;
}
/**
* Moves a datetime to the beginning og the day within timezone
*
* @param egw_time &time the datetime entry
* @param string tz_id timezone
*
* @return DateTime
*/
function &startOfDay(egw_time $time, $tz_id)
{
if (empty($tz_id))
{
$timezone = egw_time::$server_timezone;
}
else
{
if (!isset(self::$tz_cache[$tz_id]))
{
self::$tz_cache[$tz_id] = calendar_timezones::DateTimeZone($tz_id);
}
$timezone = self::$tz_cache[$tz_id];
}
return new egw_time($time->format('Y-m-d 00:00:00'), $timezone);
}
}

View File

@ -277,7 +277,7 @@ class Horde_SyncML_State {
$this->setPassword($password);
}
$this->_isAuthorized = false;
$this->_isAuthorized = 0;
$this->_isAuthConfirmed = false;
}
@ -560,12 +560,12 @@ class Horde_SyncML_State {
if($GLOBALS['sessionid'] = $GLOBALS['egw']->session->create($this->_locName,$this->_password,'text','u'))
{
$this->_isAuthorized = true;
$this->_isAuthorized = 1;
#Horde::logMessage('SyncML_EGW: Authentication of ' . $this->_locName . '/' . $GLOBALS['sessionid'] . ' succeded' , __FILE__, __LINE__, PEAR_LOG_DEBUG);
}
else
{
$this->_isAuthorized = false;
$this->_isAuthorized = -1;
Horde::logMessage('SyncML: Authentication of ' . $this->_locName . ' failed' , __FILE__, __LINE__, PEAR_LOG_DEBUG);
}
}
@ -577,7 +577,7 @@ class Horde_SyncML_State {
Horde::logMessage('SyncML_EGW: egw session('.$sessionID. ') not verified ' , __FILE__, __LINE__, PEAR_LOG_DEBUG);
}
return $this->_isAuthorized;
return ($this->_isAuthorized > 0);
}
function isAuthConfirmed()

View File

@ -60,6 +60,12 @@ class EGW_SyncML_State extends Horde_SyncML_State
$ts = $GLOBALS['egw']->contenthistory->getTSforAction($_appName, $_id, $_action);
if (strstr($_id, ':')) {
// pseudo entries are related to parent entry
$parentId = array_shift(explode(':', $_id));
$pts = $GLOBALS['egw']->contenthistory->getTSforAction($_appName, $parentId, $_action);
if ($pts > $ts) $ts = $pts; // We have changed the parent
}
return $ts;
}
@ -336,18 +342,18 @@ class EGW_SyncML_State extends Horde_SyncML_State
if (($GLOBALS['sessionid'] = $GLOBALS['egw']->session->create($this->_locName,$this->_password,'text'))) {
if ($GLOBALS['egw_info']['user']['apps']['syncml']) {
$this->_isAuthorized = true;
$this->_isAuthorized = 1;
Horde::logMessage('SyncML_EGW: Authentication of ' . $this->_locName . '/' . $GLOBALS['sessionid'] . ' succeded',
__FILE__, __LINE__, PEAR_LOG_DEBUG);
} else {
$this->_isAuthorized = false;
$this->_isAuthorized = -1; // Authentication failed!
Horde::logMessage('SyncML is not enabled for user ' . $this->_locName,
__FILE__, __LINE__, PEAR_LOG_ERROR);
}
return $this->_isAuthorized;
return ($this->_isAuthorized > 0);
}
}
$this->_isAuthorized = false;
$this->_isAuthorized = -1;
Horde::logMessage('SyncML: Authentication of ' . $this->_locName . ' failed' ,
__FILE__, __LINE__, PEAR_LOG_INFO);
} else {
@ -359,7 +365,7 @@ class EGW_SyncML_State extends Horde_SyncML_State
__FILE__, __LINE__, PEAR_LOG_WARNING);
}
}
return $this->_isAuthorized;
return ($this->_isAuthorized > 0);
}
/**

View File

@ -89,6 +89,9 @@ class Horde_SyncML_Sync_RefreshFromServerSync extends Horde_SyncML_Sync_TwoWaySy
$contentType = $state->getPreferedContentTypeClient($this->_sourceLocURI, $this->_targetLocURI);
$c = $registry->call($hordeType . '/export', array('guid' => $guid, 'contentType' => $contentType));
if ($c === false) continue; // no content to export
if (is_a($c, 'PEAR_Error')) {
Horde::logMessage("SyncML: refresh failed to export guid $guid:\n" . print_r($c, true),
__FILE__, __LINE__, PEAR_LOG_WARNING);

View File

@ -96,6 +96,9 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync {
$contentType = $state->getPreferedContentTypeClient($this->_sourceLocURI, $this->_targetLocURI);
$c = $registry->call($hordeType . '/export', array('guid' => $guid, 'contentType' => $contentType));
if ($c === false) continue; // no content to export
if (is_a($c, 'PEAR_Error')) {
Horde::logMessage("SyncML: slowsync failed to export guid $guid:\n" . print_r($c, true),
__FILE__, __LINE__, PEAR_LOG_WARNING);
@ -235,7 +238,7 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync {
$guid = false;
$guid = $registry->call($hordeType . '/search',
array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType, $state->getGlobalUID($type, $syncItem->getLocURI()) ));
array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType, $state->getGlobalUID($type, $syncItem->getLocURI()), $type));
if ($guid) {
// Check if the found entry came from the client

View File

@ -135,6 +135,9 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync {
'guid' => $guid,
'contentType' => $contentType
));
if ($c === false) continue; // no content to export
if (is_a($c, 'PEAR_Error')) {
// Item in history but not in database. Strange, but can happen.
Horde :: logMessage("SyncML: change: export of guid $guid failed:\n" . print_r($c, true),
@ -343,13 +346,14 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync {
// Create an Add request for client.
$contentType = $state->getPreferedContentTypeClient($this->_sourceLocURI, $this->_targetLocURI);
$c = $registry->call($hordeType . '/export', array (
'guid' => $guid,
'contentType' => $contentType,
));
if ($c === false) continue; // no content to export
if (is_a($c, 'PEAR_Error')) {
// Item in history but not in database. Strange, but can happen.
Horde :: logMessage("SyncML: add: export of guid $guid failed:\n" . print_r($c, true),
@ -406,7 +410,7 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync {
function loadData() {
global $registry;
$state = & $_SESSION['SyncML.state'];
$state =& $_SESSION['SyncML.state'];
$syncType = $this->_targetLocURI;
$hordeType = $state->getHordeType($syncType);
$refts = $state->getServerAnchorLast($syncType);
@ -421,15 +425,29 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync {
$state->setAddedItems($syncType, $addedItems);
$state->setDeletedItems($syncType, $registry->call($hordeType . '/listBy', array (
$changedItems =& $state->getChangedItems($syncType);
$deletedItems =& $registry->call($hordeType . '/listBy', array (
'action' => 'delete',
'timestamp' => $refts,
'type' => $syncType,
'filter' => $this->_filterExpression
)));
));
foreach ($deletedItems as $guid)
{
if (strstr($guid, ':'))
{
$parentGUID = array_shift(explode(':', $guid));
if (!in_array($parentGUID, $changedItems))
{
$changedItems[] = $parentGUID;
}
}
}
$state->setDeletedItems($syncType, $deletedItems);
$this->_syncDataLoaded = TRUE;
$this->_syncDataLoaded = true;
return count($state->getChangedItems($syncType)) + count($state->getDeletedItems($syncType)) + count($state->getAddedItems($syncType)) + count($state->getConflictItems($syncType));
return count($changedItems) + count($deletedItems) + count($addedItems) + count($state->getConflictItems($syncType));
}
}

View File

@ -735,9 +735,9 @@ class Horde_iCalendar {
foreach ($values[1] as $value) {
if ((isset($params['VALUE'])
&& $params['VALUE'] == 'DATE') || (!isset($params['VALUE']) && $isDate)) {
$dates[] = $this->_parseDate($value);
$dates[] = $this->_parseDate(trim($value));
} else {
$dates[] = $this->_parseDateTime($value, $tzid);
$dates[] = $this->_parseDateTime(trim($value), $tzid);
}
}
$this->setAttribute($tag, isset($dates[0]) ? $dates[0] : null, $params, true, $dates);
@ -939,14 +939,54 @@ class Horde_iCalendar {
case 'DCREATED':
case 'LAST-MODIFIED':
$value = $this->_exportDateTime($value);
break;
// Support additional fields after date.
case 'AALARM':
case 'DALARM':
if (isset($params['VALUE'])) {
if ($params['VALUE'] == 'DATE') {
// VCALENDAR 1.0 uses T000000 - T235959 for all day events:
if ($this->isOldFormat() && $name == 'DTEND') {
$d = new Horde_Date($value);
$value = new Horde_Date(array(
'year' => $d->year,
'month' => $d->month,
'mday' => $d->mday - 1));
$value->correct();
$value = $this->_exportDate($value, '235959');
} else {
$value = $this->_exportDate($value, '000000');
}
} else {
$value = $this->_exportDateTime($value);
}
} else {
$value = $this->_exportDateTime($value);
}
if (is_array($attribute['values']) &&
count($attribute['values']) > 0) {
$values = $attribute['values'];
if ($this->isOldFormat()) {
$values = str_replace(';', '\\;', $values);
} else {
// As of rfc 2426 2.5 semicolon and comma must be
// escaped.
$values = str_replace(array('\\', ';', ','),
array('\\\\', '\\;', '\\,'),
$values);
}
$value .= ';' . implode(';', $values);
}
break;
case 'DTEND':
case 'DTSTART':
case 'DTSTAMP':
case 'DUE':
case 'AALARM':
case 'DALARM':
case 'RECURRENCE-ID':
case 'X-RECURRENCE-ID':
if (isset($params['VALUE'])) {