Make use of mailbox cache because flag info is updated in the mailbox cache
[squirrelmail.git] / functions / options.php
index abfe9fc16cf57af71ff6824652c9086e6fb093fa..24b094effe714a843a9a709a6e4bf3b4f430d4b4 100644 (file)
@@ -3,11 +3,10 @@
 /**
  * options.php
  *
- * Copyright (c) 1999-2005 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
  * Functions needed to display the options pages.
  *
+ * @copyright © 1999-2006 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
  * @subpackage prefs
@@ -143,6 +142,13 @@ class SquirrelOption {
      * @var bool
      */
     var $htmlencoded=false;
+    /**
+     * Controls folder list limits in SMOPT_TYPE_FLDRLIST widget.
+     * See $flag argument in sqimap_mailbox_option_list() function.
+     * @var string
+     * @since 1.5.1
+     */
+    var $folder_filter='noselect';
 
     /**
      * Constructor function
@@ -169,11 +175,11 @@ class SquirrelOption {
         $this->script = '';
         $this->post_script = '';
 
-        /* Check for a current value. */
-        if (!empty($initial_value)) {
-            $this->value = $initial_value;
-        } else if (isset($GLOBALS[$name])) {
+        //Check for a current value.  
+        if (isset($GLOBALS[$name])) {
             $this->value = $GLOBALS[$name];
+        } else if (!empty($initial_value)) {
+            $this->value = $initial_value;
         } else {
             $this->value = '';
         }
@@ -255,6 +261,15 @@ class SquirrelOption {
         $this->save_function = $save_function;
     }
 
+    /**
+     * Set the trailing_text for this option.
+     * @param string $folder_filter
+     * @since 1.5.1
+     */
+    function setFolderFilter($folder_filter) {
+        $this->folder_filter = $folder_filter;
+    }
+
     /**
      * Creates fields on option pages according to option type
      *
@@ -384,14 +399,14 @@ class SquirrelOption {
     function createWidget_FolderList() {
         $selected = array(strtolower($this->value));
 
-        /* Begin the select tag. */
-        $result = "<select name=\"new_$this->name\" $this->script>\n";
+        /* set initial value */
+        $result = '';
 
         /* Add each possible value to the select list. */
         foreach ($this->possible_values as $real_value => $disp_value) {
             if ( is_array($disp_value) ) {
               /* For folder list, we passed in the array of boxes.. */
-              $new_option = sqimap_mailbox_option_list(0, $selected, 0, $disp_value);
+              $new_option = sqimap_mailbox_option_list(0, $selected, 0, $disp_value, $this->folder_filter);
             } else {
               /* Start the next new option string. */
               $new_option = '<option value="' . htmlspecialchars($real_value) . '"';
@@ -407,9 +422,19 @@ class SquirrelOption {
             /* And add the new option string to our select tag. */
             $result .= $new_option;
         }
-        /* Close the select tag and return our happy result. */
-        $result .= "</select>\n";
-        return ($result);
+
+
+        if (empty($result)) {
+            // string is displayed when interface can't build folder selection box
+            return _("unavailable");
+        } else {
+            /* Begin the select tag. */
+            $ret = "<select name=\"new_$this->name\" $this->script>\n";
+            $ret.= $result;
+            /* Close the select tag and return our happy result. */
+            $ret.= "</select>\n";
+            return ($ret);
+        }
     }
 
     /**
@@ -425,10 +450,9 @@ class SquirrelOption {
             case SMOPT_SIZE_NORMAL:
             default: $rows = 5; $cols =  50;
         }
-        $result = "<textarea name=\"new_$this->name\" rows=\"$rows\" "
-                . "cols=\"$cols\" $this->script>"
-                . htmlspecialchars($this->value) . "</textarea>\n";
-        return ($result);
+//FIXME: we need to change $this->script into $this->aExtraAttribs, and anyone who wants to add some javascript or other attributes to an options widget can put them in an array and pass them as extra attributes (key == attrib name, value == attrib value).... for now, this is the only place it is used, and there is no place in the code that text areas get extra attribs or javascript... in fact the only place that was using $this->script is include/options/display.php:200, so that's easy to change.... just have to go through this file and change all the places that use "script"
+$this->aExtraAttribs = array();
+        return addTextArea('new_' . $this->name, $this->value, $cols, $rows, $this->aExtraAttribs);
     }
 
     /**
@@ -438,11 +462,10 @@ class SquirrelOption {
      * @return string html formated option field
      */
     function createWidget_Integer() {
-        global $javascript_on;
 
         // add onChange javascript handler to a regular string widget
         // which will strip out all non-numeric chars
-        if ($javascript_on)
+        if (checkForJavascript())
            return preg_replace('/\/>/', ' onChange="origVal=this.value; newVal=\'\'; '
                     . 'for (i=0;i<origVal.length;i++) { if (origVal.charAt(i)>=\'0\' '
                     . '&& origVal.charAt(i)<=\'9\') newVal += origVal.charAt(i); } '
@@ -457,11 +480,10 @@ class SquirrelOption {
      * @return string html formated option field
      */
     function createWidget_Float() {
-        global $javascript_on;
 
         // add onChange javascript handler to a regular string widget
         // which will strip out all non-numeric (period also OK) chars
-        if ($javascript_on)
+        if (checkForJavascript())
            return preg_replace('/\/>/', ' onChange="origVal=this.value; newVal=\'\'; '
                     . 'for (i=0;i<origVal.length;i++) { if ((origVal.charAt(i)>=\'0\' '
                     . '&& origVal.charAt(i)<=\'9\') || origVal.charAt(i)==\'.\') '
@@ -650,6 +672,11 @@ function create_option_groups($optgrps, $optvals) {
                 $next_option->setPostScript($optset['post_script']);
             }
 
+            /* If provided, set the folder_filter for this option. */
+            if (isset($optset['folder_filter'])) {
+                $next_option->setFolderFilter($optset['folder_filter']);
+            }
+
             /* Add this option to the option array. */
             $result[$grpkey]['options'][] = $next_option;
         }
@@ -659,49 +686,4 @@ function create_option_groups($optgrps, $optvals) {
     return ($result);
 }
 
-/**
- * @param array $option_groups
- */
-function print_option_groups($option_groups) {
-    /* Print each option group. */
-    foreach ($option_groups as $next_optgrp) {
-        /* If it is not blank, print the name for this option group. */
-        if ($next_optgrp['name'] != '') {
-            echo html_tag( 'tr', "\n".
-                        html_tag( 'td',
-                            '<b>' . $next_optgrp['name'] . '</b>' ,
-                        'center' ,'', 'valign="middle" colspan="2" style="white-space: nowrap;"' )
-                    ) ."\n";
-        }
-
-        /* Print each option in this option group. */
-        foreach ($next_optgrp['options'] as $option) {
-            if ($option->type != SMOPT_TYPE_HIDDEN) {
-                echo html_tag( 'tr', "\n".
-                           html_tag( 'td', $option->caption . ':', 'right' ,'', 'valign="middle"' ) .
-                           html_tag( 'td', $option->createHTMLWidget(), 'left' )
-                       ) ."\n";
-            } else {
-                echo $option->createHTMLWidget();
-            }
-        }
-
-        /* Print an empty row after this option group. */
-        echo html_tag( 'tr',
-                   html_tag( 'td', '&nbsp;', 'left', '', 'colspan="2"' )
-                ) . "\n";
-    }
-}
-
-/**
- * Create submit button inside table row.
- * @param string $name
- */
-function OptionSubmit( $name ) {
-        echo html_tag( 'tr',
-                   html_tag( 'td', '<input type="submit" value="' . _("Submit") . '" name="' . $name . '" />&nbsp;&nbsp;&nbsp;&nbsp;', 'right', '', 'colspan="2"' )
-                ) . "\n";
-}
-
 // vim: et ts=4
-?>
\ No newline at end of file