diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php index 920462c1..9880da57 100644 --- a/plugins/calendar/calendar.php +++ b/plugins/calendar/calendar.php @@ -564,6 +564,39 @@ class calendar extends rcube_plugin $this->rc->output->add_script('$("input.colors").miniColors({ colorValues:rcmail.env.mscolors })', 'docready'); } + $p['blocks']['birthdays']['name'] = $this->gettext('birthdayscalendar'); + + if (!isset($no_override['calendar_contact_birthdays'])) { + if (!$p['current']) { + $p['blocks']['birthdays']['content'] = true; + return $p; + } + + $field_id = 'rcmfd_contact_birthdays'; + $input = new html_checkbox(array('name' => '_contact_birthdays', 'id' => $field_id, 'value' => 1, 'onclick' => '$("input.calendar_birthday_props").prop("disabled",!this.checked)')); + + $p['blocks']['birthdays']['options']['contact_birthdays'] = array( + 'title' => html::label($field_id, $this->gettext('displaybirthdayscalendar')), + 'content' => $input->show($this->rc->config->get('calendar_contact_birthdays')?1:0), + ); + + $sources = array(); + $checkbox = new html_checkbox(array( + 'name' => '_birthday_adressbooks[]', + 'class' => 'calendar_birthday_props', + 'disabled' => !$this->rc->config->get('calendar_contact_birthdays'), + )); + foreach ($this->rc->get_address_sources(false, true) as $source) { + $active = in_array($source['id'], (array)$this->rc->config->get('calendar_birthday_adressbooks', array())) ? $source['id'] : ''; + $sources[] = html::label(null, $checkbox->show($active, array('value' => $source['id'])) . ' ' . rcube::Q($source['realname'] ?: $source['name'])); + } + + $p['blocks']['birthdays']['options']['birthday_adressbooks'] = array( + 'title' => rcube::Q($this->gettext('birthdayscalendarsources')), + 'content' => join(html::br(), $sources), + ); + } + return $p; } @@ -596,6 +629,8 @@ class calendar extends rcube_plugin 'calendar_default_calendar' => get_input_value('_default_calendar', RCUBE_INPUT_POST), 'calendar_date_format' => null, // clear previously saved values 'calendar_time_format' => null, + 'calendar_contact_birthdays' => get_input_value('_contact_birthdays', RCUBE_INPUT_POST) ? true : false, + 'calendar_birthday_adressbooks' => array_filter((array)get_input_value('_birthday_adressbooks', RCUBE_INPUT_POST)), ); // categories diff --git a/plugins/calendar/drivers/calendar_driver.php b/plugins/calendar/drivers/calendar_driver.php index af8cb2fc..1f6b2587 100644 --- a/plugins/calendar/drivers/calendar_driver.php +++ b/plugins/calendar/drivers/calendar_driver.php @@ -429,19 +429,22 @@ abstract class calendar_driver $cache = $rcmail->get_cache('calendar.birthdays', 'db', 3600); $cache->expunge(); - // TODO: let the user select the address books to consider in prefs - foreach ($rcmail->get_address_sources(false, true) as $source) { - $abook = $rcmail->get_address_book($source['id']); - $abook->set_pagesize(10000); + // let the user select the address books to consider in prefs + $selected_sources = $rcmail->config->get('calendar_birthday_adressbooks'); + $sources = $selected_sources ?: array_keys($rcmail->get_address_sources(false, true)); + foreach ($sources as $source) { + $abook = $rcmail->get_address_book($source); - // skip LDAP address books (really?) - if ($abook instanceof rcube_ldap) { + // skip LDAP address books unless selected by the user + if (!$abook || ($abook instanceof rcube_ldap && empty($selected_sources))) { continue; } + $abook->set_pagesize(10000); + // check for cached results $cache_records = array(); - $cached = $cache->get($source['id']); + $cached = $cache->get($source); // iterate over (cached) contacts foreach (($cached ?: $abook->list_records()) as $contact) { @@ -509,7 +512,7 @@ abstract class calendar_driver // store collected contacts in cache if (empty($cached)) { - $cache->write($source['id'], $cache_records); + $cache->write($source, $cache_records); } } diff --git a/plugins/calendar/localization/en_US.inc b/plugins/calendar/localization/en_US.inc index c582db92..e6cbceb7 100644 --- a/plugins/calendar/localization/en_US.inc +++ b/plugins/calendar/localization/en_US.inc @@ -240,6 +240,9 @@ $labels['saveasnew'] = 'Save as new'; // birthdays calendar $labels['birthdays'] = 'Birthdays'; +$labels['birthdayscalendar'] = 'Birthdays Calendar'; +$labels['displaybirthdayscalendar'] = 'Display birthdays calendar'; +$labels['birthdayscalendarsources'] = 'From these address books'; $labels['birthdayeventtitle'] = '$name\'s Birthday'; $labels['birthdayage'] = 'Age $age';