From 22bb23b8ff922ae99a1d00eb00809956e9ea5fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Lehrke?= Date: Fri, 23 Apr 2010 13:52:45 +0000 Subject: [PATCH] Fix new all-day event handling --- calendar/inc/class.calendar_bo.inc.php | 6 +- calendar/inc/class.calendar_boupdate.inc.php | 3 +- calendar/inc/class.calendar_ical.inc.php | 64 ++++++++++---------- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/calendar/inc/class.calendar_bo.inc.php b/calendar/inc/class.calendar_bo.inc.php index e81296f260..35a3fdbb90 100644 --- a/calendar/inc/class.calendar_bo.inc.php +++ b/calendar/inc/class.calendar_bo.inc.php @@ -715,15 +715,15 @@ class calendar_bo function db2data(&$events,$date_format='ts') { if (!is_array($events)) echo "

bocal::db2data(\$events,$date_format) \$events is no array
\n".function_backtrace()."

\n"; - foreach($events as &$event) + foreach ($events as &$event) { // convert timezone id of event to tzid (iCal id like 'Europe/Berlin') if (!$event['tz_id'] || !($event['tzid'] = calendar_timezones::id2tz($event['tz_id']))) { $event['tzid'] = egw_time::$server_timezone->getName(); } - if (($event['whole_day'] = $this->so->isWholeDay($event)) && - $date_format != 'server') + $event['whole_day'] = $this->isWholeDay($event); + if ($event['whole_day'] && $date_format != 'server') { // Adjust dates to user TZ $time = new egw_time($event['start'], egw_time::$server_timezone); diff --git a/calendar/inc/class.calendar_boupdate.inc.php b/calendar/inc/class.calendar_boupdate.inc.php index dea1532ded..04bebd3898 100644 --- a/calendar/inc/class.calendar_boupdate.inc.php +++ b/calendar/inc/class.calendar_boupdate.inc.php @@ -852,7 +852,8 @@ class calendar_boupdate extends calendar_bo } $save_event = $event; - if (!isset($event['whole_day']) && ($event['whole_day'] = $this->isWholeDay($event))) + if (!isset($event['whole_day'])) $event['whole_day'] = $this->isWholeDay($event); + if ($event['whole_day']) { $time = new egw_time($event['start'], egw_time::$user_timezone); $time =& $this->so->startOfDay($time); diff --git a/calendar/inc/class.calendar_ical.inc.php b/calendar/inc/class.calendar_ical.inc.php index 1d51c1554f..345e7a1c35 100644 --- a/calendar/inc/class.calendar_ical.inc.php +++ b/calendar/inc/class.calendar_ical.inc.php @@ -568,16 +568,20 @@ class calendar_ical extends calendar_boupdate break; case 'DTSTART': - if (!isset($event['whole_day'])) + if (empty($event['whole_day'])) { $attributes['DTSTART'] = self::getDateTime($event['start'],$tzid,$parameters['DTSTART']); } break; case 'DTEND': - // write start + end of whole day events as dates - if (isset($event['whole_day'])) + if (empty($event['whole_day'])) { + $attributes['DTEND'] = self::getDateTime($event['end'],$tzid,$parameters['DTEND']); + } + else + { + // write start + end of whole day events as dates $event['end-nextday'] = $event['end'] + 12*3600; // we need the date of the next day, as DTEND is non-inclusive (= exclusive) in rfc2445 foreach (array('start' => 'DTSTART','end-nextday' => 'DTEND') as $f => $t) { @@ -588,10 +592,6 @@ class calendar_ical extends calendar_boupdate } unset($attributes['DTSTART']); } - else - { - $attributes['DTEND'] = self::getDateTime($event['end'],$tzid,$parameters['DTEND']); - } break; case 'RRULE': @@ -613,9 +613,17 @@ class calendar_ical extends calendar_boupdate if ($event['recur_type'] == MCAL_RECUR_NONE) break; if (!empty($event['recur_exception'])) { - // use 'DATE' instead of 'DATE-TIME' on whole day events - if (isset($event['whole_day'])) + if (empty($event['whole_day'])) { + $value_type = 'DATE-TIME'; + foreach ($event['recur_exception'] as $key => $timestamp) + { + $event['recur_exception'][$key] = self::getDateTime($timestamp,$tzid,$parameters['EXDATE']); + } + } + else + { + // use 'DATE' instead of 'DATE-TIME' on whole day events $value_type = 'DATE'; foreach ($event['recur_exception'] as $id => $timestamp) { @@ -630,14 +638,7 @@ class calendar_ical extends calendar_boupdate } $event['recur_exception'] = $days; } - else - { - $value_type = 'DATE-TIME'; - foreach ($event['recur_exception'] as $key => $timestamp) - { - $event['recur_exception'][$key] = self::getDateTime($timestamp,$tzid,$parameters['EXDATE']); - } - } + $attributes['EXDATE'] = ''; $values['EXDATE'] = $event['recur_exception']; $parameters['EXDATE']['VALUE'] = $value_type; @@ -694,7 +695,11 @@ class calendar_ical extends calendar_boupdate if ($recur_date) { // We handle a pseudo exception - if (isset($event['whole_day'])) + if (empty($event['whole_day'])) + { + $attributes[$icalFieldName] = self::getDateTime($recur_date,$tzid,$parameters[$icalFieldName]); + } + else { $time = new egw_time($recur_date,egw_time::$server_timezone); $time->setTimezone(self::$tz_cache[$event['tzid']]); @@ -706,17 +711,17 @@ class calendar_ical extends calendar_boupdate array('VALUE' => 'DATE') ); } - else - { - $attributes[$icalFieldName] = self::getDateTime($recur_date,$tzid,$parameters[$icalFieldName]); - } } elseif ($event['recurrence'] && $event['reference']) { // $event['reference'] is a calendar_id, not a timestamp if (!($revent = $this->read($event['reference']))) break; // referenced event does not exist - if (isset($revent['whole_day'])) + if (empty($revent['whole_day'])) + { + $attributes[$icalFieldName] = self::getDateTime($event['recurrence'],$tzid,$parameters[$icalFieldName]); + } + else { $time = new egw_time($event['recurrence'],egw_time::$server_timezone); $time->setTimezone(self::$tz_cache[$event['tzid']]); @@ -728,10 +733,7 @@ class calendar_ical extends calendar_boupdate array('VALUE' => 'DATE') ); } - else - { - $attributes[$icalFieldName] = self::getDateTime($event['recurrence'],$tzid,$parameters[$icalFieldName]); - } + unset($revent); } break; @@ -859,7 +861,7 @@ class calendar_ical extends calendar_boupdate // RFC requires DESCRIPTION for DISPLAY if (!$event['title'] && !$description) continue; - if (isset($event['whole_day']) && $alarmData['offset']) + if (!empty($event['whole_day']) && $alarmData['offset']) { $alarmData['time'] = $event['start'] - $alarmData['offset']; $alarmData['offset'] = false; @@ -1205,7 +1207,7 @@ class calendar_ical extends calendar_boupdate } } - if ($event['whole_day'] && $event['tzid'] != $event_info['stored_event']['tzid']) + if (!empty($event['whole_day']) && $event['tzid'] != $event_info['stored_event']['tzid']) { // Adjust dates to original TZ $time = new egw_time($event['start'],egw_time::$server_timezone); @@ -1224,7 +1226,7 @@ class calendar_ical extends calendar_boupdate $event['recur_exception'][$key] = egw_time::to($time,'server'); } } - elseif($event['recurrence']) + elseif ($event['recurrence']) { $time = new egw_time($event['recurrence'],egw_time::$server_timezone); $time =& $this->so->startOfDay($time, $event_info['stored_event']['tzid']); @@ -1244,7 +1246,7 @@ class calendar_ical extends calendar_boupdate { unset($event['id']); // set non blocking all day depending on the user setting - if (isset($event['whole_day']) && $this->nonBlockingAllday) + if (!empty($event['whole_day']) && $this->nonBlockingAllday) { $event['non_blocking'] = 1; }