From a3644638aaf0418598196a870204e0b632a4c8ad Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Fri, 17 Apr 2015 06:28:40 -0400
Subject: [PATCH] Allow preference sections to define CSS class names

---
 program/steps/settings/edit_folder.inc |   52 ++++++++++++++++++++++++++++++----------------------
 1 files changed, 30 insertions(+), 22 deletions(-)

diff --git a/program/steps/settings/edit_folder.inc b/program/steps/settings/edit_folder.inc
index fc6b2cd..f34e3c5 100644
--- a/program/steps/settings/edit_folder.inc
+++ b/program/steps/settings/edit_folder.inc
@@ -38,22 +38,20 @@
     $storage = $RCMAIL->get_storage();
 
     // edited folder name (empty in create-folder mode)
-    $mbox      = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GPC, true);
-    $mbox_imap = rcube_charset::convert($mbox, RCUBE_CHARSET, 'UTF7-IMAP');
+    $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GPC, true);
 
     // predefined path for new folder
-    $parent      = rcube_utils::get_input_value('_path', rcube_utils::INPUT_GPC, true);
-    $parent_imap = rcube_charset::convert($parent, RCUBE_CHARSET, 'UTF7-IMAP');
+    $parent = rcube_utils::get_input_value('_path', rcube_utils::INPUT_GPC, true);
 
     $threading_supported = $storage->get_capability('THREAD');
     $delimiter = $storage->get_hierarchy_delimiter();
 
     // Get mailbox parameters
     if (strlen($mbox)) {
-        $options   = rcmail_folder_options($mbox_imap);
+        $options   = rcmail_folder_options($mbox);
         $namespace = $storage->get_namespace();
 
-        $path   = explode($delimiter, $mbox_imap);
+        $path   = explode($delimiter, $mbox);
         $folder = array_pop($path);
         $path   = implode($delimiter, $path);
         $folder = rcube_charset::convert($folder, 'UTF7-IMAP');
@@ -62,7 +60,7 @@
     }
     else {
         $options = array();
-        $path    = $parent_imap;
+        $path    = $parent;
 
         // allow creating subfolders of INBOX folder
         if ($path == 'INBOX') {
@@ -88,7 +86,7 @@
 
     // Location (name)
     if ($options['protected']) {
-        $foldername = str_replace($delimiter, ' &raquo; ', rcube::Q($RCMAIL->localize_folderpath($mbox_imap)));
+        $foldername = str_replace($delimiter, ' &raquo; ', rcube::Q($RCMAIL->localize_folderpath($mbox)));
     }
     else if ($options['norename']) {
         $foldername = rcube::Q($folder);
@@ -101,7 +99,7 @@
         $foldername = $foldername->show($folder);
 
         if ($options['special']) {
-            $foldername .= '&nbsp;(' . rcube::Q($RCMAIL->localize_foldername($mbox_imap)) .')';
+            $foldername .= '&nbsp;(' . rcube::Q($RCMAIL->localize_foldername($mbox)) .')';
         }
     }
 
@@ -122,7 +120,7 @@
     }
     else {
         $selected = isset($_POST['_parent']) ? $_POST['_parent'] : $path_id;
-        $exceptions = array($mbox_imap);
+        $exceptions = array($mbox);
 
         // Exclude 'prefix' namespace from parent folders list (#1488349)
         // If INBOX. namespace exists, folders created as INBOX subfolders
@@ -132,13 +130,14 @@
         }
 
         $select = $RCMAIL->folder_selector(array(
+            'id'          => '_parent',
             'name'        => '_parent',
             'noselection' => '---',
-            'realnames'   => false,
             'maxlength'   => 150,
             'unsubscribed' => true,
             'skip_noinferiors' => true,
             'exceptions'  => $exceptions,
+            'additional'  => strlen($selected) ? array($selected) : null,
         ));
 
         $form['props']['fieldsets']['location']['content']['path'] = array(
@@ -153,17 +152,19 @@
     );
 
     // Settings: threading
-    if ($threading_supported && ($mbox_imap == 'INBOX' || (!$options['noselect'] && !$options['is_root']))) {
-        $select = new html_select(array('name' => '_viewmode', 'id' => '_listmode'));
+    if ($threading_supported && ($mbox == 'INBOX' || (!$options['noselect'] && !$options['is_root']))) {
+        $select = new html_select(array('name' => '_viewmode', 'id' => '_viewmode'));
         $select->add($RCMAIL->gettext('list'), 0);
         $select->add($RCMAIL->gettext('threads'), 1);
 
         if (isset($_POST['_viewmode'])) {
             $value = (int) $_POST['_viewmode'];
         }
-        else if (strlen($mbox_imap)) {
-            $a_threaded = $RCMAIL->config->get('message_threading', array());
-            $value = (int) isset($a_threaded[$mbox_imap]);
+        else if (strlen($mbox)) {
+            $a_threaded   = $RCMAIL->config->get('message_threading', array());
+            $default_mode = $RCMAIL->config->get('default_list_mode', 'list');
+
+            $value = (int) (isset($a_threaded[$mbox]) ? $a_threaded[$mbox] : $default_mode == 'threads');
         }
 
         $form['props']['fieldsets']['settings']['content']['viewmode'] = array(
@@ -210,14 +211,14 @@
             'content' => array()
         );
 
-        if ((!$options['noselect'] && !$options['is_root']) || $mbox_imap == 'INBOX') {
-            $msgcount = $storage->count($mbox_imap, 'ALL', true, false);
+        if ((!$options['noselect'] && !$options['is_root']) || $mbox == 'INBOX') {
+            $msgcount = $storage->count($mbox, 'ALL', true, false);
 
             // Size
             if ($msgcount) {
                 // create link with folder-size command
                 $onclick = sprintf("return %s.command('folder-size', '%s', this)",
-                    rcmail_output::JS_OBJECT_NAME, rcube::JQ($mbox_imap));
+                    rcmail_output::JS_OBJECT_NAME, rcube::JQ($mbox));
                 $size = html::a(array('href' => '#', 'onclick' => $onclick,
                     'id' => 'folder-size'), $RCMAIL->gettext('getfoldersize'));
             }
@@ -247,7 +248,7 @@
     // Allow plugins to modify folder form content
     $plugin = $RCMAIL->plugins->exec_hook('folder_form',
         array('form' => $form, 'options' => $options,
-            'name' => $mbox_imap, 'parent_name' => $parent_imap));
+            'name' => $mbox, 'parent_name' => $parent));
 
     $form = $plugin['form'];
 
@@ -260,7 +261,7 @@
     $out = "$form_start\n";
 
     // Create form output
-    foreach ($form as $tab) {
+    foreach ($form as $idx => $tab) {
         if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) {
             $content = '';
             foreach ($tab['fieldsets'] as $fieldset) {
@@ -275,7 +276,7 @@
             $content = rcmail_get_form_part($tab, $attrib);
         }
 
-        if ($content && sizeof($form) > 1) {
+        if ($idx != 'props') {
             $out .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($tab['name'])) . $content) ."\n";
         }
         else {
@@ -286,12 +287,19 @@
     $out .= "\n$form_end";
 
     $RCMAIL->output->set_env('messagecount', (int) $msgcount);
+    $RCMAIL->output->set_env('folder', $mbox);
+
+    if ($mbox !== null && empty($_POST)) {
+        $RCMAIL->output->command('parent.set_quota', $RCMAIL->quota_content(null, $mbox));
+    }
 
     return $out;
 }
 
 function rcmail_get_form_part($form, $attrib = array())
 {
+    global $RCMAIL;
+
     $content = '';
 
     if (is_array($form['content']) && !empty($form['content'])) {

--
Gitblit v1.9.1