[bugs] [Bug 1066] Changed - [sam] spamassassin.php numeric format

bugs@bugs.horde.org bugs@bugs.horde.org
Mon, 7 Oct 2002 19:41:58 -0300


http://bugs.horde.org/show_bug.cgi?id=1066

*** shadow/1066	Mon Oct  7 16:08:17 2002
--- shadow/1066.tmp.10730	Mon Oct  7 19:41:58 2002
***************
*** 52,54 ****
--- 52,113 ----
  If the locale is using something else for the decimal separator, shouldn't the
  people using the locale do so as well? This patch would break things who expect
  us to be obeying their locale settings.
+ 
+ ------- Additional Comments From horde@jonuschat.de  10/07/02 19:41 -------
+ I'll try to explain a bit more:
+ 
+ I have selected "German" as my language for all Horde applications. SAM 
+ expects me to input 7,1 as a value for required hits. This is the only 
+ way "float" like values are accepted by the php is_numeric() function. This 
+ value will be saved as exactly 7,1 into the SQL database. Problem is that 
+ SpamAssassin itself chokes on 7,1 - it expects 7.1 as a value. 
+ 
+ Part of the problem is the database layout for SpamAssassin - it stores mixed 
+ variable types in the same field, so PHP does store the 7,1 as a string, not 
+ as a number. 
+ 
+ Basically it comes down to this: There needs to be some locale conversion done 
+ between what the user needs to input and what is saved in the database. To get 
+ from the users locale to a 'C' type locale that SpamAssassin understands a 
+ simple sprintf() is sufficient. To get from the 'C' locale to the users locale 
+ seems to be more difficult as printf() and friends don't do a conversion - the 
+ only way i found yet is with localeconv() and str_replace() paired.
+ 
+ I hope this makes the problem easier to understand. A patch to do the 
+ mentioned locale conversion is atteched. (Sorry for the wraps, seems bugzilla 
+ forces some linebreaks)
+ 
+ --- spamassassin.php.orig       Tue Oct  8 00:31:55 2002
+ +++ spamassassin.php    Tue Oct  8 00:34:21 2002
+ @@ -26,7 +26,7 @@
+      /* Store the 'required_hits' spam option. */
+      if (is_numeric(Horde::getFormData('required_hits'))) {
+          /* Valid numeric data for 'required_hits' field. */
+ -        $sam->setOption('required_hits', Horde::getFormData('required_hits'));
+ +        $sam->setOption('required_hits', sprintf("%.1f",Horde::getFormData
+ ('required_hits')));
+      } else {
+          /* Not valid numeric data for 'required_hits' field. */
+          $notification->push(_("Non-numeric value for Required 
+ Hits"), 'horde.error');
+ @@ -59,6 +59,10 @@
+  $report_header = $sam->getOption('report_header') ? $sam->getOption
+ ('report_header') : 1;
+  $use_terse_report = $sam->getOption('use_terse_report') ? $sam->getOption
+ ('use_terse_report') : 0;
+  $defang_mime = $sam->getOption('defang_mime') ? $sam->getOption
+ ('defang_mime') : 1;
+ +
+ +/* Change output formate to match locale, avoid problems with is_numeric on 
+ resubmit of form */
+ +$localeconv_data = localeconv();
+ +$required_hits = str_replace(".",$localeconv_data
+ [decimal_point],$required_hits);
+ 
+  $help = (boolean)$conf['user']['online_help'] && $browser->hasFeature
+ ('javascript');
+  require SAM_TEMPLATES . '/common-header.inc';
+ 
+ 
+ 
+