diff --git a/plugins/kolab_addressbook/lib/kolab_addressbook_ui.php b/plugins/kolab_addressbook/lib/kolab_addressbook_ui.php index 6bac21b1..0b4880f5 100644 --- a/plugins/kolab_addressbook/lib/kolab_addressbook_ui.php +++ b/plugins/kolab_addressbook/lib/kolab_addressbook_ui.php @@ -163,17 +163,11 @@ class kolab_addressbook_ui $hidden_fields[] = array('name' => '_parent', 'value' => $path_imap); } else { - $radio1 = new html_radiobutton(array('name' => '_parent', 'value' => '')); - $radio2 = new html_radiobutton(array('name' => '_parent', 'value' => $path_imap)); - - $html_path = str_replace($delim, ' » ', $path); - - $folderpath = $radio1->show($path_imap) . Q(rcube_label('none')) . ' ' - .$radio2->show($path_imap) . Q($html_path); + $select = rcube_kolab::folder_selector('contact', array('name' => '_parent')); $form['props']['fieldsets']['location']['content']['path'] = array( 'label' => $this->plugin->gettext('parentbook'), - 'value' => $folderpath, + 'value' => $select->show($path_imap), ); } } diff --git a/plugins/kolab_core/rcube_kolab.php b/plugins/kolab_core/rcube_kolab.php index 2a82fbf0..74b46a86 100644 --- a/plugins/kolab_core/rcube_kolab.php +++ b/plugins/kolab_core/rcube_kolab.php @@ -377,4 +377,52 @@ class rcube_kolab return 'personal'; } + /** + * Creates a SELECT field with folders list + * + * @param string $type Folder type + * @param array $attrs SELECT field attributes (e.g. name) + * + * @return html_select SELECT object + */ + public static function folder_selector($type, $attrs) + { + // get all folders of specified type + $folders = self::get_folders($type); + + $names = array(); + foreach ($folders as $c_folder) + $names[$c_folder->name] = rcube_charset_convert($c_folder->name, 'UTF7-IMAP'); + asort($names, SORT_LOCALE_STRING); + + $folders = array_keys($names); + $names = array(); + + // Build SELECT field of parent folder + $select = new html_select($attrs); + $select->add('---', ''); + + foreach ($folders as $name) { + $imap_name = $name; + $name = $origname = self::object_name($name); + + // find folder prefix to truncate + for ($i = count($names)-1; $i >= 0; $i--) { + if (strpos($name, $names[$i].' » ') === 0) { + $length = strlen($names[$i].' » '); + $prefix = substr($name, 0, $length); + $count = count(explode(' » ', $prefix)); + $name = str_repeat('  ', $count-1) . '» ' . substr($name, $length); + break; + } + } + + $names[] = $origname; + + $select->add($name, $imap_name); + } + + return $select; + } + }