diff --git a/htdocs/admin/limits.php b/htdocs/admin/limits.php index 1209f41c48e..db963562deb 100644 --- a/htdocs/admin/limits.php +++ b/htdocs/admin/limits.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2007-2022 Laurent Destailleur * Copyright (C) 2009-2018 Regis Houssin * Copyright (C) 2010 Juanjo Menent * @@ -29,11 +29,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; // Load translation files required by the page $langs->loadLangs(array('companies', 'products', 'admin')); -if (!$user->admin) { - accessforbidden(); -} - $action = GETPOST('action', 'aZ09'); +$cancel = GETPOST('cancel', 'aZ09'); $currencycode = GETPOST('currencycode', 'alpha'); if (!empty($conf->multicurrency->enabled) && !empty($conf->global->MULTICURRENCY_USE_LIMIT_BY_CURRENCY)) { @@ -48,25 +45,36 @@ $mainroundingruletot = 'MAIN_ROUNDING_RULE_TOT'.(!empty($currencycode) ? '_'.$cu $valmainmaxdecimalsunit = GETPOST($mainmaxdecimalsunit, 'int'); $valmainmaxdecimalstot = GETPOST($mainmaxdecimalstot, 'int'); -$valmainmaxdecimalsshown = GETPOST($mainmaxdecimalsshown, 'int'); +$valmainmaxdecimalsshown = GETPOST($mainmaxdecimalsshown, 'alpha'); // Can be 'x.y' but also 'x...' $valmainroundingruletot = price2num(GETPOST($mainroundingruletot, 'alphanohtml'), '', 2); -if ($action == 'update') { +if (!$user->admin) { + accessforbidden(); +} + + +/* + * Actions + */ + +if ($action == 'update' && !$cancel) { $error = 0; $MAXDEC = 8; - if ($_POST[$mainmaxdecimalsunit] > $MAXDEC - || $_POST[$mainmaxdecimalstot] > $MAXDEC - || $_POST[$mainmaxdecimalsshown] > $MAXDEC) { + if ($valmainmaxdecimalsunit > $MAXDEC + || $valmainmaxdecimalstot > $MAXDEC + || $valmainmaxdecimalsshown > $MAXDEC) { $error++; setEventMessages($langs->trans("ErrorDecimalLargerThanAreForbidden", $MAXDEC), null, 'errors'); + $action = 'edit'; } - if ($_POST[$mainmaxdecimalsunit].(!empty($currencycode) ? '_'.$currencycode : '') < 0 - || $_POST[$mainmaxdecimalstot] < 0 - || $_POST[$mainmaxdecimalsshown] < 0) { + if ($valmainmaxdecimalsunit < 0 + || $valmainmaxdecimalstot < 0 + || $valmainmaxdecimalsshown < 0) { $langs->load("errors"); $error++; setEventMessages($langs->trans("ErrorNegativeValueNotAllowed"), null, 'errors'); + $action = 'edit'; } if ($valmainroundingruletot) { @@ -74,9 +82,23 @@ if ($action == 'update') { $langs->load("errors"); $error++; setEventMessages($langs->trans("ErrorMAIN_ROUNDING_RULE_TOTCanMAIN_MAX_DECIMALS_TOT"), null, 'errors'); + $action = 'edit'; } } + if ((float) $valmainmaxdecimalsshown == 0) { + $langs->load("errors"); + $error++; + setEventMessages($langs->trans("ErrorValueCantBeNull", dol_trunc(dol_string_nohtmltag($langs->transnoentitiesnoconv("MAIN_MAX_DECIMALS_SHOWN")), 40)), null, 'errors'); + $action = 'edit'; + } + if (! $error && ((float) $valmainmaxdecimalsshown < $valmainmaxdecimalsunit || (float) $valmainmaxdecimalsshown < $valmainmaxdecimalstot)) { + $langs->load("errors"); + $error++; + setEventMessages($langs->trans("ErrorValueForTooLow", dol_trunc(dol_string_nohtmltag($langs->transnoentitiesnoconv("MAIN_MAX_DECIMALS_SHOWN")), 40)), null, 'errors'); + $action = 'edit'; + } + if (!$error) { dolibarr_set_const($db, $mainmaxdecimalsunit, $valmainmaxdecimalsunit, 'chaine', 0, '', $conf->entity); dolibarr_set_const($db, $mainmaxdecimalstot, $valmainmaxdecimalstot, 'chaine', 0, '', $conf->entity); @@ -143,24 +165,25 @@ if ($action == 'edit') { print ''; print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"), $langs->trans("ParameterActiveForNextInputOnly")); - print ''; + print ''; print ''; print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_TOT"), $langs->trans("ParameterActiveForNextInputOnly")); - print ''; + print ''; print ''.$langs->trans("MAIN_MAX_DECIMALS_SHOWN").''; - print ''; + print ''; print ''; print $form->textwithpicto($langs->trans("MAIN_ROUNDING_RULE_TOT"), $langs->trans("ParameterActiveForNextInputOnly")); - print ''; + print ''; print ''; - print '
'; print '
'; - print ''; + print ''; + print '   '; + print ''; print '
'; print '
'; @@ -169,7 +192,7 @@ if ($action == 'edit') { } else { print '
'; print ''; - print ''; + print ''; print '
'.$langs->trans("Parameter").''.$langs->trans("Value").'
'.$langs->trans("Parameter").''.$langs->trans("Value").'
'; print $form->textwithpicto($langs->trans("MAIN_MAX_DECIMALS_UNIT"), $langs->trans("ParameterActiveForNextInputOnly")); @@ -190,7 +213,7 @@ if ($action == 'edit') { print ''; print ''; } diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 7cf67f10af8..8c5e7562b8b 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -291,6 +291,8 @@ ErrorAjaxRequestFailed=Request failed ErrorThirpdartyOrMemberidIsMandatory=Third party or Member of partnership is mandatory ErrorFailedToWriteInTempDirectory=Failed to write in temp directory ErrorQuantityIsLimitedTo=Quantity is limited to %s +ErrorValueForTooLow=Value for %s is too low +ErrorValueCantBeNull=Value for %s can't be null # Warnings WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup. @@ -327,7 +329,7 @@ WarningModuleXDisabledSoYouMayMissEventHere=Module %s has not been enabled. So y WarningPaypalPaymentNotCompatibleWithStrict=The value 'Strict' makes the online payment features not working correctly. Use 'Lax' instead. WarningThemeForcedTo=Warning, theme has been forced to %s by hidden constant MAIN_FORCETHEME WarningAutoValNotPossibleWhenStockIsDecreasedOnInvoiceVal=Automatic validation is disabled when option to decrease stock is set on "Invoice validation". - + # Validate RequireValidValue = Value not valid RequireAtLeastXString = Requires at least %s character(s)