2008-06-07 19:45:33 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* iCal import and export via Horde iCalendar classes
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Lars Kneschke <lkneschke@egroupware.org>
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2009-07-15 22:35:56 +02:00
|
|
|
* @author Joerg Lehrke <jlehrke@noc.de>
|
2008-06-07 19:45:33 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package calendar
|
|
|
|
* @subpackage export
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
require_once EGW_SERVER_ROOT.'/phpgwapi/inc/horde/lib/core.php';
|
2008-06-07 19:45:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* iCal import and export via Horde iCalendar classes
|
|
|
|
*/
|
2008-06-07 19:49:16 +02:00
|
|
|
class calendar_ical extends calendar_boupdate
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array $supportedFields array containing the supported fields of the importing device
|
|
|
|
*/
|
|
|
|
var $supportedFields;
|
|
|
|
|
2009-12-01 11:24:55 +01:00
|
|
|
var $recur_days_1_0 = array(
|
|
|
|
MCAL_M_MONDAY => 'MO',
|
|
|
|
MCAL_M_TUESDAY => 'TU',
|
|
|
|
MCAL_M_WEDNESDAY => 'WE',
|
|
|
|
MCAL_M_THURSDAY => 'TH',
|
|
|
|
MCAL_M_FRIDAY => 'FR',
|
|
|
|
MCAL_M_SATURDAY => 'SA',
|
|
|
|
MCAL_M_SUNDAY => 'SU',
|
|
|
|
);
|
2008-06-07 19:45:33 +02:00
|
|
|
/**
|
|
|
|
* @var array $status_egw2ical conversation of the participant status egw => ical
|
|
|
|
*/
|
|
|
|
var $status_egw2ical = array(
|
|
|
|
'U' => 'NEEDS-ACTION',
|
|
|
|
'A' => 'ACCEPTED',
|
|
|
|
'R' => 'DECLINED',
|
|
|
|
'T' => 'TENTATIVE',
|
|
|
|
);
|
|
|
|
/**
|
|
|
|
* @var array conversation of the participant status ical => egw
|
|
|
|
*/
|
|
|
|
var $status_ical2egw = array(
|
|
|
|
'NEEDS-ACTION' => 'U',
|
2009-07-15 22:35:56 +02:00
|
|
|
'NEEDS ACTION' => 'U',
|
2008-06-07 19:45:33 +02:00
|
|
|
'ACCEPTED' => 'A',
|
|
|
|
'DECLINED' => 'R',
|
|
|
|
'TENTATIVE' => 'T',
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2009-12-29 14:51:07 +01:00
|
|
|
* @var array $priority_egw2ical conversion of the priority egw => ical
|
2008-06-07 19:45:33 +02:00
|
|
|
*/
|
|
|
|
var $priority_egw2ical = array(
|
|
|
|
0 => 0, // undefined
|
|
|
|
1 => 9, // low
|
|
|
|
2 => 5, // normal
|
|
|
|
3 => 1, // high
|
|
|
|
);
|
2009-07-15 22:35:56 +02:00
|
|
|
|
2008-06-07 19:45:33 +02:00
|
|
|
/**
|
2009-12-29 14:51:07 +01:00
|
|
|
* @var array $priority_ical2egw conversion of the priority ical => egw
|
2008-06-07 19:45:33 +02:00
|
|
|
*/
|
|
|
|
var $priority_ical2egw = array(
|
|
|
|
0 => 0, // undefined
|
|
|
|
9 => 1, 8 => 1, 7 => 1, 6 => 1, // low
|
|
|
|
5 => 2, // normal
|
2009-07-15 22:35:56 +02:00
|
|
|
4 => 3, 3 => 3, 2 => 3, 1 => 3, // high
|
2008-06-07 19:45:33 +02:00
|
|
|
);
|
2009-12-29 14:51:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array $priority_egw2funambol conversion of the priority egw => funambol
|
|
|
|
*/
|
|
|
|
var $priority_egw2funambol = array(
|
|
|
|
0 => 1, // undefined (mapped to normal since undefined does not exist)
|
|
|
|
1 => 0, // low
|
|
|
|
2 => 1, // normal
|
|
|
|
3 => 2, // high
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array $priority_funambol2egw conversion of the priority funambol => egw
|
|
|
|
*/
|
|
|
|
var $priority_funambol2egw = array(
|
|
|
|
0 => 1, // low
|
|
|
|
1 => 2, // normal
|
|
|
|
2 => 3, // high
|
|
|
|
);
|
2008-06-07 19:45:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* manufacturer and name of the sync-client
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $productManufacturer = 'file';
|
|
|
|
var $productName = '';
|
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2009-11-29 15:03:45 +01:00
|
|
|
/**
|
|
|
|
* user preference: calendar to synchronize with
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
var $calendarOwner = 0;
|
|
|
|
|
2009-11-11 22:31:33 +01:00
|
|
|
/**
|
|
|
|
* user preference: Use this timezone for import from and export to device
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $tzid = null;
|
|
|
|
|
2009-11-19 11:13:17 +01:00
|
|
|
/**
|
|
|
|
* Cached timezone data
|
|
|
|
*
|
|
|
|
* @var array id => data
|
|
|
|
*/
|
|
|
|
protected static $tz_cache = array();
|
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
/**
|
|
|
|
* Device CTCap Properties
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $clientProperties;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vCalendar Instance for parsing
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $vCalendar;
|
|
|
|
|
2009-07-24 16:18:57 +02:00
|
|
|
/**
|
2009-08-04 19:37:49 +02:00
|
|
|
* Set Logging
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2009-11-27 09:33:10 +01:00
|
|
|
var $log = false;
|
2009-07-24 16:18:57 +02:00
|
|
|
var $logfile="/tmp/log-vcal";
|
|
|
|
|
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param array $_clientProperties client properties
|
|
|
|
*/
|
2009-07-17 14:08:45 +02:00
|
|
|
function __construct(&$_clientProperties = array())
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
parent::__construct();
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($this->log) $this->logfile = $GLOBALS['egw_info']['server']['temp_dir']."/log-vcal";
|
2009-07-15 22:35:56 +02:00
|
|
|
$this->clientProperties = $_clientProperties;
|
|
|
|
$this->vCalendar = new Horde_iCalendar;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-07 19:45:33 +02:00
|
|
|
/**
|
|
|
|
* Exports one calendar event to an iCalendar item
|
|
|
|
*
|
|
|
|
* @param int/array $events (array of) cal_id or array of the events
|
|
|
|
* @param string $version='1.0' could be '2.0' too
|
|
|
|
* @param string $method='PUBLISH'
|
2009-08-17 12:34:22 +02:00
|
|
|
* @param int $recur_date=0 if set export the next recurrence at or after the timestamp,
|
2009-07-15 22:35:56 +02:00
|
|
|
* default 0 => export whole series (or events, if not recurring)
|
2008-11-03 10:36:20 +01:00
|
|
|
* @return string/boolean string with iCal or false on error (eg. no permission to read the event)
|
2008-06-07 19:45:33 +02:00
|
|
|
*/
|
2009-07-15 22:35:56 +02:00
|
|
|
function &exportVCal($events, $version='1.0', $method='PUBLISH', $recur_date=0)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
|
|
|
$egwSupportedFields = array(
|
2009-07-28 10:58:39 +02:00
|
|
|
'CLASS' => 'public',
|
|
|
|
'SUMMARY' => 'title',
|
|
|
|
'DESCRIPTION' => 'description',
|
|
|
|
'LOCATION' => 'location',
|
|
|
|
'DTSTART' => 'start',
|
|
|
|
'DTEND' => 'end',
|
|
|
|
'ATTENDEE' => 'participants',
|
2009-11-26 19:36:19 +01:00
|
|
|
'ORGANIZER' => 'owner',
|
2009-07-28 10:58:39 +02:00
|
|
|
'RRULE' => 'recur_type',
|
|
|
|
'EXDATE' => 'recur_exception',
|
|
|
|
'PRIORITY' => 'priority',
|
|
|
|
'TRANSP' => 'non_blocking',
|
|
|
|
'CATEGORIES' => 'category',
|
|
|
|
'UID' => 'uid',
|
|
|
|
'RECURRENCE-ID' => 'recurrence',
|
2009-10-25 19:22:01 +01:00
|
|
|
'SEQUENCE' => 'etag',
|
2008-06-07 19:45:33 +02:00
|
|
|
);
|
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
if (!is_array($this->supportedFields)) $this->setSupportedFields();
|
|
|
|
|
|
|
|
if ($this->productManufacturer == '' )
|
2008-06-07 19:45:33 +02:00
|
|
|
{ // syncevolution is broken
|
2009-07-15 22:35:56 +02:00
|
|
|
$version = '2.0';
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
|
2009-06-08 18:21:14 +02:00
|
|
|
$vcal = new Horde_iCalendar;
|
2008-06-07 19:45:33 +02:00
|
|
|
$vcal->setAttribute('PRODID','-//eGroupWare//NONSGML eGroupWare Calendar '.$GLOBALS['egw_info']['apps']['calendar']['version'].'//'.
|
|
|
|
strtoupper($GLOBALS['egw_info']['user']['preferences']['common']['lang']));
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcal->setAttribute('VERSION', $version);
|
|
|
|
$vcal->setAttribute('METHOD', $method);
|
2008-06-07 19:45:33 +02:00
|
|
|
|
|
|
|
if (!is_array($events)) $events = array($events);
|
|
|
|
|
2009-11-10 16:08:35 +01:00
|
|
|
$vtimezones_added = array();
|
|
|
|
foreach($events as $event)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-11-26 19:36:19 +01:00
|
|
|
$mailtoOrganizer = false;
|
|
|
|
$organizerCN = false;
|
|
|
|
|
2009-11-10 16:08:35 +01:00
|
|
|
if (strpos($this->productName, 'palmos') !== false)
|
2009-10-05 23:00:08 +02:00
|
|
|
{
|
|
|
|
$date_format = 'ts';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-06 14:41:08 +02:00
|
|
|
$date_format = 'server';
|
2009-10-05 23:00:08 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
if (!is_array($event)
|
|
|
|
&& !($event = $this->read($event, $recur_date, false, $date_format)))
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
|
|
|
return false; // no permission to read $cal_id
|
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
if ($recur_date)
|
|
|
|
{
|
|
|
|
// force single event
|
|
|
|
foreach (array('recur_enddate','recur_interval','recur_exception','recur_data','recur_date','id','etag') as $name)
|
|
|
|
{
|
|
|
|
unset($event[$name]);
|
|
|
|
}
|
|
|
|
$event['recur_type'] = MCAL_RECUR_NONE;
|
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
elseif ($event['recur_enddate'])
|
|
|
|
{
|
2009-12-04 16:38:23 +01:00
|
|
|
$time = new egw_time($event['start'],egw_time::$server_timezone);
|
|
|
|
if (!isset(self::$tz_cache[$event['tzid']]))
|
|
|
|
{
|
|
|
|
self::$tz_cache[$event['tzid']] = calendar_timezones::DateTimeZone($event['tzid']);
|
|
|
|
}
|
|
|
|
// all calculations in the event's timezone
|
|
|
|
$time->setTimezone(self::$tz_cache[$event['tzid']]);
|
|
|
|
$time->setTime(0, 0, 0);
|
|
|
|
$delta = $event['end'] - (int)$time->format('U');
|
|
|
|
// Adjust recur_enddate to end time
|
|
|
|
$event['recur_enddate'] += $delta;
|
2009-10-25 19:22:01 +01:00
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-11-11 22:31:33 +01:00
|
|
|
if ($this->log) error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n".array2string($event)."\n",3,$this->logfile);
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-11-11 22:31:33 +01:00
|
|
|
if ($this->tzid === false)
|
2009-10-05 23:00:08 +02:00
|
|
|
{
|
2009-11-10 16:08:35 +01:00
|
|
|
$tzid = null;
|
|
|
|
}
|
2009-11-11 22:31:33 +01:00
|
|
|
elseif ($this->tzid)
|
|
|
|
{
|
|
|
|
$tzid = $this->tzid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$tzid = $event['tzid'];
|
|
|
|
}
|
2009-11-10 16:08:35 +01:00
|
|
|
// check if tzid of event (not only recuring ones) is already added to export
|
2009-11-11 22:31:33 +01:00
|
|
|
if ($tzid && $tzid != 'UTC' && !in_array($tzid,$vtimezones_added))
|
2009-11-10 16:08:35 +01:00
|
|
|
{
|
|
|
|
// check if we have vtimezone component data for tzid of event, if not default to user timezone (default to server tz)
|
|
|
|
if (!($vtimezone = calendar_timezones::tz2id($tzid,'component')))
|
2009-10-06 16:29:46 +02:00
|
|
|
{
|
2009-11-10 16:08:35 +01:00
|
|
|
error_log(__METHOD__."() unknown TZID='$tzid', defaulting to user timezone '".egw_time::$user_timezone->getName()."'!");
|
|
|
|
$vtimezone = calendar_timezones::tz2id($tzid=egw_time::$user_timezone->getName(),'component');
|
2009-10-06 16:29:46 +02:00
|
|
|
}
|
2009-11-19 14:30:30 +01:00
|
|
|
if (!isset(self::$tz_cache[$tzid]))
|
|
|
|
{
|
|
|
|
self::$tz_cache[$tzid] = calendar_timezones::DateTimeZone($tzid);
|
|
|
|
}
|
2009-11-10 16:08:35 +01:00
|
|
|
//error_log("in_array('$tzid',\$vtimezones_added)=".array2string(in_array($tzid,$vtimezones_added)).", component=$vtimezone");;
|
|
|
|
if (!in_array($tzid,$vtimezones_added))
|
2009-10-30 22:39:19 +01:00
|
|
|
{
|
2009-11-10 16:08:35 +01:00
|
|
|
// $vtimezone is a string with a single VTIMEZONE component, afaik Horde_iCalendar can not add it directly
|
|
|
|
// --> we have to parse it and let Horde_iCalendar add it again
|
|
|
|
$horde_vtimezone = Horde_iCalendar::newComponent('VTIMEZONE',$container=false);
|
|
|
|
$horde_vtimezone->parsevCalendar($vtimezone,'VTIMEZONE');
|
2009-11-19 08:52:42 +01:00
|
|
|
// DTSTART must be in local time!
|
|
|
|
$standard = $horde_vtimezone->findComponent('STANDARD');
|
|
|
|
$dtstart = $standard->getAttribute('DTSTART');
|
2009-11-19 14:30:30 +01:00
|
|
|
$dtstart = new egw_time($dtstart, egw_time::$server_timezone);
|
|
|
|
$dtstart->setTimezone(self::$tz_cache[$tzid]);
|
|
|
|
$standard->setAttribute('DTSTART', $dtstart->format('Ymd\THis'), array(), false);
|
2009-11-19 08:52:42 +01:00
|
|
|
$daylight = $horde_vtimezone->findComponent('DAYLIGHT');
|
|
|
|
$dtstart = $daylight->getAttribute('DTSTART');
|
2009-11-19 14:30:30 +01:00
|
|
|
$dtstart = new egw_time($dtstart, egw_time::$server_timezone);
|
|
|
|
$dtstart->setTimezone(self::$tz_cache[$tzid]);
|
|
|
|
$daylight->setAttribute('DTSTART', $dtstart->format('Ymd\THis'), array(), false);
|
2009-11-10 16:08:35 +01:00
|
|
|
$vcal->addComponent($horde_vtimezone);
|
|
|
|
$vtimezones_added[] = $tzid;
|
2009-10-30 22:39:19 +01:00
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
}
|
2009-08-04 19:37:49 +02:00
|
|
|
if ($this->productManufacturer != 'file' && $this->uidExtension)
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
// Append UID to DESCRIPTION
|
|
|
|
if (!preg_match('/\[UID:.+\]/m', $event['description'])) {
|
|
|
|
$event['description'] .= "\n[UID:" . $event['uid'] . "]";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$vevent = Horde_iCalendar::newComponent('VEVENT', $vcal);
|
|
|
|
$parameters = $attributes = $values = array();
|
|
|
|
|
|
|
|
if ($this->productManufacturer == 'sonyericsson')
|
|
|
|
{
|
|
|
|
$eventDST = date('I', $event['start']);
|
|
|
|
if ($eventDST)
|
|
|
|
{
|
|
|
|
$attributes['X-SONYERICSSON-DST'] = 4;
|
|
|
|
}
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach ($egwSupportedFields as $icalFieldName => $egwFieldName)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-11-11 22:31:33 +01:00
|
|
|
if (!isset($this->supportedFields[$egwFieldName])) continue;
|
|
|
|
|
2009-07-28 10:58:39 +02:00
|
|
|
$values[$icalFieldName] = array();
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($icalFieldName)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-07-28 10:58:39 +02:00
|
|
|
case 'ATTENDEE':
|
|
|
|
//if (count($event['participants']) == 1 && isset($event['participants'][$this->user])) break;
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach ((array)$event['participants'] as $uid => $status)
|
2009-07-28 10:58:39 +02:00
|
|
|
{
|
|
|
|
if (!($info = $this->resource_info($uid))) continue;
|
2009-11-26 19:36:19 +01:00
|
|
|
$mailtoParticipant = $info['email'] ? 'MAILTO:'.$info['email'] : '';
|
|
|
|
$participantCN = '"' . ($info['cn'] ? $info['cn'] : $info['name']) . '"';
|
|
|
|
calendar_so::split_status($status, $quantity, $role);
|
|
|
|
if ($role == 'CHAIR' && $uid != $this->user)
|
|
|
|
{
|
|
|
|
$mailtoOrganizer = $mailtoParticipant;
|
|
|
|
$organizerCN = $participantCN;
|
|
|
|
if ($status == 'U') continue; // saved ORGANIZER
|
|
|
|
}
|
2009-07-28 10:58:39 +02:00
|
|
|
// RB: MAILTO href contains only the email-address, NO cn!
|
2009-11-26 19:36:19 +01:00
|
|
|
$attributes['ATTENDEE'][] = $mailtoParticipant;
|
2009-07-28 10:58:39 +02:00
|
|
|
// RSVP={TRUE|FALSE} // resonse expected, not set in eGW => status=U
|
|
|
|
$rsvp = $status == 'U' ? 'TRUE' : 'FALSE';
|
|
|
|
// PARTSTAT={NEEDS-ACTION|ACCEPTED|DECLINED|TENTATIVE|DELEGATED|COMPLETED|IN-PROGRESS} everything from delegated is NOT used by eGW atm.
|
|
|
|
$status = $this->status_egw2ical[$status];
|
|
|
|
// CUTYPE={INDIVIDUAL|GROUP|RESOURCE|ROOM|UNKNOWN}
|
|
|
|
switch ($info['type'])
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-07-28 10:58:39 +02:00
|
|
|
case 'g':
|
|
|
|
$cutype = 'GROUP';
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
$cutype = 'RESOURCE';
|
|
|
|
break;
|
|
|
|
case 'u': // account
|
|
|
|
case 'c': // contact
|
|
|
|
case 'e': // email address
|
|
|
|
$cutype = 'INDIVIDUAL';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$cutype = 'UNKNOWN';
|
|
|
|
break;
|
|
|
|
};
|
2009-11-26 19:36:19 +01:00
|
|
|
// ROLE={CHAIR|REQ-PARTICIPANT|OPT-PARTICIPANT|NON-PARTICIPANT|X-*}
|
2009-07-28 10:58:39 +02:00
|
|
|
$parameters['ATTENDEE'][] = array(
|
2009-11-26 19:36:19 +01:00
|
|
|
'CN' => $participantCN,
|
2009-07-28 10:58:39 +02:00
|
|
|
'ROLE' => $role,
|
|
|
|
'PARTSTAT' => $status,
|
|
|
|
'CUTYPE' => $cutype,
|
|
|
|
'RSVP' => $rsvp,
|
2009-08-04 19:37:49 +02:00
|
|
|
)+($info['type'] != 'e' ? array('X-EGROUPWARE-UID' => $uid) : array())+
|
2009-08-06 13:29:05 +02:00
|
|
|
($quantity > 1 ? array('X-EGROUPWARE-QUANTITY' => $quantity) : array());
|
2009-07-28 10:58:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-08-04 19:37:49 +02:00
|
|
|
case 'CLASS':
|
|
|
|
$attributes['CLASS'] = $event['public'] ? 'PUBLIC' : 'CONFIDENTIAL';
|
|
|
|
break;
|
2009-07-28 10:58:39 +02:00
|
|
|
|
2009-11-26 19:36:19 +01:00
|
|
|
case 'ORGANIZER':
|
|
|
|
// according to iCalendar standard, ORGANIZER not used for events in the own calendar
|
|
|
|
if (!$organizerCN &&
|
|
|
|
($event['owner'] != $this->user
|
|
|
|
|| $this->productManufacturer != 'groupdav'))
|
2009-10-25 19:22:01 +01:00
|
|
|
{
|
|
|
|
$mailtoOrganizer = $GLOBALS['egw']->accounts->id2name($event['owner'],'account_email');
|
2009-11-26 19:36:19 +01:00
|
|
|
$mailtoOrganizer = $mailtoOrganizer ? 'MAILTO:'.$mailtoOrganizer : '';
|
|
|
|
$organizerCN = '"' . trim($GLOBALS['egw']->accounts->id2name($event['owner'],'account_firstname')
|
|
|
|
. ' ' . $GLOBALS['egw']->accounts->id2name($event['owner'],'account_lastname')) . '"';
|
|
|
|
}
|
|
|
|
if ($organizerCN)
|
|
|
|
{
|
|
|
|
$attributes['ORGANIZER'] = $mailtoOrganizer;
|
|
|
|
$parameters['ORGANIZER']['CN'] = $organizerCN;
|
2009-10-25 19:22:01 +01:00
|
|
|
}
|
|
|
|
break;
|
2009-07-28 10:58:39 +02:00
|
|
|
|
|
|
|
case 'DTSTART':
|
2009-11-10 16:08:35 +01:00
|
|
|
$attributes['DTSTART'] = self::getDateTime($event['start'],$tzid,$parameters['DTSTART']);
|
2009-07-28 10:58:39 +02:00
|
|
|
break;
|
2009-07-15 22:35:56 +02:00
|
|
|
|
2009-07-28 10:58:39 +02:00
|
|
|
case 'DTEND':
|
|
|
|
// write start + end of whole day events as dates
|
|
|
|
if ($this->isWholeDay($event))
|
|
|
|
{
|
|
|
|
$event['end-nextday'] = $event['end'] + 12*3600; // we need the date of the next day, as DTEND is non-inclusive (= exclusive) in rfc2445
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach (array('start' => 'DTSTART','end-nextday' => 'DTEND') as $f => $t)
|
2009-07-28 10:58:39 +02:00
|
|
|
{
|
|
|
|
$arr = $this->date2array($event[$f]);
|
|
|
|
$vevent->setAttribute($t, array('year' => $arr['year'],'month' => $arr['month'],'mday' => $arr['day']),
|
|
|
|
array('VALUE' => 'DATE'));
|
|
|
|
}
|
|
|
|
unset($attributes['DTSTART']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-10 16:08:35 +01:00
|
|
|
$attributes['DTEND'] = self::getDateTime($event['end'],$tzid,$parameters['DTEND']);
|
2009-07-28 10:58:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-07-28 10:58:39 +02:00
|
|
|
case 'RRULE':
|
|
|
|
if ($event['recur_type'] == MCAL_RECUR_NONE) break; // no recuring event
|
2009-11-13 08:52:06 +01:00
|
|
|
$rriter = calendar_rrule::event2rrule($event,$date_format != 'server');
|
2009-11-12 20:08:23 +01:00
|
|
|
$rrule = $rriter->generate_rrule($version);
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($version == '1.0')
|
|
|
|
{
|
2009-10-29 20:42:32 +01:00
|
|
|
$attributes['RRULE'] = $rrule['FREQ'].' '.$rrule['UNTIL'];
|
2009-10-19 22:46:23 +02:00
|
|
|
}
|
2009-10-29 20:42:32 +01:00
|
|
|
else // $version == '2.0'
|
2009-10-19 22:46:23 +02:00
|
|
|
{
|
2009-10-29 20:42:32 +01:00
|
|
|
$attributes['RRULE'] = '';
|
|
|
|
$parameters['RRULE'] = $rrule;
|
2009-07-28 10:58:39 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-07-28 10:58:39 +02:00
|
|
|
case 'EXDATE':
|
|
|
|
if ($event['recur_type'] == MCAL_RECUR_NONE) break;
|
|
|
|
$days = array();
|
|
|
|
// dont use "virtual" exceptions created by participant status for GroupDAV or file export
|
|
|
|
if (!in_array($this->productManufacturer,array('file','groupdav')))
|
|
|
|
{
|
2009-11-19 11:13:17 +01:00
|
|
|
$tz_id = ($tzid != $event['tzid'] ? $tzid : null);
|
|
|
|
$days = $this->so->get_recurrence_exceptions($event, $tz_id);
|
2009-07-28 10:58:39 +02:00
|
|
|
}
|
|
|
|
if (is_array($event['recur_exception']))
|
|
|
|
{
|
|
|
|
$days = array_merge($days,$event['recur_exception']); // can NOT use +, as it overwrites numeric indexes
|
|
|
|
}
|
|
|
|
if (!empty($days))
|
|
|
|
{
|
|
|
|
$days = array_unique($days);
|
|
|
|
sort($days);
|
|
|
|
// use 'DATE' instead of 'DATE-TIME' on whole day events
|
|
|
|
if ($this->isWholeDay($event))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-07-28 10:58:39 +02:00
|
|
|
$value_type = 'DATE';
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach ($days as $id => $timestamp)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-07-28 10:58:39 +02:00
|
|
|
$arr = $this->date2array($timestamp);
|
|
|
|
$days[$id] = array(
|
|
|
|
'year' => $arr['year'],
|
|
|
|
'month' => $arr['month'],
|
|
|
|
'mday' => $arr['day'],
|
|
|
|
);
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
}
|
2009-07-28 10:58:39 +02:00
|
|
|
else
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-07-28 10:58:39 +02:00
|
|
|
$value_type = 'DATE-TIME';
|
2009-11-10 16:08:35 +01:00
|
|
|
foreach ($days as &$timestamp)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-11-10 16:08:35 +01:00
|
|
|
$timestamp = self::getDateTime($timestamp,$tzid,$parameters['EXDATE']);
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
}
|
2009-07-28 10:58:39 +02:00
|
|
|
$attributes['EXDATE'] = '';
|
|
|
|
$values['EXDATE'] = $days;
|
|
|
|
$parameters['EXDATE']['VALUE'] = $value_type;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'PRIORITY':
|
2010-01-02 14:25:58 +01:00
|
|
|
if($this->productManufacturer == 'funambol')
|
|
|
|
{
|
|
|
|
$attributes['PRIORITY'] = (int) $this->priority_egw2funambol[$event['priority']];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$attributes['PRIORITY'] = (int) $this->priority_egw2ical[$event['priority']];
|
|
|
|
}
|
|
|
|
break;
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-10-12 17:44:52 +02:00
|
|
|
case 'TRANSP':
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($version == '1.0')
|
|
|
|
{
|
2009-07-28 10:58:39 +02:00
|
|
|
$attributes['TRANSP'] = ($event['non_blocking'] ? 1 : 0);
|
2009-10-25 19:22:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-28 10:58:39 +02:00
|
|
|
$attributes['TRANSP'] = ($event['non_blocking'] ? 'TRANSPARENT' : 'OPAQUE');
|
|
|
|
}
|
|
|
|
break;
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-07-28 10:58:39 +02:00
|
|
|
case 'CATEGORIES':
|
|
|
|
if ($event['category'])
|
|
|
|
{
|
|
|
|
$attributes['CATEGORIES'] = '';
|
|
|
|
$values['CATEGORIES'] = $this->get_categories($event['category']);
|
|
|
|
}
|
|
|
|
break;
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-07-28 10:58:39 +02:00
|
|
|
case 'RECURRENCE-ID':
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($version == '1.0')
|
|
|
|
{
|
|
|
|
$icalFieldName = 'X-RECURRENCE-ID';
|
|
|
|
}
|
2009-07-28 10:58:39 +02:00
|
|
|
if ($recur_date)
|
|
|
|
{
|
|
|
|
// We handle a status only exception
|
|
|
|
if ($this->isWholeDay($event))
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-07-28 10:58:39 +02:00
|
|
|
$arr = $this->date2array($recur_date);
|
2009-10-25 19:22:01 +01:00
|
|
|
$vevent->setAttribute($icalFieldName, array(
|
2009-07-28 10:58:39 +02:00
|
|
|
'year' => $arr['year'],
|
|
|
|
'month' => $arr['month'],
|
|
|
|
'mday' => $arr['day']),
|
|
|
|
array('VALUE' => 'DATE')
|
|
|
|
);
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-07-28 10:58:39 +02:00
|
|
|
else
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-11-10 16:08:35 +01:00
|
|
|
$attributes[$icalFieldName] = self::getDateTime($recur_date,$tzid,$parameters[$icalFieldName]);
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2009-07-28 10:58:39 +02:00
|
|
|
}
|
|
|
|
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
|
2009-07-17 12:15:22 +02:00
|
|
|
|
2009-07-28 10:58:39 +02:00
|
|
|
if ($this->isWholeDay($revent))
|
|
|
|
{
|
2009-08-23 21:26:14 +02:00
|
|
|
$arr = $this->date2array($event['recurrence']);
|
2009-10-25 19:22:01 +01:00
|
|
|
$vevent->setAttribute($icalFieldName, array(
|
2009-07-28 10:58:39 +02:00
|
|
|
'year' => $arr['year'],
|
|
|
|
'month' => $arr['month'],
|
|
|
|
'mday' => $arr['day']),
|
|
|
|
array('VALUE' => 'DATE')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-23 14:03:35 +01:00
|
|
|
$attributes[$icalFieldName] = self::getDateTime($event['recurrence'],$tzid,$parameters[$icalFieldName]);
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-07-28 10:58:39 +02:00
|
|
|
unset($revent);
|
|
|
|
}
|
|
|
|
break;
|
2009-07-15 22:35:56 +02:00
|
|
|
|
2009-07-28 10:58:39 +02:00
|
|
|
default:
|
2009-10-25 19:22:01 +01:00
|
|
|
if (isset($this->clientProperties[$icalFieldName]['Size']))
|
|
|
|
{
|
2009-07-28 10:58:39 +02:00
|
|
|
$size = $this->clientProperties[$icalFieldName]['Size'];
|
|
|
|
$noTruncate = $this->clientProperties[$icalFieldName]['NoTruncate'];
|
|
|
|
#Horde::logMessage("vCalendar $icalFieldName Size: $size, NoTruncate: " .
|
|
|
|
# ($noTruncate ? 'TRUE' : 'FALSE'), __FILE__, __LINE__, PEAR_LOG_DEBUG);
|
2009-10-25 19:22:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-28 10:58:39 +02:00
|
|
|
$size = -1;
|
|
|
|
$noTruncate = false;
|
|
|
|
}
|
|
|
|
$value = $event[$egwFieldName];
|
|
|
|
$cursize = strlen($value);
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($size > 0 && $cursize > $size)
|
|
|
|
{
|
|
|
|
if ($noTruncate)
|
|
|
|
{
|
2009-07-28 10:58:39 +02:00
|
|
|
Horde::logMessage("vCalendar $icalFieldName omitted due to maximum size $size",
|
|
|
|
__FILE__, __LINE__, PEAR_LOG_WARNING);
|
|
|
|
continue; // skip field
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2009-07-28 10:58:39 +02:00
|
|
|
// truncate the value to size
|
|
|
|
$value = substr($value, 0, $size - 1);
|
|
|
|
Horde::logMessage("vCalendar $icalFieldName truncated to maximum size $size",
|
|
|
|
__FILE__, __LINE__, PEAR_LOG_INFO);
|
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
if (!empty($value) || ($size >= 0 && !$noTruncate))
|
|
|
|
{
|
2009-07-28 10:58:39 +02:00
|
|
|
$attributes[$icalFieldName] = $value;
|
|
|
|
}
|
|
|
|
break;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($this->productManufacturer == 'nokia')
|
|
|
|
{
|
|
|
|
if ($event['special'] == '1')
|
|
|
|
{
|
2008-06-07 19:45:33 +02:00
|
|
|
$attributes['X-EPOCAGENDAENTRYTYPE'] = 'ANNIVERSARY';
|
|
|
|
$attributes['DTEND'] = $attributes['DTSTART'];
|
2008-09-03 19:13:54 +02:00
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
elseif ($event['special'] == '2')
|
|
|
|
{
|
2008-09-03 19:13:54 +02:00
|
|
|
$attributes['X-EPOCAGENDAENTRYTYPE'] = 'EVENT';
|
2009-10-25 19:22:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-07 19:45:33 +02:00
|
|
|
$attributes['X-EPOCAGENDAENTRYTYPE'] = 'APPOINTMENT';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-03 08:44:02 +01:00
|
|
|
$modified = $GLOBALS['egw']->contenthistory->getTSforAction('calendar',$event['id'],'modify');
|
|
|
|
$created = $GLOBALS['egw']->contenthistory->getTSforAction('calendar',$event['id'],'add');
|
2008-06-07 19:45:33 +02:00
|
|
|
if (!$created && !$modified) $created = $event['modified'];
|
2009-07-15 22:35:56 +02:00
|
|
|
if ($created)
|
|
|
|
{
|
2009-10-05 23:00:08 +02:00
|
|
|
$attributes['CREATED'] = $created;
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
if (!$modified) $modified = $event['modified'];
|
2009-07-15 22:35:56 +02:00
|
|
|
if ($modified)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-10-05 23:00:08 +02:00
|
|
|
$attributes['LAST-MODIFIED'] = $modified;
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
$attributes['DTSTAMP'] = time();
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach ($event['alarm'] as $alarmID => $alarmData)
|
2009-08-23 21:26:14 +02:00
|
|
|
{
|
2009-10-30 22:39:19 +01:00
|
|
|
// skip alarms not being set for all users and alarms owned by other users
|
|
|
|
if ($alarmData['all'] != true && $alarmData['owner'] != $this->user)
|
2009-09-23 10:08:37 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-08-23 21:26:14 +02:00
|
|
|
if ($version == '1.0')
|
|
|
|
{
|
2009-11-10 16:08:35 +01:00
|
|
|
$attributes['DALARM'] = self::getDateTime($alarmData['time'],$tzid,$parameters['DALARM']);
|
|
|
|
$attributes['AALARM'] = self::getDateTime($alarmData['time'],$tzid,$parameters['AALARM']);
|
2009-07-15 22:35:56 +02:00
|
|
|
// lets take only the first alarm
|
|
|
|
break;
|
2009-08-23 21:26:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-07 19:45:33 +02:00
|
|
|
// VCalendar 2.0 / RFC 2445
|
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
$description = trim(preg_replace("/\r?\n?\\[[A-Z_]+:.*\\]/i", '', $event['description']));
|
|
|
|
|
2008-06-07 19:45:33 +02:00
|
|
|
// skip over alarms that don't have the minimum required info
|
2009-08-23 21:26:14 +02:00
|
|
|
if (!$alarmData['offset'] && !$alarmData['time']) continue;
|
2008-06-07 19:45:33 +02:00
|
|
|
|
|
|
|
// RFC requires DESCRIPTION for DISPLAY
|
2009-08-23 21:26:14 +02:00
|
|
|
if (!$event['title'] && !$description) continue;
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-10-05 23:00:08 +02:00
|
|
|
if ($this->isWholeDay($event) && $alarmData['offset'])
|
|
|
|
{
|
|
|
|
$alarmData['time'] = $event['start'] - $alarmData['offset'];
|
|
|
|
$alarmData['offset'] = false;
|
|
|
|
}
|
|
|
|
|
2008-06-07 19:45:33 +02:00
|
|
|
$valarm = Horde_iCalendar::newComponent('VALARM',$vevent);
|
2009-08-23 21:26:14 +02:00
|
|
|
if ($alarmData['offset'])
|
|
|
|
{
|
2008-06-07 19:45:33 +02:00
|
|
|
$valarm->setAttribute('TRIGGER', -$alarmData['offset'],
|
|
|
|
array('VALUE' => 'DURATION', 'RELATED' => 'START'));
|
2009-08-23 21:26:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-05 23:00:08 +02:00
|
|
|
$params = array('VALUE' => 'DATE-TIME');
|
2009-11-10 16:08:35 +01:00
|
|
|
$value = self::getDateTime($alarmData['time'],$tzid,$params);
|
2009-10-05 23:00:08 +02:00
|
|
|
$valarm->setAttribute('TRIGGER', $value, $params);
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$valarm->setAttribute('ACTION','DISPLAY');
|
2009-07-15 22:35:56 +02:00
|
|
|
$valarm->setAttribute('DESCRIPTION',$event['title'] ? $event['title'] : $description);
|
2008-06-07 19:45:33 +02:00
|
|
|
$vevent->addComponent($valarm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach ($attributes as $key => $value)
|
2009-08-23 21:26:14 +02:00
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach (is_array($value)&&$parameters[$key]['VALUE']!='DATE' ? $value : array($value) as $valueID => $valueData)
|
2009-08-23 21:26:14 +02:00
|
|
|
{
|
2008-06-07 19:45:33 +02:00
|
|
|
$valueData = $GLOBALS['egw']->translation->convert($valueData,$GLOBALS['egw']->translation->charset(),'UTF-8');
|
2009-07-15 22:35:56 +02:00
|
|
|
$paramData = (array) $GLOBALS['egw']->translation->convert(is_array($value) ?
|
|
|
|
$parameters[$key][$valueID] : $parameters[$key],
|
|
|
|
$GLOBALS['egw']->translation->charset(),'UTF-8');
|
|
|
|
$valuesData = (array) $GLOBALS['egw']->translation->convert($values[$key],
|
|
|
|
$GLOBALS['egw']->translation->charset(),'UTF-8');
|
|
|
|
//echo "$key:$valueID: value=$valueData, param=".print_r($paramDate,true)."\n";
|
|
|
|
$vevent->setAttribute($key, $valueData, $paramData, true, $valuesData);
|
2008-06-07 19:45:33 +02:00
|
|
|
$options = array();
|
2008-11-12 14:52:38 +01:00
|
|
|
if ($paramData['CN']) $valueData .= $paramData['CN']; // attendees or organizer CN can contain utf-8 content
|
2009-07-15 22:35:56 +02:00
|
|
|
/*if($key != 'RRULE' && preg_match('/([\000-\012\015\016\020-\037\075])/',$valueData)) {
|
|
|
|
$options['ENCODING'] = 'QUOTED-PRINTABLE';
|
|
|
|
}*/
|
|
|
|
if ($this->productManufacturer != 'groupdav' && preg_match('/([\177-\377])/', $valueData))
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
|
|
|
$options['CHARSET'] = 'UTF-8';
|
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
if (preg_match('/([\000-\012])/', $valueData))
|
2009-04-02 14:35:26 +02:00
|
|
|
{
|
2009-11-11 22:31:33 +01:00
|
|
|
if ($this->log) error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."() Has invalid XML data: $valueData",3,$this->logfile);
|
2009-04-02 14:35:26 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
$vevent->setParameter($key, $options);
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$vcal->addComponent($vevent);
|
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
|
|
|
|
$retval = $vcal->exportvCalendar();
|
2009-11-11 22:31:33 +01:00
|
|
|
if ($this->log) error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n".array2string($retval)."\n",3,$this->logfile);
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-11-23 14:03:35 +01:00
|
|
|
return $retval;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
|
2009-11-10 16:08:35 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @param array &$params=null parameter array to set TZID
|
|
|
|
* @return mixed attribute value to set: integer timestamp if $tzid == 'UTC' otherwise Ymd\THis string IN $tzid
|
|
|
|
*/
|
|
|
|
static function getDateTime($time,$tzid,array &$params=null)
|
|
|
|
{
|
|
|
|
if (empty($tzid) || $tzid == 'UTC')
|
|
|
|
{
|
|
|
|
return egw_time::to($time,'ts');
|
|
|
|
}
|
|
|
|
if (!is_a($time,'DateTime'))
|
|
|
|
{
|
|
|
|
$time = new egw_time($time,egw_time::$server_timezone);
|
|
|
|
}
|
2009-11-19 11:13:17 +01:00
|
|
|
if (!isset(self::$tz_cache[$tzid]))
|
2009-11-10 16:08:35 +01:00
|
|
|
{
|
2009-11-19 11:13:17 +01:00
|
|
|
self::$tz_cache[$tzid] = calendar_timezones::DateTimeZone($tzid);
|
2009-11-10 16:08:35 +01:00
|
|
|
}
|
2009-11-19 11:13:17 +01:00
|
|
|
$time->setTimezone(self::$tz_cache[$tzid]);
|
2009-11-10 16:08:35 +01:00
|
|
|
$params['TZID'] = $tzid;
|
|
|
|
|
|
|
|
return $time->format('Ymd\THis');
|
|
|
|
}
|
|
|
|
|
2008-06-07 19:45:33 +02:00
|
|
|
/**
|
|
|
|
* Import an iCal
|
|
|
|
*
|
|
|
|
* @param string $_vcalData
|
2009-07-15 22:35:56 +02:00
|
|
|
* @param int $cal_id=-1 must be -1 for new entries!
|
2008-06-07 19:45:33 +02:00
|
|
|
* @param string $etag=null if an etag is given, it has to match the current etag or the import will fail
|
2009-07-15 22:35:56 +02:00
|
|
|
* @param boolean $merge=false merge data with existing entry
|
2009-09-22 15:43:55 +02:00
|
|
|
* @param int $recur_date=0 if set, import the recurrence at this timestamp,
|
2009-07-15 22:35:56 +02:00
|
|
|
* default 0 => import whole series (or events, if not recurring)
|
2008-06-07 19:45:33 +02:00
|
|
|
* @return int|boolean cal_id > 0 on success, false on failure or 0 for a failed etag
|
|
|
|
*/
|
2009-07-15 22:35:56 +02:00
|
|
|
function importVCal($_vcalData, $cal_id=-1, $etag=null, $merge=false, $recur_date=0)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-11-11 22:31:33 +01:00
|
|
|
if ($this->log) error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n".array2string($_vcalData)."\n",3,$this->logfile);
|
2009-07-15 22:35:56 +02:00
|
|
|
|
2009-10-25 19:22:01 +01:00
|
|
|
if (!($events = $this->icaltoegw($_vcalData,$cal_id,$etag,$recur_date)))
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
return false;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
if (!is_array($this->supportedFields)) $this->setSupportedFields();
|
|
|
|
|
2009-12-27 05:21:33 +01:00
|
|
|
// check if we are importing an event series with exceptions in CalDAV
|
|
|
|
// only first event / series master get's cal_id from URL
|
|
|
|
// other events are exceptions and need to be checked if they are new
|
|
|
|
// and for real (not status only) exceptions their recurrence-id need
|
|
|
|
// to be included as recur_exception to the master
|
2009-12-27 16:49:40 +01:00
|
|
|
if ($this->productManufacturer == 'groupdav' && $cal_id > 0 &&
|
|
|
|
count($events) > 1 && !$events[1]['id'] &&
|
2009-12-27 05:21:33 +01:00
|
|
|
$events[0]['recur_type'] != MCAL_RECUR_NONE)
|
|
|
|
{
|
|
|
|
calendar_groupdav::fix_series($events);
|
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
foreach ($events as $event)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
$updated_id = false;
|
|
|
|
$event_info = $this->get_event_info($event);
|
2009-07-15 22:35:56 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
// common adjustments for new events
|
2009-10-25 19:22:01 +01:00
|
|
|
if (!is_array($event_info['stored_event']))
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
|
|
|
// set non blocking all day depending on the user setting
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($this->isWholeDay($event) && $this->nonBlockingAllday)
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
|
|
|
$event['non_blocking'] = 1;
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
// check if an owner is set and the current user has add rights
|
|
|
|
// for that owners calendar; if not set the current user
|
2009-10-25 19:22:01 +01:00
|
|
|
if (!isset($event['owner'])
|
|
|
|
|| !$this->check_perms(EGW_ACL_ADD, 0, $event['owner']))
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
$event['owner'] = $this->user;
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-11-26 19:36:19 +01:00
|
|
|
if (!is_array($event['participants']) || !count($event['participants']))
|
|
|
|
{
|
|
|
|
$status = $event['owner'] == $this->user ? 'A' : 'U';
|
|
|
|
$status = calendar_so::combine_status($status, 1, 'CHAIR');
|
|
|
|
$event['participants'] = array($event['owner'] => $status);
|
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
// common adjustments for existing events
|
2009-10-01 15:30:18 +02:00
|
|
|
if (is_array($event_info['stored_event']))
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
|
|
|
if ($merge)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
|
|
|
// overwrite with server data for merge
|
2009-09-22 15:43:55 +02:00
|
|
|
foreach ($event_info['stored_event'] as $key => $value)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
switch ($key)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
case 'participants_types':
|
|
|
|
continue;
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
case 'participants':
|
2009-09-22 15:43:55 +02:00
|
|
|
foreach ($event_info['stored_event']['participants'] as $uid => $status)
|
|
|
|
{
|
|
|
|
// Is a participant and no longer present in the event?
|
|
|
|
if (!isset($event['participants'][$uid]))
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
// Add it back in
|
|
|
|
$event['participants'][$uid] = $event['participant_types']['r'][substr($uid,1)] = $status;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
default:
|
2009-09-22 15:43:55 +02:00
|
|
|
if (!empty($value))
|
|
|
|
{
|
|
|
|
$event[$key] = $value;
|
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// no merge
|
|
|
|
if (!isset($this->supportedFields['participants']) || !count($event['participants']))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
// If this is an updated meeting, and the client doesn't support
|
|
|
|
// participants OR the event no longer contains participants, add them back
|
|
|
|
$event['participants'] = $event_info['stored_event']['participants'];
|
|
|
|
$event['participant_types'] = $event_info['stored_event']['participant_types'];
|
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
foreach ($event_info['stored_event']['participants'] as $uid => $status)
|
|
|
|
{
|
|
|
|
// Is it a resource and no longer present in the event?
|
|
|
|
if ( $uid[0] == 'r' && !isset($event['participants'][$uid]) )
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
// Add it back in
|
|
|
|
$event['participants'][$uid] = $event['participant_types']['r'][substr($uid,1)] = $status;
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
// avoid that iCal changes the organizer, which is not allowed
|
|
|
|
$event['owner'] = $event_info['stored_event']['owner'];
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
|
2009-11-03 17:31:07 +01:00
|
|
|
// update alarms depending on the given event type
|
|
|
|
if (count($event['alarm']) > 0 || isset($this->supportedFields['alarm']))
|
|
|
|
{
|
|
|
|
switch ($event_info['type'])
|
|
|
|
{
|
|
|
|
case 'SINGLE':
|
|
|
|
case 'SERIES-MASTER':
|
|
|
|
case 'SERIES-EXCEPTION':
|
|
|
|
case 'SERIES-EXCEPTION-PROPAGATE':
|
|
|
|
if (count($event['alarm']) > 0)
|
|
|
|
{
|
|
|
|
foreach ($event['alarm'] as $newid => &$alarm)
|
|
|
|
{
|
|
|
|
if (!isset($alarm['offset']) && isset($alarm['time']))
|
|
|
|
{
|
|
|
|
$alarm['offset'] = $event['start'] - $alarm['time'];
|
|
|
|
}
|
|
|
|
if (!isset($alarm['time']) && isset($alarm['offset']))
|
|
|
|
{
|
|
|
|
$alarm['time'] = $event['start'] - $alarm['offset'];
|
|
|
|
}
|
|
|
|
$alarm['owner'] = $this->user;
|
|
|
|
$alarm['all'] = false;
|
|
|
|
|
|
|
|
if (is_array($event_info['stored_event'])
|
|
|
|
&& count($event_info['stored_event']['alarm']) > 0)
|
|
|
|
{
|
|
|
|
foreach ($event_info['stored_event']['alarm'] as $alarm_id => $alarm_data)
|
|
|
|
{
|
|
|
|
if ($alarm['time'] == $alarm_data['time'] &&
|
|
|
|
($alarm_data['all'] || $alarm_data['owner'] == $this->user))
|
|
|
|
{
|
|
|
|
unset($event['alarm'][$newid]);
|
|
|
|
unset($event_info['stored_event']['alarm'][$alarm_id]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'SERIES-EXCEPTION-STATUS':
|
|
|
|
// nothing to do here
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (is_array($event_info['stored_event'])
|
|
|
|
&& count($event_info['stored_event']['alarm']) > 0)
|
|
|
|
{
|
|
|
|
foreach ($event_info['stored_event']['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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
// save event depending on the given event type
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($event_info['type'])
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
|
|
|
case 'SINGLE':
|
|
|
|
Horde::logMessage('importVCAL event SINGLE',__FILE__, __LINE__, PEAR_LOG_DEBUG);
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
// update the event
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($event_info['acl_edit'])
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
|
|
|
$event_to_store = $event; // prevent $event from being changed by the update method
|
|
|
|
$updated_id = $this->update($event_to_store, true);
|
|
|
|
unset($event_to_store);
|
|
|
|
}
|
|
|
|
break;
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
case 'SERIES-MASTER':
|
|
|
|
Horde::logMessage('importVCAL event SERIES-MASTER',__FILE__, __LINE__, PEAR_LOG_DEBUG);
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
// remove all known "status only" exceptions and update the event
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($event_info['acl_edit'])
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
$days = $this->so->get_recurrence_exceptions($event);
|
2009-10-25 19:22:01 +01:00
|
|
|
if (is_array($days))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
$recur_exceptions = array();
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach ($event['recur_exception'] as $recur_exception)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
if (!in_array($recur_exception, $days))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
$recur_exceptions[] = $recur_exception;
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
$event['recur_exception'] = $recur_exceptions;
|
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
$event_to_store = $event; // prevent $event from being changed by the update method
|
|
|
|
$updated_id = $this->update($event_to_store, true);
|
|
|
|
unset($event_to_store);
|
|
|
|
}
|
|
|
|
break;
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
case 'SERIES-EXCEPTION':
|
2009-10-01 15:30:18 +02:00
|
|
|
case 'SERIES-EXCEPTION-PROPAGATE':
|
2009-09-22 15:43:55 +02:00
|
|
|
Horde::logMessage('importVCAL event SERIES-EXCEPTION',__FILE__, __LINE__, PEAR_LOG_DEBUG);
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
// update event
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($event_info['acl_edit'])
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
if (isset($event_info['stored_event']['id']))
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
|
|
|
// We update an existing exception
|
|
|
|
$event['id'] = $event_info['stored_event']['id'];
|
|
|
|
$event['category'] = $event_info['stored_event']['category'];
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
// We create a new exception
|
|
|
|
unset($event['id']);
|
|
|
|
$event_info['master_event']['recur_exception'] = array_unique(array_merge($event_info['master_event']['recur_exception'], array($event['recurrence'])));
|
|
|
|
$event_to_store = $event_info['master_event']; // prevent the master_event from being changed by the update method
|
|
|
|
$this->update($event_to_store, true);
|
|
|
|
unset($event_to_store);
|
|
|
|
$event['reference'] = $event_info['master_event']['id'];
|
|
|
|
$event['category'] = $event_info['master_event']['category'];
|
2009-11-29 15:03:45 +01:00
|
|
|
$event['owner'] = $event_info['master_event']['owner'];
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
$event_to_store = $event; // prevent $event from being changed by update method
|
2009-10-25 19:22:01 +01:00
|
|
|
$updated_id = $this->update($event_to_store, true, true, false, false);
|
2009-09-22 15:43:55 +02:00
|
|
|
unset($event_to_store);
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
break;
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
case 'SERIES-EXCEPTION-STATUS':
|
|
|
|
Horde::logMessage('importVCAL event SERIES-EXCEPTION-STATUS',__FILE__, __LINE__, PEAR_LOG_DEBUG);
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($event_info['acl_edit'])
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
// truncate the status only exception from the series master
|
2009-07-15 22:35:56 +02:00
|
|
|
$recur_exceptions = array();
|
2009-09-22 15:43:55 +02:00
|
|
|
foreach ($event_info['master_event']['recur_exception'] as $recur_exception)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
if ($recur_exception != $event['recurrence'])
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$recur_exceptions[] = $recur_exception;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
$event_info['master_event']['recur_exception'] = $recur_exceptions;
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
// save the series master with the adjusted exceptions
|
|
|
|
$event_to_store = $event_info['master_event']; // prevent the master_event from being changed by the update method
|
2009-10-25 19:22:01 +01:00
|
|
|
$updated_id = $this->update($event_to_store, true, true, false, false);
|
2009-09-22 15:43:55 +02:00
|
|
|
unset($event_to_store);
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
break;
|
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
// read stored event into info array for fresh stored (new) events
|
2009-10-25 19:22:01 +01:00
|
|
|
if (!is_array($event_info['stored_event']) && $updated_id > 0)
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
|
|
|
$event_info['stored_event'] = $this->read($updated_id);
|
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
// update status depending on the given event type
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($event_info['type'])
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
|
|
|
case 'SINGLE':
|
|
|
|
case 'SERIES-MASTER':
|
|
|
|
case 'SERIES-EXCEPTION':
|
2009-10-01 15:30:18 +02:00
|
|
|
case 'SERIES-EXCEPTION-PROPAGATE':
|
2009-10-25 19:22:01 +01:00
|
|
|
if (is_array($event_info['stored_event'])) // status update requires a stored event
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($event_info['acl_edit'])
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
// update all participants if we have the right to do that
|
|
|
|
$this->update_status($event, $event_info['stored_event']);
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
elseif (isset($event['participants'][$this->user]) || isset($event_info['stored_event']['participants'][$this->user]))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
// update the users status only
|
|
|
|
$this->set_status($event_info['stored_event']['id'], $this->user,
|
|
|
|
($event['participants'][$this->user] ? $event['participants'][$this->user] : 'R'), 0, true);
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
break;
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
case 'SERIES-EXCEPTION-STATUS':
|
2009-10-25 19:22:01 +01:00
|
|
|
if (is_array($event_info['master_event'])) // status update requires a stored master event
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($event_info['acl_edit'])
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
// update all participants if we have the right to do that
|
2009-10-01 15:30:18 +02:00
|
|
|
$this->update_status($event, $event_info['master_event'], $event['recurrence']);
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
elseif (isset($event['participants'][$this->user]) || isset($event_info['master_event']['participants'][$this->user]))
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
// update the users status only
|
|
|
|
$this->set_status($event_info['master_event']['id'], $this->user,
|
|
|
|
($event['participants'][$this->user] ? $event['participants'][$this->user] : 'R'), $event['recurrence'], true);
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
break;
|
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
// choose which id to return to the client
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($event_info['type'])
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
|
|
|
case 'SINGLE':
|
|
|
|
case 'SERIES-MASTER':
|
|
|
|
case 'SERIES-EXCEPTION':
|
|
|
|
$return_id = is_array($event_info['stored_event']) ? $event_info['stored_event']['id'] : false;
|
|
|
|
break;
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
case 'SERIES-EXCEPTION-STATUS':
|
|
|
|
$return_id = is_array($event_info['master_event']) ? $event_info['master_event']['id'] . ':' . $event['recurrence'] : false;
|
|
|
|
break;
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-10-01 15:30:18 +02:00
|
|
|
case 'SERIES-EXCEPTION-PROPAGATE':
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($event_info['acl_edit'] && is_array($event_info['stored_event']))
|
2009-10-01 15:30:18 +02:00
|
|
|
{
|
|
|
|
// we had sufficient rights to propagate the status only exception to a real one
|
|
|
|
$return_id = $event_info['stored_event']['id'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// we did not have sufficient rights to propagate the status only exception to a real one
|
|
|
|
// we have to keep the SERIES-EXCEPTION-STATUS id and keep the event untouched
|
|
|
|
$return_id = $event_info['master_event']['id'] . ':' . $event['recurrence'];
|
|
|
|
}
|
|
|
|
break;
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
|
|
|
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($this->log)
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
2009-11-26 19:36:19 +01:00
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n".array2string($event_info['stored_event'])."\n",3,$this->logfile);
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
return $return_id;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the value of an attribute by its name
|
|
|
|
*
|
|
|
|
* @param array $attributes
|
|
|
|
* @param string $name eg. 'DTSTART'
|
|
|
|
* @param string $what='value'
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
static function _get_attribute($components,$name,$what='value')
|
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach ($components as $attribute)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
|
|
|
if ($attribute['name'] == $name)
|
|
|
|
{
|
|
|
|
return !$what ? $attribute : $attribute[$what];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static function valarm2egw(&$alarms, &$valarm)
|
|
|
|
{
|
|
|
|
$count = 0;
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach ($valarm->_attributes as $vattr)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($vattr['name'])
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
|
|
|
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;
|
2009-07-15 22:35:56 +02:00
|
|
|
case 'ACTION':
|
|
|
|
case 'DISPLAY':
|
|
|
|
case 'DESCRIPTION':
|
|
|
|
case 'SUMMARY':
|
|
|
|
case 'ATTACH':
|
|
|
|
case 'ATTENDEE':
|
|
|
|
// we ignore these fields silently
|
|
|
|
break;
|
2008-06-07 19:45:33 +02:00
|
|
|
|
|
|
|
default:
|
2009-07-15 22:35:56 +02:00
|
|
|
error_log('VALARM field ' .$vattr['name'] . ': ' . $vattr['value'] . ' HAS NO CONVERSION YET');
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $count;
|
|
|
|
}
|
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
function setSupportedFields($_productManufacturer='', $_productName='')
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$state = &$_SESSION['SyncML.state'];
|
2009-10-25 19:22:01 +01:00
|
|
|
if (isset($state))
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$deviceInfo = $state->getClientDeviceInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
// store product manufacturer and name, to be able to use it elsewhere
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($_productManufacturer)
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$this->productManufacturer = strtolower($_productManufacturer);
|
|
|
|
$this->productName = strtolower($_productName);
|
|
|
|
}
|
|
|
|
|
2009-10-25 19:22:01 +01:00
|
|
|
if (isset($deviceInfo) && is_array($deviceInfo))
|
|
|
|
{
|
|
|
|
if (isset($deviceInfo['uidExtension']) &&
|
|
|
|
$deviceInfo['uidExtension'])
|
|
|
|
{
|
|
|
|
$this->uidExtension = true;
|
|
|
|
}
|
|
|
|
if (isset($deviceInfo['nonBlockingAllday']) &&
|
|
|
|
$deviceInfo['nonBlockingAllday'])
|
|
|
|
{
|
|
|
|
$this->nonBlockingAllday = true;
|
|
|
|
}
|
2009-11-11 22:31:33 +01:00
|
|
|
if (isset($deviceInfo['tzid']) &&
|
|
|
|
$deviceInfo['tzid'])
|
|
|
|
{
|
|
|
|
$this->tzid = $deviceInfo['tzid'];
|
|
|
|
}
|
2009-11-29 15:03:45 +01:00
|
|
|
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->calendarOwner = $owner;
|
|
|
|
}
|
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
if (!isset($this->productManufacturer) ||
|
2009-07-15 22:35:56 +02:00
|
|
|
$this->productManufacturer == '' ||
|
2009-10-25 19:22:01 +01:00
|
|
|
$this->productManufacturer == 'file')
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$this->productManufacturer = strtolower($deviceInfo['manufacturer']);
|
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
if (!isset($this->productName) || $this->productName == '')
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$this->productName = strtolower($deviceInfo['model']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Horde::logMessage('setSupportedFields(' . $this->productManufacturer
|
|
|
|
. ', ' . $this->productName .')', __FILE__, __LINE__, PEAR_LOG_DEBUG);
|
2008-06-07 19:45:33 +02:00
|
|
|
|
|
|
|
$defaultFields['minimal'] = array(
|
|
|
|
'public' => 'public',
|
|
|
|
'description' => 'description',
|
|
|
|
'end' => 'end',
|
|
|
|
'start' => 'start',
|
|
|
|
'location' => 'location',
|
|
|
|
'recur_type' => 'recur_type',
|
|
|
|
'recur_interval' => 'recur_interval',
|
|
|
|
'recur_data' => 'recur_data',
|
|
|
|
'recur_enddate' => 'recur_enddate',
|
|
|
|
'title' => 'title',
|
2009-07-15 22:35:56 +02:00
|
|
|
'alarm' => 'alarm',
|
2008-06-07 19:45:33 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$defaultFields['basic'] = $defaultFields['minimal'] + array(
|
|
|
|
'recur_exception' => 'recur_exception',
|
|
|
|
'priority' => 'priority',
|
|
|
|
);
|
|
|
|
|
|
|
|
$defaultFields['nexthaus'] = $defaultFields['basic'] + array(
|
|
|
|
'participants' => 'participants',
|
2009-07-15 22:35:56 +02:00
|
|
|
'uid' => 'uid',
|
|
|
|
);
|
|
|
|
|
|
|
|
$defaultFields['s60'] = $defaultFields['basic'] + array(
|
|
|
|
'category' => 'category',
|
|
|
|
'uid' => 'uid',
|
2008-06-07 19:45:33 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$defaultFields['synthesis'] = $defaultFields['basic'] + array(
|
2009-07-15 22:35:56 +02:00
|
|
|
'participants' => 'participants',
|
|
|
|
'owner' => 'owner',
|
2008-06-07 19:45:33 +02:00
|
|
|
'category' => 'category',
|
2009-07-15 22:35:56 +02:00
|
|
|
'non_blocking' => 'non_blocking',
|
|
|
|
'uid' => 'uid',
|
2009-08-17 12:34:22 +02:00
|
|
|
'recurrence' => 'recurrence',
|
2009-10-25 19:22:01 +01:00
|
|
|
'etag' => 'etag',
|
2008-06-07 19:45:33 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$defaultFields['evolution'] = $defaultFields['basic'] + array(
|
|
|
|
'participants' => 'participants',
|
|
|
|
'owner' => 'owner',
|
|
|
|
'category' => 'category',
|
2009-07-15 22:35:56 +02:00
|
|
|
'uid' => 'uid',
|
2008-06-07 19:45:33 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$defaultFields['full'] = $defaultFields['basic'] + array(
|
|
|
|
'participants' => 'participants',
|
|
|
|
'owner' => 'owner',
|
|
|
|
'category' => 'category',
|
|
|
|
'non_blocking' => 'non_blocking',
|
2009-07-15 22:35:56 +02:00
|
|
|
'uid' => 'uid',
|
2009-08-17 12:34:22 +02:00
|
|
|
'recurrence' => 'recurrence',
|
2009-10-25 19:22:01 +01:00
|
|
|
'etag' => 'etag',
|
2008-06-07 19:45:33 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($this->productManufacturer)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
|
|
|
case 'nexthaus corporation':
|
|
|
|
case 'nexthaus corp':
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($this->productName)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
$this->supportedFields = $defaultFields['nexthaus'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// multisync does not provide anymore information then the manufacturer
|
|
|
|
// we suppose multisync with evolution
|
|
|
|
case 'the multisync project':
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($this->productName)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
$this->supportedFields = $defaultFields['basic'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
case 'siemens':
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($this->productName)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
|
|
|
case 'sx1':
|
|
|
|
$this->supportedFields = $defaultFields['minimal'];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error_log("Unknown Siemens phone '$_productName', using minimal set");
|
|
|
|
$this->supportedFields = $defaultFields['minimal'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-06-07 19:45:33 +02:00
|
|
|
case 'nokia':
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($this->productName)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
|
|
|
case 'e61':
|
|
|
|
$this->supportedFields = $defaultFields['minimal'];
|
|
|
|
break;
|
2008-11-03 08:44:02 +01:00
|
|
|
case 'e51':
|
|
|
|
case 'e90':
|
|
|
|
case 'e71':
|
2009-07-15 22:35:56 +02:00
|
|
|
case 'e66':
|
|
|
|
case '6120c':
|
|
|
|
case 'nokia 6131':
|
|
|
|
$this->supportedFields = $defaultFields['s60'];
|
2008-11-03 08:44:02 +01:00
|
|
|
break;
|
2008-06-07 19:45:33 +02:00
|
|
|
default:
|
|
|
|
error_log("Unknown Nokia phone '$_productName', assuming E61");
|
|
|
|
$this->supportedFields = $defaultFields['minimal'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'sonyericsson':
|
|
|
|
case 'sony ericsson':
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($this->productName)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
|
|
|
case 'd750i':
|
|
|
|
case 'p910i':
|
2009-07-15 22:35:56 +02:00
|
|
|
case 'g705i':
|
2008-06-07 19:45:33 +02:00
|
|
|
$this->supportedFields = $defaultFields['basic'];
|
|
|
|
break;
|
|
|
|
default:
|
2009-07-15 22:35:56 +02:00
|
|
|
error_log("Unknown Sony Ericsson phone '$this->productName' assuming d750i");
|
2008-06-07 19:45:33 +02:00
|
|
|
$this->supportedFields = $defaultFields['basic'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'synthesis ag':
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($this->productName)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
|
|
|
case 'sysync client pocketpc std':
|
|
|
|
case 'sysync client pocketpc pro':
|
2009-07-15 22:35:56 +02:00
|
|
|
case 'sysync client iphone contacts':
|
|
|
|
case 'sysync client iphone contacts+todoz':
|
2008-06-07 19:45:33 +02:00
|
|
|
default:
|
|
|
|
$this->supportedFields = $defaultFields['synthesis'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
//Syncevolution compatibility
|
|
|
|
case 'patrick ohly':
|
|
|
|
$this->supportedFields = $defaultFields['evolution'];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '': // seems syncevolution 0.5 doesn't send a manufacturer
|
|
|
|
error_log("No vendor name, assuming syncevolution 0.5");
|
|
|
|
$this->supportedFields = $defaultFields['evolution'];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'file': // used outside of SyncML, eg. by the calendar itself ==> all possible fields
|
|
|
|
$this->supportedFields = $defaultFields['full'];
|
|
|
|
break;
|
|
|
|
|
2008-11-03 10:36:20 +01:00
|
|
|
case 'groupdav': // all GroupDAV access goes through here
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($this->productName)
|
2008-11-03 10:36:20 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
$this->supportedFields = $defaultFields['full'];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-12-01 11:24:55 +01:00
|
|
|
case 'funambol':
|
|
|
|
$this->supportedFields = $defaultFields['synthesis'];
|
|
|
|
break;
|
|
|
|
|
2008-06-07 19:45:33 +02:00
|
|
|
// the fallback for SyncML
|
|
|
|
default:
|
2009-07-15 22:35:56 +02:00
|
|
|
error_log("Unknown calendar SyncML client: manufacturer='$this->productManufacturer' product='$this->productName'");
|
|
|
|
$this->supportedFields = $defaultFields['synthesis'];
|
2008-06-07 19:45:33 +02:00
|
|
|
break;
|
|
|
|
}
|
2009-11-11 22:31:33 +01:00
|
|
|
// for palmos we have to use user-time and NO timezone
|
|
|
|
if (strpos($this->productName, 'palmos') !== false)
|
|
|
|
{
|
|
|
|
$this->tzid = false;
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
function icaltoegw($_vcalData, $cal_id=-1, $etag=null, $recur_date=0)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
$events = array();
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-11-11 22:31:33 +01:00
|
|
|
if ($this->tzid)
|
|
|
|
{
|
|
|
|
date_default_timezone_set($this->tzid);
|
|
|
|
}
|
|
|
|
|
2009-06-08 18:21:14 +02:00
|
|
|
$vcal = new Horde_iCalendar;
|
2009-11-11 22:31:33 +01:00
|
|
|
if (!$vcal->parsevCalendar($_vcalData))
|
|
|
|
{
|
|
|
|
if ($this->tzid)
|
|
|
|
{
|
2009-12-03 09:28:45 +01:00
|
|
|
date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
|
2009-11-11 22:31:33 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
$version = $vcal->getAttribute('VERSION');
|
|
|
|
if (!is_array($this->supportedFields)) $this->setSupportedFields();
|
|
|
|
|
|
|
|
foreach ($vcal->getComponents() as $component)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
if (is_a($component, 'Horde_iCalendar_vevent'))
|
|
|
|
{
|
2009-12-27 05:21:33 +01:00
|
|
|
if (($event = $this->vevent2egw($component, $version, $this->supportedFields, $cal_id)))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
//common adjustments
|
2009-07-15 22:35:56 +02:00
|
|
|
if ($this->productManufacturer == '' && $this->productName == ''
|
|
|
|
&& !empty($event['recur_enddate']))
|
|
|
|
{
|
|
|
|
// syncevolution needs an adjusted recur_enddate
|
|
|
|
$event['recur_enddate'] = (int)$event['recur_enddate'] + 86400;
|
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
if ($event['recur_type'] != MCAL_RECUR_NONE)
|
|
|
|
{
|
|
|
|
// No reference or RECURRENCE-ID for the series master
|
|
|
|
$event['reference'] = $event['recurrence'] = 0;
|
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
// handle the alarms
|
|
|
|
$alarms = $event['alarm'];
|
|
|
|
foreach ($component->getComponents() as $valarm)
|
|
|
|
{
|
|
|
|
if (is_a($valarm, 'Horde_iCalendar_valarm'))
|
|
|
|
{
|
|
|
|
$this->valarm2egw($alarms, $valarm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$event['alarm'] = $alarms;
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
$events[] = $event;
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-11-11 22:31:33 +01:00
|
|
|
if ($this->tzid)
|
|
|
|
{
|
2009-12-03 09:28:45 +01:00
|
|
|
date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
|
2009-11-11 22:31:33 +01:00
|
|
|
}
|
|
|
|
|
2009-12-27 05:21:33 +01:00
|
|
|
// if cal_id, etag or recur_date is given, use/set it for 1. event
|
|
|
|
if ($cal_id > 0) $events[0]['id'] = $cal_id;
|
|
|
|
if (!is_null($etag)) $events[0]['etag'] = $etag;
|
|
|
|
if ($recur_date) $events[0]['recurrence'] = $recur_date;
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-12-27 05:21:33 +01:00
|
|
|
return $events;
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
/**
|
2009-09-22 15:43:55 +02:00
|
|
|
* Parse a VEVENT
|
2009-07-15 22:35:56 +02:00
|
|
|
*
|
|
|
|
* @param array $component VEVENT
|
|
|
|
* @param string $version vCal version (1.0/2.0)
|
|
|
|
* @param array $supportedFields supported fields of the device
|
2009-11-18 15:46:25 +01:00
|
|
|
* @param int $cal_id id of existing event in the content (only used to merge categories)
|
2009-07-15 22:35:56 +02:00
|
|
|
*
|
|
|
|
* @return array|boolean event on success, false on failure
|
|
|
|
*/
|
2009-11-18 15:46:25 +01:00
|
|
|
function vevent2egw(&$component, $version, $supportedFields, $cal_id=-1)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
|
|
|
if (!is_a($component, 'Horde_iCalendar_vevent')) return false;
|
|
|
|
|
|
|
|
if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) {
|
|
|
|
$minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'];
|
|
|
|
}
|
|
|
|
else
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$minimum_uid_length = 8;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
$isDate = false;
|
|
|
|
$event = array();
|
|
|
|
$alarms = array();
|
|
|
|
$vcardData = array(
|
|
|
|
'recur_type' => MCAL_RECUR_NONE,
|
|
|
|
'recur_exception' => array(),
|
|
|
|
);
|
2009-10-25 19:22:01 +01:00
|
|
|
// we parse DTSTART and DTEND first
|
2009-07-15 22:35:56 +02:00
|
|
|
foreach ($component->_attributes as $attributes)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($attributes['name'])
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
case 'DTSTART':
|
|
|
|
if (isset($attributes['params']['VALUE'])
|
|
|
|
&& $attributes['params']['VALUE'] == 'DATE')
|
|
|
|
{
|
|
|
|
$isDate = true;
|
|
|
|
}
|
|
|
|
$dtstart_ts = is_numeric($attributes['value']) ? $attributes['value'] : $this->date2ts($attributes['value']);
|
|
|
|
$vcardData['start'] = $dtstart_ts;
|
2009-11-10 16:08:35 +01:00
|
|
|
|
2009-11-27 07:47:21 +01:00
|
|
|
|
|
|
|
if ($this->tzid)
|
|
|
|
{
|
|
|
|
// enforce device settings
|
|
|
|
$event['tzid'] = $this->tzid;
|
|
|
|
}
|
|
|
|
elseif (!empty($attributes['params']['TZID']))
|
2009-11-10 16:08:35 +01:00
|
|
|
{
|
2009-11-27 07:47:21 +01:00
|
|
|
// import TZID, if PHP understands it (we only care about TZID of starttime, as we store only a TZID for the whole event)
|
2009-11-10 16:08:35 +01:00
|
|
|
try
|
|
|
|
{
|
2009-11-10 21:07:33 +01:00
|
|
|
$tz = calendar_timezones::DateTimeZone($attributes['params']['TZID']);
|
2009-11-10 16:08:35 +01:00
|
|
|
$event['tzid'] = $tz->getName();
|
|
|
|
}
|
|
|
|
catch(Exception $e)
|
|
|
|
{
|
|
|
|
error_log(__METHOD__."() unknown TZID='{$attributes['params']['TZID']}', defaulting to user timezone '".egw_time::$user_timezone->getName()."'!");
|
2009-12-04 16:38:23 +01:00
|
|
|
$tz = egw_time::$user_timezone;
|
2009-11-10 16:08:35 +01:00
|
|
|
$event['tzid'] = egw_time::$user_timezone->getName(); // default to user timezone
|
|
|
|
}
|
|
|
|
}
|
2009-11-16 18:28:34 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$event['tzid'] = egw_time::$user_timezone->getName(); // default to user timezone
|
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
break;
|
|
|
|
case 'DTEND':
|
|
|
|
$dtend_ts = is_numeric($attributes['value']) ? $attributes['value'] : $this->date2ts($attributes['value']);
|
|
|
|
if (date('H:i:s',$dtend_ts) == '00:00:00')
|
|
|
|
{
|
|
|
|
$dtend_ts -= 60;
|
|
|
|
}
|
|
|
|
$vcardData['end'] = $dtend_ts;
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isset($vcardData['start'])) return false; // not a valid entry
|
|
|
|
|
|
|
|
// lets see what we can get from the vcard
|
|
|
|
foreach ($component->_attributes as $attributes)
|
|
|
|
{
|
|
|
|
switch ($attributes['name'])
|
|
|
|
{
|
|
|
|
case 'AALARM':
|
|
|
|
case 'DALARM':
|
|
|
|
$alarmTime = $attributes['value'];
|
|
|
|
$alarms[$alarmTime] = array(
|
|
|
|
'time' => $alarmTime
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'CLASS':
|
|
|
|
$vcardData['public'] = (int)(strtolower($attributes['value']) == 'public');
|
|
|
|
break;
|
|
|
|
case 'DESCRIPTION':
|
|
|
|
$vcardData['description'] = $attributes['value'];
|
2009-10-25 19:22:01 +01:00
|
|
|
if (preg_match('/\s*\[UID:(.+)?\]/Usm', $attributes['value'], $matches))
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
if (!isset($vCardData['uid'])
|
2009-10-25 19:22:01 +01:00
|
|
|
&& strlen($matches[1]) >= $minimum_uid_length)
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcardData['uid'] = $matches[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'RECURRENCE-ID':
|
2009-10-25 19:22:01 +01:00
|
|
|
case 'X-RECURRENCE-ID':
|
2009-07-28 10:58:39 +02:00
|
|
|
$vcardData['recurrence'] = $attributes['value'];
|
2009-07-15 22:35:56 +02:00
|
|
|
break;
|
|
|
|
case 'LOCATION':
|
|
|
|
$vcardData['location'] = $attributes['value'];
|
|
|
|
break;
|
|
|
|
case 'RRULE':
|
|
|
|
$recurence = $attributes['value'];
|
|
|
|
$type = preg_match('/FREQ=([^;: ]+)/i',$recurence,$matches) ? $matches[1] : $recurence[0];
|
|
|
|
// vCard 2.0 values for all types
|
2009-11-29 15:03:45 +01:00
|
|
|
if (preg_match('/UNTIL=([0-9TZ]+)/',$recurence,$matches))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
|
|
|
$vcardData['recur_enddate'] = $this->vCalendar->_parseDateTime($matches[1]);
|
|
|
|
}
|
|
|
|
elseif (preg_match('/COUNT=([0-9]+)/',$recurence,$matches))
|
|
|
|
{
|
|
|
|
$vcardData['recur_count'] = (int)$matches[1];
|
|
|
|
}
|
|
|
|
if (preg_match('/INTERVAL=([0-9]+)/',$recurence,$matches))
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
// 1 is invalid,, egw uses 0 for interval
|
|
|
|
$vcardData['recur_interval'] = (int) $matches[1] != 0 ? (int) $matches[1] : 0;
|
|
|
|
}
|
|
|
|
$vcardData['recur_data'] = 0;
|
|
|
|
switch($type)
|
|
|
|
{
|
|
|
|
case 'W':
|
|
|
|
case 'WEEKLY':
|
|
|
|
$days = array();
|
2009-10-25 19:22:01 +01:00
|
|
|
if (preg_match('/W(\d+) ([^ ]*)( ([^ ]*))?$/',$recurence, $recurenceMatches)) // 1.0
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcardData['recur_interval'] = $recurenceMatches[1];
|
2009-10-25 19:22:01 +01:00
|
|
|
if (empty($recurenceMatches[4]))
|
|
|
|
{
|
|
|
|
if ($recurenceMatches[2] != '#0')
|
|
|
|
{
|
|
|
|
$vcardData['recur_enddate'] = $this->vCalendar->_parseDateTime($recurenceMatches[2]);
|
|
|
|
}
|
|
|
|
$days[0] = strtoupper(substr(date('D', $vcardData['start']),0,2));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$days = explode(' ',trim($recurenceMatches[2]));
|
|
|
|
|
|
|
|
if ($recurenceMatches[4] != '#0')
|
|
|
|
{
|
|
|
|
$vcardData['recur_enddate'] = $this->vCalendar->_parseDateTime($recurenceMatches[4]);
|
|
|
|
}
|
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
$recur_days = $this->recur_days_1_0;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
elseif (preg_match('/BYDAY=([^;: ]+)/',$recurence,$recurenceMatches)) // 2.0
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$days = explode(',',$recurenceMatches[1]);
|
|
|
|
$recur_days = $this->recur_days;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
else // no day given, use the day of dtstart
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcardData['recur_data'] |= 1 << (int)date('w',$vcardData['start']);
|
|
|
|
$vcardData['recur_type'] = MCAL_RECUR_WEEKLY;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
if ($days)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach ($recur_days as $id => $day)
|
|
|
|
{
|
|
|
|
if (in_array(strtoupper(substr($day,0,2)),$days))
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcardData['recur_data'] |= $id;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
$vcardData['recur_type'] = MCAL_RECUR_WEEKLY;
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
if (!empty($vcardData['recur_count']))
|
|
|
|
{
|
2009-12-04 16:38:23 +01:00
|
|
|
$vcardData['recur_enddate'] = mktime(
|
|
|
|
date('H', $vcardData['end']),
|
|
|
|
date('i', $vcardData['end']),
|
|
|
|
date('s', $vcardData['end']),
|
|
|
|
date('m', $vcardData['start']),
|
|
|
|
date('d', $vcardData['start']) + ($vcardData['recur_interval']*($vcardData['recur_count']-1)*7),
|
|
|
|
date('Y', $vcardData['start']));
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
case 'D': // 1.0
|
2009-10-25 19:22:01 +01:00
|
|
|
if (preg_match('/D(\d+) #(.\d)/', $recurence, $recurenceMatches))
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcardData['recur_interval'] = $recurenceMatches[1];
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($recurenceMatches[2] > 0 && $vcardData['end'])
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcardData['recur_enddate'] = mktime(
|
|
|
|
date('H', $vcardData['end']),
|
|
|
|
date('i', $vcardData['end']),
|
|
|
|
date('s', $vcardData['end']),
|
|
|
|
date('m', $vcardData['end']),
|
|
|
|
date('d', $vcardData['end']) + ($recurenceMatches[2] * $vcardData['recur_interval']),
|
|
|
|
date('Y', $vcardData['end'])
|
|
|
|
);
|
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
}
|
|
|
|
elseif (preg_match('/D(\d+) (.*)/', $recurence, $recurenceMatches))
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcardData['recur_interval'] = $recurenceMatches[1];
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($recurenceMatches[2] != '#0')
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcardData['recur_enddate'] = $this->vCalendar->_parseDateTime($recurenceMatches[2]);
|
|
|
|
}
|
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
else break;
|
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
// fall-through
|
|
|
|
case 'DAILY': // 2.0
|
|
|
|
$vcardData['recur_type'] = MCAL_RECUR_DAILY;
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
if (!empty($vcardData['recur_count']))
|
|
|
|
{
|
2009-12-04 16:38:23 +01:00
|
|
|
$vcardData['recur_enddate'] = mktime(
|
|
|
|
date('H', $vcardData['end']),
|
|
|
|
date('i', $vcardData['end']),
|
|
|
|
date('s', $vcardData['end']),
|
|
|
|
date('m', $vcardData['start']),
|
|
|
|
date('d', $vcardData['start']) + ($vcardData['recur_interval']*($vcardData['recur_count']-1)),
|
|
|
|
date('Y', $vcardData['start']));
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
break;
|
2009-07-15 22:35:56 +02:00
|
|
|
|
|
|
|
case 'M':
|
2009-10-25 19:22:01 +01:00
|
|
|
if (preg_match('/MD(\d+) #(.\d)/', $recurence, $recurenceMatches))
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcardData['recur_type'] = MCAL_RECUR_MONTHLY_MDAY;
|
|
|
|
$vcardData['recur_interval'] = $recurenceMatches[1];
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($recurenceMatches[2] > 0 && $vcardData['end'])
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcardData['recur_enddate'] = mktime(
|
|
|
|
date('H', $vcardData['end']),
|
|
|
|
date('i', $vcardData['end']),
|
|
|
|
date('s', $vcardData['end']),
|
|
|
|
date('m', $vcardData['end']) + ($recurenceMatches[2] * $vcardData['recur_interval']),
|
|
|
|
date('d', $vcardData['end']),
|
|
|
|
date('Y', $vcardData['end'])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif (preg_match('/MD(\d+) (.*)/',$recurence, $recurenceMatches))
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcardData['recur_type'] = MCAL_RECUR_MONTHLY_MDAY;
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($recurenceMatches[1] > 1)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
|
|
|
$vcardData['recur_interval'] = $recurenceMatches[1];
|
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($recurenceMatches[2] != '#0')
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
|
|
|
$vcardData['recur_enddate'] = $this->vCalendar->_parseDateTime($recurenceMatches[2]);
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
elseif (preg_match('/MP(\d+) (.*) (.*) (.*)/',$recurence, $recurenceMatches))
|
Big SyncML patch from Philip Herbert <pherbert(at)knauber.de>:
- change the processing of slowsync, to use the content_map instead of
trying to build a new one. This caused duplication issues on the
client if multiple similar records where stored, because only the first
one found in the server-db was matched, These duplicate entries at client
side had no entry at serverside, so deleting the wrong one
on the client (the content with a valid map entry) could cause
unwanted data loss at server side, because it is impossible for the
user to see what is a duplicate, and what is not.
see also:
http://www.nabble.com/again---syncml-duplication-issue-to20333619s3741.html
- reenabled UID from syncml clients, because it was partly used this caused
issues during SlowSync if the content was changed.
- infolog, calendar if a uid is found in the provided data, allway try to
find the corresponding content first using only the UID, instead of
using the content-id taken from content_map.
also fixed:
- a few fixes in ./notes
- creating an entry on the client that can not be imported,
(Example, Nokia E Series Appointment without a Title)
will no longer create an invalid content-map entry
However, at client side this is still counted in the Protocol as
Server-Add
2008-11-16 11:42:29 +01:00
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcardData['recur_type'] = MCAL_RECUR_MONTHLY_WDAY;
|
|
|
|
if ($recurenceMatches[1] > 1)
|
|
|
|
{
|
|
|
|
$vcardData['recur_interval'] = $recurenceMatches[1];
|
|
|
|
}
|
|
|
|
if ($recurenceMatches[4] != '#0')
|
|
|
|
{
|
|
|
|
$vcardData['recur_enddate'] = $this->vCalendar->_parseDateTime($recurenceMatches[4]);
|
|
|
|
}
|
2008-11-17 17:31:59 +01:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
break;
|
2009-07-15 22:35:56 +02:00
|
|
|
case 'MONTHLY':
|
|
|
|
$vcardData['recur_type'] = strpos($recurence,'BYDAY') !== false ?
|
|
|
|
MCAL_RECUR_MONTHLY_WDAY : MCAL_RECUR_MONTHLY_MDAY;
|
|
|
|
|
|
|
|
if (!empty($vcardData['recur_count']))
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-12-04 16:38:23 +01:00
|
|
|
$vcardData['recur_enddate'] = mktime(
|
|
|
|
date('H', $vcardData['end']),
|
|
|
|
date('i', $vcardData['end']),
|
|
|
|
date('s', $vcardData['end']),
|
|
|
|
date('m', $vcardData['start']) + ($vcardData['recur_interval']*($vcardData['recur_count']-1)),
|
|
|
|
date('d', $vcardData['start']),
|
|
|
|
date('Y', $vcardData['start']));
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Y': // 1.0
|
2009-12-06 19:04:08 +01:00
|
|
|
if (preg_match('/YM(\d+)[^#]*#(\d+)/', $recurence, $recurenceMatches))
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcardData['recur_interval'] = $recurenceMatches[1];
|
|
|
|
if ($recurenceMatches[2] > 0 && $vcardData['end'])
|
|
|
|
{
|
|
|
|
$vcardData['recur_enddate'] = mktime(
|
|
|
|
date('H', $vcardData['end']),
|
|
|
|
date('i', $vcardData['end']),
|
|
|
|
date('s', $vcardData['end']),
|
|
|
|
date('m', $vcardData['end']),
|
|
|
|
date('d', $vcardData['end']),
|
|
|
|
date('Y', $vcardData['end']) + ($recurenceMatches[2] * $vcardData['recur_interval'])
|
|
|
|
);
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
elseif (preg_match('/YM(\d+) (.*)/',$recurence, $recurenceMatches))
|
|
|
|
{
|
|
|
|
$vcardData['recur_interval'] = $recurenceMatches[1];
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($recurenceMatches[2] != '#0')
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcardData['recur_enddate'] = $this->vCalendar->_parseDateTime($recurenceMatches[2]);
|
|
|
|
}
|
2009-08-23 21:26:14 +02:00
|
|
|
} else break;
|
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
// fall-through
|
|
|
|
case 'YEARLY': // 2.0
|
|
|
|
$vcardData['recur_type'] = MCAL_RECUR_YEARLY;
|
|
|
|
|
|
|
|
if (!empty($vcardData['recur_count']))
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-12-04 16:38:23 +01:00
|
|
|
$vcardData['recur_enddate'] = mktime(
|
|
|
|
date('H', $vcardData['end']),
|
|
|
|
date('i', $vcardData['end']),
|
|
|
|
date('s', $vcardData['end']),
|
|
|
|
date('m', $vcardData['start']),
|
|
|
|
date('d', $vcardData['start']),
|
|
|
|
date('Y', $vcardData['start']) + ($vcardData['recur_interval']*($vcardData['recur_count']-1)));
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
break;
|
|
|
|
case 'EXDATE':
|
|
|
|
if ((isset($attributes['params']['VALUE'])
|
|
|
|
&& $attributes['params']['VALUE'] == 'DATE') ||
|
|
|
|
(!isset($attributes['params']['VALUE']) && $isDate))
|
|
|
|
{
|
|
|
|
$days = array();
|
|
|
|
$hour = date('H', $vcardData['start']);
|
|
|
|
$minutes = date('i', $vcardData['start']);
|
|
|
|
$seconds = date('s', $vcardData['start']);
|
|
|
|
foreach ($attributes['values'] as $day)
|
|
|
|
{
|
|
|
|
$days[] = mktime(
|
|
|
|
$hour,
|
|
|
|
$minutes,
|
|
|
|
$seconds,
|
|
|
|
$day['month'],
|
|
|
|
$day['mday'],
|
|
|
|
$day['year']);
|
|
|
|
}
|
|
|
|
$vcardData['recur_exception'] = array_merge($vcardData['recur_exception'], $days);
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$vcardData['recur_exception'] = array_merge($vcardData['recur_exception'], $attributes['values']);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'SUMMARY':
|
|
|
|
$vcardData['title'] = $attributes['value'];
|
|
|
|
break;
|
|
|
|
case 'UID':
|
|
|
|
if (strlen($attributes['value']) >= $minimum_uid_length)
|
|
|
|
{
|
|
|
|
$event['uid'] = $vcardData['uid'] = $attributes['value'];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'TRANSP':
|
|
|
|
if ($version == '1.0')
|
|
|
|
{
|
|
|
|
$vcardData['non_blocking'] = ($attributes['value'] == 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$vcardData['non_blocking'] = ($attributes['value'] == 'TRANSPARENT');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'PRIORITY':
|
2009-12-29 14:51:07 +01:00
|
|
|
if($this->productManufacturer == 'funambol')
|
|
|
|
{
|
|
|
|
$vcardData['priority'] = (int) $this->priority_funambol2egw[$attributes['value']];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$vcardData['priority'] = (int) $this->priority_ical2egw[$attributes['value']];
|
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
break;
|
|
|
|
case 'CATEGORIES':
|
|
|
|
if ($attributes['value'])
|
|
|
|
{
|
|
|
|
if($version == '1.0')
|
|
|
|
{
|
2009-11-18 15:46:25 +01:00
|
|
|
$vcardData['category'] = $this->find_or_add_categories(explode(';',$attributes['value']), $cal_id);
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-18 15:46:25 +01:00
|
|
|
$vcardData['category'] = $this->find_or_add_categories(explode(',',$attributes['value']), $cal_id);
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$vcardData['category'] = array();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'ATTENDEE':
|
|
|
|
case 'ORGANIZER': // will be written direct to the event
|
2009-08-23 21:26:14 +02:00
|
|
|
if (isset($attributes['params']['PARTSTAT']))
|
|
|
|
{
|
|
|
|
$attributes['params']['STATUS'] = $attributes['params']['PARTSTAT'];
|
|
|
|
}
|
|
|
|
if (isset($attributes['params']['STATUS']))
|
|
|
|
{
|
|
|
|
$status = $this->status_ical2egw[strtoupper($attributes['params']['STATUS'])];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-26 19:36:19 +01:00
|
|
|
$status = 'U';
|
2009-08-23 21:26:14 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
$cn = '';
|
|
|
|
if (preg_match('/MAILTO:([@.a-z0-9_-]+)|MAILTO:"?([.a-z0-9_ -]*)"?[ ]*<([@.a-z0-9_-]*)>/i',
|
2009-10-25 19:22:01 +01:00
|
|
|
$attributes['value'],$matches))
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$email = $matches[1] ? $matches[1] : $matches[3];
|
|
|
|
$cn = isset($matches[2]) ? $matches[2]: '';
|
|
|
|
}
|
|
|
|
elseif (preg_match('/"?([.a-z0-9_ -]*)"?[ ]*<([@.a-z0-9_-]*)>/i',
|
|
|
|
$attributes['value'],$matches))
|
2009-10-25 19:22:01 +01:00
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$cn = $matches[1];
|
|
|
|
$email = $matches[2];
|
2009-10-25 19:22:01 +01:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
elseif (strpos($attributes['value'],'@') !== false)
|
|
|
|
{
|
|
|
|
$email = $attributes['value'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$email = false; // no email given
|
|
|
|
}
|
|
|
|
$searcharray = array();
|
|
|
|
if ($email)
|
|
|
|
{
|
|
|
|
$searcharray = array('email' => $email, 'email_home' => $email);
|
|
|
|
}
|
|
|
|
if (isset($attributes['params']['CN']) && $attributes['params']['CN'])
|
|
|
|
{
|
|
|
|
if ($attributes['params']['CN'][0] == '"'
|
|
|
|
&& substr($attributes['params']['CN'],-1) == '"')
|
|
|
|
{
|
|
|
|
$attributes['params']['CN'] = substr($attributes['params']['CN'],1,-1);
|
|
|
|
}
|
|
|
|
$searcharray['n_fn'] = $attributes['params']['CN'];
|
|
|
|
}
|
|
|
|
elseif ($cn)
|
|
|
|
{
|
|
|
|
$searcharray['n_fn'] = $cn;
|
|
|
|
}
|
|
|
|
if (($uid = $attributes['params']['X-EGROUPWARE-UID'])
|
2009-08-04 19:37:49 +02:00
|
|
|
&& ($info = $this->resource_info($uid))
|
|
|
|
&& (!$email || $info['email'] == $email))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
|
|
|
// we use the (checked) X-EGROUPWARE-UID
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-08-23 21:26:14 +02:00
|
|
|
//elseif (//$attributes['params']['CUTYPE'] == 'GROUP'
|
2009-11-26 19:36:19 +01:00
|
|
|
elseif (preg_match('/(.*) Group/', $searcharray['n_fn'], $matches))
|
2009-08-23 21:26:14 +02:00
|
|
|
{
|
|
|
|
if (($uid = $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'g')))
|
|
|
|
{
|
|
|
|
//Horde::logMessage("vevent2egw: group participant $uid",
|
2009-11-26 19:36:19 +01:00
|
|
|
// __FILE__, __LINE__, PEAR_LOG_DEBUG);
|
2009-11-29 15:03:45 +01:00
|
|
|
if ($status != 'U')
|
2009-11-26 19:36:19 +01:00
|
|
|
{
|
|
|
|
// User tries to reply to the group invitiation
|
|
|
|
$members = $GLOBALS['egw']->accounts->members($uid, true);
|
|
|
|
if (in_array($this->user, $members))
|
|
|
|
{
|
|
|
|
//Horde::logMessage("vevent2egw: set status to " . $status,
|
|
|
|
// __FILE__, __LINE__, PEAR_LOG_DEBUG);
|
|
|
|
$event['participants'][$this->user] =
|
|
|
|
calendar_so::combine_status($status);
|
|
|
|
}
|
2009-11-29 22:03:17 +01:00
|
|
|
$status = 'U'; // keep the group
|
2009-08-23 21:26:14 +02:00
|
|
|
}
|
|
|
|
}
|
2009-11-29 15:03:45 +01:00
|
|
|
else continue; // can't find this group
|
2009-08-23 21:26:14 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
elseif ($attributes['value'] == 'Unknown')
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
$uid = $this->user;
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
elseif ($email && ($uid = $GLOBALS['egw']->accounts->name2id($email,'account_email')))
|
|
|
|
{
|
|
|
|
// we use the account we found
|
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
elseif (!$searcharray)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
|
|
|
continue; // participants without email AND CN --> ignore it
|
|
|
|
}
|
|
|
|
elseif ((list($data) = ExecMethod2('addressbook.addressbook_bo.search',$searcharray,
|
|
|
|
array('id','egw_addressbook.account_id as account_id','n_fn'),'egw_addressbook.account_id IS NOT NULL DESC, n_fn IS NOT NULL DESC','','',false,'OR')))
|
2009-07-28 10:58:39 +02:00
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$uid = $data['account_id'] ? (int)$data['account_id'] : 'c'.$data['id'];
|
2009-07-28 10:58:39 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!$email)
|
|
|
|
{
|
|
|
|
$email = 'no-email@egroupware.org'; // set dummy email to store the CN
|
|
|
|
}
|
|
|
|
$uid = 'e'.($attributes['params']['CN'] ? $attributes['params']['CN'].' <'.$email.'>' : $email);
|
|
|
|
}
|
|
|
|
switch($attributes['name'])
|
|
|
|
{
|
|
|
|
case 'ATTENDEE':
|
2009-11-26 19:36:19 +01:00
|
|
|
if (!isset($attributes['params']['ROLE']) &&
|
|
|
|
isset($event['owner']) && $event['owner'] == $uid)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-11-26 19:36:19 +01:00
|
|
|
$attributes['params']['ROLE'] = 'CHAIR';
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2009-11-26 19:36:19 +01:00
|
|
|
// add quantity and role
|
|
|
|
$event['participants'][$uid] =
|
|
|
|
calendar_so::combine_status($status,
|
|
|
|
$attributes['params']['X-EGROUPWARE-QUANTITY'],
|
|
|
|
$attributes['params']['ROLE']);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ORGANIZER':
|
|
|
|
if (isset($event['participants'][$uid]))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-11-26 19:36:19 +01:00
|
|
|
$status = $event['participants'][$uid];
|
|
|
|
calendar_so::split_status($status, $quantity, $role);
|
|
|
|
$event['participants'][$uid] =
|
|
|
|
calendar_so::combine_status($status, $quantity, 'CHAIR');
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-11-29 15:03:45 +01:00
|
|
|
if (is_numeric($uid) && ($uid == $this->calendarOwner || !$this->calendarOwner))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-11-29 15:03:45 +01:00
|
|
|
// we can store the ORGANIZER as event owner
|
2009-07-15 22:35:56 +02:00
|
|
|
$event['owner'] = $uid;
|
|
|
|
}
|
|
|
|
else
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-11-29 15:03:45 +01:00
|
|
|
// we must insert a CHAIR participant to keep the ORGANIZER
|
2009-07-15 22:35:56 +02:00
|
|
|
$event['owner'] = $this->user;
|
2009-11-26 19:36:19 +01:00
|
|
|
if (!isset($event['participants'][$uid]))
|
|
|
|
{
|
|
|
|
// save the ORGANIZER as event CHAIR
|
|
|
|
$event['participants'][$uid] =
|
|
|
|
calendar_so::combine_status('U', 1, 'CHAIR');
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
break;
|
|
|
|
case 'CREATED': // will be written direct to the event
|
|
|
|
if ($event['modified']) break;
|
|
|
|
// fall through
|
|
|
|
case 'LAST-MODIFIED': // will be written direct to the event
|
|
|
|
$event['modified'] = $attributes['value'];
|
|
|
|
break;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
// check if the entry is a birthday
|
|
|
|
// this field is only set from NOKIA clients
|
|
|
|
$agendaEntryType = $component->getAttribute('X-EPOCAGENDAENTRYTYPE');
|
|
|
|
if (!is_a($agendaEntryType, 'PEAR_Error'))
|
|
|
|
{
|
|
|
|
if (strtolower($agendaEntryType) == 'anniversary')
|
|
|
|
{
|
|
|
|
$event['special'] = '1';
|
|
|
|
$event['non_blocking'] = 1;
|
|
|
|
// make it a whole day event for eGW
|
|
|
|
$vcardData['end'] = $vcardData['start'] + 86399;
|
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
elseif (strtolower($agendaEntryType) == 'event')
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
|
|
|
$event['special'] = '2';
|
|
|
|
$event['non_blocking'] = 1;
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
|
|
|
|
if (!empty($vcardData['recur_enddate']))
|
Big SyncML patch from Philip Herbert <pherbert(at)knauber.de>:
- change the processing of slowsync, to use the content_map instead of
trying to build a new one. This caused duplication issues on the
client if multiple similar records where stored, because only the first
one found in the server-db was matched, These duplicate entries at client
side had no entry at serverside, so deleting the wrong one
on the client (the content with a valid map entry) could cause
unwanted data loss at server side, because it is impossible for the
user to see what is a duplicate, and what is not.
see also:
http://www.nabble.com/again---syncml-duplication-issue-to20333619s3741.html
- reenabled UID from syncml clients, because it was partly used this caused
issues during SlowSync if the content was changed.
- infolog, calendar if a uid is found in the provided data, allway try to
find the corresponding content first using only the UID, instead of
using the content-id taken from content_map.
also fixed:
- a few fixes in ./notes
- creating an entry on the client that can not be imported,
(Example, Nokia E Series Appointment without a Title)
will no longer create an invalid content-map entry
However, at client side this is still counted in the Protocol as
Server-Add
2008-11-16 11:42:29 +01:00
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
// reset recure_enddate to 00:00:00 on the last day
|
|
|
|
$vcardData['recur_enddate'] = mktime(0, 0, 0,
|
2009-12-04 16:38:23 +01:00
|
|
|
date('m', $vcardData['recur_enddate']),
|
|
|
|
date('d', $vcardData['recur_enddate']),
|
|
|
|
date('Y', $vcardData['recur_enddate'])
|
2009-07-15 22:35:56 +02:00
|
|
|
);
|
Big SyncML patch from Philip Herbert <pherbert(at)knauber.de>:
- change the processing of slowsync, to use the content_map instead of
trying to build a new one. This caused duplication issues on the
client if multiple similar records where stored, because only the first
one found in the server-db was matched, These duplicate entries at client
side had no entry at serverside, so deleting the wrong one
on the client (the content with a valid map entry) could cause
unwanted data loss at server side, because it is impossible for the
user to see what is a duplicate, and what is not.
see also:
http://www.nabble.com/again---syncml-duplication-issue-to20333619s3741.html
- reenabled UID from syncml clients, because it was partly used this caused
issues during SlowSync if the content was changed.
- infolog, calendar if a uid is found in the provided data, allway try to
find the corresponding content first using only the UID, instead of
using the content-id taken from content_map.
also fixed:
- a few fixes in ./notes
- creating an entry on the client that can not be imported,
(Example, Nokia E Series Appointment without a Title)
will no longer create an invalid content-map entry
However, at client side this is still counted in the Protocol as
Server-Add
2008-11-16 11:42:29 +01:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
$event['priority'] = 2; // default
|
|
|
|
$event['alarm'] = $alarms;
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
// now that we know what the vard provides,
|
|
|
|
// we merge that data with the information we have about the device
|
|
|
|
while (($fieldName = array_shift($supportedFields)))
|
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($fieldName)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
|
|
|
case 'recur_interval':
|
|
|
|
case 'recur_enddate':
|
|
|
|
case 'recur_data':
|
|
|
|
case 'recur_exception':
|
|
|
|
// not handled here
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'recur_type':
|
|
|
|
$event['recur_type'] = $vcardData['recur_type'];
|
|
|
|
if ($event['recur_type'] != MCAL_RECUR_NONE)
|
|
|
|
{
|
|
|
|
$event['reference'] = 0;
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach (array('recur_interval','recur_enddate','recur_data','recur_exception') as $r)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
if (isset($vcardData[$r]))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
|
|
|
$event[$r] = $vcardData[$r];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
Big SyncML patch from Philip Herbert <pherbert(at)knauber.de>:
- change the processing of slowsync, to use the content_map instead of
trying to build a new one. This caused duplication issues on the
client if multiple similar records where stored, because only the first
one found in the server-db was matched, These duplicate entries at client
side had no entry at serverside, so deleting the wrong one
on the client (the content with a valid map entry) could cause
unwanted data loss at server side, because it is impossible for the
user to see what is a duplicate, and what is not.
see also:
http://www.nabble.com/again---syncml-duplication-issue-to20333619s3741.html
- reenabled UID from syncml clients, because it was partly used this caused
issues during SlowSync if the content was changed.
- infolog, calendar if a uid is found in the provided data, allway try to
find the corresponding content first using only the UID, instead of
using the content-id taken from content_map.
also fixed:
- a few fixes in ./notes
- creating an entry on the client that can not be imported,
(Example, Nokia E Series Appointment without a Title)
will no longer create an invalid content-map entry
However, at client side this is still counted in the Protocol as
Server-Add
2008-11-16 11:42:29 +01:00
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
default:
|
|
|
|
if (isset($vcardData[$fieldName]))
|
|
|
|
{
|
|
|
|
$event[$fieldName] = $vcardData[$fieldName];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-11-29 15:03:45 +01:00
|
|
|
if ($this->calendarOwner) $event['owner'] = $this->calendarOwner;
|
2009-07-15 22:35:56 +02:00
|
|
|
//Horde::logMessage("vevent2egw:\n" . print_r($event, true),
|
|
|
|
// __FILE__, __LINE__, PEAR_LOG_DEBUG);
|
|
|
|
return $event;
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
function search($_vcalData, $contentID=null, $relax=false)
|
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
if (($events = $this->icaltoegw($_vcalData,!is_null($contentID) ? $contentID : -1)))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2009-09-22 15:43:55 +02:00
|
|
|
// this function only supports searching a single event
|
2009-10-25 19:22:01 +01:00
|
|
|
if (count($events) == 1)
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
|
|
|
$event = array_shift($events);
|
|
|
|
return $this->find_event($event, $relax);
|
2009-10-05 23:00:08 +02:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
return false;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a freebusy vCal for the given user(s)
|
|
|
|
*
|
|
|
|
* @param int $user account_id
|
|
|
|
* @param mixed $end=null end-date, default now+1 month
|
2009-11-06 16:44:04 +01:00
|
|
|
* @param boolean $utc=true if false, use severtime for dates
|
2008-06-07 19:45:33 +02:00
|
|
|
* @return string
|
|
|
|
*/
|
2009-11-06 16:44:04 +01:00
|
|
|
function freebusy($user,$end=null,$utc=true)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
|
|
|
if (!$end) $end = $this->now_su + 100*DAY_s; // default next 100 days
|
|
|
|
|
2009-06-08 18:21:14 +02:00
|
|
|
$vcal = new Horde_iCalendar;
|
2008-06-07 19:45:33 +02:00
|
|
|
$vcal->setAttribute('PRODID','-//eGroupWare//NONSGML eGroupWare Calendar '.$GLOBALS['egw_info']['apps']['calendar']['version'].'//'.
|
|
|
|
strtoupper($GLOBALS['egw_info']['user']['preferences']['common']['lang']));
|
|
|
|
$vcal->setAttribute('VERSION','2.0');
|
|
|
|
|
|
|
|
$vfreebusy = Horde_iCalendar::newComponent('VFREEBUSY',$vcal);
|
|
|
|
$parameters = array(
|
|
|
|
'ORGANIZER' => $GLOBALS['egw']->translation->convert(
|
|
|
|
$GLOBALS['egw']->accounts->id2name($user,'account_firstname').' '.
|
|
|
|
$GLOBALS['egw']->accounts->id2name($user,'account_lastname'),
|
|
|
|
$GLOBALS['egw']->translation->charset(),'utf-8'),
|
|
|
|
);
|
2009-11-06 16:44:04 +01:00
|
|
|
if ($utc)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach (array(
|
2009-07-15 22:35:56 +02:00
|
|
|
'URL' => $this->freebusy_url($user),
|
2009-11-06 16:44:04 +01:00
|
|
|
'DTSTART' => $this->date2ts($this->now_su,true), // true = server-time
|
|
|
|
'DTEND' => $this->date2ts($end,true), // true = server-time
|
2009-07-15 22:35:56 +02:00
|
|
|
'ORGANIZER' => $GLOBALS['egw']->accounts->id2name($user,'account_email'),
|
2009-11-06 16:44:04 +01:00
|
|
|
'DTSTAMP' => time(),
|
2009-07-15 22:35:56 +02:00
|
|
|
) as $attr => $value)
|
|
|
|
{
|
|
|
|
$vfreebusy->setAttribute($attr, $value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach (array(
|
2009-07-15 22:35:56 +02:00
|
|
|
'URL' => $this->freebusy_url($user),
|
2009-11-06 16:44:04 +01:00
|
|
|
'DTSTART' => date('Ymd\THis',$this->date2ts($this->now_su,true)), // true = server-time
|
|
|
|
'DTEND' => date('Ymd\THis',$this->date2ts($end,true)), // true = server-time
|
2009-07-15 22:35:56 +02:00
|
|
|
'ORGANIZER' => $GLOBALS['egw']->accounts->id2name($user,'account_email'),
|
2009-11-06 16:44:04 +01:00
|
|
|
'DTSTAMP' => date('Ymd\THis',time()),
|
2009-07-15 22:35:56 +02:00
|
|
|
) as $attr => $value)
|
|
|
|
{
|
|
|
|
$vfreebusy->setAttribute($attr, $value);
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
$fbdata = parent::search(array(
|
2009-07-28 10:58:39 +02:00
|
|
|
'start' => $this->now_su,
|
|
|
|
'end' => $end,
|
|
|
|
'users' => $user,
|
|
|
|
'date_format' => 'server',
|
|
|
|
'show_rejected' => false,
|
|
|
|
));
|
2008-06-07 19:45:33 +02:00
|
|
|
if (is_array($fbdata))
|
|
|
|
{
|
|
|
|
foreach ($fbdata as $event)
|
|
|
|
{
|
|
|
|
if ($event['non_blocking']) continue;
|
|
|
|
|
2009-11-06 16:44:04 +01:00
|
|
|
if ($utc)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
|
|
|
$vfreebusy->setAttribute('FREEBUSY',array(array(
|
2009-11-06 16:44:04 +01:00
|
|
|
'start' => $event['start'],
|
|
|
|
'end' => $event['end'],
|
2009-07-15 22:35:56 +02:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$vfreebusy->setAttribute('FREEBUSY',array(array(
|
2009-11-06 16:44:04 +01:00
|
|
|
'start' => date('Ymd\THis',$event['start']),
|
|
|
|
'end' => date('Ymd\THis',$event['end']),
|
2009-07-15 22:35:56 +02:00
|
|
|
)));
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$vcal->addComponent($vfreebusy);
|
|
|
|
|
|
|
|
return $vcal->exportvCalendar();
|
|
|
|
}
|
2009-04-02 14:35:26 +02:00
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
/**
|
|
|
|
* update the status of all participant for a given recurrence or for all recurrences since now (includes recur_date=0)
|
|
|
|
*
|
|
|
|
* @param array $new_event event-array with the new stati
|
|
|
|
* @param array $old_event event-array with the old stati
|
|
|
|
* @param int $recur_date=0 date to change, or 0 = all since now
|
|
|
|
*/
|
2009-09-22 15:43:55 +02:00
|
|
|
function update_status($new_event, $old_event , $recur_date=0)
|
2009-10-25 19:22:01 +01:00
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
// check the old list against the new list
|
|
|
|
foreach ($old_event['participants'] as $userid => $status)
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
if (!isset($new_event['participants'][$userid])){
|
2009-07-15 22:35:56 +02:00
|
|
|
// Attendee will be deleted this way
|
|
|
|
$new_event['participants'][$userid] = 'G';
|
2009-10-25 19:22:01 +01:00
|
|
|
}
|
|
|
|
elseif ($new_event['participants'][$userid] == $status)
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
// Same status -- nothing to do.
|
|
|
|
unset($new_event['participants'][$userid]);
|
2009-04-02 14:35:26 +02:00
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
// write the changes
|
|
|
|
foreach ($new_event['participants'] as $userid => $status)
|
|
|
|
{
|
|
|
|
$this->set_status($old_event, $userid, $status, $recur_date, true, false);
|
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
/**
|
|
|
|
* classifies an incoming event from the eGW point-of-view
|
2009-10-05 23:00:08 +02:00
|
|
|
*
|
2009-09-22 15:43:55 +02:00
|
|
|
* exceptions: unlike other calendar apps eGW does not create an event exception
|
|
|
|
* if just the participant state changes - therefore we have to distinguish between
|
|
|
|
* real exceptions and status only exceptions
|
2009-10-05 23:00:08 +02:00
|
|
|
*
|
2009-09-22 15:43:55 +02:00
|
|
|
* @param array $event the event to check
|
2009-10-05 23:00:08 +02:00
|
|
|
*
|
2009-09-22 15:43:55 +02:00
|
|
|
* @return array
|
|
|
|
* type =>
|
|
|
|
* SINGLE a single event
|
|
|
|
* SERIES-MASTER the series master
|
|
|
|
* SERIES-EXCEPTION event is a real exception
|
|
|
|
* SERIES-EXCEPTION-STATUS event is a status only exception
|
2009-10-01 15:30:18 +02:00
|
|
|
* SERIES-EXCEPTION-PROPAGATE event was a status only exception in the past and is now a real exception
|
2009-09-22 15:43:55 +02:00
|
|
|
* stored_event => if event already exists in the database array with event data or false
|
2009-10-01 15:30:18 +02:00
|
|
|
* master_event => for event type SERIES-EXCEPTION, SERIES-EXCEPTION-STATUS or SERIES-EXCEPTION-PROPAGATE
|
|
|
|
* the corresponding series master event array
|
|
|
|
* NOTE: this param is false if event is of type SERIES-MASTER
|
2009-09-22 15:43:55 +02:00
|
|
|
*/
|
|
|
|
private function get_event_info($event)
|
|
|
|
{
|
|
|
|
$type = 'SINGLE'; // default
|
|
|
|
$return_master = false; //default
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($event['recur_type'] != MCAL_RECUR_NONE)
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
|
|
|
$type = 'SERIES-MASTER';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// SINGLE, SERIES-EXCEPTION OR SERIES-EXCEPTON-STATUS
|
2009-10-25 19:22:01 +01:00
|
|
|
if (empty($event['uid']) && $event['id'] > 0 && ($stored_event = $this->read($event['id'])))
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
|
|
|
$event['uid'] = $stored_event['uid']; // restore the UID if it was not delivered
|
|
|
|
}
|
|
|
|
|
2009-10-25 19:22:01 +01:00
|
|
|
if (isset($event['uid'])
|
2009-09-22 15:43:55 +02:00
|
|
|
&& $event['recurrence']
|
|
|
|
&& ($master_event = $this->read($event['uid']))
|
|
|
|
&& isset($master_event['recur_type'])
|
2009-10-25 19:22:01 +01:00
|
|
|
&& $master_event['recur_type'] != MCAL_RECUR_NONE)
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
|
|
|
// SERIES-EXCEPTION OR SERIES-EXCEPTON-STATUS
|
|
|
|
$return_master = true; // we have a valid master and can return it
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-10-25 19:22:01 +01:00
|
|
|
if (isset($event['id']) && $master_event['id'] != $event['id'])
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
2009-10-01 15:30:18 +02:00
|
|
|
$type = 'SERIES-EXCEPTION'; // this is an existing exception
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$type = 'SERIES-EXCEPTION-STATUS'; // default if we cannot find a proof for a fundamental change
|
2009-10-01 15:30:18 +02:00
|
|
|
// the recurrence_event is the master event with start and end adjusted to the recurrence
|
|
|
|
$recurrence_event = $master_event;
|
|
|
|
$recurrence_event['start'] = $event['recurrence'];
|
|
|
|
$recurrence_event['end'] = $event['recurrence'] + ($master_event['end'] - $master_event['start']);
|
2009-09-22 15:43:55 +02:00
|
|
|
// check for changed data
|
2009-11-29 15:03:45 +01:00
|
|
|
foreach (array('start','end','uid','title','location',
|
|
|
|
'priority','public','special','non_blocking') as $key)
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
|
|
|
if (!empty($event[$key]) && $recurrence_event[$key] != $event[$key])
|
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
if (isset($event['id']))
|
2009-10-01 15:30:18 +02:00
|
|
|
{
|
|
|
|
$type = 'SERIES-EXCEPTION-PROPAGATE';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$type = 'SERIES-EXCEPTION'; // this is a new exception
|
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-10-01 15:30:18 +02:00
|
|
|
// the event id here is always the id of the master event
|
|
|
|
// unset it to prevent confusion of stored event and master event
|
2009-10-05 23:00:08 +02:00
|
|
|
unset($event['id']);
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// SINGLE
|
|
|
|
$type = 'SINGLE';
|
|
|
|
}
|
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-10-01 15:30:18 +02:00
|
|
|
// read existing event
|
2009-10-25 19:22:01 +01:00
|
|
|
if (isset($event['id']))
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
|
|
|
$stored_event = $this->read($event['id']);
|
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-10-01 15:30:18 +02:00
|
|
|
// check ACL
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($return_master)
|
2009-10-01 15:30:18 +02:00
|
|
|
{
|
|
|
|
$acl_edit = $this->check_perms(EGW_ACL_EDIT, $master_event['id']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-25 19:22:01 +01:00
|
|
|
if (is_array($stored_event))
|
2009-10-01 15:30:18 +02:00
|
|
|
{
|
|
|
|
$acl_edit = $this->check_perms(EGW_ACL_EDIT, $stored_event['id']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$acl_edit = true; // new event
|
|
|
|
}
|
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
return array(
|
|
|
|
'type' => $type,
|
2009-10-01 15:30:18 +02:00
|
|
|
'acl_edit' => $acl_edit,
|
2009-09-22 15:43:55 +02:00
|
|
|
'stored_event' => is_array($stored_event) ? $stored_event : false,
|
|
|
|
'master_event' => $return_master ? $master_event : false,
|
|
|
|
);
|
2009-04-02 14:35:26 +02:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|