public function sif2vevent($sif)
{
$a = Horde_SyncMl_Device_sync4j::sif2array($sif);
$iCal = new Horde_Icalendar();
$iCal->setAttribute('PRODID', '-//The Horde Project//SyncML//EN');
$iCal->setAttribute('METHOD', 'PUBLISH');
$vEvent = Horde_Icalendar::newComponent('vevent', $iCal);
$vEvent->setAttribute('DTSTAMP', time());
$map = array('Subject' => 'SUMMARY', 'Body' => 'DESCRIPTION', 'Categories' => 'CATEGORIES', 'Location' => 'LOCATION');
foreach ($map as $source => $target) {
if (!empty($a[$source])) {
$vEvent->setAttribute($target, $a[$source]);
}
}
if ($a['AllDayEvent'] == 1) {
// Not exactly correct, we ignore the start and end time of
// all-day events and simple assume that the client had set them
// correctly to 0:00.
$startTime = $iCal->_parseDateTime($a['Start']);
$vEvent->setAttribute('DTSTART', array('year' => date('Y', $startTime), 'month' => date('m', $startTime), 'mday' => date('d', $startTime)), array('VALUE' => 'DATE'));
$t = $iCal->_parseDateTime($a['End']);
$d = new Horde_Date(array('year' => date('Y', $t), 'month' => date('m', $t), 'mday' => date('d', $t) + 1));
$vEvent->setAttribute('DTEND', $d, array('VALUE' => 'DATE'));
} else {
$startTime = $iCal->_parseDateTime($a['Start']);
$vEvent->setAttribute('DTSTART', $startTime);
$vEvent->setAttribute('DTEND', $iCal->_parseDateTime($a['End']));
}
if (isset($a['IsRecurring']) && $a['IsRecurring'] == 1) {
$interval = '';
switch ($a['RecurrenceType']) {
case 0:
/* olDaily */
if (!empty($a['DayOfWeekMask'])) {
$freq = 'WEEKLY';
$interval = ';INTERVAL=1';
} else {
$freq = 'DAILY';
$interval = ';INTERVAL=' . $a['Interval'];
}
break;
case 1:
/* olWeekly */
$freq = 'WEEKLY';
$interval = ';INTERVAL=' . $a['Interval'];
break;
case 2:
/* olMonthly */
$freq = 'MONTHLY';
$interval = ';INTERVAL=' . $a['Interval'];
break;
case 3:
/* olMonthNth */
$freq = 'MONTHLY';
$interval = ';INTERVAL=' . $a['Interval'];
break;
case 5:
/* olYearly */
$freq = 'YEARLY';
$interval = ';INTERVAL=' . $a['Interval'];
break;
case 6:
/* olYearNth */
$freq = 'YEARLY';
$interval = ';INTERVAL=' . $a['Interval'];
break;
}
$rrule = 'FREQ=' . $freq;
if (isset($a['Occurrences'])) {
$rrule .= ';COUNT=' . $a['Occurrences'];
} elseif (!isset($a['NoEndDate']) || $a['NoEndDate'] != 1) {
$rrule .= ';UNTIL=' . $a['PatternEndDate'];
}
$rrule .= $interval;
if (!empty($a['DayOfMonth'])) {
$rrule .= ';BYMONTHDAY=' . $a['DayOfMonth'];
}
if (!empty($a['MonthOfYear'])) {
$rrule .= ';BYMONTH=' . $a['MonthOfYear'];
}
if (!empty($a['DayOfWeekMask'])) {
$rrule .= ';BYDAY=';
$icaldays = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
for ($i = $flag = 0; $i <= 7; ++$i) {
if (pow(2, $i) & $a['DayOfWeekMask']) {
if ($flag) {
$rrule .= ',';
}
$rrule .= $icaldays[$i];
$flag = true;
}
}
}
$vEvent->setAttribute('RRULE', $rrule);
}
if (isset($a['ExcludeDate'])) {
$dates = array();
if (!is_array($a['ExcludeDate'])) {
$dates[] = $a['AllDayEvent'] == 1 ? $iCal->_parseDate($a['ExcludeDate']) : $iCal->_parseDateTime($a['ExcludeDate']);
} else {
foreach ($a['ExcludeDate'] as $date) {
$dates[] = $a['AllDayEvent'] == 1 ? $iCal->_parseDate($date) : $iCal->_parseDateTime($date);
}
}
if ($a['AllDayEvent'] == 1) {
$vEvent->setAttribute('EXDATE', $dates, array('VALUE' => 'DATE'));
} else {
$vEvent->setAttribute('EXDATE', $dates);
}
}
if (isset($a['ReminderSet']) && $a['ReminderSet'] == 1) {
$vEvent->setAttribute('AALARM', $startTime - $a['ReminderMinutesBeforeStart'] * 60);
}
if (isset($a['BusyStatus'])) {
switch ($a['BusyStatus']) {
case 0:
/* olFree - FREE is not a iCalendar standard value. */
$vEvent->setAttribute('STATUS', 'FREE');
break;
case 1:
/* olTentative */
$vEvent->setAttribute('STATUS', 'TENTATIVE');
break;
case 2:
/* olBusy */
/* olBusy */
case 3:
/* olOutOfOffice */
$vEvent->setAttribute('STATUS', 'CONFIRMED');
break;
}
}
if (isset($a['Sensitivity'])) {
switch ($a['Sensitivity']) {
case 0:
/* olNormal - FREE is not a iCalendar standard value. */
$vEvent->setAttribute('CLASS', 'PUBLIC');
break;
case 1:
/* olPersonal */
/* olPersonal */
case 2:
/* olPrivate */
$vEvent->setAttribute('CLASS', 'PRIVATE');
break;
case 3:
/* olConfidential */
$vEvent->setAttribute('CLASS', 'CONFIDENTIAL');
break;
}
}
return $vEvent->exportvCalendar();
}