2011-05-20 19:04:25 +02:00
|
|
|
<?php
|
2011-08-21 12:48:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Kolab driver for the Calendar plugin
|
|
|
|
*
|
|
|
|
* @version 0.6-beta
|
|
|
|
* @author Thomas Bruederli <roundcube@gmail.com>
|
|
|
|
* @author Aleksander Machniak <machniak@kolabsys.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011, Kolab Systems AG
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
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;
|
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;
|
2011-05-20 19:04:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Default constructor
|
|
|
|
*/
|
|
|
|
public function __construct($cal)
|
|
|
|
{
|
|
|
|
$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'));
|
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
|
|
|
|
|
|
|
// get all folders that have "event" type
|
|
|
|
$folders = rcube_kolab::get_folders('event');
|
2011-06-28 10:32:52 +02:00
|
|
|
$this->calendars = array();
|
2011-05-20 19:04:25 +02:00
|
|
|
|
|
|
|
if (PEAR::isError($folders)) {
|
2011-06-28 10:32:52 +02:00
|
|
|
raise_error(array(
|
|
|
|
'code' => 600, 'type' => 'php',
|
|
|
|
'file' => __FILE__, 'line' => __LINE__,
|
|
|
|
'message' => "Failed to list calendar folders from Kolab server:" . $folders->getMessage()),
|
|
|
|
true, false);
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-06-28 10:32:52 +02:00
|
|
|
// convert to UTF8 and sort
|
|
|
|
$names = array();
|
|
|
|
foreach ($folders as $folder)
|
|
|
|
$names[$folder->name] = rcube_charset_convert($folder->name, 'UTF7-IMAP');
|
2011-05-20 19:04:25 +02:00
|
|
|
|
2011-06-28 10:32:52 +02:00
|
|
|
asort($names, SORT_LOCALE_STRING);
|
2011-05-20 19:04:25 +02:00
|
|
|
|
2011-06-28 10:32:52 +02:00
|
|
|
foreach ($names as $utf7name => $name) {
|
|
|
|
$calendar = new kolab_calendar($utf7name, $this->cal);
|
|
|
|
$this->calendars[$calendar->id] = $calendar;
|
2011-08-06 17:51:08 +02:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
public function list_calendars()
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
2011-06-28 10:32:52 +02:00
|
|
|
$calendars = $names = array();
|
|
|
|
|
|
|
|
foreach ($this->calendars as $id => $cal) {
|
|
|
|
if ($cal->ready) {
|
|
|
|
$name = $origname = $cal->get_name();
|
|
|
|
|
|
|
|
// find folder prefix to truncate (the same code as in kolab_addressbook plugin)
|
|
|
|
for ($i = count($names)-1; $i >= 0; $i--) {
|
|
|
|
if (strpos($name, $names[$i].' » ') === 0) {
|
|
|
|
$length = strlen($names[$i].' » ');
|
|
|
|
$prefix = substr($name, 0, $length);
|
|
|
|
$count = count(explode(' » ', $prefix));
|
|
|
|
$name = str_repeat(' ', $count-1) . '» ' . substr($name, $length);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$names[] = $origname;
|
|
|
|
|
|
|
|
$calendars[$cal->id] = array(
|
|
|
|
'id' => $cal->id,
|
|
|
|
'name' => $name,
|
|
|
|
'editname' => $cal->get_foldername(),
|
|
|
|
'color' => $cal->get_color(),
|
|
|
|
'readonly' => $cal->readonly,
|
2011-07-31 14:40:52 +02:00
|
|
|
'showalarms' => $cal->alarms,
|
2011-06-28 10:32:52 +02:00
|
|
|
'class_name' => $cal->get_namespace(),
|
2011-08-26 23:24:49 +02:00
|
|
|
'active' => rcube_kolab::is_subscribed($cal->get_realname()),
|
2011-06-28 10:32:52 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $calendars;
|
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)
|
|
|
|
{
|
2011-07-26 13:13:04 +02:00
|
|
|
$folder = $this->folder_update($prop);
|
2011-06-27 15:49:51 +02:00
|
|
|
|
2011-07-26 13:13:04 +02:00
|
|
|
if ($folder === false) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-26 23:24:49 +02:00
|
|
|
|
|
|
|
// subscribe to new calendar by default
|
|
|
|
$this->rc->imap_connect();
|
|
|
|
$this->rc->imap->subscribe($folder);
|
2011-06-27 15:49:51 +02:00
|
|
|
|
|
|
|
// create ID
|
|
|
|
$id = rcube_kolab::folder_id($folder);
|
|
|
|
|
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)
|
|
|
|
{
|
2011-06-28 10:32:52 +02:00
|
|
|
if ($prop['id'] && ($cal = $this->calendars[$prop['id']])) {
|
2011-06-27 15:49:51 +02:00
|
|
|
$oldfolder = $cal->get_realname();
|
2011-07-26 13:13:04 +02:00
|
|
|
$newfolder = $this->folder_update($prop);
|
|
|
|
|
|
|
|
if ($newfolder === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create ID
|
|
|
|
$id = rcube_kolab::folder_id($newfolder);
|
|
|
|
|
2011-08-26 23:24:49 +02:00
|
|
|
// fallback to local prefs
|
2011-07-26 13:13:04 +02:00
|
|
|
$prefs['kolab_calendars'] = $this->rc->config->get('kolab_calendars', array());
|
|
|
|
unset($prefs['kolab_calendars'][$prop['id']]);
|
|
|
|
|
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-07-26 13:13:04 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-26 23:24:49 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set active/subscribed state of a calendar
|
|
|
|
*
|
|
|
|
* @see calendar_driver::subscribe_calendar()
|
|
|
|
*/
|
|
|
|
public function subscribe_calendar($prop)
|
|
|
|
{
|
|
|
|
if ($prop['id'] && ($cal = $this->calendars[$prop['id']])) {
|
|
|
|
$this->rc->imap_connect();
|
|
|
|
if ($prop['active'])
|
|
|
|
return $this->rc->imap->subscribe($cal->get_realname());
|
|
|
|
else
|
|
|
|
return $this->rc->imap->unsubscribe($cal->get_realname());
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2011-07-26 13:13:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rename or Create a new IMAP folder
|
|
|
|
*
|
|
|
|
* @param array Hash array with calendar properties
|
|
|
|
*
|
|
|
|
* @return mixed New folder name or False on failure
|
|
|
|
*/
|
2011-08-26 23:24:49 +02:00
|
|
|
private function folder_update(&$prop)
|
2011-07-26 13:13:04 +02:00
|
|
|
{
|
|
|
|
$folder = rcube_charset_convert($prop['name'], RCMAIL_CHARSET, 'UTF7-IMAP');
|
|
|
|
$oldfolder = $prop['oldname']; // UTF7
|
|
|
|
$parent = $prop['parent']; // UTF7
|
|
|
|
$delimiter = $_SESSION['imap_delimiter'];
|
|
|
|
|
2011-08-01 12:44:30 +02:00
|
|
|
if (strlen($oldfolder)) {
|
|
|
|
$this->rc->imap_connect();
|
|
|
|
$options = $this->rc->imap->mailbox_info($oldfolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($options) && ($options['norename'] || $options['protected'])) {
|
|
|
|
}
|
2011-07-26 13:13:04 +02:00
|
|
|
// sanity checks (from steps/settings/save_folder.inc)
|
2011-08-01 12:44:30 +02:00
|
|
|
else if (!strlen($folder)) {
|
2011-08-17 14:04:48 +02:00
|
|
|
$this->last_error = 'Invalid folder name';
|
2011-07-26 13:13:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (strlen($folder) > 128) {
|
2011-08-17 14:04:48 +02:00
|
|
|
$this->last_error = 'Folder name too long';
|
2011-07-26 13:13:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// these characters are problematic e.g. when used in LIST/LSUB
|
|
|
|
foreach (array($delimiter, '%', '*') as $char) {
|
|
|
|
if (strpos($folder, $delimiter) !== false) {
|
2011-08-17 14:04:48 +02:00
|
|
|
$this->last_error = 'Invalid folder name';
|
2011-07-26 13:13:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-01 12:44:30 +02:00
|
|
|
if (!empty($options) && ($options['protected'] || $options['norename'])) {
|
2011-07-26 13:13:04 +02:00
|
|
|
$folder = $oldfolder;
|
|
|
|
}
|
|
|
|
else if (strlen($parent)) {
|
|
|
|
$folder = $parent . $delimiter . $folder;
|
|
|
|
}
|
|
|
|
else {
|
2011-06-27 15:49:51 +02:00
|
|
|
// add namespace prefix (when needed)
|
|
|
|
$this->rc->imap_init();
|
2011-07-26 13:13:04 +02:00
|
|
|
$folder = $this->rc->imap->mod_mailbox($folder, 'in');
|
|
|
|
}
|
2011-06-27 15:49:51 +02:00
|
|
|
|
2011-08-10 19:01:09 +02:00
|
|
|
// Check access rights to the parent folder
|
|
|
|
if (strlen($parent) && (!strlen($oldfolder) || $oldfolder != $folder)) {
|
|
|
|
$this->rc->imap_connect();
|
|
|
|
$parent_opts = $this->rc->imap->mailbox_info($parent);
|
|
|
|
if ($parent_opts['namespace'] != 'personal'
|
|
|
|
&& (empty($parent_opts['rights']) || !preg_match('/[ck]/', implode($parent_opts)))
|
|
|
|
) {
|
2011-08-17 14:04:48 +02:00
|
|
|
$this->last_error = 'No permission to create folder';
|
2011-08-10 19:01:09 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-26 13:13:04 +02:00
|
|
|
// update the folder name
|
|
|
|
if (strlen($oldfolder)) {
|
2011-08-17 14:04:48 +02:00
|
|
|
if ($oldfolder != $folder) {
|
|
|
|
if (!($result = rcube_kolab::folder_rename($oldfolder, $folder)))
|
|
|
|
$this->last_error = rcube_kolab::$last_error;
|
|
|
|
}
|
2011-06-27 15:49:51 +02:00
|
|
|
else
|
|
|
|
$result = true;
|
2011-07-26 13:13:04 +02:00
|
|
|
}
|
|
|
|
// create new folder
|
|
|
|
else {
|
2011-08-17 14:04:48 +02:00
|
|
|
if (!($result = rcube_kolab::folder_create($folder, 'event', false)))
|
|
|
|
$this->last_error = rcube_kolab::$last_error;
|
2011-06-27 15:49:51 +02:00
|
|
|
}
|
2011-08-31 22:03:37 +02:00
|
|
|
|
2011-08-26 23:24:49 +02:00
|
|
|
// save color in METADATA
|
|
|
|
// TODO: also save 'showalarams' and other properties here
|
|
|
|
if ($result && $prop['color']) {
|
|
|
|
if (!($meta_saved = $this->rc->imap->set_metadata($folder, array('/shared/vendor/kolab/color' => $prop['color'])))) // try in shared namespace
|
|
|
|
$meta_saved = $this->rc->imap->set_metadata($folder, array('/private/vendor/kolab/color' => $prop['color'])); // try in private namespace
|
|
|
|
if ($meta_saved)
|
|
|
|
unset($prop['color']); // unsetting will prevent fallback to local user prefs
|
|
|
|
}
|
2011-08-31 22:03:37 +02:00
|
|
|
|
2011-07-26 13:13:04 +02:00
|
|
|
return $result ? $folder : false;
|
2011-06-08 18:48:06 -06:00
|
|
|
}
|
|
|
|
|
2011-06-27 15:49:51 +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)
|
|
|
|
{
|
2011-06-28 10:32:52 +02:00
|
|
|
if ($prop['id'] && ($cal = $this->calendars[$prop['id']])) {
|
2011-06-27 15:49:51 +02:00
|
|
|
$folder = $cal->get_realname();
|
2011-06-29 19:42:56 +02:00
|
|
|
if (rcube_kolab::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
|
|
|
|
$this->last_error = rcube_kolab::$last_error;
|
2011-06-27 15:49:51 +02:00
|
|
|
}
|
|
|
|
|
2011-06-08 18:48:06 -06:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2011-09-05 23:05:19 +02:00
|
|
|
public function get_event($event, $writeable = null)
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($cal && ($storage = $this->calendars[$cal])) {
|
2011-08-24 17:45:51 +02:00
|
|
|
return $storage->get_event($id);
|
|
|
|
}
|
|
|
|
// iterate over all calendar folders and search for the event ID
|
2011-09-05 23:05:19 +02:00
|
|
|
else if (!$cal) {
|
2011-08-24 17:45:51 +02:00
|
|
|
foreach ($this->calendars as $storage) {
|
2011-09-05 23:53:46 +02:00
|
|
|
if ($writeable && $storage->readonly)
|
2011-09-05 23:05:19 +02:00
|
|
|
continue;
|
2011-08-24 17:45:51 +02:00
|
|
|
if ($result = $storage->get_event($id)) {
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
$cid = $event['calendar'] ? $event['calendar'] : reset(array_keys($this->calendars));
|
2011-07-01 21:08:12 +02:00
|
|
|
if ($storage = $this->calendars[$cid]) {
|
|
|
|
// 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
|
|
|
$GLOBALS['conf']['kolab']['no_triggering'] = true;
|
|
|
|
$success = $storage->insert_event($event);
|
|
|
|
|
|
|
|
if ($success)
|
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
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2011-06-28 10:32:52 +02:00
|
|
|
if (($storage = $this->calendars[$event['calendar']]) && ($ev = $storage->get_event($event['id'])))
|
2011-06-29 19:42:56 +02:00
|
|
|
return $this->update_event($event + $ev);
|
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)
|
|
|
|
{
|
2011-06-28 11:20:17 +02:00
|
|
|
if (($storage = $this->calendars[$event['calendar']]) && ($ev = $storage->get_event($event['id'])))
|
2011-06-29 19:42:56 +02:00
|
|
|
return $this->update_event($event + $ev);
|
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;
|
2011-07-18 15:28:57 +02:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
if (($storage = $this->calendars[$event['calendar']]) && ($event = $storage->get_event($event['id']))) {
|
|
|
|
$savemode = 'all';
|
|
|
|
$master = $event;
|
2011-07-18 15:28:57 +02:00
|
|
|
|
2011-07-16 17:14:36 +02:00
|
|
|
$GLOBALS['conf']['kolab']['no_triggering'] = true;
|
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;
|
|
|
|
$savemode = $event['savemode'];
|
|
|
|
}
|
2011-07-18 15:28:57 +02:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
switch ($savemode) {
|
|
|
|
case 'current':
|
|
|
|
// add exception to master event
|
|
|
|
$master['recurrence']['EXDATE'][] = $event['start'];
|
|
|
|
$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']) {
|
|
|
|
// set until-date on master event
|
|
|
|
$master['recurrence']['UNTIL'] = $event['start'] - 86400;
|
|
|
|
unset($master['recurrence']['COUNT']);
|
|
|
|
$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
|
|
|
|
2011-07-16 17:14:36 +02:00
|
|
|
if ($success)
|
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)
|
|
|
|
{
|
|
|
|
if ($storage = $this->calendars[$event['calendar']]) {
|
2011-08-12 16:25:54 +02:00
|
|
|
if ($success = $storage->restore_event($event))
|
|
|
|
$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)
|
|
|
|
{
|
|
|
|
if (!($storage = $this->calendars[$event['calendar']]))
|
|
|
|
return false;
|
2011-07-01 21:08:12 +02:00
|
|
|
|
2011-06-29 19:42:56 +02:00
|
|
|
$success = false;
|
|
|
|
$savemode = 'all';
|
2011-07-01 21:08:12 +02:00
|
|
|
$attachments = array();
|
2011-06-29 19:42:56 +02:00
|
|
|
$old = $master = $storage->get_event($event['id']);
|
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) {
|
|
|
|
unset($old['attachments'][$idx]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2011-07-01 21:08:12 +02:00
|
|
|
// 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
|
|
|
|
$attachments[] = array(
|
|
|
|
'name' => $attachment['name'],
|
|
|
|
'type' => $attachment['mimetype'],
|
|
|
|
'content' => $attachment['data'] ? $attachment['data'] : file_get_contents($attachment['path']),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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']) {
|
|
|
|
$master = $old['recurrence_id'] ? $storage->get_event($old['recurrence_id']) : $old;
|
|
|
|
$savemode = $event['savemode'];
|
|
|
|
}
|
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'];
|
2011-07-01 21:08:12 +02:00
|
|
|
|
2011-07-16 17:14:36 +02:00
|
|
|
$GLOBALS['conf']['kolab']['no_triggering'] = true;
|
|
|
|
|
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();
|
|
|
|
$success = $storage->insert_event($event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'current':
|
|
|
|
// add exception to master event
|
|
|
|
$master['recurrence']['EXDATE'][] = $old['start'];
|
|
|
|
$storage->update_event($master);
|
|
|
|
|
|
|
|
// insert new event for this occurence
|
|
|
|
$event += $old;
|
|
|
|
$event['recurrence'] = array();
|
|
|
|
$event['uid'] = $this->cal->generate_uid();
|
|
|
|
$success = $storage->insert_event($event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'future':
|
|
|
|
if ($master['id'] != $event['id']) {
|
|
|
|
// set until-date on master event
|
|
|
|
$master['recurrence']['UNTIL'] = $old['start'] - 86400;
|
|
|
|
unset($master['recurrence']['COUNT']);
|
|
|
|
$storage->update_event($master);
|
|
|
|
|
|
|
|
// save this instance as new recurring event
|
|
|
|
$event += $old;
|
|
|
|
$event['uid'] = $this->cal->generate_uid();
|
|
|
|
|
|
|
|
// if recurrence COUNT, update value to the correct number of future occurences
|
|
|
|
if ($event['recurrence']['COUNT']) {
|
|
|
|
$event['recurrence']['COUNT'] -= $old['_instance'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove fixed weekday, will be re-set to the new weekday in kolab_calendar::insert_event()
|
|
|
|
if (strlen($event['recurrence']['BYDAY']) == 2)
|
|
|
|
unset($event['recurrence']['BYDAY']);
|
2011-07-05 19:45:09 +02:00
|
|
|
if ($master['recurrence']['BYMONTH'] == gmdate('n', $master['start']))
|
2011-06-29 19:42:56 +02:00
|
|
|
unset($event['recurrence']['BYMONTH']);
|
|
|
|
|
|
|
|
$success = $storage->insert_event($event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: // 'all' is default
|
|
|
|
$event['id'] = $master['id'];
|
|
|
|
$event['uid'] = $master['uid'];
|
|
|
|
|
|
|
|
// use start date from master but try to be smart on time or duration changes
|
|
|
|
$old_start_date = date('Y-m-d', $old['start']);
|
|
|
|
$old_start_time = date('H:i:s', $old['start']);
|
|
|
|
$old_duration = $old['end'] - $old['start'];
|
|
|
|
|
|
|
|
$new_start_date = date('Y-m-d', $event['start']);
|
|
|
|
$new_start_time = date('H:i:s', $event['start']);
|
|
|
|
$new_duration = $event['end'] - $event['start'];
|
|
|
|
|
|
|
|
// shifted or resized
|
|
|
|
if ($old_start_date == $new_start_date || $old_duration == $new_duration) {
|
|
|
|
$event['start'] = $master['start'] + ($event['start'] - $old['start']);
|
|
|
|
$event['end'] = $event['start'] + $new_duration;
|
|
|
|
|
|
|
|
// remove fixed weekday, will be re-set to the new weekday in kolab_calendar::update_event()
|
|
|
|
if (strlen($event['recurrence']['BYDAY']) == 2)
|
|
|
|
unset($event['recurrence']['BYDAY']);
|
2011-07-05 19:45:09 +02:00
|
|
|
if ($old['recurrence']['BYMONTH'] == gmdate('n', $old['start']))
|
2011-06-29 19:42:56 +02:00
|
|
|
unset($event['recurrence']['BYMONTH']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$success = $storage->update_event($event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-16 17:14:36 +02:00
|
|
|
if ($success)
|
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)
|
2011-07-19 14:54:13 +03:00
|
|
|
* @param boolean Strip virtual events (optional)
|
2011-05-20 19:04:25 +02:00
|
|
|
* @return array A list of event records
|
|
|
|
*/
|
2011-07-19 14:54:13 +03:00
|
|
|
public function load_events($start, $end, $search = null, $calendars = null, $virtual = 1)
|
2011-05-20 19:04:25 +02:00
|
|
|
{
|
|
|
|
if ($calendars && is_string($calendars))
|
|
|
|
$calendars = explode(',', $calendars);
|
2011-06-28 10:32:52 +02:00
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
$events = array();
|
|
|
|
foreach ($this->calendars as $cid => $calendar) {
|
|
|
|
if ($calendars && !in_array($cid, $calendars))
|
|
|
|
continue;
|
2011-06-28 10:32:52 +02:00
|
|
|
|
2011-07-19 14:54:13 +03:00
|
|
|
$events = array_merge($events, $this->calendars[$cid]->list_events($start, $end, $search, $virtual));
|
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;
|
|
|
|
|
|
|
|
$last = $time - max(60, $this->rc->session->get_keep_alive());
|
|
|
|
$last -= $last % $interval;
|
|
|
|
|
|
|
|
// only check for alerts once in 5 minutes
|
|
|
|
if ($last == $slot)
|
|
|
|
return false;
|
|
|
|
|
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;
|
|
|
|
|
2011-06-27 11:47:52 -04:00
|
|
|
$events = array();
|
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;
|
|
|
|
|
|
|
|
foreach ($calendar->list_events($time, $time + 86400 * 365) as $e) {
|
|
|
|
// add to list if alarm is set
|
|
|
|
if ($e['_alarm'] && ($notifyat = $e['start'] - $e['_alarm'] * 60) <= $time) {
|
|
|
|
$id = $e['id'];
|
|
|
|
$events[$id] = $e;
|
|
|
|
$events[$id]['notifyat'] = $notifyat;
|
|
|
|
}
|
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
|
|
|
|
if (!empty($events)) {
|
2011-06-28 08:45:05 +02:00
|
|
|
$event_ids = array_map(array($this->rc->db, 'quote'), array_keys($events));
|
2011-06-27 11:47:52 -04:00
|
|
|
$result = $this->rc->db->query(sprintf(
|
|
|
|
"SELECT * FROM kolab_alarms
|
2011-06-28 08:45:05 +02:00
|
|
|
WHERE event_id IN (%s)",
|
2011-06-27 11:47:52 -04:00
|
|
|
join(',', $event_ids),
|
|
|
|
$this->rc->db->now()
|
|
|
|
));
|
|
|
|
|
|
|
|
while ($result && ($e = $this->rc->db->fetch_assoc($result))) {
|
|
|
|
$dbdata[$e['event_id']] = $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$alarms = array();
|
|
|
|
foreach ($events as $id => $e) {
|
|
|
|
// skip dismissed
|
|
|
|
if ($dbdata[$id]['dismissed'])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// snooze function may have shifted alarm time
|
2011-06-28 08:45:05 +02:00
|
|
|
$notifyat = $dbdata[$id]['notifyat'] ? strtotime($dbdata[$id]['notifyat']) : $e['notifyat'];
|
2011-06-27 11:47:52 -04:00
|
|
|
if ($notifyat <= $time)
|
|
|
|
$alarms[] = $e;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
*/
|
2011-05-25 23:16:13 +02:00
|
|
|
public function dismiss_alarm($event_id, $snooze = 0)
|
2011-05-23 21:00:14 +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;
|
|
|
|
|
|
|
|
$query = $this->rc->db->query(
|
2011-06-28 08:45:05 +02:00
|
|
|
"REPLACE INTO kolab_alarms
|
|
|
|
(event_id, dismissed, notifyat)
|
|
|
|
VALUES(?, ?, ?)",
|
|
|
|
$event_id,
|
2011-06-27 11:47:52 -04: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
|
|
|
{
|
2011-07-01 21:08:12 +02:00
|
|
|
if (!($storage = $this->calendars[$event['calendar']]))
|
|
|
|
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
|
|
|
{
|
2011-07-01 21:08:12 +02:00
|
|
|
if (!($storage = $this->calendars[$event['calendar']]))
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public function get_attachment_body($id, $event)
|
|
|
|
{
|
|
|
|
if (!($storage = $this->calendars[$event['calendar']]))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return $storage->get_attachment_body($id);
|
|
|
|
}
|
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-05-26 15:44:46 +02:00
|
|
|
# fixed list according to http://www.kolab.org/doc/kolabformat-2.0rc7-html/c300.html
|
|
|
|
return array(
|
|
|
|
'important' => 'cc0000',
|
|
|
|
'business' => '333333',
|
|
|
|
'personal' => '333333',
|
|
|
|
'vacation' => '333333',
|
|
|
|
'must-attend' => '333333',
|
|
|
|
'travel-required' => '333333',
|
|
|
|
'needs-preparation' => '333333',
|
|
|
|
'birthday' => '333333',
|
|
|
|
'anniversary' => '333333',
|
|
|
|
'phone-call' => '333333',
|
|
|
|
);
|
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-08 17:29:22 +02:00
|
|
|
require_once('Horde/iCalendar.php');
|
2011-08-04 11:56:13 +02:00
|
|
|
|
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
|
|
|
|
$fbdata = @file_get_contents(rcube_kolab::get_freebusy_url($email));
|
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) {
|
2011-07-08 17:29:22 +02:00
|
|
|
$fbcal = new Horde_iCalendar;
|
|
|
|
$fbcal->parsevCalendar($fbdata);
|
|
|
|
if ($fb = $fbcal->findComponent('vfreebusy')) {
|
|
|
|
$result = array();
|
2011-07-23 12:18:29 +02:00
|
|
|
$params = $fb->getExtraParams();
|
2011-07-08 17:29:22 +02:00
|
|
|
foreach ($fb->getBusyPeriods() as $from => $to) {
|
|
|
|
if ($to == null) // no information, assume free
|
|
|
|
break;
|
2011-07-23 12:18:29 +02:00
|
|
|
$type = $params[$from]['FBTYPE'];
|
|
|
|
$result[] = array($from, $to, isset($fbtypemap[$type]) ? $fbtypemap[$type] : calendar::FREEBUSY_BUSY);
|
2011-07-08 17:29:22 +02:00
|
|
|
}
|
2011-07-27 10:48:40 +02:00
|
|
|
|
|
|
|
// set period from $start till the begin of the free-busy information as 'unknown'
|
|
|
|
if (($fbstart = $fb->getStart()) && $start < $fbstart) {
|
|
|
|
array_unshift($result, array($start, $fbstart, calendar::FREEBUSY_UNKNOWN));
|
|
|
|
}
|
2011-07-29 13:16:13 +02:00
|
|
|
// pad period till $end with status 'unknown'
|
|
|
|
if (($fbend = $fb->getEnd()) && $fbend < $end) {
|
|
|
|
$result[] = array($fbend, $end, calendar::FREEBUSY_UNKNOWN);
|
|
|
|
}
|
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);
|
|
|
|
if (!($storage = $this->calendars[$cal]))
|
|
|
|
return false;
|
2011-08-04 11:56:13 +02:00
|
|
|
|
2011-07-16 17:14:36 +02:00
|
|
|
// trigger updates on folder
|
|
|
|
$folder = $storage->get_folder();
|
|
|
|
$trigger = $folder->trigger();
|
2011-09-10 13:40:56 +02:00
|
|
|
if (is_object($trigger) && is_a($trigger, 'PEAR_Error')) {
|
2011-07-16 17:14:36 +02:00
|
|
|
raise_error(array(
|
|
|
|
'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
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
$delim = $_SESSION['imap_delimiter'];
|
|
|
|
$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);
|
|
|
|
|
|
|
|
$this->rc->imap_connect();
|
|
|
|
$options = $this->rc->imap->mailbox_info($folder);
|
|
|
|
}
|
|
|
|
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'));
|
|
|
|
$formfields['name']['value'] = Q(str_replace($delimiter, ' » ', rcube_kolab::object_name($folder)))
|
|
|
|
. $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 {
|
2011-07-29 13:33:08 +02:00
|
|
|
$select = rcube_kolab::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);
|
|
|
|
if ($calid && ($cal = $this->calendars[$calid])) {
|
|
|
|
$folder = $cal->get_realname(); // UTF7
|
|
|
|
$color = $cal->get_color();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$folder = '';
|
|
|
|
$color = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$hidden_fields[] = array('name' => 'oldname', 'value' => $folder);
|
|
|
|
|
|
|
|
$delim = $_SESSION['imap_delimiter'];
|
|
|
|
$form = array();
|
|
|
|
|
|
|
|
if (strlen($folder)) {
|
|
|
|
$path_imap = explode($delim, $folder);
|
|
|
|
array_pop($path_imap); // pop off name part
|
|
|
|
$path_imap = implode($path_imap, $delim);
|
|
|
|
|
|
|
|
$this->rc->imap_connect();
|
|
|
|
$options = $this->rc->imap->mailbox_info($folder);
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $plugin['form']['sharing']['content'];
|
|
|
|
}
|
|
|
|
|
2011-05-20 19:04:25 +02:00
|
|
|
}
|