2008-06-07 19:45:33 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2011-04-06 21:26:10 +02:00
|
|
|
* EGroupware - Calendar iCal import and export via Horde iCalendar classes
|
2008-06-07 19:45:33 +02:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
2016-04-05 00:39:49 +02:00
|
|
|
use EGroupware\Api;
|
2016-05-01 19:47:59 +02:00
|
|
|
use EGroupware\Api\Acl;
|
2016-04-05 00:39:49 +02:00
|
|
|
|
2008-06-07 19:45:33 +02:00
|
|
|
/**
|
|
|
|
* iCal import and export via Horde iCalendar classes
|
2013-01-31 16:15:48 +01:00
|
|
|
*
|
|
|
|
* @ToDo: NOT changing default-timezone as it messes up timezone calculation of timestamps eg. in calendar_boupdate::send_update
|
|
|
|
* (currently fixed by restoring server-timezone in calendar_boupdate::send_update)
|
2008-06-07 19:45:33 +02:00
|
|
|
*/
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array $status_egw2ical conversation of the participant status egw => ical
|
|
|
|
*/
|
|
|
|
var $status_egw2ical = array(
|
|
|
|
'U' => 'NEEDS-ACTION',
|
|
|
|
'A' => 'ACCEPTED',
|
|
|
|
'R' => 'DECLINED',
|
|
|
|
'T' => 'TENTATIVE',
|
2010-02-17 14:29:28 +01:00
|
|
|
'D' => 'DELEGATED'
|
2008-06-07 19:45:33 +02:00
|
|
|
);
|
|
|
|
/**
|
|
|
|
* @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',
|
2010-02-17 14:29:28 +01:00
|
|
|
'DELEGATED' => 'D',
|
2010-03-07 00:06:43 +01:00
|
|
|
'X-UNINVITED' => 'G', // removed
|
2008-06-07 19:45:33 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
);
|
2010-01-05 12:24:27 +01: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
|
|
|
|
*
|
2010-02-26 13:37:07 +01:00
|
|
|
* === false => use event's TZ
|
|
|
|
* === null => export in UTC
|
|
|
|
* string => device TZ
|
|
|
|
*
|
2010-04-14 12:19:41 +02:00
|
|
|
* @var string|boolean
|
2009-11-11 22:31:33 +01:00
|
|
|
*/
|
|
|
|
var $tzid = null;
|
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
/**
|
|
|
|
* Device CTCap Properties
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $clientProperties;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* vCalendar Instance for parsing
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $vCalendar;
|
|
|
|
|
2010-03-07 00:06:43 +01:00
|
|
|
/**
|
|
|
|
* Addressbook BO instance
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $addressbook;
|
|
|
|
|
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";
|
|
|
|
|
2019-03-27 17:26:50 +01:00
|
|
|
/**
|
|
|
|
* Event callback
|
|
|
|
* If set, this will be called on each discovered event so it can be
|
|
|
|
* modified. Event is passed by reference, return true to keep the event
|
|
|
|
* or false to skip it.
|
|
|
|
*
|
|
|
|
* @var callable
|
|
|
|
*/
|
|
|
|
var $event_callback = null;
|
|
|
|
|
2016-07-11 21:08:41 +02:00
|
|
|
/**
|
|
|
|
* Conflict callback
|
2016-11-05 12:00:19 +01:00
|
|
|
* If set, conflict checking will be enabled, and the event as well as
|
2016-07-11 21:08:41 +02:00
|
|
|
* conflicts are passed as parameters to this callback
|
|
|
|
*/
|
|
|
|
var $conflict_callback = null;
|
2016-11-05 12:00:19 +01:00
|
|
|
|
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;
|
2015-06-22 17:36:23 +02:00
|
|
|
$this->vCalendar = new Horde_Icalendar;
|
2016-05-01 19:47:59 +02:00
|
|
|
$this->addressbook = new Api\Contacts;
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-07 19:45:33 +02:00
|
|
|
/**
|
|
|
|
* Exports one calendar event to an iCalendar item
|
|
|
|
*
|
2010-04-23 12:34:47 +02:00
|
|
|
* @param int|array $events (array of) cal_id or array of the events with timestamps in server time
|
2015-06-22 17:36:23 +02:00
|
|
|
* @param string $version ='1.0' could be '2.0' too
|
|
|
|
* @param string $method ='PUBLISH'
|
|
|
|
* @param int $recur_date =0 if set export the next recurrence at or after the timestamp,
|
2010-01-29 22:42:54 +01:00
|
|
|
* default 0 => export whole series (or events, if not recurring)
|
2015-06-22 17:36:23 +02:00
|
|
|
* @param string $principalURL ='' Used for CalDAV exports
|
|
|
|
* @param string $charset ='UTF-8' encoding of the vcalendar, default UTF-8
|
2015-10-14 18:39:39 +02:00
|
|
|
* @param int|string $current_user =0 uid of current user to only export that one as participant for method=REPLY
|
2010-03-22 19:03:23 +01:00
|
|
|
* @return string|boolean string with iCal or false on error (e.g. no permission to read the event)
|
2008-06-07 19:45:33 +02:00
|
|
|
*/
|
2020-08-21 13:59:15 +02:00
|
|
|
function exportVCal($events, $version='1.0', $method='PUBLISH', $recur_date=0, $principalURL='', $charset='UTF-8', $current_user=0)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2010-03-07 00:06:43 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
2010-03-22 19:03:23 +01:00
|
|
|
"($version, $method, $recur_date, $principalURL, $charset)\n",
|
2010-03-07 00:06:43 +01:00
|
|
|
3, $this->logfile);
|
|
|
|
}
|
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',
|
2010-02-23 19:19:12 +01:00
|
|
|
'STATUS' => 'status',
|
2013-09-23 12:21:31 +02:00
|
|
|
'ATTACH' => 'attachments',
|
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
|
|
|
}
|
|
|
|
|
2015-06-22 17:36:23 +02:00
|
|
|
$vcal = new Horde_Icalendar;
|
2011-10-08 20:40:29 +02:00
|
|
|
$vcal->setAttribute('PRODID','-//EGroupware//NONSGML EGroupware Calendar '.$GLOBALS['egw_info']['apps']['calendar']['version'].'//'.
|
2008-06-07 19:45:33 +02:00
|
|
|
strtoupper($GLOBALS['egw_info']['user']['preferences']['common']['lang']));
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcal->setAttribute('VERSION', $version);
|
2011-10-03 14:53:28 +02:00
|
|
|
if ($method) $vcal->setAttribute('METHOD', $method);
|
2010-02-24 16:05:00 +01:00
|
|
|
$events_exported = false;
|
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();
|
2010-01-29 22:42:54 +01:00
|
|
|
foreach ($events as $event)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2010-03-07 00:06:43 +01:00
|
|
|
$organizerURL = '';
|
2009-11-26 19:36:19 +01:00
|
|
|
$organizerCN = false;
|
2010-02-23 19:19:12 +01:00
|
|
|
$recurrence = $this->date2usertime($recur_date);
|
2010-01-29 22:42:54 +01:00
|
|
|
$tzid = null;
|
2009-11-26 19:36:19 +01:00
|
|
|
|
2010-04-23 13:03:32 +02:00
|
|
|
if ((!is_array($event) || empty($event['tzid']) && ($event = $event['id'])) &&
|
|
|
|
!($event = $this->read($event, $recurrence, false, 'server')))
|
2009-10-05 23:00:08 +02:00
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
if ($this->read($event, $recurrence, true, 'server'))
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
if ($this->check_perms(calendar_bo::ACL_FREEBUSY, $event, 0, 'server'))
|
2010-01-29 22:42:54 +01:00
|
|
|
{
|
2015-06-25 22:39:53 +02:00
|
|
|
$this->clear_private_infos($event, array($this->user, $event['owner']));
|
2010-05-14 10:35:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
|
|
|
'() User does not have the permission to read event ' . $event['id']. "\n",
|
|
|
|
3,$this->logfile);
|
|
|
|
}
|
|
|
|
return -1; // Permission denied
|
2010-01-29 22:42:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$retval = false; // Entry does not exist
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
2010-02-17 14:29:28 +01:00
|
|
|
"() Event $event not found.\n",
|
|
|
|
3, $this->logfile);
|
2010-01-29 22:42:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2011-03-05 11:21:32 +01:00
|
|
|
|
2010-06-23 16:52:55 +02:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
|
|
|
'() export event UID: ' . $event['uid'] . ".\n",
|
|
|
|
3, $this->logfile);
|
|
|
|
}
|
2010-01-29 22:42:54 +01:00
|
|
|
|
|
|
|
if ($this->tzid)
|
|
|
|
{
|
|
|
|
// explicit device timezone
|
|
|
|
$tzid = $this->tzid;
|
2009-10-05 23:00:08 +02:00
|
|
|
}
|
2010-02-09 22:56:39 +01:00
|
|
|
elseif ($this->tzid === false)
|
2009-10-05 23:00:08 +02:00
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
// use event's timezone
|
|
|
|
$tzid = $event['tzid'];
|
2009-10-05 23:00:08 +02:00
|
|
|
}
|
2010-01-29 22:42:54 +01:00
|
|
|
|
|
|
|
if (!isset(self::$tz_cache[$event['tzid']]))
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2017-12-18 13:47:27 +01:00
|
|
|
try {
|
|
|
|
self::$tz_cache[$event['tzid']] = calendar_timezones::DateTimeZone($event['tzid']);
|
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
// log unknown timezones
|
2017-12-20 12:16:34 +01:00
|
|
|
if (!empty($event['tzid'])) _egw_log_exception($e);
|
2017-12-18 13:47:27 +01:00
|
|
|
// default for no timezone and unkown to user timezone
|
|
|
|
self::$tz_cache[$event['tzid']] = Api\DateTime::$user_timezone;
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2010-01-29 22:42:54 +01:00
|
|
|
|
|
|
|
if ($this->so->isWholeDay($event)) $event['whole_day'] = true;
|
|
|
|
|
|
|
|
if ($this->log)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
|
|
|
'(' . $event['id']. ',' . $recurrence . ")\n" .
|
|
|
|
array2string($event)."\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($recurrence)
|
|
|
|
{
|
|
|
|
if (!($master = $this->read($event['id'], 0, true, 'server'))) continue;
|
|
|
|
|
|
|
|
if (!isset($this->supportedFields['participants']))
|
|
|
|
{
|
|
|
|
$days = $this->so->get_recurrence_exceptions($master, $tzid, 0, 0, 'tz_rrule');
|
|
|
|
if (isset($days[$recurrence]))
|
|
|
|
{
|
|
|
|
$recurrence = $days[$recurrence]; // use remote representation
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We don't need status only exceptions
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
2015-06-22 17:36:23 +02:00
|
|
|
"(, $recurrence) Gratuitous pseudo exception, skipped ...\n",
|
2010-01-29 22:42:54 +01:00
|
|
|
3,$this->logfile);
|
|
|
|
}
|
|
|
|
continue; // unsupported status only exception
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$days = $this->so->get_recurrence_exceptions($master, $tzid, 0, 0, 'rrule');
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n" .
|
|
|
|
array2string($days)."\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
$recurrence = $days[$recurrence]; // use remote representation
|
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
// 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-05 23:00:08 +02:00
|
|
|
|
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)
|
2011-10-08 20:40:29 +02:00
|
|
|
if (calendar_timezones::add_vtimezone($vcal, $tzid) ||
|
2016-05-01 19:47:59 +02:00
|
|
|
!in_array($tzid = Api\DateTime::$user_timezone->getName(), $vtimezones_added) &&
|
2011-10-08 20:40:29 +02:00
|
|
|
calendar_timezones::add_vtimezone($vcal, $tzid))
|
2009-10-06 16:29:46 +02:00
|
|
|
{
|
2011-10-08 20:40:29 +02:00
|
|
|
$vtimezones_added[] = $tzid;
|
|
|
|
if (!isset(self::$tz_cache[$tzid]))
|
2010-02-17 14:29:28 +01:00
|
|
|
{
|
2011-10-08 20:40:29 +02:00
|
|
|
self::$tz_cache[$tzid] = calendar_timezones::DateTimeZone($tzid);
|
2010-02-17 14:29:28 +01:00
|
|
|
}
|
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'] . "]";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-22 17:36:23 +02:00
|
|
|
$vevent = Horde_Icalendar::newComponent('VEVENT', $vcal);
|
2009-07-15 22:35:56 +02:00
|
|
|
$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
|
|
|
|
2010-01-29 22:42:54 +01:00
|
|
|
if ($event['recur_type'] != MCAL_RECUR_NONE)
|
|
|
|
{
|
|
|
|
$exceptions = array();
|
|
|
|
|
|
|
|
// dont use "virtual" exceptions created by participant status for GroupDAV or file export
|
|
|
|
if (!in_array($this->productManufacturer,array('file','groupdav')))
|
|
|
|
{
|
|
|
|
$filter = isset($this->supportedFields['participants']) ? 'rrule' : 'tz_rrule';
|
|
|
|
$exceptions = $this->so->get_recurrence_exceptions($event, $tzid, 0, 0, $filter);
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."(EXCEPTIONS)\n" .
|
|
|
|
array2string($exceptions)."\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif (is_array($event['recur_exception']))
|
|
|
|
{
|
|
|
|
$exceptions = array_unique($event['recur_exception']);
|
|
|
|
sort($exceptions);
|
|
|
|
}
|
|
|
|
$event['recur_exception'] = $exceptions;
|
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach ($egwSupportedFields as $icalFieldName => $egwFieldName)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2010-02-17 14:29:28 +01:00
|
|
|
if (!isset($this->supportedFields[$egwFieldName]))
|
|
|
|
{
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
|
|
|
'(' . $event['id'] . ") [$icalFieldName] not supported\n",
|
|
|
|
3,$this->logfile);
|
|
|
|
}
|
|
|
|
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':
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach ((array)$event['participants'] as $uid => $status)
|
2009-07-28 10:58:39 +02:00
|
|
|
{
|
2015-06-22 17:36:23 +02:00
|
|
|
$quantity = $role = null;
|
2010-06-23 17:54:07 +02:00
|
|
|
calendar_so::split_status($status, $quantity, $role);
|
2011-10-20 22:10:04 +02:00
|
|
|
// do not include event owner/ORGANIZER as participant in his own calendar, if he is only participant
|
2020-02-26 13:51:41 +01:00
|
|
|
if (count($event['participants']) == 1 && $event['owner'] == $uid && $uid == $this->user) continue;
|
2011-10-20 22:10:04 +02:00
|
|
|
|
2009-07-28 10:58:39 +02:00
|
|
|
if (!($info = $this->resource_info($uid))) continue;
|
2011-10-20 22:10:04 +02:00
|
|
|
|
2014-10-28 17:01:55 +01:00
|
|
|
if (in_array($status, array('X','E'))) continue; // dont include deleted participants
|
2012-09-26 16:30:47 +02:00
|
|
|
|
2010-03-22 19:03:23 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
|
|
|
|
'()attendee:' . array2string($info) ."\n",3,$this->logfile);
|
|
|
|
}
|
2010-05-18 12:04:29 +02:00
|
|
|
$participantCN = str_replace(array('\\', ',', ';', ':'),
|
|
|
|
array('\\\\', '\\,', '\\;', '\\:'),
|
2015-06-22 17:36:23 +02:00
|
|
|
trim(empty($info['cn']) ? $info['name'] : $info['cn']));
|
2010-03-22 19:03:23 +01:00
|
|
|
if ($version == '1.0')
|
|
|
|
{
|
2010-05-18 12:04:29 +02:00
|
|
|
$participantURL = trim('"' . $participantCN . '"' . (empty($info['email']) ? '' : ' <' . $info['email'] .'>'));
|
2010-03-22 19:03:23 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-23 10:45:11 +01:00
|
|
|
$participantURL = empty($info['email']) ? '' : 'mailto:' . $info['email'];
|
2010-03-22 19:03:23 +01:00
|
|
|
}
|
2010-06-28 00:16:22 +02:00
|
|
|
// RSVP={TRUE|FALSE} // resonse expected, not set in eGW => status=U
|
|
|
|
$rsvp = $status == 'U' ? 'TRUE' : 'FALSE';
|
2010-03-22 19:03:23 +01:00
|
|
|
if ($role == 'CHAIR')
|
2009-11-26 19:36:19 +01:00
|
|
|
{
|
2010-03-07 00:06:43 +01:00
|
|
|
$organizerURL = $participantURL;
|
2010-06-28 00:16:22 +02:00
|
|
|
$rsvp = '';
|
2009-11-26 19:36:19 +01:00
|
|
|
$organizerCN = $participantCN;
|
2015-09-28 10:11:31 +02:00
|
|
|
$organizerUID = ($info['type'] != 'e' ? (string)$uid : '');
|
2009-11-26 19:36:19 +01:00
|
|
|
}
|
2015-10-14 18:39:39 +02:00
|
|
|
// iCal method=REPLY only exports replying / current user, except external organiser / chair above
|
|
|
|
if ($method == 'REPLY' && $current_user && (string)$current_user !== (string)$uid)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2009-07-28 10:58:39 +02:00
|
|
|
// 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';
|
2016-04-05 00:39:49 +02:00
|
|
|
$participantURL = 'urn:uuid:'.Api\CalDAV::generate_uid('accounts', $uid);
|
2012-08-09 11:08:45 +02:00
|
|
|
if (!isset($event['participants'][$this->user]) &&
|
|
|
|
($members = $GLOBALS['egw']->accounts->members($uid, true)) && in_array($this->user, $members))
|
2010-06-28 07:08:22 +02:00
|
|
|
{
|
|
|
|
$user = $this->resource_info($this->user);
|
2015-01-23 10:45:11 +01:00
|
|
|
$attributes['ATTENDEE'][] = 'mailto:' . $user['email'];
|
2020-02-26 13:51:41 +01:00
|
|
|
$parameters['ATTENDEE'][] = array(
|
|
|
|
'CN' => $user['name'],
|
|
|
|
'ROLE' => 'REQ-PARTICIPANT',
|
2010-06-28 07:08:22 +02:00
|
|
|
'PARTSTAT' => 'NEEDS-ACTION',
|
|
|
|
'CUTYPE' => 'INDIVIDUAL',
|
|
|
|
'RSVP' => 'TRUE',
|
2015-09-28 10:11:31 +02:00
|
|
|
'X-EGROUPWARE-UID' => (string)$this->user,
|
2020-02-26 13:51:41 +01:00
|
|
|
);
|
|
|
|
$event['participants'][$this->user] = true;
|
2010-06-28 07:08:22 +02:00
|
|
|
}
|
2009-07-28 10:58:39 +02:00
|
|
|
break;
|
|
|
|
case 'r':
|
2016-04-05 00:39:49 +02:00
|
|
|
$participantURL = 'urn:uuid:'.Api\CalDAV::generate_uid('resources', substr($uid, 1));
|
|
|
|
$cutype = Api\CalDAV\Principals::resource_is_location(substr($uid, 1)) ? 'ROOM' : 'RESOURCE';
|
2011-11-08 22:09:06 +01:00
|
|
|
// unset resource email (email of responsible user) as iCal at least has problems,
|
|
|
|
// if resonpsible is also pariticipant or organizer
|
|
|
|
unset($info['email']);
|
2009-07-28 10:58:39 +02:00
|
|
|
break;
|
|
|
|
case 'u': // account
|
|
|
|
case 'c': // contact
|
|
|
|
case 'e': // email address
|
|
|
|
$cutype = 'INDIVIDUAL';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$cutype = 'UNKNOWN';
|
|
|
|
break;
|
2011-11-24 15:37:12 +01:00
|
|
|
}
|
2011-10-17 17:36:28 +02:00
|
|
|
// generate urn:uuid, if we have no other participant URL
|
|
|
|
if (empty($participantURL) && $info && $info['app'])
|
|
|
|
{
|
2016-04-05 00:39:49 +02:00
|
|
|
$participantURL = 'urn:uuid:'.Api\CalDAV::generate_uid($info['app'], substr($uid, 1));
|
2011-10-17 17:36:28 +02:00
|
|
|
}
|
2009-11-26 19:36:19 +01:00
|
|
|
// ROLE={CHAIR|REQ-PARTICIPANT|OPT-PARTICIPANT|NON-PARTICIPANT|X-*}
|
2010-06-28 00:16:22 +02:00
|
|
|
$options = array();
|
|
|
|
if (!empty($participantCN)) $options['CN'] = $participantCN;
|
|
|
|
if (!empty($role)) $options['ROLE'] = $role;
|
|
|
|
if (!empty($status)) $options['PARTSTAT'] = $status;
|
|
|
|
if (!empty($cutype)) $options['CUTYPE'] = $cutype;
|
|
|
|
if (!empty($rsvp)) $options['RSVP'] = $rsvp;
|
2015-01-23 10:45:11 +01:00
|
|
|
if (!empty($info['email']) && $participantURL != 'mailto:'.$info['email'])
|
2011-10-16 10:53:07 +02:00
|
|
|
{
|
|
|
|
$options['EMAIL'] = $info['email']; // only add EMAIL attribute, if not already URL, as eg. Akonadi is reported to have problems with it
|
|
|
|
}
|
2015-09-28 10:11:31 +02:00
|
|
|
if ($info['type'] != 'e') $options['X-EGROUPWARE-UID'] = (string)$uid;
|
2018-08-06 19:04:41 +02:00
|
|
|
if ($quantity > 1)
|
|
|
|
{
|
|
|
|
$options['X-EGROUPWARE-QUANTITY'] = (string)$quantity;
|
|
|
|
$options['CN'] .= ' ('.$quantity.')';
|
|
|
|
}
|
2011-10-17 17:36:28 +02:00
|
|
|
$attributes['ATTENDEE'][] = $participantURL;
|
2010-06-28 00:16:22 +02:00
|
|
|
$parameters['ATTENDEE'][] = $options;
|
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':
|
2018-12-11 12:45:17 +01:00
|
|
|
if ($event['public']) continue 2; // public is default, no need to export, fails CalDAVTester if added as default
|
2010-03-15 18:18:17 +01:00
|
|
|
$attributes['CLASS'] = $event['public'] ? 'PUBLIC' : 'PRIVATE';
|
2012-02-07 21:19:16 +01:00
|
|
|
// Apple iCal on OS X uses X-CALENDARSERVER-ACCESS: CONFIDENTIAL on VCALANDAR (not VEVENT!)
|
2015-07-29 15:31:03 +02:00
|
|
|
if (!$event['public'] && $this->productManufacturer == 'groupdav')
|
2015-06-22 16:13:28 +02:00
|
|
|
{
|
|
|
|
$vcal->setAttribute('X-CALENDARSERVER-ACCESS', 'CONFIDENTIAL');
|
|
|
|
}
|
2009-08-04 19:37:49 +02:00
|
|
|
break;
|
2009-07-28 10:58:39 +02:00
|
|
|
|
2020-02-26 13:51:41 +01:00
|
|
|
case 'ORGANIZER':
|
|
|
|
if (!$organizerURL)
|
|
|
|
{
|
|
|
|
$organizerCN = '"' . trim($GLOBALS['egw']->accounts->id2name($event['owner'],'account_firstname')
|
|
|
|
. ' ' . $GLOBALS['egw']->accounts->id2name($event['owner'],'account_lastname')) . '"';
|
|
|
|
$organizerEMail = $GLOBALS['egw']->accounts->id2name($event['owner'],'account_email');
|
|
|
|
if ($version == '1.0')
|
|
|
|
{
|
|
|
|
$organizerURL = trim($organizerCN . (empty($organizerURL) ? '' : ' <' . $organizerURL .'>'));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$organizerURL = empty($organizerEMail) ? '' : 'mailto:' . $organizerEMail;
|
|
|
|
}
|
|
|
|
$organizerUID = $event['owner'];
|
|
|
|
}
|
|
|
|
// do NOT use ORGANIZER for events without further participants or a different organizer
|
2021-05-31 22:35:12 +02:00
|
|
|
if (is_array($event['participants']) && (count($event['participants']) > 1 || !isset($event['participants'][$event['owner']])) || $event['owner'] != $this->user)
|
2020-02-26 13:51:41 +01:00
|
|
|
{
|
|
|
|
$attributes['ORGANIZER'] = $organizerURL;
|
|
|
|
$parameters['ORGANIZER']['CN'] = $organizerCN;
|
|
|
|
if (!empty($organizerUID))
|
|
|
|
{
|
|
|
|
$parameters['ORGANIZER']['X-EGROUPWARE-UID'] = $organizerUID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-07-28 10:58:39 +02:00
|
|
|
|
|
|
|
case 'DTSTART':
|
2010-04-23 15:52:45 +02:00
|
|
|
if (empty($event['whole_day']))
|
2010-01-29 22:42:54 +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':
|
2010-04-23 15:52:45 +02:00
|
|
|
if (empty($event['whole_day']))
|
2009-07-28 10:58:39 +02:00
|
|
|
{
|
2015-09-29 12:25:32 +02:00
|
|
|
// Hack for CalDAVTester to export duration instead of endtime
|
2021-11-10 11:22:58 +01:00
|
|
|
if ($tzid == 'UTC' && ($duration = Api\DateTime::to($event['end'], 'ts') - Api\DateTime::to($event['start'], 'ts')) <= 86400)
|
|
|
|
$attributes['duration'] = $duration;
|
2015-09-29 12:25:32 +02:00
|
|
|
else
|
2017-06-12 12:33:33 +02:00
|
|
|
$attributes['DTEND'] = self::getDateTime($event['end'],$tzid,$parameters['DTEND']);
|
2010-04-23 15:52:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// write start + end of whole day events as dates
|
2021-01-25 18:27:20 +01:00
|
|
|
if(!is_object($event['end']))
|
|
|
|
{
|
|
|
|
$event['end'] = new Api\DateTime($event['end']);
|
|
|
|
}
|
|
|
|
$event['end-nextday'] = clone $event['end'];
|
|
|
|
$event['end-nextday']->add("1 day"); // 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
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$time = new Api\DateTime($event[$f],Api\DateTime::$server_timezone);
|
|
|
|
$arr = Api\DateTime::to($time,'array');
|
2009-07-28 10:58:39 +02:00
|
|
|
$vevent->setAttribute($t, array('year' => $arr['year'],'month' => $arr['month'],'mday' => $arr['day']),
|
|
|
|
array('VALUE' => 'DATE'));
|
|
|
|
}
|
|
|
|
unset($attributes['DTSTART']);
|
2012-02-03 23:28:00 +01:00
|
|
|
// Outlook does NOT care about type of DTSTART/END, only setting X-MICROSOFT-CDO-ALLDAYEVENT is used to determine an event is a whole-day event
|
|
|
|
$vevent->setAttribute('X-MICROSOFT-CDO-ALLDAYEVENT','TRUE');
|
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
|
2010-01-29 22:42:54 +01:00
|
|
|
$rriter = calendar_rrule::event2rrule($event, false, $tzid);
|
2009-11-12 20:08:23 +01:00
|
|
|
$rrule = $rriter->generate_rrule($version);
|
2010-06-12 00:13:27 +02:00
|
|
|
if ($event['recur_enddate'])
|
|
|
|
{
|
2010-06-14 16:54:24 +02:00
|
|
|
if (!$tzid || $version != '1.0')
|
2010-06-12 00:13:27 +02:00
|
|
|
{
|
|
|
|
if (!isset(self::$tz_cache['UTC']))
|
|
|
|
{
|
|
|
|
self::$tz_cache['UTC'] = calendar_timezones::DateTimeZone('UTC');
|
|
|
|
}
|
2017-03-29 19:31:53 +02:00
|
|
|
if (empty($event['whole_day']))
|
|
|
|
{
|
|
|
|
$rrule['UNTIL']->setTimezone(self::$tz_cache['UTC']);
|
|
|
|
$rrule['UNTIL'] = $rrule['UNTIL']->format('Ymd\THis\Z');
|
|
|
|
}
|
|
|
|
// for whole-day events UNTIL must be just the inclusive date
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$rrule['UNTIL'] = $rrule['UNTIL']->format('Ymd');
|
|
|
|
}
|
2010-06-12 00:13:27 +02:00
|
|
|
}
|
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($version == '1.0')
|
|
|
|
{
|
2010-06-11 14:16:58 +02:00
|
|
|
if ($event['recur_enddate'] && $tzid)
|
2011-03-05 11:21:32 +01:00
|
|
|
{
|
2010-06-12 00:13:27 +02:00
|
|
|
$rrule['UNTIL'] = self::getDateTime($rrule['UNTIL'],$tzid);
|
2010-06-11 08:19:22 +02:00
|
|
|
}
|
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'] = '';
|
2015-06-25 22:39:53 +02:00
|
|
|
foreach($rrule as $n => $v)
|
|
|
|
{
|
|
|
|
$attributes['RRULE'] .= ($attributes['RRULE']?';':'').$n.'='.$v;
|
|
|
|
}
|
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;
|
2010-01-29 22:42:54 +01:00
|
|
|
if (!empty($event['recur_exception']))
|
2009-07-28 10:58:39 +02:00
|
|
|
{
|
2010-04-23 15:52:45 +02:00
|
|
|
if (empty($event['whole_day']))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2010-04-23 15:52:45 +02:00
|
|
|
foreach ($event['recur_exception'] as $key => $timestamp)
|
|
|
|
{
|
2020-04-28 18:47:38 +02:00
|
|
|
// current Horde_Icalendar 2.1.4 exports EXDATE always in UTC, postfixed with a Z :(
|
2020-01-10 11:13:18 +01:00
|
|
|
// so if we set a timezone here, we have to remove the Z, see the hack at the end of this method
|
2016-04-27 18:27:04 +02:00
|
|
|
// Apple calendar on OS X 10.11.4 uses a timezone, so does Horde eg. for Recurrence-ID
|
2020-04-28 18:47:38 +02:00
|
|
|
$ex_date = new Api\DateTime($timestamp, Api\DateTime::$server_timezone);
|
|
|
|
$event['recur_exception'][$key] = self::getDateTime($ex_date->format('ts') + $ex_date->getOffset(), $tzid, $parameters['EXDATE']);
|
2010-08-26 22:28:54 +02:00
|
|
|
}
|
2010-04-23 15:52:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// use 'DATE' instead of 'DATE-TIME' on whole day events
|
2010-01-29 22:42:54 +01:00
|
|
|
foreach ($event['recur_exception'] as $id => $timestamp)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$time = new Api\DateTime($timestamp,Api\DateTime::$server_timezone);
|
2010-01-29 22:42:54 +01:00
|
|
|
$time->setTimezone(self::$tz_cache[$event['tzid']]);
|
2016-05-01 19:47:59 +02:00
|
|
|
$arr = Api\DateTime::to($time,'array');
|
2009-07-28 10:58:39 +02:00
|
|
|
$days[$id] = array(
|
|
|
|
'year' => $arr['year'],
|
|
|
|
'month' => $arr['month'],
|
|
|
|
'mday' => $arr['day'],
|
|
|
|
);
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2010-01-29 22:42:54 +01:00
|
|
|
$event['recur_exception'] = $days;
|
2010-08-26 22:28:54 +02:00
|
|
|
if ($version != '1.0') $parameters['EXDATE']['VALUE'] = 'DATE';
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2015-07-16 14:53:28 +02:00
|
|
|
$vevent->setAttribute('EXDATE', $event['recur_exception'], $parameters['EXDATE']);
|
2009-07-28 10:58:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'PRIORITY':
|
2018-12-11 12:45:17 +01:00
|
|
|
if (!$event['priority']) continue 2; // 0=undefined is default, no need to export, fails CalDAVTester if our default is added
|
2010-01-09 23:28:41 +01:00
|
|
|
if ($this->productManufacturer == 'funambol' &&
|
|
|
|
(strpos($this->productName, 'outlook') !== false
|
|
|
|
|| strpos($this->productName, 'pocket pc') !== false))
|
2010-01-02 14:25:58 +01:00
|
|
|
{
|
|
|
|
$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':
|
2018-12-11 12:45:17 +01:00
|
|
|
if (!$event['non_blocking']) continue 2; // OPAQUE is default, no need to export, fails CalDAVTester if added as default
|
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
|
|
|
|
2010-02-23 19:19:12 +01:00
|
|
|
case 'STATUS':
|
|
|
|
$attributes['STATUS'] = 'CONFIRMED';
|
|
|
|
break;
|
|
|
|
|
2009-07-28 10:58:39 +02:00
|
|
|
case 'CATEGORIES':
|
2010-01-08 14:09:36 +01:00
|
|
|
if ($event['category'] && ($values['CATEGORIES'] = $this->get_categories($event['category'])))
|
2009-07-28 10:58:39 +02:00
|
|
|
{
|
2010-01-08 14:09:36 +01:00
|
|
|
if (count($values['CATEGORIES']) == 1)
|
|
|
|
{
|
|
|
|
$attributes['CATEGORIES'] = array_shift($values['CATEGORIES']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$attributes['CATEGORIES'] = '';
|
|
|
|
}
|
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 'RECURRENCE-ID':
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($version == '1.0')
|
|
|
|
{
|
|
|
|
$icalFieldName = 'X-RECURRENCE-ID';
|
|
|
|
}
|
2010-02-23 19:19:12 +01:00
|
|
|
if ($recur_date)
|
2009-07-28 10:58:39 +02:00
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
// We handle a pseudo exception
|
2010-04-23 15:52:45 +02:00
|
|
|
if (empty($event['whole_day']))
|
|
|
|
{
|
|
|
|
$attributes[$icalFieldName] = self::getDateTime($recur_date,$tzid,$parameters[$icalFieldName]);
|
|
|
|
}
|
|
|
|
else
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$time = new Api\DateTime($recur_date,Api\DateTime::$server_timezone);
|
2010-01-29 22:42:54 +01:00
|
|
|
$time->setTimezone(self::$tz_cache[$event['tzid']]);
|
2016-05-01 19:47:59 +02:00
|
|
|
$arr = Api\DateTime::to($time,'array');
|
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
|
|
|
}
|
|
|
|
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
|
|
|
|
2010-04-23 15:52:45 +02:00
|
|
|
if (empty($revent['whole_day']))
|
|
|
|
{
|
|
|
|
$attributes[$icalFieldName] = self::getDateTime($event['recurrence'],$tzid,$parameters[$icalFieldName]);
|
|
|
|
}
|
|
|
|
else
|
2009-07-28 10:58:39 +02:00
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$time = new Api\DateTime($event['recurrence'],Api\DateTime::$server_timezone);
|
2010-01-29 22:42:54 +01:00
|
|
|
$time->setTimezone(self::$tz_cache[$event['tzid']]);
|
2016-05-01 19:47:59 +02:00
|
|
|
$arr = Api\DateTime::to($time,'array');
|
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')
|
|
|
|
);
|
|
|
|
}
|
2010-04-23 15:52:45 +02:00
|
|
|
|
2009-07-28 10:58:39 +02:00
|
|
|
unset($revent);
|
|
|
|
}
|
|
|
|
break;
|
2009-07-15 22:35:56 +02:00
|
|
|
|
2013-09-23 12:21:31 +02:00
|
|
|
case 'ATTACH':
|
2018-02-02 17:27:59 +01:00
|
|
|
if (!empty($event['id']))
|
|
|
|
{
|
|
|
|
Api\CalDAV::add_attach('calendar', $event['id'], $attributes, $parameters);
|
|
|
|
}
|
2013-09-23 12:21:31 +02:00
|
|
|
break;
|
|
|
|
|
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'];
|
2010-01-10 20:02:16 +01:00
|
|
|
if ($this->log && $size > 0)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
|
|
|
|
"() $icalFieldName Size: $size, NoTruncate: " .
|
|
|
|
($noTruncate ? 'TRUE' : 'FALSE') . "\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
//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)
|
|
|
|
{
|
2010-01-10 20:02:16 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
|
|
|
|
"() $icalFieldName omitted due to maximum size $size\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
//Horde::logMessage("vCalendar $icalFieldName omitted due to maximum size $size",
|
|
|
|
// __FILE__, __LINE__, PEAR_LOG_WARNING);
|
2018-12-11 12:45:17 +01:00
|
|
|
continue 2; // 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);
|
2010-01-10 20:02:16 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
|
|
|
|
"() $icalFieldName truncated to maximum size $size\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
//Horde::logMessage("vCalendar $icalFieldName truncated to maximum size $size",
|
|
|
|
// __FILE__, __LINE__, PEAR_LOG_INFO);
|
2009-07-28 10:58:39 +02:00
|
|
|
}
|
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;
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-25 22:39:53 +02:00
|
|
|
// for CalDAV add all X-Properties previously parsed
|
|
|
|
if ($this->productManufacturer == 'groupdav' || $this->productManufacturer == 'file')
|
|
|
|
{
|
|
|
|
foreach($event as $name => $value)
|
|
|
|
{
|
|
|
|
if (substr($name, 0, 2) == '##')
|
|
|
|
{
|
2021-04-20 19:44:44 +02:00
|
|
|
$attr_name = substr($name, 2);
|
|
|
|
// Apply prefix to our stuff
|
|
|
|
if(in_array($attr_name,['videoconference','notify_externals']))
|
|
|
|
{
|
|
|
|
$attr_name = 'X-EGROUPWARE-'.$attr_name;
|
|
|
|
}
|
2018-12-09 13:48:35 +01:00
|
|
|
if ($value[0] === '{' && ($attr = json_decode($value, true)) && is_array($attr))
|
2015-06-25 22:39:53 +02:00
|
|
|
{
|
2018-12-09 13:48:35 +01:00
|
|
|
// check if attribute was stored compressed --> uncompress it
|
|
|
|
if (count($attr) === 1 && !empty($attr['gzcompress']))
|
|
|
|
{
|
|
|
|
$attr = json_decode(gzuncompress(base64_decode($attr['gzcompress'])), true);
|
|
|
|
if (!is_array($attr)) continue;
|
|
|
|
}
|
2021-04-20 19:44:44 +02:00
|
|
|
$vevent->setAttribute($attr_name, $attr['value'], $attr['params'], true, $attr['values']);
|
2015-06-25 22:39:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-20 19:44:44 +02:00
|
|
|
$vevent->setAttribute($attr_name, $value);
|
2015-06-25 22:39:53 +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
|
|
|
}
|
2010-04-23 16:38:07 +02:00
|
|
|
elseif ($event['special'] == '2' || !empty($event['whole_day']))
|
2009-10-25 19:22:01 +01:00
|
|
|
{
|
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';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-05 19:57:59 +02:00
|
|
|
if ($event['created'] || $event['modified'])
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2010-08-05 19:57:59 +02:00
|
|
|
$attributes['CREATED'] = $event['created'] ? $event['created'] : $event['modified'];
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2012-09-25 13:54:41 +02:00
|
|
|
if ($event['modified'])
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2010-08-05 19:57:59 +02:00
|
|
|
$attributes['LAST-MODIFIED'] = $event['modified'];
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
$attributes['DTSTAMP'] = time();
|
2015-06-22 17:36:23 +02:00
|
|
|
foreach ((array)$event['alarm'] as $alarmData)
|
2009-08-23 21:26:14 +02:00
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
// skip over alarms that don't have the minimum required info
|
2015-06-25 22:39:53 +02:00
|
|
|
if (!isset($alarmData['offset']) && !isset($alarmData['time'])) continue;
|
2010-01-29 22:42:54 +01: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
|
|
|
|
2010-01-29 22:42:54 +01:00
|
|
|
if ($alarmData['offset'])
|
|
|
|
{
|
2021-11-05 14:58:38 +01:00
|
|
|
$alarmData['time'] = Api\DateTime::to($event['start'], 'ts') - $alarmData['offset'];
|
2010-01-29 22:42:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$description = trim(preg_replace("/\r?\n?\\[[A-Z_]+:.*\\]/i", '', $event['description']));
|
|
|
|
|
2009-08-23 21:26:14 +02:00
|
|
|
if ($version == '1.0')
|
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
if ($event['title']) $description = $event['title'];
|
|
|
|
if ($description)
|
|
|
|
{
|
|
|
|
$values['DALARM']['snooze_time'] = '';
|
|
|
|
$values['DALARM']['repeat count'] = '';
|
|
|
|
$values['DALARM']['display text'] = $description;
|
|
|
|
$values['AALARM']['snooze_time'] = '';
|
|
|
|
$values['AALARM']['repeat count'] = '';
|
|
|
|
$values['AALARM']['display text'] = $description;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
// RFC requires DESCRIPTION for DISPLAY
|
2015-06-25 22:39:53 +02:00
|
|
|
if (!$event['title'] && !$description) $description = 'Alarm';
|
2011-03-05 11:21:32 +01:00
|
|
|
|
2015-06-25 22:39:53 +02:00
|
|
|
/* Disabling for now
|
2011-03-07 14:49:08 +01:00
|
|
|
// Lightning infinitly pops up alarms for recuring events, if the only use an offset
|
|
|
|
if ($this->productName == 'lightning' && $event['recur_type'] != MCAL_RECUR_NONE)
|
2010-05-18 16:41:22 +02:00
|
|
|
{
|
|
|
|
// return only future alarms to lightning
|
|
|
|
if (($nextOccurence = $this->read($event['id'], $this->now_su + $alarmData['offset'], false, 'server')))
|
|
|
|
{
|
|
|
|
$alarmData['time'] = $nextOccurence['start'] - $alarmData['offset'];
|
2011-03-05 11:21:32 +01:00
|
|
|
$alarmData['offset'] = false;
|
2010-05-18 16:41:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2015-06-25 22:39:53 +02:00
|
|
|
}*/
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2011-03-07 14:49:08 +01:00
|
|
|
// for SyncML non-whole-day events always use absolute times
|
|
|
|
// (probably because some devices have no clue about timezones)
|
|
|
|
// GroupDAV uses offsets, as web UI assumes alarms are relative too
|
|
|
|
// (with absolute times GroupDAV clients do NOT move alarms, if events move!)
|
2015-07-29 15:31:03 +02:00
|
|
|
if ($this->productManufacturer != 'groupdav' &&
|
2011-03-07 14:49:08 +01:00
|
|
|
!empty($event['whole_day']) && $alarmData['offset'])
|
2009-10-05 23:00:08 +02:00
|
|
|
{
|
|
|
|
$alarmData['offset'] = false;
|
2011-03-05 11:21:32 +01:00
|
|
|
}
|
|
|
|
|
2015-06-22 17:36:23 +02:00
|
|
|
$valarm = Horde_Icalendar::newComponent('VALARM',$vevent);
|
2011-03-07 14:49:08 +01:00
|
|
|
if ($alarmData['offset'] !== false)
|
2009-08-23 21:26:14 +02:00
|
|
|
{
|
2008-06-07 19:45:33 +02:00
|
|
|
$valarm->setAttribute('TRIGGER', -$alarmData['offset'],
|
2015-06-25 22:39:53 +02:00
|
|
|
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
|
|
|
}
|
2015-06-25 22:39:53 +02:00
|
|
|
if (!empty($alarmData['uid']))
|
|
|
|
{
|
|
|
|
$valarm->setAttribute('UID', $alarmData['uid']);
|
|
|
|
$valarm->setAttribute('X-WR-ALARMUID', $alarmData['uid']);
|
|
|
|
}
|
|
|
|
// set evtl. existing attributes set by iCal clients not used by EGroupware
|
|
|
|
if (isset($alarmData['attrs']))
|
|
|
|
{
|
|
|
|
foreach($alarmData['attrs'] as $attr => $data)
|
|
|
|
{
|
|
|
|
$valarm->setAttribute($attr, $data['value'], $data['params']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// set default ACTION and DESCRIPTION, if not set by a client
|
|
|
|
if (!isset($alarmData['attrs']) || !isset($alarmData['attrs']['ACTION']))
|
|
|
|
{
|
|
|
|
$valarm->setAttribute('ACTION','DISPLAY');
|
|
|
|
}
|
|
|
|
if (!isset($alarmData['attrs']) || !isset($alarmData['attrs']['DESCRIPTION']))
|
|
|
|
{
|
|
|
|
$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
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
foreach (is_array($value) && $parameters[$key]['VALUE']!='DATE' ? $value : array($value) as $valueID => $valueData)
|
2009-08-23 21:26:14 +02:00
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$valueData = Api\Translation::convert($valueData,Api\Translation::charset(),$charset);
|
2020-02-26 13:51:41 +01:00
|
|
|
$paramData = (array) Api\Translation::convert(is_array($value) ?
|
|
|
|
$parameters[$key][$valueID] : $parameters[$key],
|
|
|
|
Api\Translation::charset(),$charset);
|
|
|
|
$valuesData = (array) Api\Translation::convert($values[$key],
|
|
|
|
Api\Translation::charset(),$charset);
|
|
|
|
$content = $valueData . implode(';', $valuesData);
|
2010-01-10 20:02:16 +01:00
|
|
|
|
2015-07-23 17:51:26 +02:00
|
|
|
if ($version == '1.0' && (preg_match('/[^\x20-\x7F]/', $content) ||
|
|
|
|
($paramData['CN'] && preg_match('/[^\x20-\x7F]/', $paramData['CN']))))
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2010-03-22 19:03:23 +01:00
|
|
|
$paramData['CHARSET'] = $charset;
|
2010-01-08 14:09:36 +01:00
|
|
|
switch ($this->productManufacturer)
|
|
|
|
{
|
|
|
|
case 'groupdav':
|
|
|
|
if ($this->productName == 'kde')
|
|
|
|
{
|
2010-01-09 19:04:21 +01:00
|
|
|
$paramData['ENCODING'] = 'QUOTED-PRINTABLE';
|
2010-01-08 14:09:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-09 19:04:21 +01:00
|
|
|
$paramData['CHARSET'] = '';
|
2019-05-24 15:10:48 +02:00
|
|
|
if (preg_match(Api\CalDAV\Handler::REQUIRE_QUOTED_PRINTABLE_ENCODING, $valueData))
|
2010-01-08 14:09:36 +01:00
|
|
|
{
|
2010-01-09 19:04:21 +01:00
|
|
|
$paramData['ENCODING'] = 'QUOTED-PRINTABLE';
|
2010-01-08 14:09:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-09 19:04:21 +01:00
|
|
|
$paramData['ENCODING'] = '';
|
2010-01-08 14:09:36 +01:00
|
|
|
}
|
2015-07-23 17:51:26 +02:00
|
|
|
}
|
2010-01-08 14:09:36 +01:00
|
|
|
break;
|
|
|
|
case 'funambol':
|
2010-01-09 19:04:21 +01:00
|
|
|
$paramData['ENCODING'] = 'FUNAMBOL-QP';
|
2010-01-08 14:09:36 +01:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2019-05-28 16:25:11 +02:00
|
|
|
/*
|
|
|
|
if (preg_match('/([\000-\012])/', $valueData))
|
2009-04-02 14:35:26 +02:00
|
|
|
{
|
2019-05-28 16:25:11 +02: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
|
|
|
}
|
2019-05-28 16:25:11 +02:00
|
|
|
*/
|
2010-01-09 19:04:21 +01:00
|
|
|
$vevent->setAttribute($key, $valueData, $paramData, true, $valuesData);
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$vcal->addComponent($vevent);
|
2010-02-24 16:05:00 +01:00
|
|
|
$events_exported = true;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
|
2010-02-24 16:05:00 +01:00
|
|
|
$retval = $events_exported ? $vcal->exportvCalendar() : false;
|
2010-01-09 19:04:21 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
|
|
|
|
"() '$this->productManufacturer','$this->productName'\n",3,$this->logfile);
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
|
|
|
|
"()\n".array2string($retval)."\n",3,$this->logfile);
|
|
|
|
}
|
2020-01-10 11:13:18 +01:00
|
|
|
|
|
|
|
// hack to fix iCalendar exporting EXDATE always postfixed with a Z
|
|
|
|
// EXDATE can have multiple values and therefore be folded into multiple lines
|
2020-04-15 21:40:14 +02:00
|
|
|
return preg_replace_callback("/\nEXDATE;TZID=[^:]+:[0-9TZ \r\n,]+/", function($matches)
|
2020-01-10 11:13:18 +01:00
|
|
|
{
|
|
|
|
return preg_replace('/([0-9 ])Z/', '$1', $matches[0]);
|
|
|
|
}, $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')
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
return Api\DateTime::to($time,'ts');
|
2009-11-10 16:08:35 +01:00
|
|
|
}
|
|
|
|
if (!is_a($time,'DateTime'))
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$time = new Api\DateTime($time,Api\DateTime::$server_timezone);
|
2009-11-10 16:08:35 +01:00
|
|
|
}
|
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');
|
|
|
|
}
|
|
|
|
|
2010-04-14 12:19:41 +02:00
|
|
|
/**
|
|
|
|
* Number of events imported in last call to importVCal
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
var $events_imported;
|
|
|
|
|
2008-06-07 19:45:33 +02:00
|
|
|
/**
|
|
|
|
* Import an iCal
|
|
|
|
*
|
2013-03-14 16:40:05 +01:00
|
|
|
* @param string|resource $_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)
|
2010-03-07 00:06:43 +01:00
|
|
|
* @param string $principalURL='' Used for CalDAV imports
|
|
|
|
* @param int $user=null account_id of owner, default null
|
2010-03-22 19:03:23 +01:00
|
|
|
* @param string $charset The encoding charset for $text. Defaults to
|
|
|
|
* utf-8 for new format, iso-8859-1 for old format.
|
2011-04-06 21:26:10 +02:00
|
|
|
* @param string $caldav_name=null name from CalDAV client or null (to use default)
|
2015-09-30 05:27:29 +02:00
|
|
|
* @return int|boolean|null cal_id > 0 on success, false on failure or 0 for a failed etag|permission denied or null for "403 Forbidden"
|
2008-06-07 19:45:33 +02:00
|
|
|
*/
|
2012-12-18 00:56:56 +01:00
|
|
|
function importVCal($_vcalData, $cal_id=-1, $etag=null, $merge=false, $recur_date=0, $principalURL='', $user=null, $charset=null, $caldav_name=null,$skip_notification=false)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2011-04-06 21:26:10 +02:00
|
|
|
//error_log(__METHOD__."(, $cal_id, $etag, $merge, $recur_date, $principalURL, $user, $charset, $caldav_name)");
|
2010-04-14 12:19:41 +02:00
|
|
|
$this->events_imported = 0;
|
2010-06-26 17:58:33 +02:00
|
|
|
$replace = $delete_exceptions= false;
|
2010-04-14 12:19:41 +02:00
|
|
|
|
2010-01-08 14:09:36 +01:00
|
|
|
if (!is_array($this->supportedFields)) $this->setSupportedFields();
|
|
|
|
|
2010-03-22 19:03:23 +01:00
|
|
|
if (!($events = $this->icaltoegw($_vcalData, $principalURL, $charset)))
|
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
|
|
|
}
|
2010-04-14 12:19:41 +02:00
|
|
|
if (!is_array($events)) $cal_id = -1; // just to be sure, as iterator does NOT allow array access (eg. $events[0])
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2010-02-17 14:29:28 +01:00
|
|
|
if ($cal_id > 0)
|
|
|
|
{
|
|
|
|
if (count($events) == 1)
|
|
|
|
{
|
2010-06-26 17:58:33 +02:00
|
|
|
$replace = $recur_date == 0;
|
2010-02-17 14:29:28 +01:00
|
|
|
$events[0]['id'] = $cal_id;
|
|
|
|
if (!is_null($etag)) $events[0]['etag'] = (int) $etag;
|
|
|
|
if ($recur_date) $events[0]['recurrence'] = $recur_date;
|
|
|
|
}
|
|
|
|
elseif (($foundEvent = $this->find_event(array('id' => $cal_id), 'exact')) &&
|
|
|
|
($eventId = array_shift($foundEvent)) &&
|
|
|
|
($egwEvent = $this->read($eventId)))
|
|
|
|
{
|
|
|
|
foreach ($events as $k => $event)
|
|
|
|
{
|
|
|
|
if (!isset($event['uid'])) $events[$k]['uid'] = $egwEvent['uid'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2010-01-05 12:24:27 +01:00
|
|
|
// and for real (not status only) exceptions their recurrence-id need
|
2009-12-27 05:21:33 +01:00
|
|
|
// to be included as recur_exception to the master
|
2009-12-27 16:49:40 +01:00
|
|
|
if ($this->productManufacturer == 'groupdav' && $cal_id > 0 &&
|
2009-12-27 05:21:33 +01:00
|
|
|
$events[0]['recur_type'] != MCAL_RECUR_NONE)
|
|
|
|
{
|
2016-04-27 18:23:30 +02:00
|
|
|
calendar_groupdav::fix_series($events);
|
2009-12-27 05:21:33 +01:00
|
|
|
}
|
2011-03-05 11:21:32 +01:00
|
|
|
|
2010-05-21 08:18:52 +02:00
|
|
|
if ($this->tzid)
|
|
|
|
{
|
|
|
|
$tzid = $this->tzid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$tzid = Api\DateTime::$user_timezone->getName();
|
2010-05-21 08:18:52 +02:00
|
|
|
}
|
2011-03-05 11:21:32 +01:00
|
|
|
|
2010-05-21 08:18:52 +02:00
|
|
|
date_default_timezone_set($tzid);
|
2011-03-05 11:21:32 +01:00
|
|
|
|
2020-08-21 13:59:15 +02:00
|
|
|
$msg = $master = null;
|
2009-09-22 15:43:55 +02:00
|
|
|
foreach ($events as $event)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2010-05-21 08:18:52 +02:00
|
|
|
if (!is_array($event)) continue; // the iterator may return false
|
2019-03-27 17:26:50 +01:00
|
|
|
|
|
|
|
// Run event through callback
|
|
|
|
if($this->event_callback && is_callable($this->event_callback))
|
|
|
|
{
|
|
|
|
if(!call_user_func_array($this->event_callback, array(&$event)))
|
|
|
|
{
|
|
|
|
// Callback cancelled event
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2010-04-14 12:19:41 +02:00
|
|
|
++$this->events_imported;
|
|
|
|
|
2010-01-29 22:42:54 +01:00
|
|
|
if ($this->so->isWholeDay($event)) $event['whole_day'] = true;
|
2010-02-17 14:29:28 +01:00
|
|
|
if (is_array($event['category']))
|
|
|
|
{
|
|
|
|
$event['category'] = $this->find_or_add_categories($event['category'],
|
|
|
|
isset($event['id']) ? $event['id'] : -1);
|
|
|
|
}
|
2010-01-09 19:04:21 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
2010-03-07 00:06:43 +01:00
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
|
2010-03-22 19:03:23 +01:00
|
|
|
."($cal_id, $etag, $recur_date, $principalURL, $user, $charset)\n"
|
2010-03-07 00:06:43 +01:00
|
|
|
. array2string($event)."\n",3,$this->logfile);
|
2010-01-09 19:04:21 +01:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
|
2010-06-26 17:58:33 +02:00
|
|
|
$updated_id = false;
|
2011-03-05 11:21:32 +01:00
|
|
|
|
2010-06-26 17:58:33 +02:00
|
|
|
if ($replace)
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
2010-06-26 17:58:33 +02:00
|
|
|
$event_info['type'] = $event['recur_type'] == MCAL_RECUR_NONE ?
|
|
|
|
'SINGLE' : 'SERIES-MASTER';
|
2016-05-01 19:47:59 +02:00
|
|
|
$event_info['acl_edit'] = $this->check_perms(Acl::EDIT, $cal_id);
|
2010-06-26 17:58:33 +02:00
|
|
|
if (($event_info['stored_event'] = $this->read($cal_id, 0, false, 'server')) &&
|
|
|
|
$event_info['stored_event']['recur_type'] != MCAL_RECUR_NONE &&
|
|
|
|
($event_info['stored_event']['recur_type'] != $event['recur_type']
|
|
|
|
|| $event_info['stored_event']['recur_interval'] != $event['recur_interval']
|
|
|
|
|| $event_info['stored_event']['recur_data'] != $event['recur_data']
|
|
|
|
|| $event_info['stored_event']['start'] != $event['start']))
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
2010-06-26 17:58:33 +02:00
|
|
|
// handle the old exceptions
|
|
|
|
$recur_exceptions = $this->so->get_related($event_info['stored_event']['uid']);
|
|
|
|
foreach ($recur_exceptions as $id)
|
2010-01-29 22:42:54 +01:00
|
|
|
{
|
2010-06-26 17:58:33 +02:00
|
|
|
if ($delete_exceptions)
|
2010-01-29 22:42:54 +01:00
|
|
|
{
|
2012-12-18 00:56:56 +01:00
|
|
|
$this->delete($id,0,false,$skip_notification);
|
2010-06-26 17:58:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!($exception = $this->read($id))) continue;
|
2016-04-05 00:39:49 +02:00
|
|
|
$exception['uid'] = Api\CalDAV::generate_uid('calendar', $id);
|
2010-06-26 17:58:33 +02:00
|
|
|
$exception['reference'] = $exception['recurrence'] = 0;
|
2012-12-18 00:56:56 +01:00
|
|
|
$this->update($exception, true,true,false,true,$msg,$skip_notification);
|
2010-01-29 22:42:54 +01:00
|
|
|
}
|
|
|
|
}
|
2009-11-26 19:36:19 +01:00
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
2010-06-26 17:58:33 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$event_info = $this->get_event_info($event);
|
|
|
|
}
|
2010-01-29 22:42:54 +01: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
|
|
|
{
|
2010-05-19 11:20:15 +02:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
|
|
|
|
. "(UPDATE Event)\n"
|
|
|
|
. array2string($event_info['stored_event'])."\n",3,$this->logfile);
|
|
|
|
}
|
2010-01-11 19:15:44 +01:00
|
|
|
if (empty($event['uid']))
|
|
|
|
{
|
|
|
|
$event['uid'] = $event_info['stored_event']['uid']; // restore the UID if it was not delivered
|
|
|
|
}
|
2010-02-09 22:56:39 +01:00
|
|
|
elseif (empty($event['id']))
|
|
|
|
{
|
|
|
|
$event['id'] = $event_info['stored_event']['id']; // CalDAV does only provide UIDs
|
|
|
|
}
|
2010-04-14 16:44:21 +02:00
|
|
|
if (is_array($event['participants']))
|
|
|
|
{
|
|
|
|
// if the client does not return a status, we restore the original one
|
|
|
|
foreach ($event['participants'] as $uid => $status)
|
|
|
|
{
|
|
|
|
if ($status[0] == 'X')
|
|
|
|
{
|
|
|
|
if (isset($event_info['stored_event']['participants'][$uid]))
|
|
|
|
{
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
|
|
|
"() Restore status for $uid\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
$event['participants'][$uid] = $event_info['stored_event']['participants'][$uid];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$event['participants'][$uid] = calendar_so::combine_status('U');
|
|
|
|
}
|
|
|
|
}
|
2018-08-06 19:04:41 +02:00
|
|
|
// restore resource-quantity from existing event as neither iOS nor Thunderbird returns our X-EGROUPWARE-QUANTITY
|
|
|
|
elseif ($uid[0] === 'r' && isset($event_info['stored_event']['participants'][$uid]))
|
|
|
|
{
|
|
|
|
$quantity = $role = $old_quantity = null;
|
|
|
|
calendar_so::split_status($status, $quantity, $role);
|
|
|
|
calendar_so::split_status($event_info['stored_event']['participants'][$uid], $old_quantity);
|
|
|
|
if ($old_quantity > 1)
|
|
|
|
{
|
|
|
|
$event['participants'][$uid] = calendar_so::combine_status('U', $old_quantity, $role);
|
|
|
|
}
|
|
|
|
}
|
2010-04-14 16:44:21 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-05 11:17:37 +02:00
|
|
|
// unset old X-* attributes stored in custom-fields with exception of our videoconference and notify-externals
|
2015-06-25 22:39:53 +02:00
|
|
|
foreach ($event_info['stored_event'] as $key => $value)
|
|
|
|
{
|
|
|
|
if ($key[0] == '#' && $key[1] == '#' && !isset($event[$key]))
|
|
|
|
{
|
2020-06-05 11:17:37 +02:00
|
|
|
$event[$key] = in_array($key, ['##videoconference', '##notify_externals']) ?
|
|
|
|
$value : '';
|
2015-06-25 22:39:53 +02:00
|
|
|
}
|
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
if ($merge)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
|
|
|
"()[MERGE]\n",3,$this->logfile);
|
|
|
|
}
|
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':
|
2018-12-11 12:45:17 +01:00
|
|
|
continue 2; // +1 for switch
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2010-01-29 22:42:54 +01: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
|
2010-02-24 16:05:00 +01:00
|
|
|
$event['participants'][$uid] = $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
|
|
|
|
2010-01-29 22:42:54 +01:00
|
|
|
default:
|
|
|
|
if (!empty($value)) $event[$key] = $value;
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
// no merge
|
2019-05-28 18:47:55 +02:00
|
|
|
if(!isset($this->supportedFields['category']))
|
2010-02-24 16:05:00 +01:00
|
|
|
{
|
|
|
|
$event['category'] = $event_info['stored_event']['category'];
|
|
|
|
}
|
|
|
|
if (!isset($this->supportedFields['participants'])
|
|
|
|
|| !$event['participants']
|
|
|
|
|| !is_array($event['participants'])
|
|
|
|
|| !count($event['participants']))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
|
|
|
"() No participants\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
|
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
|
2010-02-23 19:19:12 +01:00
|
|
|
unset($event['participants']);
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
2011-10-17 17:36:28 +02:00
|
|
|
// since we export now all participants in CalDAV as urn:uuid, if they have no email,
|
|
|
|
// we dont need and dont want that special treatment anymore, as it keeps client from changing resources
|
|
|
|
elseif ($this->productManufacturer != 'groupdav')
|
2010-01-29 22:42:54 +01:00
|
|
|
{
|
2010-02-24 16:05:00 +01:00
|
|
|
foreach ($event_info['stored_event']['participants'] as $uid => $status)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2010-02-24 16:05:00 +01:00
|
|
|
// Is it a resource and no longer present in the event?
|
|
|
|
if ($uid[0] == 'r' && !isset($event['participants'][$uid]))
|
2010-01-29 22:42:54 +01:00
|
|
|
{
|
2010-02-24 16:05:00 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
|
|
|
"() Restore resource $uid to status $status\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
// Add it back in
|
|
|
|
$event['participants'][$uid] = $status;
|
2010-01-29 22:42:54 +01:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2010-01-29 22:42:54 +01:00
|
|
|
|
2011-11-10 19:47:53 +01:00
|
|
|
/* Modifying an existing event with timezone different from default timezone of user
|
|
|
|
* to a whole-day event (no timezone allowed according to iCal rfc)
|
|
|
|
* --> code to modify start- and end-time here creates a one day longer event!
|
|
|
|
* Skipping that code, creates the event correct in default timezone of user
|
|
|
|
if (!empty($event['whole_day']) && $event['tzid'] != $event_info['stored_event']['tzid'])
|
2010-01-29 22:42:54 +01:00
|
|
|
{
|
|
|
|
// Adjust dates to original TZ
|
2016-05-01 19:47:59 +02:00
|
|
|
$time = new Api\DateTime($event['start'],Api\DateTime::$server_timezone);
|
2010-01-29 22:42:54 +01:00
|
|
|
$time =& $this->so->startOfDay($time, $event_info['stored_event']['tzid']);
|
2016-05-01 19:47:59 +02:00
|
|
|
$event['start'] = Api\DateTime::to($time,'server');
|
|
|
|
//$time = new Api\DateTime($event['end'],Api\DateTime::$server_timezone);
|
2011-11-10 19:47:53 +01:00
|
|
|
//$time =& $this->so->startOfDay($time, $event_info['stored_event']['tzid']);
|
|
|
|
//$time->setTime(23, 59, 59);
|
|
|
|
$time->modify('+'.round(($event['end']-$event['start'])/DAY_s).' day');
|
2016-05-01 19:47:59 +02:00
|
|
|
$event['end'] = Api\DateTime::to($time,'server');
|
2010-01-29 22:42:54 +01:00
|
|
|
if ($event['recur_type'] != MCAL_RECUR_NONE)
|
|
|
|
{
|
|
|
|
foreach ($event['recur_exception'] as $key => $day)
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$time = new Api\DateTime($day,Api\DateTime::$server_timezone);
|
2010-01-29 22:42:54 +01:00
|
|
|
$time =& $this->so->startOfDay($time, $event_info['stored_event']['tzid']);
|
2016-05-01 19:47:59 +02:00
|
|
|
$event['recur_exception'][$key] = Api\DateTime::to($time,'server');
|
2010-01-29 22:42:54 +01:00
|
|
|
}
|
|
|
|
}
|
2010-04-23 15:52:45 +02:00
|
|
|
elseif ($event['recurrence'])
|
2010-01-29 22:42:54 +01:00
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$time = new Api\DateTime($event['recurrence'],Api\DateTime::$server_timezone);
|
2010-01-29 22:42:54 +01:00
|
|
|
$time =& $this->so->startOfDay($time, $event_info['stored_event']['tzid']);
|
2016-05-01 19:47:59 +02:00
|
|
|
$event['recurrence'] = Api\DateTime::to($time,'server');
|
2010-01-29 22:42:54 +01:00
|
|
|
}
|
2011-11-10 19:47:53 +01:00
|
|
|
error_log(__METHOD__."() TZ adjusted {$event_info['stored_event']['tzid']} --> {$event['tzid']} event=".array2string($event));
|
|
|
|
}*/
|
2010-01-29 22:42:54 +01:00
|
|
|
|
|
|
|
calendar_rrule::rrule2tz($event, $event_info['stored_event']['start'],
|
|
|
|
$event_info['stored_event']['tzid']);
|
|
|
|
|
2010-01-23 10:53:38 +01:00
|
|
|
$event['tzid'] = $event_info['stored_event']['tzid'];
|
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
|
|
|
}
|
2011-04-06 21:26:10 +02:00
|
|
|
$event['caldav_name'] = $event_info['stored_event']['caldav_name'];
|
2011-10-20 22:10:04 +02:00
|
|
|
|
|
|
|
// as we no longer export event owner/ORGANIZER as only participant, we have to re-add owner as participant
|
|
|
|
// to not loose him, as EGroupware knows events without owner/ORGANIZER as participant
|
2011-11-08 22:09:06 +01:00
|
|
|
if (isset($event_info['stored_event']['participants'][$event['owner']]) && !isset($event['participants'][$event['owner']]))
|
2011-10-20 22:10:04 +02:00
|
|
|
{
|
2016-07-11 21:08:41 +02:00
|
|
|
$event['participants'][$event['owner']] = $event_info['stored_event']['participants'][$event['owner']];
|
2011-10-20 22:10:04 +02:00
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
2010-01-29 22:42:54 +01:00
|
|
|
else // common adjustments for new events
|
|
|
|
{
|
|
|
|
unset($event['id']);
|
2011-04-06 21:26:10 +02:00
|
|
|
if ($caldav_name) $event['caldav_name'] = $caldav_name;
|
2010-01-29 22:42:54 +01:00
|
|
|
// set non blocking all day depending on the user setting
|
2010-04-23 15:52:45 +02:00
|
|
|
if (!empty($event['whole_day']) && $this->nonBlockingAllday)
|
2010-01-29 22:42:54 +01:00
|
|
|
{
|
|
|
|
$event['non_blocking'] = 1;
|
|
|
|
}
|
|
|
|
|
2010-03-07 00:06:43 +01:00
|
|
|
if (!is_null($user))
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
if ($user > 0 && $this->check_perms(Acl::ADD, 0, $user))
|
2010-03-07 00:06:43 +01:00
|
|
|
{
|
|
|
|
$event['owner'] = $user;
|
|
|
|
}
|
2012-10-22 14:45:04 +02:00
|
|
|
elseif ($user > 0)
|
2010-03-07 00:06:43 +01:00
|
|
|
{
|
2010-05-21 08:18:52 +02:00
|
|
|
date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
|
2010-05-18 16:41:22 +02:00
|
|
|
return 0; // no permission
|
2010-03-07 00:06:43 +01:00
|
|
|
}
|
2010-09-29 18:54:16 +02:00
|
|
|
else
|
|
|
|
{
|
2012-10-22 14:45:04 +02:00
|
|
|
// add group or resource invitation
|
2010-09-29 18:54:16 +02:00
|
|
|
$event['owner'] = $this->user;
|
|
|
|
if (!isset($event['participants'][$this->user]))
|
|
|
|
{
|
|
|
|
$event['participants'][$this->user] = calendar_so::combine_status('A', 1, 'CHAIR');
|
|
|
|
}
|
2012-10-22 14:45:04 +02:00
|
|
|
// for resources check which new-status to give (eg. with direct booking permision 'A' instead 'U')
|
|
|
|
$event['participants'][$user] = calendar_so::combine_status(
|
|
|
|
$user < 0 || !isset($this->resources[$user[0]]['new_status']) ? 'U' :
|
|
|
|
ExecMethod($this->resources[$user[0]]['new_status'], substr($user, 1)));
|
2010-09-29 18:54:16 +02:00
|
|
|
}
|
2010-03-07 00:06:43 +01:00
|
|
|
}
|
2010-01-29 22:42:54 +01:00
|
|
|
// check if an owner is set and the current user has add rights
|
|
|
|
// for that owners calendar; if not set the current user
|
2010-03-07 00:06:43 +01:00
|
|
|
elseif (!isset($event['owner'])
|
2016-05-01 19:47:59 +02:00
|
|
|
|| !$this->check_perms(Acl::ADD, 0, $event['owner']))
|
2010-01-29 22:42:54 +01:00
|
|
|
{
|
|
|
|
$event['owner'] = $this->user;
|
|
|
|
}
|
|
|
|
|
2010-02-24 16:05:00 +01:00
|
|
|
if (!$event['participants']
|
|
|
|
|| !is_array($event['participants'])
|
2011-10-03 11:43:06 +02:00
|
|
|
|| !count($event['participants'])
|
|
|
|
// for new events, allways add owner as participant. Users expect to participate too, if they invite further participants.
|
|
|
|
// They can now only remove themselfs, if that is desired, after storing the event first.
|
|
|
|
|| !isset($event['participants'][$event['owner']]))
|
2010-01-29 22:42:54 +01:00
|
|
|
{
|
2015-06-22 17:36:23 +02:00
|
|
|
$status = calendar_so::combine_status($event['owner'] == $this->user ? 'A' : 'U', 1, 'CHAIR');
|
2011-10-03 11:43:06 +02:00
|
|
|
if (!is_array($event['participants'])) $event['participants'] = array();
|
|
|
|
$event['participants'][$event['owner']] = $status;
|
2010-01-29 22:42:54 +01:00
|
|
|
}
|
2021-03-01 14:39:44 +01:00
|
|
|
foreach ($event['participants'] as $uid => $status)
|
2010-01-29 22:42:54 +01:00
|
|
|
{
|
2021-03-01 14:39:44 +01:00
|
|
|
// if the client did not give us a proper status => set default
|
|
|
|
if ($status[0] == 'X')
|
2010-01-29 22:42:54 +01:00
|
|
|
{
|
2021-03-01 14:39:44 +01:00
|
|
|
if ($uid == $event['owner'])
|
2010-01-29 22:42:54 +01:00
|
|
|
{
|
2021-03-01 14:39:44 +01:00
|
|
|
$event['participants'][$uid] = calendar_so::combine_status('A', 1, 'CHAIR');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$event['participants'][$uid] = calendar_so::combine_status('U');
|
2010-01-29 22:42:54 +01: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
|
2020-08-21 13:59:15 +02:00
|
|
|
if (count($event['alarm']) > 0 || isset($this->supportedFields['alarm']) && isset($event['alarm']))
|
2009-11-03 17:31:07 +01:00
|
|
|
{
|
|
|
|
switch ($event_info['type'])
|
|
|
|
{
|
|
|
|
case 'SINGLE':
|
|
|
|
case 'SERIES-MASTER':
|
|
|
|
case 'SERIES-EXCEPTION':
|
|
|
|
case 'SERIES-EXCEPTION-PROPAGATE':
|
2020-08-21 13:59:15 +02:00
|
|
|
$this->sync_alarms($event, (array)$event_info['stored_event']['alarm'], $this->user);
|
|
|
|
if ($event_info['type'] === 'SERIES-MASTER') $master = $event;
|
2009-11-03 17:31:07 +01:00
|
|
|
break;
|
|
|
|
|
2010-01-29 22:42:54 +01:00
|
|
|
case 'SERIES-PSEUDO-EXCEPTION':
|
2020-08-21 13:59:15 +02:00
|
|
|
// only sync alarms for pseudo exceptions, if we have a master
|
|
|
|
if (!isset($master) && isset($event_info['master_event'])) $master = $event_info['master_event'];
|
|
|
|
if ($master) $this->sync_alarms($event, (array)$event_info['stored_event']['alarm'], $this->user, $master);
|
2009-11-03 17:31:07 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-03-05 11:21:32 +01:00
|
|
|
|
2010-05-19 11:20:15 +02:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ . '('
|
|
|
|
. $event_info['type'] . ")\n"
|
|
|
|
. array2string($event)."\n",3,$this->logfile);
|
|
|
|
}
|
2009-11-03 17:31:07 +01:00
|
|
|
|
2012-10-07 19:13:03 +02:00
|
|
|
// Android (any maybe others) delete recurrences by setting STATUS: CANCELLED
|
|
|
|
// as we ignore STATUS we have to delete the recurrence by calling delete
|
|
|
|
if (in_array($event_info['type'], array('SERIES-EXCEPTION', 'SERIES-EXCEPTION-PROPAGATE', 'SERIES-PSEUDO-EXCEPTION')) &&
|
|
|
|
$event['status'] == 'CANCELLED')
|
|
|
|
{
|
2012-12-18 00:56:56 +01:00
|
|
|
if (!$this->delete($event['id'] ? $event['id'] : $cal_id, $event['recurrence'],false,$skip_notification))
|
2012-10-07 19:13:03 +02:00
|
|
|
{
|
|
|
|
// delete fails (because no rights), reject recurrence
|
2012-12-18 00:56:56 +01:00
|
|
|
$this->set_status($event['id'] ? $event['id'] : $cal_id, $this->user, 'R', $event['recurrence'],false,true,$skip_notification);
|
2012-10-07 19:13:03 +02:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
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':
|
2010-01-11 19:15:44 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
|
|
|
"(): event SINGLE\n",3,$this->logfile);
|
|
|
|
}
|
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
|
|
|
{
|
2010-01-11 19:15:44 +01:00
|
|
|
// Force SINGLE
|
|
|
|
$event['reference'] = 0;
|
2009-09-22 15:43:55 +02:00
|
|
|
$event_to_store = $event; // prevent $event from being changed by the update method
|
2010-01-29 22:42:54 +01:00
|
|
|
$this->server2usertime($event_to_store);
|
2012-12-18 00:56:56 +01:00
|
|
|
$updated_id = $this->update($event_to_store, true,true,false,true,$msg,$skip_notification);
|
2009-09-22 15:43:55 +02:00
|
|
|
unset($event_to_store);
|
|
|
|
}
|
|
|
|
break;
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
case 'SERIES-MASTER':
|
2010-01-11 19:15:44 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
|
|
|
"(): event SERIES-MASTER\n",3,$this->logfile);
|
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2010-01-29 22:42:54 +01:00
|
|
|
// remove all known pseudo 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
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
$filter = isset($this->supportedFields['participants']) ? 'map' : 'tz_map';
|
|
|
|
$days = $this->so->get_recurrence_exceptions($event_info['stored_event'], $this->tzid, 0, 0, $filter);
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."(EXCEPTIONS MAPPING):\n" .
|
|
|
|
array2string($days)."\n",3,$this->logfile);
|
|
|
|
}
|
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();
|
2011-03-05 11:21:32 +01:00
|
|
|
|
2009-10-25 19:22:01 +01:00
|
|
|
foreach ($event['recur_exception'] as $recur_exception)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
if (isset($days[$recur_exception]))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
$recur_exceptions[] = $days[$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
|
2010-01-29 22:42:54 +01:00
|
|
|
$this->server2usertime($event_to_store);
|
2012-12-18 00:56:56 +01:00
|
|
|
$updated_id = $this->update($event_to_store, true,true,false,true,$msg,$skip_notification);
|
2009-09-22 15:43:55 +02:00
|
|
|
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':
|
2010-01-11 19:15:44 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
|
|
|
"(): event SERIES-EXCEPTION\n",3,$this->logfile);
|
|
|
|
}
|
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']);
|
2010-01-29 22:42:54 +01:00
|
|
|
unset($event_info['stored_event']);
|
|
|
|
$event['recur_type'] = MCAL_RECUR_NONE;
|
2010-06-23 16:52:55 +02:00
|
|
|
if (empty($event['recurrence']))
|
|
|
|
{
|
|
|
|
// find an existing exception slot
|
|
|
|
$occurence = $exception = false;
|
|
|
|
foreach ($event_info['master_event']['recur_exception'] as $exception)
|
|
|
|
{
|
|
|
|
if ($exception > $event['start']) break;
|
|
|
|
$occurence = $exception;
|
|
|
|
}
|
|
|
|
if (!$occurence)
|
|
|
|
{
|
|
|
|
if (!$exception)
|
|
|
|
{
|
|
|
|
// use start as dummy recurrence
|
|
|
|
$event['recurrence'] = $event['start'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$event['recurrence'] = $exception;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$event['recurrence'] = $occurence;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$event_info['master_event']['recur_exception'] =
|
|
|
|
array_unique(array_merge($event_info['master_event']['recur_exception'],
|
|
|
|
array($event['recurrence'])));
|
|
|
|
}
|
2011-03-05 11:21:32 +01:00
|
|
|
|
2009-09-22 15:43:55 +02:00
|
|
|
$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'];
|
2010-02-17 14:29:28 +01:00
|
|
|
$event_to_store = $event_info['master_event']; // prevent the master_event from being changed by the update method
|
|
|
|
$this->server2usertime($event_to_store);
|
2012-12-18 00:56:56 +01:00
|
|
|
$this->update($event_to_store, true,true,false,true,$msg,$skip_notification);
|
2010-02-17 14:29:28 +01:00
|
|
|
unset($event_to_store);
|
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
|
2010-01-29 22:42:54 +01:00
|
|
|
$this->server2usertime($event_to_store);
|
2012-12-18 00:56:56 +01:00
|
|
|
$updated_id = $this->update($event_to_store, true,true,false,true,$msg,$skip_notification);
|
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
|
|
|
|
2010-01-29 22:42:54 +01:00
|
|
|
case 'SERIES-PSEUDO-EXCEPTION':
|
2010-01-11 19:15:44 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
2010-01-29 22:42:54 +01:00
|
|
|
"(): event SERIES-PSEUDO-EXCEPTION\n",3,$this->logfile);
|
2010-01-11 19:15:44 +01:00
|
|
|
}
|
2010-01-29 22:42:54 +01:00
|
|
|
//Horde::logMessage('importVCAL event SERIES-PSEUDO-EXCEPTION',
|
2010-01-11 19:15:44 +01:00
|
|
|
// __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
|
2010-01-29 22:42:54 +01:00
|
|
|
$this->server2usertime($event_to_store);
|
2012-12-18 00:56:56 +01:00
|
|
|
$updated_id = $this->update($event_to_store, true, true, false, false,$msg,$skip_notification);
|
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
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
$event_info['stored_event'] = $this->read($updated_id, 0, false, 'server');
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2010-02-24 16:05:00 +01:00
|
|
|
if (isset($event['participants']))
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
2010-02-24 16:05:00 +01:00
|
|
|
// update status depending on the given event type
|
|
|
|
switch ($event_info['type'])
|
|
|
|
{
|
|
|
|
case 'SINGLE':
|
|
|
|
case 'SERIES-MASTER':
|
|
|
|
case 'SERIES-EXCEPTION':
|
|
|
|
case 'SERIES-EXCEPTION-PROPAGATE':
|
|
|
|
if (is_array($event_info['stored_event'])) // status update requires a stored event
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2010-02-24 16:05:00 +01:00
|
|
|
if ($event_info['acl_edit'])
|
|
|
|
{
|
|
|
|
// update all participants if we have the right to do that
|
2012-12-18 17:00:29 +01:00
|
|
|
$this->update_status($event, $event_info['stored_event'],0,$skip_notification);
|
2010-02-24 16:05:00 +01:00
|
|
|
}
|
|
|
|
elseif (isset($event['participants'][$this->user]) || isset($event_info['stored_event']['participants'][$this->user]))
|
|
|
|
{
|
|
|
|
// update the users status only
|
|
|
|
$this->set_status($event_info['stored_event']['id'], $this->user,
|
2012-12-18 00:56:56 +01:00
|
|
|
($event['participants'][$this->user] ? $event['participants'][$this->user] : 'R'), 0, true,true,$skip_notification);
|
2010-02-24 16:05:00 +01:00
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2010-02-24 16:05:00 +01:00
|
|
|
break;
|
2009-10-05 23:00:08 +02:00
|
|
|
|
2010-02-24 16:05:00 +01:00
|
|
|
case 'SERIES-PSEUDO-EXCEPTION':
|
|
|
|
if (is_array($event_info['master_event'])) // status update requires a stored master event
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2010-02-24 16:05:00 +01:00
|
|
|
$recurrence = $this->date2usertime($event['recurrence']);
|
|
|
|
if ($event_info['acl_edit'])
|
|
|
|
{
|
|
|
|
// update all participants if we have the right to do that
|
2012-12-18 17:00:29 +01:00
|
|
|
$this->update_status($event, $event_info['stored_event'], $recurrence,$skip_notification);
|
2010-02-24 16:05:00 +01:00
|
|
|
}
|
|
|
|
elseif (isset($event['participants'][$this->user]) || isset($event_info['master_event']['participants'][$this->user]))
|
|
|
|
{
|
|
|
|
// update the users status only
|
|
|
|
$this->set_status($event_info['master_event']['id'], $this->user,
|
2012-12-18 00:56:56 +01:00
|
|
|
($event['participants'][$this->user] ? $event['participants'][$this->user] : 'R'), $recurrence, true,true,$skip_notification);
|
2010-02-24 16:05:00 +01:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2010-02-24 16:05:00 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
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
|
|
|
|
2010-01-29 22:42:54 +01:00
|
|
|
case 'SERIES-PSEUDO-EXCEPTION':
|
2009-09-22 15:43:55 +02:00
|
|
|
$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
|
2010-01-29 22:42:54 +01:00
|
|
|
// we have to keep the SERIES-PSEUDO-EXCEPTION id and keep the event untouched
|
2009-10-01 15:30:18 +02:00
|
|
|
$return_id = $event_info['master_event']['id'] . ':' . $event['recurrence'];
|
|
|
|
}
|
|
|
|
break;
|
2009-09-22 15:43:55 +02:00
|
|
|
}
|
|
|
|
|
2013-09-23 15:39:28 +02:00
|
|
|
// handle ATTACH attribute for managed attachments
|
2016-04-05 00:39:49 +02:00
|
|
|
if ($updated_id && Api\CalDAV::handle_attach('calendar', $updated_id, $event['attach'], $event['attach-delete-by-put']) === false)
|
2013-09-23 15:39:28 +02:00
|
|
|
{
|
2015-09-30 05:27:29 +02:00
|
|
|
$return_id = null;
|
2013-09-23 15:39:28 +02:00
|
|
|
}
|
|
|
|
|
2009-10-25 19:22:01 +01:00
|
|
|
if ($this->log)
|
2009-09-22 15:43:55 +02:00
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
$event_info['stored_event'] = $this->read($event_info['stored_event']['id']);
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()[$updated_id]\n" .
|
2010-01-09 19:04:21 +01:00
|
|
|
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
|
|
|
}
|
2010-05-21 08:18:52 +02:00
|
|
|
date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
|
2011-11-08 22:09:06 +01:00
|
|
|
|
|
|
|
return $updated_id === 0 ? 0 : $return_id;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
|
2016-07-11 21:08:41 +02:00
|
|
|
/**
|
|
|
|
* Override parent update function to handle conflict checking callback, if set
|
2016-11-05 12:00:19 +01:00
|
|
|
*
|
2016-07-11 21:08:41 +02:00
|
|
|
* @param array &$event event-array, on return some values might be changed due to set defaults
|
|
|
|
* @param boolean $ignore_conflicts =false just ignore conflicts or do a conflict check and return the conflicting events.
|
|
|
|
* Set to false if $this->conflict_callback is set
|
|
|
|
* @param boolean $touch_modified =true NOT USED ANYMORE (was only used in old csv-import), modified&modifier is always updated!
|
|
|
|
* @param boolean $ignore_acl =false should we ignore the acl
|
|
|
|
* @param boolean $updateTS =true update the content history of the event
|
|
|
|
* @param array &$messages=null messages about because of missing ACL removed participants or categories
|
|
|
|
* @param boolean $skip_notification =false true: send NO notifications, default false = send them
|
|
|
|
* @return mixed on success: int $cal_id > 0, on error or conflicts false.
|
|
|
|
* Conflicts are passed to $this->conflict_callback
|
|
|
|
*/
|
|
|
|
public function update(&$event,$ignore_conflicts=false,$touch_modified=true,$ignore_acl=false,$updateTS=true,&$messages=null, $skip_notification=false)
|
|
|
|
{
|
|
|
|
if($this->conflict_callback !== null)
|
|
|
|
{
|
|
|
|
// calendar_ical overrides search(), which breaks conflict checking
|
|
|
|
// so we make sure to use the original from parent
|
2016-11-05 12:00:19 +01:00
|
|
|
static $bo = null;
|
2016-07-11 21:08:41 +02:00
|
|
|
if(!$bo)
|
|
|
|
{
|
|
|
|
$bo = new calendar_boupdate();
|
|
|
|
}
|
|
|
|
$conflicts = $bo->conflicts($event);
|
|
|
|
if(is_array($conflicts) && count($conflicts) > 0)
|
|
|
|
{
|
|
|
|
call_user_func_array($this->conflict_callback, array(&$event, &$conflicts));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return parent::update($event, $ignore_conflicts, $touch_modified, $ignore_acl, $updateTS, $messages, $skip_notification);
|
|
|
|
}
|
2016-11-05 12:00:19 +01:00
|
|
|
|
2015-06-25 22:39:53 +02:00
|
|
|
/**
|
|
|
|
* Sync alarms of current user: add alarms added on client and remove the ones removed
|
|
|
|
*
|
2020-08-21 13:59:15 +02:00
|
|
|
* Currently alarms of pseudo exceptions will always be added to series master (and searched for there too)!
|
|
|
|
* Alarms are search by uid first, but if no uid match found, we also consider same offset as a match.
|
|
|
|
*
|
2015-06-25 22:39:53 +02:00
|
|
|
* @param array& $event
|
|
|
|
* @param array $old_alarms
|
|
|
|
* @param int $user account_id of user to create alarm for
|
2020-08-21 13:59:15 +02:00
|
|
|
* @param array $master =null master for pseudo exceptions
|
2015-06-25 22:39:53 +02:00
|
|
|
* @return int number of modified alarms
|
|
|
|
*/
|
2020-08-21 13:59:15 +02:00
|
|
|
public function sync_alarms(array &$event, array $old_alarms, $user, array &$master=null)
|
2015-06-25 22:39:53 +02:00
|
|
|
{
|
2020-08-21 13:59:15 +02:00
|
|
|
if ($this->debug) error_log(__METHOD__."(".array2string($event).', old_alarms='.array2string($old_alarms).", $user, master=".")");
|
2015-06-25 22:39:53 +02:00
|
|
|
$modified = 0;
|
|
|
|
foreach($event['alarm'] as &$alarm)
|
|
|
|
{
|
|
|
|
// check if alarm is already stored or from other users
|
2017-03-31 15:08:04 +02:00
|
|
|
$found = false;
|
2015-06-25 22:39:53 +02:00
|
|
|
foreach($old_alarms as $id => $old_alarm)
|
|
|
|
{
|
|
|
|
// not current users alarm --> ignore
|
|
|
|
if (!$old_alarm['all'] && $old_alarm['owner'] != $user)
|
|
|
|
{
|
|
|
|
unset($old_alarm[$id]);
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-21 13:59:15 +02:00
|
|
|
// alarm with matching uid found --> stop
|
|
|
|
if (!empty($alarm['uid']) && $alarm['uid'] == $old_alarm['uid'])
|
2015-06-25 22:39:53 +02:00
|
|
|
{
|
2017-03-31 15:08:04 +02:00
|
|
|
$found = true;
|
2015-06-25 22:39:53 +02:00
|
|
|
unset($old_alarms[$id]);
|
|
|
|
break;
|
|
|
|
}
|
2020-08-21 13:59:15 +02:00
|
|
|
// alarm only matching offset, remember first matching one, in case no uid match
|
|
|
|
if ($alarm['offset'] == $old_alarm['offset'] && $found === false)
|
|
|
|
{
|
|
|
|
$found = $id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// no uid, but offset match found --> use it like an uid match
|
|
|
|
if (!is_bool($found))
|
|
|
|
{
|
|
|
|
$found = true;
|
|
|
|
$old_alarm = $old_alarms[$id];
|
|
|
|
unset($old_alarms[$id]);
|
2015-06-25 22:39:53 +02:00
|
|
|
}
|
2017-03-31 15:08:04 +02:00
|
|
|
if ($this->debug) error_log(__METHOD__."($event[title] (#$event[id]), ..., $user) processing ".($found?'existing':'new')." alarm ".array2string($alarm));
|
|
|
|
if (!empty($alarm['attrs']['X-LIC-ERROR']))
|
|
|
|
{
|
|
|
|
if ($this->debug) error_log(__METHOD__."($event[title] (#$event[id]), ..., $user) ignored X-LIC-ERROR=".array2string($alarm['X-LIC-ERROR']));
|
|
|
|
unset($alarm['attrs']['X-LIC-ERROR']);
|
|
|
|
}
|
2020-08-21 13:59:15 +02:00
|
|
|
// search not found alarm in master
|
|
|
|
if ($master && !$found)
|
|
|
|
{
|
|
|
|
foreach($master['alarm'] ?? [] as $m_alarm)
|
|
|
|
{
|
|
|
|
if ($alarm['offset'] == $m_alarm['offset'] &&
|
|
|
|
($m_alarm['all'] || $m_alarm['owner'] == $user))
|
|
|
|
{
|
|
|
|
if ($this->debug) error_log(__METHOD__."() alarm of pseudo exception already in master --> ignored alarm=".json_encode($alarm).", master=".json_encode($m_alarm));
|
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// alarm not found --> add it (to master as $event['id'] is the one from the master)
|
2017-03-31 15:08:04 +02:00
|
|
|
if (!$found)
|
2015-06-25 22:39:53 +02:00
|
|
|
{
|
|
|
|
$alarm['owner'] = $user;
|
|
|
|
if (!isset($alarm['time'])) $alarm['time'] = $event['start'] - $alarm['offset'];
|
|
|
|
if ($alarm['time'] < time()) calendar_so::shift_alarm($event, $alarm);
|
|
|
|
if ($this->debug) error_log(__METHOD__."() adding new alarm from client ".array2string($alarm));
|
2020-08-21 13:59:15 +02:00
|
|
|
if ($event['id'] || $master) $alarm['id'] = $this->save_alarm($event['id'] ?? $master['id'], $alarm);
|
|
|
|
// adding alarm to master to be found for further pseudo exceptions (it will be added to DB below)
|
|
|
|
if ($master) $master['alarm'][] = $alarm;
|
2015-06-25 22:39:53 +02:00
|
|
|
++$modified;
|
|
|
|
}
|
|
|
|
// existing alarm --> update it
|
2017-03-31 15:08:04 +02:00
|
|
|
else
|
2015-06-25 22:39:53 +02:00
|
|
|
{
|
|
|
|
if (!isset($alarm['time'])) $alarm['time'] = $event['start'] - $alarm['offset'];
|
|
|
|
if ($alarm['time'] < time()) calendar_so::shift_alarm($event, $alarm);
|
|
|
|
$alarm = array_merge($old_alarm, $alarm);
|
|
|
|
if ($this->debug) error_log(__METHOD__."() updating existing alarm from client ".array2string($alarm));
|
|
|
|
$alarm['id'] = $this->save_alarm($event['id'], $alarm);
|
|
|
|
++$modified;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// remove all old alarms left from current user
|
|
|
|
foreach($old_alarms as $id => $old_alarm)
|
|
|
|
{
|
|
|
|
// not current users alarm --> ignore
|
|
|
|
if (!$old_alarm['all'] && $old_alarm['owner'] != $user)
|
|
|
|
{
|
|
|
|
unset($old_alarm[$id]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($this->debug) error_log(__METHOD__."() deleting alarm '$id' deleted on client ".array2string($old_alarm));
|
|
|
|
$this->delete_alarm($id);
|
|
|
|
++$modified;
|
|
|
|
}
|
|
|
|
return $modified;
|
|
|
|
}
|
|
|
|
|
2008-06-07 19:45:33 +02:00
|
|
|
/**
|
|
|
|
* get the value of an attribute by its name
|
|
|
|
*
|
2015-06-22 17:36:23 +02:00
|
|
|
* @param array $components
|
2008-06-07 19:45:33 +02:00
|
|
|
* @param string $name eg. 'DTSTART'
|
2015-06-22 17:36:23 +02:00
|
|
|
* @param string $what ='value'
|
2008-06-07 19:45:33 +02:00
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
|
2015-06-25 22:39:53 +02:00
|
|
|
/**
|
|
|
|
* Parsing a valarm component preserving all attributes unknown to EGw
|
|
|
|
*
|
|
|
|
* @param array &$alarms on return alarms parsed
|
|
|
|
* @param Horde_Icalendar_Valarm $valarm valarm component
|
|
|
|
* @param int $duration in seconds to be able to convert RELATED=END
|
|
|
|
* @return int number of parsed alarms
|
|
|
|
*/
|
|
|
|
static function valarm2egw(&$alarms, Horde_Icalendar_Valarm $valarm, $duration)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2015-06-25 22:39:53 +02:00
|
|
|
$alarm = array();
|
2015-06-24 12:46:19 +02:00
|
|
|
foreach ($valarm->getAllAttributes() 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':
|
2015-06-25 22:39:53 +02:00
|
|
|
if (isset($vattr['params']['RELATED']) && $vattr['params']['RELATED'] == 'END')
|
|
|
|
{
|
|
|
|
$alarm['offset'] = $duration -$vattr['value'];
|
|
|
|
}
|
|
|
|
elseif (isset($vattr['params']['RELATED']) && $vattr['params']['RELATED'] != 'START')
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
|
|
|
error_log("Unsupported VALARM offset anchor ".$vattr['params']['RELATED']);
|
2015-06-25 22:39:53 +02:00
|
|
|
return;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-25 22:39:53 +02:00
|
|
|
$alarm['offset'] = -$vattr['value'];
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'DATE-TIME':
|
2015-06-25 22:39:53 +02:00
|
|
|
$alarm['time'] = $vattr['value'];
|
2008-06-07 19:45:33 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error_log('VALARM/TRIGGER: unsupported value type:' . $vtype);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-06-25 22:39:53 +02:00
|
|
|
case 'UID':
|
|
|
|
case 'X-WR-ALARMUID':
|
|
|
|
$alarm['uid'] = $vattr['value'];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: // store all other attributes, so we dont loose them
|
|
|
|
$alarm['attrs'][$vattr['name']] = array(
|
|
|
|
'params' => $vattr['params'],
|
|
|
|
'value' => $vattr['value'],
|
|
|
|
);
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
}
|
2015-06-25 22:39:53 +02:00
|
|
|
if (isset($alarm['offset']) || isset($alarm['time']))
|
|
|
|
{
|
|
|
|
//error_log(__METHOD__."(..., ".$valarm->exportvCalendar().", $duration) alarm=".array2string($alarm));
|
|
|
|
$alarms[] = $alarm;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
|
2009-07-15 22:35:56 +02:00
|
|
|
function setSupportedFields($_productManufacturer='', $_productName='')
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2010-01-13 21:48:39 +01: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();
|
|
|
|
}
|
|
|
|
|
2010-01-13 21:48:39 +01:00
|
|
|
// store product manufacturer and name for further usage
|
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))
|
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
/*
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
|
|
|
'() ' . array2string($deviceInfo) . "\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
*/
|
2009-10-25 19:22:01 +01:00
|
|
|
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'])
|
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
switch ($deviceInfo['tzid'])
|
|
|
|
{
|
2010-03-22 19:03:23 +01:00
|
|
|
case -1:
|
2010-02-26 13:37:07 +01:00
|
|
|
$this->tzid = false; // use event's TZ
|
2010-02-09 22:56:39 +01:00
|
|
|
break;
|
2010-03-22 19:03:23 +01:00
|
|
|
case -2:
|
2010-02-26 13:37:07 +01:00
|
|
|
$this->tzid = null; // use UTC for export
|
2010-02-09 22:56:39 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$this->tzid = $deviceInfo['tzid'];
|
|
|
|
}
|
2009-11-11 22:31:33 +01:00
|
|
|
}
|
2010-02-26 13:37:07 +01:00
|
|
|
elseif (strpos($this->productName, 'palmos') !== false)
|
|
|
|
{
|
|
|
|
// for palmos we have to use user-time and NO timezone
|
|
|
|
$this->tzid = false;
|
|
|
|
}
|
|
|
|
|
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'];
|
2010-03-24 12:37:22 +01:00
|
|
|
switch ($owner)
|
2010-02-09 22:56:39 +01:00
|
|
|
{
|
2010-03-24 12:37:22 +01:00
|
|
|
case 'G':
|
|
|
|
case 'P':
|
2010-04-14 18:40:54 +02:00
|
|
|
case 0:
|
2010-04-16 09:04:53 +02:00
|
|
|
case -1:
|
2010-03-24 12:37:22 +01:00
|
|
|
$owner = $this->user;
|
2010-04-14 18:40:54 +02:00
|
|
|
break;
|
|
|
|
default:
|
2016-05-01 19:47:59 +02:00
|
|
|
if ((int)$owner && $this->check_perms(Acl::EDIT, 0, $owner))
|
2010-04-14 18:40:54 +02:00
|
|
|
{
|
|
|
|
$this->calendarOwner = $owner;
|
|
|
|
}
|
2009-11-29 15:03:45 +01:00
|
|
|
}
|
|
|
|
}
|
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']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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',
|
2010-03-15 18:18:17 +01:00
|
|
|
'recur_exception' => 'recur_exception',
|
2008-06-07 19:45:33 +02:00
|
|
|
'title' => 'title',
|
2009-07-15 22:35:56 +02:00
|
|
|
'alarm' => 'alarm',
|
2013-11-23 09:13:01 +01:00
|
|
|
'whole_day' => 'whole_day',
|
2008-06-07 19:45:33 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$defaultFields['basic'] = $defaultFields['minimal'] + array(
|
|
|
|
'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',
|
2010-11-04 11:46:56 +01:00
|
|
|
'recurrence' => 'recurrence',
|
2009-07-15 22:35:56 +02:00
|
|
|
'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
|
|
|
);
|
|
|
|
|
2010-01-08 14:09:36 +01:00
|
|
|
$defaultFields['funambol'] = $defaultFields['basic'] + array(
|
2010-01-09 19:04:21 +01:00
|
|
|
'participants' => 'participants',
|
|
|
|
'owner' => 'owner',
|
2010-01-08 14:09:36 +01:00
|
|
|
'category' => 'category',
|
|
|
|
'non_blocking' => 'non_blocking',
|
|
|
|
);
|
|
|
|
|
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',
|
2010-03-08 14:54:13 +01:00
|
|
|
'status' => 'status',
|
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':
|
2010-06-07 12:26:00 +02:00
|
|
|
case 'e72-1':
|
|
|
|
case 'e75-1':
|
2009-07-15 22:35:56 +02:00
|
|
|
case 'e66':
|
|
|
|
case '6120c':
|
|
|
|
case 'nokia 6131':
|
2010-04-26 09:29:51 +02:00
|
|
|
case 'n97':
|
2010-03-15 18:18:17 +01:00
|
|
|
case 'n97 mini':
|
2010-04-26 09:29:51 +02:00
|
|
|
case '5800 xpressmusic':
|
2009-07-15 22:35:56 +02:00
|
|
|
$this->supportedFields = $defaultFields['s60'];
|
2008-11-03 08:44:02 +01:00
|
|
|
break;
|
2008-06-07 19:45:33 +02:00
|
|
|
default:
|
2010-06-07 14:50:17 +02:00
|
|
|
if ($this->productName[0] == 'e')
|
|
|
|
{
|
|
|
|
$model = 'E90';
|
|
|
|
$this->supportedFields = $defaultFields['s60'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$model = 'E61';
|
|
|
|
$this->supportedFields = $defaultFields['minimal'];
|
|
|
|
}
|
|
|
|
error_log("Unknown Nokia phone '$_productName', assuming same as '$model'");
|
2008-06-07 19:45:33 +02:00
|
|
|
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':
|
2010-02-24 16:05:00 +01:00
|
|
|
case 'w890i':
|
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
|
2011-04-11 12:59:59 +02:00
|
|
|
if ($this->cal_prefs['export_timezone'])
|
2010-03-17 17:57:03 +01:00
|
|
|
{
|
2011-04-11 12:59:59 +02:00
|
|
|
$this->tzid = $this->cal_prefs['export_timezone'];
|
2010-03-17 17:57:03 +01:00
|
|
|
}
|
2011-04-11 12:59:59 +02:00
|
|
|
else // not set or '0' = use event TZ
|
2010-03-17 17:57:03 +01:00
|
|
|
{
|
|
|
|
$this->tzid = false; // use event's TZ
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
$this->supportedFields = $defaultFields['full'];
|
|
|
|
break;
|
|
|
|
|
2011-05-26 12:48:57 +02:00
|
|
|
case 'full':
|
2008-11-03 10:36:20 +01:00
|
|
|
case 'groupdav': // all GroupDAV access goes through here
|
2010-02-26 13:37:07 +01:00
|
|
|
$this->tzid = false; // use event's TZ
|
2009-10-25 19:22:01 +01:00
|
|
|
switch ($this->productName)
|
2008-11-03 10:36:20 +01:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
$this->supportedFields = $defaultFields['full'];
|
2013-11-23 09:13:01 +01:00
|
|
|
unset($this->supportedFields['whole_day']);
|
2008-11-03 10:36:20 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-12-01 11:24:55 +01:00
|
|
|
case 'funambol':
|
2010-01-08 14:09:36 +01:00
|
|
|
$this->supportedFields = $defaultFields['funambol'];
|
2009-12-01 11:24:55 +01:00
|
|
|
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
|
|
|
}
|
2010-02-26 13:37:07 +01:00
|
|
|
|
|
|
|
if ($this->log)
|
2009-11-11 22:31:33 +01:00
|
|
|
{
|
2010-02-26 13:37:07 +01:00
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
|
|
|
'(' . $this->productManufacturer .
|
|
|
|
', '. $this->productName .', ' .
|
2016-05-01 19:47:59 +02:00
|
|
|
($this->tzid ? $this->tzid : Api\DateTime::$user_timezone->getName()) .
|
2010-03-24 12:37:22 +01:00
|
|
|
', ' . $this->calendarOwner . ")\n" , 3, $this->logfile);
|
2009-11-11 22:31:33 +01:00
|
|
|
}
|
2010-02-26 13:37:07 +01:00
|
|
|
|
|
|
|
//Horde::logMessage('setSupportedFields(' . $this->productManufacturer . ', '
|
|
|
|
// . $this->productName .', ' .
|
2016-05-01 19:47:59 +02:00
|
|
|
// ($this->tzid ? $this->tzid : Api\DateTime::$user_timezone->getName()) .')',
|
2010-02-26 13:37:07 +01:00
|
|
|
// __FILE__, __LINE__, PEAR_LOG_DEBUG);
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
|
2010-03-07 00:06:43 +01:00
|
|
|
/**
|
|
|
|
* Convert vCalendar data in EGw events
|
|
|
|
*
|
2010-04-14 12:19:41 +02:00
|
|
|
* @param string|resource $_vcalData
|
2015-06-22 17:36:23 +02:00
|
|
|
* @param string $principalURL ='' Used for CalDAV imports
|
2010-03-22 19:03:23 +01:00
|
|
|
* @param string $charset The encoding charset for $text. Defaults to
|
2020-02-26 13:51:41 +01:00
|
|
|
* utf-8 for new format, iso-8859-1 for old format.
|
2010-04-14 12:19:41 +02:00
|
|
|
* @return Iterator|array|boolean Iterator if resource given or array of events on success, false on failure
|
2010-03-07 00:06:43 +01:00
|
|
|
*/
|
2010-03-22 19:03:23 +01:00
|
|
|
function icaltoegw($_vcalData, $principalURL='', $charset=null)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
2010-03-22 19:03:23 +01:00
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."($principalURL, $charset)\n" .
|
2010-01-29 22:42:54 +01:00
|
|
|
array2string($_vcalData)."\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
|
2010-05-21 08:18:52 +02:00
|
|
|
if (!is_array($this->supportedFields)) $this->setSupportedFields();
|
|
|
|
|
2016-04-05 01:45:39 +02:00
|
|
|
// we use Api\CalDAV\IcalIterator only on resources, as calling importVCal() accesses single events like an array (eg. $events[0])
|
2010-05-21 08:18:52 +02:00
|
|
|
if (is_resource($_vcalData))
|
|
|
|
{
|
2016-05-04 19:15:18 +02:00
|
|
|
return new Api\CalDAV\IcalIterator($_vcalData, 'VCALENDAR', $charset,
|
|
|
|
// true = add container as last parameter to callback parameters
|
|
|
|
array($this, '_ical2egw_callback'), array($this->tzid, $principalURL), true);
|
2010-05-21 08:18:52 +02:00
|
|
|
}
|
2011-03-05 11:21:32 +01:00
|
|
|
|
2009-11-11 22:31:33 +01:00
|
|
|
if ($this->tzid)
|
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
$tzid = $this->tzid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-01 19:47:59 +02:00
|
|
|
$tzid = Api\DateTime::$user_timezone->getName();
|
2009-11-11 22:31:33 +01:00
|
|
|
}
|
2011-03-05 11:21:32 +01:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
date_default_timezone_set($tzid);
|
2011-03-05 11:21:32 +01:00
|
|
|
|
2010-04-14 12:19:41 +02:00
|
|
|
$events = array();
|
2015-06-22 17:36:23 +02:00
|
|
|
$vcal = new Horde_Icalendar;
|
2016-04-29 09:51:13 +02:00
|
|
|
if ($charset && $charset != 'utf-8')
|
|
|
|
{
|
|
|
|
$_vcalData = Api\Translation::convert($_vcalData, $charset, 'utf-8');
|
|
|
|
}
|
|
|
|
if (!$vcal->parsevCalendar($_vcalData, 'VCALENDAR'))
|
2009-11-11 22:31:33 +01:00
|
|
|
{
|
2010-01-09 19:04:21 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.
|
|
|
|
"(): No vCalendar Container found!\n",3,$this->logfile);
|
|
|
|
}
|
2010-05-21 08:18:52 +02:00
|
|
|
date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
|
2009-11-11 22:31:33 +01:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-22 17:36:23 +02:00
|
|
|
foreach ($vcal->getComponents() as $component)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2015-07-29 15:31:03 +02:00
|
|
|
if (($event = $this->_ical2egw_callback($component,$this->tzid,$principalURL,$vcal)))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2011-04-28 19:56:44 +02:00
|
|
|
$events[] = $event;
|
2010-03-07 00:06:43 +01:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2010-02-09 22:56:39 +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
|
|
|
return $events;
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2015-10-22 19:24:14 +02:00
|
|
|
/**
|
|
|
|
* Get email of organizer of first vevent in given iCalendar
|
|
|
|
*
|
|
|
|
* @param string $_ical
|
|
|
|
* @return string|boolean
|
|
|
|
*/
|
|
|
|
public static function getIcalOrganizer($_ical)
|
|
|
|
{
|
|
|
|
$vcal = new Horde_Icalendar;
|
|
|
|
if (!$vcal->parsevCalendar($_ical, 'VCALENDAR'))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (($vevent = $vcal->findComponentByAttribute('Vevent', 'ORGANIZER')))
|
|
|
|
{
|
|
|
|
$organizer = $vevent->getAttribute('ORGANIZER');
|
|
|
|
if (stripos($organizer, 'mailto:') === 0)
|
|
|
|
{
|
|
|
|
return substr($organizer, 7);
|
|
|
|
}
|
|
|
|
$params = $vevent->getAttribute('ORGANIZER', true);
|
|
|
|
return $params['email'];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-04-14 12:19:41 +02:00
|
|
|
/**
|
2016-04-05 01:45:39 +02:00
|
|
|
* Callback for Api\CalDAV\IcalIterator to convert Horde_iCalendar_Vevent to EGw event array
|
2010-04-14 12:19:41 +02:00
|
|
|
*
|
|
|
|
* @param Horde_iCalendar $component
|
|
|
|
* @param string $tzid timezone
|
2015-06-22 17:36:23 +02:00
|
|
|
* @param string $principalURL ='' Used for CalDAV imports
|
2015-06-24 10:51:20 +02:00
|
|
|
* @param Horde_Icalendar $container =null container to access attributes on container
|
2015-06-22 17:36:23 +02:00
|
|
|
* @return array|boolean event array or false if $component is no Horde_Icalendar_Vevent
|
2010-04-14 12:19:41 +02:00
|
|
|
*/
|
2015-06-24 10:51:20 +02:00
|
|
|
function _ical2egw_callback(Horde_Icalendar $component, $tzid, $principalURL='', Horde_Icalendar $container=null)
|
2010-04-14 12:19:41 +02:00
|
|
|
{
|
|
|
|
//unset($component->_container); _debug_array($component);
|
2011-03-05 11:21:32 +01:00
|
|
|
|
2010-05-21 08:18:52 +02:00
|
|
|
if ($this->log)
|
|
|
|
{
|
2020-06-09 18:26:59 +02:00
|
|
|
error_log(__FILE__ . '[' . __LINE__ . '] ' . __METHOD__ . '() ' . get_class($component) . " found\n", 3, $this->logfile);
|
2010-05-21 08:18:52 +02:00
|
|
|
}
|
2010-04-14 12:19:41 +02:00
|
|
|
|
2016-05-04 19:15:18 +02:00
|
|
|
// eg. Mozilla holiday calendars contain only a X-WR-TIMEZONE on vCalendar component
|
|
|
|
if (!$tzid && $container && ($tz = $container->getAttributeDefault('X-WR-TIMEZONE')))
|
|
|
|
{
|
|
|
|
$tzid = $tz;
|
|
|
|
}
|
|
|
|
|
2015-06-22 17:36:23 +02:00
|
|
|
if (!is_a($component, 'Horde_Icalendar_Vevent') ||
|
2020-06-09 18:26:59 +02:00
|
|
|
!($event = $this->vevent2egw($component, $container ? $container->getAttributeDefault('VERSION', '2.0') : '2.0',
|
|
|
|
$this->supportedFields, $principalURL, null, $container)))
|
2010-04-14 12:19:41 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//common adjustments
|
|
|
|
if ($this->productManufacturer == '' && $this->productName == '' && !empty($event['recur_enddate']))
|
|
|
|
{
|
|
|
|
// syncevolution needs an adjusted recur_enddate
|
|
|
|
$event['recur_enddate'] = (int)$event['recur_enddate'] + 86400;
|
|
|
|
}
|
|
|
|
if ($event['recur_type'] != MCAL_RECUR_NONE)
|
|
|
|
{
|
|
|
|
// No reference or RECURRENCE-ID for the series master
|
|
|
|
$event['reference'] = $event['recurrence'] = 0;
|
|
|
|
}
|
2017-06-12 12:33:33 +02:00
|
|
|
if (Api\DateTime::to($event['start'], 'H:i:s') == '00:00:00' && Api\DateTime::to($event['end'], 'H:i:s') == '00:00:00')
|
2017-06-09 23:28:06 +02:00
|
|
|
{
|
|
|
|
// 'All day' event that ends at midnight the next day, avoid that
|
|
|
|
$event['end']--;
|
|
|
|
}
|
2010-04-14 12:19:41 +02:00
|
|
|
|
2020-06-09 18:26:59 +02:00
|
|
|
// Remove videoconference link appended to description in calendar_groupdav->iCal()
|
|
|
|
if (class_exists('EGroupware\Status\Videoconference\Call'))
|
|
|
|
{
|
|
|
|
$regex = "/^(\r?\n)?(Videoconference|" . lang('Videoconference') . "):\r?\n" . str_replace('/','\/',EGroupware\Status\Videoconference\Call::getMeetingRegex()) ."(\r?\n)*/im";
|
|
|
|
$event['description'] = preg_replace($regex, '', $event['description']);
|
|
|
|
}
|
|
|
|
|
2010-04-14 12:19:41 +02:00
|
|
|
// handle the alarms
|
|
|
|
$alarms = $event['alarm'];
|
|
|
|
foreach ($component->getComponents() as $valarm)
|
|
|
|
{
|
2015-06-22 17:36:23 +02:00
|
|
|
if (is_a($valarm, 'Horde_Icalendar_Valarm'))
|
2010-04-14 12:19:41 +02:00
|
|
|
{
|
2015-06-25 22:39:53 +02:00
|
|
|
self::valarm2egw($alarms, $valarm, $event['end'] - $event['start']);
|
2010-04-14 12:19:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$event['alarm'] = $alarms;
|
2010-05-21 08:18:52 +02:00
|
|
|
if ($tzid || empty($event['tzid']))
|
2010-04-14 12:19:41 +02:00
|
|
|
{
|
|
|
|
$event['tzid'] = $tzid;
|
|
|
|
}
|
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
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
|
2016-04-05 00:39:49 +02:00
|
|
|
* @param string $principalURL ='' Used for CalDAV imports, no longer used in favor of Api\CalDAV\Principals::url2uid()
|
2015-06-22 17:36:23 +02:00
|
|
|
* @param string $check_component ='Horde_Icalendar_Vevent'
|
2015-06-24 10:51:20 +02:00
|
|
|
* @param Horde_Icalendar $container =null container to access attributes on container
|
2009-07-15 22:35:56 +02:00
|
|
|
* @return array|boolean event on success, false on failure
|
|
|
|
*/
|
2015-06-24 10:51:20 +02:00
|
|
|
function vevent2egw($component, $version, $supportedFields, $principalURL='', $check_component='Horde_Icalendar_Vevent', Horde_Icalendar $container=null)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2015-06-22 17:36:23 +02:00
|
|
|
unset($principalURL); // not longer used, but required in function signature
|
|
|
|
|
2011-09-22 17:22:52 +02:00
|
|
|
if ($check_component && !is_a($component, $check_component))
|
2010-03-07 00:06:43 +01:00
|
|
|
{
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__.'()' .
|
|
|
|
get_class($component)." found\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-03-05 11:21:32 +01:00
|
|
|
|
2010-04-14 12:19:41 +02:00
|
|
|
if (!empty($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']))
|
|
|
|
{
|
2009-07-15 22:35:56 +02:00
|
|
|
$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();
|
2018-08-06 18:15:36 +02:00
|
|
|
$organizer_status = $organizer_uid = null;
|
2009-07-15 22:35:56 +02:00
|
|
|
$vcardData = array(
|
|
|
|
'recur_type' => MCAL_RECUR_NONE,
|
|
|
|
'recur_exception' => array(),
|
2015-09-29 12:25:32 +02:00
|
|
|
'priority' => 0, // iCalendar default is 0=undefined, not EGroupware 5=normal
|
2019-06-14 21:12:05 +02:00
|
|
|
'public' => 1,
|
2009-07-15 22:35:56 +02:00
|
|
|
);
|
2012-10-23 16:22:33 +02:00
|
|
|
// we need to parse DTSTART, DTEND or DURATION (in that order!) first
|
|
|
|
foreach (array_merge(
|
|
|
|
$component->getAllAttributes('DTSTART'),
|
|
|
|
$component->getAllAttributes('DTEND'),
|
|
|
|
$component->getAllAttributes('DURATION')) as $attributes)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2017-12-18 13:47:27 +01:00
|
|
|
//error_log(__METHOD__."() attribute=".array2string($attributes));
|
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
|
|
|
|
2016-11-05 12:00:19 +01:00
|
|
|
// set event timezone from dtstart, if specified there
|
|
|
|
if (!empty($attributes['params']['TZID']))
|
2009-11-10 16:08:35 +01:00
|
|
|
{
|
2016-11-05 12:00:19 +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)
|
|
|
|
try
|
2009-11-10 16:08:35 +01:00
|
|
|
{
|
2016-11-05 12:00:19 +01:00
|
|
|
$tz = calendar_timezones::DateTimeZone($attributes['params']['TZID']);
|
|
|
|
// sometimes we do not get an Api\DateTime object but no exception is thrown
|
|
|
|
// may be php 5.2.x related. occurs when a NokiaE72 tries to open Outlook invitations
|
|
|
|
if ($tz instanceof DateTimeZone)
|
2010-02-09 22:56:39 +01:00
|
|
|
{
|
2016-11-05 12:00:19 +01:00
|
|
|
$event['tzid'] = $tz->getName();
|
2010-02-09 22:56:39 +01:00
|
|
|
}
|
2016-11-05 12:00:19 +01:00
|
|
|
else
|
2010-02-09 22:56:39 +01:00
|
|
|
{
|
|
|
|
error_log(__METHOD__ . '() unknown TZID='
|
|
|
|
. $attributes['params']['TZID'] . ', defaulting to timezone "'
|
2016-11-05 12:00:19 +01:00
|
|
|
. date_default_timezone_get() . '".'.array2string($tz));
|
2010-02-09 22:56:39 +01:00
|
|
|
$event['tzid'] = date_default_timezone_get(); // default to current timezone
|
|
|
|
}
|
2009-11-10 16:08:35 +01:00
|
|
|
}
|
2016-11-05 12:00:19 +01:00
|
|
|
catch(Exception $e)
|
2015-09-29 12:25:32 +02:00
|
|
|
{
|
2016-11-05 12:00:19 +01:00
|
|
|
error_log(__METHOD__ . '() unknown TZID='
|
|
|
|
. $attributes['params']['TZID'] . ', defaulting to timezone "'
|
|
|
|
. date_default_timezone_get() . '".'.$e->getMessage());
|
|
|
|
$event['tzid'] = date_default_timezone_get(); // default to current timezone
|
2015-09-29 12:25:32 +02:00
|
|
|
}
|
2009-11-10 16:08:35 +01:00
|
|
|
}
|
2016-11-05 12:00:19 +01:00
|
|
|
// if no timezone given and one is specified in class (never the case for CalDAV)
|
|
|
|
elseif ($this->tzid)
|
|
|
|
{
|
|
|
|
$event['tzid'] = $this->tzid;
|
|
|
|
}
|
|
|
|
// Horde seems not to distinguish between an explicit UTC time postfixed with Z and one without
|
|
|
|
// assuming for now UTC to pass CalDAVTester tests
|
|
|
|
// ToDo: fix Horde_Icalendar to return UTC for timestamp postfixed with Z
|
|
|
|
elseif (!$isDate)
|
|
|
|
{
|
|
|
|
$event['tzid'] = 'UTC';
|
|
|
|
}
|
|
|
|
// default to use timezone to better kope with floating time
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$event['tzid'] = Api\DateTime::$user_timezone->getName();
|
|
|
|
}
|
2009-10-25 19:22:01 +01:00
|
|
|
break;
|
2010-02-09 22:56:39 +01:00
|
|
|
|
2009-10-25 19:22:01 +01:00
|
|
|
case 'DTEND':
|
|
|
|
$dtend_ts = is_numeric($attributes['value']) ? $attributes['value'] : $this->date2ts($attributes['value']);
|
|
|
|
if (date('H:i:s',$dtend_ts) == '00:00:00')
|
|
|
|
{
|
2010-01-04 14:56:20 +01:00
|
|
|
$dtend_ts -= 1;
|
2009-10-25 19:22:01 +01:00
|
|
|
}
|
|
|
|
$vcardData['end'] = $dtend_ts;
|
2012-10-23 16:22:33 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'DURATION': // clients can use DTSTART+DURATION, instead of DTSTART+DTEND
|
|
|
|
if (!isset($vcardData['end']))
|
|
|
|
{
|
|
|
|
$vcardData['end'] = $vcardData['start'] + $attributes['value'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error_log(__METHOD__."() find DTEND AND DURATION --> ignoring DURATION");
|
|
|
|
}
|
|
|
|
break;
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
}
|
2010-03-07 00:06:43 +01:00
|
|
|
if (!isset($vcardData['start']))
|
|
|
|
{
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
|
|
|
|
. "() DTSTART missing!\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
return false; // not a valid entry
|
|
|
|
}
|
2016-11-05 12:00:19 +01:00
|
|
|
// if neither duration nor dtend specified, default for dtstart as date is 1 day
|
|
|
|
if (!isset($vcardData['end']) && !$isDate)
|
|
|
|
{
|
|
|
|
$end = new Api\DateTime($vcardData['start']);
|
|
|
|
$end->add('1 day');
|
|
|
|
$vcardData['end'] = $end->format('ts');
|
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
// lets see what we can get from the vcard
|
2015-06-24 12:46:19 +02:00
|
|
|
foreach ($component->getAllAttributes() as $attributes)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
|
|
|
switch ($attributes['name'])
|
|
|
|
{
|
2012-02-03 23:28:00 +01:00
|
|
|
case 'X-MICROSOFT-CDO-ALLDAYEVENT':
|
2013-11-23 09:13:01 +01:00
|
|
|
if (isset($supportedFields['whole_day']))
|
|
|
|
{
|
|
|
|
$event['whole_day'] = (isset($attributes['value'])?strtoupper($attributes['value'])=='TRUE':true);
|
|
|
|
}
|
2012-02-03 23:28:00 +01:00
|
|
|
break;
|
2009-07-15 22:35:56 +02:00
|
|
|
case 'AALARM':
|
|
|
|
case 'DALARM':
|
|
|
|
$alarmTime = $attributes['value'];
|
|
|
|
$alarms[$alarmTime] = array(
|
|
|
|
'time' => $alarmTime
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'CLASS':
|
2010-01-29 22:42:54 +01:00
|
|
|
$vcardData['public'] = (int)(strtolower($attributes['value']) == 'public');
|
2009-07-15 22:35:56 +02:00
|
|
|
break;
|
|
|
|
case 'DESCRIPTION':
|
2010-01-29 22:42:54 +01:00
|
|
|
$vcardData['description'] = str_replace("\r\n", "\n", $attributes['value']);
|
2015-06-22 17:36:23 +02:00
|
|
|
$matches = null;
|
2009-10-25 19:22:01 +01:00
|
|
|
if (preg_match('/\s*\[UID:(.+)?\]/Usm', $attributes['value'], $matches))
|
|
|
|
{
|
2015-06-22 17:36:23 +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':
|
2021-11-08 18:01:18 +01:00
|
|
|
if (is_array($attributes['value'])) // whole-day event recurrence-id is returned as array
|
|
|
|
{
|
|
|
|
$attributes['value'] = mktime(0, 0, 0,
|
|
|
|
$attributes['value']['month'], $attributes['value']['mday'], $attributes['value']['year']);
|
|
|
|
}
|
2009-07-28 10:58:39 +02:00
|
|
|
$vcardData['recurrence'] = $attributes['value'];
|
2009-07-15 22:35:56 +02:00
|
|
|
break;
|
|
|
|
case 'LOCATION':
|
2010-01-29 22:42:54 +01:00
|
|
|
$vcardData['location'] = str_replace("\r\n", "\n", $attributes['value']);
|
2009-07-15 22:35:56 +02:00
|
|
|
break;
|
|
|
|
case 'RRULE':
|
2018-09-24 15:49:44 +02:00
|
|
|
unset($vcardData['recur_type']); // it wont be set by +=
|
2021-03-02 14:26:55 +01:00
|
|
|
$vcardData += calendar_rrule::parseRrule($attributes['value'], false, $vcardData);
|
2018-09-18 16:24:09 +02:00
|
|
|
if (!empty($vcardData['recur_enddate'])) self::check_fix_endate ($vcardData);
|
2009-07-15 22:35:56 +02:00
|
|
|
break;
|
2017-09-21 15:19:07 +02:00
|
|
|
case 'EXDATE': // current Horde_Icalendar returns dates, no timestamps
|
|
|
|
if ($attributes['values'])
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
|
|
|
$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
|
|
|
break;
|
|
|
|
case 'SUMMARY':
|
2010-02-22 11:02:33 +01:00
|
|
|
$vcardData['title'] = str_replace("\r\n", "\n", $attributes['value']);
|
2009-07-15 22:35:56 +02:00
|
|
|
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':
|
2010-01-09 23:28:41 +01:00
|
|
|
if ($this->productManufacturer == 'funambol' &&
|
|
|
|
(strpos($this->productName, 'outlook') !== false
|
|
|
|
|| strpos($this->productName, 'pocket pc') !== false))
|
2009-12-29 14:51:07 +01:00
|
|
|
{
|
|
|
|
$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'])
|
|
|
|
{
|
2010-02-17 14:29:28 +01:00
|
|
|
$vcardData['category'] = explode(',', $attributes['value']);
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$vcardData['category'] = array();
|
|
|
|
}
|
|
|
|
break;
|
2010-03-07 00:06:43 +01:00
|
|
|
case 'ORGANIZER':
|
2011-04-28 19:56:44 +02:00
|
|
|
$event['organizer'] = $attributes['value']; // no egw field, but needed in AS
|
2015-01-27 14:07:59 +01:00
|
|
|
if (strtolower(substr($event['organizer'],0,7)) == 'mailto:')
|
2011-04-28 19:56:44 +02:00
|
|
|
{
|
|
|
|
$event['organizer'] = substr($event['organizer'],7);
|
|
|
|
}
|
|
|
|
if (!empty($attributes['params']['CN']))
|
|
|
|
{
|
|
|
|
$event['organizer'] = $attributes['params']['CN'].' <'.$event['organizer'].'>';
|
|
|
|
}
|
|
|
|
// fall throught
|
|
|
|
case 'ATTENDEE':
|
2019-02-21 17:49:54 +01:00
|
|
|
// work around Ligthning sending @ as %40
|
|
|
|
$attributes['value'] = str_replace('%40', '@', $attributes['value']);
|
2009-08-23 21:26:14 +02:00
|
|
|
if (isset($attributes['params']['PARTSTAT']))
|
2020-02-26 13:51:41 +01:00
|
|
|
{
|
|
|
|
$attributes['params']['STATUS'] = $attributes['params']['PARTSTAT'];
|
|
|
|
}
|
|
|
|
if (isset($attributes['params']['STATUS']))
|
2009-08-23 21:26:14 +02:00
|
|
|
{
|
|
|
|
$status = $this->status_ical2egw[strtoupper($attributes['params']['STATUS'])];
|
2010-02-17 14:29:28 +01:00
|
|
|
if (empty($status)) $status = 'X';
|
2009-08-23 21:26:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-29 22:42:54 +01:00
|
|
|
$status = 'X'; // client did not return the status
|
2009-08-23 21:26:14 +02:00
|
|
|
}
|
2010-03-07 00:06:43 +01:00
|
|
|
$uid = $email = $cn = '';
|
|
|
|
$quantity = 1;
|
|
|
|
$role = 'REQ-PARTICIPANT';
|
|
|
|
if (!empty($attributes['params']['ROLE']))
|
|
|
|
{
|
|
|
|
$role = $attributes['params']['ROLE'];
|
|
|
|
}
|
2014-03-13 11:20:17 +01:00
|
|
|
// CN explicit given --> use it
|
2015-01-23 10:45:11 +01:00
|
|
|
if (strtolower(substr($attributes['value'], 0, 7)) == 'mailto:' &&
|
2014-03-13 11:20:17 +01:00
|
|
|
!empty($attributes['params']['CN']))
|
|
|
|
{
|
|
|
|
$email = substr($attributes['value'], 7);
|
|
|
|
$cn = $attributes['params']['CN'];
|
|
|
|
}
|
|
|
|
// try parsing email and cn from attendee
|
2015-01-23 10:45:11 +01:00
|
|
|
elseif (preg_match('/mailto:([@.a-z0-9_-]+)|mailto:"?([.a-z0-9_ -]*)"?[ ]*<([@.a-z0-9_-]*)>/i',
|
2011-05-26 18:46:23 +02:00
|
|
|
$attributes['value'],$matches))
|
|
|
|
{
|
|
|
|
$email = $matches[1] ? $matches[1] : $matches[3];
|
|
|
|
$cn = isset($matches[2]) ? $matches[2]: '';
|
|
|
|
}
|
|
|
|
elseif (!empty($attributes['value']) &&
|
|
|
|
preg_match('/"?([.a-z0-9_ -]*)"?[ ]*<([@.a-z0-9_-]*)>/i',
|
|
|
|
$attributes['value'],$matches))
|
|
|
|
{
|
|
|
|
$cn = $matches[1];
|
|
|
|
$email = $matches[2];
|
|
|
|
}
|
|
|
|
elseif (strpos($attributes['value'],'@') !== false)
|
|
|
|
{
|
|
|
|
$email = $attributes['value'];
|
|
|
|
}
|
2020-08-14 18:03:30 +02:00
|
|
|
// check if we need to replace email domain with something else in participants (mail address migration)
|
|
|
|
if (!empty($email) && !empty($GLOBALS['egw_info']['server']['calendar_domain_replace']) &&
|
|
|
|
!empty($GLOBALS['egw_info']['server']['calendar_domain_replace_with']))
|
|
|
|
{
|
|
|
|
$email = preg_replace('/@'.preg_quote($GLOBALS['egw_info']['server']['calendar_domain_replace'], '/').'(>|$)/i',
|
|
|
|
'@'.$GLOBALS['egw_info']['server']['calendar_domain_replace_with'].'$1', $e=$email);
|
|
|
|
}
|
2011-05-26 18:46:23 +02:00
|
|
|
// try X-EGROUPWARE-UID, but only if it resolves to same email (otherwise we are in trouble if different EGw installs talk to each other)
|
|
|
|
if (!$uid && !empty($attributes['params']['X-EGROUPWARE-UID']) &&
|
|
|
|
($res_info = $this->resource_info($attributes['params']['X-EGROUPWARE-UID'])) &&
|
|
|
|
!strcasecmp($res_info['email'], $email))
|
2010-03-07 00:06:43 +01:00
|
|
|
{
|
|
|
|
$uid = $attributes['params']['X-EGROUPWARE-UID'];
|
|
|
|
if (!empty($attributes['params']['X-EGROUPWARE-QUANTITY']))
|
|
|
|
{
|
|
|
|
$quantity = $attributes['params']['X-EGROUPWARE-QUANTITY'];
|
|
|
|
}
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
|
|
|
|
. "(): Found X-EGROUPWARE-UID: '$uid'\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif ($attributes['value'] == 'Unknown')
|
|
|
|
{
|
|
|
|
// we use the current user
|
|
|
|
$uid = $this->user;
|
|
|
|
}
|
2011-10-07 08:02:30 +02:00
|
|
|
// check principal url from CalDAV here after X-EGROUPWARE-UID and to get optional X-EGROUPWARE-QUANTITY
|
2016-04-05 00:39:49 +02:00
|
|
|
if (!$uid) $uid = Api\CalDAV\Principals::url2uid($attributes['value'], null, $cn);
|
2011-10-07 08:02:30 +02:00
|
|
|
|
2010-03-07 00:06:43 +01:00
|
|
|
// try to find an email address
|
|
|
|
if (!$uid && $email && ($uid = $GLOBALS['egw']->accounts->name2id($email, 'account_email')))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2010-03-07 00:06:43 +01:00
|
|
|
// we use the account we found
|
|
|
|
if ($this->log)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2010-03-07 00:06:43 +01:00
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
|
|
|
|
. "() Found account: '$uid', '$cn', '$email'\n",3,$this->logfile);
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
}
|
2010-03-07 00:06:43 +01:00
|
|
|
if (!$uid)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2010-03-07 00:06:43 +01:00
|
|
|
$searcharray = array();
|
|
|
|
// search for provided email address ...
|
|
|
|
if ($email)
|
|
|
|
{
|
|
|
|
$searcharray = array('email' => $email, 'email_home' => $email);
|
|
|
|
}
|
|
|
|
// ... and for provided CN
|
|
|
|
if (!empty($attributes['params']['CN']))
|
|
|
|
{
|
2010-05-18 12:04:29 +02:00
|
|
|
$cn = str_replace(array('\\,', '\\;', '\\:', '\\\\'),
|
|
|
|
array(',', ';', ':', '\\'),
|
|
|
|
$attributes['params']['CN']);
|
2010-04-12 09:20:11 +02:00
|
|
|
if ($cn[0] == '"' && substr($cn,-1) == '"')
|
2010-03-07 00:06:43 +01:00
|
|
|
{
|
2010-04-12 09:20:11 +02:00
|
|
|
$cn = substr($cn,1,-1);
|
2010-03-07 00:06:43 +01:00
|
|
|
}
|
2012-07-24 22:13:56 +02:00
|
|
|
// not searching for $cn, as match can be not unique or without an email address
|
|
|
|
// --> notification will fail, better store just as email
|
2010-03-07 00:06:43 +01:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2010-04-12 09:20:11 +02:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
|
|
|
|
. "() Search participant: '$cn', '$email'\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
|
2010-03-07 00:06:43 +01:00
|
|
|
//elseif (//$attributes['params']['CUTYPE'] == 'GROUP'
|
2010-04-12 08:31:30 +02:00
|
|
|
if (preg_match('/(.*) '. lang('Group') . '/', $cn, $matches))
|
2009-08-23 21:26:14 +02:00
|
|
|
{
|
2010-04-12 09:20:11 +02:00
|
|
|
// we found a group
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
|
|
|
|
. "() Found group: '$matches[1]', '$cn', '$email'\n",3,$this->logfile);
|
|
|
|
}
|
2010-03-07 00:06:43 +01:00
|
|
|
if (($uid = $GLOBALS['egw']->accounts->name2id($matches[1], 'account_lid', 'g')))
|
2009-11-26 19:36:19 +01:00
|
|
|
{
|
2010-03-07 00:06:43 +01:00
|
|
|
//Horde::logMessage("vevent2egw: group participant $uid",
|
|
|
|
// __FILE__, __LINE__, PEAR_LOG_DEBUG);
|
|
|
|
if (!isset($vcardData['participants'][$this->user]) &&
|
|
|
|
$status != 'X' && $status != 'U')
|
2009-11-26 19:36:19 +01:00
|
|
|
{
|
2010-03-07 00:06:43 +01:00
|
|
|
// User tries to reply to the group invitiation
|
2012-08-09 11:08:45 +02:00
|
|
|
if (($members = $GLOBALS['egw']->accounts->members($uid, true)) &&
|
|
|
|
in_array($this->user, $members))
|
2010-03-07 00:06:43 +01:00
|
|
|
{
|
|
|
|
//Horde::logMessage("vevent2egw: set status to " . $status,
|
|
|
|
// __FILE__, __LINE__, PEAR_LOG_DEBUG);
|
|
|
|
$vcardData['participants'][$this->user] =
|
|
|
|
calendar_so::combine_status($status,$quantity,$role);
|
|
|
|
}
|
2009-11-26 19:36:19 +01:00
|
|
|
}
|
2009-11-29 22:03:17 +01:00
|
|
|
$status = 'U'; // keep the group
|
2009-08-23 21:26:14 +02:00
|
|
|
}
|
2018-12-11 12:45:17 +01:00
|
|
|
else continue 2; // can't find this group
|
2009-08-23 21:26:14 +02:00
|
|
|
}
|
2010-03-07 00:06:43 +01:00
|
|
|
elseif (empty($searcharray))
|
|
|
|
{
|
2018-12-11 12:45:17 +01:00
|
|
|
continue 2; // participants without email AND CN --> ignore it
|
2010-03-07 00:06:43 +01:00
|
|
|
}
|
|
|
|
elseif ((list($data) = $this->addressbook->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')))
|
|
|
|
{
|
|
|
|
// found an addressbook entry
|
|
|
|
$uid = $data['account_id'] ? (int)$data['account_id'] : 'c'.$data['id'];
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
|
|
|
|
. "() Found addressbook entry: '$uid', '$cn', '$email'\n",3,$this->logfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2010-03-07 00:06:43 +01:00
|
|
|
if (!$email)
|
|
|
|
{
|
|
|
|
$email = 'no-email@egroupware.org'; // set dummy email to store the CN
|
|
|
|
}
|
2010-05-14 10:06:08 +02:00
|
|
|
$uid = 'e'. ($cn ? $cn . ' <' . $email . '>' : $email);
|
2010-03-07 00:06:43 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
|
|
|
|
. "() Not Found, create dummy: '$uid', '$cn', '$email'\n",3,$this->logfile);
|
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2010-02-24 16:05:00 +01:00
|
|
|
if (!isset($vcardData['participants'][$uid]) ||
|
|
|
|
$vcardData['participants'][$uid][0] != 'A')
|
2010-02-09 22:56:39 +01:00
|
|
|
{
|
2013-08-26 19:48:19 +02:00
|
|
|
// keep role 'CHAIR' from an external organizer, even if he is a regular participant with a different role
|
|
|
|
// as this is currently the only way to store an external organizer and send him iMip responses
|
2015-06-22 17:36:23 +02:00
|
|
|
$q = $r = null;
|
2013-08-26 19:48:19 +02:00
|
|
|
if (isset($vcardData['participants'][$uid]) && ($s=$vcardData['participants'][$uid]) &&
|
|
|
|
calendar_so::split_status($s, $q, $r) && $r == 'CHAIR')
|
|
|
|
{
|
|
|
|
$role = 'CHAIR';
|
|
|
|
}
|
2010-02-09 22:56:39 +01:00
|
|
|
// for multiple entries the ACCEPT wins
|
|
|
|
// add quantity and role
|
2010-02-24 16:05:00 +01:00
|
|
|
$vcardData['participants'][$uid] =
|
2018-08-06 18:15:36 +02:00
|
|
|
calendar_so::combine_status(
|
|
|
|
// Thunderbird: if there is a PARTICIPANT for the ORGANIZER AND ORGANZIER has PARTSTAT
|
|
|
|
// --> use the one from ORGANIZER
|
|
|
|
$uid === $organizer_uid && !empty($organizer_status) && $organizer_status !== 'X' ?
|
|
|
|
$organizer_status : $status, $quantity, $role);
|
2010-03-07 00:06:43 +01:00
|
|
|
|
2015-06-24 14:30:56 +02:00
|
|
|
try {
|
|
|
|
if (!$this->calendarOwner && is_numeric($uid) && $role == 'CHAIR')
|
|
|
|
$component->getAttribute('ORGANIZER');
|
|
|
|
}
|
|
|
|
catch(Horde_Icalendar_Exception $e)
|
2010-03-07 00:06:43 +01:00
|
|
|
{
|
|
|
|
// we can store the ORGANIZER as event owner
|
|
|
|
$event['owner'] = $uid;
|
|
|
|
}
|
2010-02-09 22:56:39 +01:00
|
|
|
}
|
2009-11-26 19:36:19 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'ORGANIZER':
|
2018-08-06 18:15:36 +02:00
|
|
|
// remember evtl. set PARTSTAT from ORGANIZER, as TB sets it on ORGANIZER not PARTICIPANT!
|
|
|
|
$organizer_uid = $uid;
|
|
|
|
$organizer_status = $status;
|
2010-02-24 16:05:00 +01:00
|
|
|
if (isset($vcardData['participants'][$uid]))
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2010-02-24 16:05:00 +01:00
|
|
|
$status = $vcardData['participants'][$uid];
|
2009-11-26 19:36:19 +01:00
|
|
|
calendar_so::split_status($status, $quantity, $role);
|
2010-02-24 16:05:00 +01:00
|
|
|
$vcardData['participants'][$uid] =
|
2009-11-26 19:36:19 +01:00
|
|
|
calendar_so::combine_status($status, $quantity, 'CHAIR');
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2010-03-07 00:06:43 +01:00
|
|
|
if (!$this->calendarOwner && is_numeric($uid))
|
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;
|
2010-02-24 16:05:00 +01:00
|
|
|
if (!isset($vcardData['participants'][$uid]))
|
2009-11-26 19:36:19 +01:00
|
|
|
{
|
|
|
|
// save the ORGANIZER as event CHAIR
|
2010-02-24 16:05:00 +01:00
|
|
|
$vcardData['participants'][$uid] =
|
2010-03-07 00:06:43 +01:00
|
|
|
calendar_so::combine_status('D', 1, 'CHAIR');
|
2009-11-26 19:36:19 +01:00
|
|
|
}
|
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'];
|
2012-10-07 19:13:03 +02:00
|
|
|
break;
|
|
|
|
case 'STATUS': // currently no EGroupware event column, but needed as Android uses it to delete single recurrences
|
|
|
|
$event['status'] = $attributes['value'];
|
|
|
|
break;
|
2015-06-25 22:39:53 +02:00
|
|
|
|
2021-04-20 19:44:44 +02:00
|
|
|
case 'X-EGROUPWARE-NOTIFY_EXTERNALS':
|
|
|
|
$event['##notify_externals'] = $attributes['value'];
|
|
|
|
break;
|
|
|
|
case 'X-EGROUPWARE-VIDEOCONFERENCE':
|
|
|
|
$event['##videoconference'] = $attributes['value'];
|
|
|
|
break;
|
|
|
|
|
2015-06-25 22:39:53 +02:00
|
|
|
// ignore all PROPS, we dont want to store like X-properties or unsupported props
|
|
|
|
case 'DTSTAMP':
|
|
|
|
case 'SEQUENCE':
|
|
|
|
case 'CREATED':
|
|
|
|
case 'LAST-MODIFIED':
|
|
|
|
case 'DTSTART':
|
|
|
|
case 'DTEND':
|
|
|
|
case 'DURATION':
|
|
|
|
case 'X-LIC-ERROR': // parse errors from libical, makes no sense to store them
|
|
|
|
break;
|
|
|
|
|
2015-09-29 09:37:15 +02:00
|
|
|
case 'ATTACH':
|
|
|
|
if ($attributes['params'] && !empty($attributes['params']['FMTTYPE'])) break; // handeled by managed attachment code
|
|
|
|
// fall throught to store external attachment url
|
2015-06-25 22:39:53 +02:00
|
|
|
default: // X- attribute or other by EGroupware unsupported property
|
|
|
|
//error_log(__METHOD__."() $attributes[name] = ".array2string($attributes));
|
|
|
|
// for attributes with multiple values in multiple lines, merge the values
|
|
|
|
if (isset($event['##'.$attributes['name']]))
|
|
|
|
{
|
|
|
|
//error_log(__METHOD__."() taskData['##$attribute[name]'] = ".array2string($taskData['##'.$attribute['name']]));
|
|
|
|
$attributes['values'] = array_merge(
|
|
|
|
is_array($event['##'.$attributes['name']]) ? $event['##'.$attributes['name']]['values'] : (array)$event['##'.$attributes['name']],
|
|
|
|
$attributes['values']);
|
|
|
|
}
|
|
|
|
$event['##'.$attributes['name']] = $attributes['params'] || count($attributes['values']) > 1 ?
|
|
|
|
json_encode($attributes) : $attributes['value'];
|
2018-12-09 13:48:35 +01:00
|
|
|
|
|
|
|
// check if json_encoded attribute is to big for our table
|
|
|
|
if (($attributes['params'] || count($attributes['values']) > 1) &&
|
|
|
|
strlen($event['##'.$attributes['name']]) >
|
2021-10-11 13:15:34 +02:00
|
|
|
$GLOBALS['egw']->db->get_column_attribute('cal_extra_value', 'egw_cal_extra', 'calendar', 'precision'))
|
2018-12-09 13:48:35 +01:00
|
|
|
{
|
|
|
|
// store content compressed (Outlook/Exchange HTML garbadge is very good compressable)
|
2018-12-10 14:12:31 +01:00
|
|
|
if (function_exists('gzcompress'))
|
2018-12-09 13:48:35 +01:00
|
|
|
{
|
|
|
|
$event['##'.$attributes['name']] = json_encode(array(
|
|
|
|
'gzcompress' => base64_encode(gzcompress($event['##'.$attributes['name']]))
|
|
|
|
));
|
|
|
|
}
|
|
|
|
// if that's not enough --> unset it, as truncating the json gives nothing
|
|
|
|
if (strlen($event['##'.$attributes['name']]) >
|
2021-10-11 13:23:26 +02:00
|
|
|
$GLOBALS['egw']->db->get_column_attribute('cal_extra_value', 'egw_cal_extra', 'calendar', 'precision'))
|
2018-12-09 13:48:35 +01:00
|
|
|
{
|
|
|
|
unset($event['##'.$attributes['name']]);
|
|
|
|
}
|
|
|
|
}
|
2015-06-25 22:39:53 +02:00
|
|
|
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
|
2015-06-24 14:30:56 +02:00
|
|
|
try {
|
|
|
|
$agendaEntryType = $component->getAttribute('X-EPOCAGENDAENTRYTYPE');
|
2009-07-15 22:35:56 +02:00
|
|
|
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';
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2015-06-24 14:30:56 +02:00
|
|
|
catch (Horde_Icalendar_Exception $e) {}
|
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':
|
2013-02-27 15:35:12 +01:00
|
|
|
case 'recur_count':
|
2013-11-23 09:13:01 +01:00
|
|
|
case 'whole_day':
|
2009-07-15 22:35:56 +02:00
|
|
|
// not handled here
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'recur_type':
|
|
|
|
$event['recur_type'] = $vcardData['recur_type'];
|
|
|
|
if ($event['recur_type'] != MCAL_RECUR_NONE)
|
|
|
|
{
|
|
|
|
$event['reference'] = 0;
|
2013-02-27 15:35:12 +01:00
|
|
|
foreach (array('recur_interval','recur_enddate','recur_data','recur_exception','recur_count') 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
|
|
|
}
|
2013-02-28 18:00:01 +01:00
|
|
|
if ($event['recur_enddate'])
|
2010-01-05 12:24:27 +01:00
|
|
|
{
|
|
|
|
// reset recure_enddate to 00:00:00 on the last day
|
|
|
|
$rriter = calendar_rrule::event2rrule($event, false);
|
2014-06-16 15:25:00 +02:00
|
|
|
$last = $rriter->normalize_enddate();
|
2015-04-11 02:17:28 +02:00
|
|
|
if(!is_object($last))
|
|
|
|
{
|
|
|
|
if($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__ .
|
|
|
|
" Unable to determine recurrence end date. \n".array2string($event),3, $this->logfile);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-01-05 12:24:27 +01:00
|
|
|
$last->setTime(0, 0, 0);
|
2016-05-01 19:47:59 +02:00
|
|
|
//error_log(__METHOD__."() rrule=$recurence --> ".array2string($rriter)." --> enddate=".array2string($last).'='.Api\DateTime::to($last, ''));
|
|
|
|
$event['recur_enddate'] = Api\DateTime::to($last, 'server');
|
2010-01-05 12:24:27 +01:00
|
|
|
}
|
2013-02-27 15:35:12 +01:00
|
|
|
// translate COUNT into an enddate, as we only store enddates
|
|
|
|
elseif($event['recur_count'])
|
|
|
|
{
|
|
|
|
$rriter = calendar_rrule::event2rrule($event, false);
|
|
|
|
$last = $rriter->count2date($event['recur_count']);
|
2015-04-11 02:17:28 +02:00
|
|
|
if(!is_object($last))
|
|
|
|
{
|
|
|
|
if($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__,
|
|
|
|
" Unable to determine recurrence end date. \n".array2string($event),3, $this->logfile);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-27 15:35:12 +01:00
|
|
|
$last->setTime(0, 0, 0);
|
2016-05-01 19:47:59 +02:00
|
|
|
$event['recur_enddate'] = Api\DateTime::to($last, 'server');
|
2013-02-27 15:35:12 +01:00
|
|
|
unset($event['recur_count']);
|
|
|
|
}
|
2010-01-05 12:24:27 +01:00
|
|
|
|
2012-02-07 21:19:16 +01:00
|
|
|
// Apple iCal on OS X uses X-CALENDARSERVER-ACCESS: CONFIDENTIAL on VCALANDAR (not VEVENT!)
|
2015-06-24 14:30:56 +02:00
|
|
|
try {
|
2015-07-29 15:31:03 +02:00
|
|
|
if ($this->productManufacturer == 'groupdav' && $container &&
|
2015-06-24 14:30:56 +02:00
|
|
|
($x_calendarserver_access = $container->getAttribute('X-CALENDARSERVER-ACCESS')))
|
|
|
|
{
|
|
|
|
$event['public'] = (int)(strtoupper($x_calendarserver_access) == 'PUBLIC');
|
|
|
|
}
|
|
|
|
//error_log(__METHOD__."() X-CALENDARSERVER-ACCESS=".array2string($x_calendarserver_access).' --> public='.array2string($event['public']));
|
2012-02-07 21:19:16 +01:00
|
|
|
}
|
2015-06-24 14:30:56 +02:00
|
|
|
catch (Horde_Icalendar_Exception $e) {}
|
2012-02-07 21:19:16 +01:00
|
|
|
|
2012-01-29 19:20:40 +01:00
|
|
|
// if no end is given in iCal we use the default lenght from user prefs
|
|
|
|
// whole day events get one day in calendar_boupdate::save()
|
|
|
|
if (!isset($event['end']))
|
|
|
|
{
|
2012-01-29 19:41:46 +01:00
|
|
|
$event['end'] = $event['start'] + 60 * $this->cal_prefs['defaultlength'];
|
2012-01-29 19:20:40 +01:00
|
|
|
}
|
|
|
|
|
2009-11-29 15:03:45 +01:00
|
|
|
if ($this->calendarOwner) $event['owner'] = $this->calendarOwner;
|
2010-01-29 22:42:54 +01:00
|
|
|
|
2013-09-23 15:39:28 +02:00
|
|
|
// parsing ATTACH attributes for managed attachments
|
2015-06-24 14:30:56 +02:00
|
|
|
$event['attach-delete-by-put'] = $component->getAttributeDefault('X-EGROUPWARE-ATTACH-INCLUDED', null) === 'TRUE';
|
2013-09-23 15:39:28 +02:00
|
|
|
$event['attach'] = $component->getAllAttributes('ATTACH');
|
|
|
|
|
2010-01-09 19:04:21 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n" .
|
|
|
|
array2string($event)."\n",3,$this->logfile);
|
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
//Horde::logMessage("vevent2egw:\n" . print_r($event, true),
|
2020-02-26 13:51:41 +01:00
|
|
|
// __FILE__, __LINE__, PEAR_LOG_DEBUG);
|
2009-07-15 22:35:56 +02:00
|
|
|
return $event;
|
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2021-03-28 20:48:55 +02:00
|
|
|
function iCalSearch($_vcalData, $contentID=null, $relax=false, $charset=null)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2010-03-22 19:03:23 +01:00
|
|
|
if (($events = $this->icaltoegw($_vcalData, $charset)))
|
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
|
|
|
{
|
2010-02-11 08:33:32 +01:00
|
|
|
$filter = $relax ? 'relax' : 'check';
|
2009-09-22 15:43:55 +02:00
|
|
|
$event = array_shift($events);
|
2010-03-07 00:06:43 +01:00
|
|
|
$eventId = -1;
|
2010-01-29 22:42:54 +01:00
|
|
|
if ($this->so->isWholeDay($event)) $event['whole_day'] = true;
|
2010-03-07 00:06:43 +01:00
|
|
|
if ($contentID)
|
|
|
|
{
|
|
|
|
$parts = preg_split('/:/', $contentID);
|
|
|
|
$event['id'] = $eventId = $parts[0];
|
|
|
|
}
|
2010-02-17 14:29:28 +01:00
|
|
|
$event['category'] = $this->find_or_add_categories($event['category'], $eventId);
|
2010-01-29 22:42:54 +01:00
|
|
|
return $this->find_event($event, $filter);
|
|
|
|
}
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."() found:\n" .
|
|
|
|
array2string($events)."\n",3,$this->logfile);
|
2009-10-05 23:00:08 +02:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2010-01-29 22:42:54 +01:00
|
|
|
return array();
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
|
2017-03-29 19:31:53 +02:00
|
|
|
/**
|
|
|
|
* iCal defines enddate to be a time and eg. Apple sends 1s less then next recurance, if they split events
|
|
|
|
*
|
|
|
|
* We need to fix that situation by moving end one day back.
|
|
|
|
*
|
|
|
|
* @param array& $vcardData values for keys "start" and "recur_enddate", later get's modified if neccessary
|
|
|
|
*/
|
|
|
|
static function check_fix_endate(array &$vcardData)
|
|
|
|
{
|
|
|
|
$end = new Api\DateTime($vcardData['recur_enddate']);
|
|
|
|
$start = new Api\DateTime($vcardData['start']);
|
|
|
|
$start->setDate($end->format('Y'), $end->format('m'), $end->format('d'));
|
|
|
|
|
|
|
|
if ($end->format('ts') < $start->format('ts'))
|
|
|
|
{
|
|
|
|
$end->modify('-1day');
|
|
|
|
$vcardData['recur_enddate'] = $end->format('ts');
|
|
|
|
//error_log(__METHOD__."($vcardData[event_title]) fix recure_enddate to ".$end->format('Y-m-d H:i:s'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-07 19:45:33 +02:00
|
|
|
/**
|
|
|
|
* Create a freebusy vCal for the given user(s)
|
|
|
|
*
|
|
|
|
* @param int $user account_id
|
2015-06-22 17:36:23 +02:00
|
|
|
* @param mixed $end =null end-date, default now+1 month
|
|
|
|
* @param boolean $utc =true if false, use severtime for dates
|
|
|
|
* @param string $charset ='UTF-8' encoding of the vcalendar, default UTF-8
|
|
|
|
* @param mixed $start =null default now
|
|
|
|
* @param string $method ='PUBLISH' or eg. 'REPLY'
|
|
|
|
* @param array $extra =null extra attributes to add
|
2011-09-22 17:22:52 +02:00
|
|
|
* X-CALENDARSERVER-MASK-UID can be used to not include an event specified by this uid as busy
|
2008-06-07 19:45:33 +02:00
|
|
|
*/
|
2011-09-22 17:22:52 +02:00
|
|
|
function freebusy($user,$end=null,$utc=true, $charset='UTF-8', $start=null, $method='PUBLISH', array $extra=null)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2011-09-22 17:22:52 +02:00
|
|
|
if (!$start) $start = time(); // default now
|
|
|
|
if (!$end) $end = time() + 100*DAY_s; // default next 100 days
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2015-06-22 17:36:23 +02:00
|
|
|
$vcal = new Horde_Icalendar;
|
2011-09-22 17:22:52 +02:00
|
|
|
$vcal->setAttribute('PRODID','-//EGroupware//NONSGML EGroupware Calendar '.$GLOBALS['egw_info']['apps']['calendar']['version'].'//'.
|
2008-06-07 19:45:33 +02:00
|
|
|
strtoupper($GLOBALS['egw_info']['user']['preferences']['common']['lang']));
|
|
|
|
$vcal->setAttribute('VERSION','2.0');
|
2011-09-22 17:22:52 +02:00
|
|
|
$vcal->setAttribute('METHOD',$method);
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2015-06-22 17:36:23 +02:00
|
|
|
$vfreebusy = Horde_Icalendar::newComponent('VFREEBUSY',$vcal);
|
2011-09-22 17:22:52 +02:00
|
|
|
|
|
|
|
$attributes = array(
|
|
|
|
'DTSTAMP' => time(),
|
|
|
|
'DTSTART' => $this->date2ts($start,true), // true = server-time
|
|
|
|
'DTEND' => $this->date2ts($end,true), // true = server-time
|
2008-06-07 19:45:33 +02:00
|
|
|
);
|
2011-09-22 17:22:52 +02:00
|
|
|
if (!$utc)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2011-09-22 17:22:52 +02:00
|
|
|
foreach ($attributes as $attr => $value)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2011-09-22 17:22:52 +02:00
|
|
|
$attributes[$attr] = date('Ymd\THis', $value);
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
|
|
|
}
|
2011-09-22 17:22:52 +02:00
|
|
|
if (is_null($extra)) $extra = array(
|
|
|
|
'URL' => $this->freebusy_url($user),
|
|
|
|
'ORGANIZER' => 'mailto:'.$GLOBALS['egw']->accounts->id2name($user,'account_email'),
|
|
|
|
);
|
|
|
|
foreach($attributes+$extra as $attr => $value)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2011-09-22 17:22:52 +02:00
|
|
|
$vfreebusy->setAttribute($attr, $value);
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2017-09-29 09:39:47 +02:00
|
|
|
$events = parent::search(array(
|
2011-09-22 17:22:52 +02:00
|
|
|
'start' => $start,
|
2009-07-28 10:58:39 +02:00
|
|
|
'end' => $end,
|
|
|
|
'users' => $user,
|
|
|
|
'date_format' => 'server',
|
|
|
|
'show_rejected' => false,
|
|
|
|
));
|
2017-09-29 09:39:47 +02:00
|
|
|
if (is_array($events))
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
2017-09-29 09:39:47 +02:00
|
|
|
$fbdata = array();
|
|
|
|
|
|
|
|
foreach ($events as $event)
|
2008-06-07 19:45:33 +02:00
|
|
|
{
|
|
|
|
if ($event['non_blocking']) continue;
|
2011-09-22 17:22:52 +02:00
|
|
|
if ($event['uid'] === $extra['X-CALENDARSERVER-MASK-UID']) continue;
|
2017-08-18 09:49:02 +02:00
|
|
|
$status = $event['participants'][$user];
|
|
|
|
$quantity = $role = null;
|
|
|
|
calendar_so::split_status($status, $quantity, $role);
|
|
|
|
if ($status == 'R' || $role == 'NON-PARTICIPANT') continue;
|
2008-06-07 19:45:33 +02:00
|
|
|
|
2017-08-18 09:49:02 +02:00
|
|
|
$fbtype = $status == 'T' ? 'BUSY-TENTATIVE' : 'BUSY';
|
2011-09-22 21:49:01 +02:00
|
|
|
|
2017-09-29 09:39:47 +02:00
|
|
|
// hack to fix end-time to be non-inclusive
|
|
|
|
// all-day events end in our data-model at 23:59:59 (of given TZ)
|
|
|
|
if (date('is', $event['end']) == '5959') ++$event['end'];
|
|
|
|
|
|
|
|
$fbdata[$fbtype][] = $event;
|
|
|
|
}
|
|
|
|
foreach($fbdata as $fbtype => $events)
|
|
|
|
{
|
|
|
|
foreach($this->aggregate_periods($events, $start, $end) as $event)
|
2009-07-15 22:35:56 +02:00
|
|
|
{
|
2017-09-29 09:39:47 +02:00
|
|
|
if ($utc)
|
|
|
|
{
|
|
|
|
$vfreebusy->setAttribute('FREEBUSY',array(array(
|
|
|
|
'start' => $event['start'],
|
|
|
|
'end' => $event['end'],
|
|
|
|
)), array('FBTYPE' => $fbtype));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$vfreebusy->setAttribute('FREEBUSY',array(array(
|
|
|
|
'start' => date('Ymd\THis',$event['start']),
|
|
|
|
'end' => date('Ymd\THis',$event['end']),
|
|
|
|
)), array('FBTYPE' => $fbtype));
|
|
|
|
}
|
2009-07-15 22:35:56 +02:00
|
|
|
}
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$vcal->addComponent($vfreebusy);
|
|
|
|
|
2010-03-22 19:03:23 +01:00
|
|
|
return $vcal->exportvCalendar($charset);
|
2008-06-07 19:45:33 +02:00
|
|
|
}
|
2017-09-29 09:39:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Aggregate multiple, possibly overlapping events cliped by $start and $end
|
|
|
|
*
|
|
|
|
* @param array $events array with values for keys "start" and "end"
|
|
|
|
* @param int $start
|
|
|
|
* @param int $end
|
|
|
|
* @return array of array with values for keys "start" and "end"
|
|
|
|
*/
|
|
|
|
public function aggregate_periods(array $events, $start, $end)
|
|
|
|
{
|
|
|
|
// sort by start datetime
|
|
|
|
uasort($events, function($a, $b)
|
|
|
|
{
|
2018-12-18 16:04:22 +01:00
|
|
|
$diff = $a['start'] - $b['start'];
|
2017-09-29 09:39:47 +02:00
|
|
|
|
2018-12-18 16:04:22 +01:00
|
|
|
return $diff == 0 ? 0 : ($diff < 0 ? -1 : 1);
|
2017-09-29 09:39:47 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$fbdata = array();
|
|
|
|
foreach($events as $event)
|
|
|
|
{
|
|
|
|
error_log(__METHOD__."(..., $start, $end) event[start]=$event[start], event[end]=$event[end], fbdata=".array2string($fbdata));
|
|
|
|
if ($event['end'] <= $start || $event['start'] >= $end) continue;
|
|
|
|
|
|
|
|
if (!$fbdata)
|
|
|
|
{
|
|
|
|
$fbdata[] = array(
|
|
|
|
'start' => $event['start'] < $start ? $start : $event['start'],
|
|
|
|
'end' => $event['end'],
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$last =& $fbdata[count($fbdata)-1];
|
|
|
|
|
|
|
|
if ($last['end'] >= $event['start'])
|
|
|
|
{
|
|
|
|
if ($last['end'] < $event['end'])
|
|
|
|
{
|
|
|
|
$last['end'] = $event['end'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$fbdata[] = array(
|
|
|
|
'start' => $event['start'],
|
|
|
|
'end' => $event['end'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$last =& $fbdata[count($fbdata)-1];
|
|
|
|
|
|
|
|
if ($last['end'] > $end) $last['end'] = $end;
|
|
|
|
|
|
|
|
error_log(__METHOD__."(..., $start, $end) returning ".array2string($fbdata));
|
|
|
|
return $fbdata;
|
|
|
|
}
|
2010-11-04 11:46:56 +01:00
|
|
|
}
|