Adds global variable 'PRODUCT_GENERATE_REF_AFTER_FORM' to allow product ref generation after the form validation
This commit is contained in:
parent
0cf2164260
commit
2aef13c3b4
@ -71,7 +71,7 @@ $mesg = ''; $error = 0; $errors = array();
|
|||||||
$refalreadyexists = 0;
|
$refalreadyexists = 0;
|
||||||
|
|
||||||
$id = GETPOST('id', 'int');
|
$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;
|
$type = (GETPOST('type', 'int') !== '') ? GETPOST('type', 'int') : Product::TYPE_PRODUCT;
|
||||||
$action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view');
|
$action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view');
|
||||||
$cancel = GETPOST('cancel', 'alpha');
|
$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;
|
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 = new Product($db);
|
||||||
$object->type = $type; // so test later to fill $usercancxxx is correct
|
$object->type = $type; // so test later to fill $usercancxxx is correct
|
||||||
$extrafields = new ExtraFields($db);
|
$extrafields = new ExtraFields($db);
|
||||||
@ -212,9 +224,11 @@ if (empty($reshook))
|
|||||||
}
|
}
|
||||||
if (empty($ref))
|
if (empty($ref))
|
||||||
{
|
{
|
||||||
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Ref')), null, 'errors');
|
if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) {
|
||||||
$action = "create";
|
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Ref')), null, 'errors');
|
||||||
$error++;
|
$action = "create";
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!empty($duration_value) && empty($duration_unit))
|
if (!empty($duration_value) && empty($duration_unit))
|
||||||
{
|
{
|
||||||
@ -371,6 +385,11 @@ if (empty($reshook))
|
|||||||
$ret = $extrafields->setOptionalsFromPost(null, $object);
|
$ret = $extrafields->setOptionalsFromPost(null, $object);
|
||||||
if ($ret < 0) $error++;
|
if ($ret < 0) $error++;
|
||||||
|
|
||||||
|
if (!$ref && !empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) {
|
||||||
|
// Generate ref...
|
||||||
|
$ref = $modCodeProduct->getNextValue($object, $type);
|
||||||
|
}
|
||||||
|
|
||||||
if (!$error)
|
if (!$error)
|
||||||
{
|
{
|
||||||
$id = $object->create($user);
|
$id = $object->create($user);
|
||||||
@ -411,7 +430,9 @@ if (empty($reshook))
|
|||||||
{
|
{
|
||||||
$object->oldcopy = clone $object;
|
$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->label = GETPOST('label', $label_security_check);
|
||||||
$object->description = dol_htmlcleanlastbr(GETPOST('desc', 'restricthtml'));
|
$object->description = dol_htmlcleanlastbr(GETPOST('desc', 'restricthtml'));
|
||||||
$object->url = GETPOST('url');
|
$object->url = GETPOST('url');
|
||||||
@ -995,15 +1016,17 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
|
|||||||
|
|
||||||
print '<table class="border centpercent">';
|
print '<table class="border centpercent">';
|
||||||
|
|
||||||
print '<tr>';
|
if (empty($conf->global->PRODUCT_GENERATE_REF_AFTER_FORM)) {
|
||||||
$tmpcode = '';
|
print '<tr>';
|
||||||
if (!empty($modCodeProduct->code_auto)) $tmpcode = $modCodeProduct->getNextValue($object, $type);
|
$tmpcode = '';
|
||||||
print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td colspan="3"><input id="ref" name="ref" class="maxwidth200" maxlength="128" value="'.dol_escape_htmltag(GETPOSTISSET('ref') ? GETPOST('ref', 'alphanohtml') : $tmpcode).'">';
|
if (!empty($modCodeProduct->code_auto)) $tmpcode = $modCodeProduct->getNextValue($object, $type);
|
||||||
if ($refalreadyexists)
|
print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Ref").'</td><td colspan="3"><input id="ref" name="ref" class="maxwidth200" maxlength="128" value="'.dol_escape_htmltag(GETPOSTISSET('ref') ? GETPOST('ref', 'alphanohtml') : $tmpcode).'">';
|
||||||
{
|
if ($refalreadyexists)
|
||||||
print $langs->trans("RefAlreadyExists");
|
{
|
||||||
|
print $langs->trans("RefAlreadyExists");
|
||||||
|
}
|
||||||
|
print '</td></tr>';
|
||||||
}
|
}
|
||||||
print '</td></tr>';
|
|
||||||
|
|
||||||
// Label
|
// Label
|
||||||
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td colspan="3"><input name="label" class="minwidth300 maxwidth400onsmartphone" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label', $label_security_check)).'"></td></tr>';
|
print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td colspan="3"><input name="label" class="minwidth300 maxwidth400onsmartphone" maxlength="255" value="'.dol_escape_htmltag(GETPOST('label', $label_security_check)).'"></td></tr>';
|
||||||
@ -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 = '';
|
$tmpcode = '';
|
||||||
if (!empty($modCodeProduct->code_auto)) $tmpcode = $modCodeProduct->getNextValue($object, $object->type);
|
if (!empty($modCodeProduct->code_auto)) $tmpcode = $modCodeProduct->getNextValue($object, $object->type);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user