mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-14 09:58:16 +01:00
- added recurrence information to calendar events (GetMessage)
- added timezone export (currently disabled) --> both needs testing and will probably not just work
This commit is contained in:
parent
f9163f2747
commit
0ff32d804a
@ -187,6 +187,10 @@ class calendar_activesync implements activesync_plugin_read
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$message = new SyncAppointment();
|
$message = new SyncAppointment();
|
||||||
|
|
||||||
|
// set timezones (Todo: timestamps have to be in that timezone)
|
||||||
|
//$message->timezone = base64_encode(self::_getSyncBlobFromTZ(self::tz2as($event['tzid'])));
|
||||||
|
|
||||||
// copying timestamps
|
// copying timestamps
|
||||||
foreach(array(
|
foreach(array(
|
||||||
'start' => 'starttime',
|
'start' => 'starttime',
|
||||||
@ -208,7 +212,6 @@ class calendar_activesync implements activesync_plugin_read
|
|||||||
}
|
}
|
||||||
$message->organizername = $GLOBALS['egw']->accounts->id2name($event['owner'],'account_fullname');
|
$message->organizername = $GLOBALS['egw']->accounts->id2name($event['owner'],'account_fullname');
|
||||||
$message->organizeremail = $GLOBALS['egw']->accounts->id2name($event['owner'],'account_email');
|
$message->organizeremail = $GLOBALS['egw']->accounts->id2name($event['owner'],'account_email');
|
||||||
$message->location;
|
|
||||||
|
|
||||||
$message->sensitivity = $event['public'] ? 0 : 2; // 0=normal, 1=personal, 2=private, 3=confidential
|
$message->sensitivity = $event['public'] ? 0 : 2; // 0=normal, 1=personal, 2=private, 3=confidential
|
||||||
$message->alldayevent = (int)$this->calendar->isWholeDay($event);
|
$message->alldayevent = (int)$this->calendar->isWholeDay($event);
|
||||||
@ -232,12 +235,30 @@ class calendar_activesync implements activesync_plugin_read
|
|||||||
);
|
);
|
||||||
calendar_so::split_status($status, $quantity, $role);
|
calendar_so::split_status($status, $quantity, $role);
|
||||||
$attendee = new SyncAttendee();
|
$attendee = new SyncAttendee();
|
||||||
|
$attendee->status = (int)$status2as[$status];
|
||||||
|
$attendee->type = (int)$role2as[$role];
|
||||||
if (is_numeric($uid))
|
if (is_numeric($uid))
|
||||||
{
|
{
|
||||||
$attendee->name = $GLOBALS['egw']->accounts->id2name($uid,'account_fullname');
|
$attendee->name = $GLOBALS['egw']->accounts->id2name($uid,'account_fullname');
|
||||||
$attendee->email = $GLOBALS['egw']->accounts->id2name($uid,'account_email');
|
$attendee->email = $GLOBALS['egw']->accounts->id2name($uid,'account_email');
|
||||||
$attendee->status = (int)$status2as[$status];
|
}
|
||||||
$attendee->type = (int)$role2as[$role];
|
else
|
||||||
|
{
|
||||||
|
// ToDo: ressources, eg. contacts
|
||||||
|
continue;
|
||||||
|
|
||||||
|
list($info) = $this->calendar->resources[$uid[0]]['info'] ?
|
||||||
|
ExecMethod($this->resources[$uid[0]]['info'],substr($uid,1)) : array(false);
|
||||||
|
if ($info)
|
||||||
|
{
|
||||||
|
if (!$info['email'] && $info['responsible'])
|
||||||
|
{
|
||||||
|
$info['email'] = $GLOBALS['egw']->accounts->id2name($info['responsible'],'account_email');
|
||||||
|
}
|
||||||
|
$attendee->name = empty($info['cn']) ? $info['name'] : $info['cn'];
|
||||||
|
$attendee->email = $info['email'];
|
||||||
|
if ($uid[0] == 'r') $attendee->type = 3; // 3 = resource
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$message->attendees[] = $attendee;
|
$message->attendees[] = $attendee;
|
||||||
}
|
}
|
||||||
@ -246,13 +267,57 @@ class calendar_activesync implements activesync_plugin_read
|
|||||||
{
|
{
|
||||||
$message->categories[] = categories::id2name($cat_id);
|
$message->categories[] = categories::id2name($cat_id);
|
||||||
}
|
}
|
||||||
//$message->recurrence; // SYNC RECURRENCE;
|
|
||||||
|
// recurring information
|
||||||
|
if ($event['recur_type'] != RECUR_NONE)
|
||||||
|
{
|
||||||
|
$message->recurrence = $recurrence = new SyncRecurrence();
|
||||||
|
$rrule = calendar_rrule::event2rrule($event);
|
||||||
|
static $recur_type2as = array(
|
||||||
|
calendar_rrule::DAILY => 0,
|
||||||
|
calendar_rrule::WEEKLY => 1,
|
||||||
|
calendar_rrule::MONTHLY_MDAY => 2, // monthly
|
||||||
|
calendar_rrule::MONTHLY_WDAY => 3, // monthly on nth day
|
||||||
|
calendar_rrule::YEARLY => 5,
|
||||||
|
// 6 = yearly on nth day
|
||||||
|
);
|
||||||
|
$recurrence->type = (int)$recur_type2as[$rrule->type];
|
||||||
|
$recurrence->interval = $rrule->interval;
|
||||||
|
switch ($rrule->type)
|
||||||
|
{
|
||||||
|
case calendar_rrule::MONTHLY_WDAY:
|
||||||
|
$recurrence->weekofmonth = $rrule->monthly_byday_num >= 1 ?
|
||||||
|
$rrule->monthly_byday_num : 5; // 1..5=last week of month, not -1
|
||||||
|
// fall throught
|
||||||
|
case calendar_rrule::WEEKLY:
|
||||||
|
$recurrence->dayofweek = $rrule->weekdays; // 1=Su, 2=Mo, 4=Tu, .., 64=Sa
|
||||||
|
break;
|
||||||
|
case calendar_rrule::MONTHLY_MDAY:
|
||||||
|
$recurrence->dayofmonth = $rrule->monthly_bymonthday >= 1 ? // 1..31
|
||||||
|
$rrule->monthly_bymonthday : 31; // not -1 for last day of month!
|
||||||
|
break;
|
||||||
|
case calendar_rrule::YEARLY:
|
||||||
|
$recurrence->dayofmonth = (int)$rrule->time->format('d'); // 1..31
|
||||||
|
$recurrence->monthofyear = (int)$rrule->time->format('m'); // 1..12
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ($rrule->enddate) $recurrence->until = $rrule->enddate->format('ts'); // Timezone?
|
||||||
|
|
||||||
|
if ($rrule->exceptions)
|
||||||
|
{
|
||||||
|
$message->exceptions = array();
|
||||||
|
foreach($rrule->exceptions as $exception_time)
|
||||||
|
{
|
||||||
|
$exception = new SyncAppointment(); // exceptions seems to be full SyncAppointments, with only starttime required
|
||||||
|
$exception->starttime = $exception_time->format('ts'); // Timezone?
|
||||||
|
$message->exceptions[] = $exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
//$message->busystatus;
|
//$message->busystatus;
|
||||||
//$message->reminder;
|
//$message->reminder;
|
||||||
//$message->meetingstatus;
|
//$message->meetingstatus;
|
||||||
//$message->exceptions; // SYNC APPOINTMENTS;
|
|
||||||
//$message->deleted;
|
//$message->deleted;
|
||||||
//$message->exceptionstarttime;
|
|
||||||
/*
|
/*
|
||||||
if (isset($protocolversion) && $protocolversion < 12.0) {
|
if (isset($protocolversion) && $protocolversion < 12.0) {
|
||||||
$message->body;
|
$message->body;
|
||||||
@ -295,7 +360,7 @@ class calendar_activesync implements activesync_plugin_read
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
list(,,$etag) = explode(':',$etag);
|
//list(,,$etag) = explode(':',$etag);
|
||||||
$stat = array(
|
$stat = array(
|
||||||
'mod' => $etag,
|
'mod' => $etag,
|
||||||
'id' => is_array($id) ? $id['id'] : $id,
|
'id' => is_array($id) ? $id['id'] : $id,
|
||||||
@ -336,4 +401,144 @@ list(,,$etag) = explode(':',$etag);
|
|||||||
//error_log(__METHOD__."('$folderid','$syncstate_was') syncstate='$syncstate' returning ".array2string($changes));
|
//error_log(__METHOD__."('$folderid','$syncstate_was') syncstate='$syncstate' returning ".array2string($changes));
|
||||||
return $changes;
|
return $changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return AS timezone data from given timezone and time
|
||||||
|
*
|
||||||
|
* AS spezifies the timezone by the date it changes to dst and back and the offsets.
|
||||||
|
* Unfortunately this data is not available from PHP's DateTime(Zone) class.
|
||||||
|
* Just given the exact time of the next transition, which is available via DateTimeZone::getTransistions(),
|
||||||
|
* will fail for recurring events longer then a year, as the transition date/time changes!
|
||||||
|
*
|
||||||
|
* We could use the RRule given in the iCal timezone defintion available via calendar_timezones::tz2id($tz,'component').
|
||||||
|
*
|
||||||
|
* Not every timezone uses DST, in which case only bias matters and dstbias=0
|
||||||
|
* (probably all other values should be 0, as MapiMapping::_getGMTTZ() in backend/ics.php does it).
|
||||||
|
*
|
||||||
|
* @param string|DateTimeZone $tz
|
||||||
|
* @param int|string|DateTime $ts=null time for which active sync timezone data is requested, default current time
|
||||||
|
* @return array with values for keys:
|
||||||
|
* - "bias": timezone offset from UTC in minutes for NO DST
|
||||||
|
* - "dstendmonth", "dstendday", "dstendweek", "dstendhour", "dstendminute", "dstendsecond", "dstendmillis"
|
||||||
|
* - "stdbias": seems not to be used
|
||||||
|
* - "dststartmonth", "dststartday", "dststartweek", "dststarthour", "dststartminute", "dststartsecond", "dststartmillis"
|
||||||
|
* - "dstbias": offset in minutes for no DST --> DST, usually 1
|
||||||
|
*
|
||||||
|
* @link http://download.microsoft.com/download/5/D/D/5DD33FDF-91F5-496D-9884-0A0B0EE698BB/%5BMS-ASDTYPE%5D.pdf
|
||||||
|
*/
|
||||||
|
function tz2as($tz,$ts=null)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
BEGIN:VTIMEZONE
|
||||||
|
TZID:Europe/Berlin
|
||||||
|
X-LIC-LOCATION:Europe/Berlin
|
||||||
|
BEGIN:DAYLIGHT
|
||||||
|
TZOFFSETFROM:+0100
|
||||||
|
--> bias: 60 min
|
||||||
|
TZOFFSETTO:+0200
|
||||||
|
--> dstbias: +0200 - +0100 = +0100 = 60 min
|
||||||
|
TZNAME:CEST
|
||||||
|
DTSTART:19700329T020000
|
||||||
|
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
|
||||||
|
--> dststart: month: 3, day: SU(0???), week: 5, hour: 2, minute, second, millis: 0
|
||||||
|
END:DAYLIGHT
|
||||||
|
BEGIN:STANDARD
|
||||||
|
TZOFFSETFROM:+0200
|
||||||
|
TZOFFSETTO:+0100
|
||||||
|
TZNAME:CET
|
||||||
|
DTSTART:19701025T030000
|
||||||
|
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
|
||||||
|
--> dstend: month: 10, day: SU(0???), week: -1|5, hour: 3, minute, second, millis: 0
|
||||||
|
END:STANDARD
|
||||||
|
END:VTIMEZONE
|
||||||
|
*/
|
||||||
|
$data = array(
|
||||||
|
'bias' => 0,
|
||||||
|
'stdbias' => 0,
|
||||||
|
'dstbias' => 0,
|
||||||
|
'dststartmonth' => 0, 'dststartday' => 0, 'dststartweek' => 0,
|
||||||
|
'dststarthour' => 0, 'dststartminute' => 0, 'dststartsecond' => 0, 'dststartmillis' => 0,
|
||||||
|
'dstendmonth' => 0, 'dstendday' => 0, 'dstendweek' => 0,
|
||||||
|
'dstendhour' => 0, 'dstendminute' => 0, 'dstendsecond' => 0, 'dstendmillis' => 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
$name = is_a($tz,'DateTimeZone') ? $tz->getName() : $tz;
|
||||||
|
$component = calendar_timezones::tz2id($name,'component');
|
||||||
|
|
||||||
|
if (!preg_match("/BEGIN:STANDARD\nTZOFFSETFROM:([+-]?\d{4})\nTZOFFSETTO:([+-]?\d{4})\n(.*)\nEND:STANDARD\n/m",$component,$matches))
|
||||||
|
{
|
||||||
|
throw new egw_exception_assertion_failed("NO standard component for '$name' in '$component'!");
|
||||||
|
}
|
||||||
|
// get bias and dstbias, should be present in all tz
|
||||||
|
$data['bias'] = 60 * substr($matches[2],0,-2) + substr($matches[2],-2); // TZOFFSETTO
|
||||||
|
$data['dstbias'] = 60 * substr($matches[1],0,-2) + substr($matches[1],-2); // TZOFFSETFROM
|
||||||
|
|
||||||
|
// check if we have a RRULE and a BEGIN:DAYLIGHT component
|
||||||
|
if (($end=$matches[3]) &&
|
||||||
|
preg_match("/BEGIN:DAYLIGHT\nTZOFFSETFROM:([+-]?\d{4})\nTZOFFSETTO:([+-]?\d{4})\n(.*)\nEND:DAYLIGHT\n/m",$component,$matches))
|
||||||
|
{
|
||||||
|
foreach(array('dststart' => $matches[3],'dstend' => $end) as $prefix => $comp)
|
||||||
|
{
|
||||||
|
if (pregmatch('/RRULE:FREQ=YEARLY;BYDAY=(.*);BYMONTH=(\d+)/',$comp,$matches))
|
||||||
|
{
|
||||||
|
$data[$prefix.'month'] = (int)$matches[2];
|
||||||
|
$data[$prefix.'week'] = (int)$matches[1];
|
||||||
|
static $day2int = array('SU'=>0,'MO'=>1,'TU'=>2,'WE'=>3,'TH'=>4,'FR'=>5,'SA'=>6);
|
||||||
|
$data[$prefix.'day'] = (int)$day2int[substr($matches[1],-2)];
|
||||||
|
}
|
||||||
|
if (pregmatch('/DTSTART:\d{8}T(\d{6})/',$comp,$matches))
|
||||||
|
{
|
||||||
|
$data[$prefix.'hour'] = (int)substr($matches[1],0,2);
|
||||||
|
$data[$prefix.'minute'] = (int)substr($matches[1],2,2);
|
||||||
|
$data[$prefix.'second'] = (int)substr($matches[1],4,2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
error_log(__METHOD__."('$name') returning ".array2string($data));
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get timezone from AS timezone data
|
||||||
|
*
|
||||||
|
* Here we can only loop through all available timezones (possibly starting with the users timezone) and
|
||||||
|
* try to find a timezone matching the change data and offsets specified in $data.
|
||||||
|
* This conversation is not unique, as multiple timezones can match the given data or none!
|
||||||
|
*
|
||||||
|
* Maybe returning the users timezone, if no match found makes more sense.
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return string|boolean timezone name, eg. "Europe/Berlin" or false if no matching timezone found
|
||||||
|
*/
|
||||||
|
function as2tz(array $data)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unpack timezone info from Sync
|
||||||
|
*
|
||||||
|
* copied from backend/ics.php
|
||||||
|
*/
|
||||||
|
static private function _getTZFromSyncBlob($data) {
|
||||||
|
$tz = unpack( "lbias/a64name/vdstendyear/vdstendmonth/vdstendday/vdstendweek/vdstendhour/vdstendminute/vdstendsecond/vdstendmillis/" .
|
||||||
|
"lstdbias/a64name/vdststartyear/vdststartmonth/vdststartday/vdststartweek/vdststarthour/vdststartminute/vdststartsecond/vdststartmillis/" .
|
||||||
|
"ldstbias", $data);
|
||||||
|
|
||||||
|
return $tz;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pack timezone info for Sync
|
||||||
|
*
|
||||||
|
* copied from backend/ics.php
|
||||||
|
*/
|
||||||
|
static private function _getSyncBlobFromTZ($tz) {
|
||||||
|
$packed = pack("la64vvvvvvvv" . "la64vvvvvvvv" . "l",
|
||||||
|
$tz["bias"], "", 0, $tz["dstendmonth"], $tz["dstendday"], $tz["dstendweek"], $tz["dstendhour"], $tz["dstendminute"], $tz["dstendsecond"], $tz["dstendmillis"],
|
||||||
|
$tz["stdbias"], "", 0, $tz["dststartmonth"], $tz["dststartday"], $tz["dststartweek"], $tz["dststarthour"], $tz["dststartminute"], $tz["dststartsecond"], $tz["dststartmillis"],
|
||||||
|
$tz["dstbias"]);
|
||||||
|
|
||||||
|
return $packed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user