From 02cf3fa36102ecebd890d5d9d12652d01d1aad0d Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Fri, 29 Apr 2022 15:38:12 +0200 Subject: [PATCH] end factoring --- htdocs/core/actions_massactions.inc.php | 12 +++++++----- htdocs/core/tpl/massactions_pre.tpl.php | 6 +++++- htdocs/product/list.php | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index ccf2fbec73e..6308c33d268 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1605,20 +1605,22 @@ if (!$error && ($massaction == 'disable' || ($action == 'disable' && $confirm == if (!$error && $action == 'confirm_edit_value_extrafields' && $confirm == 'yes' && $permissiontoadd) { $db->begin(); - $nbok = 0; + $objecttmp = new $objectclass($db); + $e = new ExtraFields($db);// fetch optionals attributes and labels + $e->fetch_name_optionals_label($objecttmp->table_element); - $extrafieldKeyToUpdate = GETPOST('extrafield-key-yo-update'); // TODO A FAIRE coté formulaire : ajouter le select de l'extrafield a utiliser - $extrafieldKeyToUpdate = 'code_tva_achat'; // TODO A FAIRE coté formulaire : ajouter le select de l'extrafield a utiliser + $nbok = 0; + $extrafieldKeyToUpdate = GETPOST('extrafield-key-to-update'); // TODO A FAIRE coté formulaire : ajouter le select de l'extrafield a utiliser // TODO vérifier que $extrafieldKeyToUpdate correspond bien a un extrafield foreach ($toselect as $toselectid) { /** @var CommonObject $objecttmp */ - $objecttmp = new $objectclass($db); + $objecttmp = new $objectclass($db); // to avoid ghost data $result = $objecttmp->fetch($toselectid); if ($result>0) { // Fill array 'array_options' with data from add form - $e = new ExtraFields($db); $ret = $e->setOptionalsFromPost(null, $objecttmp, $extrafieldKeyToUpdate); + if ($ret > 0) { $objecttmp->insertExtraFields(); // TODO gérer l'erreur } else { diff --git a/htdocs/core/tpl/massactions_pre.tpl.php b/htdocs/core/tpl/massactions_pre.tpl.php index 40394cb99ff..8e364cd24e1 100644 --- a/htdocs/core/tpl/massactions_pre.tpl.php +++ b/htdocs/core/tpl/massactions_pre.tpl.php @@ -212,7 +212,6 @@ if ($massaction == 'presend') { } if ($massaction == 'edit_extrafields') { - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $elementtype = 'product'; /** @var CommonObject $objecttmp */ @@ -225,6 +224,11 @@ if ($massaction == 'edit_extrafields') { if (!empty($extrafields_list)) { $myParamExtra = $object->showOptionals($extrafields, 'create'); + $formquestion[] = array( + 'type' => 'other', + 'value' => $form->selectarray('extrafield-key-to-update', $extrafields_list, GETPOST('extrafield-key-to-update')) + ); + $formquestion[] = array( 'type' => 'other', 'value' => $object->showOptionals($extrafields, 'create') diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 7cd0a91c923..4824015c299 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -740,7 +740,7 @@ if ($resql) { $arrayofmassactions['switchonpurchasestatus'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SwitchOnPurchaseStatus"); $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag"); } - if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) { + if (in_array($massaction, array('presend', 'predelete','preaffecttag', 'edit_extrafields'))) { $arrayofmassactions = array(); } $massactionbutton = $form->selectMassAction('', $arrayofmassactions);