Enable SIFE again

This commit is contained in:
Jörg Lehrke 2010-01-13 20:48:39 +00:00
parent 2d310645f9
commit 023b5979dd
2 changed files with 328 additions and 111 deletions

View File

@ -1289,13 +1289,13 @@ class calendar_ical extends calendar_boupdate
function setSupportedFields($_productManufacturer='', $_productName='') function setSupportedFields($_productManufacturer='', $_productName='')
{ {
$state = &$_SESSION['SyncML.state']; $state =& $_SESSION['SyncML.state'];
if (isset($state)) if (isset($state))
{ {
$deviceInfo = $state->getClientDeviceInfo(); $deviceInfo = $state->getClientDeviceInfo();
} }
// store product manufacturer and name, to be able to use it elsewhere // store product manufacturer and name for further usage
if ($_productManufacturer) if ($_productManufacturer)
{ {
$this->productManufacturer = strtolower($_productManufacturer); $this->productManufacturer = strtolower($_productManufacturer);

View File

@ -21,50 +21,113 @@ class calendar_sif extends calendar_boupdate
var $sifMapping = array( var $sifMapping = array(
'Start' => 'start', 'Start' => 'start',
'End' => 'end', 'End' => 'end',
'AllDayEvent' => 'alldayevent', 'AllDayEvent' => 'alldayevent',
'Attendees' => '', 'Attendees' => '',
'BillingInformation' => '', 'BillingInformation' => '',
'Body' => 'description', 'Body' => 'description',
'BusyStatus' => '', 'BusyStatus' => '',
'Categories' => 'category', 'Categories' => 'category',
'Companies' => '', 'Companies' => '',
'Importance' => 'priority', 'Importance' => 'priority',
'IsRecurring' => 'isrecurring', 'IsRecurring' => 'isrecurring',
'Location' => 'location', 'Location' => 'location',
'MeetingStatus' => '', 'MeetingStatus' => '',
'Mileage' => '', 'Mileage' => '',
'ReminderMinutesBeforeStart' => 'reminderstart', 'ReminderMinutesBeforeStart' => 'reminderstart',
'ReminderSet' => 'reminderset', 'ReminderSet' => 'reminderset',
'ReminderSoundFile' => '', 'ReminderSoundFile' => '',
'ReminderOptions' => '', 'ReminderOptions' => '',
'ReminderInterval' => '', 'ReminderInterval' => '',
'ReminderRepeatCount' => '', 'ReminderRepeatCount' => '',
'Exceptions' => '', 'Exceptions' => '',
'ReplyTime' => '', 'ReplyTime' => '',
'Sensitivity' => 'public', 'Sensitivity' => 'public',
'Subject' => 'title', 'Subject' => 'title',
'RecurrenceType' => 'recur_type', 'RecurrenceType' => 'recur_type',
'Interval' => 'recur_interval', 'Interval' => 'recur_interval',
'MonthOfYear' => '', 'MonthOfYear' => '',
'DayOfMonth' => '', 'DayOfMonth' => '',
'DayOfWeekMask' => 'recur_weekmask', 'DayOfWeekMask' => 'recur_weekmask',
'Instance' => '', 'Instance' => '',
'PatternStartDate' => '', 'PatternStartDate' => '',
'NoEndDate' => 'recur_noenddate', 'NoEndDate' => 'recur_noenddate',
'PatternEndDate' => 'recur_enddate', 'PatternEndDate' => 'recur_enddate',
'Occurrences' => '', 'Occurrences' => '',
); );
// the calendar event array /**
* the calendar event array for the XML Parser
*/
var $event; var $event;
// device specific settings /**
* name and sorftware version of the Funambol client
*
* @var string
*/
var $productName = 'mozilla plugin'; var $productName = 'mozilla plugin';
var $productSoftwareVersion = '0.3'; var $productSoftwareVersion = '0.3';
/**
* user preference: import all-day events as non blocking
*
* @var boolean
*/
var $nonBlockingAllday = false;
/**
* user preference: attach UID entries to the DESCRIPTION
*
* @var boolean
*/
var $uidExtension = false; var $uidExtension = false;
/**
* user preference: calendar to synchronize with
*
* @var int
*/
var $calendarOwner = 0;
/**
* user preference: Use this timezone for import from and export to device
*
* @var string
*/
var $tzid = null;
/**
* Cached timezone data
*
* @var array id => data
*/
protected static $tz_cache = array();
/**
* Device CTCap Properties
*
* @var array
*/
var $clientProperties;
/**
* vCalendar Instance for parsing
*
* @var array
*/
var $vCalendar;
/**
* Set Logging
*
* @var boolean
*/
var $log = false;
var $logfile="/tmp/log-sifcal";
// constants for recurence type // constants for recurence type
const olRecursDaily = 0; const olRecursDaily = 0;
const olRecursWeekly = 1; const olRecursWeekly = 1;
const olRecursMonthly = 2; const olRecursMonthly = 2;
const olRecursMonthNth = 3; const olRecursMonthNth = 3;
@ -72,28 +135,50 @@ class calendar_sif extends calendar_boupdate
const olRecursYearNth = 6; const olRecursYearNth = 6;
// constants for weekdays // constants for weekdays
const olSunday = 1; const olSunday = 1;
const olMonday = 2; const olMonday = 2;
const olTuesday = 4; const olTuesday = 4;
const olWednesday = 8; const olWednesday = 8;
const olThursday = 16; const olThursday = 16;
const olFriday = 32; const olFriday = 32;
const olSaturday = 64; const olSaturday = 64;
// standard headers // standard headers
const xml_decl = '<?xml version="1.0" encoding="UTF-8"?>'; const xml_decl = '<?xml version="1.0" encoding="UTF-8"?>';
const SIF_decl = '<SIFVersion>1.1</SIFVersion>'; const SIF_decl = '<SIFVersion>1.1</SIFVersion>';
/**
* Constructor
*
* @param array $_clientProperties client properties
*/
function __construct(&$_clientProperties = array())
{
parent::__construct();
if ($this->log) $this->logfile = $GLOBALS['egw_info']['server']['temp_dir']."/log-sifcal";
$this->clientProperties = $_clientProperties;
$this->vCalendar = new Horde_iCalendar;
}
function startElement($_parser, $_tag, $_attributes) function startElement($_parser, $_tag, $_attributes)
{ {
} }
function endElement($_parser, $_tag) function endElement($_parser, $_tag)
{ {
//error_log('endElem: ' . $_tag .' => '. trim($this->sifData)); switch (strtolower($_tag))
if(!empty($this->sifMapping[$_tag]))
{ {
$this->event[$this->sifMapping[$_tag]] = trim($this->sifData); case 'excludedate':
$this->event['recur_exception'][] = trim($this->sifData);
break;
default:
if(!empty($this->sifMapping[$_tag]))
{
$this->event[$this->sifMapping[$_tag]] = trim($this->sifData);
}
} }
unset($this->sifData); unset($this->sifData);
} }
@ -103,11 +188,47 @@ class calendar_sif extends calendar_boupdate
$this->sifData .= $_data; $this->sifData .= $_data;
} }
/**
* Get DateTime value for a given time and timezone
*
* @param int|string|DateTime $time in server-time as returned by calendar_bo for $data_format='server'
* @param string $tzid TZID of event or 'UTC' or NULL for palmos timestamps in usertime
* @return mixed attribute value to set: integer timestamp if $tzid == 'UTC' otherwise Ymd\THis string IN $tzid
*/
function getDateTime($time,$tzid)
{
if (empty($tzid) || $tzid == 'UTC')
{
return $this->vCalendar->_exportDateTime(egw_time::to($time,'ts'));
}
if (!is_a($time,'DateTime'))
{
$time = new egw_time($time,egw_time::$server_timezone);
}
if (!isset(self::$tz_cache[$tzid]))
{
self::$tz_cache[$tzid] = calendar_timezones::DateTimeZone($tzid);
}
$time->setTimezone(self::$tz_cache[$tzid]);
return $this->vCalendar->_exportDateTime($time->format('Ymd\THis'));
}
function siftoegw($sifData, $_calID=-1) function siftoegw($sifData, $_calID=-1)
{ {
$vcal = new Horde_iCalendar;
$finalEvent = array(); $finalEvent = array();
$this->event = array();
$sysCharSet = $GLOBALS['egw']->translation->charset(); $sysCharSet = $GLOBALS['egw']->translation->charset();
if ($this->tzid)
{
// enforce device settings
$finalEvent['tzid'] = $this->tzid;
}
else
{
$finalEvent['tzid'] = egw_time::$user_timezone->getName(); // default to user timezone
}
#error_log($sifData); #error_log($sifData);
#$tmpfname = tempnam('/tmp/sync/contents','sife_'); #$tmpfname = tempnam('/tmp/sync/contents','sife_');
@ -135,7 +256,12 @@ class calendar_sif extends calendar_boupdate
{ {
$value = preg_replace('/<\!\[CDATA\[(.+)\]\]>/Usim', '$1', $value); $value = preg_replace('/<\!\[CDATA\[(.+)\]\]>/Usim', '$1', $value);
$value = $GLOBALS['egw']->translation->convert($value, 'utf-8', $sysCharSet); $value = $GLOBALS['egw']->translation->convert($value, 'utf-8', $sysCharSet);
#error_log("$key => $value"); if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
"() $key => $value\n",3,$this->logfile);
}
switch ($key) switch ($key)
{ {
case 'alldayevent': case 'alldayevent':
@ -175,18 +301,27 @@ class calendar_sif extends calendar_boupdate
case 'start': case 'start':
if ($this->event['alldayevent'] < 1) if ($this->event['alldayevent'] < 1)
{ {
$finalEvent[$key] = $vcal->_parseDateTime($value); $finalEvent[$key] = $this->vCalendar->_parseDateTime($value);
error_log("event ".$key." val=".$value.", parsed=".$finalEvent[$key]);
} }
break; break;
case 'isrecurring': case 'isrecurring':
if ($value == 1) if ($value == 1)
{ {
if (is_array($this->event['recur_exception']))
{
$finalEvent['recur_exception'] = array();
foreach ($this->event['recur_exception'] as $day)
{
$finalEvent['recur_exception'][] = $this->vCalendar->_parseDateTime($day);
}
array_unique($finalEvent['recur_exception']);
}
$finalEvent['recur_interval'] = $this->event['recur_interval']; $finalEvent['recur_interval'] = $this->event['recur_interval'];
$finalEvent['recur_data'] = 0;
if ($this->event['recur_noenddate'] == 0) if ($this->event['recur_noenddate'] == 0)
{ {
$finalEvent['recur_enddate'] = $vcal->_parseDateTime($this->event['recur_enddate']); $finalEvent['recur_enddate'] = $this->vCalendar->_parseDateTime($this->event['recur_enddate']);
} }
switch ($this->event['recur_type']) switch ($this->event['recur_type'])
{ {
@ -231,6 +366,7 @@ class calendar_sif extends calendar_boupdate
case 'recur_interval': case 'recur_interval':
case 'recur_weekmask': case 'recur_weekmask':
case 'reminderstart': case 'reminderstart':
case 'recur_exception':
// do nothing, get's handled in isrecuring clause // do nothing, get's handled in isrecuring clause
break; break;
@ -246,10 +382,11 @@ class calendar_sif extends calendar_boupdate
} }
} }
#$middleName = ($finalEvent['n_middle']) ? ' '.trim($finalEvent['n_middle']) : ''; if ($this->log)
#$finalEvent['fn'] = trim($finalEvent['n_given']. $middleName .' '. $finalEvent['n_family']); {
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n" .
#error_log(print_r($finalEvent, true)); array2string($finalEvent)."\n",3,$this->logfile);
}
return $finalEvent; return $finalEvent;
} }
@ -277,9 +414,11 @@ class calendar_sif extends calendar_boupdate
*/ */
function addSIF($_sifdata, $_calID=-1, $merge=false) function addSIF($_sifdata, $_calID=-1, $merge=false)
{ {
$state = &$_SESSION['SyncML.state']; if ($this->log)
$deviceInfo = $state->getClientDeviceInfo(); {
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n" .
array2string($_sifdata)."\n",3,$this->logfile);
}
if (!$event = $this->siftoegw($_sifdata, $_calID)) if (!$event = $this->siftoegw($_sifdata, $_calID))
{ {
return false; return false;
@ -287,42 +426,48 @@ class calendar_sif extends calendar_boupdate
if (isset($event['alarm'])) if (isset($event['alarm']))
{ {
$alarm = $event['alarm']; $alarmData = array();
unset($event['alarm']); $alarmData['offset'] = $event['alarm'] * 60;
$alarmData['time'] = $event['start'] - $alarmData['offset'];
$alarmData['owner'] = $this->user;
$alarmData['all'] = false;
$event['alarm'] = $alarmData;
} }
if ($_calID > 0) if ($_calID > 0 && ($storedEvent = $this->read($_calID)))
{ {
// update entry // update entry
$event['id'] = $_calID; $event['id'] = $_calID;
// delete existing alarms
if (count($storedEvent['alarm']) > 0)
{
foreach ($storedEvent['alarm'] as $alarm_id => $alarm_data)
{
// only touch own alarms
if ($alarm_data['all'] == false && $alarm_data['owner'] == $this->user)
{
$this->delete_alarm($alarm_id);
}
}
}
} }
else else
{ {
if (isset($event['whole_day']) && $event['whole_day'] if (isset($event['whole_day'])
&& isset ($deviceInfo) && is_array($deviceInfo) && $event['whole_day']
&& isset($deviceInfo['nonBlockingAllday']) && $this->nonBlockingAllday)
&& $deviceInfo['nonBlockingAllday'])
{ {
$event['non_blocking'] = '1'; $event['non_blocking'] = 1;
} }
} }
if ($eventID = $this->update($event, TRUE)) $eventID = $this->update($event, true);
{
$updatedEvent = $this->read($eventID);
foreach ($updatedEvent['alarm'] as $alarmID => $alarmData)
{
$this->delete_alarm($alarmID);
}
if (isset($alarm)) if ($eventID && $this->log)
{ {
$alarmData['time'] = $event['start'] - ($alarm*60); $storedEvent = $this->read($eventID);
$alarmData['offset'] = $alarm*60; error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n" .
$alarmData['all'] = 1; array2string($storedEvent)."\n",3,$this->logfile);
$alarmData['owner'] = $GLOBALS['egw_info']['user']['account_id'];
$this->save_alarm($eventID, $alarmData);
}
} }
return $eventID; return $eventID;
@ -346,7 +491,11 @@ class calendar_sif extends calendar_boupdate
if (($event = $this->read($_id,null,false,'server'))) if (($event = $this->read($_id,null,false,'server')))
{ {
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n" .
array2string($event)."\n",3,$this->logfile);
}
if ($this->uidExtension) if ($this->uidExtension)
{ {
if (!preg_match('/\[UID:.+\]/m', $event['description'])) if (!preg_match('/\[UID:.+\]/m', $event['description']))
@ -355,10 +504,31 @@ class calendar_sif extends calendar_boupdate
} }
} }
$vcal = new Horde_iCalendar('1.0'); if ($this->tzid === false)
{
$tzid = null;
}
elseif ($this->tzid)
{
$tzid = $this->tzid;
}
else
{
$tzid = $event['tzid'];
}
if ($tzid && $tzid != 'UTC')
{
if (!isset(self::$tz_cache[$tzid]))
{
self::$tz_cache[$tzid] = calendar_timezones::DateTimeZone($tzid);
}
}
if (!isset(self::$tz_cache[$event['tzid']]))
{
self::$tz_cache[$event['tzid']] = calendar_timezones::DateTimeZone($event['tzid']);
}
$sifEvent = self::xml_decl . "<appointment>" . self::SIF_decl;
$sifEvent = self::xml_decl . "\n<appointment>" . self::SIF_decl;
foreach ($this->sifMapping as $sifField => $egwField) foreach ($this->sifMapping as $sifField => $egwField)
{ {
@ -396,24 +566,28 @@ class calendar_sif extends calendar_boupdate
} }
else else
{ {
$recurEndDate = mktime(24 , 0, 0, $time = new egw_time($event['recur_enddate'],egw_time::$server_timezone);
date('m',$event['recur_enddate']), // all calculations in the event's timezone
date('d', $event['recur_enddate']), $time->setTimezone(self::$tz_cache[$event['tzid']]);
date('Y', $event['recur_enddate'])); $time->setTime(23, 59, 59);
$recurEndDate = $this->date2ts($time);
$sifEvent .= '<NoEndDate>0</NoEndDate>'; $sifEvent .= '<NoEndDate>0</NoEndDate>';
$sifEvent .= '<PatternEndDate>'. $vcal->_exportDateTime($recurEndDate) .'</PatternEndDate>'; $sifEvent .= '<PatternEndDate>'. $this->vCalendar->_exportDateTime($recurEndDate) .'</PatternEndDate>';
} }
$time = new egw_time($event['start'],egw_time::$server_timezone);
// all calculations in the event's timezone
$time->setTimezone(self::$tz_cache[$event['tzid']]);
$time->setTime(0, 0, 0);
$recurStartDate = $this->date2ts($time);
$eventInterval = ($event['recur_interval'] > 1 ? $event['recur_interval'] : 1);
switch ($event['recur_type']) switch ($event['recur_type'])
{ {
case MCAL_RECUR_DAILY: case MCAL_RECUR_DAILY:
$eventInterval = ($event['recur_interval'] > 1 ? $event['recur_interval'] : 1);
$recurStartDate = mktime(0,0,0,date('m',$event['start']), date('d', $event['start']), date('Y', $event['start']));
$sifEvent .= "<$sifField>1</$sifField>"; $sifEvent .= "<$sifField>1</$sifField>";
$sifEvent .= '<RecurrenceType>'. self::olRecursDaily .'</RecurrenceType>'; $sifEvent .= '<RecurrenceType>'. self::olRecursDaily .'</RecurrenceType>';
$sifEvent .= '<Interval>'. $eventInterval .'</Interval>'; $sifEvent .= '<Interval>'. $eventInterval .'</Interval>';
$sifEvent .= '<PatternStartDate>'. $vcal->_exportDateTime($recurStartDate) .'</PatternStartDate>'; $sifEvent .= '<PatternStartDate>'. $this->vCalendar->_exportDateTime($recurStartDate) .'</PatternStartDate>';
if ($event['recur_enddate']) if ($event['recur_enddate'])
{ {
$totalDays = ($recurEndDate - $recurStartDate) / 86400; $totalDays = ($recurEndDate - $recurStartDate) / 86400;
@ -423,19 +597,15 @@ class calendar_sif extends calendar_boupdate
break; break;
case MCAL_RECUR_WEEKLY: case MCAL_RECUR_WEEKLY:
$eventInterval = ($event['recur_interval'] > 1 ? $event['recur_interval'] : 1);
$recurStartDate = mktime(0,0,0,date('m',$event['start']), date('d', $event['start']), date('Y', $event['start']));
$sifEvent .= "<$sifField>1</$sifField>"; $sifEvent .= "<$sifField>1</$sifField>";
$sifEvent .= '<RecurrenceType>'. self::olRecursWeekly .'</RecurrenceType>'; $sifEvent .= '<RecurrenceType>'. self::olRecursWeekly .'</RecurrenceType>';
$sifEvent .= '<Interval>'. $eventInterval .'</Interval>'; $sifEvent .= '<Interval>'. $eventInterval .'</Interval>';
$sifEvent .= '<PatternStartDate>'. $vcal->_exportDateTime($recurStartDate) .'</PatternStartDate>'; $sifEvent .= '<PatternStartDate>'. $this->vCalendar->_exportDateTime($recurStartDate) .'</PatternStartDate>';
$sifEvent .= '<DayOfWeekMask>'. $event['recur_data'] .'</DayOfWeekMask>'; $sifEvent .= '<DayOfWeekMask>'. $event['recur_data'] .'</DayOfWeekMask>';
if ($event['recur_enddate']) if ($event['recur_enddate'])
{ {
$daysPerWeek = substr_count(decbin($event['recur_data']),'1'); $daysPerWeek = substr_count(decbin($event['recur_data']),'1');
$totalWeeks = floor(($recurEndDate - $recurStartDate) / (86400*7)); $totalWeeks = floor(($recurEndDate - $recurStartDate) / (86400*7));
#error_log("AAA: $daysPerWeek $totalWeeks");
$occurrences = ($totalWeeks / $eventInterval) * $daysPerWeek; $occurrences = ($totalWeeks / $eventInterval) * $daysPerWeek;
for($i = $recurEndDate; $i > $recurStartDate + ($totalWeeks * 86400*7); $i = $i - 86400) for($i = $recurEndDate; $i > $recurStartDate + ($totalWeeks * 86400*7); $i = $i - 86400)
{ {
@ -470,26 +640,20 @@ class calendar_sif extends calendar_boupdate
break; break;
case MCAL_RECUR_MONTHLY_MDAY: case MCAL_RECUR_MONTHLY_MDAY:
$eventInterval = ($event['recur_interval'] > 1 ? $event['recur_interval'] : 1);
$recurStartDate = mktime(0,0,0,date('m',$event['start']), date('d', $event['start']), date('Y', $event['start']));
$sifEvent .= "<$sifField>1</$sifField>"; $sifEvent .= "<$sifField>1</$sifField>";
$sifEvent .= '<RecurrenceType>'. self::olRecursMonthly .'</RecurrenceType>'; $sifEvent .= '<RecurrenceType>'. self::olRecursMonthly .'</RecurrenceType>';
$sifEvent .= '<Interval>'. $eventInterval .'</Interval>'; $sifEvent .= '<Interval>'. $eventInterval .'</Interval>';
$sifEvent .= '<PatternStartDate>'. $vcal->_exportDateTime($recurStartDate) .'</PatternStartDate>'; $sifEvent .= '<PatternStartDate>'. $this->vCalendar->_exportDateTime($recurStartDate) .'</PatternStartDate>';
break; break;
case MCAL_RECUR_MONTHLY_WDAY: case MCAL_RECUR_MONTHLY_WDAY:
$weekMaskMap = array('Sun' => self::olSunday, 'Mon' => self::olMonday, 'Tue' => self::olTuesday, $weekMaskMap = array('Sun' => self::olSunday, 'Mon' => self::olMonday, 'Tue' => self::olTuesday,
'Wed' => self::olWednesday, 'Thu' => self::olThursday, 'Fri' => self::olFriday, 'Wed' => self::olWednesday, 'Thu' => self::olThursday, 'Fri' => self::olFriday,
'Sat' => self::olSaturday); 'Sat' => self::olSaturday);
$eventInterval = ($event['recur_interval'] > 1 ? $event['recur_interval'] : 1);
$recurStartDate = mktime(0,0,0,date('m',$event['start']), date('d', $event['start']), date('Y', $event['start']));
$sifEvent .= "<$sifField>1</$sifField>"; $sifEvent .= "<$sifField>1</$sifField>";
$sifEvent .= '<RecurrenceType>'. self::olRecursMonthNth .'</RecurrenceType>'; $sifEvent .= '<RecurrenceType>'. self::olRecursMonthNth .'</RecurrenceType>';
$sifEvent .= '<Interval>'. $eventInterval .'</Interval>'; $sifEvent .= '<Interval>'. $eventInterval .'</Interval>';
$sifEvent .= '<PatternStartDate>'. $vcal->_exportDateTime($recurStartDate) .'</PatternStartDate>'; $sifEvent .= '<PatternStartDate>'. $this->vCalendar->_exportDateTime($recurStartDate) .'</PatternStartDate>';
$sifEvent .= '<Instance>' . (1 + (int) ((date('d',$event['start'])-1) / 7)) . '</Instance>'; $sifEvent .= '<Instance>' . (1 + (int) ((date('d',$event['start'])-1) / 7)) . '</Instance>';
$sifEvent .= '<DayOfWeekMask>' . $weekMaskMap[date('D',$event['start'])] . '</DayOfWeekMask>'; $sifEvent .= '<DayOfWeekMask>' . $weekMaskMap[date('D',$event['start'])] . '</DayOfWeekMask>';
break; break;
@ -499,6 +663,24 @@ class calendar_sif extends calendar_boupdate
$sifEvent .= '<RecurrenceType>'. self::olRecursYearly .'</RecurrenceType>'; $sifEvent .= '<RecurrenceType>'. self::olRecursYearly .'</RecurrenceType>';
break; break;
} }
if (is_array($event['recur_exception']))
{
$sifEvent .= '<Exceptions>';
foreach ($event['recur_exception'] as $day)
{
if ($this->isWholeDay($event))
{
$time = new egw_time($day,egw_time::$server_timezone);
$time->setTimezone(self::$tz_cache[$tzid]);
$sifEvent .= '<ExcludeDate>' . $time->format('Y-m-d') . '</ExcludeDate>';
}
else
{
$sifEvent .= '<ExcludeDate>' . self::getDateTime($day,$tzid) . '</ExcludeDate>';
}
}
$sifEvent .= '</Exceptions>';
}
break; break;
case 'Sensitivity': case 'Sensitivity':
@ -519,18 +701,18 @@ class calendar_sif extends calendar_boupdate
case 'Start': case 'Start':
if ($this->isWholeDay($event)) if ($this->isWholeDay($event))
{ {
$value = date('Y-m-d', $event['start']); $time = new egw_time($event['start'],egw_time::$server_timezone);
$sifEvent .= "<Start>$value</Start>"; $time->setTimezone(self::$tz_cache[$tzid]);
$vaule = date('Y-m-d', $event['end']); $sifEvent .= '<Start>' . $time->format('Y-m-d') . '</Start>';
$sifEvent .= "<End>$value</End>"; $time = new egw_time($event['end'],egw_time::$server_timezone);
$time->setTimezone(self::$tz_cache[$tzid]);
$sifEvent .= '<End>' . $time->format('Y-m-d') . '</End>';
$sifEvent .= "<AllDayEvent>1</AllDayEvent>"; $sifEvent .= "<AllDayEvent>1</AllDayEvent>";
} }
else else
{ {
$value = $vcal->_exportDateTime($event['start']); $sifEvent .= '<Start>' . self::getDateTime($event['start'],$tzid) . '</Start>';
$sifEvent .= "<Start>$value</Start>"; $sifEvent .= '<End>' . self::getDateTime($event['end'],$tzid) . '</End>';
$value = $vcal->_exportDateTime($event['end']);
$sifEvent .= "<End>$value</End>";
$sifEvent .= "<AllDayEvent>0</AllDayEvent>"; $sifEvent .= "<AllDayEvent>0</AllDayEvent>";
} }
break; break;
@ -556,9 +738,9 @@ class calendar_sif extends calendar_boupdate
break; break;
case 'Categories': case 'Categories':
if (!empty($value)) if (!empty($value) && ($values = $this->get_categories($value)))
{ {
$value = implode(', ', $this->get_categories($value)); $value = implode(', ', $values);
$value = $GLOBALS['egw']->translation->convert($value, $sysCharSet, 'utf-8'); $value = $GLOBALS['egw']->translation->convert($value, $sysCharSet, 'utf-8');
} }
else else
@ -572,7 +754,15 @@ class calendar_sif extends calendar_boupdate
break; break;
} }
} }
$sifEvent .= '</appointment>'; $sifEvent .= "</appointment>";
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
"() '$this->productName','$this->productSoftwareVersion'\n",3,$this->logfile);
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
"()\n".array2string($sifEvent)."\n",3,$this->logfile);
}
return $sifEvent; return $sifEvent;
} }
@ -594,18 +784,39 @@ class calendar_sif extends calendar_boupdate
*/ */
function setSupportedFields($_productName='', $_productSoftwareVersion='') function setSupportedFields($_productName='', $_productSoftwareVersion='')
{ {
$state = &$_SESSION['SyncML.state']; $state =& $_SESSION['SyncML.state'];
$deviceInfo = $state->getClientDeviceInfo(); if (isset($state))
{
$deviceInfo = $state->getClientDeviceInfo();
}
if (isset($deviceInfo) && is_array($deviceInfo)) if (isset($deviceInfo) && is_array($deviceInfo))
{ {
if (isset($deviceInfo['uidExtension']) && if (isset($deviceInfo['uidExtension']) &&
$deviceInfo['uidExtension']) $deviceInfo['uidExtension'])
{
$this->uidExtension = true;
}
if (isset($deviceInfo['nonBlockingAllday']) &&
$deviceInfo['nonBlockingAllday'])
{
$this->nonBlockingAllday = true;
}
if (isset($deviceInfo['tzid']) &&
$deviceInfo['tzid'])
{
$this->tzid = $deviceInfo['tzid'];
}
if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['calendar_owner']))
{
$owner = $GLOBALS['egw_info']['user']['preferences']['syncml']['calendar_owner'];
if (0 < (int)$owner && $this->check_perms(EGW_ACL_EDIT,0,$owner))
{ {
$this->uidExtension = true; $this->calendarOwner = $owner;
} }
}
} }
// store product name and version, to be able to use it elsewhere // store product name and software version for futher usage
if ($_productName) if ($_productName)
{ {
$this->productName = strtolower($_productName); $this->productName = strtolower($_productName);
@ -614,5 +825,11 @@ class calendar_sif extends calendar_boupdate
$this->productSoftwareVersion = $matches[1]; $this->productSoftwareVersion = $matches[1];
} }
} }
if ($this->log)
{
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
'(' . $this->productName .
', '. $this->productSoftwareVersion . ")\n",3,$this->logfile);
}
} }
} }