Weird locales seem to mess with uppercase i, and php seems to like to
[squirrelmail.git] / functions / options.php
index 1828271598096f724798f3f91bcfcffaeec97ab8..0f284d0bbeebdd209cd385b11c0200976c8eb21b 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * options.php
  *
- * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Copyright (c) 1999-2003 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * Functions needed to display the options pages.
@@ -91,9 +91,7 @@ class SquirrelOption {
         }
 
         /* Check for a new value. */
-        if (isset($_POST["new_$name"])) {
-            $this->new_value = $_POST["new_$name"];
-        } else {
+       if ( !sqgetGlobalVar("new_$name", $this->new_value, SQ_POST ) ) {
             $this->new_value = '';
         }
 
@@ -276,11 +274,24 @@ class SquirrelOption {
     }
 
     function createWidget_Integer() {
-        return ($this->createWidget_String());
+
+        // add onChange javascript handler to a regular string widget
+        // which will strip out all non-numeric chars
+        return preg_replace('/>/', ' onChange="a=this.value; b=\'\'; '
+                    . 'for (i=0;i<a.length;i++) { if (a.charAt(i)>=\'0\' '
+                    . '&& a.charAt(i)<=\'9\') b += a.charAt(i); } '
+                    . 'this.value=b;">', $this->createWidget_String());
     }
 
     function createWidget_Float() {
-        return ($this->createWidget_String());
+        
+        // add onChange javascript handler to a regular string widget
+        // which will strip out all non-numeric (period also OK) chars 
+        return preg_replace('/>/', ' onChange="a=this.value; b=\'\'; '
+                    . 'for (i=0;i<a.length;i++) { if ((a.charAt(i)>=\'0\' '
+                    . '&& a.charAt(i)<=\'9\') || a.charAt(i)==\'.\') '
+                    . 'b += a.charAt(i); } this.value=b;">'
+                , $this->createWidget_String());
     }
 
     function createWidget_Boolean() {
@@ -330,12 +341,11 @@ class SquirrelOption {
 }
 
 function save_option($option) {
-    if ( (float)substr(PHP_VERSION,0,3) < 4.1 ) {
-        global $_SESSION;
+    if ( !sqgetGlobalVar('username', $username, SQ_SESSION ) ) {
+        /* Can't save the pref if we don't have the username */
+        return;
     }
     global $data_dir;
-    $username = $_SESSION['username'];
-
     setPref($data_dir, $username, $option->name, $option->new_value);
 }