From 894dfc127cee3062ffa001947dc38eb41f4c3ccf Mon Sep 17 00:00:00 2001 From: Patrick Bihan-Faou Date: Thu, 27 Mar 2008 08:31:17 +0000 Subject: [PATCH] Add support for vcalendar 2.0 valarm elements tracker #1480, thanks for the patch --- calendar/inc/class.boical.inc.php | 98 +++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 4 deletions(-) diff --git a/calendar/inc/class.boical.inc.php b/calendar/inc/class.boical.inc.php index 4217e951a4..b88bf305dd 100644 --- a/calendar/inc/class.boical.inc.php +++ b/calendar/inc/class.boical.inc.php @@ -386,10 +386,47 @@ foreach($event['alarm'] as $alarmID => $alarmData) { - $attributes['DALARM'] = $vcal->_exportDateTime($alarmData['time']); - $attributes['AALARM'] = $vcal->_exportDateTime($alarmData['time']); - // lets take only the first alarm - break; + if ($version == '1.0') + { + $attributes['DALARM'] = $vcal->_exportDateTime($alarmData['time']); + $attributes['AALARM'] = $vcal->_exportDateTime($alarmData['time']); + // lets take only the first alarm + break; + } + else + { + // VCalendar 2.0 / RFC 2445 + + // skip over alarms that don't have the minimum required info + if (!$alarmData['offset'] && !$alarmData['time']) + { + error_log("Couldn't add VALARM (no alarm time info)"); + continue; + } + + // RFC requires DESCRIPTION for DISPLAY + if (!$event['title'] && !$event['description']) + { + error_log("Couldn't add VALARM (no description)"); + continue; + } + + $valarm = Horde_iCalendar::newComponent('VALARM',$vevent); + if ($alarmData['offset']) + { + $valarm->setAttribute('TRIGGER', -$alarmData['offset'], + array('VALUE' => 'DURATION', 'RELATED' => 'START')); + } + else + { + $valarm->setAttribute('TRIGGER', $alarmData['time'], + array('VALUE' => 'DATE-TIME')); + } + + $valarm->setAttribute('ACTION','DISPLAY'); + $valarm->setAttribute('DESCRIPTION',$event['title'] ? $event['title'] : $event['description']); + $vevent->addComponent($valarm); + } } $attributes['UID'] = $eventGUID; @@ -868,6 +905,14 @@ $eventID =& $Ok; // handle the alarms + foreach ($component->getComponents() as $valarm) + { + if (is_a($valarm, 'Horde_iCalendar_valarm')) + { + $this->valarm2egw($alarms,$valarm); + } + } + if(count($alarms) > 0 || (isset($this->supportedFields['alarms']) && count($alarms) == 0)) { // delete the old alarms @@ -890,6 +935,51 @@ return $Ok; } + function valarm2egw(&$alarms, &$valarm) + { + $count = 0; + foreach($valarm->_attributes as $vattr) + { + switch($vattr['name']) + { + case 'TRIGGER': + $vtype = (isset($vattr['params']['VALUE'])) + ? $vattr['params']['VALUE'] : 'DURATION'; //default type + switch ($vtype) + { + case 'DURATION': + if (isset($vattr['params']['RELATED']) + && $vattr['params']['RELATED'] != 'START') + { + error_log("Unsupported VALARM offset anchor ".$vattr['params']['RELATED']); + } + else + { + $alarms[] = array('offset' => -$vattr['value']); + $count++; + } + break; + case 'DATE-TIME': + $alarms[] = array('time' => $vattr['value']); + $count++; + break; + default: + // we should also do ;RELATED=START|END + error_log('VALARM/TRIGGER: unsupported value type:' . $vtype); + } + break; + // case 'ACTION': + // break; + // case 'DISPLAY': + // break; + + default: + error_log('VALARM field:' .$vattr['name'] .':' . print_r($vattrval,true) . ' HAS NO CONVERSION YET'); + } + } + return $count; + } + function setSupportedFields($_productManufacturer='file', $_productName='') { // save them vor later use