Exemplo n.º 1
0
 /**
  * Read available calendars for the current user and store them internally
  */
 private function _read_lists($force = false)
 {
     // already read sources
     if (isset($this->lists) && !$force) {
         return $this->lists;
     }
     // get all folders that have type "task"
     $this->folders = kolab_storage::get_folders('task');
     $this->lists = array();
     // convert to UTF8 and sort
     $names = array();
     $default_folder = null;
     foreach ($this->folders as $folder) {
         $names[$folder->name] = rcube_charset::convert($folder->name, 'UTF7-IMAP');
         $this->folders[$folder->name] = $folder;
         if ($folder->default) {
             $default_folder = $folder->name;
         }
     }
     asort($names, SORT_LOCALE_STRING);
     // put default folder (aka INBOX) on top of the list
     if ($default_folder) {
         $default_name = $names[$default_folder];
         unset($names[$default_folder]);
         $names = array_merge(array($default_folder => $default_name), $names);
     }
     $delim = $this->rc->get_storage()->get_hierarchy_delimiter();
     $listnames = array();
     $prefs = $this->rc->config->get('kolab_tasklists', array());
     foreach ($names as $utf7name => $name) {
         $folder = $this->folders[$utf7name];
         $path_imap = explode($delim, $name);
         $editname = array_pop($path_imap);
         // pop off raw name part
         $path_imap = join($delim, $path_imap);
         $name = kolab_storage::folder_displayname(kolab_storage::object_name($utf7name), $listnames);
         if ($folder->get_namespace() == 'personal') {
             $readonly = false;
             $alarms = true;
         } else {
             $alarms = false;
             $readonly = true;
             if (($rights = $folder->get_myrights()) && !PEAR::isError($rights)) {
                 if (strpos($rights, 'i') !== false) {
                     $readonly = false;
                 }
             }
         }
         $list_id = kolab_storage::folder_id($utf7name);
         $tasklist = array('id' => $list_id, 'name' => $name, 'editname' => $editname, 'color' => $folder->get_color('0000CC'), 'showalarms' => isset($prefs[$list_id]['showalarms']) ? $prefs[$list_id]['showalarms'] : $alarms, 'editable' => !$readonly, 'active' => $folder->is_active(), 'parentfolder' => $path_imap, 'default' => $folder->default, 'children' => true, 'class_name' => trim($folder->get_namespace() . ($folder->default ? ' default' : '')));
         $this->lists[$tasklist['id']] = $tasklist;
         $this->folders[$tasklist['id']] = $folder;
     }
 }
Exemplo n.º 2
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);
 }
 /**
  * Get a list of available task lists from this source
  */
 public function get_lists(&$tree = null)
 {
     // attempt to create a default list for this user
     if (empty($this->lists) && !isset($this->search_more_results)) {
         $prop = array('name' => 'Tasks', 'color' => '0000CC', 'default' => true);
         if ($this->create_list($prop)) {
             $this->_read_lists(true);
         }
     }
     $folders = array();
     foreach ($this->lists as $id => $list) {
         if (!empty($this->folders[$id])) {
             $folders[] = $this->folders[$id];
         }
     }
     // include virtual folders for a full folder tree
     if (!is_null($tree)) {
         $folders = kolab_storage::folder_hierarchy($folders, $tree);
     }
     $delim = $this->rc->get_storage()->get_hierarchy_delimiter();
     $prefs = $this->rc->config->get('kolab_tasklists', array());
     $lists = array();
     foreach ($folders as $folder) {
         $list_id = $folder->id;
         // kolab_storage::folder_id($folder->name);
         $imap_path = explode($delim, $folder->name);
         // find parent
         do {
             array_pop($imap_path);
             $parent_id = kolab_storage::folder_id(join($delim, $imap_path));
         } while (count($imap_path) > 1 && !$this->folders[$parent_id]);
         // restore "real" parent ID
         if ($parent_id && !$this->folders[$parent_id]) {
             $parent_id = kolab_storage::folder_id($folder->get_parent());
         }
         $fullname = $folder->get_name();
         $listname = $folder->get_foldername();
         // special handling for virtual folders
         if ($folder instanceof kolab_storage_folder_user) {
             $lists[$list_id] = array('id' => $list_id, 'name' => $folder->get_name(), 'listname' => $listname, 'title' => $folder->get_title(), 'virtual' => true, 'editable' => false, 'rights' => 'l', 'group' => 'other virtual', 'class' => 'user', 'parent' => $parent_id);
         } else {
             if ($folder->virtual) {
                 $lists[$list_id] = array('id' => $list_id, 'name' => kolab_storage::object_name($fullname), 'listname' => $listname, 'virtual' => true, 'editable' => false, 'rights' => 'l', 'group' => $folder->get_namespace(), 'class' => 'folder', 'parent' => $parent_id);
             } else {
                 if (!$this->lists[$list_id]) {
                     $this->lists[$list_id] = $this->folder_props($folder, $prefs);
                     $this->folders[$list_id] = $folder;
                 }
                 $this->lists[$list_id]['parent'] = $parent_id;
                 $lists[$list_id] = $this->lists[$list_id];
             }
         }
     }
     return $lists;
 }