diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index d7e5812ac9a..383684b377a 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1302,6 +1302,49 @@ if (!$error && ($massaction == 'disable' || ($action == 'disable' && $confirm == } } +if (!$error && $action == 'confirm_edit_value_extrafields' && $confirm == 'yes' && $permissiontoadd) { + $db->begin(); + + $objecttmp = new $objectclass($db); + $e = new ExtraFields($db);// fetch optionals attributes and labels + $e->fetch_name_optionals_label($objecttmp->table_element); + + $nbok = 0; + $extrafieldKeyToUpdate = GETPOST('extrafield-key-to-update'); + + + foreach ($toselect as $toselectid) { + /** @var CommonObject $objecttmp */ + $objecttmp = new $objectclass($db); // to avoid ghost data + $result = $objecttmp->fetch($toselectid); + if ($result>0) { + // Fill array 'array_options' with data from add form + $ret = $e->setOptionalsFromPost(null, $objecttmp, $extrafieldKeyToUpdate); + if ($ret > 0) { + $objecttmp->insertExtraFields(); + } else { + $error++; + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + } + } else { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + } + + if (!$error) { + if ($nbok > 1) { + setEventMessages($langs->trans("RecordsDisabled", $nbok), null, 'mesgs'); + } else { + setEventMessages($langs->trans("save"), null, 'mesgs'); + } + $db->commit(); + } else { + $db->rollback(); + } +} + if (!$error && ($massaction == 'affectcommercial' || ($action == 'affectcommercial' && $confirm == 'yes')) && $permissiontoadd) { $db->begin(); diff --git a/htdocs/core/tpl/massactions_pre.tpl.php b/htdocs/core/tpl/massactions_pre.tpl.php index 4e138b0f1dc..207dc1b7265 100644 --- a/htdocs/core/tpl/massactions_pre.tpl.php +++ b/htdocs/core/tpl/massactions_pre.tpl.php @@ -211,6 +211,59 @@ if ($massaction == 'presend') { print dol_get_fiche_end(); } +if ($massaction == 'edit_extrafields') { + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + $elementtype = $objecttmp->element; + /** @var CommonObject $objecttmp */ + $extrafields = new ExtraFields($db); + $keysuffix = ''; + $extrafields->fetch_name_optionals_label($elementtype); + $extrafields_list = $extrafields->attributes[$elementtype]['label']; + + $formquestion = array(); + 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'), 1) + ); + + + $outputShowOutputFields = '
'; + + foreach ($extrafields_list as $extraKey => $extraLabel) { + $outputShowOutputFields.= ''; + } + $outputShowOutputFields.= ''; + $outputShowOutputFields.= '
'; + + + + $formquestion[] = array( + 'type' => 'other', + 'value' => $outputShowOutputFields + ); + + print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmEditExtrafield"), $langs->trans("ConfirmEditExtrafieldQuestion", count($toselect)), "confirm_edit_value_extrafields", $formquestion, 1, 0, 200, 500, 1); + } else { + setEventMessage($langs->trans("noExtrafields")); + } +} + if ($massaction == 'preenable') { print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassEnabling"), $langs->trans("ConfirmMassEnablingQuestion", count($toselect)), "enable", null, 'yes', 0, 200, 500, 1); } diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 2d8ef240ef1..4b38515924b 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -424,3 +424,6 @@ PMPExpected=Expected PMP ExpectedValuation=Expected Valuation PMPReal=Real PMP RealValuation=Real Valuation +ConfirmEditExtrafield = Select the extrafield you want modify +ConfirmEditExtrafieldQuestion = Are you sure you want to modify this extrafield? +ModifyValueExtrafields = Modify value of an extrafield diff --git a/htdocs/product/list.php b/htdocs/product/list.php index de5e4f278b7..2938e524377 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -727,6 +727,7 @@ if ($resql) { // List of mass actions available $arrayofmassactions = array( 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"), + 'edit_extrafields'=>img_picto('', 'edit', 'class="pictofixedwidth"').$langs->trans("ModifyValueExtrafields"), //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), ); @@ -739,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);