Exemple #1
0
 /**
  * Handler for preferences_list hook.
  * Adds options blocks into Calendar settings sections in Preferences.
  *
  * @param array Original parameters
  * @return array Modified parameters
  */
 function preferences_list($p)
 {
     if ($p['section'] != 'calendar') {
         return $p;
     }
     $no_override = array_flip((array) $this->rc->config->get('dont_override'));
     $p['blocks']['view']['name'] = $this->gettext('mainoptions');
     if (!isset($no_override['calendar_default_view'])) {
         if (!$p['current']) {
             $p['blocks']['view']['content'] = true;
             return $p;
         }
         $field_id = 'rcmfd_default_view';
         $select = new html_select(array('name' => '_default_view', 'id' => $field_id));
         $select->add($this->gettext('day'), "agendaDay");
         $select->add($this->gettext('week'), "agendaWeek");
         $select->add($this->gettext('month'), "month");
         $select->add($this->gettext('agenda'), "table");
         $p['blocks']['view']['options']['default_view'] = array('title' => html::label($field_id, rcube::Q($this->gettext('default_view'))), 'content' => $select->show($this->rc->config->get('calendar_default_view', $this->defaults['calendar_default_view'])));
     }
     if (!isset($no_override['calendar_timeslots'])) {
         if (!$p['current']) {
             $p['blocks']['view']['content'] = true;
             return $p;
         }
         $field_id = 'rcmfd_timeslot';
         $choices = array('1', '2', '3', '4', '6');
         $select = new html_select(array('name' => '_timeslots', 'id' => $field_id));
         $select->add($choices);
         $p['blocks']['view']['options']['timeslots'] = array('title' => html::label($field_id, rcube::Q($this->gettext('timeslots'))), 'content' => $select->show(strval($this->rc->config->get('calendar_timeslots', $this->defaults['calendar_timeslots']))));
     }
     if (!isset($no_override['calendar_first_day'])) {
         if (!$p['current']) {
             $p['blocks']['view']['content'] = true;
             return $p;
         }
         $field_id = 'rcmfd_firstday';
         $select = new html_select(array('name' => '_first_day', 'id' => $field_id));
         $select->add($this->gettext('sunday'), '0');
         $select->add($this->gettext('monday'), '1');
         $select->add($this->gettext('tuesday'), '2');
         $select->add($this->gettext('wednesday'), '3');
         $select->add($this->gettext('thursday'), '4');
         $select->add($this->gettext('friday'), '5');
         $select->add($this->gettext('saturday'), '6');
         $p['blocks']['view']['options']['first_day'] = array('title' => html::label($field_id, rcube::Q($this->gettext('first_day'))), 'content' => $select->show(strval($this->rc->config->get('calendar_first_day', $this->defaults['calendar_first_day']))));
     }
     if (!isset($no_override['calendar_first_hour'])) {
         if (!$p['current']) {
             $p['blocks']['view']['content'] = true;
             return $p;
         }
         $time_format = $this->rc->config->get('time_format', libcalendaring::to_php_date_format($this->rc->config->get('calendar_time_format', $this->defaults['calendar_time_format'])));
         $select_hours = new html_select();
         for ($h = 0; $h < 24; $h++) {
             $select_hours->add(date($time_format, mktime($h, 0, 0)), $h);
         }
         $field_id = 'rcmfd_firsthour';
         $p['blocks']['view']['options']['first_hour'] = array('title' => html::label($field_id, rcube::Q($this->gettext('first_hour'))), 'content' => $select_hours->show($this->rc->config->get('calendar_first_hour', $this->defaults['calendar_first_hour']), array('name' => '_first_hour', 'id' => $field_id)));
     }
     if (!isset($no_override['calendar_work_start'])) {
         if (!$p['current']) {
             $p['blocks']['view']['content'] = true;
             return $p;
         }
         $field_id = 'rcmfd_workstart';
         $p['blocks']['view']['options']['workinghours'] = array('title' => html::label($field_id, rcube::Q($this->gettext('workinghours'))), 'content' => $select_hours->show($this->rc->config->get('calendar_work_start', $this->defaults['calendar_work_start']), array('name' => '_work_start', 'id' => $field_id)) . ' &mdash; ' . $select_hours->show($this->rc->config->get('calendar_work_end', $this->defaults['calendar_work_end']), array('name' => '_work_end', 'id' => $field_id)));
     }
     if (!isset($no_override['calendar_event_coloring'])) {
         if (!$p['current']) {
             $p['blocks']['view']['content'] = true;
             return $p;
         }
         $field_id = 'rcmfd_coloring';
         $select_colors = new html_select(array('name' => '_event_coloring', 'id' => $field_id));
         $select_colors->add($this->gettext('coloringmode0'), 0);
         $select_colors->add($this->gettext('coloringmode1'), 1);
         $select_colors->add($this->gettext('coloringmode2'), 2);
         $select_colors->add($this->gettext('coloringmode3'), 3);
         $p['blocks']['view']['options']['eventcolors'] = array('title' => html::label($field_id . 'value', rcube::Q($this->gettext('eventcoloring'))), 'content' => $select_colors->show($this->rc->config->get('calendar_event_coloring', $this->defaults['calendar_event_coloring'])));
     }
     // loading driver is expensive, don't do it if not needed
     $this->load_driver();
     if (!isset($no_override['calendar_default_alarm_type']) || !isset($no_override['calendar_default_alarm_offset'])) {
         if (!$p['current']) {
             $p['blocks']['view']['content'] = true;
             return $p;
         }
         $alarm_type = $alarm_offset = '';
         if (!isset($no_override['calendar_default_alarm_type'])) {
             $field_id = 'rcmfd_alarm';
             $select_type = new html_select(array('name' => '_alarm_type', 'id' => $field_id));
             $select_type->add($this->gettext('none'), '');
             foreach ($this->driver->alarm_types as $type) {
                 $select_type->add($this->rc->gettext(strtolower("alarm{$type}option"), 'libcalendaring'), $type);
             }
             $alarm_type = $select_type->show($this->rc->config->get('calendar_default_alarm_type', ''));
         }
         if (!isset($no_override['calendar_default_alarm_offset'])) {
             $field_id = 'rcmfd_alarm';
             $input_value = new html_inputfield(array('name' => '_alarm_value', 'id' => $field_id . 'value', 'size' => 3));
             $select_offset = new html_select(array('name' => '_alarm_offset', 'id' => $field_id . 'offset'));
             foreach (array('-M', '-H', '-D', '+M', '+H', '+D') as $trigger) {
                 $select_offset->add($this->rc->gettext('trigger' . $trigger, 'libcalendaring'), $trigger);
             }
             $preset = libcalendaring::parse_alarm_value($this->rc->config->get('calendar_default_alarm_offset', '-15M'));
             $alarm_offset = $input_value->show($preset[0]) . ' ' . $select_offset->show($preset[1]);
         }
         $p['blocks']['view']['options']['alarmtype'] = array('title' => html::label($field_id, rcube::Q($this->gettext('defaultalarmtype'))), 'content' => $alarm_type . ' ' . $alarm_offset);
     }
     if (!isset($no_override['calendar_default_calendar'])) {
         if (!$p['current']) {
             $p['blocks']['view']['content'] = true;
             return $p;
         }
         // default calendar selection
         $field_id = 'rcmfd_default_calendar';
         $select_cal = new html_select(array('name' => '_default_calendar', 'id' => $field_id, 'is_escaped' => true));
         foreach ((array) $this->driver->list_calendars(calendar_driver::FILTER_PERSONAL) as $id => $prop) {
             $select_cal->add($prop['name'], strval($id));
             if ($prop['default']) {
                 $default_calendar = $id;
             }
         }
         $p['blocks']['view']['options']['defaultcalendar'] = array('title' => html::label($field_id . 'value', rcube::Q($this->gettext('defaultcalendar'))), 'content' => $select_cal->show($this->rc->config->get('calendar_default_calendar', $default_calendar)));
     }
     $p['blocks']['itip']['name'] = $this->gettext('itipoptions');
     // Invitations handling
     if (!isset($no_override['calendar_itip_after_action'])) {
         if (!$p['current']) {
             $p['blocks']['itip']['content'] = true;
             return $p;
         }
         $field_id = 'rcmfd_after_action';
         $select = new html_select(array('name' => '_after_action', 'id' => $field_id, 'onchange' => "\$('#{$field_id}_select')[this.value == 4 ? 'show' : 'hide']()"));
         $select->add($this->gettext('afternothing'), '');
         $select->add($this->gettext('aftertrash'), 1);
         $select->add($this->gettext('afterdelete'), 2);
         $select->add($this->gettext('afterflagdeleted'), 3);
         $select->add($this->gettext('aftermoveto'), 4);
         $val = $this->rc->config->get('calendar_itip_after_action', $this->defaults['calendar_itip_after_action']);
         if ($val !== null && $val !== '' && !is_int($val)) {
             $folder = $val;
             $val = 4;
         }
         $folders = $this->rc->folder_selector(array('id' => $field_id . '_select', 'name' => '_after_action_folder', 'maxlength' => 30, 'folder_filter' => 'mail', 'folder_rights' => 'w', 'style' => $val !== 4 ? 'display:none' : ''));
         $p['blocks']['itip']['options']['after_action'] = array('title' => html::label($field_id, rcube::Q($this->gettext('afteraction'))), 'content' => $select->show($val) . $folders->show($folder));
     }
     // category definitions
     if (!$this->driver->nocategories && !isset($no_override['calendar_categories'])) {
         $p['blocks']['categories']['name'] = $this->gettext('categories');
         if (!$p['current']) {
             $p['blocks']['categories']['content'] = true;
             return $p;
         }
         $categories = (array) $this->driver->list_categories();
         $categories_list = '';
         foreach ($categories as $name => $color) {
             $key = md5($name);
             $field_class = 'rcmfd_category_' . str_replace(' ', '_', $name);
             $category_remove = new html_inputfield(array('type' => 'button', 'value' => 'X', 'class' => 'button', 'onclick' => '$(this).parent().remove()', 'title' => $this->gettext('remove_category')));
             $category_name = new html_inputfield(array('name' => "_categories[{$key}]", 'class' => $field_class, 'size' => 30, 'disabled' => $this->driver->categoriesimmutable));
             $category_color = new html_inputfield(array('name' => "_colors[{$key}]", 'class' => "{$field_class} colors", 'size' => 6));
             $hidden = $this->driver->categoriesimmutable ? html::tag('input', array('type' => 'hidden', 'name' => "_categories[{$key}]", 'value' => $name)) : '';
             $categories_list .= html::div(null, $hidden . $category_name->show($name) . '&nbsp;' . $category_color->show($color) . '&nbsp;' . $category_remove->show());
         }
         $p['blocks']['categories']['options']['category_' . $name] = array('content' => html::div(array('id' => 'calendarcategories'), $categories_list));
         $field_id = 'rcmfd_new_category';
         $new_category = new html_inputfield(array('name' => '_new_category', 'id' => $field_id, 'size' => 30));
         $add_category = new html_inputfield(array('type' => 'button', 'class' => 'button', 'value' => $this->gettext('add_category'), 'onclick' => "rcube_calendar_add_category()"));
         $p['blocks']['categories']['options']['categories'] = array('content' => $new_category->show('') . '&nbsp;' . $add_category->show());
         $this->rc->output->add_script('function rcube_calendar_add_category(){
       var name = $("#rcmfd_new_category").val();
       if (name.length) {
         var input = $("<input>").attr("type", "text").attr("name", "_categories[]").attr("size", 30).val(name);
         var color = $("<input>").attr("type", "text").attr("name", "_colors[]").attr("size", 6).addClass("colors").val("000000");
         var button = $("<input>").attr("type", "button").attr("value", "X").addClass("button").click(function(){ $(this).parent().remove() });
         $("<div>").append(input).append("&nbsp;").append(color).append("&nbsp;").append(button).appendTo("#calendarcategories");
         color.miniColors({ colorValues:(rcmail.env.mscolors || []) });
         $("#rcmfd_new_category").val("");
       }
     }');
         $this->rc->output->add_script('$("#rcmfd_new_category").keypress(function(event){
       if (event.which == 13) {
         rcube_calendar_add_category();
         event.preventDefault();
       }
     });
     ', 'docready');
         // load miniColors js/css files
         jqueryui::miniColors();
     }
     // virtual birthdays calendar
     if (!isset($no_override['calendar_contact_birthdays'])) {
         $p['blocks']['birthdays']['name'] = $this->gettext('birthdayscalendar');
         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' => '$(".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));
         $input_attrib = array('class' => 'calendar_birthday_props', 'disabled' => !$this->rc->config->get('calendar_contact_birthdays'));
         $sources = array();
         $checkbox = new html_checkbox(array('name' => '_birthday_adressbooks[]') + $input_attrib);
         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'])) . '&nbsp;' . rcube::Q($source['realname'] ?: $source['name']));
         }
         $p['blocks']['birthdays']['options']['birthday_adressbooks'] = array('title' => rcube::Q($this->gettext('birthdayscalendarsources')), 'content' => join(html::br(), $sources));
         $field_id = 'rcmfd_birthdays_alarm';
         $select_type = new html_select(array('name' => '_birthdays_alarm_type', 'id' => $field_id) + $input_attrib);
         $select_type->add($this->gettext('none'), '');
         foreach ($this->driver->alarm_types as $type) {
             $select_type->add($this->rc->gettext(strtolower("alarm{$type}option"), 'libcalendaring'), $type);
         }
         $input_value = new html_inputfield(array('name' => '_birthdays_alarm_value', 'id' => $field_id . 'value', 'size' => 3) + $input_attrib);
         $select_offset = new html_select(array('name' => '_birthdays_alarm_offset', 'id' => $field_id . 'offset') + $input_attrib);
         foreach (array('-M', '-H', '-D') as $trigger) {
             $select_offset->add($this->rc->gettext('trigger' . $trigger, 'libcalendaring'), $trigger);
         }
         $preset = libcalendaring::parse_alarm_value($this->rc->config->get('calendar_birthdays_alarm_offset', '-1D'));
         $p['blocks']['birthdays']['options']['birthdays_alarmoffset'] = array('title' => html::label($field_id . 'value', rcube::Q($this->gettext('showalarms'))), 'content' => $select_type->show($this->rc->config->get('calendar_birthdays_alarm_type', '')) . ' ' . $input_value->show($preset[0]) . '&nbsp;' . $select_offset->show($preset[1]));
     }
     return $p;
 }
 /**
  * Render localized text describing the recurrence rule of an event
  */
 private function _recurrence_text($rrule)
 {
     // derive missing FREQ and INTERVAL from RDATE list
     if (empty($rrule['FREQ']) && !empty($rrule['RDATE'])) {
         $first = $rrule['RDATE'][0];
         $second = $rrule['RDATE'][1];
         $third = $rrule['RDATE'][2];
         if (is_a($first, 'DateTime') && is_a($second, 'DateTime')) {
             $diff = $first->diff($second);
             foreach (array('y' => 'YEARLY', 'm' => 'MONTHLY', 'd' => 'DAILY') as $k => $freq) {
                 if ($diff->{$k} != 0) {
                     $rrule['FREQ'] = $freq;
                     $rrule['INTERVAL'] = $diff->{$k};
                     // verify interval with next item
                     if (is_a($third, 'DateTime')) {
                         $diff2 = $second->diff($third);
                         if ($diff2->{$k} != $diff->{$k}) {
                             unset($rrule['INTERVAL']);
                         }
                     }
                     break;
                 }
             }
         }
         if (!$rrule['INTERVAL']) {
             $rrule['FREQ'] = 'RDATE';
         }
         $rrule['UNTIL'] = end($rrule['RDATE']);
     }
     // TODO: finish this
     $freq = sprintf('%s %d ', $this->gettext('every'), $rrule['INTERVAL']);
     $details = '';
     switch ($rrule['FREQ']) {
         case 'DAILY':
             $freq .= $this->gettext('days');
             break;
         case 'WEEKLY':
             $freq .= $this->gettext('weeks');
             break;
         case 'MONTHLY':
             $freq .= $this->gettext('months');
             break;
         case 'YEARLY':
             $freq .= $this->gettext('years');
             break;
     }
     if ($rrule['INTERVAL'] <= 1) {
         $freq = $this->gettext(strtolower($rrule['FREQ']));
     }
     if ($rrule['COUNT']) {
         $until = $this->gettext(array('name' => 'forntimes', 'vars' => array('nr' => $rrule['COUNT'])));
     } else {
         if ($rrule['UNTIL']) {
             $until = $this->gettext('recurrencend') . ' ' . format_date($rrule['UNTIL'], libcalendaring::to_php_date_format($this->rc->config->get('calendar_date_format', $this->defaults['calendar_date_format'])));
         } else {
             $until = $this->gettext('forever');
         }
     }
     return rtrim($freq . $details . ', ' . $until);
 }