From: Jan Schneider Date: Fri, 16 Oct 2009 13:40:54 +0000 (+0200) Subject: Manage holidays like any other calendar driver. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=b38589ebfccd19aad7af486ce11fde9043f014ca;p=horde.git Manage holidays like any other calendar driver. --- diff --git a/kronolith/config/prefs.php.dist b/kronolith/config/prefs.php.dist index 329aa4809..98162a919 100644 --- a/kronolith/config/prefs.php.dist +++ b/kronolith/config/prefs.php.dist @@ -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 diff --git a/kronolith/docs/CHANGES b/kronolith/docs/CHANGES index 7129334ab..1c60c99a4 100644 --- a/kronolith/docs/CHANGES +++ b/kronolith/docs/CHANGES @@ -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 ). diff --git a/kronolith/js/kronolith.js b/kronolith/js/kronolith.js index 346915414..80965957d 100644 --- a/kronolith/js/kronolith.js +++ b/kronolith/js/kronolith.js @@ -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(); + } }, /** diff --git a/kronolith/lib/Application.php b/kronolith/lib/Application.php index bf0de9010..a2e5e8328 100644 --- a/kronolith/lib/Application.php +++ b/kronolith/lib/Application.php @@ -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'); diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index dc0e48d25..06e8dd641 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -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']; diff --git a/kronolith/search.php b/kronolith/search.php index ee0e1c525..a094d8974 100644 --- a/kronolith/search.php +++ b/kronolith/search.php @@ -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']; } } diff --git a/kronolith/templates/index/index.inc b/kronolith/templates/index/index.inc index 74d23be92..f4266ee65 100644 --- a/kronolith/templates/index/index.inc +++ b/kronolith/templates/index/index.inc @@ -64,6 +64,13 @@ + +

+ +

+ +
diff --git a/kronolith/templates/panel.inc b/kronolith/templates/panel.inc index 9f6119021..c01343ba6 100644 --- a/kronolith/templates/panel.inc +++ b/kronolith/templates/panel.inc @@ -137,6 +137,15 @@ $ta->attach(); + +

+
    + + > + +
+ +