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);
'.$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").'