Add settings block for birthdays calendar settings

This commit is contained in:
Thomas Bruederli 2014-01-28 09:58:54 +01:00
parent b9ed08ce78
commit 92a6e5c28d
3 changed files with 49 additions and 8 deletions

View file

@ -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

View file

@ -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);
}
}

View file

@ -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';