From d9e9364ddf9356d58b5c80a1e428c573dabbea17 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 30 Sep 2019 19:00:19 +0200 Subject: [PATCH] Close #11689 Close #11696 --- htdocs/product/stock/card.php | 236 +++++++++++++++++----------------- 1 file changed, 121 insertions(+), 115 deletions(-) diff --git a/htdocs/product/stock/card.php b/htdocs/product/stock/card.php index c085bff8082..4fef23ad1c5 100644 --- a/htdocs/product/stock/card.php +++ b/htdocs/product/stock/card.php @@ -87,81 +87,17 @@ $usercanread = (($user->rights->stock->lire)); $usercancreate = (($user->rights->stock->creer)); $usercandelete = (($user->rights->stock->supprimer)); -// Ajout entrepot -if ($action == 'add' && $user->rights->stock->creer) +$parameters=array('id'=>$id, 'ref'=>$ref); +$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if (empty($reshook)) { - $object->ref = GETPOST("ref"); - $object->fk_parent = GETPOST("fk_parent"); - $object->libelle = GETPOST("libelle"); - $object->description = GETPOST("desc"); - $object->statut = GETPOST("statut"); - $object->lieu = GETPOST("lieu"); - $object->address = GETPOST("address"); - $object->zip = GETPOST("zipcode"); - $object->town = GETPOST("town"); - $object->country_id = GETPOST("country_id"); - - if (! empty($object->libelle)) + // Ajout entrepot + if ($action == 'add' && $user->rights->stock->creer) { - // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) { - $error++; - $action = 'create'; - } - - if (! $error) { - $id = $object->create($user); - if ($id > 0) { - setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); - - $categories = GETPOST('categories', 'array'); - $object->setCategories($categories); - if (!empty($backtopage)) { - header("Location: " . $backtopage); - exit; - } else { - header("Location: card.php?id=" . $id); - exit; - } - } else { - $action = 'create'; - setEventMessages($object->error, $object->errors, 'errors'); - } - } - } - else - { - setEventMessages($langs->trans("ErrorWarehouseRefRequired"), null, 'errors'); - $action="create"; // Force retour sur page creation - } -} - -// Delete warehouse -if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->stock->supprimer) -{ - $object->fetch(GETPOST('id', 'int')); - $result=$object->delete($user); - if ($result > 0) - { - setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs'); - header("Location: ".DOL_URL_ROOT.'/product/stock/list.php?restore_lastsearch_values=1'); - exit; - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - $action=''; - } -} - -// Modification entrepot -if ($action == 'update' && $cancel <> $langs->trans("Cancel")) -{ - if ($object->fetch($id)) - { - $object->libelle = GETPOST("libelle"); + $object->ref = GETPOST("ref"); $object->fk_parent = GETPOST("fk_parent"); + $object->libelle = GETPOST("libelle"); $object->description = GETPOST("desc"); $object->statut = GETPOST("statut"); $object->lieu = GETPOST("lieu"); @@ -170,57 +106,127 @@ if ($action == 'update' && $cancel <> $langs->trans("Cancel")) $object->town = GETPOST("town"); $object->country_id = GETPOST("country_id"); - // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) $error++; + if (! empty($object->libelle)) + { + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + if ($ret < 0) { + $error++; + $action = 'create'; + } - if (! $error) { - $ret = $object->update($id, $user); - if ($ret < 0) $error++; - } + if (! $error) { + $id = $object->create($user); + if ($id > 0) { + setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); - if ($error) { + $categories = GETPOST('categories', 'array'); + $object->setCategories($categories); + if (!empty($backtopage)) { + header("Location: " . $backtopage); + exit; + } else { + header("Location: card.php?id=" . $id); + exit; + } + } else { + $action = 'create'; + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } + else + { + setEventMessages($langs->trans("ErrorWarehouseRefRequired"), null, 'errors'); + $action="create"; // Force retour sur page creation + } + } + + // Delete warehouse + if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->stock->supprimer) + { + $object->fetch(GETPOST('id', 'int')); + $result=$object->delete($user); + if ($result > 0) + { + setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs'); + header("Location: ".DOL_URL_ROOT.'/product/stock/list.php?restore_lastsearch_values=1'); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + $action=''; + } + } + + // Modification entrepot + if ($action == 'update' && $cancel <> $langs->trans("Cancel")) + { + if ($object->fetch($id)) + { + $object->libelle = GETPOST("libelle"); + $object->fk_parent = GETPOST("fk_parent"); + $object->description = GETPOST("desc"); + $object->statut = GETPOST("statut"); + $object->lieu = GETPOST("lieu"); + $object->address = GETPOST("address"); + $object->zip = GETPOST("zipcode"); + $object->town = GETPOST("town"); + $object->country_id = GETPOST("country_id"); + + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + if ($ret < 0) $error++; + + if (! $error) { + $ret = $object->update($id, $user); + if ($ret < 0) $error++; + } + + if ($error) { + $action = 'edit'; + setEventMessages($object->error, $object->errors, 'errors'); + } else { + $categories = GETPOST('categories', 'array'); + $object->setCategories($categories); + $action = ''; + } + } + else + { $action = 'edit'; setEventMessages($object->error, $object->errors, 'errors'); - } else { - $categories = GETPOST('categories', 'array'); - $object->setCategories($categories); - $action = ''; - } + } } - else + elseif ($action == 'update_extras') { + $object->oldcopy = dol_clone($object); + + // Fill array 'array_options' with data from update form + $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none')); + if ($ret < 0) $error++; + if (! $error) { + $result = $object->insertExtraFields(); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + } + } + if ($error) $action = 'edit_extras'; + } + + if ($cancel == $langs->trans("Cancel")) { - $action = 'edit'; - setEventMessages($object->error, $object->errors, 'errors'); + $action = ''; } + + + // Actions to build doc + $upload_dir = $conf->stock->dir_output; + $permissioncreate = $user->rights->stock->creer; + include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; } -elseif ($action == 'update_extras') { - $object->oldcopy = dol_clone($object); - - // Fill array 'array_options' with data from update form - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none')); - if ($ret < 0) $error++; - if (! $error) { - $result = $object->insertExtraFields(); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - } - if ($error) $action = 'edit_extras'; -} - -if ($cancel == $langs->trans("Cancel")) -{ - $action = ''; -} - - -// Actions to build doc -$upload_dir = $conf->stock->dir_output; -$permissioncreate = $user->rights->stock->creer; -include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; /*