Manage holidays like any other calendar driver.
authorJan Schneider <jan@horde.org>
Fri, 16 Oct 2009 13:40:54 +0000 (15:40 +0200)
committerJan Schneider <jan@horde.org>
Fri, 16 Oct 2009 13:41:25 +0000 (15:41 +0200)
kronolith/config/prefs.php.dist
kronolith/docs/CHANGES
kronolith/js/kronolith.js
kronolith/lib/Application.php
kronolith/lib/Kronolith.php
kronolith/search.php
kronolith/templates/index/index.inc
kronolith/templates/panel.inc

index 329aa48..98162a9 100644 (file)
@@ -24,15 +24,6 @@ $prefGroups['share'] = array(
     'members' => array('shareselect'),
 );
 
-if (!empty($GLOBALS['conf']['holidays']['enable'])) {
-    $prefGroups['holidays'] = array(
-        'column' => _("Calendars"),
-        'label' => _("Holidays"),
-        'desc' => _("Choose which holidays to display"),
-        'members' => array('holiday_drivers'),
-    );
-}
-
 $prefGroups['event_options'] = array(
     'column' => _("Events"),
     'label' => _("Event Defaults"),
@@ -243,8 +234,7 @@ $_prefs['holiday_drivers'] = array(
     'value' => 'a:0:{}',
     'locked' => false,
     'shared' => false,
-    'type' => 'multienum',
-    'desc' => _("Which kind of holidays do you want to get displayed?"),
+    'type' => 'implicit',
 );
 
 // store the calendars to diplay
index 7129334..1c60c99 100644 (file)
@@ -2,6 +2,7 @@
 v3.0-git
 --------
 
+[jan] Manage holidays like any other calendar driver.
 [mjr] Add support for resource scheduling.
 [jan] Integrate tasks into Ajax interface (Gonçalo Queirós
       <mail@goncaloqueiros.net>).
index 3469154..8096595 100644 (file)
@@ -711,7 +711,7 @@ KronolithCore = {
     updateCalendarList: function()
     {
         var my = 0, shared = 0, ext = {}, extNames = {},
-            remote, api, div;
+            remote, holidays, api, div;
 
         $H(Kronolith.conf.calendars.internal).each(function(cal) {
             if (cal.value.owner) {
@@ -771,6 +771,19 @@ KronolithCore = {
         } else {
             $('kronolithRemoteCalendars').hide();
         }
+
+        holidays = $H(Kronolith.conf.calendars.holiday);
+        holidays.each(function(cal) {
+            $('kronolithHolidayCalendars')
+                .insert(new Element('DIV', { 'calendar': cal.key, 'calendarclass': 'holiday', 'class': cal.value.show ? 'kronolithCalOn' : 'kronolithCalOff' })
+                        .setStyle({ backgroundColor: cal.value.bg, color: cal.value.fg })
+                        .update(cal.value.name.escapeHTML()));
+        });
+        if (holidays.size()) {
+            $('kronolithHolidayCalendars').show();
+        } else {
+            $('kronolithHolidayCalendars').hide();
+        }
     },
 
     /**
index bf0de90..a2e5e83 100644 (file)
@@ -43,20 +43,6 @@ class Kronolith_Application extends Horde_Registry_Application
             $out['day_hour_end_options'] = $out['day_hour_start_options'];
         }
 
-        if (!empty($GLOBALS['conf']['holidays']['enable'])) {
-            if (class_exists('Date_Holidays')) {
-                foreach (Date_Holidays::getInstalledDrivers() as $driver) {
-                    if ($driver['id'] == 'Composite') {
-                        continue;
-                    }
-                    $_prefs['holiday_drivers']['enum'][$driver['id']] = $driver['title'];
-                }
-                asort($_prefs['holiday_drivers']['enum']);
-            } else {
-                $GLOBALS['notification']->push(_("Holidays support is not available on this server."), 'horde.error');
-            }
-        }
-
         return $out;
     }
 
@@ -77,10 +63,6 @@ class Kronolith_Application extends Horde_Registry_Application
         case 'shareselect':
             return $this->_prefsShareSelect($updated);
 
-        case 'holiday_drivers':
-            $this->_prefsHolidayDrivers($updated);
-            return true;
-
         case 'sourceselect':
             return $this->_prefsSourceSelect($updated);
 
@@ -200,23 +182,6 @@ class Kronolith_Application extends Horde_Registry_Application
     /**
      * TODO
      */
-    protected function _prefsHolidayDrivers()
-    {
-        $holiday_driversSelected = Horde_Util::getFormData('holiday_drivers');
-        $holiday_driversFiltered = array();
-
-        if (is_array($holiday_driversSelected)) {
-            foreach ($holiday_driversSelected as $holiday_driver) {
-                $holiday_driversFiltered[] = $holiday_driver;
-            }
-        }
-
-        $GLOBALS['prefs']->setValue('holiday_drivers', serialize($holiday_driversFiltered));
-    }
-
-    /**
-     * TODO
-     */
     protected function _prefsSourceSelect($updated)
     {
         $search_sources = Horde_Util::getFormData('search_sources');
index dc0e48d..06e8dd6 100644 (file)
@@ -176,12 +176,12 @@ class Kronolith
                 'bg' => self::backgroundColor($calendar),
                 'show' => in_array($calendar['url'], $GLOBALS['display_remote_calendars']));
         }
-        if (!empty($GLOBALS['conf']['holidays']['enable'])) {
-            foreach (unserialize($GLOBALS['prefs']->getValue('holiday_drivers')) as $holiday) {
-                $code['conf']['calendars']['holiday'][$holiday] = array(
-                    'name' => $holiday,
-                    'show' => true);
-            }
+        foreach ($GLOBALS['all_holidays'] as $holiday) {
+            $code['conf']['calendars']['holiday'][$holiday['id']] = array(
+                'name' => $holiday['title'],
+                'fg' => self::foregroundColor($holiday),
+                'bg' => self::backgroundColor($holiday),
+                'show' => in_array($holiday['id'], $GLOBALS['display_holidays']));
         }
 
         /* Gettext strings used in core javascript files. */
@@ -259,10 +259,8 @@ class Kronolith
             $calendars = array(
                 Horde_String::ucfirst($GLOBALS['conf']['calendar']['driver']) => $GLOBALS['display_calendars'],
                 'Horde' => $GLOBALS['display_external_calendars'],
-                'Ical' => $GLOBALS['display_remote_calendars']);
-            if (!empty($GLOBALS['conf']['holidays']['enable'])) {
-                $calendars['Holidays'] = unserialize($GLOBALS['prefs']->getValue('holiday_drivers'));
-            }
+                'Ical' => $GLOBALS['display_remote_calendars'],
+                'Holidays' => $GLOBALS['display_holidays']);
         }
 
         $events = array();
@@ -356,12 +354,10 @@ class Kronolith
                     self::mergeEvents($results, $events);
                 }
             }
-        }
 
-        /* Holidays. */
-        if (!empty($GLOBALS['conf']['holidays']['enable'])) {
+            /* Holidays. */
             $driver = self::getDriver('Holidays');
-            foreach (unserialize($GLOBALS['prefs']->getValue('holiday_drivers')) as $holiday) {
+            foreach ($GLOBALS['display_holidays'] as $holiday) {
                 $driver->open($holiday);
                 $events = $driver->listEvents($startDate, $endDate, true);
                 if (!is_a($events, 'PEAR_Error')) {
@@ -704,6 +700,7 @@ class Kronolith
         $GLOBALS['display_calendars'] = @unserialize($GLOBALS['prefs']->getValue('display_cals'));
         $GLOBALS['display_remote_calendars'] = @unserialize($GLOBALS['prefs']->getValue('display_remote_cals'));
         $GLOBALS['display_external_calendars'] = @unserialize($GLOBALS['prefs']->getValue('display_external_cals'));
+        $GLOBALS['display_holidays'] = @unserialize($GLOBALS['prefs']->getValue('holiday_drivers'));
 
         if (!is_array($GLOBALS['display_calendars'])) {
             $GLOBALS['display_calendars'] = array();
@@ -714,6 +711,10 @@ class Kronolith
         if (!is_array($GLOBALS['display_external_calendars'])) {
             $GLOBALS['display_external_calendars'] = array();
         }
+        if (!is_array($GLOBALS['display_holidays']) ||
+            empty($GLOBALS['conf']['holidays']['enable'])) {
+            $GLOBALS['display_holidays'] = array();
+        }
 
         /* Update preferences for which calendars to display. If the
          * user doesn't have any selected calendars to view then fall
@@ -731,6 +732,7 @@ class Kronolith
             $GLOBALS['display_remote_calendars'] = array();
             $GLOBALS['display_external_calendars'] = array();
             $GLOBALS['display_resource_calendars'] = array();
+            $GLOBALS['display_holidays'] = array();
             $calendars = $_SESSION['kronolith']['display_cal'];
             if (!is_array($calendars)) {
                 $calendars = array($calendars);
@@ -750,6 +752,11 @@ class Kronolith
                     if (!in_array($calendarId, $GLOBALS['display_resource_calendars'])) {
                         $GLOBALS['display_resource_calendars'][] = $calendarId;
                     }
+                } elseif (strncmp($calendarId, 'holidays_', 9) === 0) {
+                    $calendarId = substr($calendarId, 9);
+                    if (!in_array($calendarId, $GLOBALS['display_holidays'])) {
+                        $GLOBALS['display_holidays'][] = $calendarId;
+                    }
                 } else {
                     if (!in_array($calendarId, $GLOBALS['display_calendars'])) {
                         $GLOBALS['display_calendars'][] = $calendarId;
@@ -776,6 +783,14 @@ class Kronolith
                 } else {
                     $GLOBALS['display_external_calendars'][] = $calendarId;
                 }
+            } elseif (strncmp($calendarId, 'holidays_', 9) === 0) {
+                $calendarId = substr($calendarId, 9);
+                if (in_array($calendarId, $GLOBALS['display_holidays'])) {
+                    $key = array_search($calendarId, $GLOBALS['display_holidays']);
+                    unset($GLOBALS['display_holidays'][$key]);
+                } else {
+                    $GLOBALS['display_holidays'][] = $calendarId;
+                }
             } else {
                 if (in_array($calendarId, $GLOBALS['display_calendars'])) {
                     $key = array_search($calendarId, $GLOBALS['display_calendars']);
@@ -812,6 +827,28 @@ class Kronolith
         }
         $GLOBALS['prefs']->setValue('display_remote_cals', serialize($GLOBALS['display_remote_calendars']));
 
+        /* Make sure all the holiday drivers still exist. */
+        $GLOBALS['all_holidays'] = array();
+        if (!empty($GLOBALS['conf']['holidays']['enable'])) {
+            if (class_exists('Date_Holidays')) {
+                foreach (Date_Holidays::getInstalledDrivers() as $driver) {
+                    if ($driver['id'] == 'Composite') {
+                        continue;
+                    }
+                    $GLOBALS['all_holidays'][] = $driver;
+                }
+                asort($GLOBALS['all_holidays']);
+            }
+        }
+        $_temp = $GLOBALS['display_holidays'];
+        $GLOBALS['display_holidays'] = array();
+        foreach ($GLOBALS['all_holidays'] as $holiday) {
+            if (in_array($holiday['id'], $_temp)) {
+                $GLOBALS['display_holidays'][] = $holiday['id'];
+            }
+        }
+        $GLOBALS['prefs']->setValue('holiday_drivers', serialize($GLOBALS['display_holidays']));
+
         /* Get a list of external calendars. */
         if (isset($_SESSION['all_external_calendars'])) {
             $GLOBALS['all_external_calendars'] = $_SESSION['all_external_calendars'];
index ee0e1c5..a094d89 100644 (file)
@@ -82,10 +82,8 @@ if ($search_mode == 'basic') {
     foreach ($GLOBALS['all_remote_calendars'] as $cal) {
         $calendars[_("Remote Calendars:")]['Ical|' . $cal['url']] = $cal['name'];
     }
-    if (!empty($GLOBALS['conf']['holidays']['enable'])) {
-        foreach (unserialize($GLOBALS['prefs']->getValue('holiday_drivers')) as $holiday) {
-            $calendars[_("Holidays:")]['Holidays|' . $holiday] = $holiday;
-        }
+    foreach ($GLOBALS['all_holidays'] as $holiday) {
+        $calendars[_("Holidays:")]['Holidays|' . $holiday['id']] = $holiday['title'];
     }
 }
 
index 74d23be..f4266ee 100644 (file)
 
   <div id="kronolithRemoteCalendars" class="kronolithCalendars" style="display:none">
   </div>
+
+  <h3>
+    <span><?php echo _("Holidays") ?></span>
+  </h3>
+
+  <div id="kronolithHolidayCalendars" class="kronolithCalendars" style="display:none">
+  </div>
   </div>
 
   <div id="kronolithMenuBottom">
index 9f61190..c01343b 100644 (file)
@@ -137,6 +137,15 @@ $ta->attach();
  </ul>
 <?php endif; ?>
 
+<?php if (!empty($GLOBALS['conf']['holidays']['enable'])): ?>
+ <h4><?php echo _("Holidays:") ?></h4>
+ <ul id="holidays">
+<?php foreach ($GLOBALS['all_holidays'] as $holiday): ?>
+  <li<?php echo Kronolith::getCSSColors($holiday) ?>><label><input type="checkbox" class="checkbox" name="display_cal[]" value="holidays_<?php echo htmlspecialchars($holiday['id']) ?>"<?php echo (in_array($holiday['id'], $display_holidays) ? ' checked="checked"' : '') . ' /> ' . htmlspecialchars($holiday['title']) ?></label></li>
+<?php endforeach; ?>
+ </ul>
+<?php endif; ?>
+
 <noscript>
  <p>
   <input type="submit" value="<?php echo _("Save") ?>" class="button" />