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>
|
|
|
|
*
|
2014-01-27 19:12:29 +01:00
|
|
|
* Copyright (C) 2012-2014, 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
|
|
|
|
|
|
|
require_once(dirname(__FILE__) . '/kolab_calendar.php');
|
|
|
|
|
|
|
|
class kolab_driver extends calendar_driver
|
|
|
|
{
|
|
|
|
// 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;
|
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');
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
$this->cal = $cal;
|
|
|
|
$this->rc = $cal->rc;
|
|
|
|
$this->_read_calendars();
|
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'));
|
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
|
|
|
|
|
|
|
// 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
|
|
|
|
$folders = kolab_storage::sort_folders(kolab_storage::get_folders('event'));
|
2011-06-28 10:32:52 +02:00
|
|
|
$this->calendars = array();
|
2011-05-20 19:04:25 +02:00
|
|
|
|
2013-07-18 17:47:49 +02:00
|
|
|
foreach ($folders as $folder) {
|
|
|
|
$calendar = new kolab_calendar($folder->name, $this->cal);
|
2012-08-03 15:20:41 +02:00
|
|
|
$this->calendars[$calendar->id] = $calendar;
|
|
|
|
if (!$calendar->readonly)
|
|
|
|
$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
|
|
|
*
|
|
|
|
* @param bool $active Return only active calendars
|
|
|
|
* @param bool $personal Return only personal calendars
|
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
|
|
|
*/
|
2014-05-12 20:47:47 +02:00
|
|
|
public function list_calendars($active = false, $personal = false, &$tree = null)
|
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'))) {
|
|
|
|
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
|
|
|
|
2013-10-10 17:27:24 +02:00
|
|
|
$folders = $this->filter_calendars(false, $active, $personal);
|
|
|
|
$calendars = $names = array();
|
|
|
|
|
|
|
|
// include virtual folders for a full folder tree
|
2013-10-15 10:31:52 +02:00
|
|
|
if (!$active && !$personal && !$this->rc->output->ajax_call && in_array($this->rc->action, array('index','')))
|
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();
|
2013-10-16 16:35:56 +02:00
|
|
|
$listname = kolab_storage::folder_displayname($fullname, $names);
|
2014-05-13 17:09:53 +02:00
|
|
|
$imap_path = explode('/', $cal->name);
|
|
|
|
$topname = array_pop($imap_path);
|
|
|
|
$parent_id = kolab_storage::folder_id(join('/', $imap_path), true);
|
2013-10-10 17:27:24 +02:00
|
|
|
|
|
|
|
// special handling for virtual folders
|
|
|
|
if ($cal->virtual) {
|
|
|
|
$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(),
|
2013-10-10 17:27:24 +02:00
|
|
|
'virtual' => true,
|
2013-10-11 13:50:07 +02:00
|
|
|
'readonly' => true,
|
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(),
|
|
|
|
'color' => $cal->get_color(),
|
|
|
|
'readonly' => $cal->readonly,
|
|
|
|
'showalarms' => $cal->alarms,
|
|
|
|
'class_name' => $cal->get_namespace(),
|
|
|
|
'default' => $cal->storage->default,
|
|
|
|
'active' => $cal->storage->is_active(),
|
|
|
|
'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,
|
2013-10-10 17:27:24 +02:00
|
|
|
'caldavurl' => $cal->get_caldav_url(),
|
|
|
|
);
|
|
|
|
}
|
2011-06-28 10:32:52 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
if (!$active || $prefs[$id]['active']) {
|
|
|
|
$calendars[$id] = array(
|
|
|
|
'id' => $id,
|
|
|
|
'name' => $this->cal->gettext('birthdays'),
|
|
|
|
'listname' => $this->cal->gettext('birthdays'),
|
|
|
|
'color' => $prefs[$id]['color'],
|
|
|
|
'active' => $prefs[$id]['active'],
|
2014-01-28 11:55:06 +01:00
|
|
|
'showalarms' => (bool)$this->rc->config->get('calendar_birthdays_alarm_type'),
|
2014-01-27 19:12:29 +01:00
|
|
|
'class_name' => 'birthdays',
|
|
|
|
'readonly' => true,
|
|
|
|
'default' => false,
|
|
|
|
'children' => false,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*
|
2013-01-17 09:37:48 +01:00
|
|
|
* @param bool $writeable Return only writeable calendars
|
2012-12-04 20:10:04 +01:00
|
|
|
* @param bool $active Return only active calendars
|
|
|
|
* @param bool $personal Return only personal calendars
|
|
|
|
*
|
|
|
|
* @return array List of calendars
|
|
|
|
*/
|
2013-01-17 09:37:48 +01:00
|
|
|
protected function filter_calendars($writeable = false, $active = false, $personal = false)
|
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(
|
|
|
|
'list' => $this->calendars, 'calendars' => $calendars,
|
2013-01-17 15:16:10 +01:00
|
|
|
'writeable' => $writeable, 'active' => $active, 'personal' => $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;
|
|
|
|
}
|
|
|
|
if ($writeable && $cal->readonly) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-12-10 12:17:41 +01:00
|
|
|
if ($active && !$cal->storage->is_active()) {
|
2012-12-04 20:10:04 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ($personal && $cal->get_namespace() != 'personal') {
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
protected function get_calendar($id)
|
|
|
|
{
|
|
|
|
// create calendar object if necesary
|
|
|
|
if (!$this->calendars[$id] && $id !== self::BIRTHDAY_CALENDAR_ID) {
|
|
|
|
$foldername = kolab_storage::id_decode($id);
|
|
|
|
$calendar = new kolab_calendar($foldername, $this->cal);
|
|
|
|
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']))) {
|
2012-06-21 09:42:24 +02:00
|
|
|
$prop['oldname'] = $cal->get_realname();
|
|
|
|
$newfolder = kolab_storage::folder_update($prop);
|
2011-07-26 13:13:04 +02:00
|
|
|
|
|
|
|
if ($newfolder === 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create ID
|
2012-03-30 19:14:38 +02:00
|
|
|
$id = kolab_storage::folder_id($newfolder);
|
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()
|
|
|
|
*/
|
2014-05-13 17:09:53 +02:00
|
|
|
public function subscribe_calendar($prop, $permanent = false)
|
2011-08-26 23:24:49 +02:00
|
|
|
{
|
2014-05-13 17:09:53 +02:00
|
|
|
if ($prop['id'] && ($cal = $this->get_calendar($prop['id']))) {
|
|
|
|
if ($permanent) $cal->storage->subscribe($prop['active']);
|
2012-12-10 12:17:41 +01:00
|
|
|
return $cal->storage->activate($prop['active']);
|
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
|
|
|
|
*
|
|
|
|
* @see calendar_driver::remove_calendar()
|
|
|
|
*/
|
|
|
|
public function remove_calendar($prop)
|
|
|
|
{
|
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();
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ($source == 'users') {
|
|
|
|
// TODO: implement this
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't list the birthday calendar
|
|
|
|
$this->rc->config->set('calendar_contact_birthdays', false);
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2012-12-04 20:10:04 +01:00
|
|
|
public function get_event($event, $writeable = false, $active = false, $personal = false)
|
2011-07-27 16:06:06 +02:00
|
|
|
{
|
2011-09-05 23:05:19 +02:00
|
|
|
if (is_array($event)) {
|
|
|
|
$id = $event['id'] ? $event['id'] : $event['uid'];
|
|
|
|
$cal = $event['calendar'];
|
|
|
|
}
|
|
|
|
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)) {
|
2012-12-04 20:10:04 +01:00
|
|
|
return $storage->get_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 {
|
|
|
|
foreach ($this->filter_calendars($writeable, $active, $personal) as $calendar) {
|
|
|
|
if ($result = $calendar->get_event($id)) {
|
2011-08-24 17:45:51 +02:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
$cid = $event['calendar'] ? $event['calendar'] : reset(array_keys($this->calendars));
|
2014-05-13 17:09:53 +02:00
|
|
|
if ($storage = $this->get_calendar($cid)) {
|
2011-07-01 21:08:12 +02:00
|
|
|
// handle attachments to add
|
|
|
|
if (!empty($event['attachments'])) {
|
|
|
|
foreach ($event['attachments'] as $idx => $attachment) {
|
|
|
|
// we'll read file contacts into memory, Horde/Kolab classes does the same
|
|
|
|
// So we cannot save memory, rcube_imap class can do this better
|
|
|
|
$event['attachments'][$idx]['content'] = $attachment['data'] ? $attachment['data'] : file_get_contents($attachment['path']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-16 17:14:36 +02:00
|
|
|
$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)
|
|
|
|
{
|
2011-06-29 19:42:56 +02:00
|
|
|
return $this->update_event($event);
|
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']);
|
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']);
|
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
|
|
|
{
|
2011-06-29 19:42:56 +02:00
|
|
|
$success = false;
|
2013-01-09 11:12:19 +01:00
|
|
|
$savemode = $event['_savemode'];
|
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
|
|
|
|
if ($event['recurrence'] || $event['recurrence_id']) {
|
|
|
|
$master = $event['recurrence_id'] ? $storage->get_event($event['recurrence_id']) : $event;
|
2011-09-19 10:03:38 +02:00
|
|
|
$savemode = $event['_savemode'];
|
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
|
|
|
|
if ($event['recurrence_id']) {
|
|
|
|
$i = $event['_instance'] - 1;
|
|
|
|
if (!empty($master['recurrence']['EXCEPTIONS'][$i])) {
|
|
|
|
unset($master['recurrence']['EXCEPTIONS'][$i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
if ($master['id'] == $event['id']) {
|
2013-01-09 11:49:12 +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':
|
|
|
|
if ($master['id'] != $event['id']) {
|
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);
|
|
|
|
break;
|
|
|
|
}
|
2011-07-18 15:28:57 +02:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
default: // 'all' is default
|
2011-07-18 15:28:57 +02:00
|
|
|
$success = $storage->delete_event($master, $force);
|
2011-06-29 19:42:56 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-06-28 10:32:52 +02: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-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;
|
|
|
|
|
2011-09-19 10:03:38 +02:00
|
|
|
if ($event['_savemode'] != 'new') {
|
2011-09-19 09:50:13 +02:00
|
|
|
if (!$fromcalendar->storage->move($event['id'], $storage->get_realname()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
$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();
|
2011-09-19 09:50:13 +02:00
|
|
|
$old = $master = $fromcalendar->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-07-01 21:08:12 +02:00
|
|
|
// delete existing attachment(s)
|
|
|
|
if (!empty($event['deleted_attachments'])) {
|
|
|
|
foreach ($event['deleted_attachments'] as $attachment) {
|
|
|
|
if (!empty($old['attachments'])) {
|
|
|
|
foreach ($old['attachments'] as $idx => $att) {
|
|
|
|
if ($att['id'] == $attachment) {
|
2012-04-25 19:26:40 +02:00
|
|
|
$old['attachments'][$idx]['_deleted'] = true;
|
2011-07-01 21:08:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-13 17:39:18 +02:00
|
|
|
unset($event['deleted_attachments']);
|
2011-07-01 21:08:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// handle attachments to add
|
|
|
|
if (!empty($event['attachments'])) {
|
|
|
|
foreach ($event['attachments'] as $attachment) {
|
2011-07-14 10:57:07 +02:00
|
|
|
// skip entries without content (could be existing ones)
|
|
|
|
if (!$attachment['data'] && !$attachment['path'])
|
|
|
|
continue;
|
2012-04-25 19:26:40 +02:00
|
|
|
|
2011-07-01 21:08:12 +02:00
|
|
|
$attachments[] = array(
|
|
|
|
'name' => $attachment['name'],
|
2012-04-25 19:26:40 +02:00
|
|
|
'mimetype' => $attachment['mimetype'],
|
|
|
|
'content' => $attachment['data'],
|
|
|
|
'path' => $attachment['path'],
|
2011-07-01 21:08:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-05 19:45:09 +02:00
|
|
|
$event['attachments'] = array_merge((array)$old['attachments'], $attachments);
|
2011-07-01 21:08:12 +02:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
// modify a recurring event, check submitted savemode to do the right things
|
|
|
|
if ($old['recurrence'] || $old['recurrence_id']) {
|
2011-09-19 09:50:13 +02:00
|
|
|
$master = $old['recurrence_id'] ? $fromcalendar->get_event($old['recurrence_id']) : $old;
|
2011-09-19 10:03:38 +02:00
|
|
|
$savemode = $event['_savemode'];
|
2011-06-29 19:42:56 +02:00
|
|
|
}
|
2011-07-01 21:08:12 +02:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
// keep saved exceptions (not submitted by the client)
|
|
|
|
if ($old['recurrence']['EXDATE'])
|
|
|
|
$event['recurrence']['EXDATE'] = $old['recurrence']['EXDATE'];
|
2013-01-23 14:45:41 +01:00
|
|
|
if ($old['recurrence']['EXCEPTIONS'])
|
|
|
|
$event['recurrence']['EXCEPTIONS'] = $old['recurrence']['EXCEPTIONS'];
|
2011-07-01 21:08:12 +02:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
switch ($savemode) {
|
|
|
|
case 'new':
|
|
|
|
// save submitted data as new (non-recurring) event
|
|
|
|
$event['recurrence'] = array();
|
|
|
|
$event['uid'] = $this->cal->generate_uid();
|
2011-09-19 09:50:13 +02:00
|
|
|
|
|
|
|
// copy attachment data to new event
|
|
|
|
foreach ((array)$event['attachments'] as $idx => $attachment) {
|
|
|
|
if (!$attachment['data'])
|
2012-04-25 19:26:40 +02:00
|
|
|
$attachment['data'] = $fromcalendar->get_attachment_body($attachment['id'], $event);
|
2011-09-19 09:50:13 +02:00
|
|
|
}
|
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
$success = $storage->insert_event($event);
|
|
|
|
break;
|
2013-02-14 16:17:02 +01:00
|
|
|
|
|
|
|
case 'future':
|
2011-06-29 19:42:56 +02:00
|
|
|
case 'current':
|
2013-02-14 16:17:02 +01:00
|
|
|
// recurring instances shall not store recurrence rules
|
2011-06-29 19:42:56 +02:00
|
|
|
$event['recurrence'] = array();
|
2013-02-14 16:17:02 +01:00
|
|
|
$event['thisandfuture'] = $savemode == 'future';
|
2013-01-23 14:45:41 +01:00
|
|
|
|
2013-04-17 09:19:26 +02:00
|
|
|
// remove some internal properties which should not be saved
|
|
|
|
unset($event['_savemode'], $event['_fromcalendar'], $event['_identity']);
|
|
|
|
|
2013-01-23 14:45:41 +01:00
|
|
|
// save properties to a recurrence exception instance
|
|
|
|
if ($old['recurrence_id']) {
|
|
|
|
$i = $old['_instance'] - 1;
|
|
|
|
if (!empty($master['recurrence']['EXCEPTIONS'][$i])) {
|
|
|
|
$master['recurrence']['EXCEPTIONS'][$i] = $event;
|
|
|
|
$success = $storage->update_event($master, $old['id']);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-17 12:40:21 +01:00
|
|
|
$add_exception = true;
|
|
|
|
|
|
|
|
// adjust matching RDATE entry if dates changed
|
|
|
|
if ($savemode == 'current' && $master['recurrence']['RDATE'] && ($old_date = $old['start']->format('Ymd')) != $event['start']->format('Ymd')) {
|
|
|
|
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) {
|
|
|
|
$master['recurrence']['EXCEPTIONS'][] = $event;
|
|
|
|
}
|
2013-02-14 16:17:02 +01:00
|
|
|
$success = $storage->update_event($master);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: // 'all' is default
|
2011-06-29 19:42:56 +02:00
|
|
|
$event['id'] = $master['id'];
|
|
|
|
$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;
|
|
|
|
|
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)) {
|
2012-07-06 17:15:45 +02:00
|
|
|
$event['start'] = $master['start']->add($old['start']->diff($event['start']));
|
|
|
|
$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
|
|
|
|
else if ($event['start'] == $old['start'] && $event['end'] == $old['end']) {
|
|
|
|
$event['start'] = $master['start'];
|
|
|
|
$event['end'] = $master['end'];
|
|
|
|
}
|
2011-06-29 19:42:56 +02:00
|
|
|
|
2013-10-03 10:54:05 +02:00
|
|
|
// unset _dateonly flags in (cached) date objects
|
|
|
|
unset($event['start']->_dateonly, $event['end']->_dateonly);
|
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
$success = $storage->update_event($event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
2014-05-13 17:09:53 +02:00
|
|
|
else if (!$calendars)
|
|
|
|
$calendars = array_keys($this->calendars);
|
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
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
return $events;
|
|
|
|
}
|
|
|
|
|
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'));
|
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-04-17 17:49:00 +02:00
|
|
|
if ($alarm && $alarm['time'] && $alarm['time'] <= $time && in_array($alarm['action'], $this->alarm_types)) {
|
|
|
|
$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));
|
2011-06-27 11:47:52 -04:00
|
|
|
$result = $this->rc->db->query(sprintf(
|
2012-05-16 18:58:57 +02:00
|
|
|
"SELECT * FROM kolab_alarms
|
2014-04-17 17:49:00 +02:00
|
|
|
WHERE alarm_id IN (%s) AND user_id=?",
|
|
|
|
join(',', $alarm_ids),
|
2012-05-16 18:58:57 +02:00
|
|
|
$this->rc->db->now()
|
|
|
|
),
|
|
|
|
$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
|
|
|
{
|
2012-04-24 10:14:01 +02:00
|
|
|
// delete old alarm entry
|
2012-05-16 18:58:57 +02:00
|
|
|
$this->rc->db->query(
|
|
|
|
"DELETE FROM kolab_alarms
|
2014-04-17 17:49:00 +02:00
|
|
|
WHERE alarm_id=? AND user_id=?",
|
|
|
|
$alarm_id,
|
2012-05-16 18:58:57 +02:00
|
|
|
$this->rc->user->ID
|
|
|
|
);
|
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
|
|
|
|
2011-06-27 11:47:52 -04:00
|
|
|
$query = $this->rc->db->query(
|
2012-04-24 10:14:01 +02:00
|
|
|
"INSERT INTO kolab_alarms
|
2014-04-17 17:49:00 +02:00
|
|
|
(alarm_id, user_id, dismissed, notifyat)
|
2012-05-16 18:58:57 +02:00
|
|
|
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
|
|
|
);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
$event = $storage->get_event($event['id']);
|
|
|
|
|
|
|
|
if ($event && !empty($event['attachments'])) {
|
|
|
|
foreach ($event['attachments'] as $att) {
|
|
|
|
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;
|
|
|
|
|
2012-04-25 19:26:40 +02:00
|
|
|
return $cal->storage->get_attachment($event['id'], $id);
|
2011-07-01 21:08:12 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
$cal = get_input_value('source', RCUBE_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
|
|
|
|
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
|
|
|
|
if ($calendar['id'] == self::BIRTHDAY_CALENDAR_ID) {
|
|
|
|
return parent::calendar_form($action, $calendar, $formfields);
|
|
|
|
}
|
|
|
|
|
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 {
|
2012-03-30 19:14:38 +02:00
|
|
|
$select = kolab_storage::folder_selector('event', array('name' => 'parent'), $folder);
|
2011-07-26 13:13:04 +02:00
|
|
|
$form['props']['fieldsets']['location']['content']['path'] = array(
|
|
|
|
'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(
|
|
|
|
'name' => Q($this->cal->gettext('tabsharing')),
|
|
|
|
'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) {
|
|
|
|
$content .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $subcontent) ."\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$content = $this->get_form_part($tab);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($content) {
|
2011-08-30 00:17:06 +02:00
|
|
|
$this->form_html .= html::tag('fieldset', null, html::tag('legend', null, 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) {
|
|
|
|
$colprop['id'] = '_'.$col;
|
|
|
|
$label = !empty($colprop['label']) ? $colprop['label'] : rcube_label($col);
|
|
|
|
|
|
|
|
$table->add('title', sprintf('<label for="%s">%s</label>', $colprop['id'], Q($label)));
|
|
|
|
$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()
|
|
|
|
{
|
|
|
|
$calid = get_input_value('_id', RCUBE_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) {
|
|
|
|
$db->query("DELETE FROM $table WHERE user_id=?", $args['user']->ID);
|
|
|
|
}
|
|
|
|
}
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|