Resolve confusing var names for preferences.
[squirrelmail.git] / functions / options.php
index 71851102ec9cb6c54736b3b193b4cae90b9a7895..a8236919370cd4a2290b9c126cf8b4919fb312a0 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Functions needed to display the options pages.
  *
- * @copyright © 1999-2005 The SquirrelMail Project Team
+ * @copyright © 1999-2006 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
@@ -175,11 +175,23 @@ class SquirrelOption {
         $this->script = '';
         $this->post_script = '';
 
-        /* Check for a current value. */
+        /**
+         * Check for a current value.  If the $GLOBALS[] value exists, we also
+         * need to make sure it is the same data type as the initial value to
+         * make sure we are looking at the correct preference.
+         */
+        $var_type = NULL;        
         if (!empty($initial_value)) {
-            $this->value = $initial_value;
-        } else if (isset($GLOBALS[$name])) {
+            $var_type = gettype($initial_value);
+        } elseif (is_array($possible_values)) {
+            list($index, $x) = each ($possible_values);
+            $var_type = gettype($index);
+        }
+        
+        if (isset($GLOBALS[$name]) && (is_null($var_type) ? true : $var_type == gettype($GLOBALS[$name]))) {
             $this->value = $GLOBALS[$name];
+        } else if (!empty($initial_value)) {
+            $this->value = $initial_value;
         } else {
             $this->value = '';
         }
@@ -734,4 +746,3 @@ function OptionSubmit( $name ) {
 }
 
 // vim: et ts=4
-?>
\ No newline at end of file