2011-05-20 19:04:25 +02:00
|
|
|
<?php
|
2011-08-21 12:48:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Kolab driver for the Calendar plugin
|
|
|
|
*
|
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
|
|
|
|
|
|
|
class kolab_driver extends calendar_driver
|
|
|
|
{
|
2014-07-08 12:36:34 +02:00
|
|
|
const INVITATIONS_CALENDAR_PENDING = '--invitation--pending';
|
|
|
|
const INVITATIONS_CALENDAR_DECLINED = '--invitation--declined';
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
// features this backend supports
|
2011-05-22 17:29:09 +02:00
|
|
|
public $alarms = true;
|
2011-07-14 12:38:10 +02:00
|
|
|
public $attendees = true;
|
2011-07-27 10:48:40 +02:00
|
|
|
public $freebusy = true;
|
2011-07-01 21:08:12 +02:00
|
|
|
public $attachments = true;
|
2011-07-18 15:28:57 +02:00
|
|
|
public $undelete = true;
|
2014-04-17 17:49:00 +02:00
|
|
|
public $alarm_types = array('DISPLAY','AUDIO');
|
2011-05-26 15:44:46 +02:00
|
|
|
public $categoriesimmutable = true;
|
2011-05-20 19:04:25 +02:00
|
|
|
|
|
|
|
private $rc;
|
|
|
|
private $cal;
|
|
|
|
private $calendars;
|
2011-08-06 17:51:08 +02:00
|
|
|
private $has_writeable = false;
|
2012-09-19 11:17:15 +02:00
|
|
|
private $freebusy_trigger = false;
|
2014-07-29 15:28:35 +02:00
|
|
|
private $bonnie_api = false;
|
2011-05-20 19:04:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
*/
|
|
|
|
public function __construct($cal)
|
|
|
|
{
|
2014-03-10 14:45:24 +01:00
|
|
|
$cal->require_plugin('libkolab');
|
|
|
|
|
2014-08-07 17:41:17 +02:00
|
|
|
// load helper classes *after* libkolab has been loaded (#3248)
|
|
|
|
require_once(dirname(__FILE__) . '/kolab_calendar.php');
|
|
|
|
require_once(dirname(__FILE__) . '/kolab_user_calendar.php');
|
|
|
|
require_once(dirname(__FILE__) . '/kolab_invitation_calendar.php');
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
$this->cal = $cal;
|
2016-02-12 16:27:19 +01:00
|
|
|
$this->rc = $cal->rc;
|
|
|
|
|
2011-07-16 17:14:36 +02:00
|
|
|
$this->cal->register_action('push-freebusy', array($this, 'push_freebusy'));
|
2011-08-30 00:17:06 +02:00
|
|
|
$this->cal->register_action('calendar-acl', array($this, 'calendar_acl'));
|
2016-02-12 16:27:19 +01:00
|
|
|
|
2012-09-19 11:17:15 +02:00
|
|
|
$this->freebusy_trigger = $this->rc->config->get('calendar_freebusy_trigger', false);
|
2012-11-15 15:03:00 +01:00
|
|
|
|
2012-11-22 15:19:17 +01:00
|
|
|
if (kolab_storage::$version == '2.0') {
|
2012-11-15 15:03:00 +01:00
|
|
|
$this->alarm_types = array('DISPLAY');
|
|
|
|
$this->alarm_absolute = false;
|
|
|
|
}
|
2014-05-13 17:09:53 +02:00
|
|
|
|
2014-07-29 15:28:35 +02:00
|
|
|
// get configuration for the Bonnie API
|
2015-04-20 17:20:39 +02:00
|
|
|
$this->bonnie_api = libkolab::get_bonnie_api();
|
2014-07-29 15:28:35 +02:00
|
|
|
|
2014-05-13 17:09:53 +02:00
|
|
|
// calendar uses fully encoded identifiers
|
|
|
|
kolab_storage::$encode_ids = true;
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read available calendars from server
|
|
|
|
*/
|
|
|
|
private function _read_calendars()
|
|
|
|
{
|
|
|
|
// already read sources
|
|
|
|
if (isset($this->calendars))
|
2011-06-28 10:32:52 +02:00
|
|
|
return $this->calendars;
|
2011-05-20 19:04:25 +02:00
|
|
|
|
2013-07-18 17:47:49 +02:00
|
|
|
// get all folders that have "event" type, sorted by namespace/name
|
2014-05-23 09:00:46 +02:00
|
|
|
$folders = kolab_storage::sort_folders(kolab_storage::get_folders('event') + kolab_storage::get_user_folders('event', true));
|
2011-05-20 19:04:25 +02:00
|
|
|
|
2016-02-12 16:27:19 +01:00
|
|
|
$this->calendars = array();
|
2013-07-18 17:47:49 +02:00
|
|
|
foreach ($folders as $folder) {
|
2014-09-08 18:56:23 +02:00
|
|
|
if ($folder instanceof kolab_storage_folder_user) {
|
2014-05-14 20:37:06 +02:00
|
|
|
$calendar = new kolab_user_calendar($folder->name, $this->cal);
|
2014-09-08 18:56:23 +02:00
|
|
|
$calendar->subscriptions = count($folder->children) > 0;
|
|
|
|
}
|
|
|
|
else {
|
2014-05-14 20:37:06 +02:00
|
|
|
$calendar = new kolab_calendar($folder->name, $this->cal);
|
2014-09-08 18:56:23 +02:00
|
|
|
}
|
2014-05-14 20:37:06 +02:00
|
|
|
|
|
|
|
if ($calendar->ready) {
|
|
|
|
$this->calendars[$calendar->id] = $calendar;
|
2015-03-11 15:24:17 +01:00
|
|
|
if ($calendar->editable)
|
2014-05-14 20:37:06 +02:00
|
|
|
$this->has_writeable = true;
|
|
|
|
}
|
2011-06-28 10:32:52 +02:00
|
|
|
}
|
2011-05-20 19:04:25 +02:00
|
|
|
|
2011-06-28 10:32:52 +02:00
|
|
|
return $this->calendars;
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of available calendars from this source
|
2012-12-04 20:10:04 +01:00
|
|
|
*
|
2015-03-10 15:23:52 +01:00
|
|
|
* @param integer $filter Bitmask defining filter criterias
|
2014-05-12 20:47:47 +02:00
|
|
|
* @param object $tree Reference to hierarchical folder tree object
|
2012-12-04 20:10:04 +01:00
|
|
|
*
|
|
|
|
* @return array List of calendars
|
2011-05-20 19:04:25 +02:00
|
|
|
*/
|
2015-03-10 15:23:52 +01:00
|
|
|
public function list_calendars($filter = 0, &$tree = null)
|
2011-05-20 19:04:25 +02:00
|
|
|
{
|
2016-02-12 16:27:19 +01:00
|
|
|
$this->_read_calendars();
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
// attempt to create a default calendar for this user
|
2011-08-06 17:51:08 +02:00
|
|
|
if (!$this->has_writeable) {
|
|
|
|
if ($this->create_calendar(array('name' => 'Calendar', 'color' => 'cc0000'))) {
|
2016-02-12 16:27:19 +01:00
|
|
|
unset($this->calendars);
|
2011-05-20 19:04:25 +02:00
|
|
|
$this->_read_calendars();
|
2011-08-06 17:51:08 +02:00
|
|
|
}
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
2011-06-27 15:49:51 +02:00
|
|
|
|
2014-05-21 10:50:36 +02:00
|
|
|
$delim = $this->rc->get_storage()->get_hierarchy_delimiter();
|
2015-03-10 15:23:52 +01:00
|
|
|
$folders = $this->filter_calendars($filter);
|
2014-05-21 10:50:36 +02:00
|
|
|
$calendars = array();
|
2013-10-10 17:27:24 +02:00
|
|
|
|
|
|
|
// include virtual folders for a full folder tree
|
2014-05-14 20:37:06 +02:00
|
|
|
if (!is_null($tree))
|
2014-05-12 20:47:47 +02:00
|
|
|
$folders = kolab_storage::folder_hierarchy($folders, $tree);
|
2013-10-10 17:27:24 +02:00
|
|
|
|
|
|
|
foreach ($folders as $id => $cal) {
|
|
|
|
$fullname = $cal->get_name();
|
2014-05-14 20:37:06 +02:00
|
|
|
$listname = $cal->get_foldername();
|
2014-05-21 10:50:36 +02:00
|
|
|
$imap_path = explode($delim, $cal->name);
|
2014-05-16 10:59:28 +02:00
|
|
|
|
|
|
|
// find parent
|
|
|
|
do {
|
|
|
|
array_pop($imap_path);
|
2014-05-21 10:50:36 +02:00
|
|
|
$parent_id = kolab_storage::folder_id(join($delim, $imap_path));
|
|
|
|
}
|
|
|
|
while (count($imap_path) > 1 && !$this->calendars[$parent_id]);
|
2013-10-10 17:27:24 +02:00
|
|
|
|
2014-05-21 10:50:36 +02:00
|
|
|
// restore "real" parent ID
|
|
|
|
if ($parent_id && !$this->calendars[$parent_id]) {
|
|
|
|
$parent_id = kolab_storage::folder_id($cal->get_parent());
|
2014-05-16 10:59:28 +02:00
|
|
|
}
|
2014-05-15 11:57:54 +02:00
|
|
|
|
|
|
|
// turn a kolab_storage_folder object into a kolab_calendar
|
|
|
|
if ($cal instanceof kolab_storage_folder) {
|
|
|
|
$cal = new kolab_calendar($cal->name, $this->cal);
|
|
|
|
$this->calendars[$cal->id] = $cal;
|
|
|
|
}
|
2013-10-10 17:27:24 +02:00
|
|
|
|
2014-05-14 20:37:06 +02:00
|
|
|
// special handling for user or virtual folders
|
2014-05-15 13:15:58 +02:00
|
|
|
if ($cal instanceof kolab_storage_folder_user) {
|
2014-05-14 20:37:06 +02:00
|
|
|
$calendars[$cal->id] = array(
|
2016-02-12 13:45:58 +01:00
|
|
|
'id' => $cal->id,
|
|
|
|
'name' => $fullname,
|
2014-05-14 20:37:06 +02:00
|
|
|
'listname' => $listname,
|
|
|
|
'editname' => $cal->get_foldername(),
|
|
|
|
'color' => $cal->get_color(),
|
|
|
|
'active' => $cal->is_active(),
|
2014-05-20 09:50:41 +02:00
|
|
|
'title' => $cal->get_owner(),
|
2014-05-14 20:37:06 +02:00
|
|
|
'owner' => $cal->get_owner(),
|
2014-07-29 15:28:35 +02:00
|
|
|
'history' => false,
|
2014-05-15 11:57:54 +02:00
|
|
|
'virtual' => false,
|
2015-03-11 15:24:17 +01:00
|
|
|
'editable' => false,
|
2015-03-11 12:22:01 +01:00
|
|
|
'group' => 'other',
|
|
|
|
'class' => 'user',
|
2014-09-09 13:29:28 +02:00
|
|
|
'removable' => true,
|
2014-05-14 20:37:06 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else if ($cal->virtual) {
|
2013-10-10 17:27:24 +02:00
|
|
|
$calendars[$cal->id] = array(
|
|
|
|
'id' => $cal->id,
|
2013-10-16 16:35:56 +02:00
|
|
|
'name' => $fullname,
|
|
|
|
'listname' => $listname,
|
2014-05-12 20:47:47 +02:00
|
|
|
'editname' => $cal->get_foldername(),
|
2015-03-11 12:22:01 +01:00
|
|
|
'virtual' => true,
|
2015-03-11 15:24:17 +01:00
|
|
|
'editable' => false,
|
2015-03-11 12:22:01 +01:00
|
|
|
'group' => $cal->get_namespace(),
|
|
|
|
'class' => 'folder',
|
2013-10-10 17:27:24 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$calendars[$cal->id] = array(
|
|
|
|
'id' => $cal->id,
|
2013-10-16 16:35:56 +02:00
|
|
|
'name' => $fullname,
|
|
|
|
'listname' => $listname,
|
2013-10-10 17:27:24 +02:00
|
|
|
'editname' => $cal->get_foldername(),
|
2014-05-20 09:50:41 +02:00
|
|
|
'title' => $cal->get_title(),
|
2013-10-10 17:27:24 +02:00
|
|
|
'color' => $cal->get_color(),
|
2015-03-11 15:24:17 +01:00
|
|
|
'editable' => $cal->editable,
|
|
|
|
'rights' => $cal->rights,
|
2013-10-10 17:27:24 +02:00
|
|
|
'showalarms' => $cal->alarms,
|
2014-07-29 15:28:35 +02:00
|
|
|
'history' => !empty($this->bonnie_api),
|
2014-05-15 17:20:58 +02:00
|
|
|
'group' => $cal->get_namespace(),
|
2014-05-15 13:15:58 +02:00
|
|
|
'default' => $cal->default,
|
|
|
|
'active' => $cal->is_active(),
|
2013-10-10 17:27:24 +02:00
|
|
|
'owner' => $cal->get_owner(),
|
|
|
|
'children' => true, // TODO: determine if that folder indeed has child folders
|
2014-05-13 17:09:53 +02:00
|
|
|
'parent' => $parent_id,
|
2014-09-23 12:27:57 +02:00
|
|
|
'subtype' => $cal->subtype,
|
2013-10-10 17:27:24 +02:00
|
|
|
'caldavurl' => $cal->get_caldav_url(),
|
2014-09-09 13:33:09 +02:00
|
|
|
'removable' => !$cal->default,
|
2013-10-10 17:27:24 +02:00
|
|
|
);
|
|
|
|
}
|
2014-05-15 15:53:35 +02:00
|
|
|
|
|
|
|
if ($cal->subscriptions) {
|
2014-09-08 18:56:23 +02:00
|
|
|
$calendars[$cal->id]['subscribed'] = $cal->is_subscribed();
|
2014-05-15 15:53:35 +02:00
|
|
|
}
|
2011-06-28 10:32:52 +02:00
|
|
|
}
|
|
|
|
|
2014-07-08 12:36:34 +02:00
|
|
|
// list virtual calendars showing invitations
|
|
|
|
if ($this->rc->config->get('kolab_invitation_calendars')) {
|
|
|
|
foreach (array(self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED) as $id) {
|
|
|
|
$cal = new kolab_invitation_calendar($id, $this->cal);
|
|
|
|
$this->calendars[$cal->id] = $cal;
|
2015-03-10 15:23:52 +01:00
|
|
|
if (!($filter & self::FILTER_ACTIVE) || $cal->is_active()) {
|
2014-07-08 12:36:34 +02:00
|
|
|
$calendars[$id] = array(
|
|
|
|
'id' => $cal->id,
|
|
|
|
'name' => $cal->get_name(),
|
|
|
|
'listname' => $cal->get_name(),
|
|
|
|
'editname' => $cal->get_foldername(),
|
|
|
|
'title' => $cal->get_title(),
|
|
|
|
'color' => $cal->get_color(),
|
2015-03-11 15:24:17 +01:00
|
|
|
'editable' => $cal->editable,
|
|
|
|
'rights' => $cal->rights,
|
2014-07-08 12:36:34 +02:00
|
|
|
'showalarms' => $cal->alarms,
|
2014-07-29 15:28:35 +02:00
|
|
|
'history' => !empty($this->bonnie_api),
|
2014-07-08 12:36:34 +02:00
|
|
|
'group' => 'x-invitations',
|
|
|
|
'default' => false,
|
|
|
|
'active' => $cal->is_active(),
|
|
|
|
'owner' => $cal->get_owner(),
|
|
|
|
'children' => false,
|
|
|
|
);
|
|
|
|
|
2014-10-14 20:23:52 +02:00
|
|
|
if ($id == self::INVITATIONS_CALENDAR_PENDING) {
|
|
|
|
$calendars[$id]['counts'] = true;
|
|
|
|
}
|
|
|
|
|
2014-07-08 12:36:34 +02:00
|
|
|
if (is_object($tree)) {
|
|
|
|
$tree->children[] = $cal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-27 19:12:29 +01:00
|
|
|
// append the virtual birthdays calendar
|
|
|
|
if ($this->rc->config->get('calendar_contact_birthdays', false)) {
|
|
|
|
$id = self::BIRTHDAY_CALENDAR_ID;
|
|
|
|
$prefs = $this->rc->config->get('kolab_calendars', array()); // read local prefs
|
2015-03-10 15:23:52 +01:00
|
|
|
if (!($filter & self::FILTER_ACTIVE) || $prefs[$id]['active']) {
|
2014-01-27 19:12:29 +01:00
|
|
|
$calendars[$id] = array(
|
|
|
|
'id' => $id,
|
|
|
|
'name' => $this->cal->gettext('birthdays'),
|
|
|
|
'listname' => $this->cal->gettext('birthdays'),
|
2014-08-06 08:52:56 +02:00
|
|
|
'color' => $prefs[$id]['color'] ?: '87CEFA',
|
|
|
|
'active' => (bool)$prefs[$id]['active'],
|
2014-01-28 11:55:06 +01:00
|
|
|
'showalarms' => (bool)$this->rc->config->get('calendar_birthdays_alarm_type'),
|
2014-07-08 12:36:34 +02:00
|
|
|
'group' => 'x-birthdays',
|
2015-03-11 15:24:17 +01:00
|
|
|
'editable' => false,
|
2014-01-27 19:12:29 +01:00
|
|
|
'default' => false,
|
|
|
|
'children' => false,
|
2014-07-29 15:28:35 +02:00
|
|
|
'history' => false,
|
2014-01-27 19:12:29 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-28 10:32:52 +02:00
|
|
|
return $calendars;
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
|
|
|
|
2012-12-04 20:10:04 +01:00
|
|
|
/**
|
|
|
|
* Get list of calendars according to specified filters
|
|
|
|
*
|
2015-03-10 15:23:52 +01:00
|
|
|
* @param integer Bitmask defining restrictions. See FILTER_* constants for possible values.
|
2012-12-04 20:10:04 +01:00
|
|
|
*
|
|
|
|
* @return array List of calendars
|
|
|
|
*/
|
2015-03-10 15:23:52 +01:00
|
|
|
protected function filter_calendars($filter)
|
2012-12-04 20:10:04 +01:00
|
|
|
{
|
2016-02-12 16:27:19 +01:00
|
|
|
$this->_read_calendars();
|
|
|
|
|
2012-12-04 20:10:04 +01:00
|
|
|
$calendars = array();
|
2012-12-13 13:10:07 +01:00
|
|
|
|
|
|
|
$plugin = $this->rc->plugins->exec_hook('calendar_list_filter', array(
|
2015-03-10 15:23:52 +01:00
|
|
|
'list' => $this->calendars,
|
|
|
|
'calendars' => $calendars,
|
|
|
|
'filter' => $filter,
|
2015-03-25 15:09:04 +01:00
|
|
|
'editable' => ($filter & self::FILTER_WRITEABLE),
|
2015-03-11 12:22:01 +01:00
|
|
|
'insert' => ($filter & self::FILTER_INSERTABLE),
|
2015-03-10 15:23:52 +01:00
|
|
|
'active' => ($filter & self::FILTER_ACTIVE),
|
2015-03-25 15:09:04 +01:00
|
|
|
'personal' => ($filter & self::FILTER_PERSONAL)
|
2012-12-13 13:10:07 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
if ($plugin['abort']) {
|
|
|
|
return $plugin['calendars'];
|
|
|
|
}
|
|
|
|
|
2012-12-04 20:10:04 +01:00
|
|
|
foreach ($this->calendars as $cal) {
|
|
|
|
if (!$cal->ready) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-03-11 15:24:17 +01:00
|
|
|
if (($filter & self::FILTER_WRITEABLE) && !$cal->editable) {
|
2015-03-11 12:22:01 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (($filter & self::FILTER_INSERTABLE) && !$cal->insert) {
|
2012-12-04 20:10:04 +01:00
|
|
|
continue;
|
|
|
|
}
|
2015-03-10 15:23:52 +01:00
|
|
|
if (($filter & self::FILTER_ACTIVE) && !$cal->is_active()) {
|
2012-12-04 20:10:04 +01:00
|
|
|
continue;
|
|
|
|
}
|
2015-03-25 15:09:04 +01:00
|
|
|
if (($filter & self::FILTER_PRIVATE) && $cal->subtype != 'private') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (($filter & self::FILTER_CONFIDENTIAL) && $cal->subtype != 'confidential') {
|
|
|
|
continue;
|
|
|
|
}
|
2015-03-10 15:23:52 +01:00
|
|
|
if (($filter & self::FILTER_PERSONAL) && $cal->get_namespace() != 'personal') {
|
2012-12-04 20:10:04 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$calendars[$cal->id] = $cal;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $calendars;
|
|
|
|
}
|
|
|
|
|
2014-05-13 17:09:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the kolab_calendar instance for the given calendar ID
|
|
|
|
*
|
|
|
|
* @param string Calendar identifier (encoded imap folder name)
|
|
|
|
* @return object kolab_calendar Object nor null if calendar doesn't exist
|
|
|
|
*/
|
2014-07-08 12:36:34 +02:00
|
|
|
public function get_calendar($id)
|
2014-05-13 17:09:53 +02:00
|
|
|
{
|
2016-02-12 16:27:19 +01:00
|
|
|
$this->_read_calendars();
|
|
|
|
|
2014-05-13 17:09:53 +02:00
|
|
|
// create calendar object if necesary
|
2014-07-08 12:36:34 +02:00
|
|
|
if (!$this->calendars[$id] && in_array($id, array(self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED))) {
|
|
|
|
$this->calendars[$id] = new kolab_invitation_calendar($id, $this->cal);
|
|
|
|
}
|
|
|
|
else if (!$this->calendars[$id] && $id !== self::BIRTHDAY_CALENDAR_ID) {
|
2014-05-14 20:37:06 +02:00
|
|
|
$calendar = kolab_calendar::factory($id, $this->cal);
|
2014-05-13 17:09:53 +02:00
|
|
|
if ($calendar->ready)
|
|
|
|
$this->calendars[$calendar->id] = $calendar;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->calendars[$id];
|
|
|
|
}
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
/**
|
|
|
|
* Create a new calendar assigned to the current user
|
|
|
|
*
|
|
|
|
* @param array Hash array with calendar properties
|
|
|
|
* name: Calendar name
|
|
|
|
* color: The color of the calendar
|
|
|
|
* @return mixed ID of the calendar on success, False on error
|
|
|
|
*/
|
|
|
|
public function create_calendar($prop)
|
|
|
|
{
|
2012-06-21 09:42:24 +02:00
|
|
|
$prop['type'] = 'event';
|
2013-05-28 13:47:44 +02:00
|
|
|
$prop['active'] = true;
|
|
|
|
$prop['subscribed'] = true;
|
2012-06-21 09:42:24 +02:00
|
|
|
$folder = kolab_storage::folder_update($prop);
|
2011-06-27 15:49:51 +02:00
|
|
|
|
2011-07-26 13:13:04 +02:00
|
|
|
if ($folder === false) {
|
2012-06-21 21:34:08 +02:00
|
|
|
$this->last_error = $this->cal->gettext(kolab_storage::$last_error);
|
2011-07-26 13:13:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
2011-06-27 15:49:51 +02:00
|
|
|
|
|
|
|
// create ID
|
2012-03-30 19:14:38 +02:00
|
|
|
$id = kolab_storage::folder_id($folder);
|
2011-06-27 15:49:51 +02:00
|
|
|
|
2011-07-26 13:13:04 +02:00
|
|
|
// save color in user prefs (temp. solution)
|
|
|
|
$prefs['kolab_calendars'] = $this->rc->config->get('kolab_calendars', array());
|
2011-06-27 15:49:51 +02:00
|
|
|
|
2011-08-26 23:24:49 +02:00
|
|
|
if (isset($prop['color']))
|
|
|
|
$prefs['kolab_calendars'][$id]['color'] = $prop['color'];
|
|
|
|
if (isset($prop['showalarms']))
|
|
|
|
$prefs['kolab_calendars'][$id]['showalarms'] = $prop['showalarms'] ? true : false;
|
|
|
|
|
|
|
|
if ($prefs['kolab_calendars'][$id])
|
|
|
|
$this->rc->user->save_prefs($prefs);
|
2011-06-27 15:49:51 +02:00
|
|
|
|
2011-07-26 13:13:04 +02:00
|
|
|
return $id;
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
|
|
|
|
2011-06-27 15:49:51 +02:00
|
|
|
|
2011-06-08 18:48:06 -06:00
|
|
|
/**
|
|
|
|
* Update properties of an existing calendar
|
|
|
|
*
|
|
|
|
* @see calendar_driver::edit_calendar()
|
|
|
|
*/
|
|
|
|
public function edit_calendar($prop)
|
|
|
|
{
|
2014-05-13 17:09:53 +02:00
|
|
|
if ($prop['id'] && ($cal = $this->get_calendar($prop['id']))) {
|
2014-05-15 11:57:54 +02:00
|
|
|
$id = $cal->update($prop);
|
2014-01-27 19:12:29 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$id = $prop['id'];
|
|
|
|
}
|
2011-07-26 13:13:04 +02:00
|
|
|
|
2014-01-27 19:12:29 +01:00
|
|
|
// fallback to local prefs
|
|
|
|
$prefs['kolab_calendars'] = $this->rc->config->get('kolab_calendars', array());
|
|
|
|
unset($prefs['kolab_calendars'][$prop['id']]['color'], $prefs['kolab_calendars'][$prop['id']]['showalarms']);
|
2011-08-26 23:24:49 +02:00
|
|
|
|
2014-01-27 19:12:29 +01:00
|
|
|
if (isset($prop['color']))
|
|
|
|
$prefs['kolab_calendars'][$id]['color'] = $prop['color'];
|
2014-01-28 11:55:06 +01:00
|
|
|
|
|
|
|
if (isset($prop['showalarms']) && $id == self::BIRTHDAY_CALENDAR_ID)
|
|
|
|
$prefs['calendar_birthdays_alarm_type'] = $prop['showalarms'] ? $this->alarm_types[0] : '';
|
|
|
|
else if (isset($prop['showalarms']))
|
2014-01-27 19:12:29 +01:00
|
|
|
$prefs['kolab_calendars'][$id]['showalarms'] = $prop['showalarms'] ? true : false;
|
2011-08-26 23:24:49 +02:00
|
|
|
|
2014-01-27 19:12:29 +01:00
|
|
|
if (!empty($prefs['kolab_calendars'][$id]))
|
|
|
|
$this->rc->user->save_prefs($prefs);
|
2011-07-26 13:13:04 +02:00
|
|
|
|
2014-01-27 19:12:29 +01:00
|
|
|
return true;
|
2011-08-26 23:24:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set active/subscribed state of a calendar
|
|
|
|
*
|
|
|
|
* @see calendar_driver::subscribe_calendar()
|
|
|
|
*/
|
|
|
|
public function subscribe_calendar($prop)
|
|
|
|
{
|
2014-07-08 12:36:34 +02:00
|
|
|
if ($prop['id'] && ($cal = $this->get_calendar($prop['id'])) && is_object($cal->storage)) {
|
2014-05-15 15:53:35 +02:00
|
|
|
$ret = false;
|
|
|
|
if (isset($prop['permanent']))
|
2014-05-21 10:50:36 +02:00
|
|
|
$ret |= $cal->storage->subscribe(intval($prop['permanent']));
|
2014-05-15 15:53:35 +02:00
|
|
|
if (isset($prop['active']))
|
2014-05-21 10:50:36 +02:00
|
|
|
$ret |= $cal->storage->activate(intval($prop['active']));
|
2014-09-09 13:29:28 +02:00
|
|
|
|
|
|
|
// apply to child folders, too
|
|
|
|
if ($prop['recursive']) {
|
|
|
|
foreach ((array)kolab_storage::list_folders($cal->storage->name, '*', 'event') as $subfolder) {
|
|
|
|
if (isset($prop['permanent']))
|
|
|
|
($prop['permanent'] ? kolab_storage::folder_subscribe($subfolder) : kolab_storage::folder_unsubscribe($subfolder));
|
|
|
|
if (isset($prop['active']))
|
|
|
|
($prop['active'] ? kolab_storage::folder_activate($subfolder) : kolab_storage::folder_deactivate($subfolder));
|
|
|
|
}
|
|
|
|
}
|
2014-05-15 15:53:35 +02:00
|
|
|
return $ret;
|
2011-08-26 23:24:49 +02:00
|
|
|
}
|
2014-01-27 19:12:29 +01:00
|
|
|
else {
|
|
|
|
// save state in local prefs
|
|
|
|
$prefs['kolab_calendars'] = $this->rc->config->get('kolab_calendars', array());
|
|
|
|
$prefs['kolab_calendars'][$prop['id']]['active'] = (bool)$prop['active'];
|
|
|
|
$this->rc->user->save_prefs($prefs);
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-04 13:01:59 +02:00
|
|
|
|
2011-08-26 23:24:49 +02:00
|
|
|
return false;
|
2011-07-26 13:13:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-08 18:48:06 -06:00
|
|
|
/**
|
|
|
|
* Delete the given calendar with all its contents
|
|
|
|
*
|
2014-09-09 13:29:28 +02:00
|
|
|
* @see calendar_driver::delete_calendar()
|
2011-06-08 18:48:06 -06:00
|
|
|
*/
|
2014-09-09 13:29:28 +02:00
|
|
|
public function delete_calendar($prop)
|
2011-06-08 18:48:06 -06:00
|
|
|
{
|
2014-05-13 17:09:53 +02:00
|
|
|
if ($prop['id'] && ($cal = $this->get_calendar($prop['id']))) {
|
2011-06-27 15:49:51 +02:00
|
|
|
$folder = $cal->get_realname();
|
2014-05-13 17:09:53 +02:00
|
|
|
// TODO: unsubscribe if no admin rights
|
2012-03-30 19:14:38 +02:00
|
|
|
if (kolab_storage::folder_delete($folder)) {
|
2011-06-27 15:49:51 +02:00
|
|
|
// remove color in user prefs (temp. solution)
|
|
|
|
$prefs['kolab_calendars'] = $this->rc->config->get('kolab_calendars', array());
|
|
|
|
unset($prefs['kolab_calendars'][$prop['id']]);
|
|
|
|
|
|
|
|
$this->rc->user->save_prefs($prefs);
|
|
|
|
return true;
|
2011-06-29 19:42:56 +02:00
|
|
|
}
|
2011-08-17 14:04:48 +02:00
|
|
|
else
|
2012-03-30 19:14:38 +02:00
|
|
|
$this->last_error = kolab_storage::$last_error;
|
2011-06-27 15:49:51 +02:00
|
|
|
}
|
|
|
|
|
2011-06-08 18:48:06 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-13 17:09:53 +02:00
|
|
|
/**
|
|
|
|
* Search for shared or otherwise not listed calendars the user has access
|
|
|
|
*
|
|
|
|
* @param string Search string
|
|
|
|
* @param string Section/source to search
|
|
|
|
* @return array List of calendars
|
|
|
|
*/
|
|
|
|
public function search_calendars($query, $source)
|
|
|
|
{
|
|
|
|
if (!kolab_storage::setup())
|
|
|
|
return array();
|
|
|
|
|
|
|
|
$this->calendars = array();
|
2014-05-16 10:38:37 +02:00
|
|
|
$this->search_more_results = false;
|
2014-05-13 17:09:53 +02:00
|
|
|
|
|
|
|
// find unsubscribed IMAP folders that have "event" type
|
|
|
|
if ($source == 'folders') {
|
2014-05-13 19:14:08 +02:00
|
|
|
foreach ((array)kolab_storage::search_folders('event', $query, array('other')) as $folder) {
|
2014-05-13 17:09:53 +02:00
|
|
|
$calendar = new kolab_calendar($folder->name, $this->cal);
|
|
|
|
$this->calendars[$calendar->id] = $calendar;
|
|
|
|
}
|
|
|
|
}
|
2014-05-14 20:37:06 +02:00
|
|
|
// find other user's virtual calendars
|
2014-05-13 17:09:53 +02:00
|
|
|
else if ($source == 'users') {
|
2014-05-16 10:38:37 +02:00
|
|
|
$limit = $this->rc->config->get('autocomplete_max', 15) * 2; // we have slightly more space, so display twice the number
|
|
|
|
foreach (kolab_storage::search_users($query, 0, array(), $limit, $count) as $user) {
|
2014-05-14 20:37:06 +02:00
|
|
|
$calendar = new kolab_user_calendar($user, $this->cal);
|
|
|
|
$this->calendars[$calendar->id] = $calendar;
|
|
|
|
|
|
|
|
// search for calendar folders shared by this user
|
|
|
|
foreach (kolab_storage::list_user_folders($user, 'event', false) as $foldername) {
|
2014-05-20 09:50:41 +02:00
|
|
|
$cal = new kolab_calendar($foldername, $this->cal);
|
|
|
|
$this->calendars[$cal->id] = $cal;
|
2014-09-08 18:56:23 +02:00
|
|
|
$calendar->subscriptions = true;
|
2014-05-14 20:37:06 +02:00
|
|
|
}
|
|
|
|
}
|
2014-05-16 10:38:37 +02:00
|
|
|
|
|
|
|
if ($count > $limit) {
|
|
|
|
$this->search_more_results = true;
|
|
|
|
}
|
2014-05-13 17:09:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// don't list the birthday calendar
|
|
|
|
$this->rc->config->set('calendar_contact_birthdays', false);
|
2014-07-08 12:36:34 +02:00
|
|
|
$this->rc->config->set('kolab_invitation_calendars', false);
|
2014-05-13 17:09:53 +02:00
|
|
|
|
|
|
|
return $this->list_calendars();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-27 16:06:06 +02:00
|
|
|
/**
|
2011-08-24 17:45:51 +02:00
|
|
|
* Fetch a single event
|
2011-07-27 16:06:06 +02:00
|
|
|
*
|
|
|
|
* @see calendar_driver::get_event()
|
|
|
|
* @return array Hash array with event properties, false if not found
|
|
|
|
*/
|
2015-03-10 15:23:52 +01:00
|
|
|
public function get_event($event, $scope = 0, $full = false)
|
2011-07-27 16:06:06 +02:00
|
|
|
{
|
2011-09-05 23:05:19 +02:00
|
|
|
if (is_array($event)) {
|
2015-02-15 14:32:31 +01:00
|
|
|
$id = $event['id'] ?: $event['uid'];
|
2011-09-05 23:05:19 +02:00
|
|
|
$cal = $event['calendar'];
|
2015-02-15 14:32:31 +01:00
|
|
|
|
2015-02-17 11:36:01 +01:00
|
|
|
// we're looking for a recurring instance: expand the ID to our internal convention for recurring instances
|
2015-02-15 14:32:31 +01:00
|
|
|
if (!$event['id'] && $event['_instance']) {
|
|
|
|
$id .= '-' . $event['_instance'];
|
|
|
|
}
|
2011-09-05 23:05:19 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$id = $event;
|
|
|
|
}
|
2012-12-04 20:10:04 +01:00
|
|
|
|
|
|
|
if ($cal) {
|
2014-05-13 17:09:53 +02:00
|
|
|
if ($storage = $this->get_calendar($cal)) {
|
2015-02-20 11:54:33 +01:00
|
|
|
$result = $storage->get_event($id);
|
2015-02-27 17:52:17 +01:00
|
|
|
return self::to_rcube_event($result);
|
2012-12-04 20:10:04 +01:00
|
|
|
}
|
2014-08-06 09:34:08 +02:00
|
|
|
// get event from the address books birthday calendar
|
|
|
|
else if ($cal == self::BIRTHDAY_CALENDAR_ID) {
|
|
|
|
return $this->get_birthday_event($id);
|
|
|
|
}
|
2011-08-24 17:45:51 +02:00
|
|
|
}
|
|
|
|
// iterate over all calendar folders and search for the event ID
|
2012-12-04 20:10:04 +01:00
|
|
|
else {
|
2015-03-10 15:23:52 +01:00
|
|
|
foreach ($this->filter_calendars($scope) as $calendar) {
|
2012-12-04 20:10:04 +01:00
|
|
|
if ($result = $calendar->get_event($id)) {
|
2015-02-27 17:52:17 +01:00
|
|
|
return self::to_rcube_event($result);
|
2011-08-24 17:45:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-27 16:06:06 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
/**
|
|
|
|
* Add a single event to the database
|
|
|
|
*
|
2011-07-27 16:06:06 +02:00
|
|
|
* @see calendar_driver::new_event()
|
2011-05-20 19:04:25 +02:00
|
|
|
*/
|
|
|
|
public function new_event($event)
|
|
|
|
{
|
2012-11-21 10:33:02 +01:00
|
|
|
if (!$this->validate($event))
|
|
|
|
return false;
|
|
|
|
|
2015-02-27 17:52:17 +01:00
|
|
|
$event = self::from_rcube_event($event);
|
|
|
|
|
2016-02-12 16:27:19 +01:00
|
|
|
if (!$event['calendar']) {
|
|
|
|
$this->_read_calendars();
|
|
|
|
$event['calendar'] = reset(array_keys($this->calendars));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($storage = $this->get_calendar($event['calendar'])) {
|
2015-02-26 14:48:14 +01:00
|
|
|
// if this is a recurrence instance, append as exception to an already existing object for this UID
|
2015-02-27 17:52:17 +01:00
|
|
|
if (!empty($event['recurrence_date']) && ($master = $storage->get_event($event['uid']))) {
|
2015-02-26 14:48:14 +01:00
|
|
|
self::add_exception($master, $event);
|
|
|
|
$success = $storage->update_event($master);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$success = $storage->insert_event($event);
|
|
|
|
}
|
|
|
|
|
2013-10-16 09:38:48 +02:00
|
|
|
if ($success && $this->freebusy_trigger) {
|
2011-07-29 17:51:04 +02:00
|
|
|
$this->rc->output->command('plugin.ping_url', array('action' => 'calendar/push-freebusy', 'source' => $storage->id));
|
2013-10-16 09:38:48 +02:00
|
|
|
$this->freebusy_trigger = false; // disable after first execution (#2355)
|
|
|
|
}
|
2011-07-16 17:14:36 +02:00
|
|
|
|
|
|
|
return $success;
|
2011-07-01 21:08:12 +02:00
|
|
|
}
|
2011-06-27 15:49:51 +02:00
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update an event entry with the given data
|
|
|
|
*
|
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
|
|
|
|
*/
|
|
|
|
public function edit_event($event)
|
|
|
|
{
|
2015-02-27 17:52:17 +01:00
|
|
|
if (!($storage = $this->get_calendar($event['calendar'])))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return $this->update_event(self::from_rcube_event($event, $storage->get_event($event['id'])));
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
|
|
|
|
2014-07-08 12:36:34 +02:00
|
|
|
/**
|
|
|
|
* Extended event editing with possible changes to the argument
|
|
|
|
*
|
|
|
|
* @param array Hash array with event properties
|
|
|
|
* @param string New participant status
|
2015-03-01 18:54:54 +01:00
|
|
|
* @param array List of hash arrays with updated attendees
|
2014-07-08 12:36:34 +02:00
|
|
|
* @return boolean True on success, False on error
|
|
|
|
*/
|
2015-02-19 18:09:12 +01:00
|
|
|
public function edit_rsvp(&$event, $status, $attendees)
|
2014-07-08 12:36:34 +02:00
|
|
|
{
|
2015-02-20 00:11:40 +01:00
|
|
|
$update_event = $event;
|
|
|
|
|
|
|
|
// apply changes to master (and all exceptions)
|
|
|
|
if ($event['_savemode'] == 'all' && $event['recurrence_id']) {
|
|
|
|
if ($storage = $this->get_calendar($event['calendar'])) {
|
|
|
|
$update_event = $storage->get_event($event['recurrence_id']);
|
|
|
|
$update_event['_savemode'] = $event['_savemode'];
|
2015-02-27 17:52:17 +01:00
|
|
|
$update_event['id'] = $update_event['uid'];
|
2015-02-20 00:11:40 +01:00
|
|
|
unset($update_event['recurrence_id']);
|
2015-03-01 18:54:54 +01:00
|
|
|
calendar::merge_attendee_data($update_event, $attendees);
|
2015-02-20 00:11:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-01 18:54:54 +01:00
|
|
|
if ($ret = $this->update_attendees($update_event, $attendees)) {
|
2015-02-27 17:52:17 +01:00
|
|
|
// replace with master event (for iTip reply)
|
|
|
|
$event = self::to_rcube_event($update_event);
|
|
|
|
|
2014-07-08 12:36:34 +02:00
|
|
|
// re-assign to the according (virtual) calendar
|
2015-03-01 18:54:54 +01:00
|
|
|
if ($this->rc->config->get('kolab_invitation_calendars')) {
|
|
|
|
if (strtoupper($status) == 'DECLINED')
|
|
|
|
$event['calendar'] = self::INVITATIONS_CALENDAR_DECLINED;
|
|
|
|
else if (strtoupper($status) == 'NEEDS-ACTION')
|
|
|
|
$event['calendar'] = self::INVITATIONS_CALENDAR_PENDING;
|
|
|
|
else if ($event['_folder_id'])
|
|
|
|
$event['calendar'] = $event['_folder_id'];
|
|
|
|
}
|
2014-07-08 12:36:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2015-02-17 11:36:01 +01:00
|
|
|
/**
|
|
|
|
* Update the participant status for the given attendees
|
|
|
|
*
|
|
|
|
* @see calendar_driver::update_attendees()
|
|
|
|
*/
|
|
|
|
public function update_attendees(&$event, $attendees)
|
|
|
|
{
|
|
|
|
// for this-and-future updates, merge the updated attendees onto all exceptions in range
|
2015-02-18 10:20:00 +01:00
|
|
|
if (($event['_savemode'] == 'future' && $event['recurrence_id']) || (!empty($event['recurrence']) && !$event['recurrence_id'])) {
|
2015-02-17 11:36:01 +01:00
|
|
|
if (!($storage = $this->get_calendar($event['calendar'])))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// load master event
|
|
|
|
$master = $event['recurrence_id'] ? $storage->get_event($event['recurrence_id']) : $event;
|
|
|
|
|
|
|
|
// apply attendee update to each existing exception
|
|
|
|
if ($master['recurrence'] && !empty($master['recurrence']['EXCEPTIONS'])) {
|
|
|
|
$saved = false;
|
|
|
|
foreach ($master['recurrence']['EXCEPTIONS'] as $i => $exception) {
|
|
|
|
// merge the new event properties onto future exceptions
|
2015-02-27 17:52:17 +01:00
|
|
|
if ($exception['_instance'] >= strval($event['_instance'])) {
|
2015-03-01 18:54:54 +01:00
|
|
|
calendar::merge_attendee_data($master['recurrence']['EXCEPTIONS'][$i], $attendees);
|
2015-02-17 11:36:01 +01:00
|
|
|
}
|
|
|
|
// update a specific instance
|
|
|
|
if ($exception['_instance'] == $event['_instance'] && $exception['thisandfuture']) {
|
|
|
|
$saved = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the given event as new exception
|
|
|
|
if (!$saved && $event['id'] != $master['id']) {
|
|
|
|
$event['thisandfuture'] = true;
|
|
|
|
$master['recurrence']['EXCEPTIONS'][] = $event;
|
|
|
|
}
|
|
|
|
|
2015-02-26 14:48:14 +01:00
|
|
|
// set link to top-level exceptions
|
|
|
|
$master['exceptions'] = &$master['recurrence']['EXCEPTIONS'];
|
|
|
|
|
2015-02-17 11:36:01 +01:00
|
|
|
return $this->update_event($master);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// just update the given event (instance)
|
|
|
|
return $this->update_event($event);
|
|
|
|
}
|
2014-07-08 12:36:34 +02:00
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
/**
|
|
|
|
* Move a single event
|
|
|
|
*
|
2011-07-27 16:06:06 +02:00
|
|
|
* @see calendar_driver::move_event()
|
2011-05-20 19:04:25 +02:00
|
|
|
* @return boolean True on success, False on error
|
|
|
|
*/
|
|
|
|
public function move_event($event)
|
|
|
|
{
|
2014-05-13 17:09:53 +02:00
|
|
|
if (($storage = $this->get_calendar($event['calendar'])) && ($ev = $storage->get_event($event['id']))) {
|
2013-07-22 19:42:41 +02:00
|
|
|
unset($ev['sequence']);
|
2015-02-20 00:11:40 +01:00
|
|
|
self::clear_attandee_noreply($ev);
|
2011-06-29 19:42:56 +02:00
|
|
|
return $this->update_event($event + $ev);
|
2013-07-22 19:42:41 +02:00
|
|
|
}
|
2011-06-27 15:49:51 +02:00
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resize a single event
|
|
|
|
*
|
2011-07-27 16:06:06 +02:00
|
|
|
* @see calendar_driver::resize_event()
|
2011-05-20 19:04:25 +02:00
|
|
|
* @return boolean True on success, False on error
|
|
|
|
*/
|
|
|
|
public function resize_event($event)
|
|
|
|
{
|
2014-05-13 17:09:53 +02:00
|
|
|
if (($storage = $this->get_calendar($event['calendar'])) && ($ev = $storage->get_event($event['id']))) {
|
2013-07-22 19:42:41 +02:00
|
|
|
unset($ev['sequence']);
|
2015-02-20 00:11:40 +01:00
|
|
|
self::clear_attandee_noreply($ev);
|
2011-06-29 19:42:56 +02:00
|
|
|
return $this->update_event($event + $ev);
|
2013-07-22 19:42:41 +02:00
|
|
|
}
|
2011-06-28 11:20:17 +02:00
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-07-18 15:28:57 +02:00
|
|
|
* Remove a single event
|
|
|
|
*
|
|
|
|
* @param array Hash array with event properties:
|
|
|
|
* id: Event identifier
|
|
|
|
* @param boolean Remove record(s) irreversible (mark as deleted otherwise)
|
2011-05-20 19:04:25 +02:00
|
|
|
*
|
|
|
|
* @return boolean True on success, False on error
|
|
|
|
*/
|
2011-07-18 15:28:57 +02:00
|
|
|
public function remove_event($event, $force = true)
|
2011-05-20 19:04:25 +02:00
|
|
|
{
|
2015-03-10 13:38:53 +01:00
|
|
|
$ret = true;
|
2011-06-29 19:42:56 +02:00
|
|
|
$success = false;
|
2013-01-09 11:12:19 +01:00
|
|
|
$savemode = $event['_savemode'];
|
2015-02-27 17:52:17 +01:00
|
|
|
$decline = $event['_decline'];
|
2011-07-18 15:28:57 +02:00
|
|
|
|
2014-05-13 17:09:53 +02:00
|
|
|
if (($storage = $this->get_calendar($event['calendar'])) && ($event = $storage->get_event($event['id']))) {
|
2013-01-09 11:12:19 +01:00
|
|
|
$event['_savemode'] = $savemode;
|
2011-06-29 19:42:56 +02:00
|
|
|
$savemode = 'all';
|
|
|
|
$master = $event;
|
2011-07-18 15:28:57 +02:00
|
|
|
|
2011-09-28 17:27:25 +02:00
|
|
|
$this->rc->session->remove('calendar_restore_event_data');
|
2011-07-18 15:28:57 +02:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
// read master if deleting a recurring event
|
2015-02-26 14:48:14 +01:00
|
|
|
if ($event['recurrence'] || $event['recurrence_id'] || $event['isexception']) {
|
2015-02-27 17:52:17 +01:00
|
|
|
$master = $storage->get_event($event['uid']);
|
2015-02-26 14:48:14 +01:00
|
|
|
$savemode = $event['_savemode'] ?: ($event['_instance'] || $event['isexception'] ? 'current' : 'all');
|
|
|
|
|
|
|
|
// force 'current' mode for single occurrences stored as exception
|
|
|
|
if (!$event['recurrence'] && !$event['recurrence_id'] && $event['isexception'])
|
|
|
|
$savemode = 'current';
|
2011-06-29 19:42:56 +02:00
|
|
|
}
|
2011-07-18 15:28:57 +02:00
|
|
|
|
2013-02-14 16:17:02 +01:00
|
|
|
// removing an exception instance
|
2015-02-26 14:48:14 +01:00
|
|
|
if (($event['recurrence_id'] || $event['isexception']) && is_array($master['exceptions'])) {
|
|
|
|
foreach ($master['exceptions'] as $i => $exception) {
|
2015-02-12 10:08:22 +01:00
|
|
|
if ($exception['_instance'] == $event['_instance']) {
|
2015-02-26 14:48:14 +01:00
|
|
|
unset($master['exceptions'][$i]);
|
2015-02-12 10:08:22 +01:00
|
|
|
// set event date back to the actual occurrence
|
|
|
|
if ($exception['recurrence_date'])
|
|
|
|
$event['start'] = $exception['recurrence_date'];
|
|
|
|
}
|
2013-02-14 16:17:02 +01:00
|
|
|
}
|
2015-02-26 14:48:14 +01:00
|
|
|
|
|
|
|
if (is_array($master['recurrence'])) {
|
|
|
|
$master['recurrence']['EXCEPTIONS'] = &$master['exceptions'];
|
|
|
|
}
|
2013-02-14 16:17:02 +01:00
|
|
|
}
|
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
switch ($savemode) {
|
|
|
|
case 'current':
|
2011-09-28 17:27:25 +02:00
|
|
|
$_SESSION['calendar_restore_event_data'] = $master;
|
2013-01-09 11:12:19 +01:00
|
|
|
|
2011-09-28 17:14:29 +02:00
|
|
|
// removing the first instance => just move to next occurence
|
2015-03-10 14:30:50 +01:00
|
|
|
if ($master['recurrence'] && $event['_instance'] == libcalendaring::recurrence_instance_identifier($master)) {
|
2015-02-02 13:12:56 +01:00
|
|
|
$recurring = reset($storage->get_recurring_events($event, $event['start'], null, $event['id'].'-1'));
|
2013-03-06 10:19:22 +01:00
|
|
|
|
|
|
|
// no future instances found: delete the master event (bug #1677)
|
|
|
|
if (!$recurring['start']) {
|
|
|
|
$success = $storage->delete_event($master, $force);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-28 17:14:29 +02:00
|
|
|
$master['start'] = $recurring['start'];
|
|
|
|
$master['end'] = $recurring['end'];
|
|
|
|
if ($master['recurrence']['COUNT'])
|
|
|
|
$master['recurrence']['COUNT']--;
|
|
|
|
}
|
2014-03-17 12:40:21 +01:00
|
|
|
// remove the matching RDATE entry
|
|
|
|
else if ($master['recurrence']['RDATE']) {
|
|
|
|
foreach ($master['recurrence']['RDATE'] as $j => $rdate) {
|
|
|
|
if ($rdate->format('Ymd') == $event['start']->format('Ymd')) {
|
|
|
|
unset($master['recurrence']['RDATE'][$j]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-28 17:14:29 +02:00
|
|
|
else { // add exception to master event
|
|
|
|
$master['recurrence']['EXDATE'][] = $event['start'];
|
|
|
|
}
|
2011-06-29 19:42:56 +02:00
|
|
|
$success = $storage->update_event($master);
|
|
|
|
break;
|
2011-07-18 15:28:57 +02:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
case 'future':
|
2015-03-10 14:30:50 +01:00
|
|
|
$master['_instance'] = libcalendaring::recurrence_instance_identifier($master);
|
2015-03-10 13:38:53 +01:00
|
|
|
if ($master['_instance'] != $event['_instance']) {
|
2011-09-28 17:27:25 +02:00
|
|
|
$_SESSION['calendar_restore_event_data'] = $master;
|
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
// set until-date on master event
|
2012-07-06 17:15:45 +02:00
|
|
|
$master['recurrence']['UNTIL'] = clone $event['start'];
|
|
|
|
$master['recurrence']['UNTIL']->sub(new DateInterval('P1D'));
|
2011-06-29 19:42:56 +02:00
|
|
|
unset($master['recurrence']['COUNT']);
|
2013-03-06 10:19:22 +01:00
|
|
|
|
|
|
|
// if all future instances are deleted, remove recurrence rule entirely (bug #1677)
|
2014-03-17 12:40:21 +01:00
|
|
|
if ($master['recurrence']['UNTIL']->format('Ymd') == $master['start']->format('Ymd')) {
|
2013-03-06 10:19:22 +01:00
|
|
|
$master['recurrence'] = array();
|
2014-03-17 12:40:21 +01:00
|
|
|
}
|
|
|
|
// remove matching RDATE entries
|
|
|
|
else if ($master['recurrence']['RDATE']) {
|
|
|
|
foreach ($master['recurrence']['RDATE'] as $j => $rdate) {
|
|
|
|
if ($rdate->format('Ymd') == $event['start']->format('Ymd')) {
|
|
|
|
$master['recurrence']['RDATE'] = array_slice($master['recurrence']['RDATE'], 0, $j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-06 10:19:22 +01:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
$success = $storage->update_event($master);
|
2015-03-10 13:38:53 +01:00
|
|
|
$ret = $master['uid'];
|
2011-06-29 19:42:56 +02:00
|
|
|
break;
|
|
|
|
}
|
2011-07-18 15:28:57 +02:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
default: // 'all' is default
|
2015-02-26 14:48:14 +01:00
|
|
|
// removing the master event with loose exceptions (not recurring though)
|
2015-02-27 17:52:17 +01:00
|
|
|
if (!empty($event['recurrence_date']) && empty($master['recurrence']) && !empty($master['exceptions'])) {
|
2015-02-26 14:48:14 +01:00
|
|
|
// make the first exception the new master
|
|
|
|
$newmaster = array_shift($master['exceptions']);
|
|
|
|
$newmaster['exceptions'] = $master['exceptions'];
|
|
|
|
$newmaster['_attachments'] = $master['_attachments'];
|
|
|
|
$newmaster['_mailbox'] = $master['_mailbox'];
|
|
|
|
$newmaster['_msguid'] = $master['_msguid'];
|
|
|
|
|
|
|
|
$success = $storage->update_event($newmaster);
|
|
|
|
}
|
|
|
|
else if ($decline && $this->rc->config->get('kolab_invitation_calendars')) {
|
2014-07-08 12:36:34 +02:00
|
|
|
// don't delete but set PARTSTAT=DECLINED
|
|
|
|
if ($this->cal->lib->set_partstat($master, 'DECLINED')) {
|
|
|
|
$success = $storage->update_event($master);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$success)
|
|
|
|
$success = $storage->delete_event($master, $force);
|
2011-06-29 19:42:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-01-14 09:27:48 +01:00
|
|
|
|
2012-09-19 11:17:15 +02:00
|
|
|
if ($success && $this->freebusy_trigger)
|
2011-07-29 17:51:04 +02:00
|
|
|
$this->rc->output->command('plugin.ping_url', array('action' => 'calendar/push-freebusy', 'source' => $storage->id));
|
2011-07-16 17:14:36 +02:00
|
|
|
|
2015-03-10 13:38:53 +01:00
|
|
|
return $success ? $ret : false;
|
2011-06-29 19:42:56 +02:00
|
|
|
}
|
|
|
|
|
2011-07-18 15:28:57 +02:00
|
|
|
/**
|
|
|
|
* Restore a single deleted event
|
|
|
|
*
|
|
|
|
* @param array Hash array with event properties:
|
|
|
|
* id: Event identifier
|
|
|
|
* @return boolean True on success, False on error
|
|
|
|
*/
|
|
|
|
public function restore_event($event)
|
|
|
|
{
|
2014-05-13 17:09:53 +02:00
|
|
|
if ($storage = $this->get_calendar($event['calendar'])) {
|
2011-09-28 17:27:25 +02:00
|
|
|
if (!empty($_SESSION['calendar_restore_event_data']))
|
|
|
|
$success = $storage->update_event($_SESSION['calendar_restore_event_data']);
|
|
|
|
else
|
|
|
|
$success = $storage->restore_event($event);
|
|
|
|
|
2012-09-19 11:17:15 +02:00
|
|
|
if ($success && $this->freebusy_trigger)
|
2011-08-12 16:25:54 +02:00
|
|
|
$this->rc->output->command('plugin.ping_url', array('action' => 'calendar/push-freebusy', 'source' => $storage->id));
|
|
|
|
|
|
|
|
return $success;
|
2011-07-18 15:28:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
/**
|
|
|
|
* Wrapper to update an event object depending on the given savemode
|
|
|
|
*/
|
|
|
|
private function update_event($event)
|
|
|
|
{
|
2014-05-13 17:09:53 +02:00
|
|
|
if (!($storage = $this->get_calendar($event['calendar'])))
|
2011-06-29 19:42:56 +02:00
|
|
|
return false;
|
2011-07-01 21:08:12 +02:00
|
|
|
|
2011-09-19 09:50:13 +02:00
|
|
|
// move event to another folder/calendar
|
2011-09-19 10:03:38 +02:00
|
|
|
if ($event['_fromcalendar'] && $event['_fromcalendar'] != $event['calendar']) {
|
2014-05-13 17:09:53 +02:00
|
|
|
if (!($fromcalendar = $this->get_calendar($event['_fromcalendar'])))
|
2011-09-19 09:50:13 +02:00
|
|
|
return false;
|
|
|
|
|
2015-02-27 17:52:17 +01:00
|
|
|
$old = $fromcalendar->get_event($event['id']);
|
|
|
|
|
2011-09-19 10:03:38 +02:00
|
|
|
if ($event['_savemode'] != 'new') {
|
2015-02-27 17:52:17 +01:00
|
|
|
if (!$fromcalendar->storage->move($old['uid'], $storage->storage)) {
|
2011-09-19 09:50:13 +02:00
|
|
|
return false;
|
2015-02-27 17:52:17 +01:00
|
|
|
}
|
2011-09-19 09:50:13 +02:00
|
|
|
|
|
|
|
$fromcalendar = $storage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$fromcalendar = $storage;
|
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
$success = false;
|
|
|
|
$savemode = 'all';
|
2011-07-01 21:08:12 +02:00
|
|
|
$attachments = array();
|
2015-02-27 17:52:17 +01:00
|
|
|
$old = $master = $storage->get_event($event['id']);
|
2011-07-01 21:08:12 +02:00
|
|
|
|
2012-08-03 15:20:41 +02:00
|
|
|
if (!$old || !$old['start']) {
|
2012-11-06 11:46:15 +01:00
|
|
|
rcube::raise_error(array(
|
2012-08-03 15:20:41 +02:00
|
|
|
'code' => 600, 'type' => 'php',
|
|
|
|
'file' => __FILE__, 'line' => __LINE__,
|
|
|
|
'message' => "Failed to load event object to update: id=" . $event['id']),
|
|
|
|
true, false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
// modify a recurring event, check submitted savemode to do the right things
|
2015-02-26 14:48:14 +01:00
|
|
|
if ($old['recurrence'] || $old['recurrence_id'] || $old['isexception']) {
|
2015-02-27 17:52:17 +01:00
|
|
|
$master = $storage->get_event($old['uid']);
|
2015-02-26 14:48:14 +01:00
|
|
|
$savemode = $event['_savemode'] ?: ($old['recurrence_id'] || $old['isexception'] ? 'current' : 'all');
|
2015-02-17 15:49:14 +01:00
|
|
|
|
|
|
|
// this-and-future on the first instance equals to 'all'
|
2015-03-10 14:30:50 +01:00
|
|
|
if ($savemode == 'future' && $master['start'] && $old['_instance'] == libcalendaring::recurrence_instance_identifier($master))
|
2015-02-17 15:49:14 +01:00
|
|
|
$savemode = 'all';
|
2015-02-26 14:48:14 +01:00
|
|
|
// force 'current' mode for single occurrences stored as exception
|
|
|
|
else if (!$old['recurrence'] && !$old['recurrence_id'] && $old['isexception'])
|
|
|
|
$savemode = 'current';
|
2011-06-29 19:42:56 +02:00
|
|
|
}
|
2011-07-01 21:08:12 +02:00
|
|
|
|
2015-02-12 12:08:17 +01:00
|
|
|
// check if update affects scheduling and update attendee status accordingly
|
|
|
|
$reschedule = $this->check_scheduling($event, $old, true);
|
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
// keep saved exceptions (not submitted by the client)
|
2015-02-12 10:08:22 +01:00
|
|
|
if ($old['recurrence']['EXDATE'] && !isset($event['recurrence']['EXDATE']))
|
2011-06-29 19:42:56 +02:00
|
|
|
$event['recurrence']['EXDATE'] = $old['recurrence']['EXDATE'];
|
2015-02-12 10:08:22 +01:00
|
|
|
if (isset($event['recurrence']['EXCEPTIONS']))
|
|
|
|
$with_exceptions = true; // exceptions already provided (e.g. from iCal import)
|
|
|
|
else if ($old['recurrence']['EXCEPTIONS'])
|
2013-01-23 14:45:41 +01:00
|
|
|
$event['recurrence']['EXCEPTIONS'] = $old['recurrence']['EXCEPTIONS'];
|
2015-02-26 14:48:14 +01:00
|
|
|
else if ($old['exceptions'])
|
|
|
|
$event['exceptions'] = $old['exceptions'];
|
2011-07-01 21:08:12 +02:00
|
|
|
|
2015-02-15 18:27:38 +01:00
|
|
|
// remove some internal properties which should not be saved
|
|
|
|
unset($event['_savemode'], $event['_fromcalendar'], $event['_identity'], $event['_owner'],
|
|
|
|
$event['_notify'], $event['_method'], $event['_sender'], $event['_sender_utf'], $event['_size']);
|
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
switch ($savemode) {
|
|
|
|
case 'new':
|
|
|
|
// save submitted data as new (non-recurring) event
|
|
|
|
$event['recurrence'] = array();
|
2015-02-20 11:54:33 +01:00
|
|
|
$event['_copyfrom'] = $master['_msguid'];
|
|
|
|
$event['_mailbox'] = $master['_mailbox'];
|
2011-06-29 19:42:56 +02:00
|
|
|
$event['uid'] = $this->cal->generate_uid();
|
2015-02-20 00:11:40 +01:00
|
|
|
unset($event['recurrence_id'], $event['recurrence_date'], $event['_instance'], $event['id']);
|
2015-01-27 18:13:08 +01:00
|
|
|
|
2015-02-20 00:11:40 +01:00
|
|
|
// copy attachment metadata to new event
|
2015-02-20 11:54:33 +01:00
|
|
|
$event = self::from_rcube_event($event, $master);
|
2015-01-28 17:46:03 +01:00
|
|
|
|
2015-02-20 00:11:40 +01:00
|
|
|
self::clear_attandee_noreply($event);
|
2015-01-28 17:46:03 +01:00
|
|
|
if ($success = $storage->insert_event($event))
|
|
|
|
$success = $event['uid'];
|
2011-06-29 19:42:56 +02:00
|
|
|
break;
|
2013-02-14 16:17:02 +01:00
|
|
|
|
|
|
|
case 'future':
|
2015-02-20 00:11:40 +01:00
|
|
|
// create a new recurring event
|
2015-02-20 11:54:33 +01:00
|
|
|
$event['_copyfrom'] = $master['_msguid'];
|
|
|
|
$event['_mailbox'] = $master['_mailbox'];
|
2015-02-20 00:11:40 +01:00
|
|
|
$event['uid'] = $this->cal->generate_uid();
|
|
|
|
unset($event['recurrence_id'], $event['recurrence_date'], $event['_instance'], $event['id']);
|
|
|
|
|
|
|
|
// copy attachment metadata to new event
|
2015-02-20 11:54:33 +01:00
|
|
|
$event = self::from_rcube_event($event, $master);
|
2016-02-12 16:27:19 +01:00
|
|
|
|
2015-02-20 00:11:40 +01:00
|
|
|
// remove recurrence exceptions on re-scheduling
|
|
|
|
if ($reschedule) {
|
2015-02-27 17:52:17 +01:00
|
|
|
unset($event['recurrence']['EXCEPTIONS'], $event['exceptions'], $master['recurrence']['EXDATE']);
|
2015-02-20 00:11:40 +01:00
|
|
|
}
|
|
|
|
else if (is_array($event['recurrence']['EXCEPTIONS'])) {
|
|
|
|
// only keep relevant exceptions
|
|
|
|
$event['recurrence']['EXCEPTIONS'] = array_filter($event['recurrence']['EXCEPTIONS'], function($exception) use ($event) {
|
|
|
|
return $exception['start'] > $event['start'];
|
|
|
|
});
|
2015-02-20 09:25:24 +01:00
|
|
|
if (is_array($event['recurrence']['EXDATE'])) {
|
|
|
|
$event['recurrence']['EXDATE'] = array_filter($event['recurrence']['EXDATE'], function($exdate) use ($event) {
|
|
|
|
return $exdate > $event['start'];
|
|
|
|
});
|
|
|
|
}
|
2015-02-27 17:52:17 +01:00
|
|
|
// set link to top-level exceptions
|
|
|
|
$event['exceptions'] = &$event['recurrence']['EXCEPTIONS'];
|
2015-02-20 00:11:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// compute remaining occurrences
|
|
|
|
if ($event['recurrence']['COUNT']) {
|
|
|
|
if (!$old['_count'])
|
2015-02-20 11:54:33 +01:00
|
|
|
$old['_count'] = $this->get_recurrence_count($master, $old['start']);
|
2015-02-20 00:11:40 +01:00
|
|
|
$event['recurrence']['COUNT'] -= intval($old['_count']);
|
|
|
|
}
|
|
|
|
|
2015-02-20 09:25:24 +01:00
|
|
|
// remove fixed weekday when date changed
|
|
|
|
if ($old['start']->format('Y-m-d') != $event['start']->format('Y-m-d')) {
|
|
|
|
if (strlen($event['recurrence']['BYDAY']) == 2)
|
|
|
|
unset($event['recurrence']['BYDAY']);
|
|
|
|
if ($old['recurrence']['BYMONTH'] == $old['start']->format('n'))
|
|
|
|
unset($event['recurrence']['BYMONTH']);
|
|
|
|
}
|
|
|
|
|
2015-02-20 00:11:40 +01:00
|
|
|
// set until-date on master event
|
2015-02-20 09:25:24 +01:00
|
|
|
$master['recurrence']['UNTIL'] = clone $old['start'];
|
2015-02-20 00:11:40 +01:00
|
|
|
$master['recurrence']['UNTIL']->sub(new DateInterval('P1D'));
|
|
|
|
unset($master['recurrence']['COUNT']);
|
|
|
|
|
|
|
|
// remove all exceptions after $event['start']
|
|
|
|
if (is_array($master['recurrence']['EXCEPTIONS'])) {
|
|
|
|
$master['recurrence']['EXCEPTIONS'] = array_filter($master['recurrence']['EXCEPTIONS'], function($exception) use ($event) {
|
|
|
|
return $exception['start'] < $event['start'];
|
|
|
|
});
|
2015-02-27 17:52:17 +01:00
|
|
|
// set link to top-level exceptions
|
|
|
|
$master['exceptions'] = &$master['recurrence']['EXCEPTIONS'];
|
2015-02-20 00:11:40 +01:00
|
|
|
}
|
2015-02-20 09:25:24 +01:00
|
|
|
if (is_array($master['recurrence']['EXDATE'])) {
|
|
|
|
$master['recurrence']['EXDATE'] = array_filter($master['recurrence']['EXDATE'], function($exdate) use ($event) {
|
|
|
|
return $exdate < $event['start'];
|
|
|
|
});
|
|
|
|
}
|
2015-02-20 00:11:40 +01:00
|
|
|
|
|
|
|
// save new event
|
|
|
|
if ($success = $storage->insert_event($event)) {
|
|
|
|
$success = $event['uid'];
|
|
|
|
|
|
|
|
// update master event (no rescheduling!)
|
|
|
|
self::clear_attandee_noreply($master);
|
2015-02-26 14:48:14 +01:00
|
|
|
$storage->update_event($master);
|
2015-02-20 00:11:40 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
case 'current':
|
2015-02-15 15:12:08 +01:00
|
|
|
// recurring instances shall not store recurrence rules and attachments
|
2011-06-29 19:42:56 +02:00
|
|
|
$event['recurrence'] = array();
|
2013-02-14 16:17:02 +01:00
|
|
|
$event['thisandfuture'] = $savemode == 'future';
|
2015-02-15 18:27:38 +01:00
|
|
|
unset($event['attachments'], $event['id']);
|
2013-01-23 14:45:41 +01:00
|
|
|
|
2015-02-12 12:08:17 +01:00
|
|
|
// increment sequence of this instance if scheduling is affected
|
|
|
|
if ($reschedule) {
|
2015-02-15 14:32:31 +01:00
|
|
|
$event['sequence'] = max($old['sequence'], $master['sequence']) + 1;
|
2015-02-12 12:08:17 +01:00
|
|
|
}
|
2015-02-19 15:13:41 +01:00
|
|
|
else if (!isset($event['sequence'])) {
|
2015-02-26 14:48:14 +01:00
|
|
|
$event['sequence'] = $old['sequence'] ?: $master['sequence'];
|
2015-02-19 15:13:41 +01:00
|
|
|
}
|
2015-02-12 10:08:22 +01:00
|
|
|
|
2013-01-23 14:45:41 +01:00
|
|
|
// save properties to a recurrence exception instance
|
2015-02-17 11:36:01 +01:00
|
|
|
if ($old['_instance'] && is_array($master['recurrence']['EXCEPTIONS'])) {
|
|
|
|
if ($this->update_recurrence_exceptions($master, $event, $old, $savemode)) {
|
|
|
|
$success = $storage->update_event($master, $old['id']);
|
|
|
|
break;
|
2015-02-12 10:08:22 +01:00
|
|
|
}
|
2013-01-23 14:45:41 +01:00
|
|
|
}
|
|
|
|
|
2014-03-17 12:40:21 +01:00
|
|
|
$add_exception = true;
|
|
|
|
|
|
|
|
// adjust matching RDATE entry if dates changed
|
2015-02-27 17:52:17 +01:00
|
|
|
if (is_array($master['recurrence']['RDATE']) && ($old_date = $old['start']->format('Ymd')) != $event['start']->format('Ymd')) {
|
2014-03-17 12:40:21 +01:00
|
|
|
foreach ($master['recurrence']['RDATE'] as $j => $rdate) {
|
|
|
|
if ($rdate->format('Ymd') == $old_date) {
|
|
|
|
$master['recurrence']['RDATE'][$j] = $event['start'];
|
|
|
|
sort($master['recurrence']['RDATE']);
|
|
|
|
$add_exception = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 16:17:02 +01:00
|
|
|
// save as new exception to master event
|
2014-03-17 12:40:21 +01:00
|
|
|
if ($add_exception) {
|
2015-02-26 14:48:14 +01:00
|
|
|
self::add_exception($master, $event, $old);
|
2014-03-17 12:40:21 +01:00
|
|
|
}
|
2015-02-26 14:48:14 +01:00
|
|
|
|
2013-02-14 16:17:02 +01:00
|
|
|
$success = $storage->update_event($master);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: // 'all' is default
|
2015-02-27 17:52:17 +01:00
|
|
|
$event['id'] = $master['uid'];
|
2011-06-29 19:42:56 +02:00
|
|
|
$event['uid'] = $master['uid'];
|
|
|
|
|
|
|
|
// use start date from master but try to be smart on time or duration changes
|
2012-07-06 17:15:45 +02:00
|
|
|
$old_start_date = $old['start']->format('Y-m-d');
|
2013-01-09 11:49:12 +01:00
|
|
|
$old_start_time = $old['allday'] ? '' : $old['start']->format('H:i');
|
2012-07-06 17:15:45 +02:00
|
|
|
$old_duration = $old['end']->format('U') - $old['start']->format('U');
|
2011-06-29 19:42:56 +02:00
|
|
|
|
2012-07-06 17:15:45 +02:00
|
|
|
$new_start_date = $event['start']->format('Y-m-d');
|
2013-01-09 11:49:12 +01:00
|
|
|
$new_start_time = $event['allday'] ? '' : $event['start']->format('H:i');
|
2012-07-06 17:15:45 +02:00
|
|
|
$new_duration = $event['end']->format('U') - $event['start']->format('U');
|
2011-06-29 19:42:56 +02:00
|
|
|
|
2011-09-23 12:50:06 +02:00
|
|
|
$diff = $old_start_date != $new_start_date || $old_start_time != $new_start_time || $old_duration != $new_duration;
|
2015-02-12 10:08:22 +01:00
|
|
|
$date_shift = $old['start']->diff($event['start']);
|
2011-09-23 12:50:06 +02:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
// shifted or resized
|
2011-09-23 13:01:16 +02:00
|
|
|
if ($diff && ($old_start_date == $new_start_date || $old_duration == $new_duration)) {
|
2015-02-12 10:08:22 +01:00
|
|
|
$event['start'] = $master['start']->add($date_shift);
|
2012-07-06 17:15:45 +02:00
|
|
|
$event['end'] = clone $event['start'];
|
|
|
|
$event['end']->add(new DateInterval('PT'.$new_duration.'S'));
|
2011-06-29 19:42:56 +02:00
|
|
|
|
|
|
|
// remove fixed weekday, will be re-set to the new weekday in kolab_calendar::update_event()
|
2011-09-23 13:01:16 +02:00
|
|
|
if ($old_start_date != $new_start_date) {
|
|
|
|
if (strlen($event['recurrence']['BYDAY']) == 2)
|
|
|
|
unset($event['recurrence']['BYDAY']);
|
2012-07-06 17:15:45 +02:00
|
|
|
if ($old['recurrence']['BYMONTH'] == $old['start']->format('n'))
|
2011-09-23 13:01:16 +02:00
|
|
|
unset($event['recurrence']['BYMONTH']);
|
|
|
|
}
|
2011-06-29 19:42:56 +02:00
|
|
|
}
|
2012-07-06 15:30:06 +02:00
|
|
|
// dates did not change, use the ones from master
|
2015-02-27 17:52:17 +01:00
|
|
|
else if ($new_start_date . $new_start_time == $old_start_date . $old_start_time) {
|
2012-07-06 15:30:06 +02:00
|
|
|
$event['start'] = $master['start'];
|
|
|
|
$event['end'] = $master['end'];
|
|
|
|
}
|
2011-06-29 19:42:56 +02:00
|
|
|
|
2015-02-18 11:30:16 +01:00
|
|
|
// when saving an instance in 'all' mode, copy recurrence exceptions over
|
|
|
|
if ($old['recurrence_id']) {
|
2015-02-20 09:25:24 +01:00
|
|
|
$event['recurrence']['EXCEPTIONS'] = $master['recurrence']['EXCEPTIONS'];
|
2015-02-18 11:30:16 +01:00
|
|
|
}
|
2015-02-26 14:48:14 +01:00
|
|
|
else if ($master['_instance']) {
|
|
|
|
$event['_instance'] = $master['_instance'];
|
|
|
|
$event['recurrence_date'] = $master['recurrence_date'];
|
|
|
|
}
|
2015-02-18 11:30:16 +01:00
|
|
|
|
2015-02-17 11:36:01 +01:00
|
|
|
// TODO: forward changes to exceptions (which do not yet have differing values stored)
|
2015-02-18 11:30:16 +01:00
|
|
|
if (is_array($event['recurrence']) && is_array($event['recurrence']['EXCEPTIONS']) && !$with_exceptions) {
|
|
|
|
// determine added and removed attendees
|
|
|
|
$old_attendees = $current_attendees = $added_attendees = array();
|
|
|
|
foreach ((array)$old['attendees'] as $attendee) {
|
|
|
|
$old_attendees[] = $attendee['email'];
|
|
|
|
}
|
|
|
|
foreach ((array)$event['attendees'] as $attendee) {
|
|
|
|
$current_attendees[] = $attendee['email'];
|
|
|
|
if (!in_array($attendee['email'], $old_attendees)) {
|
|
|
|
$added_attendees[] = $attendee;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$removed_attendees = array_diff($old_attendees, $current_attendees);
|
2015-02-17 11:36:01 +01:00
|
|
|
|
2015-02-12 10:08:22 +01:00
|
|
|
foreach ($event['recurrence']['EXCEPTIONS'] as $i => $exception) {
|
2015-03-01 18:54:54 +01:00
|
|
|
calendar::merge_attendee_data($event['recurrence']['EXCEPTIONS'][$i], $added_attendees, $removed_attendees);
|
2015-02-18 11:30:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// adjust recurrence-id when start changed and therefore the entire recurrence chain changes
|
|
|
|
if ($old_start_date != $new_start_date || $old_start_time != $new_start_time) {
|
2015-03-10 14:30:50 +01:00
|
|
|
$recurrence_id_format = libcalendaring::recurrence_id_format($event);
|
2015-02-18 11:30:16 +01:00
|
|
|
foreach ($event['recurrence']['EXCEPTIONS'] as $i => $exception) {
|
|
|
|
$recurrence_id = is_a($exception['recurrence_date'], 'DateTime') ? $exception['recurrence_date'] :
|
|
|
|
rcube_utils::anytodatetime($exception['_instance'], $old['start']->getTimezone());
|
|
|
|
if (is_a($recurrence_id, 'DateTime')) {
|
|
|
|
$recurrence_id->add($date_shift);
|
|
|
|
$event['recurrence']['EXCEPTIONS'][$i]['recurrence_date'] = $recurrence_id;
|
|
|
|
$event['recurrence']['EXCEPTIONS'][$i]['_instance'] = $recurrence_id->format($recurrence_id_format);
|
|
|
|
}
|
2015-02-12 10:08:22 +01:00
|
|
|
}
|
|
|
|
}
|
2015-02-27 17:52:17 +01:00
|
|
|
|
|
|
|
// set link to top-level exceptions
|
|
|
|
$event['exceptions'] = &$event['recurrence']['EXCEPTIONS'];
|
2015-02-12 10:08:22 +01:00
|
|
|
}
|
|
|
|
|
2013-10-03 10:54:05 +02:00
|
|
|
// unset _dateonly flags in (cached) date objects
|
|
|
|
unset($event['start']->_dateonly, $event['end']->_dateonly);
|
|
|
|
|
2015-02-27 17:52:17 +01:00
|
|
|
$success = $storage->update_event($event) ? $event['id'] : false; // return master UID
|
2011-06-29 19:42:56 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-01-14 09:27:48 +01:00
|
|
|
|
2012-09-19 11:17:15 +02:00
|
|
|
if ($success && $this->freebusy_trigger)
|
2011-07-29 17:51:04 +02:00
|
|
|
$this->rc->output->command('plugin.ping_url', array('action' => 'calendar/push-freebusy', 'source' => $storage->id));
|
2011-07-16 17:14:36 +02:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
return $success;
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
|
|
|
|
2015-02-12 12:08:17 +01:00
|
|
|
/**
|
|
|
|
* Determine whether the current change affects scheduling and reset attendee status accordingly
|
|
|
|
*/
|
|
|
|
public function check_scheduling(&$event, $old, $update = true)
|
|
|
|
{
|
|
|
|
// skip this check when importing iCal/iTip events
|
|
|
|
if (isset($event['sequence']) || !empty($event['_method'])) {
|
2015-02-15 16:33:39 +01:00
|
|
|
return false;
|
2015-02-12 12:08:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// iterate through the list of properties considered 'significant' for scheduling
|
2015-02-15 17:10:22 +01:00
|
|
|
$kolab_event = $old['_formatobj'] ?: new kolab_format_event();
|
|
|
|
$reschedule = $kolab_event->check_rescheduling($event, $old);
|
2015-02-12 12:08:17 +01:00
|
|
|
|
|
|
|
// reset all attendee status to needs-action (#4360)
|
|
|
|
if ($update && $reschedule && is_array($event['attendees'])) {
|
|
|
|
$is_organizer = false;
|
|
|
|
$emails = $this->cal->get_user_emails();
|
|
|
|
$attendees = $event['attendees'];
|
|
|
|
foreach ($attendees as $i => $attendee) {
|
|
|
|
if ($attendee['role'] == 'ORGANIZER' && $attendee['email'] && in_array(strtolower($attendee['email']), $emails)) {
|
|
|
|
$is_organizer = true;
|
|
|
|
}
|
|
|
|
else if ($attendee['role'] != 'ORGANIZER' && $attendee['role'] != 'NON-PARTICIPANT' && $attendee['status'] != 'DELEGATED') {
|
|
|
|
$attendees[$i]['status'] = 'NEEDS-ACTION';
|
|
|
|
$attendees[$i]['rsvp'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update attendees only if I'm the organizer
|
|
|
|
if ($is_organizer || ($event['organizer'] && in_array(strtolower($event['organizer']['email']), $emails))) {
|
|
|
|
$event['attendees'] = $attendees;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $reschedule;
|
|
|
|
}
|
|
|
|
|
2015-02-17 11:36:01 +01:00
|
|
|
/**
|
|
|
|
* Apply the given changes to already existing exceptions
|
|
|
|
*/
|
|
|
|
protected function update_recurrence_exceptions(&$master, $event, $old, $savemode)
|
|
|
|
{
|
|
|
|
$saved = false;
|
|
|
|
$existing = null;
|
|
|
|
|
2015-02-18 11:30:16 +01:00
|
|
|
// determine added and removed attendees
|
|
|
|
$added_attendees = $removed_attendees = array();
|
|
|
|
if ($savemode == 'future') {
|
|
|
|
$old_attendees = $current_attendees = array();
|
|
|
|
foreach ((array)$old['attendees'] as $attendee) {
|
|
|
|
$old_attendees[] = $attendee['email'];
|
|
|
|
}
|
|
|
|
foreach ((array)$event['attendees'] as $attendee) {
|
|
|
|
$current_attendees[] = $attendee['email'];
|
|
|
|
if (!in_array($attendee['email'], $old_attendees)) {
|
|
|
|
$added_attendees[] = $attendee;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$removed_attendees = array_diff($old_attendees, $current_attendees);
|
|
|
|
}
|
|
|
|
|
2015-02-17 11:36:01 +01:00
|
|
|
foreach ($master['recurrence']['EXCEPTIONS'] as $i => $exception) {
|
|
|
|
// update a specific instance
|
|
|
|
if ($exception['_instance'] == $old['_instance']) {
|
|
|
|
$existing = $i;
|
|
|
|
|
|
|
|
// check savemode against existing exception mode.
|
|
|
|
// if matches, we can update this existing exception
|
|
|
|
if ((bool)$exception['thisandfuture'] === ($savemode == 'future')) {
|
|
|
|
$event['_instance'] = $old['_instance'];
|
|
|
|
$event['thisandfuture'] = $old['thisandfuture'];
|
|
|
|
$event['recurrence_date'] = $old['recurrence_date'];
|
|
|
|
$master['recurrence']['EXCEPTIONS'][$i] = $event;
|
|
|
|
$saved = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// merge the new event properties onto future exceptions
|
|
|
|
if ($savemode == 'future' && $exception['_instance'] >= $old['_instance']) {
|
|
|
|
unset($event['thisandfuture']);
|
2015-02-18 11:30:16 +01:00
|
|
|
self::merge_exception_data($master['recurrence']['EXCEPTIONS'][$i], $event, array('attendees'));
|
|
|
|
|
|
|
|
if (!empty($added_attendees) || !empty($removed_attendees)) {
|
2015-03-01 18:54:54 +01:00
|
|
|
calendar::merge_attendee_data($master['recurrence']['EXCEPTIONS'][$i], $added_attendees, $removed_attendees);
|
2015-02-18 11:30:16 +01:00
|
|
|
}
|
2015-02-17 11:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
// we could not update the existing exception due to savemode mismatch...
|
|
|
|
if (!$saved && $existing !== null && $master['recurrence']['EXCEPTIONS'][$existing]['thisandfuture']) {
|
|
|
|
// ... try to move the existing this-and-future exception to the next occurrence
|
|
|
|
foreach ($this->get_recurring_events($master, $existing['start']) as $candidate) {
|
|
|
|
// our old this-and-future exception is obsolete
|
|
|
|
if ($candidate['thisandfuture']) {
|
|
|
|
unset($master['recurrence']['EXCEPTIONS'][$existing]);
|
|
|
|
$saved = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// this occurrence doesn't yet have an exception
|
|
|
|
else if (!$candidate['isexception']) {
|
|
|
|
$event['_instance'] = $candidate['_instance'];
|
|
|
|
$event['recurrence_date'] = $candidate['recurrence_date'];
|
|
|
|
$master['recurrence']['EXCEPTIONS'][$i] = $event;
|
|
|
|
$saved = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2015-02-26 14:48:14 +01:00
|
|
|
// set link to top-level exceptions
|
|
|
|
$master['exceptions'] = &$master['recurrence']['EXCEPTIONS'];
|
|
|
|
|
2015-02-17 11:36:01 +01:00
|
|
|
// returning false here will add a new exception
|
|
|
|
return $saved;
|
|
|
|
}
|
|
|
|
|
2015-02-26 14:48:14 +01:00
|
|
|
/**
|
|
|
|
* Add or update the given event as an exception to $master
|
|
|
|
*/
|
|
|
|
public static function add_exception(&$master, $event, $old = null)
|
|
|
|
{
|
|
|
|
if ($old) {
|
|
|
|
$event['_instance'] = $old['_instance'];
|
|
|
|
if (!$event['recurrence_date'])
|
|
|
|
$event['recurrence_date'] = $old['recurrence_date'] ?: $old['start'];
|
|
|
|
}
|
|
|
|
else if (!$event['recurrence_date']) {
|
|
|
|
$event['recurrence_date'] = $event['start'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$event['_instance'] && is_a($event['recurrence_date'], 'DateTime')) {
|
2015-03-10 14:30:50 +01:00
|
|
|
$event['_instance'] = libcalendaring::recurrence_instance_identifier($event);
|
2015-02-26 14:48:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_array($master['exceptions']) && is_array($master['recurrence']['EXCEPTIONS'])) {
|
|
|
|
$master['exceptions'] = &$master['recurrence']['EXCEPTIONS'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$existing = false;
|
|
|
|
foreach ((array)$master['exceptions'] as $i => $exception) {
|
|
|
|
if ($exception['_instance'] == $event['_instance']) {
|
|
|
|
$master['exceptions'][$i] = $event;
|
|
|
|
$existing = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$existing) {
|
|
|
|
$master['exceptions'][] = $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-20 00:11:40 +01:00
|
|
|
/**
|
|
|
|
* Remove the noreply flags from attendees
|
|
|
|
*/
|
|
|
|
public static function clear_attandee_noreply(&$event)
|
|
|
|
{
|
|
|
|
foreach ((array)$event['attendees'] as $i => $attendee) {
|
|
|
|
unset($event['attendees'][$i]['noreply']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-17 11:36:01 +01:00
|
|
|
/**
|
|
|
|
* Merge certain properties from the overlay event to the base event object
|
|
|
|
*
|
|
|
|
* @param array The event object to be altered
|
|
|
|
* @param array The overlay event object to be merged over $event
|
2015-02-18 11:30:16 +01:00
|
|
|
* @param array List of properties not allowed to be overwritten
|
2015-02-17 11:36:01 +01:00
|
|
|
*/
|
2015-02-18 11:30:16 +01:00
|
|
|
public static function merge_exception_data(&$event, $overlay, $blacklist = null)
|
2015-02-17 11:36:01 +01:00
|
|
|
{
|
2015-02-18 11:30:16 +01:00
|
|
|
$forbidden = array('id','uid','recurrence','recurrence_date','thisandfuture','organizer','_attachments');
|
|
|
|
|
|
|
|
if (is_array($blacklist))
|
|
|
|
$forbidden = array_merge($forbidden, $blacklist);
|
2015-02-17 11:36:01 +01:00
|
|
|
|
2015-02-17 15:49:14 +01:00
|
|
|
// compute date offset from the exception
|
|
|
|
if ($overlay['start'] instanceof DateTime && $overlay['recurrence_date'] instanceof DateTime) {
|
|
|
|
$date_offset = $overlay['recurrence_date']->diff($overlay['start']);
|
|
|
|
}
|
|
|
|
|
2015-02-17 11:36:01 +01:00
|
|
|
foreach ($overlay as $prop => $value) {
|
|
|
|
if ($prop == 'start' || $prop == 'end') {
|
2015-02-17 15:49:14 +01:00
|
|
|
if (is_object($event[$prop]) && $event[$prop] instanceof DateTime) {
|
2015-02-17 11:36:01 +01:00
|
|
|
// set date value if overlay is an exception of the current instance
|
|
|
|
if (substr($overlay['_instance'], 0, 8) == substr($event['_instance'], 0, 8)) {
|
|
|
|
$event[$prop]->setDate(intval($value->format('Y')), intval($value->format('n')), intval($value->format('j')));
|
|
|
|
}
|
2015-02-17 15:49:14 +01:00
|
|
|
// apply date offset
|
|
|
|
else if ($date_offset) {
|
|
|
|
$event[$prop]->add($date_offset);
|
|
|
|
}
|
|
|
|
// adjust time of the recurring event instance
|
|
|
|
$event[$prop]->setTime($value->format('G'), intval($value->format('i')), intval($value->format('s')));
|
2015-02-17 11:36:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ($prop == 'thisandfuture' && $overlay['_instance'] == $event['_instance']) {
|
|
|
|
$event[$prop] = $value;
|
|
|
|
}
|
|
|
|
else if ($prop[0] != '_' && !in_array($prop, $forbidden))
|
|
|
|
$event[$prop] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
/**
|
|
|
|
* Get events from source.
|
|
|
|
*
|
|
|
|
* @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)
|
2011-07-16 20:03:19 +02:00
|
|
|
* @param mixed List of calendar IDs to load events from (either as array or comma-separated string)
|
2013-10-21 20:24:49 +02:00
|
|
|
* @param boolean Include virtual events (optional)
|
|
|
|
* @param integer Only list events modified since this time (unix timestamp)
|
2011-05-20 19:04:25 +02:00
|
|
|
* @return array A list of event records
|
|
|
|
*/
|
2013-10-21 20:24:49 +02:00
|
|
|
public function load_events($start, $end, $search = null, $calendars = null, $virtual = 1, $modifiedsince = null)
|
2011-05-20 19:04:25 +02:00
|
|
|
{
|
|
|
|
if ($calendars && is_string($calendars))
|
|
|
|
$calendars = explode(',', $calendars);
|
2016-02-12 16:27:19 +01:00
|
|
|
else if (!$calendars) {
|
|
|
|
$this->_read_calendars();
|
2014-05-13 17:09:53 +02:00
|
|
|
$calendars = array_keys($this->calendars);
|
2016-02-12 16:27:19 +01:00
|
|
|
}
|
2011-06-28 10:32:52 +02:00
|
|
|
|
2013-10-21 20:24:49 +02:00
|
|
|
$query = array();
|
|
|
|
if ($modifiedsince)
|
|
|
|
$query[] = array('changed', '>=', $modifiedsince);
|
|
|
|
|
2011-09-14 16:02:07 +02:00
|
|
|
$events = $categories = array();
|
2014-05-13 17:09:53 +02:00
|
|
|
foreach ($calendars as $cid) {
|
|
|
|
if ($storage = $this->get_calendar($cid)) {
|
|
|
|
$events = array_merge($events, $storage->list_events($start, $end, $search, $virtual, $query));
|
|
|
|
$categories += $storage->categories;
|
|
|
|
}
|
2011-09-14 16:02:07 +02:00
|
|
|
}
|
2014-01-27 19:12:29 +01:00
|
|
|
|
|
|
|
// add events from the address books birthday calendar
|
|
|
|
if (in_array(self::BIRTHDAY_CALENDAR_ID, $calendars)) {
|
2014-01-28 15:55:45 +01:00
|
|
|
$events = array_merge($events, $this->load_birthday_events($start, $end, $search, $modifiedsince));
|
2014-01-27 19:12:29 +01:00
|
|
|
}
|
|
|
|
|
2011-09-14 16:02:07 +02:00
|
|
|
// add new categories to user prefs
|
2013-05-07 10:58:39 +02:00
|
|
|
$old_categories = $this->rc->config->get('calendar_categories', $this->default_categories);
|
2014-04-03 10:20:05 +02:00
|
|
|
if ($newcats = array_udiff(array_keys($categories), array_keys($old_categories), function($a, $b){ return strcasecmp($a, $b); })) {
|
2011-09-14 16:02:07 +02:00
|
|
|
foreach ($newcats as $category)
|
|
|
|
$old_categories[$category] = ''; // no color set yet
|
|
|
|
$this->rc->user->save_prefs(array('calendar_categories' => $old_categories));
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
2011-06-28 10:32:52 +02:00
|
|
|
|
2015-02-27 17:52:17 +01:00
|
|
|
array_walk($events, 'kolab_driver::to_rcube_event');
|
2011-05-20 19:04:25 +02:00
|
|
|
return $events;
|
|
|
|
}
|
|
|
|
|
2014-10-14 20:23:52 +02:00
|
|
|
/**
|
|
|
|
* Get number of events in the given calendar
|
|
|
|
*
|
|
|
|
* @param mixed List of calendar IDs to count events (either as array or comma-separated string)
|
|
|
|
* @param integer Date range start (unix timestamp)
|
|
|
|
* @param integer Date range end (unix timestamp)
|
|
|
|
* @return array Hash array with counts grouped by calendar ID
|
|
|
|
*/
|
|
|
|
public function count_events($calendars, $start, $end = null)
|
|
|
|
{
|
|
|
|
$counts = array();
|
|
|
|
|
|
|
|
if ($calendars && is_string($calendars))
|
|
|
|
$calendars = explode(',', $calendars);
|
2016-02-12 16:27:19 +01:00
|
|
|
else if (!$calendars) {
|
|
|
|
$this->_read_calendars();
|
2014-10-14 20:23:52 +02:00
|
|
|
$calendars = array_keys($this->calendars);
|
2016-02-12 16:27:19 +01:00
|
|
|
}
|
2014-10-14 20:23:52 +02:00
|
|
|
|
|
|
|
foreach ($calendars as $cid) {
|
|
|
|
if ($storage = $this->get_calendar($cid)) {
|
|
|
|
$counts[$cid] = $storage->count_events($start, $end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $counts;
|
|
|
|
}
|
|
|
|
|
2011-05-22 18:45:04 +02:00
|
|
|
/**
|
|
|
|
* Get a list of pending alarms to be displayed to the user
|
|
|
|
*
|
2011-07-27 16:06:06 +02:00
|
|
|
* @see calendar_driver::pending_alarms()
|
2011-05-22 18:45:04 +02:00
|
|
|
*/
|
|
|
|
public function pending_alarms($time, $calendars = null)
|
|
|
|
{
|
2011-07-11 19:01:56 +02:00
|
|
|
$interval = 300;
|
|
|
|
$time -= $time % 60;
|
|
|
|
|
|
|
|
$slot = $time;
|
|
|
|
$slot -= $slot % $interval;
|
|
|
|
|
2012-11-17 09:49:57 +01:00
|
|
|
$last = $time - max(60, $this->rc->config->get('refresh_interval', 0));
|
2011-07-11 19:01:56 +02:00
|
|
|
$last -= $last % $interval;
|
|
|
|
|
|
|
|
// only check for alerts once in 5 minutes
|
|
|
|
if ($last == $slot)
|
2012-08-04 16:48:31 +02:00
|
|
|
return array();
|
2011-07-11 19:01:56 +02:00
|
|
|
|
2011-07-07 08:23:49 +02:00
|
|
|
if ($calendars && is_string($calendars))
|
|
|
|
$calendars = explode(',', $calendars);
|
2011-07-11 19:01:56 +02:00
|
|
|
|
|
|
|
$time = $slot + $interval;
|
|
|
|
|
2014-04-17 17:49:00 +02:00
|
|
|
$candidates = array();
|
2012-05-30 09:13:24 +02:00
|
|
|
$query = array(array('tags', '=', 'x-has-alarms'));
|
2016-02-12 16:27:19 +01:00
|
|
|
|
|
|
|
$this->_read_calendars();
|
|
|
|
|
2011-07-07 08:23:49 +02:00
|
|
|
foreach ($this->calendars as $cid => $calendar) {
|
|
|
|
// skip calendars with alarms disabled
|
|
|
|
if (!$calendar->alarms || ($calendars && !in_array($cid, $calendars)))
|
|
|
|
continue;
|
|
|
|
|
2012-05-16 18:36:03 +02:00
|
|
|
foreach ($calendar->list_events($time, $time + 86400 * 365, null, 1, $query) as $e) {
|
2011-07-07 08:23:49 +02:00
|
|
|
// add to list if alarm is set
|
2012-08-16 19:03:17 +02:00
|
|
|
$alarm = libcalendaring::get_next_alarm($e);
|
2014-05-20 12:05:52 +02:00
|
|
|
if ($alarm && $alarm['time'] && $alarm['time'] >= $last && in_array($alarm['action'], $this->alarm_types)) {
|
2014-04-17 17:49:00 +02:00
|
|
|
$id = $alarm['id']; // use alarm-id as primary identifier
|
|
|
|
$candidates[$id] = array(
|
|
|
|
'id' => $id,
|
|
|
|
'title' => $e['title'],
|
|
|
|
'location' => $e['location'],
|
|
|
|
'start' => $e['start'],
|
|
|
|
'end' => $e['end'],
|
|
|
|
'notifyat' => $alarm['time'],
|
|
|
|
'action' => $alarm['action'],
|
|
|
|
);
|
2011-07-07 08:23:49 +02:00
|
|
|
}
|
2011-06-27 11:47:52 -04:00
|
|
|
}
|
|
|
|
}
|
2011-06-28 10:36:11 +02:00
|
|
|
|
2011-06-27 11:47:52 -04:00
|
|
|
// get alarm information stored in local database
|
2014-04-17 17:49:00 +02:00
|
|
|
if (!empty($candidates)) {
|
|
|
|
$alarm_ids = array_map(array($this->rc->db, 'quote'), array_keys($candidates));
|
2014-09-15 12:23:46 +02:00
|
|
|
$result = $this->rc->db->query("SELECT *"
|
|
|
|
. " FROM " . $this->rc->db->table_name('kolab_alarms', true)
|
|
|
|
. " WHERE `alarm_id` IN (" . join(',', $alarm_ids) . ")"
|
|
|
|
. " AND `user_id` = ?",
|
|
|
|
$this->rc->user->ID
|
|
|
|
);
|
2011-06-27 11:47:52 -04:00
|
|
|
|
|
|
|
while ($result && ($e = $this->rc->db->fetch_assoc($result))) {
|
2014-04-17 17:49:00 +02:00
|
|
|
$dbdata[$e['alarm_id']] = $e;
|
2011-06-27 11:47:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$alarms = array();
|
2014-04-17 17:49:00 +02:00
|
|
|
foreach ($candidates as $id => $alarm) {
|
|
|
|
// skip dismissed alarms
|
2011-06-27 11:47:52 -04:00
|
|
|
if ($dbdata[$id]['dismissed'])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// snooze function may have shifted alarm time
|
2014-04-17 17:49:00 +02:00
|
|
|
$notifyat = $dbdata[$id]['notifyat'] ? strtotime($dbdata[$id]['notifyat']) : $alarm['notifyat'];
|
2011-06-27 11:47:52 -04:00
|
|
|
if ($notifyat <= $time)
|
2014-04-17 17:49:00 +02:00
|
|
|
$alarms[] = $alarm;
|
2011-06-27 11:47:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return $alarms;
|
2011-05-22 18:45:04 +02:00
|
|
|
}
|
|
|
|
|
2011-05-23 21:00:14 +02:00
|
|
|
/**
|
|
|
|
* Feedback after showing/sending an alarm notification
|
|
|
|
*
|
2011-07-27 16:06:06 +02:00
|
|
|
* @see calendar_driver::dismiss_alarm()
|
2011-05-23 21:00:14 +02:00
|
|
|
*/
|
2014-04-17 17:49:00 +02:00
|
|
|
public function dismiss_alarm($alarm_id, $snooze = 0)
|
2011-05-23 21:00:14 +02:00
|
|
|
{
|
2014-09-15 12:23:46 +02:00
|
|
|
$alarms_table = $this->rc->db->table_name('kolab_alarms', true);
|
2012-04-24 10:14:01 +02:00
|
|
|
// delete old alarm entry
|
2014-09-15 12:23:46 +02:00
|
|
|
$this->rc->db->query("DELETE FROM $alarms_table"
|
|
|
|
. " WHERE `alarm_id` = ? AND `user_id` = ?",
|
|
|
|
$alarm_id,
|
|
|
|
$this->rc->user->ID
|
2012-05-16 18:58:57 +02:00
|
|
|
);
|
2012-04-24 10:14:01 +02:00
|
|
|
|
2011-06-27 11:47:52 -04:00
|
|
|
// set new notifyat time or unset if not snoozed
|
|
|
|
$notifyat = $snooze > 0 ? date('Y-m-d H:i:s', time() + $snooze) : null;
|
2012-04-24 10:14:01 +02:00
|
|
|
|
2014-09-15 12:23:46 +02:00
|
|
|
$query = $this->rc->db->query("INSERT INTO $alarms_table"
|
|
|
|
. " (`alarm_id`, `user_id`, `dismissed`, `notifyat`)"
|
|
|
|
. " VALUES (?, ?, ?, ?)",
|
2014-04-17 17:49:00 +02:00
|
|
|
$alarm_id,
|
2012-05-16 18:58:57 +02:00
|
|
|
$this->rc->user->ID,
|
2012-04-24 10:14:01 +02:00
|
|
|
$snooze > 0 ? 0 : 1,
|
2011-06-28 08:45:05 +02:00
|
|
|
$notifyat
|
2011-06-27 11:47:52 -04:00
|
|
|
);
|
2014-09-15 12:23:46 +02:00
|
|
|
|
2011-06-27 11:47:52 -04:00
|
|
|
return $this->rc->db->affected_rows($query);
|
2011-05-23 21:00:14 +02:00
|
|
|
}
|
2011-07-01 21:08:12 +02:00
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
/**
|
2011-07-01 21:08:12 +02:00
|
|
|
* List attachments from the given event
|
2011-05-20 19:04:25 +02:00
|
|
|
*/
|
2011-07-01 21:08:12 +02:00
|
|
|
public function list_attachments($event)
|
2011-05-20 19:04:25 +02:00
|
|
|
{
|
2014-05-13 17:09:53 +02:00
|
|
|
if (!($storage = $this->get_calendar($event['calendar'])))
|
2011-07-01 21:08:12 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
$event = $storage->get_event($event['id']);
|
|
|
|
|
|
|
|
return $event['attachments'];
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-07-01 21:08:12 +02:00
|
|
|
* Get attachment properties
|
2011-05-20 19:04:25 +02:00
|
|
|
*/
|
2011-07-01 21:08:12 +02:00
|
|
|
public function get_attachment($id, $event)
|
2011-05-20 19:04:25 +02:00
|
|
|
{
|
2014-05-13 17:09:53 +02:00
|
|
|
if (!($storage = $this->get_calendar($event['calendar'])))
|
2011-07-01 21:08:12 +02:00
|
|
|
return false;
|
|
|
|
|
2015-03-18 20:23:58 +01:00
|
|
|
// get old revision of event
|
|
|
|
if ($event['rev']) {
|
|
|
|
$event = $this->get_event_revison($event, $event['rev'], true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$event = $storage->get_event($event['id']);
|
|
|
|
}
|
2011-07-01 21:08:12 +02:00
|
|
|
|
2015-02-27 17:52:17 +01:00
|
|
|
if ($event && !empty($event['_attachments'])) {
|
|
|
|
foreach ($event['_attachments'] as $att) {
|
2011-07-01 21:08:12 +02:00
|
|
|
if ($att['id'] == $id) {
|
|
|
|
return $att;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
|
|
|
|
2011-07-01 21:08:12 +02:00
|
|
|
/**
|
|
|
|
* Get attachment body
|
2012-04-25 19:26:40 +02:00
|
|
|
* @see calendar_driver::get_attachment_body()
|
2011-07-01 21:08:12 +02:00
|
|
|
*/
|
|
|
|
public function get_attachment_body($id, $event)
|
|
|
|
{
|
2014-05-13 17:09:53 +02:00
|
|
|
if (!($cal = $this->get_calendar($event['calendar'])))
|
2011-07-01 21:08:12 +02:00
|
|
|
return false;
|
|
|
|
|
2015-03-18 20:23:58 +01:00
|
|
|
// get old revision of event
|
|
|
|
if ($event['rev']) {
|
|
|
|
if (empty($this->bonnie_api)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cid = substr($id, 4);
|
|
|
|
|
|
|
|
// call Bonnie API and get the raw mime message
|
|
|
|
list($uid, $mailbox, $msguid) = $this->_resolve_event_identity($event);
|
|
|
|
if ($msg_raw = $this->bonnie_api->rawdata('event', $uid, $event['rev'], $mailbox, $msguid)) {
|
|
|
|
// parse the message and find the part with the matching content-id
|
|
|
|
$message = rcube_mime::parse_message($msg_raw);
|
|
|
|
foreach ((array)$message->parts as $part) {
|
|
|
|
if ($part->headers['content-id'] && trim($part->headers['content-id'], '<>') == $cid) {
|
|
|
|
return $part->body;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-24 12:49:05 +01:00
|
|
|
return $cal->get_attachment_body($id, $event);
|
2011-07-01 21:08:12 +02:00
|
|
|
}
|
2011-05-20 19:04:25 +02:00
|
|
|
|
2015-01-14 09:27:48 +01:00
|
|
|
/**
|
|
|
|
* Build a struct representing the given message reference
|
|
|
|
*
|
|
|
|
* @see calendar_driver::get_message_reference()
|
|
|
|
*/
|
|
|
|
public function get_message_reference($uri_or_headers, $folder = null)
|
|
|
|
{
|
|
|
|
if (is_object($uri_or_headers)) {
|
|
|
|
$uri_or_headers = kolab_storage_config::get_message_uri($uri_or_headers, $folder);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_string($uri_or_headers)) {
|
|
|
|
return kolab_storage_config::get_message_reference($uri_or_headers, 'event');
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
/**
|
2011-05-26 15:44:46 +02:00
|
|
|
* List availabale categories
|
|
|
|
* The default implementation reads them from config/user prefs
|
2011-05-20 19:04:25 +02:00
|
|
|
*/
|
2011-05-26 15:44:46 +02:00
|
|
|
public function list_categories()
|
2011-05-20 19:04:25 +02:00
|
|
|
{
|
2011-09-14 16:02:07 +02:00
|
|
|
// FIXME: complete list with categories saved in config objects (KEP:12)
|
2013-05-07 10:58:39 +02:00
|
|
|
return $this->rc->config->get('calendar_categories', $this->default_categories);
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
|
|
|
|
2015-02-02 13:12:56 +01:00
|
|
|
/**
|
|
|
|
* Create instances of a recurring event
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
* @return array List of recurring event instances
|
|
|
|
*/
|
|
|
|
public function get_recurring_events($event, $start, $end = null)
|
|
|
|
{
|
|
|
|
// load the given event data into a libkolabxml container
|
|
|
|
if (!$event['_formatobj']) {
|
|
|
|
$event_xml = new kolab_format_event();
|
|
|
|
$event_xml->set($event);
|
|
|
|
$event['_formatobj'] = $event_xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->_read_calendars();
|
|
|
|
$storage = reset($this->calendars);
|
|
|
|
return $storage->get_recurring_events($event, $start, $end);
|
|
|
|
}
|
|
|
|
|
2015-02-20 00:11:40 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
private function get_recurrence_count($event, $dtstart)
|
|
|
|
{
|
|
|
|
// use libkolab to compute recurring events
|
2015-02-20 11:54:33 +01:00
|
|
|
if (class_exists('kolabcalendaring') && $event['_formatobj']) {
|
|
|
|
$recurrence = new kolab_date_recurrence($event['_formatobj']);
|
2015-02-20 00:11:40 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// fallback to local recurrence implementation
|
|
|
|
require_once($this->cal->home . '/lib/calendar_recurrence.php');
|
|
|
|
$recurrence = new calendar_recurrence($this->cal, $event);
|
|
|
|
}
|
|
|
|
|
|
|
|
$count = 0;
|
|
|
|
while (($next_event = $recurrence->next_instance()) && $next_event['start'] <= $dtstart && $count < 1000) {
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $count;
|
|
|
|
}
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
/**
|
|
|
|
* Fetch free/busy information from a person within the given range
|
|
|
|
*/
|
|
|
|
public function get_freebusy_list($email, $start, $end)
|
|
|
|
{
|
2011-07-14 10:57:07 +02:00
|
|
|
if (empty($email)/* || $end < time()*/)
|
2011-07-08 17:29:22 +02:00
|
|
|
return false;
|
2011-08-04 11:56:13 +02:00
|
|
|
|
2011-07-23 12:18:29 +02:00
|
|
|
// map vcalendar fbtypes to internal values
|
|
|
|
$fbtypemap = array(
|
|
|
|
'FREE' => calendar::FREEBUSY_FREE,
|
|
|
|
'BUSY-TENTATIVE' => calendar::FREEBUSY_TENTATIVE,
|
|
|
|
'X-OUT-OF-OFFICE' => calendar::FREEBUSY_OOF,
|
|
|
|
'OOF' => calendar::FREEBUSY_OOF);
|
2011-08-04 11:56:13 +02:00
|
|
|
|
2011-07-16 17:14:36 +02:00
|
|
|
// ask kolab server first
|
2012-06-04 22:19:57 +02:00
|
|
|
try {
|
2013-09-26 14:53:52 +02:00
|
|
|
$request_config = array(
|
2012-06-04 22:19:57 +02:00
|
|
|
'store_body' => true,
|
|
|
|
'follow_redirects' => true,
|
2013-09-26 14:53:52 +02:00
|
|
|
);
|
|
|
|
$request = libkolab::http_request(kolab_storage::get_freebusy_url($email), 'GET', $request_config);
|
2012-06-04 22:19:57 +02:00
|
|
|
$response = $request->send();
|
|
|
|
|
|
|
|
// authentication required
|
|
|
|
if ($response->getStatus() == 401) {
|
|
|
|
$request->setAuth($this->rc->user->get_username(), $this->rc->decrypt($_SESSION['password']));
|
|
|
|
$response = $request->send();
|
|
|
|
}
|
2012-05-08 08:34:29 +02:00
|
|
|
|
2012-06-04 22:19:57 +02:00
|
|
|
if ($response->getStatus() == 200)
|
|
|
|
$fbdata = $response->getBody();
|
2012-05-08 08:34:29 +02:00
|
|
|
|
2012-06-04 22:19:57 +02:00
|
|
|
unset($request, $response);
|
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
PEAR::raiseError("Error fetching free/busy information: " . $e->getMessage());
|
|
|
|
}
|
2011-07-23 12:18:29 +02:00
|
|
|
|
2011-07-16 17:14:36 +02:00
|
|
|
// get free-busy url from contacts
|
|
|
|
if (!$fbdata) {
|
|
|
|
$fburl = null;
|
|
|
|
foreach ((array)$this->rc->config->get('autocomplete_addressbooks', 'sql') as $book) {
|
|
|
|
$abook = $this->rc->get_address_book($book);
|
2011-08-04 11:56:13 +02:00
|
|
|
|
2011-07-16 17:14:36 +02:00
|
|
|
if ($result = $abook->search(array('email'), $email, true, true, true/*, 'freebusyurl'*/)) {
|
|
|
|
while ($contact = $result->iterate()) {
|
|
|
|
if ($fburl = $contact['freebusyurl']) {
|
|
|
|
$fbdata = @file_get_contents($fburl);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-04 11:56:13 +02:00
|
|
|
|
2011-07-16 17:14:36 +02:00
|
|
|
if ($fbdata)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-08-04 11:56:13 +02:00
|
|
|
|
2011-07-16 17:14:36 +02:00
|
|
|
// parse free-busy information using Horde classes
|
|
|
|
if ($fbdata) {
|
2013-08-25 12:37:07 +02:00
|
|
|
$ical = $this->cal->get_ical();
|
|
|
|
$ical->import($fbdata);
|
|
|
|
if ($fb = $ical->freebusy) {
|
2011-07-08 17:29:22 +02:00
|
|
|
$result = array();
|
2013-08-25 12:37:07 +02:00
|
|
|
foreach ($fb['periods'] as $tuple) {
|
|
|
|
list($from, $to, $type) = $tuple;
|
|
|
|
$result[] = array($from->format('U'), $to->format('U'), isset($fbtypemap[$type]) ? $fbtypemap[$type] : calendar::FREEBUSY_BUSY);
|
2011-07-08 17:29:22 +02:00
|
|
|
}
|
2011-07-27 10:48:40 +02:00
|
|
|
|
2012-10-04 14:46:27 +02:00
|
|
|
// we take 'dummy' free-busy lists as "unknown"
|
2013-08-25 12:37:07 +02:00
|
|
|
if (empty($result) && !empty($fb['comment']) && stripos($fb['comment'], 'dummy'))
|
2012-10-04 14:46:27 +02:00
|
|
|
return false;
|
|
|
|
|
2011-07-27 10:48:40 +02:00
|
|
|
// set period from $start till the begin of the free-busy information as 'unknown'
|
2013-08-25 12:37:07 +02:00
|
|
|
if ($fb['start'] && ($fbstart = $fb['start']->format('U')) && $start < $fbstart) {
|
2011-07-27 10:48:40 +02:00
|
|
|
array_unshift($result, array($start, $fbstart, calendar::FREEBUSY_UNKNOWN));
|
|
|
|
}
|
2011-07-29 13:16:13 +02:00
|
|
|
// pad period till $end with status 'unknown'
|
2013-08-25 12:37:07 +02:00
|
|
|
if ($fb['end'] && ($fbend = $fb['end']->format('U')) && $fbend < $end) {
|
2011-07-29 13:16:13 +02:00
|
|
|
$result[] = array($fbend, $end, calendar::FREEBUSY_UNKNOWN);
|
|
|
|
}
|
2012-10-04 14:46:27 +02:00
|
|
|
|
2011-07-08 17:29:22 +02:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
2011-08-04 11:56:13 +02:00
|
|
|
|
2011-07-08 17:29:22 +02:00
|
|
|
return false;
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
2011-08-04 11:56:13 +02:00
|
|
|
|
2011-07-16 17:14:36 +02:00
|
|
|
/**
|
|
|
|
* Handler to push folder triggers when sent from client.
|
|
|
|
* Used to push free-busy changes asynchronously after updating an event
|
|
|
|
*/
|
|
|
|
public function push_freebusy()
|
|
|
|
{
|
|
|
|
// make shure triggering completes
|
|
|
|
set_time_limit(0);
|
|
|
|
ignore_user_abort(true);
|
|
|
|
|
2014-10-06 09:19:26 +02:00
|
|
|
$cal = rcube_utils::get_input_value('source', rcube_utils::INPUT_GPC);
|
2014-05-13 17:09:53 +02:00
|
|
|
if (!($cal = $this->get_calendar($cal)))
|
2011-07-16 17:14:36 +02:00
|
|
|
return false;
|
2011-08-04 11:56:13 +02:00
|
|
|
|
2011-07-16 17:14:36 +02:00
|
|
|
// trigger updates on folder
|
2012-03-30 19:14:38 +02:00
|
|
|
$trigger = $cal->storage->trigger();
|
2011-09-10 13:40:56 +02:00
|
|
|
if (is_object($trigger) && is_a($trigger, 'PEAR_Error')) {
|
2012-11-06 11:46:15 +01:00
|
|
|
rcube::raise_error(array(
|
2011-07-16 17:14:36 +02:00
|
|
|
'code' => 900, 'type' => 'php',
|
|
|
|
'file' => __FILE__, 'line' => __LINE__,
|
|
|
|
'message' => "Failed triggering folder. Error was " . $trigger->getMessage()),
|
|
|
|
true, false);
|
|
|
|
}
|
2011-07-26 13:13:04 +02:00
|
|
|
|
2011-07-16 17:14:36 +02:00
|
|
|
exit;
|
|
|
|
}
|
2011-05-20 19:04:25 +02:00
|
|
|
|
2014-07-29 15:28:35 +02:00
|
|
|
|
|
|
|
/**
|
2015-02-27 17:52:17 +01:00
|
|
|
* Convert from driver format to external caledar app data
|
2014-07-29 15:28:35 +02:00
|
|
|
*/
|
2015-02-27 17:52:17 +01:00
|
|
|
public static function to_rcube_event(&$record)
|
2014-07-29 15:28:35 +02:00
|
|
|
{
|
2015-02-27 17:52:17 +01:00
|
|
|
if (!is_array($record))
|
|
|
|
return $record;
|
|
|
|
|
2014-07-29 15:28:35 +02:00
|
|
|
$record['id'] = $record['uid'];
|
|
|
|
|
2015-02-27 17:52:17 +01:00
|
|
|
if ($record['_instance']) {
|
|
|
|
$record['id'] .= '-' . $record['_instance'];
|
|
|
|
|
|
|
|
if (!$record['recurrence_id'] && !empty($record['recurrence']))
|
|
|
|
$record['recurrence_id'] = $record['uid'];
|
|
|
|
}
|
|
|
|
|
2014-07-29 15:28:35 +02:00
|
|
|
// all-day events go from 12:00 - 13:00
|
2015-01-08 13:46:20 +01:00
|
|
|
if (is_a($record['start'], 'DateTime') && $record['end'] <= $record['start'] && $record['allday']) {
|
2014-07-29 15:28:35 +02:00
|
|
|
$record['end'] = clone $record['start'];
|
|
|
|
$record['end']->add(new DateInterval('PT1H'));
|
|
|
|
}
|
|
|
|
|
2015-02-20 11:54:33 +01:00
|
|
|
// translate internal '_attachments' to external 'attachments' list
|
2014-07-29 15:28:35 +02:00
|
|
|
if (!empty($record['_attachments'])) {
|
|
|
|
foreach ($record['_attachments'] as $key => $attachment) {
|
|
|
|
if ($attachment !== false) {
|
|
|
|
if (!$attachment['name'])
|
|
|
|
$attachment['name'] = $key;
|
|
|
|
|
|
|
|
unset($attachment['path'], $attachment['content']);
|
|
|
|
$attachments[] = $attachment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$record['attachments'] = $attachments;
|
|
|
|
}
|
|
|
|
|
2014-08-06 15:21:32 +02:00
|
|
|
if (!empty($record['attendees'])) {
|
|
|
|
foreach ((array)$record['attendees'] as $i => $attendee) {
|
|
|
|
if (is_array($attendee['delegated-from'])) {
|
|
|
|
$record['attendees'][$i]['delegated-from'] = join(', ', $attendee['delegated-from']);
|
|
|
|
}
|
|
|
|
if (is_array($attendee['delegated-to'])) {
|
|
|
|
$record['attendees'][$i]['delegated-to'] = join(', ', $attendee['delegated-to']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-29 15:28:35 +02:00
|
|
|
// Roundcube only supports one category assignment
|
|
|
|
if (is_array($record['categories']))
|
|
|
|
$record['categories'] = $record['categories'][0];
|
|
|
|
|
|
|
|
// the cancelled flag transltes into status=CANCELLED
|
|
|
|
if ($record['cancelled'])
|
|
|
|
$record['status'] = 'CANCELLED';
|
|
|
|
|
|
|
|
// The web client only supports DISPLAY type of alarms
|
|
|
|
if (!empty($record['alarms']))
|
|
|
|
$record['alarms'] = preg_replace('/:[A-Z]+$/', ':DISPLAY', $record['alarms']);
|
|
|
|
|
|
|
|
// remove empty recurrence array
|
|
|
|
if (empty($record['recurrence']))
|
|
|
|
unset($record['recurrence']);
|
|
|
|
|
2015-02-20 00:11:40 +01:00
|
|
|
// clean up exception data
|
|
|
|
if (is_array($record['recurrence']['EXCEPTIONS'])) {
|
|
|
|
array_walk($record['recurrence']['EXCEPTIONS'], function(&$exception) {
|
|
|
|
unset($exception['_mailbox'], $exception['_msguid'], $exception['_formatobj'], $exception['_attachments']);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-02-20 11:54:33 +01:00
|
|
|
unset($record['_mailbox'], $record['_msguid'], $record['_type'], $record['_size'],
|
2015-02-26 14:48:14 +01:00
|
|
|
$record['_formatobj'], $record['_attachments'], $record['exceptions'], $record['x-custom']);
|
2015-02-27 17:52:17 +01:00
|
|
|
|
|
|
|
return $record;
|
2015-02-20 11:54:33 +01:00
|
|
|
}
|
|
|
|
|
2015-02-20 00:11:40 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function from_rcube_event($event, $old = array())
|
|
|
|
{
|
|
|
|
// in kolab_storage attachments are indexed by content-id
|
2015-02-27 17:52:17 +01:00
|
|
|
if (is_array($event['attachments']) || !empty($event['deleted_attachments'])) {
|
2015-02-20 00:11:40 +01:00
|
|
|
$event['_attachments'] = array();
|
|
|
|
|
|
|
|
foreach ($event['attachments'] as $attachment) {
|
|
|
|
$key = null;
|
|
|
|
// Roundcube ID has nothing to do with the storage ID, remove it
|
|
|
|
if ($attachment['content'] || $attachment['path']) {
|
|
|
|
unset($attachment['id']);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach ((array)$old['_attachments'] as $cid => $oldatt) {
|
|
|
|
if ($attachment['id'] == $oldatt['id'])
|
|
|
|
$key = $cid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// flagged for deletion => set to false
|
2015-02-27 17:52:17 +01:00
|
|
|
if ($attachment['_deleted'] || in_array($attachment['id'], (array)$event['deleted_attachments'])) {
|
2015-02-20 00:11:40 +01:00
|
|
|
$event['_attachments'][$key] = false;
|
|
|
|
}
|
|
|
|
// replace existing entry
|
|
|
|
else if ($key) {
|
|
|
|
$event['_attachments'][$key] = $attachment;
|
|
|
|
}
|
|
|
|
// append as new attachment
|
|
|
|
else {
|
|
|
|
$event['_attachments'][] = $attachment;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-27 17:52:17 +01:00
|
|
|
$event['_attachments'] = array_merge((array)$old['_attachments'], $event['_attachments']);
|
|
|
|
|
|
|
|
// attachments flagged for deletion => set to false
|
|
|
|
foreach ($event['_attachments'] as $key => $attachment) {
|
|
|
|
if ($attachment['_deleted'] || in_array($attachment['id'], (array)$event['deleted_attachments'])) {
|
|
|
|
$event['_attachments'][$key] = false;
|
|
|
|
}
|
|
|
|
}
|
2015-02-20 00:11:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-21 17:05:16 +01:00
|
|
|
/**
|
|
|
|
* Set CSS class according to the event's attendde partstat
|
|
|
|
*/
|
|
|
|
public static function add_partstat_class($event, $partstats, $user = null)
|
|
|
|
{
|
|
|
|
// set classes according to PARTSTAT
|
|
|
|
if (is_array($event['attendees'])) {
|
|
|
|
$user_emails = libcalendaring::get_instance()->get_user_emails($user);
|
|
|
|
$partstat = 'UNKNOWN';
|
|
|
|
foreach ($event['attendees'] as $attendee) {
|
|
|
|
if (in_array($attendee['email'], $user_emails)) {
|
|
|
|
$partstat = $attendee['status'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in_array($partstat, $partstats)) {
|
|
|
|
$event['className'] = trim($event['className'] . ' fc-invitation-' . strtolower($partstat));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $event;
|
|
|
|
}
|
|
|
|
|
2014-07-29 15:28:35 +02:00
|
|
|
/**
|
|
|
|
* Provide a list of revisions for the given event
|
|
|
|
*
|
|
|
|
* @param array $event Hash array with event properties
|
|
|
|
*
|
|
|
|
* @return array List of changes, each as a hash array
|
|
|
|
* @see calendar_driver::get_event_changelog()
|
|
|
|
*/
|
|
|
|
public function get_event_changelog($event)
|
|
|
|
{
|
|
|
|
if (empty($this->bonnie_api)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-18 20:23:58 +01:00
|
|
|
list($uid, $mailbox, $msguid) = $this->_resolve_event_identity($event);
|
2014-07-29 15:28:35 +02:00
|
|
|
|
2015-03-18 20:23:58 +01:00
|
|
|
$result = $this->bonnie_api->changelog('event', $uid, $mailbox, $msguid);
|
2014-07-29 15:28:35 +02:00
|
|
|
if (is_array($result) && $result['uid'] == $uid) {
|
|
|
|
return $result['changes'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of property changes beteen two revisions of an event
|
|
|
|
*
|
|
|
|
* @param array $event Hash array with event properties
|
2015-03-18 12:57:36 +01:00
|
|
|
* @param mixed $rev1 Old Revision
|
|
|
|
* @param mixed $rev2 New Revision
|
2014-07-29 15:28:35 +02:00
|
|
|
*
|
|
|
|
* @return array List of property changes, each as a hash array
|
|
|
|
* @see calendar_driver::get_event_diff()
|
|
|
|
*/
|
2015-03-18 12:57:36 +01:00
|
|
|
public function get_event_diff($event, $rev1, $rev2)
|
2014-07-29 15:28:35 +02:00
|
|
|
{
|
|
|
|
if (empty($this->bonnie_api)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-18 20:23:58 +01:00
|
|
|
list($uid, $mailbox, $msguid) = $this->_resolve_event_identity($event);
|
2014-07-29 15:28:35 +02:00
|
|
|
|
2015-03-19 12:34:08 +01:00
|
|
|
// get diff for the requested recurrence instance
|
|
|
|
$instance_id = $event['id'] != $uid ? substr($event['id'], strlen($uid) + 1) : null;
|
|
|
|
|
2014-07-29 15:28:35 +02:00
|
|
|
// call Bonnie API
|
2015-03-19 12:34:08 +01:00
|
|
|
$result = $this->bonnie_api->diff('event', $uid, $rev1, $rev2, $mailbox, $msguid, $instance_id);
|
2014-07-29 15:28:35 +02:00
|
|
|
if (is_array($result) && $result['uid'] == $uid) {
|
2015-03-18 12:57:36 +01:00
|
|
|
$result['rev1'] = $rev1;
|
|
|
|
$result['rev2'] = $rev2;
|
2014-07-29 15:28:35 +02:00
|
|
|
|
|
|
|
$keymap = array(
|
|
|
|
'dtstart' => 'start',
|
|
|
|
'dtend' => 'end',
|
|
|
|
'dstamp' => 'changed',
|
|
|
|
'summary' => 'title',
|
|
|
|
'alarm' => 'alarms',
|
|
|
|
'attendee' => 'attendees',
|
|
|
|
'attach' => 'attachments',
|
|
|
|
'rrule' => 'recurrence',
|
|
|
|
'transparency' => 'free_busy',
|
|
|
|
'classification' => 'sensitivity',
|
|
|
|
'lastmodified-date' => 'changed',
|
|
|
|
);
|
|
|
|
$prop_keymaps = array(
|
|
|
|
'attachments' => array('fmttype' => 'mimetype', 'label' => 'name'),
|
|
|
|
'attendees' => array('partstat' => 'status'),
|
|
|
|
);
|
|
|
|
$special_changes = array();
|
|
|
|
|
|
|
|
// map kolab event properties to keys the client expects
|
|
|
|
array_walk($result['changes'], function(&$change, $i) use ($keymap, $prop_keymaps, $special_changes) {
|
|
|
|
if (array_key_exists($change['property'], $keymap)) {
|
|
|
|
$change['property'] = $keymap[$change['property']];
|
|
|
|
}
|
|
|
|
// translate free_busy values
|
|
|
|
if ($change['property'] == 'free_busy') {
|
|
|
|
$change['old'] = $old['old'] ? 'free' : 'busy';
|
|
|
|
$change['new'] = $old['new'] ? 'free' : 'busy';
|
|
|
|
}
|
|
|
|
// map alarms trigger value
|
|
|
|
if ($change['property'] == 'alarms') {
|
|
|
|
if (is_array($change['old']) && is_array($change['old']['trigger']))
|
|
|
|
$change['old']['trigger'] = $change['old']['trigger']['value'];
|
|
|
|
if (is_array($change['new']) && is_array($change['new']['trigger']))
|
|
|
|
$change['new']['trigger'] = $change['new']['trigger']['value'];
|
|
|
|
}
|
|
|
|
// make all property keys uppercase
|
|
|
|
if ($change['property'] == 'recurrence') {
|
|
|
|
$special_changes['recurrence'] = $i;
|
|
|
|
foreach (array('old','new') as $m) {
|
|
|
|
if (is_array($change[$m])) {
|
|
|
|
$props = array();
|
|
|
|
foreach ($change[$m] as $k => $v)
|
|
|
|
$props[strtoupper($k)] = $v;
|
|
|
|
$change[$m] = $props;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// map property keys names
|
|
|
|
if (is_array($prop_keymaps[$change['property']])) {
|
|
|
|
foreach ($prop_keymaps[$change['property']] as $k => $dest) {
|
|
|
|
if (is_array($change['old']) && array_key_exists($k, $change['old'])) {
|
|
|
|
$change['old'][$dest] = $change['old'][$k];
|
|
|
|
unset($change['old'][$k]);
|
|
|
|
}
|
|
|
|
if (is_array($change['new']) && array_key_exists($k, $change['new'])) {
|
|
|
|
$change['new'][$dest] = $change['new'][$k];
|
|
|
|
unset($change['new'][$k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($change['property'] == 'exdate') {
|
|
|
|
$special_changes['exdate'] = $i;
|
|
|
|
}
|
|
|
|
else if ($change['property'] == 'rdate') {
|
|
|
|
$special_changes['rdate'] = $i;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// merge some recurrence changes
|
|
|
|
foreach (array('exdate','rdate') as $prop) {
|
|
|
|
if (array_key_exists($prop, $special_changes)) {
|
|
|
|
$exdate = $result['changes'][$special_changes[$prop]];
|
|
|
|
if (array_key_exists('recurrence', $special_changes)) {
|
|
|
|
$recurrence = &$result['changes'][$special_changes['recurrence']];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$i = count($result['changes']);
|
|
|
|
$result['changes'][$i] = array('property' => 'recurrence', 'old' => array(), 'new' => array());
|
|
|
|
$recurrence = &$result['changes'][$i]['recurrence'];
|
|
|
|
}
|
|
|
|
$key = strtoupper($prop);
|
|
|
|
$recurrence['old'][$key] = $exdate['old'];
|
|
|
|
$recurrence['new'][$key] = $exdate['new'];
|
|
|
|
unset($result['changes'][$special_changes[$prop]]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return full data of a specific revision of an event
|
|
|
|
*
|
|
|
|
* @param array Hash array with event properties
|
|
|
|
* @param mixed $rev Revision number
|
|
|
|
*
|
|
|
|
* @return array Event object as hash array
|
|
|
|
* @see calendar_driver::get_event_revison()
|
|
|
|
*/
|
2015-03-18 20:23:58 +01:00
|
|
|
public function get_event_revison($event, $rev, $internal = false)
|
2014-07-29 15:28:35 +02:00
|
|
|
{
|
|
|
|
if (empty($this->bonnie_api)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-19 12:34:08 +01:00
|
|
|
$eventid = $event['id'];
|
2014-07-29 15:28:35 +02:00
|
|
|
$calid = $event['calendar'];
|
2015-03-18 20:23:58 +01:00
|
|
|
list($uid, $mailbox, $msguid) = $this->_resolve_event_identity($event);
|
2014-07-29 15:28:35 +02:00
|
|
|
|
|
|
|
// call Bonnie API
|
2015-03-18 20:23:58 +01:00
|
|
|
$result = $this->bonnie_api->get('event', $uid, $rev, $mailbox, $msguid);
|
2014-07-29 15:28:35 +02:00
|
|
|
if (is_array($result) && $result['uid'] == $uid && !empty($result['xml'])) {
|
|
|
|
$format = kolab_format::factory('event');
|
|
|
|
$format->load($result['xml']);
|
|
|
|
$event = $format->to_array();
|
2015-03-18 20:23:58 +01:00
|
|
|
$format->get_attachments($event, true);
|
|
|
|
|
2015-03-19 12:34:08 +01:00
|
|
|
// get the right instance from a recurring event
|
|
|
|
if ($eventid != $event['uid']) {
|
|
|
|
$instance_id = substr($eventid, strlen($event['uid']) + 1);
|
|
|
|
|
|
|
|
// check for recurrence exception first
|
|
|
|
if ($instance = $format->get_instance($instance_id)) {
|
|
|
|
$event = $instance;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// not a exception, compute recurrence...
|
|
|
|
$event['_formatobj'] = $format;
|
|
|
|
$recurrence_date = rcube_utils::anytodatetime($instance_id, $event['start']->getTimezone());
|
|
|
|
foreach ($this->get_recurring_events($event, $event['start'], $recurrence_date) as $instance) {
|
|
|
|
if ($instance['id'] == $eventid) {
|
|
|
|
$event = $instance;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-29 15:28:35 +02:00
|
|
|
|
|
|
|
if ($format->is_valid()) {
|
2014-07-30 09:26:29 +02:00
|
|
|
$event['calendar'] = $calid;
|
2014-07-29 15:28:35 +02:00
|
|
|
$event['rev'] = $result['rev'];
|
2015-03-18 20:23:58 +01:00
|
|
|
return $internal ? $event : self::to_rcube_event($event);
|
2014-07-29 15:28:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-18 20:23:58 +01:00
|
|
|
/**
|
|
|
|
* Command the backend to restore a certain revision of an event.
|
|
|
|
* This shall replace the current event with an older version.
|
|
|
|
*
|
|
|
|
* @param mixed UID string or hash array with event properties:
|
|
|
|
* id: Event identifier
|
|
|
|
* calendar: Calendar identifier
|
|
|
|
* @param mixed $rev Revision number
|
|
|
|
*
|
|
|
|
* @return boolean True on success, False on failure
|
|
|
|
*/
|
|
|
|
public function restore_event_revision($event, $rev)
|
|
|
|
{
|
|
|
|
if (empty($this->bonnie_api)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
list($uid, $mailbox, $msguid) = $this->_resolve_event_identity($event);
|
|
|
|
$calendar = $this->get_calendar($event['calendar']);
|
|
|
|
$success = false;
|
|
|
|
|
|
|
|
if ($calendar && $calendar->storage && $calendar->editable) {
|
|
|
|
if ($raw_msg = $this->bonnie_api->rawdata('event', $uid, $rev, $mailbox)) {
|
|
|
|
$imap = $this->rc->get_storage();
|
|
|
|
|
|
|
|
// insert $raw_msg as new message
|
|
|
|
if ($imap->save_message($calendar->storage->name, $raw_msg, null, false)) {
|
|
|
|
$success = true;
|
|
|
|
|
|
|
|
// delete old revision from imap and cache
|
|
|
|
$imap->delete_message($msguid, $calendar->storage->name);
|
|
|
|
$calendar->storage->cache->set($msguid, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $success;
|
|
|
|
}
|
|
|
|
|
2014-07-29 15:28:35 +02:00
|
|
|
/**
|
|
|
|
* Helper method to resolved the given event identifier into uid and folder
|
|
|
|
*
|
2015-03-18 20:23:58 +01:00
|
|
|
* @return array (uid,folder,msguid) tuple
|
2014-07-29 15:28:35 +02:00
|
|
|
*/
|
|
|
|
private function _resolve_event_identity($event)
|
|
|
|
{
|
2015-03-18 20:23:58 +01:00
|
|
|
$mailbox = $msguid = null;
|
2014-07-29 15:28:35 +02:00
|
|
|
if (is_array($event)) {
|
2015-03-18 20:23:58 +01:00
|
|
|
$uid = $event['uid'] ?: $event['id'];
|
2014-07-30 09:26:29 +02:00
|
|
|
if (($cal = $this->get_calendar($event['calendar'])) && !($cal instanceof kolab_invitation_calendar)) {
|
|
|
|
$mailbox = $cal->get_mailbox_id();
|
2015-03-18 20:23:58 +01:00
|
|
|
|
|
|
|
// get event object from storage in order to get the real object uid an msguid
|
|
|
|
if ($ev = $cal->get_event($event['id'])) {
|
|
|
|
$msguid = $ev['_msguid'];
|
|
|
|
$uid = $ev['uid'];
|
|
|
|
}
|
2014-07-29 15:28:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$uid = $event;
|
2015-03-18 20:23:58 +01:00
|
|
|
|
|
|
|
// get event object from storage in order to get the real object uid an msguid
|
|
|
|
if ($ev = $this->get_event($event)) {
|
|
|
|
$mailbox = $ev['_mailbox'];
|
|
|
|
$msguid = $ev['_msguid'];
|
|
|
|
$uid = $ev['uid'];
|
|
|
|
}
|
2014-07-29 15:28:35 +02:00
|
|
|
}
|
|
|
|
|
2015-03-18 20:23:58 +01:00
|
|
|
return array($uid, $mailbox, $msguid);
|
2014-07-29 15:28:35 +02:00
|
|
|
}
|
|
|
|
|
2011-07-26 13:13:04 +02:00
|
|
|
/**
|
|
|
|
* Callback function to produce driver-specific calendar create/edit form
|
|
|
|
*
|
|
|
|
* @param string Request action 'form-edit|form-new'
|
|
|
|
* @param array Calendar properties (e.g. id, color)
|
2011-07-27 13:15:15 +02:00
|
|
|
* @param array Edit form fields
|
2011-07-26 13:13:04 +02:00
|
|
|
*
|
|
|
|
* @return string HTML content of the form
|
|
|
|
*/
|
2011-07-27 13:15:15 +02:00
|
|
|
public function calendar_form($action, $calendar, $formfields)
|
2011-07-26 13:13:04 +02:00
|
|
|
{
|
2014-05-12 20:47:47 +02:00
|
|
|
// show default dialog for birthday calendar
|
2014-07-08 12:36:34 +02:00
|
|
|
if (in_array($calendar['id'], array(self::BIRTHDAY_CALENDAR_ID, self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED))) {
|
|
|
|
if ($calendar['id'] != self::BIRTHDAY_CALENDAR_ID)
|
|
|
|
unset($formfields['showalarms']);
|
2014-05-12 20:47:47 +02:00
|
|
|
return parent::calendar_form($action, $calendar, $formfields);
|
|
|
|
}
|
|
|
|
|
2016-02-12 16:27:19 +01:00
|
|
|
$this->_read_calendars();
|
|
|
|
|
2011-07-26 13:13:04 +02:00
|
|
|
if ($calendar['id'] && ($cal = $this->calendars[$calendar['id']])) {
|
|
|
|
$folder = $cal->get_realname(); // UTF7
|
|
|
|
$color = $cal->get_color();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$folder = '';
|
|
|
|
$color = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$hidden_fields[] = array('name' => 'oldname', 'value' => $folder);
|
|
|
|
|
2012-01-23 10:16:30 +01:00
|
|
|
$storage = $this->rc->get_storage();
|
|
|
|
$delim = $storage->get_hierarchy_delimiter();
|
2011-07-26 13:13:04 +02:00
|
|
|
$form = array();
|
|
|
|
|
|
|
|
if (strlen($folder)) {
|
|
|
|
$path_imap = explode($delim, $folder);
|
2011-07-27 13:15:15 +02:00
|
|
|
array_pop($path_imap); // pop off name part
|
2011-07-26 13:13:04 +02:00
|
|
|
$path_imap = implode($path_imap, $delim);
|
|
|
|
|
2012-01-23 10:16:30 +01:00
|
|
|
$options = $storage->folder_info($folder);
|
2011-07-26 13:13:04 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$path_imap = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// General tab
|
|
|
|
$form['props'] = array(
|
|
|
|
'name' => $this->rc->gettext('properties'),
|
|
|
|
);
|
|
|
|
|
2011-08-01 12:44:30 +02:00
|
|
|
// Disable folder name input
|
|
|
|
if (!empty($options) && ($options['norename'] || $options['protected'])) {
|
|
|
|
$input_name = new html_hiddenfield(array('name' => 'name', 'id' => 'calendar-name'));
|
2013-10-10 17:27:24 +02:00
|
|
|
$formfields['name']['value'] = kolab_storage::object_name($folder)
|
2011-08-01 12:44:30 +02:00
|
|
|
. $input_name->show($folder);
|
|
|
|
}
|
|
|
|
|
2011-07-27 13:15:15 +02:00
|
|
|
// calendar name (default field)
|
2011-07-26 13:13:04 +02:00
|
|
|
$form['props']['fieldsets']['location'] = array(
|
|
|
|
'name' => $this->rc->gettext('location'),
|
|
|
|
'content' => array(
|
2011-07-27 13:15:15 +02:00
|
|
|
'name' => $formfields['name']
|
2011-07-26 13:13:04 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2011-08-01 12:44:30 +02:00
|
|
|
if (!empty($options) && ($options['norename'] || $options['protected'])) {
|
2011-07-26 13:13:04 +02:00
|
|
|
// prevent user from moving folder
|
|
|
|
$hidden_fields[] = array('name' => 'parent', 'value' => $path_imap);
|
|
|
|
}
|
|
|
|
else {
|
2014-06-19 17:45:39 +02:00
|
|
|
$select = kolab_storage::folder_selector('event', array('name' => 'parent', 'id' => 'calendar-parent'), $folder);
|
2011-07-26 13:13:04 +02:00
|
|
|
$form['props']['fieldsets']['location']['content']['path'] = array(
|
2014-06-19 17:45:39 +02:00
|
|
|
'id' => 'calendar-parent',
|
2011-07-26 13:13:04 +02:00
|
|
|
'label' => $this->cal->gettext('parentcalendar'),
|
2011-07-29 19:21:26 +02:00
|
|
|
'value' => $select->show(strlen($folder) ? $path_imap : ''),
|
2011-07-26 13:13:04 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-07-27 13:15:15 +02:00
|
|
|
// calendar color (default field)
|
2011-07-26 13:13:04 +02:00
|
|
|
$form['props']['fieldsets']['settings'] = array(
|
|
|
|
'name' => $this->rc->gettext('settings'),
|
|
|
|
'content' => array(
|
2011-07-27 13:15:15 +02:00
|
|
|
'color' => $formfields['color'],
|
2011-07-31 14:40:52 +02:00
|
|
|
'showalarms' => $formfields['showalarms'],
|
2011-07-26 13:13:04 +02:00
|
|
|
),
|
|
|
|
);
|
2011-08-30 00:17:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
if ($action != 'form-new') {
|
|
|
|
$form['sharing'] = array(
|
2015-08-29 20:23:34 +02:00
|
|
|
'name' => rcube::Q($this->cal->gettext('tabsharing')),
|
2011-08-30 00:17:06 +02:00
|
|
|
'content' => html::tag('iframe', array(
|
|
|
|
'src' => $this->cal->rc->url(array('_action' => 'calendar-acl', 'id' => $calendar['id'], 'framed' => 1)),
|
|
|
|
'width' => '100%',
|
|
|
|
'height' => 350,
|
|
|
|
'border' => 0,
|
|
|
|
'style' => 'border:0'),
|
|
|
|
''),
|
|
|
|
);
|
|
|
|
}
|
2011-07-26 13:13:04 +02:00
|
|
|
|
2011-08-30 00:17:06 +02:00
|
|
|
$this->form_html = '';
|
2011-07-26 13:13:04 +02:00
|
|
|
if (is_array($hidden_fields)) {
|
|
|
|
foreach ($hidden_fields as $field) {
|
|
|
|
$hiddenfield = new html_hiddenfield($field);
|
2011-08-30 00:17:06 +02:00
|
|
|
$this->form_html .= $hiddenfield->show() . "\n";
|
2011-07-26 13:13:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create form output
|
|
|
|
foreach ($form as $tab) {
|
|
|
|
if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) {
|
|
|
|
$content = '';
|
|
|
|
foreach ($tab['fieldsets'] as $fieldset) {
|
|
|
|
$subcontent = $this->get_form_part($fieldset);
|
|
|
|
if ($subcontent) {
|
2015-08-29 20:23:34 +02:00
|
|
|
$content .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($fieldset['name'])) . $subcontent) ."\n";
|
2011-07-26 13:13:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$content = $this->get_form_part($tab);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($content) {
|
2015-08-29 20:23:34 +02:00
|
|
|
$this->form_html .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($tab['name'])) . $content) ."\n";
|
2011-07-26 13:13:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-30 00:17:06 +02:00
|
|
|
// Parse form template for skin-dependent stuff
|
|
|
|
$this->rc->output->add_handler('calendarform', array($this, 'calendar_form_html'));
|
|
|
|
return $this->rc->output->parse('calendar.kolabform', false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for template object
|
|
|
|
*/
|
|
|
|
public function calendar_form_html()
|
|
|
|
{
|
|
|
|
return $this->form_html;
|
2011-07-26 13:13:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function used in calendar_form_content(). Creates a part of the form.
|
|
|
|
*/
|
|
|
|
private function get_form_part($form)
|
|
|
|
{
|
|
|
|
$content = '';
|
|
|
|
|
|
|
|
if (is_array($form['content']) && !empty($form['content'])) {
|
|
|
|
$table = new html_table(array('cols' => 2));
|
|
|
|
foreach ($form['content'] as $col => $colprop) {
|
2015-08-02 20:15:28 +02:00
|
|
|
$label = !empty($colprop['label']) ? $colprop['label'] : $this->cal->gettext($col);
|
2011-07-26 13:13:04 +02:00
|
|
|
|
2015-08-29 20:23:34 +02:00
|
|
|
$table->add('title', html::label($colprop['id'], rcube::Q($label)));
|
2011-07-26 13:13:04 +02:00
|
|
|
$table->add(null, $colprop['value']);
|
|
|
|
}
|
|
|
|
$content = $table->show();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$content = $form['content'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
2011-08-30 00:17:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler to render ACL form for a calendar folder
|
|
|
|
*/
|
|
|
|
public function calendar_acl()
|
|
|
|
{
|
|
|
|
$this->rc->output->add_handler('folderacl', array($this, 'calendar_acl_form'));
|
|
|
|
$this->rc->output->send('calendar.kolabacl');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for ACL form template object
|
|
|
|
*/
|
|
|
|
public function calendar_acl_form()
|
|
|
|
{
|
2014-10-06 09:19:26 +02:00
|
|
|
$calid = rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC);
|
2014-05-13 17:09:53 +02:00
|
|
|
if ($calid && ($cal = $this->get_calendar($calid))) {
|
2011-08-30 00:17:06 +02:00
|
|
|
$folder = $cal->get_realname(); // UTF7
|
|
|
|
$color = $cal->get_color();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$folder = '';
|
|
|
|
$color = '';
|
|
|
|
}
|
|
|
|
|
2012-01-23 10:16:30 +01:00
|
|
|
$storage = $this->rc->get_storage();
|
|
|
|
$delim = $storage->get_hierarchy_delimiter();
|
2011-08-30 00:17:06 +02:00
|
|
|
$form = array();
|
|
|
|
|
|
|
|
if (strlen($folder)) {
|
|
|
|
$path_imap = explode($delim, $folder);
|
|
|
|
array_pop($path_imap); // pop off name part
|
|
|
|
$path_imap = implode($path_imap, $delim);
|
|
|
|
|
2012-01-23 10:16:30 +01:00
|
|
|
$options = $storage->folder_info($folder);
|
2013-05-07 11:31:30 +02:00
|
|
|
|
2011-08-30 00:17:06 +02:00
|
|
|
// Allow plugins to modify the form content (e.g. with ACL form)
|
|
|
|
$plugin = $this->rc->plugins->exec_hook('calendar_form_kolab',
|
|
|
|
array('form' => $form, 'options' => $options, 'name' => $folder));
|
|
|
|
}
|
|
|
|
|
2012-01-27 17:46:25 +01:00
|
|
|
if (!$plugin['form']['sharing']['content'])
|
|
|
|
$plugin['form']['sharing']['content'] = html::div('hint', $this->cal->gettext('aclnorights'));
|
|
|
|
|
2011-08-30 00:17:06 +02:00
|
|
|
return $plugin['form']['sharing']['content'];
|
|
|
|
}
|
2014-04-23 20:44:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for user_delete plugin hook
|
|
|
|
*/
|
|
|
|
public function user_delete($args)
|
|
|
|
{
|
|
|
|
$db = $this->rc->get_dbh();
|
|
|
|
foreach (array('kolab_alarms', 'itipinvitations') as $table) {
|
2014-09-15 12:23:46 +02:00
|
|
|
$db->query("DELETE FROM " . $this->rc->db->table_name($table, true)
|
|
|
|
. " WHERE `user_id` = ?", $args['user']->ID);
|
2014-04-23 20:44:46 +02:00
|
|
|
}
|
|
|
|
}
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|