Skip current folder (and its children) in folder selector to prevent moving to itself

This commit is contained in:
Aleksander Machniak (Kolab Systems) 2011-07-29 13:33:08 +02:00
parent 0f266481dd
commit f56e78fbf8
3 changed files with 23 additions and 9 deletions

View file

@ -858,10 +858,10 @@ class kolab_driver extends calendar_driver
{
// Remove any scripts/css/js
$this->rc->output->reset();
// Produce form content
$content = $this->calendar_form_content($calendar, $formfields);
// Parse form template for skin-dependent stuff
// TODO: copy scripts and styles added by other plugins (e.g. acl) from $this->rc->output
$html = $this->rc->output->parse('calendar.calendarform-kolab', false, false);
@ -920,7 +920,7 @@ class kolab_driver extends calendar_driver
$hidden_fields[] = array('name' => 'parent', 'value' => $path_imap);
}
else {
$select = rcube_kolab::folder_selector('event', array('name' => 'parent'));
$select = rcube_kolab::folder_selector('event', array('name' => 'parent'), $folder);
$form['props']['fieldsets']['location']['content']['path'] = array(
'label' => $this->cal->gettext('parentcalendar'),
'value' => $select->show($path_imap),

View file

@ -162,7 +162,7 @@ class kolab_addressbook_ui
$hidden_fields[] = array('name' => '_parent', 'value' => $path_imap);
}
else {
$select = rcube_kolab::folder_selector('contact', array('name' => '_parent'));
$select = rcube_kolab::folder_selector('contact', array('name' => '_parent'), $folder);
$form['props']['fieldsets']['location']['content']['path'] = array(
'label' => $this->plugin->gettext('parentbook'),

View file

@ -416,19 +416,33 @@ class rcube_kolab
/**
* Creates a SELECT field with folders list
*
* @param string $type Folder type
* @param array $attrs SELECT field attributes (e.g. name)
* @param string $type Folder type
* @param array $attrs SELECT field attributes (e.g. name)
* @param string $current The name of current folder (to skip it)
*
* @return html_select SELECT object
*/
public static function folder_selector($type, $attrs)
public static function folder_selector($type, $attrs, $current = '')
{
// get all folders of specified type
$folders = self::get_folders($type);
$delim = $_SESSION['delimiter'];
$names = array();
foreach ($folders as $c_folder)
$names[$c_folder->name] = rcube_charset_convert($c_folder->name, 'UTF7-IMAP');
$len = strlen($current);
// Filter folders list
foreach ($folders as $c_folder) {
$name = $c_folder->name;
// skip current folder and it's subfolders
if ($len && ($name == $current || strpos($name, $current.$delim) === 0)) {
continue;
}
$names[$name] = rcube_charset_convert($name, 'UTF7-IMAP');
}
// Sort folders list
asort($names, SORT_LOCALE_STRING);
$folders = array_keys($names);