2011-05-20 19:04:25 +02:00
|
|
|
<?php
|
2011-08-21 12:48:33 +02:00
|
|
|
|
|
|
|
/**
|
2011-11-21 11:20:48 +01:00
|
|
|
* Kolab calendar storage class
|
2011-08-21 12:48:33 +02:00
|
|
|
*
|
2011-11-21 11:20:48 +01:00
|
|
|
* @version @package_version@
|
2011-12-07 12:51:23 +01:00
|
|
|
* @author Thomas Bruederli <bruederli@kolabsys.com>
|
2011-08-21 12:48:33 +02:00
|
|
|
* @author Aleksander Machniak <machniak@kolabsys.com>
|
|
|
|
*
|
2015-03-10 15:38:45 +01:00
|
|
|
* Copyright (C) 2012-2015, Kolab Systems AG <contact@kolabsys.com>
|
2011-08-21 12:48:33 +02:00
|
|
|
*
|
2011-10-27 10:20:46 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2011-08-21 12:48:33 +02:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2011-10-27 10:20:46 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2011-08-21 12:48:33 +02:00
|
|
|
*
|
2011-10-27 10:20:46 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-21 12:48:33 +02:00
|
|
|
*/
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
|
2014-05-15 13:15:58 +02:00
|
|
|
class kolab_calendar extends kolab_storage_folder_api
|
2011-05-20 19:04:25 +02:00
|
|
|
{
|
|
|
|
public $ready = false;
|
2015-03-11 15:24:17 +01:00
|
|
|
public $rights = 'lrs';
|
|
|
|
public $editable = false;
|
2011-07-01 21:08:12 +02:00
|
|
|
public $attachments = true;
|
2011-07-07 08:23:49 +02:00
|
|
|
public $alarms = false;
|
2014-07-29 15:28:35 +02:00
|
|
|
public $history = false;
|
2014-05-15 15:53:35 +02:00
|
|
|
public $subscriptions = true;
|
2011-09-14 16:02:07 +02:00
|
|
|
public $categories = array();
|
2011-09-19 09:50:13 +02:00
|
|
|
public $storage;
|
2014-05-15 11:57:54 +02:00
|
|
|
|
|
|
|
public $type = 'event';
|
2011-06-27 15:49:51 +02:00
|
|
|
|
2014-05-14 20:37:06 +02:00
|
|
|
protected $cal;
|
|
|
|
protected $events = array();
|
|
|
|
protected $search_fields = array('title', 'description', 'location', 'attendees');
|
2011-06-13 16:00:55 +03:00
|
|
|
|
2014-05-14 20:37:06 +02:00
|
|
|
/**
|
|
|
|
* Factory method to instantiate a kolab_calendar object
|
|
|
|
*
|
|
|
|
* @param string Calendar ID (encoded IMAP folder name)
|
|
|
|
* @param object calendar plugin object
|
|
|
|
* @return object kolab_calendar instance
|
|
|
|
*/
|
|
|
|
public static function factory($id, $calendar)
|
|
|
|
{
|
|
|
|
$imap = $calendar->rc->get_storage();
|
|
|
|
$imap_folder = kolab_storage::id_decode($id);
|
|
|
|
$info = $imap->folder_info($imap_folder, true);
|
2014-05-21 10:50:36 +02:00
|
|
|
if (empty($info) || $info['noselect'] || strpos(kolab_storage::folder_type($imap_folder), 'event') !== 0) {
|
2014-05-14 20:37:06 +02:00
|
|
|
return new kolab_user_calendar($imap_folder, $calendar);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return new kolab_calendar($imap_folder, $calendar);
|
|
|
|
}
|
|
|
|
}
|
2011-06-27 15:49:51 +02:00
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
*/
|
2011-06-18 18:40:12 -06:00
|
|
|
public function __construct($imap_folder, $calendar)
|
2011-05-20 19:04:25 +02:00
|
|
|
{
|
2011-06-18 18:40:12 -06:00
|
|
|
$this->cal = $calendar;
|
2014-05-15 13:15:58 +02:00
|
|
|
$this->imap = $calendar->rc->get_storage();
|
|
|
|
$this->name = $imap_folder;
|
2011-06-15 11:23:59 +02:00
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
// ID is derrived from folder name
|
2014-05-15 13:15:58 +02:00
|
|
|
$this->id = kolab_storage::folder_id($this->name, true);
|
|
|
|
$old_id = kolab_storage::folder_id($this->name, false);
|
2011-05-20 19:04:25 +02:00
|
|
|
|
|
|
|
// fetch objects from the given IMAP folder
|
2014-05-15 13:15:58 +02:00
|
|
|
$this->storage = kolab_storage::get_folder($this->name);
|
2015-02-03 13:16:24 +01:00
|
|
|
$this->ready = $this->storage && $this->storage->valid;
|
2011-06-28 10:32:52 +02:00
|
|
|
|
2015-03-11 12:22:01 +01:00
|
|
|
// Set writeable and alarms flags according to folder permissions
|
2011-06-28 10:32:52 +02:00
|
|
|
if ($this->ready) {
|
2012-10-03 11:53:02 +02:00
|
|
|
if ($this->storage->get_namespace() == 'personal') {
|
2015-03-11 15:24:17 +01:00
|
|
|
$this->editable = true;
|
|
|
|
$this->rights = 'lrswikxteav';
|
2011-07-07 08:23:49 +02:00
|
|
|
$this->alarms = true;
|
2011-06-28 10:32:52 +02:00
|
|
|
}
|
|
|
|
else {
|
2012-04-21 18:43:33 +02:00
|
|
|
$rights = $this->storage->get_myrights();
|
2012-04-04 13:01:59 +02:00
|
|
|
if ($rights && !PEAR::isError($rights)) {
|
2015-03-11 15:24:17 +01:00
|
|
|
$this->rights = $rights;
|
2015-03-11 12:22:01 +01:00
|
|
|
if (strpos($rights, 't') !== false || strpos($rights, 'd') !== false)
|
2015-03-11 15:24:17 +01:00
|
|
|
$this->editable = strpos($rights, 'i');;
|
2011-07-25 12:33:44 +02:00
|
|
|
}
|
2011-06-28 10:32:52 +02:00
|
|
|
}
|
2011-07-31 14:40:52 +02:00
|
|
|
|
|
|
|
// user-specific alarms settings win
|
|
|
|
$prefs = $this->cal->rc->config->get('kolab_calendars', array());
|
|
|
|
if (isset($prefs[$this->id]['showalarms']))
|
|
|
|
$this->alarms = $prefs[$this->id]['showalarms'];
|
2014-05-13 17:09:53 +02:00
|
|
|
else if (isset($prefs[$old_id]['showalarms']))
|
|
|
|
$this->alarms = $prefs[$old_id]['showalarms'];
|
2011-06-28 10:32:52 +02:00
|
|
|
}
|
2014-05-15 13:15:58 +02:00
|
|
|
|
|
|
|
$this->default = $this->storage->default;
|
2014-09-23 12:27:57 +02:00
|
|
|
$this->subtype = $this->storage->subtype;
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-27 15:49:51 +02:00
|
|
|
/**
|
|
|
|
* Getter for the IMAP folder name
|
|
|
|
*
|
|
|
|
* @return string Name of the IMAP folder
|
|
|
|
*/
|
|
|
|
public function get_realname()
|
|
|
|
{
|
2014-05-15 13:15:58 +02:00
|
|
|
return $this->name;
|
2011-06-28 10:32:52 +02:00
|
|
|
}
|
|
|
|
|
2014-05-20 09:50:41 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function get_title()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-06-28 10:32:52 +02:00
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
/**
|
|
|
|
* Return color to display this calendar
|
|
|
|
*/
|
2011-06-27 15:49:51 +02:00
|
|
|
public function get_color()
|
2011-05-20 19:04:25 +02:00
|
|
|
{
|
2011-08-26 23:24:49 +02:00
|
|
|
// color is defined in folder METADATA
|
2012-11-21 12:30:27 +01:00
|
|
|
if ($color = $this->storage->get_color()) {
|
2011-08-26 23:24:49 +02:00
|
|
|
return $color;
|
|
|
|
}
|
2011-09-30 17:28:29 +02:00
|
|
|
|
2011-09-16 15:52:09 +02:00
|
|
|
// calendar color is stored in user prefs (temporary solution)
|
2011-06-27 15:49:51 +02:00
|
|
|
$prefs = $this->cal->rc->config->get('kolab_calendars', array());
|
|
|
|
|
|
|
|
if (!empty($prefs[$this->id]) && !empty($prefs[$this->id]['color']))
|
|
|
|
return $prefs[$this->id]['color'];
|
|
|
|
|
|
|
|
return 'cc0000';
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
2011-06-27 15:49:51 +02:00
|
|
|
|
2013-10-03 12:07:02 +02:00
|
|
|
/**
|
|
|
|
* Compose an URL for CalDAV access to this calendar (if configured)
|
|
|
|
*/
|
|
|
|
public function get_caldav_url()
|
|
|
|
{
|
|
|
|
if ($template = $this->cal->rc->config->get('calendar_caldav_url', null)) {
|
|
|
|
return strtr($template, array(
|
|
|
|
'%h' => $_SERVER['HTTP_HOST'],
|
|
|
|
'%u' => urlencode($this->cal->rc->get_user_name()),
|
|
|
|
'%i' => urlencode($this->storage->get_uid()),
|
2014-05-15 13:15:58 +02:00
|
|
|
'%n' => urlencode($this->name),
|
2013-10-03 12:07:02 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-01 21:08:12 +02:00
|
|
|
|
2014-05-15 11:57:54 +02:00
|
|
|
/**
|
|
|
|
* Update properties of this calendar folder
|
|
|
|
*
|
|
|
|
* @see calendar_driver::edit_calendar()
|
|
|
|
*/
|
|
|
|
public function update(&$prop)
|
|
|
|
{
|
|
|
|
$prop['oldname'] = $this->get_realname();
|
|
|
|
$newfolder = kolab_storage::folder_update($prop);
|
|
|
|
|
|
|
|
if ($newfolder === false) {
|
|
|
|
$this->cal->last_error = $this->cal->gettext(kolab_storage::$last_error);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create ID
|
|
|
|
return kolab_storage::folder_id($newfolder);
|
|
|
|
}
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
/**
|
|
|
|
* Getter for a single event object
|
|
|
|
*/
|
|
|
|
public function get_event($id)
|
|
|
|
{
|
2016-02-22 15:19:58 +01:00
|
|
|
// remove our occurrence identifier if it's there
|
|
|
|
$master_id = preg_replace('/-\d{8}(T\d{6})?$/', '', $id);
|
|
|
|
|
2012-05-09 19:02:46 +02:00
|
|
|
// directly access storage object
|
2016-02-22 15:19:58 +01:00
|
|
|
if (!$this->events[$id] && $master_id == $id && ($record = $this->storage->get_object($id))) {
|
|
|
|
$this->events[$id] = $this->_to_driver_event($record, true);
|
|
|
|
}
|
2012-05-09 19:02:46 +02:00
|
|
|
|
2016-02-22 15:19:58 +01:00
|
|
|
// maybe a recurring instance is requested
|
|
|
|
if (!$this->events[$id] && $master_id != $id) {
|
2015-02-26 14:48:14 +01:00
|
|
|
$instance_id = substr($id, strlen($master_id) + 1);
|
|
|
|
|
2016-02-22 15:19:58 +01:00
|
|
|
if ($record = $this->storage->get_object($master_id)) {
|
|
|
|
$master = $this->_to_driver_event($record, true);
|
|
|
|
$this->events[$master_id] = $master;
|
2015-02-26 14:48:14 +01:00
|
|
|
}
|
2012-05-09 19:02:46 +02:00
|
|
|
|
2016-02-22 15:19:58 +01:00
|
|
|
if ($master) {
|
|
|
|
// check for match in top-level exceptions (aka loose single occurrences)
|
|
|
|
if ($master['_formatobj'] && ($instance = $master['_formatobj']->get_instance($instance_id))) {
|
|
|
|
$this->events[$id] = $this->_to_driver_event($instance);
|
|
|
|
}
|
|
|
|
// check for match on the first instance already
|
|
|
|
else if ($master['_instance'] && $master['_instance'] == $instance_id) {
|
|
|
|
$this->events[$id] = $master;
|
|
|
|
}
|
|
|
|
else if (is_array($master['recurrence'])) {
|
|
|
|
$this->get_recurring_events($record, $master['start'], null, $id);
|
|
|
|
}
|
2011-06-29 19:42:56 +02:00
|
|
|
}
|
|
|
|
}
|
2012-05-09 19:02:46 +02:00
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
return $this->events[$id];
|
|
|
|
}
|
|
|
|
|
2015-02-24 12:49:05 +01:00
|
|
|
/**
|
|
|
|
* Get attachment body
|
|
|
|
* @see calendar_driver::get_attachment_body()
|
|
|
|
*/
|
|
|
|
public function get_attachment_body($id, $event)
|
|
|
|
{
|
2015-02-26 15:24:22 +01:00
|
|
|
if (!$this->ready)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$data = $this->storage->get_attachment($event['id'], $id);
|
|
|
|
|
|
|
|
if ($data == null) {
|
|
|
|
// try again with master UID
|
|
|
|
$uid = preg_replace('/-\d+(T\d{6})?$/', '', $event['id']);
|
|
|
|
if ($uid != $event['id']) {
|
|
|
|
$data = $this->storage->get_attachment($uid, $id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
2015-02-24 12:49:05 +01:00
|
|
|
}
|
2011-05-20 19:04:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param integer Event's new start (unix timestamp)
|
|
|
|
* @param integer Event's new end (unix timestamp)
|
2011-06-13 18:41:32 -06:00
|
|
|
* @param string Search query (optional)
|
2012-05-16 18:36:03 +02:00
|
|
|
* @param boolean Include virtual events (optional)
|
|
|
|
* @param array Additional parameters to query storage
|
2014-07-08 12:36:34 +02:00
|
|
|
* @param array Additional query to filter events
|
2011-05-20 19:04:25 +02:00
|
|
|
* @return array A list of event records
|
|
|
|
*/
|
2014-07-08 12:36:34 +02:00
|
|
|
public function list_events($start, $end, $search = null, $virtual = 1, $query = array(), $filter_query = null)
|
2011-05-20 19:04:25 +02:00
|
|
|
{
|
2012-07-06 17:15:45 +02:00
|
|
|
// convert to DateTime for comparisons
|
2015-08-18 12:39:55 +02:00
|
|
|
// #5190: make the range a little bit wider
|
|
|
|
// to workaround possible timezone differences
|
2014-03-07 16:15:25 +01:00
|
|
|
try {
|
2015-08-18 12:39:55 +02:00
|
|
|
$start = new DateTime('@' . ($start - 12 * 3600));
|
2014-03-07 16:15:25 +01:00
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
$start = new DateTime('@0');
|
|
|
|
}
|
|
|
|
try {
|
2015-08-18 12:39:55 +02:00
|
|
|
$end = new DateTime('@' . ($end + 12 * 3600));
|
2014-03-07 16:15:25 +01:00
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
$end = new DateTime('today +10 years');
|
|
|
|
}
|
2012-07-06 17:15:45 +02:00
|
|
|
|
2014-07-08 12:36:34 +02:00
|
|
|
// get email addresses of the current user
|
|
|
|
$user_emails = $this->cal->get_user_emails();
|
|
|
|
|
2012-05-09 19:02:46 +02:00
|
|
|
// query Kolab storage
|
2012-05-16 18:36:03 +02:00
|
|
|
$query[] = array('dtstart', '<=', $end);
|
|
|
|
$query[] = array('dtend', '>=', $start);
|
|
|
|
|
2015-02-16 11:00:26 +01:00
|
|
|
if (is_array($filter_query)) {
|
2014-07-08 12:36:34 +02:00
|
|
|
$query = array_merge($query, $filter_query);
|
|
|
|
}
|
|
|
|
|
2012-05-30 09:13:24 +02:00
|
|
|
if (!empty($search)) {
|
|
|
|
$search = mb_strtolower($search);
|
2015-02-16 11:00:26 +01:00
|
|
|
$words = rcube_utils::tokenize_string($search, 1);
|
2012-05-30 09:13:24 +02:00
|
|
|
foreach (rcube_utils::normalize_string($search, true) as $word) {
|
|
|
|
$query[] = array('words', 'LIKE', $word);
|
|
|
|
}
|
|
|
|
}
|
2015-02-16 11:00:26 +01:00
|
|
|
else {
|
|
|
|
$words = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
// set partstat filter to skip pending and declined invitations
|
2016-04-07 08:18:23 -04:00
|
|
|
if (empty($filter_query) && $this->cal->rc->config->get('kolab_invitation_calendars')
|
|
|
|
&& $this->get_namespace() != 'other'
|
|
|
|
) {
|
2015-02-16 11:00:26 +01:00
|
|
|
$partstat_exclude = array('NEEDS-ACTION','DECLINED');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$partstat_exclude = array();
|
|
|
|
}
|
2012-05-30 09:13:24 +02:00
|
|
|
|
2012-07-06 17:15:45 +02:00
|
|
|
$events = array();
|
2014-02-06 17:30:40 +01:00
|
|
|
foreach ($this->storage->select($query) as $record) {
|
2016-02-21 19:09:04 +01:00
|
|
|
$event = $this->_to_driver_event($record, !$virtual, false);
|
2012-05-09 19:02:46 +02:00
|
|
|
|
2011-09-14 16:02:07 +02:00
|
|
|
// remember seen categories
|
2015-02-27 17:52:17 +01:00
|
|
|
if ($event['categories']) {
|
|
|
|
$cat = is_array($event['categories']) ? $event['categories'][0] : $event['categories'];
|
|
|
|
$this->categories[$cat]++;
|
2016-02-21 19:09:04 +01:00
|
|
|
}
|
2015-02-05 19:37:03 +01:00
|
|
|
|
2011-05-30 22:57:36 +02:00
|
|
|
// list events in requested time window
|
2011-05-22 17:29:09 +02:00
|
|
|
if ($event['start'] <= $end && $event['end'] >= $start) {
|
2011-07-31 11:13:13 +02:00
|
|
|
unset($event['_attendees']);
|
2013-01-09 11:12:19 +01:00
|
|
|
$add = true;
|
|
|
|
|
|
|
|
// skip the first instance of a recurring event if listed in exdate
|
2015-02-17 11:36:01 +01:00
|
|
|
if ($virtual && !empty($event['recurrence']['EXDATE'])) {
|
2013-01-09 11:12:19 +01:00
|
|
|
$event_date = $event['start']->format('Ymd');
|
2013-11-29 20:23:17 +01:00
|
|
|
$exdates = (array)$event['recurrence']['EXDATE'];
|
|
|
|
|
|
|
|
foreach ($exdates as $exdate) {
|
2013-01-09 11:12:19 +01:00
|
|
|
if ($exdate->format('Ymd') == $event_date) {
|
|
|
|
$add = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-17 11:36:01 +01:00
|
|
|
// find and merge exception for the first instance
|
2015-02-17 13:10:37 +01:00
|
|
|
if ($virtual && !empty($event['recurrence']) && is_array($event['recurrence']['EXCEPTIONS'])) {
|
2015-02-17 11:36:01 +01:00
|
|
|
foreach ($event['recurrence']['EXCEPTIONS'] as $exception) {
|
2015-02-27 17:52:17 +01:00
|
|
|
if ($event['_instance'] == $exception['_instance']) {
|
|
|
|
// clone date objects from main event before adjusting them with exception data
|
|
|
|
if (is_object($event['start'])) $event['start'] = clone $record['start'];
|
|
|
|
if (is_object($event['end'])) $event['end'] = clone $record['end'];
|
2015-02-17 15:49:14 +01:00
|
|
|
kolab_driver::merge_exception_data($event, $exception);
|
2015-02-17 11:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-09 11:12:19 +01:00
|
|
|
if ($add)
|
|
|
|
$events[] = $event;
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
2015-02-16 11:00:26 +01:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
// resolve recurring events
|
2012-07-06 17:15:45 +02:00
|
|
|
if ($record['recurrence'] && $virtual == 1) {
|
2015-02-02 13:12:56 +01:00
|
|
|
$events = array_merge($events, $this->get_recurring_events($record, $start, $end));
|
2015-02-16 11:00:26 +01:00
|
|
|
}
|
2015-02-26 14:48:14 +01:00
|
|
|
// add top-level exceptions (aka loose single occurrences)
|
|
|
|
else if (is_array($record['exceptions'])) {
|
|
|
|
foreach ($record['exceptions'] as $ex) {
|
2016-02-21 19:09:04 +01:00
|
|
|
$component = $this->_to_driver_event($ex, false, false);
|
2015-02-26 14:48:14 +01:00
|
|
|
if ($component['start'] <= $end && $component['end'] >= $start) {
|
|
|
|
$events[] = $component;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-16 11:00:26 +01:00
|
|
|
}
|
2015-02-05 19:37:03 +01:00
|
|
|
|
2015-02-16 11:00:26 +01:00
|
|
|
// post-filter all events by fulltext search and partstat values
|
|
|
|
$me = $this;
|
|
|
|
$events = array_filter($events, function($event) use ($words, $partstat_exclude, $user_emails, $me) {
|
|
|
|
// fulltext search
|
|
|
|
if (count($words)) {
|
|
|
|
$hits = 0;
|
|
|
|
foreach ($words as $word) {
|
2015-02-24 17:36:04 +01:00
|
|
|
$hits += $me->fulltext_match($event, $word, false);
|
2015-02-16 11:00:26 +01:00
|
|
|
}
|
|
|
|
if ($hits < count($words)) {
|
|
|
|
return false;
|
2015-02-05 19:37:03 +01:00
|
|
|
}
|
2011-05-30 22:57:36 +02:00
|
|
|
}
|
2015-02-16 11:00:26 +01:00
|
|
|
|
|
|
|
// partstat filter
|
|
|
|
if (count($partstat_exclude) && is_array($event['attendees'])) {
|
|
|
|
foreach ($event['attendees'] as $attendee) {
|
|
|
|
if (in_array($attendee['email'], $user_emails) && in_array($attendee['status'], $partstat_exclude)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
2011-07-01 21:08:12 +02:00
|
|
|
|
2016-02-21 19:09:04 +01:00
|
|
|
// Apply event-to-mail relations
|
|
|
|
$config = kolab_storage_config::get_instance();
|
2016-02-21 19:41:49 +01:00
|
|
|
$config->apply_links($events);
|
2016-02-21 19:09:04 +01:00
|
|
|
|
2014-05-22 19:00:49 +02:00
|
|
|
// avoid session race conditions that will loose temporary subscriptions
|
2014-05-27 19:52:03 +02:00
|
|
|
$this->cal->rc->session->nowrite = true;
|
2014-05-22 19:00:49 +02:00
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
return $events;
|
|
|
|
}
|
|
|
|
|
2014-10-14 20:23:52 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param integer Date range start (unix timestamp)
|
|
|
|
* @param integer Date range end (unix timestamp)
|
|
|
|
* @param array Additional query to filter events
|
|
|
|
* @return integer Count
|
|
|
|
*/
|
|
|
|
public function count_events($start, $end = null, $filter_query = null)
|
|
|
|
{
|
|
|
|
// convert to DateTime for comparisons
|
|
|
|
try {
|
|
|
|
$start = new DateTime('@'.$start);
|
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
$start = new DateTime('@0');
|
|
|
|
}
|
|
|
|
if ($end) {
|
|
|
|
try {
|
|
|
|
$end = new DateTime('@'.$end);
|
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
$end = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// query Kolab storage
|
|
|
|
$query[] = array('dtend', '>=', $start);
|
|
|
|
|
|
|
|
if ($end)
|
|
|
|
$query[] = array('dtstart', '<=', $end);
|
|
|
|
|
|
|
|
// add query to exclude pending/declined invitations
|
|
|
|
if (empty($filter_query)) {
|
|
|
|
foreach ($this->cal->get_user_emails() as $email) {
|
|
|
|
$query[] = array('tags', '!=', 'x-partstat:' . $email . ':needs-action');
|
|
|
|
$query[] = array('tags', '!=', 'x-partstat:' . $email . ':declined');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (is_array($filter_query)) {
|
|
|
|
$query = array_merge($query, $filter_query);
|
|
|
|
}
|
|
|
|
|
|
|
|
// we rely the Kolab storage query (no post-filtering)
|
|
|
|
return $this->storage->count($query);
|
|
|
|
}
|
2011-05-20 19:04:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new event record
|
|
|
|
*
|
2011-07-27 16:06:06 +02:00
|
|
|
* @see calendar_driver::new_event()
|
2011-06-19 14:46:38 +03:00
|
|
|
*
|
2011-05-20 19:04:25 +02:00
|
|
|
* @return mixed The created record ID on success, False on error
|
|
|
|
*/
|
|
|
|
public function insert_event($event)
|
|
|
|
{
|
2011-06-29 15:36:39 +02:00
|
|
|
if (!is_array($event))
|
|
|
|
return false;
|
2011-07-01 21:08:12 +02:00
|
|
|
|
2015-01-14 09:27:48 +01:00
|
|
|
// email links are stored separately
|
|
|
|
$links = $event['links'];
|
|
|
|
unset($event['links']);
|
|
|
|
|
2011-06-29 15:36:39 +02:00
|
|
|
//generate new event from RC input
|
2015-02-27 17:52:17 +01:00
|
|
|
$object = $this->_from_driver_event($event);
|
2016-02-22 15:19:58 +01:00
|
|
|
$saved = $this->storage->save($object, 'event');
|
|
|
|
|
2012-08-03 15:20:41 +02:00
|
|
|
if (!$saved) {
|
2012-11-06 11:46:15 +01:00
|
|
|
rcube::raise_error(array(
|
2011-06-29 15:36:39 +02:00
|
|
|
'code' => 600, 'type' => 'php',
|
|
|
|
'file' => __FILE__, 'line' => __LINE__,
|
2012-08-03 15:20:41 +02:00
|
|
|
'message' => "Error saving event object to Kolab server"),
|
2011-06-29 15:36:39 +02:00
|
|
|
true, false);
|
|
|
|
$saved = false;
|
|
|
|
}
|
2011-07-27 16:06:06 +02:00
|
|
|
else {
|
2015-01-14 09:27:48 +01:00
|
|
|
// save links in configuration.relation object
|
2016-02-22 15:19:58 +01:00
|
|
|
if ($this->save_links($event['uid'], $links)) {
|
|
|
|
$object['links'] = $links;
|
|
|
|
}
|
2015-01-14 09:27:48 +01:00
|
|
|
|
2015-02-27 17:52:17 +01:00
|
|
|
$this->events = array($event['uid'] => $this->_to_driver_event($object, true));
|
2011-07-27 16:06:06 +02:00
|
|
|
}
|
2016-02-22 15:19:58 +01:00
|
|
|
|
2011-06-13 16:00:55 +03:00
|
|
|
return $saved;
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a specific event record
|
|
|
|
*
|
2011-07-27 16:06:06 +02:00
|
|
|
* @see calendar_driver::new_event()
|
2011-05-20 19:04:25 +02:00
|
|
|
* @return boolean True on success, False on error
|
|
|
|
*/
|
|
|
|
|
2013-01-23 14:45:41 +01:00
|
|
|
public function update_event($event, $exception_id = null)
|
2011-05-20 19:04:25 +02:00
|
|
|
{
|
2011-06-29 15:36:39 +02:00
|
|
|
$updated = false;
|
2015-02-26 14:48:14 +01:00
|
|
|
$old = $this->storage->get_object($event['uid'] ?: $event['id']);
|
2012-04-04 13:01:59 +02:00
|
|
|
if (!$old || PEAR::isError($old))
|
2011-09-19 09:50:13 +02:00
|
|
|
return false;
|
|
|
|
|
2015-01-14 09:27:48 +01:00
|
|
|
// email links are stored separately
|
|
|
|
$links = $event['links'];
|
|
|
|
unset($event['links']);
|
|
|
|
|
2015-02-27 17:52:17 +01:00
|
|
|
$object = $this->_from_driver_event($event, $old);
|
2016-02-22 15:19:58 +01:00
|
|
|
$saved = $this->storage->save($object, 'event', $old['uid']);
|
2011-08-01 20:39:11 +02:00
|
|
|
|
2012-08-03 15:20:41 +02:00
|
|
|
if (!$saved) {
|
2012-11-06 11:46:15 +01:00
|
|
|
rcube::raise_error(array(
|
2011-06-29 15:36:39 +02:00
|
|
|
'code' => 600, 'type' => 'php',
|
|
|
|
'file' => __FILE__, 'line' => __LINE__,
|
2012-08-03 15:20:41 +02:00
|
|
|
'message' => "Error saving event object to Kolab server"),
|
2011-06-29 15:36:39 +02:00
|
|
|
true, false);
|
|
|
|
}
|
|
|
|
else {
|
2015-01-14 09:27:48 +01:00
|
|
|
// save links in configuration.relation object
|
2016-02-22 15:19:58 +01:00
|
|
|
if ($this->save_links($event['uid'], $links)) {
|
|
|
|
$object['links'] = $links;
|
|
|
|
}
|
2015-01-14 09:27:48 +01:00
|
|
|
|
2011-06-29 15:36:39 +02:00
|
|
|
$updated = true;
|
2015-02-27 17:52:17 +01:00
|
|
|
$this->events = array($event['uid'] => $this->_to_driver_event($object, true));
|
2013-01-23 14:45:41 +01:00
|
|
|
|
|
|
|
// refresh local cache with recurring instances
|
|
|
|
if ($exception_id) {
|
2015-02-02 13:12:56 +01:00
|
|
|
$this->get_recurring_events($object, $event['start'], $event['end'], $exception_id);
|
2013-01-23 14:45:41 +01:00
|
|
|
}
|
2011-06-29 15:36:39 +02:00
|
|
|
}
|
|
|
|
|
2011-06-13 16:36:46 +03:00
|
|
|
return $updated;
|
|
|
|
}
|
|
|
|
|
2011-06-29 15:36:39 +02:00
|
|
|
/**
|
|
|
|
* Delete an event record
|
|
|
|
*
|
2011-07-27 16:06:06 +02:00
|
|
|
* @see calendar_driver::remove_event()
|
2011-06-29 15:36:39 +02:00
|
|
|
* @return boolean True on success, False on error
|
|
|
|
*/
|
2011-07-18 15:28:57 +02:00
|
|
|
public function delete_event($event, $force = true)
|
2011-06-13 16:36:46 +03:00
|
|
|
{
|
2015-02-26 16:25:51 +01:00
|
|
|
$deleted = $this->storage->delete($event['uid'] ?: $event['id'], $force);
|
2011-07-18 15:28:57 +02:00
|
|
|
|
2012-08-03 15:20:41 +02:00
|
|
|
if (!$deleted) {
|
2012-11-06 11:46:15 +01:00
|
|
|
rcube::raise_error(array(
|
2011-06-29 15:36:39 +02:00
|
|
|
'code' => 600, 'type' => 'php',
|
|
|
|
'file' => __FILE__, 'line' => __LINE__,
|
2015-02-26 16:25:51 +01:00
|
|
|
'message' => sprintf("Error deleting event object '%s' from Kolab server", $event['id'])),
|
2011-06-29 15:36:39 +02:00
|
|
|
true, false);
|
|
|
|
}
|
2011-07-18 15:28:57 +02:00
|
|
|
|
2011-06-14 14:52:20 +03:00
|
|
|
return $deleted;
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
|
|
|
|
2011-07-18 15:28:57 +02:00
|
|
|
/**
|
|
|
|
* Restore deleted event record
|
|
|
|
*
|
2011-07-27 16:06:06 +02:00
|
|
|
* @see calendar_driver::undelete_event()
|
2011-07-18 15:28:57 +02:00
|
|
|
* @return boolean True on success, False on error
|
|
|
|
*/
|
|
|
|
public function restore_event($event)
|
|
|
|
{
|
2012-05-10 21:24:48 +02:00
|
|
|
if ($this->storage->undelete($event['id'])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
2012-11-06 11:46:15 +01:00
|
|
|
rcube::raise_error(array(
|
2012-05-10 21:24:48 +02:00
|
|
|
'code' => 600, 'type' => 'php',
|
|
|
|
'file' => __FILE__, 'line' => __LINE__,
|
2013-05-08 08:55:58 +02:00
|
|
|
'message' => "Error undeleting the event object $event[id] from the Kolab server"),
|
2012-05-10 21:24:48 +02:00
|
|
|
true, false);
|
|
|
|
}
|
|
|
|
|
2012-04-04 13:01:59 +02:00
|
|
|
return false;
|
2011-07-18 15:28:57 +02:00
|
|
|
}
|
2011-05-20 19:04:25 +02:00
|
|
|
|
2015-01-14 09:27:48 +01:00
|
|
|
/**
|
|
|
|
* Find messages linked with an event
|
|
|
|
*/
|
|
|
|
protected function get_links($uid)
|
|
|
|
{
|
|
|
|
$storage = kolab_storage_config::get_instance();
|
|
|
|
return $storage->get_object_links($uid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
protected function save_links($uid, $links)
|
|
|
|
{
|
|
|
|
$storage = kolab_storage_config::get_instance();
|
2016-02-13 13:09:59 +01:00
|
|
|
return $storage->save_object_links($uid, (array) $links);
|
2015-01-14 09:27:48 +01:00
|
|
|
}
|
2011-06-29 19:42:56 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create instances of a recurring event
|
2013-01-09 11:49:12 +01:00
|
|
|
*
|
|
|
|
* @param array Hash array with event properties
|
|
|
|
* @param object DateTime Start date of the recurrence window
|
|
|
|
* @param object DateTime End date of the recurrence window
|
|
|
|
* @param string ID of a specific recurring event instance
|
|
|
|
* @return array List of recurring event instances
|
2011-06-29 19:42:56 +02:00
|
|
|
*/
|
2015-02-02 13:12:56 +01:00
|
|
|
public function get_recurring_events($event, $start, $end = null, $event_id = null)
|
2011-06-29 19:42:56 +02:00
|
|
|
{
|
2012-10-23 15:05:38 +02:00
|
|
|
$object = $event['_formatobj'];
|
|
|
|
if (!$object) {
|
|
|
|
$rec = $this->storage->get_object($event['id']);
|
|
|
|
$object = $rec['_formatobj'];
|
|
|
|
}
|
|
|
|
if (!is_object($object))
|
|
|
|
return array();
|
|
|
|
|
2013-01-09 11:49:12 +01:00
|
|
|
// determine a reasonable end date if none given
|
|
|
|
if (!$end) {
|
|
|
|
switch ($event['recurrence']['FREQ']) {
|
|
|
|
case 'YEARLY': $intvl = 'P100Y'; break;
|
|
|
|
case 'MONTHLY': $intvl = 'P20Y'; break;
|
|
|
|
default: $intvl = 'P10Y'; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$end = clone $event['start'];
|
|
|
|
$end->add(new DateInterval($intvl));
|
|
|
|
}
|
|
|
|
|
2015-02-12 10:08:22 +01:00
|
|
|
// copy the recurrence rule from the master event (to be used in the UI)
|
|
|
|
$recurrence_rule = $event['recurrence'];
|
|
|
|
unset($recurrence_rule['EXCEPTIONS'], $recurrence_rule['EXDATE']);
|
|
|
|
|
|
|
|
// read recurrence exceptions first
|
2013-01-23 14:45:41 +01:00
|
|
|
$events = array();
|
2015-02-12 10:08:22 +01:00
|
|
|
$exdata = array();
|
2013-02-14 16:17:02 +01:00
|
|
|
$futuredata = array();
|
2015-03-10 14:30:50 +01:00
|
|
|
$recurrence_id_format = libcalendaring::recurrence_id_format($event);
|
2013-02-14 16:17:02 +01:00
|
|
|
|
2015-02-12 10:08:22 +01:00
|
|
|
if (is_array($event['recurrence']['EXCEPTIONS'])) {
|
2013-02-14 16:17:02 +01:00
|
|
|
foreach ($event['recurrence']['EXCEPTIONS'] as $exception) {
|
2015-03-10 14:30:50 +01:00
|
|
|
if (!$exception['_instance'])
|
|
|
|
$exception['_instance'] = libcalendaring::recurrence_instance_identifier($exception);
|
2015-02-12 10:08:22 +01:00
|
|
|
|
2016-02-21 19:09:04 +01:00
|
|
|
$rec_event = $this->_to_driver_event($exception, false, false);
|
2015-02-12 10:08:22 +01:00
|
|
|
$rec_event['id'] = $event['uid'] . '-' . $exception['_instance'];
|
2013-04-17 09:15:34 +02:00
|
|
|
$rec_event['isexception'] = 1;
|
2013-01-23 17:17:05 +01:00
|
|
|
|
2015-02-17 11:36:01 +01:00
|
|
|
// found the specifically requested instance: register exception (single occurrence wins)
|
|
|
|
if ($rec_event['id'] == $event_id && (!$this->events[$event_id] || $this->events[$event_id]['thisandfuture'])) {
|
2015-02-12 10:08:22 +01:00
|
|
|
$rec_event['recurrence'] = $recurrence_rule;
|
|
|
|
$rec_event['recurrence_id'] = $event['uid'];
|
2013-02-14 16:17:02 +01:00
|
|
|
$this->events[$rec_event['id']] = $rec_event;
|
2013-01-23 14:45:41 +01:00
|
|
|
}
|
2013-02-14 16:17:02 +01:00
|
|
|
|
|
|
|
// remember this exception's date
|
2015-02-12 10:08:22 +01:00
|
|
|
$exdate = substr($exception['_instance'], 0, 8);
|
2015-02-17 11:36:01 +01:00
|
|
|
if (!$exdata[$exdate] || $exdata[$exdate]['thisandfuture']) {
|
|
|
|
$exdata[$exdate] = $rec_event;
|
|
|
|
}
|
2013-02-14 16:17:02 +01:00
|
|
|
if ($rec_event['thisandfuture']) {
|
|
|
|
$futuredata[$exdate] = $rec_event;
|
|
|
|
}
|
|
|
|
}
|
2013-01-23 14:45:41 +01:00
|
|
|
}
|
|
|
|
|
2015-02-17 11:36:01 +01:00
|
|
|
// found the specifically requested instance, exiting...
|
|
|
|
if ($event_id && !empty($this->events[$event_id])) {
|
|
|
|
return array($this->events[$event_id]);
|
|
|
|
}
|
|
|
|
|
2013-01-09 11:49:12 +01:00
|
|
|
// use libkolab to compute recurring events
|
2013-01-23 11:36:55 +01:00
|
|
|
if (class_exists('kolabcalendaring')) {
|
|
|
|
$recurrence = new kolab_date_recurrence($object);
|
|
|
|
}
|
|
|
|
else {
|
2013-02-14 16:17:02 +01:00
|
|
|
// fallback to local recurrence implementation
|
|
|
|
require_once($this->cal->home . '/lib/calendar_recurrence.php');
|
|
|
|
$recurrence = new calendar_recurrence($this->cal, $event);
|
2013-01-23 11:36:55 +01:00
|
|
|
}
|
2012-07-06 17:15:45 +02:00
|
|
|
|
2015-02-12 10:08:22 +01:00
|
|
|
$i = 0;
|
2012-07-06 17:15:45 +02:00
|
|
|
while ($next_event = $recurrence->next_instance()) {
|
2015-02-12 10:08:22 +01:00
|
|
|
$datestr = $next_event['start']->format('Ymd');
|
|
|
|
$instance_id = $next_event['start']->format($recurrence_id_format);
|
|
|
|
|
|
|
|
// use this event data for future recurring instances
|
|
|
|
if ($futuredata[$datestr])
|
|
|
|
$overlay_data = $futuredata[$datestr];
|
2012-07-06 17:15:45 +02:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
// add to output if in range
|
2015-02-12 10:08:22 +01:00
|
|
|
$rec_id = $event['uid'] . '-' . $instance_id;
|
2012-07-06 17:15:45 +02:00
|
|
|
if (($next_event['start'] <= $end && $next_event['end'] >= $start) || ($event_id && $rec_id == $event_id)) {
|
2016-02-21 19:09:04 +01:00
|
|
|
$rec_event = $this->_to_driver_event($next_event, false, false);
|
2015-02-12 10:08:22 +01:00
|
|
|
$rec_event['_instance'] = $instance_id;
|
2015-02-20 00:11:40 +01:00
|
|
|
$rec_event['_count'] = $i + 1;
|
2013-02-14 16:17:02 +01:00
|
|
|
|
2015-02-12 10:08:22 +01:00
|
|
|
if ($overlay_data || $exdata[$datestr]) // copy data from exception
|
2015-02-17 15:49:14 +01:00
|
|
|
kolab_driver::merge_exception_data($rec_event, $exdata[$datestr] ?: $overlay_data);
|
2013-02-14 16:17:02 +01:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
$rec_event['id'] = $rec_id;
|
2012-07-06 17:15:45 +02:00
|
|
|
$rec_event['recurrence_id'] = $event['uid'];
|
2015-02-12 10:08:22 +01:00
|
|
|
$rec_event['recurrence'] = $recurrence_rule;
|
2012-07-06 17:15:45 +02:00
|
|
|
unset($rec_event['_attendees']);
|
2011-06-29 19:42:56 +02:00
|
|
|
$events[] = $rec_event;
|
2012-07-06 17:15:45 +02:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
if ($rec_id == $event_id) {
|
|
|
|
$this->events[$rec_id] = $rec_event;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-07-06 17:15:45 +02:00
|
|
|
else if ($next_event['start'] > $end) // stop loop if out of range
|
2011-06-29 19:42:56 +02:00
|
|
|
break;
|
2012-11-09 13:55:57 +01:00
|
|
|
|
2013-01-09 11:12:19 +01:00
|
|
|
// avoid endless recursion loops
|
2015-02-12 10:08:22 +01:00
|
|
|
if (++$i > 1000)
|
2013-01-09 11:12:19 +01:00
|
|
|
break;
|
2011-06-29 19:42:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $events;
|
|
|
|
}
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
/**
|
|
|
|
* Convert from Kolab_Format to internal representation
|
|
|
|
*/
|
2016-02-21 19:09:04 +01:00
|
|
|
private function _to_driver_event($record, $noinst = false, $links = true)
|
2011-05-20 19:04:25 +02:00
|
|
|
{
|
2012-03-30 19:14:38 +02:00
|
|
|
$record['calendar'] = $this->id;
|
2016-02-21 19:09:04 +01:00
|
|
|
|
2016-02-22 15:19:58 +01:00
|
|
|
if ($links && !array_key_exists('links', $record)) {
|
2016-02-21 19:09:04 +01:00
|
|
|
$record['links'] = $this->get_links($record['uid']);
|
|
|
|
}
|
2012-03-30 19:14:38 +02:00
|
|
|
|
2015-01-21 17:05:16 +01:00
|
|
|
if ($this->get_namespace() == 'other') {
|
|
|
|
$record['className'] = 'fc-event-ns-other';
|
|
|
|
$record = kolab_driver::add_partstat_class($record, array('NEEDS-ACTION','DECLINED'), $this->get_owner());
|
|
|
|
}
|
|
|
|
|
2015-02-27 17:52:17 +01:00
|
|
|
// add instance identifier to first occurrence (master event)
|
2015-03-10 14:30:50 +01:00
|
|
|
$recurrence_id_format = libcalendaring::recurrence_id_format($record);
|
2015-02-27 17:52:17 +01:00
|
|
|
if (!$noinst && $record['recurrence'] && !$record['recurrence_id'] && !$record['_instance']) {
|
|
|
|
$record['_instance'] = $record['start']->format($recurrence_id_format);
|
|
|
|
}
|
|
|
|
else if (is_a($record['recurrence_date'], 'DateTime')) {
|
|
|
|
$record['_instance'] = $record['recurrence_date']->format($recurrence_id_format);
|
|
|
|
}
|
|
|
|
|
|
|
|
// clean up exception data
|
|
|
|
if ($record['recurrence'] && is_array($record['recurrence']['EXCEPTIONS'])) {
|
|
|
|
array_walk($record['recurrence']['EXCEPTIONS'], function(&$exception) {
|
|
|
|
unset($exception['_mailbox'], $exception['_msguid'], $exception['_formatobj'], $exception['_attachments']);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return $record;
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
|
|
|
|
2011-06-18 09:05:48 +03:00
|
|
|
/**
|
2011-05-20 19:04:25 +02:00
|
|
|
* Convert the given event record into a data structure that can be passed to Kolab_Storage backend for saving
|
2015-02-27 17:52:17 +01:00
|
|
|
* (opposite of self::_to_driver_event())
|
2011-05-20 19:04:25 +02:00
|
|
|
*/
|
2015-02-27 17:52:17 +01:00
|
|
|
private function _from_driver_event($event, $old = array())
|
2011-05-20 19:04:25 +02:00
|
|
|
{
|
2012-03-30 19:14:38 +02:00
|
|
|
// set current user as ORGANIZER
|
2014-11-27 06:33:05 -05:00
|
|
|
$identity = $this->cal->rc->user->list_emails(true);
|
2012-04-03 23:08:24 +02:00
|
|
|
if (empty($event['attendees']) && $identity['email'])
|
2012-03-30 19:14:38 +02:00
|
|
|
$event['attendees'] = array(array('role' => 'ORGANIZER', 'name' => $identity['name'], 'email' => $identity['email']));
|
|
|
|
|
2012-04-03 23:08:24 +02:00
|
|
|
$event['_owner'] = $identity['email'];
|
|
|
|
|
2014-03-17 14:28:25 +01:00
|
|
|
// remove EXDATE values if RDATE is given
|
2014-03-17 12:40:21 +01:00
|
|
|
if (!empty($event['recurrence']['RDATE'])) {
|
|
|
|
$event['recurrence']['EXDATE'] = array();
|
2014-02-28 16:51:55 +01:00
|
|
|
}
|
|
|
|
|
2014-03-17 14:28:25 +01:00
|
|
|
// remove recurrence information (e.g. EXDATES and EXCEPTIONS) entirely
|
|
|
|
if ($event['recurrence'] && empty($event['recurrence']['FREQ']) && empty($event['recurrence']['RDATE'])) {
|
|
|
|
$event['recurrence'] = array();
|
|
|
|
}
|
|
|
|
|
2014-08-01 10:28:05 +02:00
|
|
|
// keep 'comment' from initial itip invitation
|
|
|
|
if (!empty($old['comment'])) {
|
|
|
|
$event['comment'] = $old['comment'];
|
|
|
|
}
|
|
|
|
|
2015-02-27 17:52:17 +01:00
|
|
|
// clean up exception data
|
|
|
|
if (is_array($event['exceptions'])) {
|
|
|
|
array_walk($event['exceptions'], function(&$exception) {
|
|
|
|
unset($exception['_mailbox'], $exception['_msguid'], $exception['_formatobj'], $exception['_attachments'],
|
|
|
|
$event['attachments'], $event['deleted_attachments'], $event['recurrence_id']);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-17 09:19:26 +02:00
|
|
|
// remove some internal properties which should not be saved
|
2015-02-27 17:52:17 +01:00
|
|
|
unset($event['_savemode'], $event['_fromcalendar'], $event['_identity'], $event['_folder_id'],
|
|
|
|
$event['recurrence_id'], $event['attachments'], $event['deleted_attachments'], $event['className']);
|
2013-04-17 09:19:26 +02:00
|
|
|
|
2012-03-30 19:14:38 +02:00
|
|
|
// copy meta data (starting with _) from old object
|
|
|
|
foreach ((array)$old as $key => $val) {
|
|
|
|
if (!isset($event[$key]) && $key[0] == '_')
|
|
|
|
$event[$key] = $val;
|
2011-07-08 17:29:22 +02:00
|
|
|
}
|
2011-07-01 21:08:12 +02:00
|
|
|
|
2012-03-30 19:14:38 +02:00
|
|
|
return $event;
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
|
|
|
|
2015-02-05 19:37:03 +01:00
|
|
|
/**
|
|
|
|
* Match the given word in the event contents
|
|
|
|
*/
|
2015-02-24 17:36:04 +01:00
|
|
|
public function fulltext_match($event, $word, $recursive = true)
|
2015-02-05 19:37:03 +01:00
|
|
|
{
|
|
|
|
$hits = 0;
|
|
|
|
foreach ($this->search_fields as $col) {
|
|
|
|
$sval = is_array($event[$col]) ? self::_complex2string($event[$col]) : $event[$col];
|
|
|
|
if (empty($sval))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// do a simple substring matching (to be improved)
|
|
|
|
$val = mb_strtolower($sval);
|
|
|
|
if (strpos($val, $word) !== false) {
|
|
|
|
$hits++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $hits;
|
|
|
|
}
|
|
|
|
|
2013-05-01 09:12:35 +02:00
|
|
|
/**
|
|
|
|
* Convert a complex event attribute to a string value
|
|
|
|
*/
|
|
|
|
private static function _complex2string($prop)
|
|
|
|
{
|
|
|
|
static $ignorekeys = array('role','status','rsvp');
|
|
|
|
|
|
|
|
$out = '';
|
|
|
|
if (is_array($prop)) {
|
|
|
|
foreach ($prop as $key => $val) {
|
|
|
|
if (is_numeric($key)) {
|
2013-05-08 08:55:58 +02:00
|
|
|
$out .= self::_complex2string($val);
|
2013-05-01 09:12:35 +02:00
|
|
|
}
|
|
|
|
else if (!in_array($key, $ignorekeys)) {
|
|
|
|
$out .= $val . ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (is_string($prop) || is_numeric($prop)) {
|
|
|
|
$out .= $prop . ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
return rtrim($out);
|
|
|
|
}
|
2011-06-14 14:52:20 +03:00
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|