Show possible event conflicts in iTip viewer (Request #3991, Gonçalo Queirós <goncalo...
authorJan Schneider <jan@horde.org>
Sat, 25 Apr 2009 16:23:26 +0000 (18:23 +0200)
committerJan Schneider <jan@horde.org>
Sat, 25 Apr 2009 16:23:26 +0000 (18:23 +0200)
imp/config/prefs.php.dist
imp/docs/CHANGES
imp/lib/Mime/Viewer/Itip.php
imp/themes/screen.css
kronolith/lib/api.php

index 69d25e3..b04cdfd 100644 (file)
@@ -175,6 +175,13 @@ $prefGroups['addressbooks'] = array(
     'members' => array('save_recipients', 'display_contact', 'sourceselect')
 );
 
+$prefGroups['events'] = array(
+    'column' => _("Other Options"),
+    'label' => _("Event Requests"),
+    'desc' => _("Customize how should be dealt with event or meeting requests."),
+    'members' => array('conflict_interval')
+);
+
 if (isset($GLOBALS['conf']['utils']['gnupg'])) {
     $prefGroups['pgp'] = array(
         'column' => _("Other Options"),
@@ -1554,6 +1561,20 @@ $_prefs['add_source'] = array(
 // End Address book preferences
 
 
+// Event preferences
+
+// Amount of minutes to consider a event as a non-conflicting one in iTip
+$_prefs['conflict_interval'] = array(
+    'value' => 30,
+    'locked' => false,
+    'shared' => false,
+    'type' => 'number',
+    'desc' => _("Minutes needed to consider a event as a non-conflicting one in iTip")
+);
+
+// End Calendar preferences
+
+
 // PGP options
 
 // Activate PGP support?
index 39c0ba2..27d2899 100644 (file)
@@ -2,6 +2,8 @@
 v5.0-git
 --------
 
+[jan] Show possible event conflicts in iTip viewer (Gonçalo Queirós
+      <goncalo.queiros@portugalmail.net>).
 [mms] Move subfolders of special folders to lower folder display tree in
       DIMP (Bug #8127).
 [mms] Simplify quicksearch UI in DIMP.
index 0a1fb15..682e593 100644 (file)
@@ -787,6 +787,53 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver
             $html .= '</tbody></table>';
         }
 
+        if ($registry->hasMethod('calendar/getFbCalendars') &&
+            $registry->hasMethod('calendar/listEvents') &&
+            !is_a($calendars = $registry->call('calendar/getFbCalendars'), 'PEAR_Error')) {
+
+            $vevent_allDay = true;
+            $vevent_start = new Horde_Date($start);
+            $vevent_end = new Horde_Date($end);
+            // Check if it's an all-day event.
+            if (is_array($start)) {
+                $vevent_end = $vevent_end->sub(1);
+            } else {
+                $vevent_allDay = false;
+                $time_span_start = new Horde_Date($start);
+                $time_span_start = $time_span_start->sub($prefs->getValue('conflict_interval') * 60);
+                $time_span_end = new Horde_Date($end);
+                $time_span_end = $time_span_end->add($prefs->getValue('conflict_interval') * 60);
+            }
+            $events = $registry->call('calendar/listEvents', array($start, $vevent_end, $calendars, false));
+
+            if (!is_a($events, 'PEAR_Error') && count($events)) {
+                $html .= '<h2 class="smallheader">' . _("Possible Conflicts") . '</h2><table id="itipconflicts">';
+                // TODO: Check if there are too many events to show.
+                foreach ($events as $calendar) {
+                    foreach ($calendar as $event) {
+                        if ($vevent_allDay || $event->isAllDay()) {
+                            $html .= '<tr class="itipcollision">';
+                        } else {
+                            if ($event->end->compareDateTime($time_span_start) <= -1 ||
+                                $event->start->compareDateTime($time_span_end) >= 1) {
+                               continue;
+                            }
+                            if ($event->end->compareDateTime($vevent_start) <= -1 ||
+                                $event->start->compareDateTime($vevent_end) >= 1) {
+                                $html .= '<tr class="itipnearcollision">';
+                            } else {
+                                $html .= '<tr class="itipcollision">';
+                            }
+                        }
+
+                        $html .= '<td>'. $event->getTitle() . '</td><td>'
+                            . $event->getTimeRange() . '</td></tr>';
+                    }
+                }
+                $html .= '</table>';
+            }
+        }
+
         if ($_SESSION['imp']['view'] != 'imp') {
             return $html;
         }
index 23d72e9..09cc912 100644 (file)
@@ -593,3 +593,12 @@ span.threadImg8 {
 .stripAtc {
     background-image: url("graphics/delete.png");
 }
+
+#itipconflicts tr.itipcollision {
+    background-color: #f00;
+    color: #fff;
+}
+
+#itipconflicts tr.itipnearcollision {
+    background-color: #ee0;
+}
index f3ac519..0f2c570 100644 (file)
@@ -141,6 +141,11 @@ $_services['checkLocks'] = array(
     'type' => 'string'
 );
 
+$_services['getFbCalendars'] = array(
+    'args' => array(),
+    'type' => '{urn:horde}stringArray'
+);
+
 /**
  * Returns a list of available permissions.
  *
@@ -1516,4 +1521,13 @@ function _kronolith_checkLocks($calendar, $event = null)
     $share = &$GLOBALS['kronolith_shares']->getShare($calendar);
 
     return $share->checkLocks($event);
-}
\ No newline at end of file
+}
+
+/**
+ *
+ * @return array  A list of calendars used to display free/busy information
+ */
+function _kronolith_getFbCalendars()
+{
+    return (unserialize($GLOBALS['prefs']->getValue('fb_cals')));
+}