Esempio n. 1
0
 /**
  * Callback function to produce driver-specific calendar create/edit form
  *
  * @param string Request action 'form-edit|form-new'
  * @param array  Calendar properties (e.g. id, color)
  * @param array  Edit form fields
  *
  * @return string HTML content of the form
  */
 public function calendar_form($action, $calendar, $formfields)
 {
     // show default dialog for birthday calendar
     if (in_array($calendar['id'], array(self::BIRTHDAY_CALENDAR_ID, self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED))) {
         if ($calendar['id'] != self::BIRTHDAY_CALENDAR_ID) {
             unset($formfields['showalarms']);
         }
         return parent::calendar_form($action, $calendar, $formfields);
     }
     if ($calendar['id'] && ($cal = $this->calendars[$calendar['id']])) {
         $folder = $cal->get_realname();
         // UTF7
         $color = $cal->get_color();
     } else {
         $folder = '';
         $color = '';
     }
     $hidden_fields[] = array('name' => 'oldname', 'value' => $folder);
     $storage = $this->rc->get_storage();
     $delim = $storage->get_hierarchy_delimiter();
     $form = array();
     if (strlen($folder)) {
         $path_imap = explode($delim, $folder);
         array_pop($path_imap);
         // pop off name part
         $path_imap = implode($path_imap, $delim);
         $options = $storage->folder_info($folder);
     } else {
         $path_imap = '';
     }
     // General tab
     $form['props'] = array('name' => $this->rc->gettext('properties'));
     // Disable folder name input
     if (!empty($options) && ($options['norename'] || $options['protected'])) {
         $input_name = new html_hiddenfield(array('name' => 'name', 'id' => 'calendar-name'));
         $formfields['name']['value'] = kolab_storage::object_name($folder) . $input_name->show($folder);
     }
     // calendar name (default field)
     $form['props']['fieldsets']['location'] = array('name' => $this->rc->gettext('location'), 'content' => array('name' => $formfields['name']));
     if (!empty($options) && ($options['norename'] || $options['protected'])) {
         // prevent user from moving folder
         $hidden_fields[] = array('name' => 'parent', 'value' => $path_imap);
     } else {
         $select = kolab_storage::folder_selector('event', array('name' => 'parent', 'id' => 'calendar-parent'), $folder);
         $form['props']['fieldsets']['location']['content']['path'] = array('id' => 'calendar-parent', 'label' => $this->cal->gettext('parentcalendar'), 'value' => $select->show(strlen($folder) ? $path_imap : ''));
     }
     // calendar color (default field)
     $form['props']['fieldsets']['settings'] = array('name' => $this->rc->gettext('settings'), 'content' => array('color' => $formfields['color'], 'showalarms' => $formfields['showalarms']));
     if ($action != 'form-new') {
         $form['sharing'] = array('name' => rcube::Q($this->cal->gettext('tabsharing')), 'content' => html::tag('iframe', array('src' => $this->cal->rc->url(array('_action' => 'calendar-acl', 'id' => $calendar['id'], 'framed' => 1)), 'width' => '100%', 'height' => 350, 'border' => 0, 'style' => 'border:0'), ''));
     }
     $this->form_html = '';
     if (is_array($hidden_fields)) {
         foreach ($hidden_fields as $field) {
             $hiddenfield = new html_hiddenfield($field);
             $this->form_html .= $hiddenfield->show() . "\n";
         }
     }
     // Create form output
     foreach ($form as $tab) {
         if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) {
             $content = '';
             foreach ($tab['fieldsets'] as $fieldset) {
                 $subcontent = $this->get_form_part($fieldset);
                 if ($subcontent) {
                     $content .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($fieldset['name'])) . $subcontent) . "\n";
                 }
             }
         } else {
             $content = $this->get_form_part($tab);
         }
         if ($content) {
             $this->form_html .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($tab['name'])) . $content) . "\n";
         }
     }
     // Parse form template for skin-dependent stuff
     $this->rc->output->add_handler('calendarform', array($this, 'calendar_form_html'));
     return $this->rc->output->parse('calendar.kolabform', false, false);
 }
 /**
  * Callback function to produce driver-specific calendar create/edit form
  *
  * @param string Request action 'form-edit|form-new'
  * @param array  Calendar properties (e.g. id, color)
  * @param array  Edit form fields
  *
  * @return string HTML content of the form
  */
 public function calendar_form($action, $calendar, $formfields)
 {
     $cal_id = $calendar['id'];
     $protected = array();
     $preinstalled_calendars = $this->rc->config->get('calendar_preinstalled_calendars', array());
     $props = $this->_get_calendar_props($cal_id);
     foreach ($preinstalled_calendars as $idx => $properties) {
         if ($properties['driver'] == 'database') {
             if (isset($properties['protected']) && $props['name'] == $properties['name']) {
                 $protected = $properties['protected'];
                 break;
             }
         }
     }
     if ($protected['name']) {
         $formfields['name'] = str_replace('<input ', '<input readonly="readonly" ', $formfields['name']);
     }
     if ($protected['color']) {
         unset($formfields['color']);
     }
     if ($protected['showalarms']) {
         $formfields['showalarms'] = str_replace('<input ', '<input disabled="disabled" ', $formfields['showalarms']);
     }
     if ($this->freebusy && !isset($formfields['freebusy'])) {
         $enabled = $action == 'form-new' ? true : $this->calendars[$cal_id]['freebusy'];
         $readonly = array();
         if ($protected['freebusy']) {
             $readonly = array('disabled' => 'disabled');
         }
         $input_freebusy = new html_checkbox(array_merge(array("name" => "freebusy", "title" => $this->cal->gettext("allowfreebusy"), "id" => "chbox_freebusy", "value" => 1), $readonly));
         $formfields['freebusy'] = array("label" => $this->cal->gettext('freebusy'), "value" => $input_freebusy->show($enabled ? 1 : 0), "id" => "freebusy");
     }
     if (!$this->rc->config->get('calendar_disable_tasks', false) && !isset($formfields['tasks'])) {
         $enabled = $action == 'form-new' ? true : $this->calendars[$cal_id]['tasks'];
         $readonly = array();
         if ($protected['tasks']) {
             $readonly = array('disabled' => 'disabled');
         }
         $input_tasks = new html_checkbox(array_merge(array("name" => "tasks", "id" => "chbox_tasks", "value" => 1), $readonly));
         $formfields["tasks"] = array("label" => $this->cal->gettext("tasks"), "value" => $input_tasks->show($enabled ? 1 : 0), "id" => "tasks");
     }
     return parent::calendar_form($action, $calendar, $formfields);
 }