From a253938db9a51fa0e4537700256c8bd670618440 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 31 May 2022 18:08:53 +0200 Subject: [PATCH] Better error message --- htdocs/core/lib/functions.lib.php | 15 +++++++++++++++ .../core/modules/import/import_xlsx.modules.php | 2 +- htdocs/imports/import.php | 14 -------------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 7454923f94a..c3227489507 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -183,6 +183,21 @@ function isASecretKey($keyname) return preg_match('/(_pass|password|_pw|_key|securekey|serverkey|secret\d?|p12key|exportkey|_PW_[a-z]+|token)$/i', $keyname); } + +/** + * Return a numeric value into an Excel like column number. So 1 return 'A', 2 returns 'B'..., 27 return 'AA' + * + * @param int|string $n Numeric value + * @return string Column in Excel format + */ +function num2Alpha($n) +{ + for ($r = ""; $n >= 0; $n = intval($n / 26) - 1) + $r = chr($n % 26 + 0x41) . $r; + return $r; +} + + /** * Return information about user browser * diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index 7be4ee8894a..a058fd0174a 100644 --- a/htdocs/core/modules/import/import_xlsx.modules.php +++ b/htdocs/core/modules/import/import_xlsx.modules.php @@ -446,7 +446,7 @@ class ImportXlsx extends ModeleImports // Is it a required field ? if (preg_match('/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval == '')) { - $this->errors[$error]['lib'] = $langs->trans('ErrorMissingMandatoryValue', $key); + $this->errors[$error]['lib'] = $langs->trans('ErrorMissingMandatoryValue', num2Alpha($key)); $this->errors[$error]['type'] = 'NOTNULL'; $errorforthistable++; $error++; diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index 427e6a4dea6..4209b5e9e96 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -2349,20 +2349,6 @@ function show_elem($fieldssource, $pos, $key, $var, $nostyle = '') } -/** - * Return a numeric into an Excel like column number - * - * @param string $n Numeric value - * @return string Column in Excel format - */ -function num2Alpha($n) -{ - for ($r = ""; $n >= 0; $n = intval($n / 26) - 1) - $r = chr($n%26 + 0x41) . $r; - return $r; -} - - /** * Return not used field number *