Changeset View
Changeset View
Standalone View
Standalone View
plugins/calendar/drivers/kolab/kolab_driver.php
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | public function __construct($cal) | ||||
$cal->require_plugin('libkolab'); | $cal->require_plugin('libkolab'); | ||||
// load helper classes *after* libkolab has been loaded (#3248) | // load helper classes *after* libkolab has been loaded (#3248) | ||||
require_once(dirname(__FILE__) . '/kolab_calendar.php'); | require_once(dirname(__FILE__) . '/kolab_calendar.php'); | ||||
require_once(dirname(__FILE__) . '/kolab_user_calendar.php'); | require_once(dirname(__FILE__) . '/kolab_user_calendar.php'); | ||||
require_once(dirname(__FILE__) . '/kolab_invitation_calendar.php'); | require_once(dirname(__FILE__) . '/kolab_invitation_calendar.php'); | ||||
$this->cal = $cal; | $this->cal = $cal; | ||||
$this->rc = $cal->rc; | $this->rc = $cal->rc; | ||||
$this->_read_calendars(); | |||||
$this->cal->register_action('push-freebusy', array($this, 'push_freebusy')); | $this->cal->register_action('push-freebusy', array($this, 'push_freebusy')); | ||||
$this->cal->register_action('calendar-acl', array($this, 'calendar_acl')); | $this->cal->register_action('calendar-acl', array($this, 'calendar_acl')); | ||||
$this->freebusy_trigger = $this->rc->config->get('calendar_freebusy_trigger', false); | $this->freebusy_trigger = $this->rc->config->get('calendar_freebusy_trigger', false); | ||||
if (kolab_storage::$version == '2.0') { | if (kolab_storage::$version == '2.0') { | ||||
$this->alarm_types = array('DISPLAY'); | $this->alarm_types = array('DISPLAY'); | ||||
$this->alarm_absolute = false; | $this->alarm_absolute = false; | ||||
} | } | ||||
// get configuration for the Bonnie API | // get configuration for the Bonnie API | ||||
Show All 10 Lines | class kolab_driver extends calendar_driver | ||||
private function _read_calendars() | private function _read_calendars() | ||||
{ | { | ||||
// already read sources | // already read sources | ||||
if (isset($this->calendars)) | if (isset($this->calendars)) | ||||
return $this->calendars; | return $this->calendars; | ||||
// get all folders that have "event" type, sorted by namespace/name | // get all folders that have "event" type, sorted by namespace/name | ||||
$folders = kolab_storage::sort_folders(kolab_storage::get_folders('event') + kolab_storage::get_user_folders('event', true)); | $folders = kolab_storage::sort_folders(kolab_storage::get_folders('event') + kolab_storage::get_user_folders('event', true)); | ||||
$this->calendars = array(); | |||||
$this->calendars = array(); | |||||
foreach ($folders as $folder) { | foreach ($folders as $folder) { | ||||
if ($folder instanceof kolab_storage_folder_user) { | if ($folder instanceof kolab_storage_folder_user) { | ||||
$calendar = new kolab_user_calendar($folder->name, $this->cal); | $calendar = new kolab_user_calendar($folder, $this->cal); | ||||
$calendar->subscriptions = count($folder->children) > 0; | $calendar->subscriptions = count($folder->children) > 0; | ||||
} | } | ||||
else { | else { | ||||
$calendar = new kolab_calendar($folder->name, $this->cal); | $calendar = new kolab_calendar($folder->name, $this->cal); | ||||
} | } | ||||
if ($calendar->ready) { | if ($calendar->ready) { | ||||
$this->calendars[$calendar->id] = $calendar; | $this->calendars[$calendar->id] = $calendar; | ||||
Show All 10 Lines | class kolab_driver extends calendar_driver | ||||
* | * | ||||
* @param integer $filter Bitmask defining filter criterias | * @param integer $filter Bitmask defining filter criterias | ||||
* @param object $tree Reference to hierarchical folder tree object | * @param object $tree Reference to hierarchical folder tree object | ||||
* | * | ||||
* @return array List of calendars | * @return array List of calendars | ||||
*/ | */ | ||||
public function list_calendars($filter = 0, &$tree = null) | public function list_calendars($filter = 0, &$tree = null) | ||||
{ | { | ||||
$this->_read_calendars(); | |||||
// attempt to create a default calendar for this user | // attempt to create a default calendar for this user | ||||
if (!$this->has_writeable) { | if (!$this->has_writeable) { | ||||
if ($this->create_calendar(array('name' => 'Calendar', 'color' => 'cc0000'))) { | if ($this->create_calendar(array('name' => 'Calendar', 'color' => 'cc0000'))) { | ||||
unset($this->calendars); | unset($this->calendars); | ||||
$this->_read_calendars(); | $this->_read_calendars(); | ||||
} | } | ||||
} | } | ||||
$delim = $this->rc->get_storage()->get_hierarchy_delimiter(); | $delim = $this->rc->get_storage()->get_hierarchy_delimiter(); | ||||
$folders = $this->filter_calendars($filter); | $folders = $this->filter_calendars($filter); | ||||
$calendars = array(); | $calendars = array(); | ||||
Show All 22 Lines | foreach ($folders as $id => $cal) { | ||||
if ($cal instanceof kolab_storage_folder) { | if ($cal instanceof kolab_storage_folder) { | ||||
$cal = new kolab_calendar($cal->name, $this->cal); | $cal = new kolab_calendar($cal->name, $this->cal); | ||||
$this->calendars[$cal->id] = $cal; | $this->calendars[$cal->id] = $cal; | ||||
} | } | ||||
// special handling for user or virtual folders | // special handling for user or virtual folders | ||||
if ($cal instanceof kolab_storage_folder_user) { | if ($cal instanceof kolab_storage_folder_user) { | ||||
$calendars[$cal->id] = array( | $calendars[$cal->id] = array( | ||||
'id' => $cal->id, | 'id' => $cal->id, | ||||
'name' => kolab_storage::object_name($fullname), | 'name' => $fullname, | ||||
'listname' => $listname, | 'listname' => $listname, | ||||
'editname' => $cal->get_foldername(), | 'editname' => $cal->get_foldername(), | ||||
'color' => $cal->get_color(), | 'color' => $cal->get_color(), | ||||
'active' => $cal->is_active(), | 'active' => $cal->is_active(), | ||||
'title' => $cal->get_owner(), | 'title' => $cal->get_owner(), | ||||
'owner' => $cal->get_owner(), | 'owner' => $cal->get_owner(), | ||||
'history' => false, | 'history' => false, | ||||
'virtual' => false, | 'virtual' => false, | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | class kolab_driver extends calendar_driver | ||||
* Get list of calendars according to specified filters | * Get list of calendars according to specified filters | ||||
* | * | ||||
* @param integer Bitmask defining restrictions. See FILTER_* constants for possible values. | * @param integer Bitmask defining restrictions. See FILTER_* constants for possible values. | ||||
* | * | ||||
* @return array List of calendars | * @return array List of calendars | ||||
*/ | */ | ||||
protected function filter_calendars($filter) | protected function filter_calendars($filter) | ||||
{ | { | ||||
$this->_read_calendars(); | |||||
$calendars = array(); | $calendars = array(); | ||||
$plugin = $this->rc->plugins->exec_hook('calendar_list_filter', array( | $plugin = $this->rc->plugins->exec_hook('calendar_list_filter', array( | ||||
'list' => $this->calendars, | 'list' => $this->calendars, | ||||
'calendars' => $calendars, | 'calendars' => $calendars, | ||||
'filter' => $filter, | 'filter' => $filter, | ||||
'editable' => ($filter & self::FILTER_WRITEABLE), | 'editable' => ($filter & self::FILTER_WRITEABLE), | ||||
'insert' => ($filter & self::FILTER_INSERTABLE), | 'insert' => ($filter & self::FILTER_INSERTABLE), | ||||
Show All 37 Lines | class kolab_driver extends calendar_driver | ||||
/** | /** | ||||
* Get the kolab_calendar instance for the given calendar ID | * Get the kolab_calendar instance for the given calendar ID | ||||
* | * | ||||
* @param string Calendar identifier (encoded imap folder name) | * @param string Calendar identifier (encoded imap folder name) | ||||
* @return object kolab_calendar Object nor null if calendar doesn't exist | * @return object kolab_calendar Object nor null if calendar doesn't exist | ||||
*/ | */ | ||||
public function get_calendar($id) | public function get_calendar($id) | ||||
{ | { | ||||
$this->_read_calendars(); | |||||
// create calendar object if necesary | // create calendar object if necesary | ||||
if (!$this->calendars[$id] && in_array($id, array(self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED))) { | if (!$this->calendars[$id]) { | ||||
if (in_array($id, array(self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED))) { | |||||
$this->calendars[$id] = new kolab_invitation_calendar($id, $this->cal); | $this->calendars[$id] = new kolab_invitation_calendar($id, $this->cal); | ||||
} | } | ||||
else if (!$this->calendars[$id] && $id !== self::BIRTHDAY_CALENDAR_ID) { | else if ($id !== self::BIRTHDAY_CALENDAR_ID) { | ||||
$calendar = kolab_calendar::factory($id, $this->cal); | $calendar = kolab_calendar::factory($id, $this->cal); | ||||
if ($calendar->ready) | if ($calendar->ready) { | ||||
$this->calendars[$calendar->id] = $calendar; | $this->calendars[$calendar->id] = $calendar; | ||||
} | } | ||||
} | |||||
} | |||||
return $this->calendars[$id]; | return $this->calendars[$id]; | ||||
} | } | ||||
/** | /** | ||||
* Create a new calendar assigned to the current user | * Create a new calendar assigned to the current user | ||||
* | * | ||||
* @param array Hash array with calendar properties | * @param array Hash array with calendar properties | ||||
▲ Show 20 Lines • Show All 227 Lines • ▼ Show 20 Lines | class kolab_driver extends calendar_driver | ||||
*/ | */ | ||||
public function new_event($event) | public function new_event($event) | ||||
{ | { | ||||
if (!$this->validate($event)) | if (!$this->validate($event)) | ||||
return false; | return false; | ||||
$event = self::from_rcube_event($event); | $event = self::from_rcube_event($event); | ||||
$cid = $event['calendar'] ? $event['calendar'] : reset(array_keys($this->calendars)); | if (!$event['calendar']) { | ||||
if ($storage = $this->get_calendar($cid)) { | $this->_read_calendars(); | ||||
$event['calendar'] = reset(array_keys($this->calendars)); | |||||
} | |||||
if ($storage = $this->get_calendar($event['calendar'])) { | |||||
// if this is a recurrence instance, append as exception to an already existing object for this UID | // if this is a recurrence instance, append as exception to an already existing object for this UID | ||||
if (!empty($event['recurrence_date']) && ($master = $storage->get_event($event['uid']))) { | if (!empty($event['recurrence_date']) && ($master = $storage->get_event($event['uid']))) { | ||||
self::add_exception($master, $event); | self::add_exception($master, $event); | ||||
$success = $storage->update_event($master); | $success = $storage->update_event($master); | ||||
} | } | ||||
else { | else { | ||||
$success = $storage->insert_event($event); | $success = $storage->insert_event($event); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 402 Lines • ▼ Show 20 Lines | switch ($savemode) { | ||||
// create a new recurring event | // create a new recurring event | ||||
$event['_copyfrom'] = $master['_msguid']; | $event['_copyfrom'] = $master['_msguid']; | ||||
$event['_mailbox'] = $master['_mailbox']; | $event['_mailbox'] = $master['_mailbox']; | ||||
$event['uid'] = $this->cal->generate_uid(); | $event['uid'] = $this->cal->generate_uid(); | ||||
unset($event['recurrence_id'], $event['recurrence_date'], $event['_instance'], $event['id']); | unset($event['recurrence_id'], $event['recurrence_date'], $event['_instance'], $event['id']); | ||||
// copy attachment metadata to new event | // copy attachment metadata to new event | ||||
$event = self::from_rcube_event($event, $master); | $event = self::from_rcube_event($event, $master); | ||||
// remove recurrence exceptions on re-scheduling | // remove recurrence exceptions on re-scheduling | ||||
if ($reschedule) { | if ($reschedule) { | ||||
unset($event['recurrence']['EXCEPTIONS'], $event['exceptions'], $master['recurrence']['EXDATE']); | unset($event['recurrence']['EXCEPTIONS'], $event['exceptions'], $master['recurrence']['EXDATE']); | ||||
} | } | ||||
else if (is_array($event['recurrence']['EXCEPTIONS'])) { | else if (is_array($event['recurrence']['EXCEPTIONS'])) { | ||||
// only keep relevant exceptions | // only keep relevant exceptions | ||||
$event['recurrence']['EXCEPTIONS'] = array_filter($event['recurrence']['EXCEPTIONS'], function($exception) use ($event) { | $event['recurrence']['EXCEPTIONS'] = array_filter($event['recurrence']['EXCEPTIONS'], function($exception) use ($event) { | ||||
return $exception['start'] > $event['start']; | return $exception['start'] > $event['start']; | ||||
▲ Show 20 Lines • Show All 407 Lines • ▼ Show 20 Lines | */ | ||||
* @param boolean Include virtual events (optional) | * @param boolean Include virtual events (optional) | ||||
* @param integer Only list events modified since this time (unix timestamp) | * @param integer Only list events modified since this time (unix timestamp) | ||||
* @return array A list of event records | * @return array A list of event records | ||||
*/ | */ | ||||
public function load_events($start, $end, $search = null, $calendars = null, $virtual = 1, $modifiedsince = null) | public function load_events($start, $end, $search = null, $calendars = null, $virtual = 1, $modifiedsince = null) | ||||
{ | { | ||||
if ($calendars && is_string($calendars)) | if ($calendars && is_string($calendars)) | ||||
$calendars = explode(',', $calendars); | $calendars = explode(',', $calendars); | ||||
else if (!$calendars) | else if (!$calendars) { | ||||
$this->_read_calendars(); | |||||
$calendars = array_keys($this->calendars); | $calendars = array_keys($this->calendars); | ||||
} | |||||
$query = array(); | $query = array(); | ||||
if ($modifiedsince) | if ($modifiedsince) | ||||
$query[] = array('changed', '>=', $modifiedsince); | $query[] = array('changed', '>=', $modifiedsince); | ||||
$events = $categories = array(); | $events = $categories = array(); | ||||
foreach ($calendars as $cid) { | foreach ($calendars as $cid) { | ||||
if ($storage = $this->get_calendar($cid)) { | if ($storage = $this->get_calendar($cid)) { | ||||
Show All 28 Lines | */ | ||||
* @return array Hash array with counts grouped by calendar ID | * @return array Hash array with counts grouped by calendar ID | ||||
*/ | */ | ||||
public function count_events($calendars, $start, $end = null) | public function count_events($calendars, $start, $end = null) | ||||
{ | { | ||||
$counts = array(); | $counts = array(); | ||||
if ($calendars && is_string($calendars)) | if ($calendars && is_string($calendars)) | ||||
$calendars = explode(',', $calendars); | $calendars = explode(',', $calendars); | ||||
else if (!$calendars) | else if (!$calendars) { | ||||
$this->_read_calendars(); | |||||
$calendars = array_keys($this->calendars); | $calendars = array_keys($this->calendars); | ||||
} | |||||
foreach ($calendars as $cid) { | foreach ($calendars as $cid) { | ||||
if ($storage = $this->get_calendar($cid)) { | if ($storage = $this->get_calendar($cid)) { | ||||
$counts[$cid] = $storage->count_events($start, $end); | $counts[$cid] = $storage->count_events($start, $end); | ||||
} | } | ||||
} | } | ||||
return $counts; | return $counts; | ||||
Show All 21 Lines | public function pending_alarms($time, $calendars = null) | ||||
if ($calendars && is_string($calendars)) | if ($calendars && is_string($calendars)) | ||||
$calendars = explode(',', $calendars); | $calendars = explode(',', $calendars); | ||||
$time = $slot + $interval; | $time = $slot + $interval; | ||||
$candidates = array(); | $candidates = array(); | ||||
$query = array(array('tags', '=', 'x-has-alarms')); | $query = array(array('tags', '=', 'x-has-alarms')); | ||||
$this->_read_calendars(); | |||||
foreach ($this->calendars as $cid => $calendar) { | foreach ($this->calendars as $cid => $calendar) { | ||||
// skip calendars with alarms disabled | // skip calendars with alarms disabled | ||||
if (!$calendar->alarms || ($calendars && !in_array($cid, $calendars))) | if (!$calendar->alarms || ($calendars && !in_array($cid, $calendars))) | ||||
continue; | continue; | ||||
foreach ($calendar->list_events($time, $time + 86400 * 365, null, 1, $query) as $e) { | foreach ($calendar->list_events($time, $time + 86400 * 365, null, 1, $query) as $e) { | ||||
// add to list if alarm is set | // add to list if alarm is set | ||||
$alarm = libcalendaring::get_next_alarm($e); | $alarm = libcalendaring::get_next_alarm($e); | ||||
▲ Show 20 Lines • Show All 780 Lines • ▼ Show 20 Lines | */ | ||||
{ | { | ||||
// show default dialog for birthday calendar | // show default dialog for birthday calendar | ||||
if (in_array($calendar['id'], array(self::BIRTHDAY_CALENDAR_ID, self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED))) { | if (in_array($calendar['id'], array(self::BIRTHDAY_CALENDAR_ID, self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED))) { | ||||
if ($calendar['id'] != self::BIRTHDAY_CALENDAR_ID) | if ($calendar['id'] != self::BIRTHDAY_CALENDAR_ID) | ||||
unset($formfields['showalarms']); | unset($formfields['showalarms']); | ||||
return parent::calendar_form($action, $calendar, $formfields); | return parent::calendar_form($action, $calendar, $formfields); | ||||
} | } | ||||
$this->_read_calendars(); | |||||
if ($calendar['id'] && ($cal = $this->calendars[$calendar['id']])) { | if ($calendar['id'] && ($cal = $this->calendars[$calendar['id']])) { | ||||
$folder = $cal->get_realname(); // UTF7 | $folder = $cal->get_realname(); // UTF7 | ||||
$color = $cal->get_color(); | $color = $cal->get_color(); | ||||
} | } | ||||
else { | else { | ||||
$folder = ''; | $folder = ''; | ||||
$color = ''; | $color = ''; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 198 Lines • Show Last 20 Lines |