From 8ace96f495ff8650c495077d681a02c945bebc04 Mon Sep 17 00:00:00 2001 From: ATM john Date: Fri, 14 Jan 2022 11:46:31 +0100 Subject: [PATCH 1/3] Fix validate class lang load and test for numeric values --- htdocs/core/class/commonobject.class.php | 2 +- htdocs/core/class/validate.class.php | 22 ++++++++++++++++++---- htdocs/langs/en_US/errors.lang | 1 + 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 029ac6cbfc1..2d5ae6ca78b 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -7595,7 +7595,7 @@ abstract class CommonObject } else { return true; } } elseif (in_array($type, array('double', 'real', 'price'))) { // is numeric - if (!$validate->isDuration($fieldValue)) { + if (!$validate->isNumeric($fieldValue)) { $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } diff --git a/htdocs/core/class/validate.class.php b/htdocs/core/class/validate.class.php index 389bb708e82..4b500b0ae4c 100644 --- a/htdocs/core/class/validate.class.php +++ b/htdocs/core/class/validate.class.php @@ -55,18 +55,17 @@ class Validate { global $langs; - if ($outputLang) { + if (empty($outputLang)) { $this->outputLang = $langs; } else { $this->outputLang = $outputLang; } - if (!is_object($this->outputLang) || !method_exists($outputLang, 'load')) { + if (!is_object($this->outputLang) || !method_exists($this->outputLang, 'load')) { return false; } - /** @var Translate $outputLang */ - $outputLang->load('validate'); + $this->outputLang->loadLangs(array('validate', 'errors')); $this->db = $db; } @@ -229,6 +228,21 @@ class Validate return true; } + /** + * Check Duration validity + * + * @param mixed $string to validate + * @return boolean Validity is ok or not + */ + public function isNumeric($string) + { + if (!is_numeric($string)) { + $this->error = $this->outputLang->trans('RequireValidNumeric'); + return false; + } + return true; + } + /** * Check for boolean validity * diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 7f4ca7b074f..293bf4ad53b 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -315,6 +315,7 @@ RequireAtLeastXString = Requires at least %s character(s) RequireXStringMax = Requires %s character(s) max RequireAtLeastXDigits = Requires at least %s digit(s) RequireXDigitsMax = Requires %s digit(s) max +RequireValidNumeric = Requires a numeric value RequireValidEmail = Email address is not valid RequireMaxLength = Length must be less than %s chars RequireMinLength = Length must be more than %s char(s) From a394713f1bb8eda51d7a35c179bf3ee22683df79 Mon Sep 17 00:00:00 2001 From: ATM john Date: Fri, 14 Jan 2022 11:51:07 +0100 Subject: [PATCH 2/3] Fix doc comment --- htdocs/core/class/validate.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/validate.class.php b/htdocs/core/class/validate.class.php index 4b500b0ae4c..61251167c21 100644 --- a/htdocs/core/class/validate.class.php +++ b/htdocs/core/class/validate.class.php @@ -229,7 +229,7 @@ class Validate } /** - * Check Duration validity + * Check numeric validity * * @param mixed $string to validate * @return boolean Validity is ok or not From 89869a248583bf8cb58f9f4004e727cfe75e51ef Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Sat, 15 Jan 2022 12:09:36 +0100 Subject: [PATCH 3/3] Fix view after generate export --- htdocs/admin/tools/dolibarr_export.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/admin/tools/dolibarr_export.php b/htdocs/admin/tools/dolibarr_export.php index d6700cedf04..5f9dc97ba44 100644 --- a/htdocs/admin/tools/dolibarr_export.php +++ b/htdocs/admin/tools/dolibarr_export.php @@ -400,8 +400,6 @@ print ''; print ''; print ''; -print ''; -print ''; @@ -538,6 +536,8 @@ if (!empty($_SESSION["commandbackuptorun"])) { print " \n"; +print ''; +print ''; print " \n";