thomascube
2011-08-18 fbe54043cf598b19a753dc2b21a7ed558d23fd15
program/steps/settings/edit_folder.inc
@@ -24,7 +24,7 @@
// init IMAP connection
$RCMAIL->imap_connect();
function rcube_folder_form($attrib)
function rcmail_folder_form($attrib)
{
    global $RCMAIL;
@@ -36,25 +36,38 @@
    $parent      = trim(get_input_value('_path', RCUBE_INPUT_GPC, true));
    $parent_imap = rcube_charset_convert($parent, RCMAIL_CHARSET, 'UTF7-IMAP');
    $delimiter = $RCMAIL->imap->get_hierarchy_delimiter();
    $special   = (strlen($mbox_imap) && in_array($mbox_imap, (array) $RCMAIL->config->get('default_imap_folders')));
    $protected = ($special && $RCMAIL->config->get('protect_default_folders'));
    $threading_supported = $RCMAIL->imap->get_capability('THREAD');
    $delimiter = $RCMAIL->imap->get_hierarchy_delimiter();
    // Get mailbox stats (messages count, etc.), mailbox name and parent
    // Get mailbox parameters
    if (strlen($mbox)) {
        $msgcount = $RCMAIL->imap->messagecount($mbox_imap, 'ALL', true, false);
        $options   = rcmail_folder_options($mbox_imap);
        $namespace = $RCMAIL->imap->get_namespace();
        $path   = explode($delimiter, $mbox_imap);
        $folder = array_pop($path);
        $path   = implode($delimiter, $path);
        $folder = rcube_charset_convert($folder, 'UTF7-IMAP');
        $hidden_fields = array('name' => '_mbox', 'value' => $mbox);
    }
    else {
        $path = $parent_imap;
        $options = array();
        $path    = $parent_imap;
        // allow creating subfolders of INBOX folder
        if ($path == 'INBOX') {
            $path = $RCMAIL->imap->mod_mailbox($path, 'in');
        }
    }
    // remove personal namespace prefix
    if (strlen($path)) {
        $path_id = $path;
        $path    = $RCMAIL->imap->mod_mailbox($path.$delimiter);
        if ($path[strlen($path)-1] == $delimiter) {
            $path = substr($path, 0, -1);
        }
    }
    $form = array();
@@ -65,8 +78,12 @@
    );
    // Location (name)
    if ($protected)
        $foldername = rcmail_localize_foldername($mbox_imap);
    if ($options['protected']) {
        $foldername = Q(str_replace($delimiter, ' » ', rcmail_localize_folderpath($mbox_imap)));
    }
    else if ($options['norename']) {
        $foldername = Q($folder);
    }
    else {
        if (isset($_POST['_name']))
            $folder = trim(get_input_value('_name', RCUBE_INPUT_POST, true));
@@ -74,8 +91,9 @@
        $foldername = new html_inputfield(array('name' => '_name', 'id' => '_name', 'size' => 30));
        $foldername = $foldername->show($folder);
        if ($special)
            $foldername .= ' (' . rcmail_localize_foldername($mbox_imap) .')';
        if ($options['special']) {
            $foldername .= ' (' . Q(rcmail_localize_foldername($mbox_imap)) .')';
        }
    }
    $form['props']['fieldsets']['location'] = array(
@@ -88,19 +106,25 @@
        ),
    );
    if (strlen($path)) {
        $radio1 = new html_radiobutton(array('name' => '_parent', 'value' => ''));
        $radio2 = new html_radiobutton(array('name' => '_parent', 'value' => $path));
        $selected  = isset($_POST['_parent']) ? $_POST['_parent'] : $path;
        $html_path = str_replace($delimiter, ' » ', rcmail_localize_folderpath($path));
        $folderpath = $radio1->show($selected) . Q(rcube_label('none')) . ' '
            .$radio2->show($selected) . Q($html_path);
    if (!empty($options) && ($options['norename'] || $options['protected'])) {
        // prevent user from moving folder
        $hidden_path = new html_hiddenfield(array('name' => '_parent', 'value' => $path));
        $form['props']['fieldsets']['location']['content']['name']['value'] .= $hidden_path->show();
    }
    else {
        $selected = isset($_POST['_parent']) ? $_POST['_parent'] : $path_id;
        $select = rcmail_mailbox_select(array(
            'name'        => '_parent',
            'noselection' => '---',
            'realnames'   => false,
            'maxlength'   => 150,
            'unsubscribed' => true,
            'exceptions' => array($mbox_imap),
        ));
        $form['props']['fieldsets']['location']['content']['path'] = array(
            'label' => rcube_label('parentfolder'),
            'value' => $folderpath,
            'value' => $select->show($selected),
        );
    }
@@ -110,7 +134,7 @@
    );
    // Settings: threading
    if ($threading_supported) {
    if ($threading_supported && !$options['noselect'] && !$options['is_root']) {
        $select = new html_select(array('name' => '_viewmode', 'id' => '_listmode'));
        $select->add(rcube_label('list'), 0);
        $select->add(rcube_label('threads'), 1);
@@ -164,34 +188,47 @@
        // Number of messages
        $form['props']['fieldsets']['info'] = array(
            'name'  => rcube_label('info'),
            'content' => array(
                'count' => array(
                    'label' => rcube_label('messagecount'),
                    'value' => (int) $msgcount,
                ),
            ),
            'content' => array()
        );
        // Size
        if ($msgcount) {
            // create link with folder-size command
            $onclick = sprintf("return %s.command('folder-size', '%s', this)",
                JS_OBJECT_NAME, JQ($mbox_imap));
            $size = html::a(array('href' => '#', 'onclick' => $onclick, 'id' => 'folder-size'),
                rcube_label('getfoldersize'));
        if (!$options['noselect'] && !$options['is_root']) {
            $msgcount = $RCMAIL->imap->messagecount($mbox_imap, 'ALL', true, false);
            // Size
            if ($msgcount) {
                // create link with folder-size command
                $onclick = sprintf("return %s.command('folder-size', '%s', this)",
                    JS_OBJECT_NAME, JQ($mbox_imap));
                $size = html::a(array('href' => '#', 'onclick' => $onclick,
                    'id' => 'folder-size'), rcube_label('getfoldersize'));
            }
            else {
                // no messages -> zero size
                $size = 0;
            }
            $form['props']['fieldsets']['info']['content']['count'] = array(
                'label' => rcube_label('messagecount'),
                'value' => (int) $msgcount
            );
            $form['props']['fieldsets']['info']['content']['size'] = array(
                'label' => rcube_label('size'),
                'value' => $size,
            );
        }
        else {
            // no messages -> zero size
            $size = 0;
        // show folder type only if we have non-private namespaces
        if (!empty($namespace['shared']) || !empty($namespace['others'])) {
            $form['props']['fieldsets']['info']['content']['foldertype'] = array(
                'label' => rcube_label('foldertype'),
                'value' => rcube_label($options['namespace'] . 'folder'));
        }
        $form['props']['fieldsets']['info']['content']['size'] = array(
            'label' => rcube_label('size'),
            'value' => $size,
        );
    }
    // Allow plugins to modify folder form content
    $plugin = $RCMAIL->plugins->exec_hook('folder_form', array('form' => $form));
    $plugin = $RCMAIL->plugins->exec_hook('folder_form',
        array('form' => $form, 'options' => $options,
            'name' => $mbox_imap, 'parent_name' => $parent_imap));
    $form = $plugin['form'];
@@ -218,7 +255,7 @@
            $content = rcmail_get_form_part($tab);
        }
        if ($content) {
        if ($content) {
            $out .= html::tag('fieldset', null, html::tag('legend', null, Q($tab['name'])) . $content) ."\n";
        }
    }
@@ -252,39 +289,12 @@
    return $content;
}
function rcmail_localize_folderpath($path)
{
    global $RCMAIL;
    $protect_folders = $RCMAIL->config->get('protect_default_folders');
    $default_folders = (array) $RCMAIL->config->get('default_imap_folders');
    $delimiter       = $RCMAIL->imap->get_hierarchy_delimiter();
    $path            = explode($delimiter, $path);
    $result          = array();
    foreach ($path as $idx => $dir) {
        $directory = implode($delimiter, array_slice($path, 0, $idx+1));
        if ($protect_folders && in_array($directory, $default_folders)) {
            unset($result);
            $result[] = rcmail_localize_foldername($directory);
        }
        else if ($protect_folders && in_array($dir, $default_folders)) {
            $result[] = rcmail_localize_foldername($dir);
        }
        else {
            $result[] = rcube_charset_convert($dir, 'UTF7-IMAP');
        }
    }
    return implode($delimiter, $result);
}
//$OUTPUT->set_pagetitle(rcube_label('folders'));
// register UI objects
$OUTPUT->add_handlers(array(
    'folderdetails' => 'rcube_folder_form',
    'folderdetails' => 'rcmail_folder_form',
));
$OUTPUT->add_label('nonamewarning');