From 2aef13c3b4673d16b445281a46f57931d01d2921 Mon Sep 17 00:00:00 2001 From: Vincent Dieltiens Date: Fri, 13 Aug 2021 11:23:55 +0200 Subject: [PATCH 1/4] Adds global variable 'PRODUCT_GENERATE_REF_AFTER_FORM' to allow product ref generation after the form validation --- htdocs/product/card.php | 61 ++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 4857f35b121..5600365f014 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -71,7 +71,7 @@ $mesg = ''; $error = 0; $errors = array(); $refalreadyexists = 0; $id = GETPOST('id', 'int'); -$ref = GETPOST('ref', 'alpha'); +$ref = (GETPOST('ref', 'alpha') !== '') ? GETPOST('ref', 'alpha') : null; $type = (GETPOST('type', 'int') !== '') ? GETPOST('type', 'int') : Product::TYPE_PRODUCT; $action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view'); $cancel = GETPOST('cancel', 'alpha'); @@ -93,6 +93,18 @@ $label_security_check = empty($conf->global->MAIN_SECURITY_ALLOW_UNSECURED_LABEL if (!empty($user->socid)) $socid = $user->socid; +// Load object modCodeProduct +$module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON : 'mod_codeproduct_leopard'); +if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') +{ + $module = substr($module, 0, dol_strlen($module) - 4); +} +$result = dol_include_once('/core/modules/product/'.$module.'.php'); +if ($result > 0) +{ + $modCodeProduct = new $module(); +} + $object = new Product($db); $object->type = $type; // so test later to fill $usercancxxx is correct $extrafields = new ExtraFields($db); @@ -212,9 +224,11 @@ if (empty($reshook)) } if (empty($ref)) { - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Ref')), null, 'errors'); - $action = "create"; - $error++; + if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Ref')), null, 'errors'); + $action = "create"; + $error++; + } } if (!empty($duration_value) && empty($duration_unit)) { @@ -371,6 +385,11 @@ if (empty($reshook)) $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; + if (!$ref && !empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) { + // Generate ref... + $ref = $modCodeProduct->getNextValue($object, $type); + } + if (!$error) { $id = $object->create($user); @@ -411,7 +430,9 @@ if (empty($reshook)) { $object->oldcopy = clone $object; - $object->ref = $ref; + if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) { + $object->ref = $ref; + } $object->label = GETPOST('label', $label_security_check); $object->description = dol_htmlcleanlastbr(GETPOST('desc', 'restricthtml')); $object->url = GETPOST('url'); @@ -995,15 +1016,17 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print ''; - print ''; - $tmpcode = ''; - if (!empty($modCodeProduct->code_auto)) $tmpcode = $modCodeProduct->getNextValue($object, $type); - print ''; + $tmpcode = ''; + if (!empty($modCodeProduct->code_auto)) $tmpcode = $modCodeProduct->getNextValue($object, $type); + print ''; } - print ''; // Label print ''; @@ -2176,18 +2199,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { } } -// Load object modCodeProduct -$module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON : 'mod_codeproduct_leopard'); -if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') -{ - $module = substr($module, 0, dol_strlen($module) - 4); -} -$result = dol_include_once('/core/modules/product/'.$module.'.php'); -if ($result > 0) -{ - $modCodeProduct = new $module(); -} - $tmpcode = ''; if (!empty($modCodeProduct->code_auto)) $tmpcode = $modCodeProduct->getNextValue($object, $object->type); From d1858e02b5b799e2e1192c421baa8f705f8b6843 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 17 Aug 2021 17:03:41 +0200 Subject: [PATCH 2/4] Update card.php --- htdocs/product/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 5600365f014..48ad41fcc97 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -71,8 +71,8 @@ $mesg = ''; $error = 0; $errors = array(); $refalreadyexists = 0; $id = GETPOST('id', 'int'); -$ref = (GETPOST('ref', 'alpha') !== '') ? GETPOST('ref', 'alpha') : null; -$type = (GETPOST('type', 'int') !== '') ? GETPOST('type', 'int') : Product::TYPE_PRODUCT; +$ref = (GETPOSTISSET('ref', 'alpha') ? GETPOST('ref', 'alpha') : null); +$type = (GETPOSTISSET('type', 'int') ? GETPOST('type', 'int') : Product::TYPE_PRODUCT); $action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view'); $cancel = GETPOST('cancel', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha'); From b51ac49f902640294cd920c3357af7de95806e04 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 18 Aug 2021 07:15:05 +0000 Subject: [PATCH 3/4] Fixing style errors. --- htdocs/product/card.php | 44 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 261d55948a8..ede9be76ef7 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -114,14 +114,12 @@ if (!empty($user->socid)) { // Load object modCodeProduct $module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON : 'mod_codeproduct_leopard'); -if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') -{ - $module = substr($module, 0, dol_strlen($module) - 4); +if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') { + $module = substr($module, 0, dol_strlen($module) - 4); } $result = dol_include_once('/core/modules/product/'.$module.'.php'); -if ($result > 0) -{ - $modCodeProduct = new $module(); +if ($result > 0) { + $modCodeProduct = new $module(); } $object = new Product($db); @@ -259,11 +257,11 @@ if (empty($reshook)) { $error++; } if (empty($ref)) { - if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) { - setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Ref')), null, 'errors'); - $action = "create"; - $error++; - } + if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Ref')), null, 'errors'); + $action = "create"; + $error++; + } } if (!empty($duration_value) && empty($duration_unit)) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Unit')), null, 'errors'); @@ -1099,18 +1097,18 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print dol_get_fiche_head(''); print '
'.$langs->trans("Ref").''; - if ($refalreadyexists) - { - print $langs->trans("RefAlreadyExists"); + if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) { + print '
'.$langs->trans("Ref").''; + if ($refalreadyexists) + { + print $langs->trans("RefAlreadyExists"); + } + print '
'.$langs->trans("Label").'
'; - - if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) { - print ''; - $tmpcode = ''; - if (!empty($modCodeProduct->code_auto)) { - $tmpcode = $modCodeProduct->getNextValue($object, $type); - } - print ''; + + if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) { + print ''; + $tmpcode = ''; + if (!empty($modCodeProduct->code_auto)) { + $tmpcode = $modCodeProduct->getNextValue($object, $type); + } + print ''; } // Label From fa3ba05a23773e922af85420464077708517ee21 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 18 Aug 2021 21:31:54 +0200 Subject: [PATCH 4/4] Update card.php --- htdocs/product/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index ede9be76ef7..3f2833fde52 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -88,8 +88,8 @@ $mesg = ''; $error = 0; $errors = array(); $refalreadyexists = 0; $id = GETPOST('id', 'int'); -$ref = (GETPOSTISSET('ref', 'alpha') ? GETPOST('ref', 'alpha') : null); -$type = (GETPOSTISSET('type', 'int') ? GETPOST('type', 'int') : Product::TYPE_PRODUCT); +$ref = (GETPOSTISSET('ref') ? GETPOST('ref', 'alpha') : null); +$type = (GETPOSTISSET('type') ? GETPOST('type', 'int') : Product::TYPE_PRODUCT); $action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view'); $cancel = GETPOST('cancel', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha');
'.$langs->trans("Ref").''; - if ($refalreadyexists) { - print $langs->trans("RefAlreadyExists"); - } - print '
'.$langs->trans("Ref").''; + if ($refalreadyexists) { + print $langs->trans("RefAlreadyExists"); + } + print '