From 551fe7db2b95b25a7a4ad44b3c43fe338361a11f Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 5 Sep 2011 23:05:19 +0200 Subject: [PATCH] Improve invitation handling: only search writeable calendars for already saved events; fix RSVP button display --- plugins/calendar/calendar.php | 26 ++++++++++++++----- plugins/calendar/drivers/calendar_driver.php | 5 ++-- .../drivers/database/database_driver.php | 3 ++- .../calendar/drivers/kolab/kolab_driver.php | 17 +++++++++--- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php index a645f0a6..ab5f7a07 100644 --- a/plugins/calendar/calendar.php +++ b/plugins/calendar/calendar.php @@ -602,7 +602,7 @@ class calendar extends rcube_plugin // search for event if only UID is given if (!isset($event['calendar']) && $event['uid']) { - if (!($event = $this->driver->get_event($event))) { + if (!($event = $this->driver->get_event($event, true))) { break; } $undo_time = 0; @@ -665,7 +665,7 @@ class calendar extends rcube_plugin $status = $event['fallback']; $html = html::div('rsvp-status', $status != 'CANCELLED' ? $this->gettext('acceptinvitation') : ''); $this->load_driver(); - if ($existing = $this->driver->get_event($event)) { + if ($existing = $this->driver->get_event($event, true)) { $emails = $this->get_user_emails(); foreach ($existing['attendees'] as $i => $attendee) { if ($attendee['email'] && in_array($attendee['email'], $emails)) { @@ -674,7 +674,7 @@ class calendar extends rcube_plugin } } } - else if ($status != 'NEEDS-ACTION') + if ($status == 'unknown') $action = 'import'; if (in_array($status, array('ACCEPTED','TENTATIVE','DECLINED'))) { @@ -1094,9 +1094,13 @@ class calendar extends rcube_plugin */ public function generate_randomdata() { - $cats = array_keys($this->driver->list_categories()); - $cals = $this->driver->list_calendars(); $num = $_REQUEST['_num'] ? intval($_REQUEST['_num']) : 100; + $cats = array_keys($this->driver->list_categories()); + $cals = array(); + foreach ($this->driver->list_calendars() as $cid => $cal) { + if ($cal['active']) + $cals[$cid] = $cal; + } while ($count++ < $num) { $start = round((time() + rand(-2600, 2600) * 1000) / 300) * 300; @@ -1705,13 +1709,21 @@ class calendar extends rcube_plugin public function mail_message_load($p) { $this->message = $p['object']; + $itip_part = null; // check all message parts for .ics files foreach ((array)$this->message->mime_parts as $idx => $part) { if ($this->is_vcalendar($part)) { - $this->ics_parts[] = $part->mime_id; + if ($part->ctype_parameters['method']) + $itip_part = $part->mime_id; + else + $this->ics_parts[] = $part->mime_id; } } + + // priorize part with method parameter + if ($itip_part) + $this->ics_parts = array($itip_part); } /** @@ -1898,7 +1910,7 @@ class calendar extends rcube_plugin $event['calendar'] = $calendar['id']; // check for existing event with the same UID - $existing = $this->driver->get_event($event); + $existing = $this->driver->get_event($event['uid'], true); if ($existing) { // only update attendee status diff --git a/plugins/calendar/drivers/calendar_driver.php b/plugins/calendar/drivers/calendar_driver.php index 18fcdaaf..c610f158 100644 --- a/plugins/calendar/drivers/calendar_driver.php +++ b/plugins/calendar/drivers/calendar_driver.php @@ -202,10 +202,11 @@ abstract class calendar_driver * * @param mixed UID string or hash array with event properties: * id: Event identifier - * calendar: Calendar identifier + * calendar: Calendar identifier (optional) + * @param boolean If true, only writeable calendars shall be searched * @return array Event object as hash array */ - abstract function get_event($event); + abstract function get_event($event, $writeable = null); /** * Get events from source. diff --git a/plugins/calendar/drivers/database/database_driver.php b/plugins/calendar/drivers/database/database_driver.php index da83fa1e..67c54111 100644 --- a/plugins/calendar/drivers/database/database_driver.php +++ b/plugins/calendar/drivers/database/database_driver.php @@ -637,9 +637,10 @@ class database_driver extends calendar_driver /** * Return data of a specific event * @param mixed Hash array with event properties or event UID + * @param boolean Only search in writeable calendars (currently ignored) * @return array Hash array with event properties */ - public function get_event($event) + public function get_event($event, $writeable = null) { $id = is_array($event) ? ($event['id'] ? $event['id'] : $event['uid']) : $event; $col = $event['id'] && is_numeric($event['id']) ? 'event_id' : 'uid'; diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php index e6d24b4d..ea20fb9e 100644 --- a/plugins/calendar/drivers/kolab/kolab_driver.php +++ b/plugins/calendar/drivers/kolab/kolab_driver.php @@ -360,15 +360,24 @@ class kolab_driver extends calendar_driver * @see calendar_driver::get_event() * @return array Hash array with event properties, false if not found */ - public function get_event($event) + public function get_event($event, $writeable = null) { - $id = $event['id'] ? $event['id'] : $event['uid']; - if ($event['calendar'] && ($storage = $this->calendars[$event['calendar']])) { + if (is_array($event)) { + $id = $event['id'] ? $event['id'] : $event['uid']; + $cal = $event['calendar']; + } + else { + $id = $event; + } + + if ($cal && ($storage = $this->calendars[$cal])) { return $storage->get_event($id); } // iterate over all calendar folders and search for the event ID - else if (!$event['calendar']) { + else if (!$cal) { foreach ($this->calendars as $storage) { + if ($writeable && !rcube_kolab::is_subscribed($storage->get_realname())) + continue; if ($result = $storage->get_event($id)) { return $result; }