PHP8 compatibility fixes
Summary: PHP8 fixes, CS fixes, short array syntax, indentation Reviewers: #roundcube_kolab_plugins_developers Subscribers: #roundcube_kolab_plugins_developers Tags: #roundcube_kolab_plugins Differential Revision: https://git.kolab.org/D2185
This commit is contained in:
parent
fba24494dd
commit
87fbaea696
28 changed files with 10577 additions and 9546 deletions
File diff suppressed because it is too large
Load diff
|
@ -24,7 +24,7 @@
|
|||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0",
|
||||
"php": ">=5.4.0",
|
||||
"roundcube/plugin-installer": ">=0.1.3",
|
||||
"kolab/libcalendaring": ">=3.4.0",
|
||||
"kolab/libkolab": ">=3.4.0"
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -136,7 +136,7 @@ class database_driver extends calendar_driver
|
|||
$hidden = array_filter(explode(',', $this->rc->config->get('hidden_calendars', '')));
|
||||
$id = self::BIRTHDAY_CALENDAR_ID;
|
||||
|
||||
if (!$active || !in_array($id, $hidden)) {
|
||||
if (empty($active) || !in_array($id, $hidden)) {
|
||||
$calendars[$id] = array(
|
||||
'id' => $id,
|
||||
'name' => $this->cal->gettext('birthdays'),
|
||||
|
@ -172,7 +172,7 @@ class database_driver extends calendar_driver
|
|||
$this->rc->user->ID,
|
||||
$prop['name'],
|
||||
strval($prop['color']),
|
||||
$prop['showalarms'] ? 1 : 0
|
||||
!empty($prop['showalarms']) ? 1 : 0
|
||||
);
|
||||
|
||||
if ($result) {
|
||||
|
@ -321,24 +321,24 @@ class database_driver extends calendar_driver
|
|||
. " VALUES (?, $now, $now, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
$event['calendar'],
|
||||
strval($event['uid']),
|
||||
intval($event['recurrence_id']),
|
||||
strval($event['_instance']),
|
||||
intval($event['isexception']),
|
||||
isset($event['recurrence_id']) ? intval($event['recurrence_id']) : 0,
|
||||
isset($event['_instance']) ? strval($event['_instance']) : '',
|
||||
isset($event['isexception']) ? intval($event['isexception']) : 0,
|
||||
$event['start']->format(self::DB_DATE_FORMAT),
|
||||
$event['end']->format(self::DB_DATE_FORMAT),
|
||||
intval($event['all_day']),
|
||||
$event['_recurrence'],
|
||||
strval($event['title']),
|
||||
strval($event['description']),
|
||||
strval($event['location']),
|
||||
join(',', (array)$event['categories']),
|
||||
strval($event['url']),
|
||||
isset($event['description']) ? strval($event['description']) : '',
|
||||
isset($event['location']) ? strval($event['location']) : '',
|
||||
isset($event['categories']) ? join(',', (array) $event['categories']) : '',
|
||||
isset($event['url']) ? strval($event['url']) : '',
|
||||
intval($event['free_busy']),
|
||||
intval($event['priority']),
|
||||
intval($event['sensitivity']),
|
||||
strval($event['status']),
|
||||
isset($event['status']) ? strval($event['status']) : '',
|
||||
$event['attendees'],
|
||||
$event['alarms'],
|
||||
isset($event['alarms']) ? $event['alarms'] : null,
|
||||
$event['notifyat']
|
||||
);
|
||||
|
||||
|
@ -381,7 +381,7 @@ class database_driver extends calendar_driver
|
|||
|
||||
// increment sequence number
|
||||
if (empty($event['sequence']) && $reschedule) {
|
||||
$event['sequence'] = max($event['sequence'], $old['sequence']) + 1;
|
||||
$event['sequence'] = $old['sequence'] + 1;
|
||||
}
|
||||
|
||||
// modify a recurring event, check submitted savemode to do the right things
|
||||
|
@ -389,11 +389,12 @@ class database_driver extends calendar_driver
|
|||
$master = $old['recurrence_id'] ? $this->get_event(array('id' => $old['recurrence_id'])) : $old;
|
||||
|
||||
// keep saved exceptions (not submitted by the client)
|
||||
if ($old['recurrence']['EXDATE']) {
|
||||
if (!empty($old['recurrence']['EXDATE'])) {
|
||||
$event['recurrence']['EXDATE'] = $old['recurrence']['EXDATE'];
|
||||
}
|
||||
|
||||
switch ($event['_savemode']) {
|
||||
$savemode = isset($event['_savemode']) ? $event['_savemode'] : null;
|
||||
switch ($savemode) {
|
||||
case 'new':
|
||||
$event['uid'] = $this->cal->generate_uid();
|
||||
return $this->new_event($event);
|
||||
|
@ -582,10 +583,12 @@ class database_driver extends calendar_driver
|
|||
|
||||
// iterate through the list of properties considered 'significant' for scheduling
|
||||
foreach (self::$scheduling_properties as $prop) {
|
||||
$a = $old[$prop];
|
||||
$b = $event[$prop];
|
||||
$a = isset($old[$prop]) ? $old[$prop] : null;
|
||||
$b = isset($event[$prop]) ? $event[$prop] : null;
|
||||
|
||||
if ($event['allday'] && ($prop == 'start' || $prop == 'end') && $a instanceof DateTime && $b instanceof DateTime) {
|
||||
if (!empty($event['allday']) && ($prop == 'start' || $prop == 'end')
|
||||
&& $a instanceof DateTime && $b instanceof DateTime
|
||||
) {
|
||||
$a = $a->format('Y-m-d');
|
||||
$b = $b->format('Y-m-d');
|
||||
}
|
||||
|
@ -596,10 +599,10 @@ class database_driver extends calendar_driver
|
|||
$b = array_filter($b);
|
||||
|
||||
// advanced rrule comparison: no rescheduling if series was shortened
|
||||
if ($a['COUNT'] && $b['COUNT'] && $b['COUNT'] < $a['COUNT']) {
|
||||
if (!empty($a['COUNT']) && !empty($b['COUNT']) && $b['COUNT'] < $a['COUNT']) {
|
||||
unset($a['COUNT'], $b['COUNT']);
|
||||
}
|
||||
else if ($a['UNTIL'] && $b['UNTIL'] && $b['UNTIL'] < $a['UNTIL']) {
|
||||
else if (!empty($a['UNTIL']) && !empty($b['UNTIL']) && $b['UNTIL'] < $a['UNTIL']) {
|
||||
unset($a['UNTIL'], $b['UNTIL']);
|
||||
}
|
||||
}
|
||||
|
@ -652,24 +655,24 @@ class database_driver extends calendar_driver
|
|||
}
|
||||
|
||||
// compose vcalendar-style recurrencue rule from structured data
|
||||
$rrule = $event['recurrence'] ? libcalendaring::to_rrule($event['recurrence']) : '';
|
||||
$rrule = !empty($event['recurrence']) ? libcalendaring::to_rrule($event['recurrence']) : '';
|
||||
|
||||
$sensitivity = strtolower($event['sensitivity']);
|
||||
$free_busy = strtolower($event['free_busy']);
|
||||
|
||||
$event['_recurrence'] = rtrim($rrule, ';');
|
||||
$event['free_busy'] = intval($this->free_busy_map[strtolower($event['free_busy'])]);
|
||||
$event['sensitivity'] = intval($this->sensitivity_map[strtolower($event['sensitivity'])]);
|
||||
$event['free_busy'] = isset($this->free_busy_map[$free_busy]) ? $this->free_busy_map[$free_busy] : null;
|
||||
$event['sensitivity'] = isset($this->sensitivity_map[$sensitivity]) ? $this->sensitivity_map[$sensitivity] : null;
|
||||
$event['all_day'] = !empty($event['allday']) ? 1 : 0;
|
||||
|
||||
if ($event['free_busy'] == 'tentative') {
|
||||
$event['status'] = 'TENTATIVE';
|
||||
}
|
||||
|
||||
if (isset($event['allday'])) {
|
||||
$event['all_day'] = $event['allday'] ? 1 : 0;
|
||||
}
|
||||
|
||||
// compute absolute time to notify the user
|
||||
$event['notifyat'] = $this->_get_notification($event);
|
||||
|
||||
if (is_array($event['valarms'])) {
|
||||
if (!empty($event['valarms'])) {
|
||||
$event['alarms'] = $this->serialize_alarms($event['valarms']);
|
||||
}
|
||||
|
||||
|
@ -689,7 +692,7 @@ class database_driver extends calendar_driver
|
|||
*/
|
||||
private function _get_notification($event)
|
||||
{
|
||||
if ($event['valarms'] && $event['start'] > new DateTime()) {
|
||||
if (!empty($event['valarms']) && $event['start'] > new DateTime()) {
|
||||
$alarm = libcalendaring::get_next_alarm($event);
|
||||
|
||||
if ($alarm['time'] && in_array($alarm['action'], $this->alarm_types)) {
|
||||
|
@ -714,26 +717,23 @@ class database_driver extends calendar_driver
|
|||
);
|
||||
|
||||
foreach ($set_cols as $col) {
|
||||
if (is_object($event[$col]) && is_a($event[$col], 'DateTime')) {
|
||||
if (!empty($event[$col]) && is_a($event[$col], 'DateTime')) {
|
||||
$sql_args[$col] = $event[$col]->format(self::DB_DATE_FORMAT);
|
||||
}
|
||||
else if (is_array($event[$col])) {
|
||||
$sql_args[$col] = join(',', $event[$col]);
|
||||
}
|
||||
else if (array_key_exists($col, $event)) {
|
||||
$sql_args[$col] = $event[$col];
|
||||
$sql_args[$col] = is_array($event[$col]) ? join(',', $event[$col]) : $event[$col];
|
||||
}
|
||||
}
|
||||
|
||||
if ($event['_recurrence']) {
|
||||
if (!empty($event['_recurrence'])) {
|
||||
$sql_args['recurrence'] = $event['_recurrence'];
|
||||
}
|
||||
|
||||
if ($event['_instance']) {
|
||||
if (!empty($event['_instance'])) {
|
||||
$sql_args['instance'] = $event['_instance'];
|
||||
}
|
||||
|
||||
if ($event['_fromcalendar'] && $event['_fromcalendar'] != $event['calendar']) {
|
||||
if (!empty($event['_fromcalendar']) && $event['_fromcalendar'] != $event['calendar']) {
|
||||
$sql_args['calendar_id'] = $event['calendar'];
|
||||
}
|
||||
|
||||
|
@ -763,7 +763,7 @@ class database_driver extends calendar_driver
|
|||
}
|
||||
|
||||
// remove attachments
|
||||
if ($success && !empty($event['deleted_attachments'])) {
|
||||
if ($success && !empty($event['deleted_attachments']) && is_array($event['deleted_attachments'])) {
|
||||
foreach ($event['deleted_attachments'] as $attachment) {
|
||||
$this->remove_attachment($attachment, $event['id']);
|
||||
}
|
||||
|
@ -822,7 +822,7 @@ class database_driver extends calendar_driver
|
|||
|
||||
// skip exceptions
|
||||
// TODO: merge updated data from master event
|
||||
if ($exdata[$datestr]) {
|
||||
if (!empty($exdata[$datestr])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -831,7 +831,7 @@ class database_driver extends calendar_driver
|
|||
$next_end->add($duration);
|
||||
|
||||
$notify_at = $this->_get_notification(array(
|
||||
'alarms' => $event['alarms'],
|
||||
'alarms' => !empty($event['alarms']) ? $event['alarms'] : null,
|
||||
'start' => $next_start,
|
||||
'end' => $next_end,
|
||||
'status' => $event['status']
|
||||
|
@ -860,13 +860,13 @@ class database_driver extends calendar_driver
|
|||
}
|
||||
|
||||
// stop adding events for inifinite recurrence after 20 years
|
||||
if (++$count > 999 || (!$recurrence->recurEnd && !$recurrence->recurCount && $next_start->format('Y') > date('Y') + 20)) {
|
||||
if (++$count > 999 || (empty($recurrence->recurEnd) && empty($recurrence->recurCount) && $next_start->format('Y') > date('Y') + 20)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// remove all exceptions after recurrence end
|
||||
if ($next_end && !empty($exceptions)) {
|
||||
if (!empty($next_end) && !empty($exceptions)) {
|
||||
$this->rc->db->query(
|
||||
"DELETE FROM `{$this->db_events}`"
|
||||
. " WHERE `recurrence_id` = ? AND `isexception` = 1 AND `start` > ?"
|
||||
|
@ -1025,11 +1025,11 @@ class database_driver extends calendar_driver
|
|||
*/
|
||||
public function get_event($event, $scope = 0, $full = false)
|
||||
{
|
||||
$id = is_array($event) ? ($event['id'] ?: $event['uid']) : $event;
|
||||
$cal = is_array($event) ? $event['calendar'] : null;
|
||||
$id = is_array($event) ? (!empty($event['id']) ? $event['id'] : $event['uid']) : $event;
|
||||
$cal = is_array($event) && !empty($event['calendar']) ? $event['calendar'] : null;
|
||||
$col = is_array($event) && is_numeric($id) ? 'event_id' : 'uid';
|
||||
|
||||
if ($this->cache[$id]) {
|
||||
if (!empty($this->cache[$id])) {
|
||||
return $this->cache[$id];
|
||||
}
|
||||
|
||||
|
@ -1039,15 +1039,15 @@ class database_driver extends calendar_driver
|
|||
}
|
||||
|
||||
$where_add = '';
|
||||
if (is_array($event) && !$event['id'] && !empty($event['_instance'])) {
|
||||
if (is_array($event) && empty($event['id']) && !empty($event['_instance'])) {
|
||||
$where_add = " AND e.instance = " . $this->rc->db->quote($event['_instance']);
|
||||
}
|
||||
|
||||
if ($scope & self::FILTER_ACTIVE) {
|
||||
$calendars = $this->calendars;
|
||||
foreach ($calendars as $idx => $cal) {
|
||||
if (!$cal['active']) {
|
||||
unset($calendars[$idx]);
|
||||
$calendars = [];
|
||||
foreach ($this->calendars as $idx => $cal) {
|
||||
if (!empty($cal['active'])) {
|
||||
$calendars[] = $idx;
|
||||
}
|
||||
}
|
||||
$cals = join(',', $calendars);
|
||||
|
@ -1099,11 +1099,12 @@ class database_driver extends calendar_driver
|
|||
|
||||
// compose (slow) SQL query for searching
|
||||
// FIXME: improve searching using a dedicated col and normalized values
|
||||
$sql_add = '';
|
||||
if ($query) {
|
||||
foreach (array('title','location','description','categories','attendees') as $col) {
|
||||
$sql_query[] = $this->rc->db->ilike($col, '%'.$query.'%');
|
||||
}
|
||||
$sql_add = " AND (" . join(' OR ', $sql_query) . ")";
|
||||
$sql_add .= " AND (" . join(' OR ', $sql_query) . ")";
|
||||
}
|
||||
|
||||
if (!$virtual) {
|
||||
|
@ -1155,7 +1156,7 @@ class database_driver extends calendar_driver
|
|||
|
||||
// add events from the address books birthday calendar
|
||||
if (in_array(self::BIRTHDAY_CALENDAR_ID, $calendars) && empty($query)) {
|
||||
$events = array_merge($events, $this->load_birthday_events($start, $end, $search, $modifiedsince));
|
||||
$events = array_merge($events, $this->load_birthday_events($start, $end, null, $modifiedsince));
|
||||
}
|
||||
|
||||
return $events;
|
||||
|
@ -1229,7 +1230,7 @@ class database_driver extends calendar_driver
|
|||
}
|
||||
}
|
||||
|
||||
if ($event['_attachments'] > 0) {
|
||||
if (!empty($event['_attachments'])) {
|
||||
$event['attachments'] = (array)$this->list_attachments($event);
|
||||
}
|
||||
|
||||
|
@ -1398,7 +1399,7 @@ class database_driver extends calendar_driver
|
|||
. "SELECT `event_id` FROM `{$this->db_events}`"
|
||||
. " WHERE `event_id` = ? AND `calendar_id` IN ({$this->calendar_ids}))",
|
||||
$id,
|
||||
$event['recurrence_id'] ? $event['recurrence_id'] : $event['id']
|
||||
!empty($event['recurrence_id']) ? $event['recurrence_id'] : $event['id']
|
||||
);
|
||||
|
||||
if ($result && ($arr = $this->rc->db->fetch_assoc($result))) {
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -23,389 +23,402 @@
|
|||
|
||||
class kolab_invitation_calendar
|
||||
{
|
||||
public $id = '__invitation__';
|
||||
public $ready = true;
|
||||
public $alarms = false;
|
||||
public $rights = 'lrsv';
|
||||
public $editable = false;
|
||||
public $attachments = false;
|
||||
public $subscriptions = false;
|
||||
public $partstats = array('unknown');
|
||||
public $categories = array();
|
||||
public $name = 'Invitations';
|
||||
public $id = '__invitation__';
|
||||
public $ready = true;
|
||||
public $alarms = false;
|
||||
public $rights = 'lrsv';
|
||||
public $editable = false;
|
||||
public $attachments = false;
|
||||
public $subscriptions = false;
|
||||
public $partstats = ['unknown'];
|
||||
public $categories = [];
|
||||
public $name = 'Invitations';
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public function __construct($id, $calendar)
|
||||
{
|
||||
$this->cal = $calendar;
|
||||
$this->id = $id;
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public function __construct($id, $calendar)
|
||||
{
|
||||
$this->cal = $calendar;
|
||||
$this->id = $id;
|
||||
|
||||
switch ($this->id) {
|
||||
case kolab_driver::INVITATIONS_CALENDAR_PENDING:
|
||||
$this->partstats = array('NEEDS-ACTION');
|
||||
$this->name = $this->cal->gettext('invitationspending');
|
||||
if (!empty($_REQUEST['_quickview']))
|
||||
$this->partstats[] = 'TENTATIVE';
|
||||
break;
|
||||
switch ($this->id) {
|
||||
case kolab_driver::INVITATIONS_CALENDAR_PENDING:
|
||||
$this->partstats = ['NEEDS-ACTION'];
|
||||
$this->name = $this->cal->gettext('invitationspending');
|
||||
|
||||
case kolab_driver::INVITATIONS_CALENDAR_DECLINED:
|
||||
$this->partstats = array('DECLINED');
|
||||
$this->name = $this->cal->gettext('invitationsdeclined');
|
||||
break;
|
||||
}
|
||||
|
||||
// user-specific alarms settings win
|
||||
$prefs = $this->cal->rc->config->get('kolab_calendars', array());
|
||||
if (isset($prefs[$this->id]['showalarms']))
|
||||
$this->alarms = $prefs[$this->id]['showalarms'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for a nice and human readable name for this calendar
|
||||
*
|
||||
* @return string Name of this calendar
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the IMAP folder owner
|
||||
*
|
||||
* @return string Name of the folder owner
|
||||
*/
|
||||
public function get_owner()
|
||||
{
|
||||
return $this->cal->rc->get_user_name();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function get_title()
|
||||
{
|
||||
return $this->get_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the name of the namespace to which the IMAP folder belongs
|
||||
*
|
||||
* @return string Name of the namespace (personal, other, shared)
|
||||
*/
|
||||
public function get_namespace()
|
||||
{
|
||||
return 'x-special';
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the top-end calendar folder name (not the entire path)
|
||||
*
|
||||
* @return string Name of this calendar
|
||||
*/
|
||||
public function get_foldername()
|
||||
{
|
||||
return $this->get_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the Cyrus mailbox identifier corresponding to this folder
|
||||
*
|
||||
* @return string Mailbox ID
|
||||
*/
|
||||
public function get_mailbox_id()
|
||||
{
|
||||
// this is a virtual collection and has no concrete mailbox ID
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return color to display this calendar
|
||||
*/
|
||||
public function get_color()
|
||||
{
|
||||
// calendar color is stored in local user prefs
|
||||
$prefs = $this->cal->rc->config->get('kolab_calendars', array());
|
||||
|
||||
if (!empty($prefs[$this->id]) && !empty($prefs[$this->id]['color']))
|
||||
return $prefs[$this->id]['color'];
|
||||
|
||||
return 'ffffff';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose an URL for CalDAV access to this calendar (if configured)
|
||||
*/
|
||||
public function get_caldav_url()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check activation status of this folder
|
||||
*
|
||||
* @return boolean True if enabled, false if not
|
||||
*/
|
||||
public function is_active()
|
||||
{
|
||||
$prefs = $this->cal->rc->config->get('kolab_calendars', array()); // read local prefs
|
||||
return (bool)$prefs[$this->id]['active'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update properties of this calendar folder
|
||||
*
|
||||
* @see calendar_driver::edit_calendar()
|
||||
*/
|
||||
public function update(&$prop)
|
||||
{
|
||||
// don't change anything.
|
||||
// let kolab_driver save props in local prefs
|
||||
return $prop['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for a single event object
|
||||
*/
|
||||
public function get_event($id)
|
||||
{
|
||||
// redirect call to kolab_driver::get_event()
|
||||
$event = $this->cal->driver->get_event($id, calendar_driver::FILTER_WRITEABLE);
|
||||
|
||||
if (is_array($event)) {
|
||||
$event = $this->_mod_event($event, $event['calendar']);
|
||||
}
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create instances of a recurring event
|
||||
*
|
||||
* @see kolab_calendar::get_recurring_events()
|
||||
*/
|
||||
public function get_recurring_events($event, $start, $end = null, $event_id = null, $limit = null)
|
||||
{
|
||||
// forward call to the actual storage folder
|
||||
if ($event['_folder_id']) {
|
||||
$cal = $this->cal->driver->get_calendar($event['_folder_id']);
|
||||
if ($cal && $cal->ready) {
|
||||
return $cal->get_recurring_events($event, $start, $end, $event_id, $limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attachment body
|
||||
*
|
||||
* @see calendar_driver::get_attachment_body()
|
||||
*/
|
||||
public function get_attachment_body($id, $event)
|
||||
{
|
||||
// find the actual folder this event resides in
|
||||
if (!empty($event['_folder_id'])) {
|
||||
$cal = $this->cal->driver->get_calendar($event['_folder_id']);
|
||||
}
|
||||
else {
|
||||
$cal = null;
|
||||
foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) {
|
||||
$cal = $this->_get_calendar($foldername);
|
||||
if ($cal->ready && $cal->storage && $cal->get_event($event['id'])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($cal && $cal->storage) {
|
||||
return $cal->get_attachment_body($id, $event);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer Event's new start (unix timestamp)
|
||||
* @param integer Event's new end (unix timestamp)
|
||||
* @param string Search query (optional)
|
||||
* @param boolean Include virtual events (optional)
|
||||
* @param array Additional parameters to query storage
|
||||
*
|
||||
* @return array A list of event records
|
||||
*/
|
||||
public function list_events($start, $end, $search = null, $virtual = 1, $query = array())
|
||||
{
|
||||
// get email addresses of the current user
|
||||
$user_emails = $this->cal->get_user_emails();
|
||||
$subquery = array();
|
||||
foreach ($user_emails as $email) {
|
||||
foreach ($this->partstats as $partstat) {
|
||||
$subquery[] = array('tags', '=', 'x-partstat:' . $email . ':' . strtolower($partstat));
|
||||
}
|
||||
}
|
||||
|
||||
// aggregate events from all calendar folders
|
||||
$events = array();
|
||||
foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) {
|
||||
$cal = $this->_get_calendar($foldername);
|
||||
if (!$cal || $cal->get_namespace() == 'other')
|
||||
continue;
|
||||
|
||||
foreach ($cal->list_events($start, $end, $search, 1, $query, array(array($subquery, 'OR'))) as $event) {
|
||||
$match = false;
|
||||
|
||||
// post-filter events to match out partstats
|
||||
if (is_array($event['attendees'])) {
|
||||
foreach ($event['attendees'] as $attendee) {
|
||||
if (in_array($attendee['email'], $user_emails) && in_array($attendee['status'], $this->partstats)) {
|
||||
$match = true;
|
||||
break;
|
||||
if (!empty($_REQUEST['_quickview'])) {
|
||||
$this->partstats[] = 'TENTATIVE';
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case kolab_driver::INVITATIONS_CALENDAR_DECLINED:
|
||||
$this->partstats = ['DECLINED'];
|
||||
$this->name = $this->cal->gettext('invitationsdeclined');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($match) {
|
||||
$events[$event['id'] ?: $event['uid']] = $this->_mod_event($event, $cal->id);
|
||||
// user-specific alarms settings win
|
||||
$prefs = $this->cal->rc->config->get('kolab_calendars', []);
|
||||
if (isset($prefs[$this->id]['showalarms'])) {
|
||||
$this->alarms = $prefs[$this->id]['showalarms'];
|
||||
}
|
||||
}
|
||||
|
||||
// merge list of event categories (really?)
|
||||
$this->categories += $cal->categories;
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of events in the given calendar
|
||||
*
|
||||
* @param integer Date range start (unix timestamp)
|
||||
* @param integer Date range end (unix timestamp)
|
||||
* @param array Additional query to filter events
|
||||
*
|
||||
* @return integer Count
|
||||
*/
|
||||
public function count_events($start, $end = null, $filter = null)
|
||||
{
|
||||
// get email addresses of the current user
|
||||
$user_emails = $this->cal->get_user_emails();
|
||||
$subquery = array();
|
||||
foreach ($user_emails as $email) {
|
||||
foreach ($this->partstats as $partstat) {
|
||||
$subquery[] = array('tags', '=', 'x-partstat:' . $email . ':' . strtolower($partstat));
|
||||
}
|
||||
/**
|
||||
* Getter for a nice and human readable name for this calendar
|
||||
*
|
||||
* @return string Name of this calendar
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
$filter = array(
|
||||
array('tags','!=','x-status:cancelled'),
|
||||
array($subquery, 'OR')
|
||||
);
|
||||
|
||||
// aggregate counts from all calendar folders
|
||||
$count = 0;
|
||||
foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) {
|
||||
$cal = $this->_get_calendar($foldername);
|
||||
if (!$cal || $cal->get_namespace() == 'other')
|
||||
continue;
|
||||
|
||||
$count += $cal->count_events($start, $end, $filter);
|
||||
/**
|
||||
* Getter for the IMAP folder owner
|
||||
*
|
||||
* @return string Name of the folder owner
|
||||
*/
|
||||
public function get_owner()
|
||||
{
|
||||
return $this->cal->rc->get_user_name();
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get calendar object instance (that maybe already initialized)
|
||||
*/
|
||||
private function _get_calendar($folder_name)
|
||||
{
|
||||
$id = kolab_storage::folder_id($folder_name, true);
|
||||
return $this->cal->driver->get_calendar($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to modify some event properties
|
||||
*/
|
||||
private function _mod_event($event, $calendar_id = null)
|
||||
{
|
||||
// set classes according to PARTSTAT
|
||||
$event = kolab_driver::add_partstat_class($event, $this->partstats);
|
||||
|
||||
if (strpos($event['className'], 'fc-invitation-') !== false) {
|
||||
$event['calendar'] = $this->id;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function get_title()
|
||||
{
|
||||
return $this->get_name();
|
||||
}
|
||||
|
||||
// add pointer to original calendar folder
|
||||
if ($calendar_id) {
|
||||
$event['_folder_id'] = $calendar_id;
|
||||
/**
|
||||
* Getter for the name of the namespace to which the IMAP folder belongs
|
||||
*
|
||||
* @return string Name of the namespace (personal, other, shared)
|
||||
*/
|
||||
public function get_namespace()
|
||||
{
|
||||
return 'x-special';
|
||||
}
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new event record
|
||||
*
|
||||
* @see kolab_calendar::insert_event()
|
||||
*/
|
||||
public function insert_event($event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific event record
|
||||
*
|
||||
* @see kolab_calendar::update_event()
|
||||
*/
|
||||
public function update_event($event, $exception_id = null)
|
||||
{
|
||||
// forward call to the actual storage folder
|
||||
if ($event['_folder_id']) {
|
||||
$cal = $this->cal->driver->get_calendar($event['_folder_id']);
|
||||
if ($cal && $cal->ready) {
|
||||
return $cal->update_event($event, $exception_id);
|
||||
}
|
||||
/**
|
||||
* Getter for the top-end calendar folder name (not the entire path)
|
||||
*
|
||||
* @return string Name of this calendar
|
||||
*/
|
||||
public function get_foldername()
|
||||
{
|
||||
return $this->get_name();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an event record
|
||||
*
|
||||
* @see kolab_calendar::delete_event()
|
||||
*/
|
||||
public function delete_event($event, $force = true)
|
||||
{
|
||||
// forward call to the actual storage folder
|
||||
if ($event['_folder_id']) {
|
||||
$cal = $this->cal->driver->get_calendar($event['_folder_id']);
|
||||
if ($cal && $cal->ready) {
|
||||
return $cal->delete_event($event, $force);
|
||||
}
|
||||
/**
|
||||
* Getter for the Cyrus mailbox identifier corresponding to this folder
|
||||
*
|
||||
* @return string Mailbox ID
|
||||
*/
|
||||
public function get_mailbox_id()
|
||||
{
|
||||
// this is a virtual collection and has no concrete mailbox ID
|
||||
return null;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Return color to display this calendar
|
||||
*/
|
||||
public function get_color()
|
||||
{
|
||||
// calendar color is stored in local user prefs
|
||||
$prefs = $this->cal->rc->config->get('kolab_calendars', []);
|
||||
|
||||
/**
|
||||
* Restore deleted event record
|
||||
*
|
||||
* @see kolab_calendar::restore_event()
|
||||
*/
|
||||
public function restore_event($event)
|
||||
{
|
||||
// forward call to the actual storage folder
|
||||
if ($event['_folder_id']) {
|
||||
$cal = $this->cal->driver->get_calendar($event['_folder_id']);
|
||||
if ($cal && $cal->ready) {
|
||||
return $cal->restore_event($event);
|
||||
}
|
||||
if (!empty($prefs[$this->id]) && !empty($prefs[$this->id]['color'])) {
|
||||
return $prefs[$this->id]['color'];
|
||||
}
|
||||
|
||||
return 'ffffff';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Compose an URL for CalDAV access to this calendar (if configured)
|
||||
*/
|
||||
public function get_caldav_url()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check activation status of this folder
|
||||
*
|
||||
* @return bool True if enabled, false if not
|
||||
*/
|
||||
public function is_active()
|
||||
{
|
||||
$prefs = $this->cal->rc->config->get('kolab_calendars', []); // read local prefs
|
||||
return !empty($prefs[$this->id]['active']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update properties of this calendar folder
|
||||
*
|
||||
* @see calendar_driver::edit_calendar()
|
||||
*/
|
||||
public function update(&$prop)
|
||||
{
|
||||
// don't change anything.
|
||||
// let kolab_driver save props in local prefs
|
||||
return $prop['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for a single event object
|
||||
*/
|
||||
public function get_event($id)
|
||||
{
|
||||
// redirect call to kolab_driver::get_event()
|
||||
$event = $this->cal->driver->get_event($id, calendar_driver::FILTER_WRITEABLE);
|
||||
|
||||
if (is_array($event)) {
|
||||
$event = $this->_mod_event($event, $event['calendar']);
|
||||
}
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create instances of a recurring event
|
||||
*
|
||||
* @see kolab_calendar::get_recurring_events()
|
||||
*/
|
||||
public function get_recurring_events($event, $start, $end = null, $event_id = null, $limit = null)
|
||||
{
|
||||
// forward call to the actual storage folder
|
||||
if (!empty($event['_folder_id'])) {
|
||||
$cal = $this->cal->driver->get_calendar($event['_folder_id']);
|
||||
if ($cal && $cal->ready) {
|
||||
return $cal->get_recurring_events($event, $start, $end, $event_id, $limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attachment body
|
||||
*
|
||||
* @see calendar_driver::get_attachment_body()
|
||||
*/
|
||||
public function get_attachment_body($id, $event)
|
||||
{
|
||||
// find the actual folder this event resides in
|
||||
if (!empty($event['_folder_id'])) {
|
||||
$cal = $this->cal->driver->get_calendar($event['_folder_id']);
|
||||
}
|
||||
else {
|
||||
$cal = null;
|
||||
foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) {
|
||||
$cal = $this->_get_calendar($foldername);
|
||||
if ($cal->ready && $cal->storage && $cal->get_event($event['id'])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($cal && $cal->storage) {
|
||||
return $cal->get_attachment_body($id, $event);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int Event's new start (unix timestamp)
|
||||
* @param int Event's new end (unix timestamp)
|
||||
* @param string Search query (optional)
|
||||
* @param bool Include virtual events (optional)
|
||||
* @param array Additional parameters to query storage
|
||||
*
|
||||
* @return array A list of event records
|
||||
*/
|
||||
public function list_events($start, $end, $search = null, $virtual = 1, $query = [])
|
||||
{
|
||||
// get email addresses of the current user
|
||||
$user_emails = $this->cal->get_user_emails();
|
||||
$subquery = [];
|
||||
|
||||
foreach ($user_emails as $email) {
|
||||
foreach ($this->partstats as $partstat) {
|
||||
$subquery[] = ['tags', '=', 'x-partstat:' . $email . ':' . strtolower($partstat)];
|
||||
}
|
||||
}
|
||||
|
||||
$events = [];
|
||||
|
||||
// aggregate events from all calendar folders
|
||||
foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) {
|
||||
$cal = $this->_get_calendar($foldername);
|
||||
if (!$cal || $cal->get_namespace() == 'other') {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($cal->list_events($start, $end, $search, 1, $query, [[$subquery, 'OR']]) as $event) {
|
||||
$match = false;
|
||||
|
||||
// post-filter events to match out partstats
|
||||
if (!empty($event['attendees'])) {
|
||||
foreach ($event['attendees'] as $attendee) {
|
||||
if (
|
||||
in_array($attendee['email'], $user_emails)
|
||||
&& in_array($attendee['status'], $this->partstats)
|
||||
) {
|
||||
$match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($match) {
|
||||
$uid = !empty($event['id']) ? $event['id'] : $event['uid'];
|
||||
$events[$uid] = $this->_mod_event($event, $cal->id);
|
||||
}
|
||||
}
|
||||
|
||||
// merge list of event categories (really?)
|
||||
$this->categories += $cal->categories;
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of events in the given calendar
|
||||
*
|
||||
* @param int Date range start (unix timestamp)
|
||||
* @param int Date range end (unix timestamp)
|
||||
* @param array Additional query to filter events
|
||||
*
|
||||
* @return int Count
|
||||
*/
|
||||
public function count_events($start, $end = null, $filter = null)
|
||||
{
|
||||
// get email addresses of the current user
|
||||
$user_emails = $this->cal->get_user_emails();
|
||||
$subquery = [];
|
||||
|
||||
foreach ($user_emails as $email) {
|
||||
foreach ($this->partstats as $partstat) {
|
||||
$subquery[] = ['tags', '=', 'x-partstat:' . $email . ':' . strtolower($partstat)];
|
||||
}
|
||||
}
|
||||
|
||||
$filter = [
|
||||
['tags', '!=', 'x-status:cancelled'],
|
||||
[$subquery, 'OR']
|
||||
];
|
||||
|
||||
// aggregate counts from all calendar folders
|
||||
$count = 0;
|
||||
foreach (kolab_storage::list_folders('', '*', 'event', null) as $foldername) {
|
||||
$cal = $this->_get_calendar($foldername);
|
||||
if (!$cal || $cal->get_namespace() == 'other') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$count += $cal->count_events($start, $end, $filter);
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get calendar object instance (that maybe already initialized)
|
||||
*/
|
||||
private function _get_calendar($folder_name)
|
||||
{
|
||||
$id = kolab_storage::folder_id($folder_name, true);
|
||||
return $this->cal->driver->get_calendar($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to modify some event properties
|
||||
*/
|
||||
private function _mod_event($event, $calendar_id = null)
|
||||
{
|
||||
// set classes according to PARTSTAT
|
||||
$event = kolab_driver::add_partstat_class($event, $this->partstats);
|
||||
|
||||
if (strpos($event['className'], 'fc-invitation-') !== false) {
|
||||
$event['calendar'] = $this->id;
|
||||
}
|
||||
|
||||
// add pointer to original calendar folder
|
||||
if ($calendar_id) {
|
||||
$event['_folder_id'] = $calendar_id;
|
||||
}
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new event record
|
||||
*
|
||||
* @see kolab_calendar::insert_event()
|
||||
*/
|
||||
public function insert_event($event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific event record
|
||||
*
|
||||
* @see kolab_calendar::update_event()
|
||||
*/
|
||||
public function update_event($event, $exception_id = null)
|
||||
{
|
||||
// forward call to the actual storage folder
|
||||
if (!empty($event['_folder_id'])) {
|
||||
$cal = $this->cal->driver->get_calendar($event['_folder_id']);
|
||||
if ($cal && $cal->ready) {
|
||||
return $cal->update_event($event, $exception_id);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an event record
|
||||
*
|
||||
* @see kolab_calendar::delete_event()
|
||||
*/
|
||||
public function delete_event($event, $force = true)
|
||||
{
|
||||
// forward call to the actual storage folder
|
||||
if (!empty($event['_folder_id'])) {
|
||||
$cal = $this->cal->driver->get_calendar($event['_folder_id']);
|
||||
if ($cal && $cal->ready) {
|
||||
return $cal->delete_event($event, $force);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore deleted event record
|
||||
*
|
||||
* @see kolab_calendar::restore_event()
|
||||
*/
|
||||
public function restore_event($event)
|
||||
{
|
||||
// forward call to the actual storage folder
|
||||
if (!empty($event['_folder_id'])) {
|
||||
$cal = $this->cal->driver->get_calendar($event['_folder_id']);
|
||||
if ($cal && $cal->ready) {
|
||||
return $cal->restore_event($event);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,402 +23,423 @@
|
|||
|
||||
class kolab_user_calendar extends kolab_calendar
|
||||
{
|
||||
public $id = 'unknown';
|
||||
public $ready = false;
|
||||
public $editable = false;
|
||||
public $attachments = false;
|
||||
public $subscriptions = false;
|
||||
public $id = 'unknown';
|
||||
public $ready = false;
|
||||
public $editable = false;
|
||||
public $attachments = false;
|
||||
public $subscriptions = false;
|
||||
|
||||
protected $userdata = array();
|
||||
protected $timeindex = array();
|
||||
protected $userdata = [];
|
||||
protected $timeindex = [];
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public function __construct($user_or_folder, $calendar)
|
||||
{
|
||||
$this->cal = $calendar;
|
||||
$this->imap = $calendar->rc->get_storage();
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public function __construct($user_or_folder, $calendar)
|
||||
{
|
||||
$this->cal = $calendar;
|
||||
$this->imap = $calendar->rc->get_storage();
|
||||
|
||||
// full user record is provided
|
||||
if (is_array($user_or_folder)) {
|
||||
$this->userdata = $user_or_folder;
|
||||
$this->storage = new kolab_storage_folder_user($this->userdata['kolabtargetfolder'], '', $this->userdata);
|
||||
}
|
||||
else if ($user_or_folder instanceof kolab_storage_folder_user) {
|
||||
$this->storage = $user_or_folder;
|
||||
$this->userdata = $this->storage->ldaprec;
|
||||
}
|
||||
else { // get user record from LDAP
|
||||
$this->storage = new kolab_storage_folder_user($user_or_folder);
|
||||
$this->userdata = $this->storage->ldaprec;
|
||||
}
|
||||
|
||||
$this->ready = !empty($this->userdata['kolabtargetfolder']);
|
||||
$this->storage->type = 'event';
|
||||
|
||||
if ($this->ready) {
|
||||
// ID is derrived from the user's kolabtargetfolder attribute
|
||||
$this->id = kolab_storage::folder_id($this->userdata['kolabtargetfolder'], true);
|
||||
$this->imap_folder = $this->userdata['kolabtargetfolder'];
|
||||
$this->name = $this->storage->name;
|
||||
$this->parent = ''; // user calendars are top level
|
||||
|
||||
// user-specific alarms settings win
|
||||
$prefs = $this->cal->rc->config->get('kolab_calendars', array());
|
||||
if (isset($prefs[$this->id]['showalarms']))
|
||||
$this->alarms = $prefs[$this->id]['showalarms'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for a nice and human readable name for this calendar
|
||||
*
|
||||
* @return string Name of this calendar
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
return $this->userdata['displayname'] ?: ($this->userdata['name'] ?: $this->userdata['mail']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the IMAP folder owner
|
||||
*
|
||||
* @param bool Return a fully qualified owner name (unused)
|
||||
*
|
||||
* @return string Name of the folder owner
|
||||
*/
|
||||
public function get_owner($fully_qualified = false)
|
||||
{
|
||||
return $this->userdata['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function get_title()
|
||||
{
|
||||
return trim($this->userdata['displayname'] . '; ' . $this->userdata['mail'], '; ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the name of the namespace to which the IMAP folder belongs
|
||||
*
|
||||
* @return string Name of the namespace (personal, other, shared)
|
||||
*/
|
||||
public function get_namespace()
|
||||
{
|
||||
return 'other user';
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the top-end calendar folder name (not the entire path)
|
||||
*
|
||||
* @return string Name of this calendar
|
||||
*/
|
||||
public function get_foldername()
|
||||
{
|
||||
return $this->get_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return color to display this calendar
|
||||
*/
|
||||
public function get_color($default = null)
|
||||
{
|
||||
// calendar color is stored in local user prefs
|
||||
$prefs = $this->cal->rc->config->get('kolab_calendars', array());
|
||||
|
||||
if (!empty($prefs[$this->id]) && !empty($prefs[$this->id]['color']))
|
||||
return $prefs[$this->id]['color'];
|
||||
|
||||
return $default ?: 'cc0000';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose an URL for CalDAV access to this calendar (if configured)
|
||||
*/
|
||||
public function get_caldav_url()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check subscription status of this folder
|
||||
*
|
||||
* @return boolean True if subscribed, false if not
|
||||
*/
|
||||
public function is_subscribed()
|
||||
{
|
||||
return $this->storage->is_subscribed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update properties of this calendar folder
|
||||
*
|
||||
* @see calendar_driver::edit_calendar()
|
||||
*/
|
||||
public function update(&$prop)
|
||||
{
|
||||
// don't change anything.
|
||||
// let kolab_driver save props in local prefs
|
||||
return $prop['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for a single event object
|
||||
*/
|
||||
public function get_event($id)
|
||||
{
|
||||
// TODO: implement this
|
||||
return $this->events[$id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attachment body
|
||||
* @see calendar_driver::get_attachment_body()
|
||||
*/
|
||||
public function get_attachment_body($id, $event)
|
||||
{
|
||||
if (!$event['calendar'] && ($ev = $this->get_event($event['id']))) {
|
||||
$event['calendar'] = $ev['calendar'];
|
||||
}
|
||||
|
||||
if ($event['calendar'] && ($cal = $this->cal->get_calendar($event['calendar']))) {
|
||||
return $cal->get_attachment_body($id, $event);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer Event's new start (unix timestamp)
|
||||
* @param integer Event's new end (unix timestamp)
|
||||
* @param string Search query (optional)
|
||||
* @param boolean Include virtual events (optional)
|
||||
* @param array Additional parameters to query storage
|
||||
* @param array Additional query to filter events
|
||||
*
|
||||
* @return array A list of event records
|
||||
*/
|
||||
public function list_events($start, $end, $search = null, $virtual = 1, $query = array(), $filter_query = null)
|
||||
{
|
||||
// convert to DateTime for comparisons
|
||||
try {
|
||||
$start_dt = new DateTime('@'.$start);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$start_dt = new DateTime('@0');
|
||||
}
|
||||
try {
|
||||
$end_dt = new DateTime('@'.$end);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$end_dt = new DateTime('today +10 years');
|
||||
}
|
||||
|
||||
$limit_changed = null;
|
||||
if (!empty($query)) {
|
||||
foreach ($query as $q) {
|
||||
if ($q[0] == 'changed' && $q[1] == '>=') {
|
||||
try { $limit_changed = new DateTime('@'.$q[2]); }
|
||||
catch (Exception $e) { /* ignore */ }
|
||||
// full user record is provided
|
||||
if (is_array($user_or_folder)) {
|
||||
$this->userdata = $user_or_folder;
|
||||
$this->storage = new kolab_storage_folder_user($this->userdata['kolabtargetfolder'], '', $this->userdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// aggregate all calendar folders the user shares (but are not activated)
|
||||
foreach (kolab_storage::list_user_folders($this->userdata, 'event', 2) as $foldername) {
|
||||
$cal = new kolab_calendar($foldername, $this->cal);
|
||||
foreach ($cal->list_events($start, $end, $search, 1) as $event) {
|
||||
$uid = $event['id'] ?: $event['uid'];
|
||||
$this->events[$uid] = $event;
|
||||
$this->timeindex[$this->time_key($event)] = $uid;
|
||||
}
|
||||
}
|
||||
|
||||
// get events from the user's free/busy feed (for quickview only)
|
||||
$fbview = $this->cal->rc->config->get('calendar_include_freebusy_data', 1);
|
||||
if ($fbview && ($fbview == 1 || !empty($_REQUEST['_quickview'])) && empty($search)) {
|
||||
$this->fetch_freebusy($limit_changed);
|
||||
}
|
||||
|
||||
$events = array();
|
||||
foreach ($this->events as $event) {
|
||||
// list events in requested time window
|
||||
if ($event['start'] <= $end_dt && $event['end'] >= $start_dt &&
|
||||
(!$limit_changed || !$event['changed'] || $event['changed'] >= $limit_changed)) {
|
||||
$events[] = $event;
|
||||
}
|
||||
}
|
||||
|
||||
// avoid session race conditions that will loose temporary subscriptions
|
||||
$this->cal->rc->session->nowrite = true;
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of events in the given calendar
|
||||
*
|
||||
* @param integer Date range start (unix timestamp)
|
||||
* @param integer Date range end (unix timestamp)
|
||||
* @param array Additional query to filter events
|
||||
*
|
||||
* @return integer Count
|
||||
*/
|
||||
public function count_events($start, $end = null, $filter_query = null)
|
||||
{
|
||||
// not implemented
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to fetch free/busy data for the user and turn it into calendar data
|
||||
*/
|
||||
private function fetch_freebusy($limit_changed = null)
|
||||
{
|
||||
// ask kolab server first
|
||||
try {
|
||||
$request_config = array(
|
||||
'store_body' => true,
|
||||
'follow_redirects' => true,
|
||||
);
|
||||
$request = libkolab::http_request(kolab_storage::get_freebusy_url($this->userdata['mail']), 'GET', $request_config);
|
||||
$response = $request->send();
|
||||
|
||||
// authentication required
|
||||
if ($response->getStatus() == 401) {
|
||||
$request->setAuth($this->cal->rc->user->get_username(), $this->cal->rc->decrypt($_SESSION['password']));
|
||||
$response = $request->send();
|
||||
}
|
||||
|
||||
if ($response->getStatus() == 200)
|
||||
$fbdata = $response->getBody();
|
||||
|
||||
unset($request, $response);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
rcube::raise_error(array(
|
||||
'code' => 900,
|
||||
'type' => 'php',
|
||||
'file' => __FILE__,
|
||||
'line' => __LINE__,
|
||||
'message' => "Error fetching free/busy information: " . $e->getMessage()),
|
||||
true, false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$statusmap = array(
|
||||
'FREE' => 'free',
|
||||
'BUSY' => 'busy',
|
||||
'BUSY-TENTATIVE' => 'tentative',
|
||||
'X-OUT-OF-OFFICE' => 'outofoffice',
|
||||
'OOF' => 'outofoffice',
|
||||
);
|
||||
$titlemap = array(
|
||||
'FREE' => $this->cal->gettext('availfree'),
|
||||
'BUSY' => $this->cal->gettext('availbusy'),
|
||||
'BUSY-TENTATIVE' => $this->cal->gettext('availtentative'),
|
||||
'X-OUT-OF-OFFICE' => $this->cal->gettext('availoutofoffice'),
|
||||
);
|
||||
|
||||
// rcube::console('_fetch_freebusy', kolab_storage::get_freebusy_url($this->userdata['mail']), $fbdata);
|
||||
|
||||
// parse free-busy information
|
||||
$count = 0;
|
||||
if ($fbdata) {
|
||||
$ical = $this->cal->get_ical();
|
||||
$ical->import($fbdata);
|
||||
if ($fb = $ical->freebusy) {
|
||||
// consider 'changed >= X' queries
|
||||
if ($limit_changed && $fb['created'] && $fb['created'] < $limit_changed) {
|
||||
return 0;
|
||||
else if ($user_or_folder instanceof kolab_storage_folder_user) {
|
||||
$this->storage = $user_or_folder;
|
||||
$this->userdata = $this->storage->ldaprec;
|
||||
}
|
||||
else {
|
||||
// get user record from LDAP
|
||||
$this->storage = new kolab_storage_folder_user($user_or_folder);
|
||||
$this->userdata = $this->storage->ldaprec;
|
||||
}
|
||||
|
||||
foreach ($fb['periods'] as $tuple) {
|
||||
list($from, $to, $type) = $tuple;
|
||||
$event = array(
|
||||
'uid' => md5($this->id . $from->format('U') . '/' . $to->format('U')),
|
||||
'calendar' => $this->id,
|
||||
'changed' => $fb['created'] ?: new DateTime(),
|
||||
'title' => $this->get_name() . ' ' . ($titlemap[$type] ?: $type),
|
||||
'start' => $from,
|
||||
'end' => $to,
|
||||
'free_busy' => $statusmap[$type] ?: 'busy',
|
||||
'className' => 'fc-type-freebusy',
|
||||
'organizer' => array(
|
||||
'email' => $this->userdata['mail'],
|
||||
'name' => $this->userdata['displayname'],
|
||||
),
|
||||
);
|
||||
$this->ready = !empty($this->userdata['kolabtargetfolder']);
|
||||
$this->storage->type = 'event';
|
||||
|
||||
// avoid duplicate entries
|
||||
$key = $this->time_key($event);
|
||||
if (!$this->timeindex[$key]) {
|
||||
$this->events[$event['uid']] = $event;
|
||||
$this->timeindex[$key] = $event['uid'];
|
||||
$count++;
|
||||
}
|
||||
if ($this->ready) {
|
||||
// ID is derrived from the user's kolabtargetfolder attribute
|
||||
$this->id = kolab_storage::folder_id($this->userdata['kolabtargetfolder'], true);
|
||||
$this->imap_folder = $this->userdata['kolabtargetfolder'];
|
||||
$this->name = $this->storage->name;
|
||||
$this->parent = ''; // user calendars are top level
|
||||
|
||||
// user-specific alarms settings win
|
||||
$prefs = $this->cal->rc->config->get('kolab_calendars', []);
|
||||
if (isset($prefs[$this->id]['showalarms'])) {
|
||||
$this->alarms = $prefs[$this->id]['showalarms'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
/**
|
||||
* Getter for a nice and human readable name for this calendar
|
||||
*
|
||||
* @return string Name of this calendar
|
||||
*/
|
||||
public function get_name()
|
||||
{
|
||||
if (!empty($this->userdata['displayname'])) {
|
||||
return $this->userdata['displayname'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to build a key for the absolute time slot the given event convers
|
||||
*/
|
||||
private function time_key($event)
|
||||
{
|
||||
return sprintf('%s/%s', $event['start']->format('U'), is_object($event['end']) ? $event['end']->format('U') : '0');
|
||||
}
|
||||
return !empty($this->userdata['name']) ? $this->userdata['name'] : $this->userdata['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new event record
|
||||
*
|
||||
* @see calendar_driver::new_event()
|
||||
*
|
||||
* @return mixed The created record ID on success, False on error
|
||||
*/
|
||||
public function insert_event($event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Getter for the IMAP folder owner
|
||||
*
|
||||
* @param bool Return a fully qualified owner name (unused)
|
||||
*
|
||||
* @return string Name of the folder owner
|
||||
*/
|
||||
public function get_owner($fully_qualified = false)
|
||||
{
|
||||
return $this->userdata['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific event record
|
||||
*
|
||||
* @see calendar_driver::new_event()
|
||||
* @return boolean True on success, False on error
|
||||
*/
|
||||
public function update_event($event, $exception_id = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function get_title()
|
||||
{
|
||||
$title = [];
|
||||
|
||||
/**
|
||||
* Delete an event record
|
||||
*
|
||||
* @see calendar_driver::remove_event()
|
||||
* @return boolean True on success, False on error
|
||||
*/
|
||||
public function delete_event($event, $force = true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!empty($this->userdata['displayname'])) {
|
||||
$title[] = $this->userdata['displayname'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore deleted event record
|
||||
*
|
||||
* @see calendar_driver::undelete_event()
|
||||
* @return boolean True on success, False on error
|
||||
*/
|
||||
public function restore_event($event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$title[] = $this->userdata['mail'];
|
||||
|
||||
return implode('; ', $title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the name of the namespace to which the IMAP folder belongs
|
||||
*
|
||||
* @return string Name of the namespace (personal, other, shared)
|
||||
*/
|
||||
public function get_namespace()
|
||||
{
|
||||
return 'other user';
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the top-end calendar folder name (not the entire path)
|
||||
*
|
||||
* @return string Name of this calendar
|
||||
*/
|
||||
public function get_foldername()
|
||||
{
|
||||
return $this->get_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return color to display this calendar
|
||||
*/
|
||||
public function get_color($default = null)
|
||||
{
|
||||
// calendar color is stored in local user prefs
|
||||
$prefs = $this->cal->rc->config->get('kolab_calendars', []);
|
||||
|
||||
if (!empty($prefs[$this->id]) && !empty($prefs[$this->id]['color'])) {
|
||||
return $prefs[$this->id]['color'];
|
||||
}
|
||||
|
||||
return $default ?: 'cc0000';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose an URL for CalDAV access to this calendar (if configured)
|
||||
*/
|
||||
public function get_caldav_url()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check subscription status of this folder
|
||||
*
|
||||
* @return boolean True if subscribed, false if not
|
||||
*/
|
||||
public function is_subscribed()
|
||||
{
|
||||
return $this->storage->is_subscribed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update properties of this calendar folder
|
||||
*
|
||||
* @see calendar_driver::edit_calendar()
|
||||
*/
|
||||
public function update(&$prop)
|
||||
{
|
||||
// don't change anything.
|
||||
// let kolab_driver save props in local prefs
|
||||
return $prop['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for a single event object
|
||||
*/
|
||||
public function get_event($id)
|
||||
{
|
||||
// TODO: implement this
|
||||
return isset($this->events[$id]) ? $this->events[$id] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attachment body
|
||||
* @see calendar_driver::get_attachment_body()
|
||||
*/
|
||||
public function get_attachment_body($id, $event)
|
||||
{
|
||||
if (empty($event['calendar']) && ($ev = $this->get_event($event['id']))) {
|
||||
$event['calendar'] = $ev['calendar'];
|
||||
}
|
||||
|
||||
if (!empty($event['calendar']) && ($cal = $this->cal->get_calendar($event['calendar']))) {
|
||||
return $cal->get_attachment_body($id, $event);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int Event's new start (unix timestamp)
|
||||
* @param int Event's new end (unix timestamp)
|
||||
* @param string Search query (optional)
|
||||
* @param bool Include virtual events (optional)
|
||||
* @param array Additional parameters to query storage
|
||||
* @param array Additional query to filter events
|
||||
*
|
||||
* @return array A list of event records
|
||||
*/
|
||||
public function list_events($start, $end, $search = null, $virtual = 1, $query = [], $filter_query = null)
|
||||
{
|
||||
// convert to DateTime for comparisons
|
||||
try {
|
||||
$start_dt = new DateTime('@'.$start);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$start_dt = new DateTime('@0');
|
||||
}
|
||||
try {
|
||||
$end_dt = new DateTime('@'.$end);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$end_dt = new DateTime('today +10 years');
|
||||
}
|
||||
|
||||
$limit_changed = null;
|
||||
|
||||
if (!empty($query)) {
|
||||
foreach ($query as $q) {
|
||||
if ($q[0] == 'changed' && $q[1] == '>=') {
|
||||
try { $limit_changed = new DateTime('@'.$q[2]); }
|
||||
catch (Exception $e) { /* ignore */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// aggregate all calendar folders the user shares (but are not activated)
|
||||
foreach (kolab_storage::list_user_folders($this->userdata, 'event', 2) as $foldername) {
|
||||
$cal = new kolab_calendar($foldername, $this->cal);
|
||||
foreach ($cal->list_events($start, $end, $search, 1) as $event) {
|
||||
$uid = !empty($event['id']) ? $event['id'] : $event['uid'];
|
||||
$this->events[$uid] = $event;
|
||||
$this->timeindex[$this->time_key($event)] = $uid;
|
||||
}
|
||||
}
|
||||
|
||||
// get events from the user's free/busy feed (for quickview only)
|
||||
$fbview = $this->cal->rc->config->get('calendar_include_freebusy_data', 1);
|
||||
if ($fbview && ($fbview == 1 || !empty($_REQUEST['_quickview'])) && empty($search)) {
|
||||
$this->fetch_freebusy($limit_changed);
|
||||
}
|
||||
|
||||
$events = [];
|
||||
foreach ($this->events as $event) {
|
||||
// list events in requested time window
|
||||
if (
|
||||
$event['start'] <= $end_dt
|
||||
&& $event['end'] >= $start_dt
|
||||
&& (!$limit_changed || empty($event['changed']) || $event['changed'] >= $limit_changed)
|
||||
) {
|
||||
$events[] = $event;
|
||||
}
|
||||
}
|
||||
|
||||
// avoid session race conditions that will loose temporary subscriptions
|
||||
$this->cal->rc->session->nowrite = true;
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of events in the given calendar
|
||||
*
|
||||
* @param int Date range start (unix timestamp)
|
||||
* @param int Date range end (unix timestamp)
|
||||
* @param array Additional query to filter events
|
||||
*
|
||||
* @return integer Count
|
||||
*/
|
||||
public function count_events($start, $end = null, $filter_query = null)
|
||||
{
|
||||
// not implemented
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to fetch free/busy data for the user and turn it into calendar data
|
||||
*/
|
||||
private function fetch_freebusy($limit_changed = null)
|
||||
{
|
||||
// ask kolab server first
|
||||
try {
|
||||
$request_config = [
|
||||
'store_body' => true,
|
||||
'follow_redirects' => true,
|
||||
];
|
||||
$request = libkolab::http_request(kolab_storage::get_freebusy_url($this->userdata['mail']), 'GET', $request_config);
|
||||
$response = $request->send();
|
||||
|
||||
// authentication required
|
||||
if ($response->getStatus() == 401) {
|
||||
$request->setAuth($this->cal->rc->user->get_username(), $this->cal->rc->decrypt($_SESSION['password']));
|
||||
$response = $request->send();
|
||||
}
|
||||
|
||||
if ($response->getStatus() == 200) {
|
||||
$fbdata = $response->getBody();
|
||||
}
|
||||
|
||||
unset($request, $response);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
rcube::raise_error([
|
||||
'code' => 900, 'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error fetching free/busy information: " . $e->getMessage()
|
||||
],
|
||||
true, false
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$statusmap = [
|
||||
'FREE' => 'free',
|
||||
'BUSY' => 'busy',
|
||||
'BUSY-TENTATIVE' => 'tentative',
|
||||
'X-OUT-OF-OFFICE' => 'outofoffice',
|
||||
'OOF' => 'outofoffice',
|
||||
];
|
||||
|
||||
$titlemap = [
|
||||
'FREE' => $this->cal->gettext('availfree'),
|
||||
'BUSY' => $this->cal->gettext('availbusy'),
|
||||
'BUSY-TENTATIVE' => $this->cal->gettext('availtentative'),
|
||||
'X-OUT-OF-OFFICE' => $this->cal->gettext('availoutofoffice'),
|
||||
];
|
||||
|
||||
// rcube::console('_fetch_freebusy', kolab_storage::get_freebusy_url($this->userdata['mail']), $fbdata);
|
||||
|
||||
$count = 0;
|
||||
|
||||
// parse free-busy information
|
||||
if (!empty($fbdata)) {
|
||||
$ical = $this->cal->get_ical();
|
||||
$ical->import($fbdata);
|
||||
if ($fb = $ical->freebusy) {
|
||||
// consider 'changed >= X' queries
|
||||
if ($limit_changed && !empty($fb['created']) && $fb['created'] < $limit_changed) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
foreach ($fb['periods'] as $tuple) {
|
||||
list($from, $to, $type) = $tuple;
|
||||
$event = [
|
||||
'uid' => md5($this->id . $from->format('U') . '/' . $to->format('U')),
|
||||
'calendar' => $this->id,
|
||||
'changed' => !empty($fb['created']) ? $fb['created'] : new DateTime(),
|
||||
'title' => $this->get_name() . ' ' . (!empty($titlemap[$type]) ? $titlemap[$type] : $type),
|
||||
'start' => $from,
|
||||
'end' => $to,
|
||||
'free_busy' => !empty($statusmap[$type]) ? $statusmap[$type] : 'busy',
|
||||
'className' => 'fc-type-freebusy',
|
||||
'organizer' => [
|
||||
'email' => $this->userdata['mail'],
|
||||
'name' => isset($this->userdata['displayname']) ? $this->userdata['displayname'] : null,
|
||||
],
|
||||
];
|
||||
|
||||
// avoid duplicate entries
|
||||
$key = $this->time_key($event);
|
||||
if (empty($this->timeindex[$key])) {
|
||||
$this->events[$event['uid']] = $event;
|
||||
$this->timeindex[$key] = $event['uid'];
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to build a key for the absolute time slot the given event convers
|
||||
*/
|
||||
private function time_key($event)
|
||||
{
|
||||
return sprintf('%s/%s', $event['start']->format('U'), is_object($event['end']) ? $event['end']->format('U') : '0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new event record
|
||||
*
|
||||
* @see calendar_driver::new_event()
|
||||
*
|
||||
* @return mixed The created record ID on success, False on error
|
||||
*/
|
||||
public function insert_event($event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific event record
|
||||
*
|
||||
* @see calendar_driver::new_event()
|
||||
* @return bool True on success, False on error
|
||||
*/
|
||||
public function update_event($event, $exception_id = null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an event record
|
||||
*
|
||||
* @see calendar_driver::remove_event()
|
||||
* @return bool True on success, False on error
|
||||
*/
|
||||
public function delete_event($event, $force = true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore deleted event record
|
||||
*
|
||||
* @see calendar_driver::undelete_event()
|
||||
* @return bool True on success, False on error
|
||||
*/
|
||||
public function restore_event($event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,72 +41,76 @@ class resources_driver_ldap extends resources_driver
|
|||
/**
|
||||
* Fetch resource objects to be displayed for booking
|
||||
*
|
||||
* @param string Search query (optional)
|
||||
* @return array List of resource records available for booking
|
||||
* @param string $query Search query (optional)
|
||||
* @param int $num Max size of the result
|
||||
*
|
||||
* @return array List of resource records available for booking
|
||||
*/
|
||||
public function load_resources($query = null, $num = 5000)
|
||||
{
|
||||
if (!($ldap = $this->connect())) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// TODO: apply paging
|
||||
$ldap->set_pagesize($num);
|
||||
|
||||
if (isset($query)) {
|
||||
$results = $ldap->search('*', $query, 0, true, true);
|
||||
}
|
||||
else {
|
||||
$results = $ldap->list_records();
|
||||
}
|
||||
|
||||
if ($results instanceof ArrayAccess) {
|
||||
foreach ($results as $i => $rec) {
|
||||
$results[$i] = $this->decode_resource($rec);
|
||||
if (!($ldap = $this->connect())) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
// TODO: apply paging
|
||||
$ldap->set_pagesize($num);
|
||||
|
||||
if (isset($query)) {
|
||||
$results = $ldap->search('*', $query, 0, true, true);
|
||||
}
|
||||
else {
|
||||
$results = $ldap->list_records();
|
||||
}
|
||||
|
||||
if ($results instanceof ArrayAccess) {
|
||||
foreach ($results as $i => $rec) {
|
||||
$results[$i] = $this->decode_resource($rec);
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return properties of a single resource
|
||||
*
|
||||
* @param string Unique resource identifier
|
||||
* @param string $id Unique resource identifier
|
||||
*
|
||||
* @return array Resource object as hash array
|
||||
*/
|
||||
public function get_resource($dn)
|
||||
{
|
||||
$rec = null;
|
||||
$rec = null;
|
||||
|
||||
if ($ldap = $this->connect()) {
|
||||
$rec = $ldap->get_record(rcube_ldap::dn_encode($dn), true);
|
||||
if ($ldap = $this->connect()) {
|
||||
$rec = $ldap->get_record(rcube_ldap::dn_encode($dn), true);
|
||||
|
||||
if (!empty($rec)) {
|
||||
$rec = $this->decode_resource($rec);
|
||||
if (!empty($rec)) {
|
||||
$rec = $this->decode_resource($rec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $rec;
|
||||
return $rec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return properties of a resource owner
|
||||
*
|
||||
* @param string Owner identifier
|
||||
* @return array Resource object as hash array
|
||||
* @param string $dn Owner identifier
|
||||
*
|
||||
* @return array Resource object as hash array
|
||||
*/
|
||||
public function get_resource_owner($dn)
|
||||
{
|
||||
$owner = null;
|
||||
$owner = null;
|
||||
|
||||
if ($ldap = $this->connect()) {
|
||||
$owner = $ldap->get_record(rcube_ldap::dn_encode($dn), true);
|
||||
$owner['ID'] = rcube_ldap::dn_decode($owner['ID']);
|
||||
unset($owner['_raw_attrib'], $owner['_type']);
|
||||
}
|
||||
if ($ldap = $this->connect()) {
|
||||
$owner = $ldap->get_record(rcube_ldap::dn_encode($dn), true);
|
||||
$owner['ID'] = rcube_ldap::dn_decode($owner['ID']);
|
||||
unset($owner['_raw_attrib'], $owner['_type']);
|
||||
}
|
||||
|
||||
return $owner;
|
||||
return $owner;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,41 +118,40 @@ class resources_driver_ldap extends resources_driver
|
|||
*/
|
||||
private function decode_resource($rec)
|
||||
{
|
||||
$rec['ID'] = rcube_ldap::dn_decode($rec['ID']);
|
||||
$rec['ID'] = rcube_ldap::dn_decode($rec['ID']);
|
||||
|
||||
$attributes = array();
|
||||
$attributes = [];
|
||||
|
||||
foreach ((array) $rec['attributes'] as $sattr) {
|
||||
$sattr = trim($sattr);
|
||||
if ($sattr && $sattr[0] === '{') {
|
||||
$attr = @json_decode($sattr, true);
|
||||
$attributes += $attr;
|
||||
foreach ((array) $rec['attributes'] as $sattr) {
|
||||
$sattr = trim($sattr);
|
||||
if (!empty($sattr) && $sattr[0] === '{') {
|
||||
$attr = @json_decode($sattr, true);
|
||||
$attributes += $attr;
|
||||
}
|
||||
else if (!empty($sattr) && empty($rec['description'])) {
|
||||
$rec['description'] = $sattr;
|
||||
}
|
||||
}
|
||||
else if ($sattr && empty($rec['description'])) {
|
||||
$rec['description'] = $sattr;
|
||||
|
||||
$rec['attributes'] = $attributes;
|
||||
|
||||
// force $rec['members'] to be an array
|
||||
if (!empty($rec['members']) && !is_array($rec['members'])) {
|
||||
$rec['members'] = [$rec['members']];
|
||||
}
|
||||
}
|
||||
|
||||
$rec['attributes'] = $attributes;
|
||||
// remove unused cruft
|
||||
unset($rec['_raw_attrib']);
|
||||
|
||||
// force $rec['members'] to be an array
|
||||
if (!empty($rec['members']) && !is_array($rec['members'])) {
|
||||
$rec['members'] = array($rec['members']);
|
||||
}
|
||||
|
||||
// remove unused cruft
|
||||
unset($rec['_raw_attrib']);
|
||||
|
||||
return $rec;
|
||||
return $rec;
|
||||
}
|
||||
|
||||
private function connect()
|
||||
{
|
||||
if (!isset($this->ldap)) {
|
||||
$this->ldap = new rcube_ldap($this->rc->config->get('calendar_resources_directory'), true);
|
||||
}
|
||||
if (!isset($this->ldap)) {
|
||||
$this->ldap = new rcube_ldap($this->rc->config->get('calendar_resources_directory'), true);
|
||||
}
|
||||
|
||||
return $this->ldap->ready ? $this->ldap : null;
|
||||
return $this->ldap->ready ? $this->ldap : null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,87 +26,93 @@
|
|||
*/
|
||||
abstract class resources_driver
|
||||
{
|
||||
protected $cal;
|
||||
protected $cal;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
function __construct($cal)
|
||||
{
|
||||
$this->cal = $cal;
|
||||
}
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
function __construct($cal)
|
||||
{
|
||||
$this->cal = $cal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch resource objects to be displayed for booking
|
||||
*
|
||||
* @param string Search query (optional)
|
||||
* @return array List of resource records available for booking
|
||||
*/
|
||||
abstract public function load_resources($query = null);
|
||||
/**
|
||||
* Fetch resource objects to be displayed for booking
|
||||
*
|
||||
* @param string $query Search query (optional)
|
||||
*
|
||||
* @return array List of resource records available for booking
|
||||
*/
|
||||
abstract public function load_resources($query = null);
|
||||
|
||||
/**
|
||||
* Return properties of a single resource
|
||||
*
|
||||
* @param string Unique resource identifier
|
||||
* @return array Resource object as hash array
|
||||
*/
|
||||
abstract public function get_resource($id);
|
||||
/**
|
||||
* Return properties of a single resource
|
||||
*
|
||||
* @param string $id Unique resource identifier
|
||||
*
|
||||
* @return array Resource object as hash array
|
||||
*/
|
||||
abstract public function get_resource($id);
|
||||
|
||||
/**
|
||||
* Return properties of a resource owner
|
||||
*
|
||||
* @param string Owner identifier
|
||||
* @return array Resource object as hash array
|
||||
*/
|
||||
public function get_resource_owner($id)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Return properties of a resource owner
|
||||
*
|
||||
* @param string $id Owner identifier
|
||||
*
|
||||
* @return array Resource object as hash array
|
||||
*/
|
||||
public function get_resource_owner($id)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get event data to display a resource's calendar
|
||||
*
|
||||
* The default implementation extracts the resource's email address
|
||||
* and fetches free-busy data using the calendar backend driver.
|
||||
*
|
||||
* @param integer Event's new start (unix timestamp)
|
||||
* @param integer Event's new end (unix timestamp)
|
||||
* @return array A list of event objects (see calendar_driver specification)
|
||||
*/
|
||||
public function get_resource_calendar($id, $start, $end)
|
||||
{
|
||||
$events = array();
|
||||
$rec = $this->get_resource($id);
|
||||
if ($rec && !empty($rec['email']) && $this->cal->driver) {
|
||||
$fbtypemap = array(
|
||||
calendar::FREEBUSY_BUSY => 'busy',
|
||||
calendar::FREEBUSY_TENTATIVE => 'tentative',
|
||||
calendar::FREEBUSY_OOF => 'outofoffice',
|
||||
);
|
||||
/**
|
||||
* Get event data to display a resource's calendar
|
||||
*
|
||||
* The default implementation extracts the resource's email address
|
||||
* and fetches free-busy data using the calendar backend driver.
|
||||
*
|
||||
* @param string $id Calendar identifier
|
||||
* @param int $start Event's new start (unix timestamp)
|
||||
* @param int $end Event's new end (unix timestamp)
|
||||
*
|
||||
* @return array A list of event objects (see calendar_driver specification)
|
||||
*/
|
||||
public function get_resource_calendar($id, $start, $end)
|
||||
{
|
||||
$events = [];
|
||||
$rec = $this->get_resource($id);
|
||||
|
||||
// if the backend has free-busy information
|
||||
$fblist = $this->cal->driver->get_freebusy_list($rec['email'], $start, $end);
|
||||
if (is_array($fblist)) {
|
||||
foreach ($fblist as $slot) {
|
||||
list($from, $to, $type) = $slot;
|
||||
if ($type == calendar::FREEBUSY_FREE || $type == calendar::FREEBUSY_UNKNOWN) {
|
||||
continue;
|
||||
}
|
||||
if ($from < $end && $to > $start) {
|
||||
$event = array(
|
||||
'id' => sha1($id . $from . $to),
|
||||
'title' => $rec['name'],
|
||||
'start' => new DateTime('@' . $from),
|
||||
'end' => new DateTime('@' . $to),
|
||||
'status' => $fbtypemap[$type],
|
||||
'calendar' => '_resource',
|
||||
);
|
||||
$events[] = $event;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($rec && !empty($rec['email']) && !empty($this->cal->driver)) {
|
||||
$fbtypemap = [
|
||||
calendar::FREEBUSY_BUSY => 'busy',
|
||||
calendar::FREEBUSY_TENTATIVE => 'tentative',
|
||||
calendar::FREEBUSY_OOF => 'outofoffice',
|
||||
];
|
||||
|
||||
return $events;
|
||||
}
|
||||
// if the backend has free-busy information
|
||||
$fblist = $this->cal->driver->get_freebusy_list($rec['email'], $start, $end);
|
||||
if (is_array($fblist)) {
|
||||
foreach ($fblist as $slot) {
|
||||
list($from, $to, $type) = $slot;
|
||||
if ($type == calendar::FREEBUSY_FREE || $type == calendar::FREEBUSY_UNKNOWN) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($from < $end && $to > $start) {
|
||||
$events[] = [
|
||||
'id' => sha1($id . $from . $to),
|
||||
'title' => $rec['name'],
|
||||
'start' => new DateTime('@' . $from),
|
||||
'end' => new DateTime('@' . $to),
|
||||
'status' => $fbtypemap[$type],
|
||||
'calendar' => '_resource',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,213 +28,231 @@ require_once realpath(__DIR__ . '/../../libcalendaring/lib/libcalendaring_itip.p
|
|||
*/
|
||||
class calendar_itip extends libcalendaring_itip
|
||||
{
|
||||
/**
|
||||
* Constructor to set text domain to calendar
|
||||
*/
|
||||
function __construct($plugin, $domain = 'calendar')
|
||||
{
|
||||
parent::__construct($plugin, $domain);
|
||||
/**
|
||||
* Constructor to set text domain to calendar
|
||||
*/
|
||||
function __construct($plugin, $domain = 'calendar')
|
||||
{
|
||||
parent::__construct($plugin, $domain);
|
||||
|
||||
$this->db_itipinvitations = $this->rc->db->table_name('itipinvitations', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for calendar/itip-status requests
|
||||
*/
|
||||
public function get_itip_status($event, $existing = null)
|
||||
{
|
||||
$status = parent::get_itip_status($event, $existing);
|
||||
|
||||
// don't ask for deleting events when declining
|
||||
if ($this->rc->config->get('kolab_invitation_calendars'))
|
||||
$status['saved'] = false;
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find invitation record by token
|
||||
*
|
||||
* @param string Invitation token
|
||||
* @return mixed Invitation record as hash array or False if not found
|
||||
*/
|
||||
public function get_invitation($token)
|
||||
{
|
||||
if ($parts = $this->decode_token($token)) {
|
||||
$result = $this->rc->db->query("SELECT * FROM $this->db_itipinvitations WHERE `token` = ?", $parts['base']);
|
||||
if ($result && ($rec = $this->rc->db->fetch_assoc($result))) {
|
||||
$rec['event'] = unserialize($rec['event']);
|
||||
$rec['attendee'] = $parts['attendee'];
|
||||
return $rec;
|
||||
}
|
||||
$this->db_itipinvitations = $this->rc->db->table_name('itipinvitations', true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the attendee status of the given invitation record
|
||||
*
|
||||
* @param array Invitation record as fetched with calendar_itip::get_invitation()
|
||||
* @param string Attendee email address
|
||||
* @param string New attendee status
|
||||
*/
|
||||
public function update_invitation($invitation, $email, $newstatus)
|
||||
{
|
||||
if (is_string($invitation))
|
||||
$invitation = $this->get_invitation($invitation);
|
||||
|
||||
if ($invitation['token'] && $invitation['event']) {
|
||||
// update attendee record in event data
|
||||
foreach ($invitation['event']['attendees'] as $i => $attendee) {
|
||||
if ($attendee['role'] == 'ORGANIZER') {
|
||||
$organizer = $attendee;
|
||||
/**
|
||||
* Handler for calendar/itip-status requests
|
||||
*/
|
||||
public function get_itip_status($event, $existing = null)
|
||||
{
|
||||
$status = parent::get_itip_status($event, $existing);
|
||||
|
||||
// don't ask for deleting events when declining
|
||||
if ($this->rc->config->get('kolab_invitation_calendars')) {
|
||||
$status['saved'] = false;
|
||||
}
|
||||
else if ($attendee['email'] == $email) {
|
||||
// nothing to be done here
|
||||
if ($attendee['status'] == $newstatus)
|
||||
return true;
|
||||
|
||||
$invitation['event']['attendees'][$i]['status'] = $newstatus;
|
||||
$this->sender = $attendee;
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find invitation record by token
|
||||
*
|
||||
* @param string $token Invitation token
|
||||
*
|
||||
* @return mixed Invitation record as hash array or False if not found
|
||||
*/
|
||||
public function get_invitation($token)
|
||||
{
|
||||
if ($parts = $this->decode_token($token)) {
|
||||
$result = $this->rc->db->query("SELECT * FROM $this->db_itipinvitations WHERE `token` = ?", $parts['base']);
|
||||
if ($result && ($rec = $this->rc->db->fetch_assoc($result))) {
|
||||
$rec['event'] = unserialize($rec['event']);
|
||||
$rec['attendee'] = $parts['attendee'];
|
||||
|
||||
return $rec;
|
||||
}
|
||||
}
|
||||
}
|
||||
$invitation['event']['changed'] = new DateTime();
|
||||
|
||||
// send iTIP REPLY message to organizer
|
||||
if ($organizer) {
|
||||
$status = strtolower($newstatus);
|
||||
if ($this->send_itip_message($invitation['event'], 'REPLY', $organizer, 'itipsubject' . $status, 'itipmailbody' . $status))
|
||||
$this->rc->output->command('display_message', $this->plugin->gettext(array('name' => 'sentresponseto', 'vars' => array('mailto' => $organizer['name'] ? $organizer['name'] : $organizer['email']))), 'confirmation');
|
||||
else
|
||||
$this->rc->output->command('display_message', $this->plugin->gettext('itipresponseerror'), 'error');
|
||||
}
|
||||
|
||||
// update record in DB
|
||||
$query = $this->rc->db->query(
|
||||
"UPDATE $this->db_itipinvitations
|
||||
SET `event` = ?
|
||||
WHERE `token` = ?",
|
||||
self::serialize_event($invitation['event']),
|
||||
$invitation['token']
|
||||
);
|
||||
|
||||
if ($this->rc->db->affected_rows($query))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the attendee status of the given invitation record
|
||||
*
|
||||
* @param array $invitation Invitation record as fetched with calendar_itip::get_invitation()
|
||||
* @param string $email Attendee email address
|
||||
* @param string $newstatus New attendee status
|
||||
*/
|
||||
public function update_invitation($invitation, $email, $newstatus)
|
||||
{
|
||||
if (is_string($invitation)) {
|
||||
$invitation = $this->get_invitation($invitation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create iTIP invitation token for later replies via URL
|
||||
*
|
||||
* @param array Hash array with event properties
|
||||
* @param string Attendee email address
|
||||
* @return string Invitation token
|
||||
*/
|
||||
public function store_invitation($event, $attendee)
|
||||
{
|
||||
static $stored = array();
|
||||
|
||||
if (!$event['uid'] || !$attendee)
|
||||
return false;
|
||||
|
||||
// generate token for this invitation
|
||||
$token = $this->generate_token($event, $attendee);
|
||||
$base = substr($token, 0, 40);
|
||||
|
||||
// already stored this
|
||||
if ($stored[$base])
|
||||
return $token;
|
||||
if (!empty($invitation['token']) && !empty($invitation['event'])) {
|
||||
// update attendee record in event data
|
||||
foreach ($invitation['event']['attendees'] as $i => $attendee) {
|
||||
if ($attendee['role'] == 'ORGANIZER') {
|
||||
$organizer = $attendee;
|
||||
}
|
||||
else if ($attendee['email'] == $email) {
|
||||
// nothing to be done here
|
||||
if ($attendee['status'] == $newstatus) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// delete old entry
|
||||
$this->rc->db->query("DELETE FROM $this->db_itipinvitations WHERE `token` = ?", $base);
|
||||
$invitation['event']['attendees'][$i]['status'] = $newstatus;
|
||||
$this->sender = $attendee;
|
||||
}
|
||||
}
|
||||
|
||||
$event_uid = $event['uid'] . ($event['_instance'] ? '-' . $event['_instance'] : '');
|
||||
$invitation['event']['changed'] = new DateTime();
|
||||
|
||||
$query = $this->rc->db->query(
|
||||
"INSERT INTO $this->db_itipinvitations
|
||||
(`token`, `event_uid`, `user_id`, `event`, `expires`)
|
||||
VALUES(?, ?, ?, ?, ?)",
|
||||
$base,
|
||||
$event_uid,
|
||||
$this->rc->user->ID,
|
||||
self::serialize_event($event),
|
||||
date('Y-m-d H:i:s', $event['end']->format('U') + 86400 * 2)
|
||||
);
|
||||
|
||||
if ($this->rc->db->affected_rows($query)) {
|
||||
$stored[$base] = 1;
|
||||
return $token;
|
||||
// send iTIP REPLY message to organizer
|
||||
if (!empty($organizer)) {
|
||||
$status = strtolower($newstatus);
|
||||
if ($this->send_itip_message($invitation['event'], 'REPLY', $organizer, 'itipsubject' . $status, 'itipmailbody' . $status)) {
|
||||
$mailto = !empty($organizer['name']) ? $organizer['name'] : $organizer['email'];
|
||||
$message = $this->plugin->gettext([
|
||||
'name' => 'sentresponseto',
|
||||
'vars' => ['mailto' => $mailto]
|
||||
]);
|
||||
$this->rc->output->command('display_message', $message, 'confirmation');
|
||||
}
|
||||
else {
|
||||
$this->rc->output->command('display_message', $this->plugin->gettext('itipresponseerror'), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// update record in DB
|
||||
$query = $this->rc->db->query(
|
||||
"UPDATE $this->db_itipinvitations SET `event` = ? WHERE `token` = ?",
|
||||
self::serialize_event($invitation['event']),
|
||||
$invitation['token']
|
||||
);
|
||||
|
||||
if ($this->rc->db->affected_rows($query)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark invitations for the given event as cancelled
|
||||
*
|
||||
* @param array Hash array with event properties
|
||||
*/
|
||||
public function cancel_itip_invitation($event)
|
||||
{
|
||||
$event_uid = $event['uid'] . ($event['_instance'] ? '-' . $event['_instance'] : '');
|
||||
/**
|
||||
* Create iTIP invitation token for later replies via URL
|
||||
*
|
||||
* @param array $event Hash array with event properties
|
||||
* @param string $attendee Attendee email address
|
||||
*
|
||||
* @return string Invitation token
|
||||
*/
|
||||
public function store_invitation($event, $attendee)
|
||||
{
|
||||
static $stored = [];
|
||||
|
||||
// flag invitation record as cancelled
|
||||
$this->rc->db->query(
|
||||
"UPDATE $this->db_itipinvitations
|
||||
SET `cancelled` = 1
|
||||
WHERE `event_uid` = ? AND `user_id` = ?",
|
||||
$event_uid,
|
||||
$this->rc->user->ID
|
||||
);
|
||||
}
|
||||
if (empty($event['uid']) || !$attendee) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an invitation request token for the given event and attendee
|
||||
*
|
||||
* @param array Event hash array
|
||||
* @param string Attendee email address
|
||||
*/
|
||||
public function generate_token($event, $attendee)
|
||||
{
|
||||
$event_uid = $event['uid'] . ($event['_instance'] ? '-' . $event['_instance'] : '');
|
||||
$base = sha1($event_uid . ';' . $this->rc->user->ID);
|
||||
$mail = base64_encode($attendee);
|
||||
$hash = substr(md5($base . $mail . $this->rc->config->get('des_key')), 0, 6);
|
||||
|
||||
return "$base.$mail.$hash";
|
||||
}
|
||||
// generate token for this invitation
|
||||
$token = $this->generate_token($event, $attendee);
|
||||
$base = substr($token, 0, 40);
|
||||
|
||||
/**
|
||||
* Decode the given iTIP request token and return its parts
|
||||
*
|
||||
* @param string Request token to decode
|
||||
* @return mixed Hash array with parts or False if invalid
|
||||
*/
|
||||
public function decode_token($token)
|
||||
{
|
||||
list($base, $mail, $hash) = explode('.', $token);
|
||||
|
||||
// validate and return parts
|
||||
if ($mail && $hash && $hash == substr(md5($base . $mail . $this->rc->config->get('des_key')), 0, 6)) {
|
||||
return array('base' => $base, 'attendee' => base64_decode($mail));
|
||||
// already stored this
|
||||
if (!empty($stored[$base])) {
|
||||
return $token;
|
||||
}
|
||||
|
||||
// delete old entry
|
||||
$this->rc->db->query("DELETE FROM $this->db_itipinvitations WHERE `token` = ?", $base);
|
||||
|
||||
$event_uid = $event['uid'] . (!empty($event['_instance']) ? '-' . $event['_instance'] : '');
|
||||
|
||||
$query = $this->rc->db->query(
|
||||
"INSERT INTO $this->db_itipinvitations"
|
||||
. " (`token`, `event_uid`, `user_id`, `event`, `expires`)"
|
||||
. " VALUES(?, ?, ?, ?, ?)",
|
||||
$base,
|
||||
$event_uid,
|
||||
$this->rc->user->ID,
|
||||
self::serialize_event($event),
|
||||
date('Y-m-d H:i:s', $event['end']->format('U') + 86400 * 2)
|
||||
);
|
||||
|
||||
if ($this->rc->db->affected_rows($query)) {
|
||||
$stored[$base] = 1;
|
||||
return $token;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to serialize the given event for storing in invitations table
|
||||
*/
|
||||
private static function serialize_event($event)
|
||||
{
|
||||
$ev = $event;
|
||||
$ev['description'] = abbreviate_string($ev['description'], 100);
|
||||
unset($ev['attachments']);
|
||||
return serialize($ev);
|
||||
}
|
||||
/**
|
||||
* Mark invitations for the given event as cancelled
|
||||
*
|
||||
* @param array $event Hash array with event properties
|
||||
*/
|
||||
public function cancel_itip_invitation($event)
|
||||
{
|
||||
$event_uid = $event['uid'] . (!empty($event['_instance']) ? '-' . $event['_instance'] : '');
|
||||
|
||||
// flag invitation record as cancelled
|
||||
$this->rc->db->query(
|
||||
"UPDATE $this->db_itipinvitations SET `cancelled` = 1"
|
||||
. " WHERE `event_uid` = ? AND `user_id` = ?",
|
||||
$event_uid,
|
||||
$this->rc->user->ID
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an invitation request token for the given event and attendee
|
||||
*
|
||||
* @param array $event Event hash array
|
||||
* @param string $attendee Attendee email address
|
||||
*/
|
||||
public function generate_token($event, $attendee)
|
||||
{
|
||||
$event_uid = $event['uid'] . (!empty($event['_instance']) ? '-' . $event['_instance'] : '');
|
||||
$base = sha1($event_uid . ';' . $this->rc->user->ID);
|
||||
$mail = base64_encode($attendee);
|
||||
$hash = substr(md5($base . $mail . $this->rc->config->get('des_key')), 0, 6);
|
||||
|
||||
return "$base.$mail.$hash";
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the given iTIP request token and return its parts
|
||||
*
|
||||
* @param string $token Request token to decode
|
||||
*
|
||||
* @return mixed Hash array with parts or False if invalid
|
||||
*/
|
||||
public function decode_token($token)
|
||||
{
|
||||
list($base, $mail, $hash) = explode('.', $token);
|
||||
|
||||
// validate and return parts
|
||||
if ($mail && $hash && $hash == substr(md5($base . $mail . $this->rc->config->get('des_key')), 0, 6)) {
|
||||
return ['base' => $base, 'attendee' => base64_decode($mail)];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to serialize the given event for storing in invitations table
|
||||
*/
|
||||
private static function serialize_event($event)
|
||||
{
|
||||
$ev = $event;
|
||||
|
||||
if (!empty($ev['description'])) {
|
||||
$ev['description'] = abbreviate_string($ev['description'], 100);
|
||||
}
|
||||
|
||||
unset($ev['attachments']);
|
||||
|
||||
return serialize($ev);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,63 +26,64 @@ require_once realpath(__DIR__ . '/../../libcalendaring/lib/libcalendaring_recurr
|
|||
*/
|
||||
class calendar_recurrence extends libcalendaring_recurrence
|
||||
{
|
||||
private $event;
|
||||
private $duration;
|
||||
private $event;
|
||||
private $duration;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @param object calendar The calendar plugin instance
|
||||
* @param array The event object to operate on
|
||||
*/
|
||||
function __construct($cal, $event)
|
||||
{
|
||||
parent::__construct($cal->lib);
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @param calendar $cal The calendar plugin instance
|
||||
* @param array $event The event object to operate on
|
||||
*/
|
||||
function __construct($cal, $event)
|
||||
{
|
||||
parent::__construct($cal->lib);
|
||||
|
||||
$this->event = $event;
|
||||
$this->event = $event;
|
||||
|
||||
if (is_object($event['start']) && is_object($event['end']))
|
||||
$this->duration = $event['start']->diff($event['end']);
|
||||
if (is_object($event['start']) && is_object($event['end'])) {
|
||||
$this->duration = $event['start']->diff($event['end']);
|
||||
}
|
||||
|
||||
$event['start']->_dateonly |= $event['allday'];
|
||||
$this->init($event['recurrence'], $event['start']);
|
||||
}
|
||||
$event['start']->_dateonly = !empty($event['allday']);
|
||||
|
||||
/**
|
||||
* Alias of libcalendaring_recurrence::next()
|
||||
*
|
||||
* @return mixed DateTime object or False if recurrence ended
|
||||
*/
|
||||
public function next_start()
|
||||
{
|
||||
return $this->next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next recurring instance of this event
|
||||
*
|
||||
* @return mixed Array with event properties or False if recurrence ended
|
||||
*/
|
||||
public function next_instance()
|
||||
{
|
||||
if ($next_start = $this->next()) {
|
||||
$next = $this->event;
|
||||
$next['start'] = $next_start;
|
||||
|
||||
if ($this->duration) {
|
||||
$next['end'] = clone $next_start;
|
||||
$next['end']->add($this->duration);
|
||||
}
|
||||
|
||||
$next['recurrence_date'] = clone $next_start;
|
||||
$next['_instance'] = libcalendaring::recurrence_instance_identifier($next, $this->event['allday']);
|
||||
|
||||
unset($next['_formatobj']);
|
||||
|
||||
return $next;
|
||||
$this->init($event['recurrence'], $event['start']);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Alias of libcalendaring_recurrence::next()
|
||||
*
|
||||
* @return mixed DateTime object or False if recurrence ended
|
||||
*/
|
||||
public function next_start()
|
||||
{
|
||||
return $this->next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next recurring instance of this event
|
||||
*
|
||||
* @return mixed Array with event properties or False if recurrence ended
|
||||
*/
|
||||
public function next_instance()
|
||||
{
|
||||
if ($next_start = $this->next()) {
|
||||
$next = $this->event;
|
||||
$next['start'] = $next_start;
|
||||
|
||||
if ($this->duration) {
|
||||
$next['end'] = clone $next_start;
|
||||
$next['end']->add($this->duration);
|
||||
}
|
||||
|
||||
$next['recurrence_date'] = clone $next_start;
|
||||
$next['_instance'] = libcalendaring::recurrence_instance_identifier($next, $this->event['allday']);
|
||||
|
||||
unset($next['_formatobj']);
|
||||
|
||||
return $next;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1196,5 +1196,4 @@ class kolab_addressbook extends rcube_plugin
|
|||
$this->rc->user->save_prefs(array('calendar_birthday_adressbooks' => $bday_addressbooks));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,52 +34,78 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
public $undelete = true;
|
||||
public $groups = true;
|
||||
public $coltypes = array(
|
||||
'name' => array('limit' => 1),
|
||||
'firstname' => array('limit' => 1),
|
||||
'surname' => array('limit' => 1),
|
||||
'middlename' => array('limit' => 1),
|
||||
'prefix' => array('limit' => 1),
|
||||
'suffix' => array('limit' => 1),
|
||||
'nickname' => array('limit' => 1),
|
||||
'jobtitle' => array('limit' => 1),
|
||||
'organization' => array('limit' => 1),
|
||||
'department' => array('limit' => 1),
|
||||
'email' => array('subtypes' => array('home','work','other')),
|
||||
'phone' => array(),
|
||||
'address' => array('subtypes' => array('home','work','office')),
|
||||
'website' => array('subtypes' => array('homepage','blog')),
|
||||
'im' => array('subtypes' => null),
|
||||
'gender' => array('limit' => 1),
|
||||
'birthday' => array('limit' => 1),
|
||||
'anniversary' => array('limit' => 1),
|
||||
'profession' => array('type' => 'text', 'size' => 40, 'maxlength' => 80, 'limit' => 1,
|
||||
'label' => 'kolab_addressbook.profession', 'category' => 'personal'),
|
||||
'manager' => array('limit' => null),
|
||||
'assistant' => array('limit' => null),
|
||||
'spouse' => array('limit' => 1),
|
||||
'children' => array('type' => 'text', 'size' => 40, 'maxlength' => 80, 'limit' => null,
|
||||
'label' => 'kolab_addressbook.children', 'category' => 'personal'),
|
||||
'freebusyurl' => array('type' => 'text', 'size' => 40, 'limit' => 1,
|
||||
'label' => 'kolab_addressbook.freebusyurl'),
|
||||
'pgppublickey' => array('type' => 'textarea', 'size' => 70, 'rows' => 10, 'limit' => 1,
|
||||
'label' => 'kolab_addressbook.pgppublickey'),
|
||||
'pkcs7publickey' => array('type' => 'textarea', 'size' => 70, 'rows' => 10, 'limit' => 1,
|
||||
'label' => 'kolab_addressbook.pkcs7publickey'),
|
||||
'notes' => array('limit' => 1),
|
||||
'photo' => array('limit' => 1),
|
||||
// TODO: define more Kolab-specific fields such as: language, latitude, longitude, crypto settings
|
||||
'name' => array('limit' => 1),
|
||||
'firstname' => array('limit' => 1),
|
||||
'surname' => array('limit' => 1),
|
||||
'middlename' => array('limit' => 1),
|
||||
'prefix' => array('limit' => 1),
|
||||
'suffix' => array('limit' => 1),
|
||||
'nickname' => array('limit' => 1),
|
||||
'jobtitle' => array('limit' => 1),
|
||||
'organization' => array('limit' => 1),
|
||||
'department' => array('limit' => 1),
|
||||
'email' => array('subtypes' => array('home','work','other')),
|
||||
'phone' => array(),
|
||||
'address' => array('subtypes' => array('home','work','office')),
|
||||
'website' => array('subtypes' => array('homepage','blog')),
|
||||
'im' => array('subtypes' => null),
|
||||
'gender' => array('limit' => 1),
|
||||
'birthday' => array('limit' => 1),
|
||||
'anniversary' => array('limit' => 1),
|
||||
'profession' => array(
|
||||
'type' => 'text',
|
||||
'size' => 40,
|
||||
'maxlength' => 80,
|
||||
'limit' => 1,
|
||||
'label' => 'kolab_addressbook.profession',
|
||||
'category' => 'personal'
|
||||
),
|
||||
'manager' => array('limit' => null),
|
||||
'assistant' => array('limit' => null),
|
||||
'spouse' => array('limit' => 1),
|
||||
'children' => array(
|
||||
'type' => 'text',
|
||||
'size' => 40,
|
||||
'maxlength' => 80,
|
||||
'limit' => null,
|
||||
'label' => 'kolab_addressbook.children',
|
||||
'category' => 'personal'
|
||||
),
|
||||
'freebusyurl' => array(
|
||||
'type' => 'text',
|
||||
'size' => 40,
|
||||
'limit' => 1,
|
||||
'label' => 'kolab_addressbook.freebusyurl'
|
||||
),
|
||||
'pgppublickey' => array(
|
||||
'type' => 'textarea',
|
||||
'size' => 70,
|
||||
'rows' => 10,
|
||||
'limit' => 1,
|
||||
'label' => 'kolab_addressbook.pgppublickey'
|
||||
),
|
||||
'pkcs7publickey' => array(
|
||||
'type' => 'textarea',
|
||||
'size' => 70,
|
||||
'rows' => 10,
|
||||
'limit' => 1,
|
||||
'label' => 'kolab_addressbook.pkcs7publickey'
|
||||
),
|
||||
'notes' => array('limit' => 1),
|
||||
'photo' => array('limit' => 1),
|
||||
// TODO: define more Kolab-specific fields such as: language, latitude, longitude, crypto settings
|
||||
);
|
||||
|
||||
/**
|
||||
* vCard additional fields mapping
|
||||
*/
|
||||
public $vcard_map = array(
|
||||
'profession' => 'X-PROFESSION',
|
||||
'officelocation' => 'X-OFFICE-LOCATION',
|
||||
'initials' => 'X-INITIALS',
|
||||
'children' => 'X-CHILDREN',
|
||||
'freebusyurl' => 'X-FREEBUSY-URL',
|
||||
'pgppublickey' => 'KEY',
|
||||
'profession' => 'X-PROFESSION',
|
||||
'officelocation' => 'X-OFFICE-LOCATION',
|
||||
'initials' => 'X-INITIALS',
|
||||
'children' => 'X-CHILDREN',
|
||||
'freebusyurl' => 'X-FREEBUSY-URL',
|
||||
'pgppublickey' => 'KEY',
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -102,25 +128,25 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
|
||||
// list of fields used for searching in "All fields" mode
|
||||
private $search_fields = array(
|
||||
'name',
|
||||
'firstname',
|
||||
'surname',
|
||||
'middlename',
|
||||
'prefix',
|
||||
'suffix',
|
||||
'nickname',
|
||||
'jobtitle',
|
||||
'organization',
|
||||
'department',
|
||||
'email',
|
||||
'phone',
|
||||
'address',
|
||||
'profession',
|
||||
'manager',
|
||||
'assistant',
|
||||
'spouse',
|
||||
'children',
|
||||
'notes',
|
||||
'name',
|
||||
'firstname',
|
||||
'surname',
|
||||
'middlename',
|
||||
'prefix',
|
||||
'suffix',
|
||||
'nickname',
|
||||
'jobtitle',
|
||||
'organization',
|
||||
'department',
|
||||
'email',
|
||||
'phone',
|
||||
'address',
|
||||
'profession',
|
||||
'manager',
|
||||
'assistant',
|
||||
'spouse',
|
||||
'children',
|
||||
'notes',
|
||||
);
|
||||
|
||||
|
||||
|
@ -132,15 +158,17 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
|
||||
// extend coltypes configuration
|
||||
$format = kolab_format::factory('contact');
|
||||
$this->coltypes['phone']['subtypes'] = array_keys($format->phonetypes);
|
||||
|
||||
$this->coltypes['phone']['subtypes'] = array_keys($format->phonetypes);
|
||||
$this->coltypes['address']['subtypes'] = array_keys($format->addresstypes);
|
||||
|
||||
$rcube = rcube::get_instance();
|
||||
|
||||
// set localized labels for proprietary cols
|
||||
foreach ($this->coltypes as $col => $prop) {
|
||||
if (is_string($prop['label']))
|
||||
if (is_string($prop['label'])) {
|
||||
$this->coltypes[$col]['label'] = $rcube->gettext($prop['label']);
|
||||
}
|
||||
}
|
||||
|
||||
// fetch objects from the given IMAP folder
|
||||
|
@ -157,8 +185,9 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
$rights = $this->storagefolder->get_myrights();
|
||||
if ($rights && !PEAR::isError($rights)) {
|
||||
$this->rights = $rights;
|
||||
if (strpos($rights, 'i') !== false && strpos($rights, 't') !== false)
|
||||
if (strpos($rights, 'i') !== false && strpos($rights, 't') !== false) {
|
||||
$this->readonly = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -233,17 +262,17 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
*/
|
||||
public function get_carddav_url()
|
||||
{
|
||||
$rcmail = rcmail::get_instance();
|
||||
if ($template = $rcmail->config->get('kolab_addressbook_carddav_url', null)) {
|
||||
return strtr($template, array(
|
||||
'%h' => $_SERVER['HTTP_HOST'],
|
||||
'%u' => urlencode($rcmail->get_user_name()),
|
||||
'%i' => urlencode($this->storagefolder->get_uid()),
|
||||
'%n' => urlencode($this->imap_folder),
|
||||
));
|
||||
}
|
||||
$rcmail = rcmail::get_instance();
|
||||
if ($template = $rcmail->config->get('kolab_addressbook_carddav_url', null)) {
|
||||
return strtr($template, array(
|
||||
'%h' => $_SERVER['HTTP_HOST'],
|
||||
'%u' => urlencode($rcmail->get_user_name()),
|
||||
'%i' => urlencode($this->storagefolder->get_uid()),
|
||||
'%n' => urlencode($this->imap_folder),
|
||||
));
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -254,7 +283,6 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
$this->gid = $gid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save a search string for future listings
|
||||
*
|
||||
|
@ -265,7 +293,6 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
$this->filter = $filter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Getter for saved search properties
|
||||
*
|
||||
|
@ -276,7 +303,6 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
return $this->filter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reset saved results and search parameters
|
||||
*/
|
||||
|
@ -286,14 +312,13 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
$this->filter = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List all active contact groups of this source
|
||||
*
|
||||
* @param string Optional search string to match group name
|
||||
* @param int Search mode. Sum of self::SEARCH_*
|
||||
*
|
||||
* @return array Indexed list of contact groups, each a hash array
|
||||
* @return array Indexed list of contact groups, each a hash array
|
||||
*/
|
||||
function list_groups($search = null, $mode = 0)
|
||||
{
|
||||
|
@ -312,15 +337,14 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
return array_values($groups);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List the current set of contact records
|
||||
*
|
||||
* @param array List of cols to show
|
||||
* @param int Only return this number of records, use negative values for tail
|
||||
* @param boolean True to skip the count query (select only)
|
||||
* @param int Only return this number of records, use negative values for tail
|
||||
* @param bool True to skip the count query (select only)
|
||||
*
|
||||
* @return array Indexed list of contact records, each a hash array
|
||||
* @return array Indexed list of contact records, each a hash array
|
||||
*/
|
||||
public function list_records($cols = null, $subset = 0, $nocount = false)
|
||||
{
|
||||
|
@ -409,22 +433,21 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
return $this->result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Search records
|
||||
*
|
||||
* @param mixed $fields The field name of array of field names to search in
|
||||
* @param mixed $value Search value (or array of values when $fields is array)
|
||||
* @param int $mode Matching mode:
|
||||
* 0 - partial (*abc*),
|
||||
* 1 - strict (=),
|
||||
* 2 - prefix (abc*)
|
||||
* 4 - include groups (if supported)
|
||||
* @param boolean $select True if results are requested, False if count only
|
||||
* @param boolean $nocount True to skip the count query (select only)
|
||||
* @param array $required List of fields that cannot be empty
|
||||
* @param mixed $fields The field name of array of field names to search in
|
||||
* @param mixed $value Search value (or array of values when $fields is array)
|
||||
* @param int $mode Matching mode:
|
||||
* 0 - partial (*abc*),
|
||||
* 1 - strict (=),
|
||||
* 2 - prefix (abc*)
|
||||
* 4 - include groups (if supported)
|
||||
* @param bool $select True if results are requested, False if count only
|
||||
* @param bool $nocount True to skip the count query (select only)
|
||||
* @param array $required List of fields that cannot be empty
|
||||
*
|
||||
* @return object rcube_result_set List of contact records and 'count' value
|
||||
* @return rcube_result_set List of contact records and 'count' value
|
||||
*/
|
||||
public function search($fields, $value, $mode=0, $select=true, $nocount=false, $required=array())
|
||||
{
|
||||
|
@ -445,18 +468,21 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
$fields = $this->search_fields;
|
||||
}
|
||||
|
||||
if (!is_array($fields))
|
||||
if (!is_array($fields)) {
|
||||
$fields = array($fields);
|
||||
if (!is_array($required) && !empty($required))
|
||||
}
|
||||
if (!is_array($required) && !empty($required)) {
|
||||
$required = array($required);
|
||||
}
|
||||
|
||||
// advanced search
|
||||
if (is_array($value)) {
|
||||
$advanced = true;
|
||||
$value = array_map('mb_strtolower', $value);
|
||||
}
|
||||
else
|
||||
else {
|
||||
$value = mb_strtolower($value);
|
||||
}
|
||||
|
||||
$scount = count($fields);
|
||||
// build key name regexp
|
||||
|
@ -526,19 +552,18 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
return $this->list_records();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Refresh saved search results after data has changed
|
||||
*/
|
||||
public function refresh_search()
|
||||
{
|
||||
if ($this->filter)
|
||||
if ($this->filter) {
|
||||
$this->search($this->filter['fields'], $this->filter['value'], $this->filter['mode']);
|
||||
}
|
||||
|
||||
return $this->get_search_set();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Count number of available contacts in database
|
||||
*
|
||||
|
@ -560,7 +585,6 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
return new rcube_result_set($count, ($this->list_page-1) * $this->page_size);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the last result set
|
||||
*
|
||||
|
@ -571,15 +595,15 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
return $this->result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a specific contact record
|
||||
*
|
||||
* @param mixed record identifier(s)
|
||||
* @param boolean True to return record as associative array, otherwise a result set is returned
|
||||
* @param mixed Record identifier(s)
|
||||
* @param bool True to return record as associative array, otherwise a result set is returned
|
||||
*
|
||||
* @return mixed Result object with all record fields or False if not found
|
||||
*/
|
||||
public function get_record($id, $assoc=false)
|
||||
public function get_record($id, $assoc = false)
|
||||
{
|
||||
$rec = null;
|
||||
$uid = $this->id2uid($id);
|
||||
|
@ -612,11 +636,11 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get group assignments of a specific contact record
|
||||
*
|
||||
* @param mixed Record identifier
|
||||
*
|
||||
* @return array List of assigned groups as ID=>Name pairs
|
||||
*/
|
||||
public function get_record_groups($id)
|
||||
|
@ -624,28 +648,33 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
$out = array();
|
||||
$this->_fetch_groups();
|
||||
|
||||
foreach ((array)$this->groupmembers[$id] as $gid) {
|
||||
if ($group = $this->distlists[$gid])
|
||||
$out[$gid] = $group['name'];
|
||||
if (!empty($this->groupmembers[$id])) {
|
||||
foreach ((array) $this->groupmembers[$id] as $gid) {
|
||||
if (!empty($this->distlists[$gid])) {
|
||||
$group = $this->distlists[$gid];
|
||||
$out[$gid] = $group['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new contact record
|
||||
*
|
||||
* @param array Assoziative array with save data
|
||||
* @param array Associative array with save data
|
||||
* Keys: Field name with optional section in the form FIELD:SECTION
|
||||
* Values: Field value. Can be either a string or an array of strings for multiple values
|
||||
* @param boolean True to check for duplicates first
|
||||
* @param bool True to check for duplicates first
|
||||
*
|
||||
* @return mixed The created record ID on success, False on error
|
||||
*/
|
||||
public function insert($save_data, $check=false)
|
||||
{
|
||||
if (!is_array($save_data))
|
||||
if (!is_array($save_data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$insert_id = $existing = false;
|
||||
|
||||
|
@ -682,15 +711,15 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
return $insert_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a specific contact record
|
||||
*
|
||||
* @param mixed Record identifier
|
||||
* @param array Assoziative array with save data
|
||||
* @param array Associative array with save data
|
||||
* Keys: Field name with optional section in the form FIELD:SECTION
|
||||
* Values: Field value. Can be either a string or an array of strings for multiple values
|
||||
* @return boolean True on success, False on error
|
||||
*
|
||||
* @return bool True on success, False on error
|
||||
*/
|
||||
public function update($id, $save_data)
|
||||
{
|
||||
|
@ -700,10 +729,11 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
|
||||
if (!$this->storagefolder->save($object, 'contact', $old['uid'])) {
|
||||
rcube::raise_error(array(
|
||||
'code' => 600, 'type' => 'php',
|
||||
'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error saving contact object to Kolab server"),
|
||||
true, false);
|
||||
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error saving contact object to Kolab server"
|
||||
),
|
||||
true, false
|
||||
);
|
||||
}
|
||||
else {
|
||||
$updated = true;
|
||||
|
@ -715,12 +745,11 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
return $updated;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Mark one or more contact records as deleted
|
||||
*
|
||||
* @param array Record identifiers
|
||||
* @param boolean Remove record(s) irreversible (mark as deleted otherwise)
|
||||
* @param array Record identifiers
|
||||
* @param bool Remove record(s) irreversible (mark as deleted otherwise)
|
||||
*
|
||||
* @return int Number of records deleted
|
||||
*/
|
||||
|
@ -728,8 +757,9 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
{
|
||||
$this->_fetch_groups();
|
||||
|
||||
if (!is_array($ids))
|
||||
if (!is_array($ids)) {
|
||||
$ids = explode(',', $ids);
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
foreach ($ids as $id) {
|
||||
|
@ -739,16 +769,18 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
|
||||
if (!$deleted) {
|
||||
rcube::raise_error(array(
|
||||
'code' => 600, 'type' => 'php',
|
||||
'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error deleting a contact object $uid from the Kolab server"),
|
||||
true, false);
|
||||
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error deleting a contact object $uid from the Kolab server"
|
||||
),
|
||||
true, false
|
||||
);
|
||||
}
|
||||
else {
|
||||
// remove from distribution lists
|
||||
foreach ((array)$this->groupmembers[$id] as $gid) {
|
||||
if (!$is_mailto || $gid == $this->gid)
|
||||
foreach ((array) $this->groupmembers[$id] as $gid) {
|
||||
if (!$is_mailto || $gid == $this->gid) {
|
||||
$this->remove_from_group($gid, $id);
|
||||
}
|
||||
}
|
||||
|
||||
// clear internal cache
|
||||
|
@ -761,19 +793,19 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
return $count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Undelete one or more contact records.
|
||||
* Only possible just after delete (see 2nd argument of delete() method).
|
||||
*
|
||||
* @param array Record identifiers
|
||||
* @param array Record identifiers
|
||||
*
|
||||
* @return int Number of records restored
|
||||
*/
|
||||
public function undelete($ids)
|
||||
{
|
||||
if (!is_array($ids))
|
||||
if (!is_array($ids)) {
|
||||
$ids = explode(',', $ids);
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
foreach ($ids as $id) {
|
||||
|
@ -783,17 +815,17 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
}
|
||||
else {
|
||||
rcube::raise_error(array(
|
||||
'code' => 600, 'type' => 'php',
|
||||
'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error undeleting a contact object $uid from the Kolab server"),
|
||||
true, false);
|
||||
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error undeleting a contact object $uid from the Kolab server"
|
||||
),
|
||||
true, false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove all records from the database
|
||||
*
|
||||
|
@ -809,7 +841,6 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Close connection to source
|
||||
* Called on script shutdown
|
||||
|
@ -818,11 +849,11 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a contact group with the given name
|
||||
*
|
||||
* @param string The group name
|
||||
*
|
||||
* @return mixed False on error, array with record props in success
|
||||
*/
|
||||
function create_group($name)
|
||||
|
@ -838,10 +869,11 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
|
||||
if (!$saved) {
|
||||
rcube::raise_error(array(
|
||||
'code' => 600, 'type' => 'php',
|
||||
'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error saving distribution-list object to Kolab server"),
|
||||
true, false);
|
||||
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error saving distribution-list object to Kolab server"
|
||||
),
|
||||
true, false
|
||||
);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
|
@ -857,7 +889,8 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
* Delete the given group and all linked group members
|
||||
*
|
||||
* @param string Group identifier
|
||||
* @return boolean True on success, false if no data was changed
|
||||
*
|
||||
* @return bool True on success, false if no data was changed
|
||||
*/
|
||||
function delete_group($gid)
|
||||
{
|
||||
|
@ -870,10 +903,11 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
|
||||
if (!$deleted) {
|
||||
rcube::raise_error(array(
|
||||
'code' => 600, 'type' => 'php',
|
||||
'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error deleting distribution-list object from the Kolab server"),
|
||||
true, false);
|
||||
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error deleting distribution-list object from the Kolab server"
|
||||
),
|
||||
true, false
|
||||
);
|
||||
}
|
||||
else {
|
||||
$result = true;
|
||||
|
@ -889,7 +923,7 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
* @param string New name to set for this group
|
||||
* @param string New group identifier (if changed, otherwise don't set)
|
||||
*
|
||||
* @return boolean New name on success, false if no data was changed
|
||||
* @return bool New name on success, false if no data was changed
|
||||
*/
|
||||
function rename_group($gid, $newname, &$newid)
|
||||
{
|
||||
|
@ -903,10 +937,11 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
|
||||
if (!$saved) {
|
||||
rcube::raise_error(array(
|
||||
'code' => 600, 'type' => 'php',
|
||||
'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error saving distribution-list object to Kolab server"),
|
||||
true, false);
|
||||
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error saving distribution-list object to Kolab server"
|
||||
),
|
||||
true, false
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -916,9 +951,9 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
/**
|
||||
* Add the given contact records the a certain group
|
||||
*
|
||||
* @param string Group identifier
|
||||
* @param array List of contact identifiers to be added
|
||||
* @return int Number of contacts added
|
||||
* @param string Group identifier
|
||||
* @param array List of contact identifiers to be added
|
||||
* @return int Number of contacts added
|
||||
*/
|
||||
function add_to_group($gid, $ids)
|
||||
{
|
||||
|
@ -965,17 +1000,21 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
}
|
||||
}
|
||||
|
||||
if ($added)
|
||||
if ($added) {
|
||||
$saved = $this->storagefolder->save($list, 'distribution-list', $list['uid']);
|
||||
else
|
||||
}
|
||||
else {
|
||||
$saved = true;
|
||||
}
|
||||
|
||||
if (!$saved) {
|
||||
rcube::raise_error(array(
|
||||
'code' => 600, 'type' => 'php',
|
||||
'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error saving distribution-list to Kolab server"),
|
||||
true, false);
|
||||
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error saving distribution-list to Kolab server"
|
||||
),
|
||||
true, false
|
||||
);
|
||||
|
||||
$added = false;
|
||||
$this->set_error(self::ERROR_SAVING, 'errorsaving');
|
||||
}
|
||||
|
@ -989,23 +1028,26 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
/**
|
||||
* Remove the given contact records from a certain group
|
||||
*
|
||||
* @param string Group identifier
|
||||
* @param array List of contact identifiers to be removed
|
||||
* @return int Number of deleted group members
|
||||
* @param string Group identifier
|
||||
* @param array List of contact identifiers to be removed
|
||||
* @return int Number of deleted group members
|
||||
*/
|
||||
function remove_from_group($gid, $ids)
|
||||
{
|
||||
if (!is_array($ids))
|
||||
if (!is_array($ids)) {
|
||||
$ids = explode(',', $ids);
|
||||
}
|
||||
|
||||
$this->_fetch_groups();
|
||||
if (!($list = $this->distlists[$gid]))
|
||||
if (!($list = $this->distlists[$gid])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$new_member = array();
|
||||
foreach ((array)$list['member'] as $member) {
|
||||
if (!in_array($member['ID'], $ids))
|
||||
if (!in_array($member['ID'], $ids)) {
|
||||
$new_member[] = $member;
|
||||
}
|
||||
}
|
||||
|
||||
// write distribution list back to server
|
||||
|
@ -1014,10 +1056,11 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
|
||||
if (!$saved) {
|
||||
rcube::raise_error(array(
|
||||
'code' => 600, 'type' => 'php',
|
||||
'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error saving distribution-list object to Kolab server"),
|
||||
true, false);
|
||||
'code' => 600, 'file' => __FILE__, 'line' => __LINE__,
|
||||
'message' => "Error saving distribution-list object to Kolab server"
|
||||
),
|
||||
true, false
|
||||
);
|
||||
}
|
||||
else {
|
||||
// remove group assigments in local cache
|
||||
|
@ -1039,7 +1082,7 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
* @param array Associative array with contact data to save
|
||||
* @param bool Attempt to fix/complete data automatically
|
||||
*
|
||||
* @return boolean True if input is valid, False if not.
|
||||
* @return bool True if input is valid, False if not.
|
||||
*/
|
||||
public function validate(&$save_data, $autofix = false)
|
||||
{
|
||||
|
@ -1245,15 +1288,23 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
}
|
||||
|
||||
// photo is stored as separate attachment
|
||||
if ($record['photo'] && strlen($record['photo']) < 255 && ($att = $record['_attachments'][$record['photo']])) {
|
||||
if ($record['photo'] && strlen($record['photo']) < 255 && !empty($record['_attachments'][$record['photo']])) {
|
||||
$att = $record['_attachments'][$record['photo']];
|
||||
// only fetch photo content if requested
|
||||
if ($this->action == 'photo')
|
||||
$record['photo'] = $att['content'] ? $att['content'] : $this->storagefolder->get_attachment($record['uid'], $att['id']);
|
||||
if ($this->action == 'photo') {
|
||||
if (!empty($att['content'])) {
|
||||
$record['photo'] = $att['content'];
|
||||
}
|
||||
else {
|
||||
$record['photo'] = $this->storagefolder->get_attachment($record['uid'], $att['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// truncate publickey value for display
|
||||
if ($record['pgppublickey'] && $this->action == 'show')
|
||||
if (!empty($record['pgppublickey']) && $this->action == 'show') {
|
||||
$record['pgppublickey'] = substr($record['pgppublickey'], 0, 140) . '...';
|
||||
}
|
||||
|
||||
// remove empty fields
|
||||
$record = array_filter($record);
|
||||
|
@ -1269,10 +1320,12 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
*/
|
||||
private function _from_rcube_contact($contact, $old = array())
|
||||
{
|
||||
if (!$contact['uid'] && $contact['ID'])
|
||||
if (!$contact['uid'] && $contact['ID']) {
|
||||
$contact['uid'] = $this->id2uid($contact['ID']);
|
||||
else if (!$contact['uid'] && $old['uid'])
|
||||
}
|
||||
else if (!$contact['uid'] && $old['uid']) {
|
||||
$contact['uid'] = $old['uid'];
|
||||
}
|
||||
|
||||
$contact['im'] = array_filter($this->get_col_values('im', $contact, true));
|
||||
|
||||
|
@ -1295,8 +1348,9 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
foreach ((array)$values as $adr) {
|
||||
// skip empty address
|
||||
$adr = array_filter($adr);
|
||||
if (empty($adr))
|
||||
if (empty($adr)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$addresses[] = array(
|
||||
'type' => $type,
|
||||
|
@ -1318,8 +1372,9 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
|
||||
// copy meta data (starting with _) from old object
|
||||
foreach ((array)$old as $key => $val) {
|
||||
if (!isset($contact[$key]) && $key[0] == '_')
|
||||
if (!isset($contact[$key]) && $key[0] == '_') {
|
||||
$contact[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
// convert one-item-array elements into string element
|
||||
|
@ -1334,7 +1389,12 @@ class rcube_kolab_contacts extends rcube_addressbook
|
|||
unset($contact['vcard']);
|
||||
|
||||
// add empty values for some fields which can be removed in the UI
|
||||
return array_filter($contact) + array('nickname' => '', 'birthday' => '', 'anniversary' => '', 'freebusyurl' => '', 'photo' => $contact['photo']);
|
||||
return array_filter($contact) + array(
|
||||
'nickname' => '',
|
||||
'birthday' => '',
|
||||
'anniversary' => '',
|
||||
'freebusyurl' => '',
|
||||
'photo' => $contact['photo']
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -118,14 +118,15 @@ class libcalendaring_itip
|
|||
// compose a list of all event attendees
|
||||
$attendees_list = array();
|
||||
foreach ((array)$event['attendees'] as $attendee) {
|
||||
$attendees_list[] = ($attendee['name'] && $attendee['email']) ?
|
||||
$attendees_list[] = (!empty($attendee['name']) && !empty($attendee['email'])) ?
|
||||
$attendee['name'] . ' <' . $attendee['email'] . '>' :
|
||||
($attendee['name'] ? $attendee['name'] : $attendee['email']);
|
||||
(!empty($attendee['name']) ? $attendee['name'] : $attendee['email']);
|
||||
}
|
||||
|
||||
$recurrence_info = '';
|
||||
if (!empty($event['recurrence_id'])) {
|
||||
$recurrence_info = "\n\n** " . $this->gettext($event['thisandfuture'] ? 'itipmessagefutureoccurrence' : 'itipmessagesingleoccurrence') . ' **';
|
||||
$msg = $this->gettext(!empty($event['thisandfuture']) ? 'itipmessagefutureoccurrence' : 'itipmessagesingleoccurrence');
|
||||
$recurrence_info = "\n\n** $msg **";
|
||||
}
|
||||
else if (!empty($event['recurrence'])) {
|
||||
$recurrence_info = sprintf("\n%s: %s", $this->gettext('recurring'), $this->lib->recurrence_text($event['recurrence']));
|
||||
|
@ -139,7 +140,7 @@ class libcalendaring_itip
|
|||
'attendees' => join(",\n ", $attendees_list),
|
||||
'sender' => $this->sender['name'],
|
||||
'organizer' => $this->sender['name'],
|
||||
'description' => $event['description'],
|
||||
'description' => isset($event['description']) ? $event['description'] : '',
|
||||
)
|
||||
));
|
||||
|
||||
|
@ -243,8 +244,14 @@ class libcalendaring_itip
|
|||
// set RSVP for every attendee
|
||||
else if ($method == 'REQUEST') {
|
||||
foreach ($event['attendees'] as $i => $attendee) {
|
||||
if (($rsvp || !isset($attendee['rsvp'])) && ($attendee['status'] != 'DELEGATED' && $attendee['role'] != 'NON-PARTICIPANT')) {
|
||||
$event['attendees'][$i]['rsvp']= (bool)$rsvp;
|
||||
if (
|
||||
($rsvp || !isset($attendee['rsvp']))
|
||||
&& (
|
||||
(empty($attendee['status']) || $attendee['status'] != 'DELEGATED')
|
||||
&& $attendee['role'] != 'NON-PARTICIPANT'
|
||||
)
|
||||
) {
|
||||
$event['attendees'][$i]['rsvp']= (bool) $rsvp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -293,7 +300,7 @@ class libcalendaring_itip
|
|||
// attach ics file for this event
|
||||
$ical = libcalendaring::get_ical();
|
||||
$ics = $ical->export(array($event), $method, false, $method == 'REQUEST' && $this->plugin->driver ? array($this->plugin->driver, 'get_attachment_body') : false);
|
||||
$filename = $event['_type'] == 'task' ? 'todo.ics' : 'event.ics';
|
||||
$filename = !empty($event['_type']) && $event['_type'] == 'task' ? 'todo.ics' : 'event.ics';
|
||||
$message->addAttachment($ics, 'text/calendar', $filename, false, '8bit', '', RCUBE_CHARSET . "; method=" . $method);
|
||||
|
||||
return $message;
|
||||
|
@ -521,7 +528,7 @@ class libcalendaring_itip
|
|||
|
||||
protected function get_itip_diff($event, $existing)
|
||||
{
|
||||
if (empty($event) || empty($existing) || empty($event['message_uid'])) {
|
||||
if (empty($event) || empty($existing) || empty($event['message_uid']) || empty($event['mime_id'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -556,14 +563,14 @@ class libcalendaring_itip
|
|||
$attendee['status'] = 'ACCEPTED'; // sometimes is not set for exceptions
|
||||
$existing['attendees'][$idx] = $attendee;
|
||||
}
|
||||
$existing_attendees[] = $attendee['email'].$attendee['name'];
|
||||
$existing_attendees[] = $attendee['email'] . (isset($attendee['name']) ? $attendee['name'] : '');
|
||||
}
|
||||
foreach ((array) $itip['attendees'] as $idx => $attendee) {
|
||||
if ($attendee['email'] && ($_status = $status[strtolower($attendee['email'])])) {
|
||||
$attendee['status'] = $_status;
|
||||
if (!empty($attendee['email']) && !empty($status[strtolower($attendee['email'])])) {
|
||||
$attendee['status'] = $status[strtolower($attendee['email'])];
|
||||
$itip['attendees'][$idx] = $attendee;
|
||||
}
|
||||
$itip_attendees[] = $attendee['email'].$attendee['name'];
|
||||
$itip_attendees[] = $attendee['email'] . (isset($attendee['name']) ? $attendee['name'] : '');
|
||||
}
|
||||
|
||||
if ($itip_attendees != $existing_attendees) {
|
||||
|
@ -597,14 +604,16 @@ class libcalendaring_itip
|
|||
public function mail_itip_inline_ui($event, $method, $mime_id, $task, $message_date = null, $preview_url = null)
|
||||
{
|
||||
$buttons = array();
|
||||
$dom_id = asciiwords($event['uid'], true);
|
||||
$rsvp_status = 'unknown';
|
||||
$dom_id = asciiwords($event['uid'], true);
|
||||
|
||||
$rsvp_status = 'unknown';
|
||||
$rsvp_buttons = '';
|
||||
|
||||
// pass some metadata about the event and trigger the asynchronous status check
|
||||
$changed = is_object($event['changed']) ? $event['changed'] : $message_date;
|
||||
$metadata = array(
|
||||
'uid' => $event['uid'],
|
||||
'_instance' => $event['_instance'],
|
||||
'_instance' => isset($event['_instance']) ? $event['_instance'] : null,
|
||||
'changed' => $changed ? $changed->format('U') : 0,
|
||||
'sequence' => intval($event['sequence']),
|
||||
'method' => $method,
|
||||
|
@ -744,7 +753,7 @@ class libcalendaring_itip
|
|||
}
|
||||
|
||||
// add itip reply message controls
|
||||
$rsvp_buttons .= html::div('itip-reply-controls', $this->itip_rsvp_options_ui($dom_id, $metadata['nosave']));
|
||||
$rsvp_buttons .= html::div('itip-reply-controls', $this->itip_rsvp_options_ui($dom_id, !empty($metadata['nosave'])));
|
||||
|
||||
$buttons[] = html::div(array('id' => 'rsvp-'.$dom_id, 'class' => 'rsvp-buttons', 'style' => 'display:none'), $rsvp_buttons);
|
||||
$buttons[] = html::div(array('id' => 'update-'.$dom_id, 'style' => 'display:none'), $update_button);
|
||||
|
@ -759,8 +768,8 @@ class libcalendaring_itip
|
|||
$title = $this->gettext('itipcancellation');
|
||||
$event_prop = array_filter(array(
|
||||
'uid' => $event['uid'],
|
||||
'_instance' => $event['_instance'],
|
||||
'_savemode' => $event['_savemode'],
|
||||
'_instance' => isset($event['_instance']) ? $event['_instance'] : null,
|
||||
'_savemode' => isset($event['_savemode']) ? $event['_savemode'] : null,
|
||||
));
|
||||
|
||||
// 1. remove the event from our calendar
|
||||
|
@ -786,7 +795,7 @@ class libcalendaring_itip
|
|||
}
|
||||
|
||||
// append generic import button
|
||||
if ($import_button) {
|
||||
if (!empty($import_button)) {
|
||||
$buttons[] = html::div(array('id' => 'import-'.$dom_id, 'style' => 'display:none'), $import_button);
|
||||
}
|
||||
|
||||
|
@ -815,13 +824,16 @@ class libcalendaring_itip
|
|||
{
|
||||
$attrib += array('type' => 'button');
|
||||
|
||||
if (!$actions)
|
||||
if (!$actions) {
|
||||
$actions = $this->rsvp_actions;
|
||||
}
|
||||
|
||||
$buttons = '';
|
||||
|
||||
foreach ($actions as $method) {
|
||||
$buttons .= html::tag('input', array(
|
||||
'type' => $attrib['type'],
|
||||
'name' => $attrib['iname'],
|
||||
'name' => !empty($attrib['iname']) ? $attrib['iname'] : null,
|
||||
'class' => 'button',
|
||||
'rel' => $method,
|
||||
'value' => $this->gettext('itip' . $method),
|
||||
|
@ -923,7 +935,7 @@ class libcalendaring_itip
|
|||
$table->add('label', $this->gettext('recurring'));
|
||||
$table->add('recurrence', $this->lib->recurrence_text($event['recurrence']));
|
||||
}
|
||||
if ($location = trim($event['location'])) {
|
||||
if (isset($event['location']) && ($location = trim($event['location']))) {
|
||||
$table->add('label', $this->gettext('location'));
|
||||
$table->add('location', rcube::Q($location));
|
||||
}
|
||||
|
@ -931,11 +943,11 @@ class libcalendaring_itip
|
|||
$table->add('label', $this->gettext('sensitivity'));
|
||||
$table->add('sensitivity', ucfirst($this->gettext($sensitivity)) . '!');
|
||||
}
|
||||
if ($event['status'] == 'COMPLETED' || $event['status'] == 'CANCELLED') {
|
||||
if (!empty($event['status']) && ($event['status'] == 'COMPLETED' || $event['status'] == 'CANCELLED')) {
|
||||
$table->add('label', $this->gettext('status'));
|
||||
$table->add('status', $this->gettext('status-' . strtolower($event['status'])));
|
||||
}
|
||||
if ($comment = trim($event['comment'])) {
|
||||
if (isset($event['comment']) && ($comment = trim($event['comment']))) {
|
||||
$table->add('label', $this->gettext('comment'));
|
||||
$table->add('location', rcube::Q($comment));
|
||||
}
|
||||
|
|
|
@ -61,15 +61,15 @@ class libcalendaring_recurrence
|
|||
|
||||
$this->set_start($start);
|
||||
|
||||
if (is_array($recurrence['EXDATE'])) {
|
||||
foreach ($recurrence['EXDATE'] as $exdate) {
|
||||
if (!empty($recurrence['EXDATE'])) {
|
||||
foreach ((array) $recurrence['EXDATE'] as $exdate) {
|
||||
if (is_a($exdate, 'DateTime')) {
|
||||
$this->engine->addException($exdate->format('Y'), $exdate->format('n'), $exdate->format('j'));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_array($recurrence['RDATE'])) {
|
||||
foreach ($recurrence['RDATE'] as $rdate) {
|
||||
if (!empty($recurrence['RDATE'])) {
|
||||
foreach ((array) $recurrence['RDATE'] as $rdate) {
|
||||
if (is_a($rdate, 'DateTime')) {
|
||||
$this->engine->addRDate($rdate->format('Y'), $rdate->format('n'), $rdate->format('j'));
|
||||
}
|
||||
|
@ -160,9 +160,10 @@ class libcalendaring_recurrence
|
|||
$start = clone $this->start;
|
||||
$orig_start = clone $this->start;
|
||||
$r = $this->recurrence;
|
||||
$interval = intval($r['INTERVAL'] ?: 1);
|
||||
$interval = !empty($r['INTERVAL']) ? intval($r['INTERVAL']) : 1;
|
||||
$frequency = isset($this->recurrence['FREQ']) ? $this->recurrence['FREQ'] : null;
|
||||
|
||||
switch ($this->recurrence['FREQ']) {
|
||||
switch ($frequency) {
|
||||
case 'WEEKLY':
|
||||
if (empty($this->recurrence['BYDAY'])) {
|
||||
return $start;
|
||||
|
@ -193,7 +194,7 @@ class libcalendaring_recurrence
|
|||
|
||||
$r = $this->recurrence;
|
||||
$r['INTERVAL'] = $interval;
|
||||
if ($r['COUNT']) {
|
||||
if (!empty($r['COUNT'])) {
|
||||
// Increase count so we do not stop the loop to early
|
||||
$r['COUNT'] += 100;
|
||||
}
|
||||
|
|
|
@ -40,23 +40,23 @@ class libcalendaring extends rcube_plugin
|
|||
public $ical_message;
|
||||
|
||||
public $defaults = array(
|
||||
'calendar_date_format' => "Y-m-d",
|
||||
'calendar_date_short' => "M-j",
|
||||
'calendar_date_long' => "F j Y",
|
||||
'calendar_date_agenda' => "l M-d",
|
||||
'calendar_time_format' => "H:m",
|
||||
'calendar_first_day' => 1,
|
||||
'calendar_first_hour' => 6,
|
||||
'calendar_date_format_sets' => array(
|
||||
'Y-m-d' => array('d M Y', 'm-d', 'l m-d'),
|
||||
'Y/m/d' => array('d M Y', 'm/d', 'l m/d'),
|
||||
'Y.m.d' => array('d M Y', 'm.d', 'l m.d'),
|
||||
'd-m-Y' => array('d M Y', 'd-m', 'l d-m'),
|
||||
'd/m/Y' => array('d M Y', 'd/m', 'l d/m'),
|
||||
'd.m.Y' => array('d M Y', 'd.m', 'l d.m'),
|
||||
'j.n.Y' => array('d M Y', 'd.m', 'l d.m'),
|
||||
'm/d/Y' => array('M d Y', 'm/d', 'l m/d'),
|
||||
),
|
||||
'calendar_date_format' => "Y-m-d",
|
||||
'calendar_date_short' => "M-j",
|
||||
'calendar_date_long' => "F j Y",
|
||||
'calendar_date_agenda' => "l M-d",
|
||||
'calendar_time_format' => "H:m",
|
||||
'calendar_first_day' => 1,
|
||||
'calendar_first_hour' => 6,
|
||||
'calendar_date_format_sets' => array(
|
||||
'Y-m-d' => array('d M Y', 'm-d', 'l m-d'),
|
||||
'Y/m/d' => array('d M Y', 'm/d', 'l m/d'),
|
||||
'Y.m.d' => array('d M Y', 'm.d', 'l m.d'),
|
||||
'd-m-Y' => array('d M Y', 'd-m', 'l d-m'),
|
||||
'd/m/Y' => array('d M Y', 'd/m', 'l d/m'),
|
||||
'd.m.Y' => array('d M Y', 'd.m', 'l d.m'),
|
||||
'j.n.Y' => array('d M Y', 'd.m', 'l d.m'),
|
||||
'm/d/Y' => array('M d Y', 'm/d', 'l m/d'),
|
||||
),
|
||||
);
|
||||
|
||||
private static $instance;
|
||||
|
@ -187,19 +187,20 @@ class libcalendaring extends rcube_plugin
|
|||
*/
|
||||
public function adjust_timezone($dt, $dateonly = false)
|
||||
{
|
||||
if (is_numeric($dt))
|
||||
if (is_numeric($dt)) {
|
||||
$dt = new DateTime('@'.$dt);
|
||||
else if (is_string($dt))
|
||||
}
|
||||
else if (is_string($dt)) {
|
||||
$dt = rcube_utils::anytodatetime($dt);
|
||||
}
|
||||
|
||||
if ($dt instanceof DateTime && !($dt->_dateonly || $dateonly)) {
|
||||
if ($dt instanceof DateTime && empty($dt->_dateonly) && !$dateonly) {
|
||||
$dt->setTimezone($this->timezone);
|
||||
}
|
||||
|
||||
return $dt;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -289,11 +290,12 @@ class libcalendaring extends rcube_plugin
|
|||
*/
|
||||
public function event_date_text($event, $tzinfo = false)
|
||||
{
|
||||
$fromto = '--';
|
||||
$fromto = '--';
|
||||
$is_task = !empty($event['_type']) && $event['_type'] == 'task';
|
||||
|
||||
// handle task objects
|
||||
if ($event['_type'] == 'task' && is_object($event['due'])) {
|
||||
$date_format = $event['due']->_dateonly ? self::to_php_date_format($this->rc->config->get('calendar_date_format', $this->defaults['calendar_date_format'])) : null;
|
||||
if ($is_task && !empty($event['due']) && is_object($event['due'])) {
|
||||
$date_format = !empty($event['due']->_dateonly) ? self::to_php_date_format($this->rc->config->get('calendar_date_format', $this->defaults['calendar_date_format'])) : null;
|
||||
$fromto = $this->rc->format_date($event['due'], $date_format, false);
|
||||
|
||||
// add timezone information
|
||||
|
@ -351,18 +353,21 @@ class libcalendaring extends rcube_plugin
|
|||
$select_type = new html_select(array('name' => 'alarmtype[]', 'class' => 'edit-alarm-type form-control', 'id' => $attrib['id']));
|
||||
$select_offset = new html_select(array('name' => 'alarmoffset[]', 'class' => 'edit-alarm-offset form-control'));
|
||||
$select_related = new html_select(array('name' => 'alarmrelated[]', 'class' => 'edit-alarm-related form-control'));
|
||||
$object_type = $attrib['_type'] ?: 'event';
|
||||
$object_type = !empty($attrib['_type']) ? $attrib['_type'] : 'event';
|
||||
|
||||
$select_type->add($this->gettext('none'), '');
|
||||
foreach ($alarm_types as $type)
|
||||
foreach ($alarm_types as $type) {
|
||||
$select_type->add($this->gettext(strtolower("alarm{$type}option")), $type);
|
||||
}
|
||||
|
||||
foreach (array('-M','-H','-D','+M','+H','+D') as $trigger)
|
||||
foreach (array('-M','-H','-D','+M','+H','+D') as $trigger) {
|
||||
$select_offset->add($this->gettext('trigger' . $trigger), $trigger);
|
||||
}
|
||||
|
||||
$select_offset->add($this->gettext('trigger0'), '0');
|
||||
if ($absolute_time)
|
||||
if ($absolute_time) {
|
||||
$select_offset->add($this->gettext('trigger@'), '@');
|
||||
}
|
||||
|
||||
$select_related->add($this->gettext('relatedstart'), 'start');
|
||||
$select_related->add($this->gettext('relatedend' . $object_type), 'end');
|
||||
|
@ -399,7 +404,7 @@ class libcalendaring extends rcube_plugin
|
|||
}
|
||||
|
||||
// return cached result
|
||||
if (is_array($_emails[$user])) {
|
||||
if (isset($_emails[$user])) {
|
||||
return $_emails[$user];
|
||||
}
|
||||
|
||||
|
@ -802,12 +807,13 @@ class libcalendaring extends rcube_plugin
|
|||
return rcmail::get_instance()->format_date($dt, $format);
|
||||
};
|
||||
|
||||
if (is_array($rrule['EXDATE']) && !empty($rrule['EXDATE'])) {
|
||||
if (!empty($rrule['EXDATE']) && is_array($rrule['EXDATE'])) {
|
||||
$exdates = array_map($format_fn, $rrule['EXDATE']);
|
||||
}
|
||||
|
||||
if (empty($rrule['FREQ']) && !empty($rrule['RDATE'])) {
|
||||
$rdates = array_map($format_fn, $rrule['RDATE']);
|
||||
$more = false;
|
||||
|
||||
if (!empty($exdates)) {
|
||||
$rdates = array_diff($rdates, $exdates);
|
||||
|
@ -818,8 +824,7 @@ class libcalendaring extends rcube_plugin
|
|||
$more = true;
|
||||
}
|
||||
|
||||
return $this->gettext('ondate') . ' ' . join(', ', $rdates)
|
||||
. ($more ? '...' : '');
|
||||
return $this->gettext('ondate') . ' ' . join(', ', $rdates) . ($more ? '...' : '');
|
||||
}
|
||||
|
||||
$output = sprintf('%s %d ', $this->gettext('every'), $rrule['INTERVAL'] ?: 1);
|
||||
|
@ -839,10 +844,10 @@ class libcalendaring extends rcube_plugin
|
|||
break;
|
||||
}
|
||||
|
||||
if ($rrule['COUNT']) {
|
||||
if (!empty($rrule['COUNT'])) {
|
||||
$until = $this->gettext(array('name' => 'forntimes', 'vars' => array('nr' => $rrule['COUNT'])));
|
||||
}
|
||||
else if ($rrule['UNTIL']) {
|
||||
else if (!empty($rrule['UNTIL'])) {
|
||||
$until = $this->gettext('recurrencend') . ' ' . $this->rc->format_date($rrule['UNTIL'], $format);
|
||||
}
|
||||
else {
|
||||
|
@ -852,13 +857,13 @@ class libcalendaring extends rcube_plugin
|
|||
$output .= ', ' . $until;
|
||||
|
||||
if (!empty($exdates)) {
|
||||
$more = false;
|
||||
if (count($exdates) > $limit) {
|
||||
$exdates = array_slice($exdates, 0, $limit);
|
||||
$more = true;
|
||||
}
|
||||
|
||||
$output .= '; ' . $this->gettext('except') . ' ' . join(', ', $exdates)
|
||||
. ($more ? '...' : '');
|
||||
$output .= '; ' . $this->gettext('except') . ' ' . join(', ', $exdates) . ($more ? '...' : '');
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
@ -1056,16 +1061,16 @@ class libcalendaring extends rcube_plugin
|
|||
*/
|
||||
public function to_client_recurrence($recurrence, $allday = false)
|
||||
{
|
||||
if ($recurrence['UNTIL']) {
|
||||
if (!empty($recurrence['UNTIL'])) {
|
||||
$recurrence['UNTIL'] = $this->adjust_timezone($recurrence['UNTIL'], $allday)->format('c');
|
||||
}
|
||||
|
||||
// format RDATE values
|
||||
if (is_array($recurrence['RDATE'])) {
|
||||
if (!empty($recurrence['RDATE'])) {
|
||||
$libcal = $this;
|
||||
$recurrence['RDATE'] = array_map(function($rdate) use ($libcal) {
|
||||
return $libcal->adjust_timezone($rdate, true)->format('c');
|
||||
}, $recurrence['RDATE']);
|
||||
}, (array) $recurrence['RDATE']);
|
||||
}
|
||||
|
||||
unset($recurrence['EXCEPTIONS']);
|
||||
|
@ -1082,7 +1087,7 @@ class libcalendaring extends rcube_plugin
|
|||
$recurrence['UNTIL'] = new DateTime($recurrence['UNTIL'], $this->timezone);
|
||||
}
|
||||
|
||||
if (is_array($recurrence) && is_array($recurrence['RDATE'])) {
|
||||
if (is_array($recurrence) && !empty($recurrence['RDATE'])) {
|
||||
$tz = $this->timezone;
|
||||
$recurrence['RDATE'] = array_map(function($rdate) use ($tz, $start) {
|
||||
try {
|
||||
|
@ -1195,7 +1200,7 @@ class libcalendaring extends rcube_plugin
|
|||
$headers = $imap->get_message_headers($uid);
|
||||
$parser = $this->get_ical();
|
||||
|
||||
if ($part->ctype_parameters['charset']) {
|
||||
if (!empty($part->ctype_parameters['charset'])) {
|
||||
$charset = $part->ctype_parameters['charset'];
|
||||
}
|
||||
|
||||
|
@ -1238,8 +1243,9 @@ class libcalendaring extends rcube_plugin
|
|||
$level = explode('.', $part->mime_id);
|
||||
|
||||
while (array_pop($level) !== null) {
|
||||
$parent = $message->mime_parts[join('.', $level) ?: 0];
|
||||
if ($parent->mimetype == 'multipart/report') {
|
||||
$id = join('.', $level) ?: 0;
|
||||
$parent = !empty($message->mime_parts[$id]) ? $message->mime_parts[$id] : null;
|
||||
if ($parent && $parent->mimetype == 'multipart/report') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1248,7 +1254,7 @@ class libcalendaring extends rcube_plugin
|
|||
return (
|
||||
in_array($part->mimetype, array('text/calendar', 'text/x-vcalendar', 'application/ics')) ||
|
||||
// Apple sends files as application/x-any (!?)
|
||||
($part->mimetype == 'application/x-any' && $part->filename && preg_match('/\.ics$/i', $part->filename))
|
||||
($part->mimetype == 'application/x-any' && !empty($part->filename) && preg_match('/\.ics$/i', $part->filename))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1288,7 +1294,7 @@ class libcalendaring extends rcube_plugin
|
|||
*/
|
||||
public static function recurrence_id_format($event)
|
||||
{
|
||||
return $event['allday'] ? 'Ymd' : 'Ymd\THis';
|
||||
return !empty($event['allday']) ? 'Ymd' : 'Ymd\THis';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1301,13 +1307,13 @@ class libcalendaring extends rcube_plugin
|
|||
*/
|
||||
public static function recurrence_instance_identifier($event, $allday = null)
|
||||
{
|
||||
$instance_date = $event['recurrence_date'] ?: $event['start'];
|
||||
$instance_date = !empty($event['recurrence_date']) ? $event['recurrence_date'] : $event['start'];
|
||||
|
||||
if ($instance_date && is_a($instance_date, 'DateTime')) {
|
||||
if ($instance_date instanceof DateTime) {
|
||||
// According to RFC5545 (3.8.4.4) RECURRENCE-ID format should
|
||||
// be date/date-time depending on the main event type, not the exception
|
||||
if ($allday === null) {
|
||||
$allday = $event['allday'];
|
||||
$allday = !empty($event['allday']);
|
||||
}
|
||||
|
||||
return $instance_date->format($allday ? 'Ymd' : 'Ymd\THis');
|
||||
|
@ -1547,5 +1553,4 @@ class libcalendaring extends rcube_plugin
|
|||
'c' => '',
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -577,7 +577,7 @@ class libvcalendar implements Iterator
|
|||
$schedule_agent = $attendee['schedule-agent'];
|
||||
}
|
||||
}
|
||||
else if ($attendee['email'] != $event['organizer']['email']) {
|
||||
else if (empty($event['organizer']) || $attendee['email'] != $event['organizer']['email']) {
|
||||
$event['attendees'][] = $attendee;
|
||||
}
|
||||
break;
|
||||
|
@ -756,7 +756,7 @@ class libvcalendar implements Iterator
|
|||
}
|
||||
|
||||
// For date-only we'll keep the date and time intact
|
||||
if ($date->_dateonly) {
|
||||
if (!empty($date->_dateonly)) {
|
||||
$dt = new DateTime(null, $this->timezone);
|
||||
$dt->setDate($date->format('Y'), $date->format('n'), $date->format('j'));
|
||||
$dt->setTime($date->format('G'), $date->format('i'), 0);
|
||||
|
|
|
@ -48,7 +48,7 @@ class kolab_attachments_handler
|
|||
*/
|
||||
public function files_list($attrib = array())
|
||||
{
|
||||
if (!$attrib['id']) {
|
||||
if (empty($attrib['id'])) {
|
||||
$attrib['id'] = 'kolabattachmentlist';
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ class kolab_attachments_handler
|
|||
public function files_form($attrib = array())
|
||||
{
|
||||
// add ID if not given
|
||||
if (!$attrib['id']) {
|
||||
if (empty($attrib['id'])) {
|
||||
$attrib['id'] = 'kolabuploadform';
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ class kolab_attachments_handler
|
|||
public function files_drop_area($attrib = array())
|
||||
{
|
||||
// add ID if not given
|
||||
if (!$attrib['id']) {
|
||||
if (empty($attrib['id'])) {
|
||||
$attrib['id'] = 'kolabfiledroparea';
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ class kolab_attachments_handler
|
|||
$recid = $id_prefix . rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC);
|
||||
$uploadid = rcube_utils::get_input_value('_uploadid', rcube_utils::INPUT_GPC);
|
||||
|
||||
if (!is_array($_SESSION[$session_key]) || $_SESSION[$session_key]['id'] != $recid) {
|
||||
if (empty($_SESSION[$session_key]) || $_SESSION[$session_key]['id'] != $recid) {
|
||||
$_SESSION[$session_key] = array();
|
||||
$_SESSION[$session_key]['id'] = $recid;
|
||||
$_SESSION[$session_key]['attachments'] = array();
|
||||
|
@ -151,13 +151,16 @@ class kolab_attachments_handler
|
|||
unset($attachment['status'], $attachment['abort']);
|
||||
$this->rc->session->append($session_key . '.attachments', $id, $attachment);
|
||||
|
||||
if (($icon = $_SESSION[$session_key . '_deleteicon']) && is_file($icon)) {
|
||||
if (!empty($_SESSION[$session_key . '_deleteicon'])
|
||||
&& ($icon = $_SESSION[$session_key . '_deleteicon'])
|
||||
&& is_file($icon)
|
||||
) {
|
||||
$button = html::img(array(
|
||||
'src' => $icon,
|
||||
'alt' => $this->rc->gettext('delete')
|
||||
));
|
||||
}
|
||||
else if ($_SESSION[$session_key . '_textbuttons']) {
|
||||
else if (!empty($_SESSION[$session_key . '_textbuttons'])) {
|
||||
$button = rcube::Q($this->rc->gettext('delete'));
|
||||
}
|
||||
else {
|
||||
|
@ -181,7 +184,8 @@ class kolab_attachments_handler
|
|||
'onclick' => 'return false', // sprintf("return %s.command('load-attachment','rcmfile%s', this, event)", rcmail_output::JS_OBJECT_NAME, $id),
|
||||
), $link_content);
|
||||
|
||||
$content .= $_SESSION[$session_key . '_icon_pos'] == 'left' ? $delete_link.$content_link : $content_link.$delete_link;
|
||||
$left = !empty($_SESSION[$session_key . '_icon_pos']) && $_SESSION[$session_key . '_icon_pos'] == 'left';
|
||||
$content = $left ? $delete_link.$content_link : $content_link.$delete_link;
|
||||
|
||||
$this->rc->output->command('add2attachment_list', "rcmfile$id", array(
|
||||
'html' => $content,
|
||||
|
@ -196,7 +200,7 @@ class kolab_attachments_handler
|
|||
$msg = $this->rc->gettext(array('name' => 'filesizeerror', 'vars' => array(
|
||||
'size' => $this->rc->show_bytes(parse_bytes(ini_get('upload_max_filesize'))))));
|
||||
}
|
||||
else if ($attachment['error']) {
|
||||
else if (!empty($attachment['error'])) {
|
||||
$msg = $attachment['error'];
|
||||
}
|
||||
else {
|
||||
|
@ -211,11 +215,13 @@ class kolab_attachments_handler
|
|||
else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
// if filesize exceeds post_max_size then $_FILES array is empty,
|
||||
// show filesizeerror instead of fileuploaderror
|
||||
if ($maxsize = ini_get('post_max_size'))
|
||||
if ($maxsize = ini_get('post_max_size')) {
|
||||
$msg = $this->rc->gettext(array('name' => 'filesizeerror', 'vars' => array(
|
||||
'size' => $this->rc->show_bytes(parse_bytes($maxsize)))));
|
||||
else
|
||||
}
|
||||
else {
|
||||
$msg = $this->rc->gettext('fileuploaderror');
|
||||
}
|
||||
|
||||
$this->rc->output->command('display_message', $msg, 'error');
|
||||
$this->rc->output->command('remove_from_attachment_list', $uploadid);
|
||||
|
@ -233,7 +239,7 @@ class kolab_attachments_handler
|
|||
{
|
||||
ob_end_clean();
|
||||
|
||||
if ($attachment && $attachment['body']) {
|
||||
if ($attachment && !empty($attachment['body'])) {
|
||||
// allow post-processing of the attachment body
|
||||
$part = new rcube_message_part;
|
||||
$part->filename = $attachment['name'];
|
||||
|
|
|
@ -93,5 +93,4 @@ class kolab_bonnie_api
|
|||
{
|
||||
return $this->client->execute($method, $params);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -235,5 +235,4 @@ class kolab_bonnie_api_client
|
|||
|
||||
rcube::write_log('bonnie', join(";\n", $msg));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,5 +151,4 @@ class kolab_format_task extends kolab_format_xcal
|
|||
|
||||
return array_unique($tags);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -150,5 +150,4 @@ class kolab_storage_dataset implements Iterator, ArrayAccess, Countable
|
|||
{
|
||||
return !empty($this->index[$this->iteratorkey]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -93,7 +93,15 @@ class libkolab extends rcube_plugin
|
|||
*/
|
||||
function storage_init($p)
|
||||
{
|
||||
$p['fetch_headers'] = trim($p['fetch_headers'] .' X-KOLAB-TYPE X-KOLAB-MIME-VERSION MESSAGE-ID');
|
||||
$kolab_headers = 'X-KOLAB-TYPE X-KOLAB-MIME-VERSION MESSAGE-ID';
|
||||
|
||||
if (!empty($p['fetch_headers'])) {
|
||||
$p['fetch_headers'] .= ' ' . $kolab_headers;
|
||||
}
|
||||
else {
|
||||
$p['fetch_headers'] = $kolab_headers;
|
||||
}
|
||||
|
||||
return $p;
|
||||
}
|
||||
|
||||
|
|
|
@ -118,8 +118,8 @@ class tasklist_database_driver extends tasklist_driver
|
|||
. " VALUES (?, ?, ?, ?)",
|
||||
$this->rc->user->ID,
|
||||
strval($prop['name']),
|
||||
strval($prop['color']),
|
||||
$prop['showalarms'] ? 1 : 0
|
||||
isset($prop['color']) ? strval($prop['color']) : '',
|
||||
!empty($prop['showalarms']) ? 1 : 0
|
||||
);
|
||||
|
||||
if ($result) {
|
||||
|
@ -143,8 +143,8 @@ class tasklist_database_driver extends tasklist_driver
|
|||
"UPDATE " . $this->db_lists . " SET `name` = ?, `color` = ?, `showalarms` = ?"
|
||||
. " WHERE `tasklist_id` = ? AND `user_id` = ?",
|
||||
strval($prop['name']),
|
||||
strval($prop['color']),
|
||||
$prop['showalarms'] ? 1 : 0,
|
||||
isset($prop['color']) ? strval($prop['color']) : '',
|
||||
!empty($prop['showalarms']) ? 1 : 0,
|
||||
$prop['id'],
|
||||
$this->rc->user->ID
|
||||
);
|
||||
|
@ -163,7 +163,7 @@ class tasklist_database_driver extends tasklist_driver
|
|||
{
|
||||
$hidden = array_flip(explode(',', $this->rc->config->get('hidden_tasklists', '')));
|
||||
|
||||
if ($prop['active']) {
|
||||
if (!empty($prop['active'])) {
|
||||
unset($hidden[$prop['id']]);
|
||||
}
|
||||
else {
|
||||
|
@ -291,56 +291,53 @@ class tasklist_database_driver extends tasklist_driver
|
|||
$sql_add = '';
|
||||
|
||||
// add filter criteria
|
||||
if ($filter['from'] || ($filter['mask'] & tasklist::FILTER_MASK_TODAY)) {
|
||||
$sql_add .= " AND (`date` IS NULL OR `date` >= ?)";
|
||||
$datefrom = $filter['from'];
|
||||
}
|
||||
if ($filter['to']) {
|
||||
if ($filter['mask'] & tasklist::FILTER_MASK_OVERDUE) {
|
||||
$sql_add .= " AND (`date` IS NOT NULL AND `date` <= " . $this->rc->db->quote($filter['to']) . ")";
|
||||
if ($filter) {
|
||||
if (!empty($filter['from']) || ($filter['mask'] & tasklist::FILTER_MASK_TODAY)) {
|
||||
$sql_add .= " AND (`date` IS NULL OR `date` >= " . $this->rc->db->quote($filter['from']) . ")";
|
||||
}
|
||||
else {
|
||||
$sql_add .= " AND (`date` IS NULL OR `date` <= " . $this->rc->db->quote($filter['to']) . ")";
|
||||
|
||||
if (!empty($filter['to'])) {
|
||||
if ($filter['mask'] & tasklist::FILTER_MASK_OVERDUE) {
|
||||
$sql_add .= " AND (`date` IS NOT NULL AND `date` <= " . $this->rc->db->quote($filter['to']) . ")";
|
||||
}
|
||||
else {
|
||||
$sql_add .= " AND (`date` IS NULL OR `date` <= " . $this->rc->db->quote($filter['to']) . ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// special case 'today': also show all events with date before today
|
||||
if ($filter['mask'] & tasklist::FILTER_MASK_TODAY) {
|
||||
$datefrom = date('Y-m-d', 0);
|
||||
}
|
||||
|
||||
if ($filter['mask'] & tasklist::FILTER_MASK_NODATE) {
|
||||
$sql_add = " AND `date` IS NULL";
|
||||
}
|
||||
|
||||
if ($filter['mask'] & tasklist::FILTER_MASK_COMPLETE) {
|
||||
$sql_add .= " AND " . self::IS_COMPLETE_SQL;
|
||||
}
|
||||
else if (empty($filter['since'])) {
|
||||
// don't show complete tasks by default
|
||||
$sql_add .= " AND NOT " . self::IS_COMPLETE_SQL;
|
||||
}
|
||||
|
||||
if ($filter['mask'] & tasklist::FILTER_MASK_FLAGGED) {
|
||||
$sql_add .= " AND `flagged` = 1";
|
||||
}
|
||||
|
||||
// compose (slow) SQL query for searching
|
||||
// FIXME: improve searching using a dedicated col and normalized values
|
||||
if ($filter['search']) {
|
||||
$sql_query = array();
|
||||
foreach (array('title', 'description', 'organizer', 'attendees') as $col) {
|
||||
$sql_query[] = $this->rc->db->ilike($col, '%' . $filter['search'] . '%');
|
||||
if ($filter['mask'] & tasklist::FILTER_MASK_NODATE) {
|
||||
$sql_add = " AND `date` IS NULL";
|
||||
}
|
||||
$sql_add = " AND (" . join(" OR ", $sql_query) . ")";
|
||||
}
|
||||
|
||||
if ($filter['since'] && is_numeric($filter['since'])) {
|
||||
$sql_add .= " AND `changed` >= " . $this->rc->db->quote(date('Y-m-d H:i:s', $filter['since']));
|
||||
}
|
||||
if ($filter['mask'] & tasklist::FILTER_MASK_COMPLETE) {
|
||||
$sql_add .= " AND " . self::IS_COMPLETE_SQL;
|
||||
}
|
||||
else if (empty($filter['since'])) {
|
||||
// don't show complete tasks by default
|
||||
$sql_add .= " AND NOT " . self::IS_COMPLETE_SQL;
|
||||
}
|
||||
|
||||
if ($filter['uid']) {
|
||||
$sql_add .= " AND `uid` IN (" . implode(',', array_map(array($this->rc->db, 'quote'), $filter['uid'])) . ")";
|
||||
if ($filter['mask'] & tasklist::FILTER_MASK_FLAGGED) {
|
||||
$sql_add .= " AND `flagged` = 1";
|
||||
}
|
||||
|
||||
// compose (slow) SQL query for searching
|
||||
// FIXME: improve searching using a dedicated col and normalized values
|
||||
if ($filter['search']) {
|
||||
$sql_query = array();
|
||||
foreach (array('title', 'description', 'organizer', 'attendees') as $col) {
|
||||
$sql_query[] = $this->rc->db->ilike($col, '%' . $filter['search'] . '%');
|
||||
}
|
||||
$sql_add = " AND (" . join(" OR ", $sql_query) . ")";
|
||||
}
|
||||
|
||||
if (!empty($filter['since']) && is_numeric($filter['since'])) {
|
||||
$sql_add .= " AND `changed` >= " . $this->rc->db->quote(date('Y-m-d H:i:s', $filter['since']));
|
||||
}
|
||||
|
||||
if (!empty($filter['uid'])) {
|
||||
$sql_add .= " AND `uid` IN (" . implode(',', array_map(array($this->rc->db, 'quote'), $filter['uid'])) . ")";
|
||||
}
|
||||
}
|
||||
|
||||
$tasks = array();
|
||||
|
@ -348,8 +345,7 @@ class tasklist_database_driver extends tasklist_driver
|
|||
$result = $this->rc->db->query("SELECT * FROM " . $this->db_tasks
|
||||
. " WHERE `tasklist_id` IN (" . join(',', $list_ids) . ")"
|
||||
. " AND `del` = 0" . $sql_add
|
||||
. " ORDER BY `parent_id`, `task_id` ASC",
|
||||
$datefrom
|
||||
. " ORDER BY `parent_id`, `task_id` ASC"
|
||||
);
|
||||
|
||||
while ($result && ($rec = $this->rc->db->fetch_assoc($result))) {
|
||||
|
@ -375,12 +371,12 @@ class tasklist_database_driver extends tasklist_driver
|
|||
$prop['uid'] = $prop;
|
||||
}
|
||||
|
||||
$query_col = $prop['id'] ? 'task_id' : 'uid';
|
||||
$query_col = !empty($prop['id']) ? 'task_id' : 'uid';
|
||||
|
||||
$result = $this->rc->db->query("SELECT * FROM " . $this->db_tasks
|
||||
. " WHERE `tasklist_id` IN (" . $this->list_ids . ")"
|
||||
. " AND `$query_col` = ? AND `del` = 0",
|
||||
$prop['id'] ? $prop['id'] : $prop['uid']
|
||||
!empty($prop['id']) ? $prop['id'] : $prop['uid']
|
||||
);
|
||||
|
||||
if ($result && ($rec = $this->rc->db->fetch_assoc($result))) {
|
||||
|
@ -557,15 +553,15 @@ class tasklist_database_driver extends tasklist_driver
|
|||
public function create_task($prop)
|
||||
{
|
||||
// check list permissions
|
||||
$list_id = $prop['list'] ? $prop['list'] : reset(array_keys($this->lists));
|
||||
if (!$this->lists[$list_id] || $this->lists[$list_id]['readonly']) {
|
||||
$list_id = !empty($prop['list']) ? $prop['list'] : reset(array_keys($this->lists));
|
||||
if (empty($this->lists[$list_id]) || !empty($this->lists[$list_id]['readonly'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_array($prop['valarms'])) {
|
||||
if (!empty($prop['valarms'])) {
|
||||
$prop['alarms'] = $this->serialize_alarms($prop['valarms']);
|
||||
}
|
||||
if (is_array($prop['recurrence'])) {
|
||||
if (!empty($prop['recurrence'])) {
|
||||
$prop['recurrence'] = $this->serialize_recurrence($prop['recurrence']);
|
||||
}
|
||||
if (array_key_exists('complete', $prop)) {
|
||||
|
@ -594,13 +590,13 @@ class tasklist_database_driver extends tasklist_driver
|
|||
$prop['time'],
|
||||
$prop['startdate'],
|
||||
$prop['starttime'],
|
||||
strval($prop['description']),
|
||||
join(',', (array)$prop['tags']),
|
||||
$prop['flagged'] ? 1 : 0,
|
||||
$prop['complete'] ?: 0,
|
||||
isset($prop['description']) ? strval($prop['description']) : '',
|
||||
!empty($prop['tags']) ? join(',', (array)$prop['tags']) : '',
|
||||
!empty($prop['flagged']) ? 1 : 0,
|
||||
!empty($prop['complete']) ?: 0,
|
||||
strval($prop['status']),
|
||||
$prop['alarms'],
|
||||
$prop['recurrence'],
|
||||
isset($prop['alarms']) ? $prop['alarms'] : '',
|
||||
isset($prop['recurrence']) ? $prop['recurrence'] : '',
|
||||
$notify_at
|
||||
);
|
||||
|
||||
|
@ -621,10 +617,10 @@ class tasklist_database_driver extends tasklist_driver
|
|||
*/
|
||||
public function edit_task($prop)
|
||||
{
|
||||
if (is_array($prop['valarms'])) {
|
||||
if (isset($prop['valarms'])) {
|
||||
$prop['alarms'] = $this->serialize_alarms($prop['valarms']);
|
||||
}
|
||||
if (is_array($prop['recurrence'])) {
|
||||
if (isset($prop['recurrence'])) {
|
||||
$prop['recurrence'] = $this->serialize_recurrence($prop['recurrence']);
|
||||
}
|
||||
if (array_key_exists('complete', $prop)) {
|
||||
|
@ -655,7 +651,7 @@ class tasklist_database_driver extends tasklist_driver
|
|||
}
|
||||
|
||||
// moved from another list
|
||||
if ($prop['_fromlist'] && ($newlist = $prop['list'])) {
|
||||
if (!empty($prop['_fromlist']) && ($newlist = $prop['list'])) {
|
||||
$sql_set[] = $this->rc->db->quote_identifier('tasklist_id') . '=' . $this->rc->db->quote($newlist);
|
||||
}
|
||||
|
||||
|
@ -735,10 +731,10 @@ class tasklist_database_driver extends tasklist_driver
|
|||
*/
|
||||
private function _get_notification($task)
|
||||
{
|
||||
if ($task['valarms'] && !$this->is_complete($task)) {
|
||||
if (!empty($task['valarms']) && !$this->is_complete($task)) {
|
||||
$alarm = libcalendaring::get_next_alarm($task, 'task');
|
||||
|
||||
if ($alarm['time'] && in_array($alarm['action'], $this->alarm_types)) {
|
||||
if (!empty($alarm['time']) && in_array($alarm['action'], $this->alarm_types)) {
|
||||
return date('Y-m-d H:i:s', $alarm['time']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,7 @@ class tasklist extends rcube_plugin
|
|||
|
||||
private $collapsed_tasks = array();
|
||||
private $message_tasks = array();
|
||||
private $task_titles = array();
|
||||
|
||||
|
||||
/**
|
||||
|
@ -139,7 +140,7 @@ class tasklist extends rcube_plugin
|
|||
}
|
||||
|
||||
// add 'Create event' item to message menu
|
||||
if ($this->api->output->type == 'html' && $_GET['_rel'] != 'task') {
|
||||
if ($this->api->output->type == 'html' && (empty($_GET['_rel']) || $_GET['_rel'] != 'task')) {
|
||||
$this->api->add_content(html::tag('li', array('role' => 'menuitem'),
|
||||
$this->api->output->button(array(
|
||||
'command' => 'tasklist-create-from-mail',
|
||||
|
@ -155,7 +156,7 @@ class tasklist extends rcube_plugin
|
|||
}
|
||||
}
|
||||
|
||||
if (!$this->rc->output->ajax_call && !$this->rc->output->env['framed']) {
|
||||
if (!$this->rc->output->ajax_call && empty($this->rc->output->env['framed'])) {
|
||||
$this->load_ui();
|
||||
$this->ui->init();
|
||||
}
|
||||
|
@ -181,7 +182,7 @@ class tasklist extends rcube_plugin
|
|||
*/
|
||||
private function load_driver()
|
||||
{
|
||||
if (is_object($this->driver)) {
|
||||
if (!empty($this->driver)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -209,15 +210,16 @@ class tasklist extends rcube_plugin
|
|||
|
||||
// force notify if hidden + active
|
||||
$itip_send_option = (int)$this->rc->config->get('calendar_itip_send_option', 3);
|
||||
if ($itip_send_option === 1 && empty($rec['_reportpartstat']))
|
||||
if ($itip_send_option === 1 && empty($rec['_reportpartstat'])) {
|
||||
$rec['_notify'] = 1;
|
||||
}
|
||||
|
||||
switch ($action) {
|
||||
case 'new':
|
||||
$oldrec = null;
|
||||
$rec = $this->prepare_task($rec);
|
||||
$rec['uid'] = $this->generate_uid();
|
||||
$temp_id = $rec['tempid'];
|
||||
$temp_id = !empty($rec['tempid']) ? $rec['tempid'] : null;
|
||||
if ($success = $this->driver->create_task($rec)) {
|
||||
$refresh = $this->driver->get_task($rec);
|
||||
if ($temp_id) $refresh['tempid'] = $temp_id;
|
||||
|
@ -514,7 +516,7 @@ class tasklist extends rcube_plugin
|
|||
}
|
||||
|
||||
// send out notifications
|
||||
if ($success && $rec['_notify'] && ($rec['attendees'] || $oldrec['attendees'])) {
|
||||
if ($success && !empty($rec['_notify']) && ($rec['attendees'] || $oldrec['attendees'])) {
|
||||
// make sure we have the complete record
|
||||
$task = $action == 'delete' ? $oldrec : $this->driver->get_task($rec);
|
||||
|
||||
|
@ -528,7 +530,7 @@ class tasklist extends rcube_plugin
|
|||
}
|
||||
}
|
||||
|
||||
if ($success && $rec['_reportpartstat'] && $rec['_reportpartstat'] != 'NEEDS-ACTION') {
|
||||
if ($success && !empty($rec['_reportpartstat']) && $rec['_reportpartstat'] != 'NEEDS-ACTION') {
|
||||
// get the full record after update
|
||||
if (!$task) {
|
||||
$task = $this->driver->get_task($rec);
|
||||
|
@ -556,7 +558,7 @@ class tasklist extends rcube_plugin
|
|||
$this->rc->output->command('plugin.unlock_saving', $success);
|
||||
|
||||
if ($refresh) {
|
||||
if ($refresh['id']) {
|
||||
if (!empty($refresh['id'])) {
|
||||
$this->encode_task($refresh);
|
||||
}
|
||||
else if (is_array($refresh)) {
|
||||
|
@ -575,8 +577,8 @@ class tasklist extends rcube_plugin
|
|||
*/
|
||||
private function load_itip()
|
||||
{
|
||||
if (!$this->itip) {
|
||||
require_once realpath(__DIR__ . '/../libcalendaring/lib/libcalendaring_itip.php');
|
||||
if (empty($this->itip)) {
|
||||
require_once __DIR__ . '/../libcalendaring/lib/libcalendaring_itip.php';
|
||||
$this->itip = new libcalendaring_itip($this, 'tasklist');
|
||||
$this->itip->set_rsvp_actions(array('accepted','declined','delegated'));
|
||||
$this->itip->set_rsvp_status(array('accepted','tentative','declined','delegated','in-process','completed'));
|
||||
|
@ -591,7 +593,7 @@ class tasklist extends rcube_plugin
|
|||
private function prepare_task($rec)
|
||||
{
|
||||
// try to be smart and extract date from raw input
|
||||
if ($rec['raw']) {
|
||||
if (!empty($rec['raw'])) {
|
||||
foreach (array('today','tomorrow','sunday','monday','tuesday','wednesday','thursday','friday','saturday','sun','mon','tue','wed','thu','fri','sat') as $word) {
|
||||
$locwords[] = '/^' . preg_quote(mb_strtolower($this->gettext($word))) . '\b/i';
|
||||
$normwords[] = $word;
|
||||
|
@ -675,7 +677,7 @@ class tasklist extends rcube_plugin
|
|||
}
|
||||
|
||||
// convert the submitted alarm values
|
||||
if ($rec['valarms']) {
|
||||
if (!empty($rec['valarms'])) {
|
||||
$valarms = array();
|
||||
foreach (libcalendaring::from_client_alarms($rec['valarms']) as $alarm) {
|
||||
// alarms can only work with a date (either task start, due or absolute alarm date)
|
||||
|
@ -701,7 +703,7 @@ class tasklist extends rcube_plugin
|
|||
// translate count into an absolute end date.
|
||||
// why? because when shifting completed tasks to the next recurrence,
|
||||
// the initial start date to count from gets lost.
|
||||
if ($rec['recurrence']['COUNT']) {
|
||||
if (!empty($rec['recurrence']['COUNT'])) {
|
||||
$engine = libcalendaring::get_recurrence();
|
||||
$engine->init($rec['recurrence'], $refdate);
|
||||
if ($until = $engine->end()) {
|
||||
|
@ -717,7 +719,7 @@ class tasklist extends rcube_plugin
|
|||
|
||||
$attachments = array();
|
||||
$taskid = $rec['id'];
|
||||
if (is_array($_SESSION[self::SESSION_KEY]) && $_SESSION[self::SESSION_KEY]['id'] == $taskid) {
|
||||
if (!empty($_SESSION[self::SESSION_KEY]) && $_SESSION[self::SESSION_KEY]['id'] == $taskid) {
|
||||
if (!empty($_SESSION[self::SESSION_KEY]['attachments'])) {
|
||||
foreach ($_SESSION[self::SESSION_KEY]['attachments'] as $id => $attachment) {
|
||||
if (is_array($rec['attachments']) && in_array($id, $rec['attachments'])) {
|
||||
|
@ -736,12 +738,15 @@ class tasklist extends rcube_plugin
|
|||
}
|
||||
|
||||
// convert invalid data
|
||||
if (isset($rec['attendees']) && !is_array($rec['attendees']))
|
||||
if (isset($rec['attendees']) && !is_array($rec['attendees'])) {
|
||||
$rec['attendees'] = array();
|
||||
}
|
||||
|
||||
foreach ((array)$rec['attendees'] as $i => $attendee) {
|
||||
if (is_string($attendee['rsvp'])) {
|
||||
$rec['attendees'][$i]['rsvp'] = $attendee['rsvp'] == 'true' || $attendee['rsvp'] == '1';
|
||||
if (!empty($rec['attendees'])) {
|
||||
foreach ((array) $rec['attendees'] as $i => $attendee) {
|
||||
if (is_string($attendee['rsvp'])) {
|
||||
$rec['attendees'][$i]['rsvp'] = $attendee['rsvp'] == 'true' || $attendee['rsvp'] == '1';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1000,7 +1005,7 @@ class tasklist extends rcube_plugin
|
|||
$list += array('showalarms' => true, 'active' => true, 'editable' => true);
|
||||
if ($insert_id = $this->driver->create_list($list)) {
|
||||
$list['id'] = $insert_id;
|
||||
if (!$list['_reload']) {
|
||||
if (empty($list['_reload'])) {
|
||||
$this->load_ui();
|
||||
$list['html'] = $this->ui->tasklist_list_item($insert_id, $list, $jsenv);
|
||||
$list += (array)$jsenv[$insert_id];
|
||||
|
@ -1048,7 +1053,7 @@ class tasklist extends rcube_plugin
|
|||
$results[] = $prop;
|
||||
}
|
||||
// report more results available
|
||||
if ($this->driver->search_more_results) {
|
||||
if (!empty($this->driver->search_more_results)) {
|
||||
$this->rc->output->show_message('autocompletemore', 'notice');
|
||||
}
|
||||
|
||||
|
@ -1056,10 +1061,12 @@ class tasklist extends rcube_plugin
|
|||
return;
|
||||
}
|
||||
|
||||
if ($success)
|
||||
if ($success) {
|
||||
$this->rc->output->show_message('successfullysaved', 'confirmation');
|
||||
else
|
||||
}
|
||||
else {
|
||||
$this->rc->output->show_message('tasklist.errorsaving', 'error');
|
||||
}
|
||||
|
||||
$this->rc->output->command('plugin.unlock_saving');
|
||||
}
|
||||
|
@ -1074,8 +1081,9 @@ class tasklist extends rcube_plugin
|
|||
}
|
||||
else {
|
||||
foreach ($this->driver->get_lists() as $list) {
|
||||
if ($list['active'])
|
||||
if (!empty($list['active'])) {
|
||||
$lists[] = $list['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$counts = $this->driver->count_tasks($lists);
|
||||
|
@ -1161,7 +1169,7 @@ class tasklist extends rcube_plugin
|
|||
$data = $this->task_tree = $this->task_titles = array();
|
||||
|
||||
foreach ($records as $rec) {
|
||||
if ($rec['parent_id']) {
|
||||
if (!empty($rec['parent_id'])) {
|
||||
$this->task_tree[$rec['id']] = $rec['parent_id'];
|
||||
}
|
||||
|
||||
|
@ -1224,18 +1232,20 @@ class tasklist extends rcube_plugin
|
|||
}
|
||||
}
|
||||
|
||||
if ($rec['valarms']) {
|
||||
if (!empty($rec['valarms'])) {
|
||||
$rec['alarms_text'] = libcalendaring::alarms_text($rec['valarms']);
|
||||
$rec['valarms'] = libcalendaring::to_client_alarms($rec['valarms']);
|
||||
}
|
||||
|
||||
if ($rec['recurrence']) {
|
||||
if (!empty($rec['recurrence'])) {
|
||||
$rec['recurrence_text'] = $this->lib->recurrence_text($rec['recurrence']);
|
||||
$rec['recurrence'] = $this->lib->to_client_recurrence($rec['recurrence'], $rec['time'] || $rec['starttime']);
|
||||
}
|
||||
|
||||
foreach ((array)$rec['attachments'] as $k => $attachment) {
|
||||
$rec['attachments'][$k]['classname'] = rcube_utils::file2class($attachment['mimetype'], $attachment['name']);
|
||||
if (!empty($rec['attachments'])) {
|
||||
foreach ((array) $rec['attachments'] as $k => $attachment) {
|
||||
$rec['attachments'][$k]['classname'] = rcube_utils::file2class($attachment['mimetype'], $attachment['name']);
|
||||
}
|
||||
}
|
||||
|
||||
// convert link URIs references into structs
|
||||
|
@ -1283,11 +1293,13 @@ class tasklist extends rcube_plugin
|
|||
{
|
||||
$rec['_depth'] = 0;
|
||||
$parent_titles = array();
|
||||
$parent_id = $this->task_tree[$rec['id']];
|
||||
$parent_id = isset($this->task_tree[$rec['id']]) ? $this->task_tree[$rec['id']] : null;
|
||||
while ($parent_id) {
|
||||
$rec['_depth']++;
|
||||
array_unshift($parent_titles, $this->task_titles[$parent_id]);
|
||||
$parent_id = $this->task_tree[$parent_id];
|
||||
if (isset($this->task_titles[$parent_id])) {
|
||||
array_unshift($parent_titles, $this->task_titles[$parent_id]);
|
||||
}
|
||||
$parent_id = isset($this->task_tree[$parent_id]) ? $this->task_tree[$parent_id] : null;
|
||||
}
|
||||
|
||||
if (count($parent_titles)) {
|
||||
|
@ -1702,7 +1714,7 @@ class tasklist extends rcube_plugin
|
|||
header("Content-Disposition: inline; filename=\"". $plugin['filename'] ."\"");
|
||||
|
||||
$this->get_ical()->export($plugin['result'], '', true,
|
||||
$plugins['attachments'] ? array($this->driver, 'get_attachment_body') : null);
|
||||
!empty($plugin['attachments']) ? array($this->driver, 'get_attachment_body') : null);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
@ -1927,7 +1939,7 @@ class tasklist extends rcube_plugin
|
|||
*/
|
||||
public function mail_message_load($p)
|
||||
{
|
||||
if (!$p['object']->headers->others['x-kolab-type']) {
|
||||
if (empty($p['object']->headers->others['x-kolab-type'])) {
|
||||
$this->load_driver();
|
||||
$this->message_tasks = $this->driver->get_message_related_tasks($p['object']->headers, $p['object']->folder);
|
||||
|
||||
|
@ -1950,7 +1962,7 @@ class tasklist extends rcube_plugin
|
|||
*/
|
||||
public function get_ical()
|
||||
{
|
||||
if (!$this->ical) {
|
||||
if (empty($this->ical)) {
|
||||
$this->ical = libcalendaring::get_ical();
|
||||
}
|
||||
|
||||
|
@ -2442,7 +2454,7 @@ class tasklist extends rcube_plugin
|
|||
if ($task['flagged']) {
|
||||
$object['priority'] = 1;
|
||||
}
|
||||
else if (!$task['priority']) {
|
||||
else if (empty($task['priority'])) {
|
||||
$object['priority'] = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -83,8 +83,9 @@ class tasklist_ui
|
|||
|
||||
// get user identity to create default attendee
|
||||
foreach ($this->rc->user->list_emails() as $rec) {
|
||||
if (!$identity)
|
||||
if (empty($identity)) {
|
||||
$identity = $rec;
|
||||
}
|
||||
|
||||
$identity['emails'][] = $rec['email'];
|
||||
$settings['identities'][$rec['identity_id']] = $rec['email'];
|
||||
|
@ -184,14 +185,15 @@ class tasklist_ui
|
|||
|
||||
$html = '';
|
||||
foreach ((array)$lists as $id => $prop) {
|
||||
if ($attrib['activeonly'] && !$prop['active'])
|
||||
continue;
|
||||
if (!empty($attrib['activeonly']) && empty($prop['active'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$html .= html::tag('li', array(
|
||||
'id' => 'rcmlitasklist' . rcube_utils::html_identifier($id),
|
||||
'class' => $prop['group'],
|
||||
'class' => isset($prop['group']) ? $prop['group'] : null,
|
||||
),
|
||||
$this->tasklist_list_item($id, $prop, $jsenv, $attrib['activeonly'])
|
||||
$this->tasklist_list_item($id, $prop, $jsenv, !empty($attrib['activeonly']))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -241,7 +243,7 @@ class tasklist_ui
|
|||
public function tasklist_list_item($id, $prop, &$jsenv, $activeonly = false)
|
||||
{
|
||||
// enrich list properties with settings from the driver
|
||||
if (!$prop['virtual']) {
|
||||
if (empty($prop['virtual'])) {
|
||||
unset($prop['user_id']);
|
||||
$prop['alarms'] = $this->plugin->driver->alarms;
|
||||
$prop['undelete'] = $this->plugin->driver->undelete;
|
||||
|
@ -253,17 +255,27 @@ class tasklist_ui
|
|||
}
|
||||
|
||||
$classes = array('tasklist');
|
||||
$title = $prop['title'] ?: ($prop['name'] != $prop['listname'] || strlen($prop['name']) > 25 ?
|
||||
html_entity_decode($prop['name'], ENT_COMPAT, RCUBE_CHARSET) : '');
|
||||
$title = '';
|
||||
|
||||
if ($prop['virtual'])
|
||||
if (!empty($prop['title'])) {
|
||||
$title = $prop['title'];
|
||||
}
|
||||
else if (empty($prop['listname']) || $prop['name'] != $prop['listname'] || strlen($prop['name']) > 25) {
|
||||
html_entity_decode($prop['name'], ENT_COMPAT, RCUBE_CHARSET);
|
||||
}
|
||||
|
||||
if (!empty($prop['virtual'])) {
|
||||
$classes[] = 'virtual';
|
||||
else if (!$prop['editable'])
|
||||
}
|
||||
else if (empty($prop['editable'])) {
|
||||
$classes[] = 'readonly';
|
||||
if ($prop['subscribed'])
|
||||
}
|
||||
if (!empty($prop['subscribed'])) {
|
||||
$classes[] = 'subscribed';
|
||||
if ($prop['class'])
|
||||
}
|
||||
if (!empty($prop['class'])) {
|
||||
$classes[] = $prop['class'];
|
||||
}
|
||||
|
||||
if (!$activeonly || $prop['active']) {
|
||||
$label_id = 'tl:' . $id;
|
||||
|
@ -277,9 +289,10 @@ class tasklist_ui
|
|||
));
|
||||
|
||||
return html::div(join(' ', $classes),
|
||||
html::a(array('class' => 'listname', 'title' => $title, 'href' => '#', 'id' => $label_id), $prop['listname'] ?: $prop['name']) .
|
||||
($prop['virtual'] ? '' : $chbox . html::span('actions',
|
||||
($prop['removable'] ? html::a(array('href' => '#', 'class' => 'remove', 'title' => $this->plugin->gettext('removelist')), ' ') : '')
|
||||
html::a(array('class' => 'listname', 'title' => $title, 'href' => '#', 'id' => $label_id),
|
||||
!empty($prop['listname']) ? $prop['listname'] : $prop['name']) .
|
||||
(!empty($prop['virtual']) ? '' : $chbox . html::span('actions',
|
||||
(!empty($prop['removable']) ? html::a(array('href' => '#', 'class' => 'remove', 'title' => $this->plugin->gettext('removelist')), ' ') : '')
|
||||
. html::a(array('href' => '#', 'class' => 'quickview', 'title' => $this->plugin->gettext('focusview'), 'role' => 'checkbox', 'aria-checked' => 'false'), ' ')
|
||||
. (isset($prop['subscribed']) ? html::a(array('href' => '#', 'class' => 'subscribed', 'title' => $this->plugin->gettext('tasklistsubscribe'), 'role' => 'checkbox', 'aria-checked' => $prop['subscribed'] ? 'true' : 'false'), ' ') : '')
|
||||
)
|
||||
|
@ -319,15 +332,18 @@ class tasklist_ui
|
|||
$select = new html_select($attrib);
|
||||
$default = null;
|
||||
|
||||
foreach ((array) $attrib['extra'] as $id => $name) {
|
||||
$select->add($name, $id);
|
||||
if (!empty($attrib['extra'])) {
|
||||
foreach ((array) $attrib['extra'] as $id => $name) {
|
||||
$select->add($name, $id);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ((array)$this->plugin->driver->get_lists() as $id => $prop) {
|
||||
if ($prop['editable'] || strpos($prop['rights'], 'i') !== false) {
|
||||
foreach ((array) $this->plugin->driver->get_lists() as $id => $prop) {
|
||||
if (!empty($prop['editable']) || strpos($prop['rights'], 'i') !== false) {
|
||||
$select->add($prop['name'], $id);
|
||||
if (!$default || $prop['default'])
|
||||
if (!$default || !empty($prop['default'])) {
|
||||
$default = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -421,7 +437,12 @@ class tasklist_ui
|
|||
$attrib += array('id' => 'rcmtasktagsedit');
|
||||
$this->register_gui_object('edittagline', $attrib['id']);
|
||||
|
||||
$input = new html_inputfield(array('name' => 'tags[]', 'class' => 'tag', 'size' => $attrib['size'], 'tabindex' => $attrib['tabindex']));
|
||||
$input = new html_inputfield(array(
|
||||
'name' => 'tags[]',
|
||||
'class' => 'tag',
|
||||
'size' => !empty($attrib['size']) ? $attrib['size'] : null,
|
||||
'tabindex' => isset($attrib['tabindex']) ? $attrib['tabindex'] : null,
|
||||
));
|
||||
unset($attrib['tabindex']);
|
||||
return html::div($attrib, $input->show(''));
|
||||
}
|
||||
|
@ -461,9 +482,21 @@ class tasklist_ui
|
|||
*/
|
||||
function attendees_form($attrib = array())
|
||||
{
|
||||
$input = new html_inputfield(array('name' => 'participant', 'id' => 'edit-attendee-name', 'size' => $attrib['size'], 'class' => 'form-control'));
|
||||
$textarea = new html_textarea(array('name' => 'comment', 'id' => 'edit-attendees-comment',
|
||||
'rows' => 4, 'cols' => 55, 'title' => $this->plugin->gettext('itipcommenttitle'), 'class' => 'form-control'));
|
||||
$input = new html_inputfield(array(
|
||||
'name' => 'participant',
|
||||
'id' => 'edit-attendee-name',
|
||||
'size' => !empty($attrib['size']) ? $attrib['size'] : null,
|
||||
'class' => 'form-control'
|
||||
));
|
||||
|
||||
$textarea = new html_textarea(array(
|
||||
'name' => 'comment',
|
||||
'id' => 'edit-attendees-comment',
|
||||
'rows' => 4,
|
||||
'cols' => 55,
|
||||
'title' => $this->plugin->gettext('itipcommenttitle'),
|
||||
'class' => 'form-control'
|
||||
));
|
||||
|
||||
return html::div($attrib,
|
||||
html::div('form-searchbar', $input->show() . " " .
|
||||
|
@ -488,7 +521,7 @@ class tasklist_ui
|
|||
*/
|
||||
function tasks_import_form($attrib = array())
|
||||
{
|
||||
if (!$attrib['id']) {
|
||||
if (empty($attrib['id'])) {
|
||||
$attrib['id'] = 'rcmImportForm';
|
||||
}
|
||||
|
||||
|
@ -503,7 +536,7 @@ class tasklist_ui
|
|||
'id' => 'importfile',
|
||||
'type' => 'file',
|
||||
'name' => '_data',
|
||||
'size' => $attrib['uploadfieldsize'],
|
||||
'size' => !empty($attrib['uploadfieldsize']) ? $attrib['uploadfieldsize'] : null,
|
||||
'accept' => $accept
|
||||
));
|
||||
|
||||
|
@ -537,11 +570,11 @@ class tasklist_ui
|
|||
*/
|
||||
function tasks_export_form($attrib = array())
|
||||
{
|
||||
if (!$attrib['id']) {
|
||||
if (empty($attrib['id'])) {
|
||||
$attrib['id'] = 'rcmTaskExportForm';
|
||||
}
|
||||
|
||||
$html .= html::div('form-section form-group row',
|
||||
$html = html::div('form-section form-group row',
|
||||
html::label(array('for' => 'task-export-list', 'class' => 'col-sm-4 col-form-label'), $this->plugin->gettext('list'))
|
||||
. html::div('col-sm-8', $this->tasklist_select(array(
|
||||
'name' => 'source',
|
||||
|
|
Loading…
Add table
Reference in a new issue