From 3e4cd251eabf9f7559c8f8dd933474b611685f6f Mon Sep 17 00:00:00 2001 From: GregM Date: Fri, 29 Apr 2022 11:45:50 +0200 Subject: [PATCH] add edit extrafields Massaction products --- htdocs/core/actions_massactions.inc.php | 70 +++++++++++++++++++++++++ htdocs/core/tpl/massactions_pre.tpl.php | 25 +++++++++ htdocs/langs/en_US/main.lang | 4 ++ htdocs/product/list.php | 1 + 4 files changed, 100 insertions(+) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index c5ff1d8f82a..5f5703fc872 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1602,6 +1602,76 @@ if (!$error && ($massaction == 'disable' || ($action == 'disable' && $confirm == } } +if (!$error && $action == 'confirm_edit_value_extrafields' && $confirm == 'yes' && $permissiontoadd){ + $db->begin(); + + /** @var CommonObject $objecttmp */ + $objecttmp = new $objectclass($db); + + $nbok = 0; + $e = new ExtraFields($db); + $e->fetch_name_optionals_label($objecttmp->table_element); + + foreach ($toselect as $toselectid) { + $result = $objecttmp->fetch($toselectid); + + if ($result>0) { + + if (isset($e->attributes[$objecttmp->table_element]['type']) && is_array($e->attributes[$objecttmp->table_element]['type'])) { + foreach ($e->attributes[$objecttmp->table_element]['type'] as $key => $type){ + + //Permet de gérer les types d'extrafields + if (in_array($type, array('price', 'double'))) { + $value_arr = GETPOST("options_".$key, 'alpha'); + if(empty($value_arr)){ + continue; + } + $value_key = price2num($value_arr); + //var_dump($value_key);exit; + }else if (in_array($type, array('date'))) { + // Clean parameters + $value_key = dol_mktime(12, 0, 0, GETPOST("options_" . $key . "month", 'int'), GETPOST("options_" . $key . "day", 'int'), GETPOST("options_" . $key . "year", 'int')); + //var_dump($value_key);exit; + if(empty($value_key)){ + continue; + } + }else if (in_array($type, array('datetime'))) { + // Clean parameters + $value_key = dol_mktime(GETPOST("options_".$key."hour", 'int'), GETPOST("options_".$key."min", 'int'), GETPOST("options_".$key."sec", 'int'), GETPOST("options_".$key."month", 'int'), GETPOST("options_".$key."day", 'int'), GETPOST("options_".$key."year", 'int'), 'tzuserrel'); + if(empty($value_key)){ + continue; + } + } else { + $value_key = GETPOST("options_".$key); + if ((in_array($type, array('link')) && $key == '-1') || empty($value_key)) { + continue; + } + } + $objecttmp->array_options["options_".$key] = $value_key; + } + } + $objecttmp->insertExtraFields(); + + } 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(); + } + +} + // Approve for leave only if (!$error && ($massaction == 'approveleave' || ($action == 'approveleave' && $confirm == 'yes')) && $permissiontoapprove) { $db->begin(); diff --git a/htdocs/core/tpl/massactions_pre.tpl.php b/htdocs/core/tpl/massactions_pre.tpl.php index de034f652d3..40394cb99ff 100644 --- a/htdocs/core/tpl/massactions_pre.tpl.php +++ b/htdocs/core/tpl/massactions_pre.tpl.php @@ -211,6 +211,31 @@ if ($massaction == 'presend') { print dol_get_fiche_end(); } +if ($massaction == 'edit_extrafields') { + + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + $elementtype = 'product'; + /** @var CommonObject $objecttmp */ + $extrafields = new ExtraFields($db); + + $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' => $object->showOptionals($extrafields, 'create') + ); + + 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/main.lang b/htdocs/langs/en_US/main.lang index c66895e58a4..c543fcf31e0 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -1169,3 +1169,7 @@ CanceledShown=Canceled shown Terminate=Terminate Terminated=Terminated AddLineOnPosition=Add line on position (at the end if empty) +ConfirmEditExtrafield = Modifier les champs supplémentaires en masse +ChangeValueExtrafield = Modifier la valeur du champ supplémentaire +ConfirmEditExtrafieldQuestion = Etes vous sur de modifier cet extrafield ? +ConfirmEditValueExtrafieldQuestion = Etes vous sur de modifier la valeur de cet extrafield ? diff --git a/htdocs/product/list.php b/htdocs/product/list.php index de5e4f278b7..7cd0a91c923 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("Extrafields"), //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), );