From 2f2dff815532593c36f5c34c8e1d48d3b7b3bf6d Mon Sep 17 00:00:00 2001 From: Jean-Marie Arsac Date: Tue, 11 Sep 2018 14:57:31 +0200 Subject: [PATCH 1/2] Convert localized numeric extrafields value before inserting - add 'double' case in insertExtraFields and updateExtraFields to to convert localized value using price2num() --- htdocs/core/class/commonobject.class.php | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index dae9827e0e4..3a9f5e96c9b 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4851,6 +4851,9 @@ abstract class CommonObject } } + //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG); + //dol_syslog("attributeType=".$attributeType, LOG_DEBUG); + switch ($attributeType) { case 'int': @@ -4864,6 +4867,21 @@ abstract class CommonObject $new_array_options[$key] = null; } break; + case 'double': + $value = price2num($value); + if (!is_numeric($value) && $value!='') + { + dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG); + $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); + return -1; + } + elseif ($value=='') + { + $new_array_options[$key] = null; + } + //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG); + $new_array_options[$key] = $value; + break; /*case 'select': // Not required, we chosed value='0' for undefined values if ($value=='-1') { @@ -5058,6 +5076,9 @@ abstract class CommonObject $attributeParam = $extrafields->attributes[$this->table_element]['param'][$key]; $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$key]; + //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG); + //dol_syslog("attributeType=".$attributeType, LOG_DEBUG); + switch ($attributeType) { case 'int': @@ -5071,6 +5092,21 @@ abstract class CommonObject $this->array_options["options_".$key] = null; } break; + case 'double': + $value = price2num($value); + if (!is_numeric($value) && $value!='') + { + dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG); + $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); + return -1; + } + elseif ($value=='') + { + $new_array_options[$key] = null; + } + //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG); + $this->array_options["options_".$key] = $value; + break; /*case 'select': // Not required, we chosed value='0' for undefined values if ($value=='-1') { From 345c24990ef76749b9dca6aeb657133f40dc9ff7 Mon Sep 17 00:00:00 2001 From: Jean-Marie Arsac Date: Tue, 11 Sep 2018 20:51:54 +0200 Subject: [PATCH 2/2] Correction of variable name --- htdocs/core/class/commonobject.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 3a9f5e96c9b..22eba559d10 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5102,7 +5102,7 @@ abstract class CommonObject } elseif ($value=='') { - $new_array_options[$key] = null; + $this->array_options["options_".$key] = null; } //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG); $this->array_options["options_".$key] = $value;