add edit extrafields Massaction products

This commit is contained in:
GregM 2022-04-29 11:45:50 +02:00
parent 914b037a9a
commit 3e4cd251ea
4 changed files with 100 additions and 0 deletions

View File

@ -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();

View File

@ -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);
}

View File

@ -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 ?

View File

@ -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"),
);