From 0f9b01cd5b4f7829b49c495fd5cd1be4180e5bad Mon Sep 17 00:00:00 2001 From: Tim Otte Date: Thu, 5 Sep 2019 09:47:40 +0200 Subject: [PATCH] Added support for extrafield styling options: - visibility now implemented - fieldrequired now implemented --- htdocs/product/fournisseurs.php | 35 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index 3d8585ecfc4..f4431d7bf77 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -151,7 +151,7 @@ if (empty($reshook)) } } - if ($action == 'updateprice') + if ($action == 'save_price') { $id_fourn=GETPOST("id_fourn"); if (empty($id_fourn)) $id_fourn=GETPOST("search_id_fourn"); @@ -437,7 +437,7 @@ if ($id > 0 || $ref) // Form to add or update a price - if (($action == 'add_price' || $action == 'updateprice' ) && $usercancreate) + if (($action == 'add_price' || $action == 'update_price' ) && $usercancreate) { $langs->load("suppliers"); @@ -453,7 +453,7 @@ if ($id > 0 || $ref) print '
'; print ''; - print ''; + print ''; dol_fiche_head(); @@ -763,12 +763,16 @@ SCRIPT; $resql = $db->query("SELECT * FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields WHERE fk_object = " . $rowid); if ($db->num_rows($resql) != 1) { foreach ($extralabels as $key => $value) { - print '' . $langs->trans($value) . '' . $extrafields->showInputField($key, '', '', '', '', '', 0, 'product_fournisseur_price') . ''; + if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && ($extrafields->attributes["product_fournisseur_price"]['list'][$key] == 1 || $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 3 || ($action == "update_price" && $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 4))) { + print 'attributes["product_fournisseur_price"]['required'][$key] ? ' class="fieldrequired"' : '') . '>' . $langs->trans($value) . '' . $extrafields->showInputField($key, '', '', '', '', '', 0, 'product_fournisseur_price') . ''; + } } } else { $resql = $db->fetch_object($resql); foreach ($extralabels as $key => $value) { - print '' . $langs->trans($value) . '' . $extrafields->showInputField($key, $resql->{$key}, '', '', '', '', 0, 'product_fournisseur_price') . ''; + if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && ($extrafields->attributes["product_fournisseur_price"]['list'][$key] == 1 || $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 3 || ($action == "update_price" && $extrafields->attributes["product_fournisseur_price"]['list'][$key] == 4))) { + print 'attributes["product_fournisseur_price"]['required'][$key] ? ' class="fieldrequired"' : '') . '>' . $langs->trans($value) . '' . $extrafields->showInputField($key, $resql->{$key}, '', '', '', '', 0, 'product_fournisseur_price') . ''; + } } } @@ -796,7 +800,7 @@ SCRIPT; print "\n
\n"; - if ($action != 'add_price' && $action != 'updateprice') + if ($action != 'add_price' && $action != 'update_price') { $parameters=array(); $reshook=$hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook @@ -862,8 +866,11 @@ SCRIPT; // fetch optionals attributes and labels $extralabels=$extrafields->fetch_name_optionals_label("product_fournisseur_price"); - foreach ($extralabels as $extrafield) { - print_liste_field_titre($extrafield, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); + foreach ($extralabels as $key => $value) { + // Show field if not hidden + if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) { + print_liste_field_titre($value, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right '); + } } if (is_object($hookmanager)) @@ -983,13 +990,17 @@ SCRIPT; // Extrafields $resql = $db->query("SELECT * FROM " . MAIN_DB_PREFIX . "product_fournisseur_price_extrafields WHERE fk_object = " . $productfourn->product_fourn_price_id); if ($db->num_rows($resql) != 1) { - foreach ($extralabels as $extrafield) { - print ""; + foreach ($extralabels as $key => $value) { + if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) { + print ""; + } } } else { $resql = $db->fetch_object($resql); foreach ($extralabels as $key => $value) { - print "" . $extrafields->showOutputField($key, $resql->{$key}) . ""; + if (! empty($extrafields->attributes["product_fournisseur_price"]['list'][$key]) && $extrafields->attributes["product_fournisseur_price"]['list'][$key] != 3) { + print '' . $extrafields->showOutputField($key, $resql->{$key}) . ""; + } } } @@ -1003,7 +1014,7 @@ SCRIPT; print ''; if ($usercancreate) { - print ''.img_edit().""; + print ''.img_edit().""; print '   '; print ''.img_picto($langs->trans("Remove"), 'delete').''; }