From 2b66282b61ea87966d4d312dfd2dc55f1a9c6a55 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 6 Oct 2019 14:41:52 +0200 Subject: [PATCH] NEW Code for extrafields uses the new array $extrafields->attributes --- htdocs/adherents/card.php | 15 ++-- htdocs/adherents/cartes/carte.php | 2 +- htdocs/adherents/list.php | 2 +- htdocs/adherents/subscription.php | 2 +- htdocs/adherents/subscription/list.php | 2 +- htdocs/adherents/type.php | 6 +- htdocs/admin/emailcollector_card.php | 2 +- htdocs/admin/emailcollector_list.php | 2 +- htdocs/admin/mails_senderprofile_list.php | 2 +- htdocs/asset/card.php | 7 +- htdocs/asset/document.php | 2 +- htdocs/asset/list.php | 2 +- htdocs/asset/note.php | 2 +- htdocs/asset/type.php | 6 +- htdocs/bom/bom_agenda.php | 2 +- htdocs/bom/bom_card.php | 2 +- htdocs/bom/bom_document.php | 2 +- htdocs/bom/bom_list.php | 2 +- htdocs/bom/bom_note.php | 2 +- htdocs/bom/tpl/objectline_create.tpl.php | 2 +- htdocs/bom/tpl/objectline_edit.tpl.php | 2 +- htdocs/bom/tpl/objectline_view.tpl.php | 4 +- htdocs/categories/card.php | 4 +- htdocs/categories/edit.php | 4 +- htdocs/categories/viewcat.php | 2 +- htdocs/comm/action/card.php | 6 +- htdocs/comm/action/list.php | 2 +- htdocs/comm/card.php | 5 +- htdocs/comm/mailing/card.php | 2 +- .../mailing/class/advtargetemailing.class.php | 69 ++++++++++--------- htdocs/comm/mailing/list.php | 2 +- htdocs/comm/propal/card.php | 17 ++--- htdocs/comm/propal/list.php | 2 +- htdocs/commande/card.php | 17 ++--- htdocs/commande/list.php | 2 +- htdocs/commande/orderstoinvoice.php | 7 +- htdocs/compta/bank/bankentries_list.php | 2 +- htdocs/compta/bank/card.php | 9 +-- htdocs/compta/bank/list.php | 2 +- .../compta/cashcontrol/cashcontrol_card.php | 2 +- .../compta/cashcontrol/cashcontrol_list.php | 4 +- htdocs/compta/facture/card.php | 24 +++---- .../facture/class/facture-rec.class.php | 13 ++-- htdocs/compta/facture/fiche-rec.php | 16 ++--- .../compta/facture/invoicetemplate_list.php | 3 +- htdocs/compta/facture/list.php | 3 +- htdocs/contact/agenda.php | 2 +- htdocs/contact/card.php | 6 +- htdocs/contact/list.php | 3 +- htdocs/contrat/card.php | 24 +++---- htdocs/contrat/class/contrat.class.php | 15 ++-- htdocs/contrat/list.php | 3 +- htdocs/contrat/services_list.php | 3 +- .../core/class/commondocgenerator.class.php | 14 ++-- htdocs/core/class/commonobject.class.php | 41 ++++++----- htdocs/core/class/extrafields.class.php | 17 +++-- htdocs/core/class/html.formactions.class.php | 2 +- htdocs/core/class/html.formticket.class.php | 2 +- htdocs/core/lib/company.lib.php | 2 +- htdocs/core/lib/project.lib.php | 14 ++-- .../doc/doc_generic_project_odt.modules.php | 8 +-- .../task/doc/doc_generic_task_odt.modules.php | 2 +- .../stock/doc/pdf_stdmovement.modules.php | 2 +- htdocs/core/tpl/advtarget.tpl.php | 41 +++++------ htdocs/core/tpl/extrafields_add.tpl.php | 4 +- .../tpl/extrafields_list_search_title.tpl.php | 2 +- htdocs/core/tpl/extrafields_view.tpl.php | 3 +- htdocs/core/tpl/objectline_edit.tpl.php | 4 +- htdocs/core/tpl/objectline_view.tpl.php | 8 +-- htdocs/cron/list.php | 2 +- htdocs/don/card.php | 8 +-- htdocs/expedition/card.php | 49 ++++++------- htdocs/expedition/list.php | 17 +---- htdocs/expedition/shipment.php | 5 +- htdocs/expensereport/card.php | 7 +- htdocs/expensereport/list.php | 3 +- htdocs/fichinter/card-rec.php | 5 +- htdocs/fichinter/card.php | 44 +++++------- htdocs/fichinter/list.php | 4 +- htdocs/fourn/card.php | 5 +- htdocs/fourn/commande/card.php | 17 ++--- htdocs/fourn/commande/list.php | 3 +- htdocs/fourn/commande/orderstoinvoice.php | 5 +- htdocs/fourn/facture/card.php | 22 ++---- htdocs/fourn/facture/list.php | 3 +- htdocs/fourn/facture/paiement.php | 6 +- htdocs/holiday/card.php | 5 +- htdocs/holiday/list.php | 3 +- htdocs/livraison/card.php | 29 ++++---- .../template/myobject_agenda.php | 2 +- .../modulebuilder/template/myobject_card.php | 8 ++- .../template/myobject_document.php | 2 +- .../modulebuilder/template/myobject_list.php | 7 +- .../modulebuilder/template/myobject_note.php | 2 +- htdocs/opensurvey/list.php | 2 +- htdocs/product/card.php | 6 +- .../class/price_parser.class.php | 2 +- htdocs/product/inventory/card.php | 63 ++++++++--------- htdocs/product/inventory/list.php | 2 +- htdocs/product/list.php | 2 +- htdocs/product/stock/card.php | 9 ++- htdocs/product/stock/list.php | 2 +- htdocs/product/stock/movement_card.php | 3 +- htdocs/product/stock/movement_list.php | 3 +- htdocs/product/stock/product.php | 2 +- htdocs/product/stock/productlot_card.php | 5 +- htdocs/product/stock/productlot_list.php | 3 +- htdocs/projet/activity/perday.php | 22 +++--- htdocs/projet/activity/perweek.php | 7 +- htdocs/projet/card.php | 6 +- htdocs/projet/comment.php | 2 +- htdocs/projet/list.php | 3 +- htdocs/projet/tasks.php | 7 +- htdocs/projet/tasks/comment.php | 2 +- htdocs/projet/tasks/list.php | 2 +- htdocs/projet/tasks/task.php | 4 +- htdocs/projet/tasks/time.php | 4 +- htdocs/public/members/new.php | 4 +- htdocs/public/members/public_card.php | 3 +- htdocs/public/ticket/create_ticket.php | 6 +- htdocs/public/ticket/list.php | 43 ++++++------ htdocs/reception/card.php | 48 ++++++------- htdocs/reception/class/reception.class.php | 4 +- htdocs/reception/list.php | 22 ++---- htdocs/resource/card.php | 6 +- htdocs/resource/class/dolresource.class.php | 23 +++---- htdocs/resource/list.php | 2 +- htdocs/salaries/card.php | 6 +- htdocs/societe/card.php | 9 +-- htdocs/societe/contact.php | 4 +- htdocs/societe/list.php | 3 +- htdocs/societe/paymentmodes.php | 6 +- htdocs/societe/website.php | 6 +- htdocs/supplier_proposal/card.php | 17 ++--- htdocs/supplier_proposal/list.php | 3 +- htdocs/ticket/agenda.php | 3 +- htdocs/ticket/card.php | 11 ++- htdocs/ticket/class/ticket.class.php | 2 +- htdocs/ticket/list.php | 2 +- htdocs/ticket/messaging.php | 2 +- htdocs/user/card.php | 8 +-- htdocs/user/group/card.php | 6 +- htdocs/user/list.php | 2 +- htdocs/webservices/server_actioncomm.php | 8 +-- htdocs/webservices/server_contact.php | 8 +-- htdocs/webservices/server_order.php | 10 +-- .../webservices/server_productorservice.php | 10 +-- htdocs/webservices/server_project.php | 6 +- htdocs/webservices/server_thirdparty.php | 10 +-- htdocs/webservices/server_user.php | 4 +- htdocs/website/websiteaccount_card.php | 7 +- htdocs/zapier/hook_agenda.php | 3 +- htdocs/zapier/hook_card.php | 4 +- htdocs/zapier/hook_document.php | 3 +- htdocs/zapier/hook_list.php | 5 +- htdocs/zapier/hook_note.php | 3 +- 156 files changed, 622 insertions(+), 649 deletions(-) diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index 4653ed43714..20da8ffd2f7 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -68,7 +68,7 @@ $object = new Adherent($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $object->getCanvas($id); @@ -320,7 +320,7 @@ if (empty($reshook)) $object->public = GETPOST("public", 'alpha'); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; // Check if we need to also synchronize user information @@ -497,7 +497,7 @@ if (empty($reshook)) $object->public = $public; // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; // Check parameters @@ -1362,15 +1362,8 @@ else else print $langs->trans("NoDolibarrAccess"); print ''; - // Other attributes + // Other attributes. Fields from hook formObjectOptions and Extrafields. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; - //Hooks here - $reshook=$hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - if (empty($reshook)) - { - print $object->showOptionals($extrafields, 'edit'); - } print ''; dol_fiche_end(); diff --git a/htdocs/adherents/cartes/carte.php b/htdocs/adherents/cartes/carte.php index d7e0e9215a9..177e2eef18f 100644 --- a/htdocs/adherents/cartes/carte.php +++ b/htdocs/adherents/cartes/carte.php @@ -48,7 +48,7 @@ $object=new Adherent($db); $extrafields = new ExtraFields($db); // Fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); /* diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index 57d99a387e2..877dde34af0 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -89,7 +89,7 @@ $hookmanager->initHooks(array('memberlist')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); diff --git a/htdocs/adherents/subscription.php b/htdocs/adherents/subscription.php index 97f259b53de..8cde161a88d 100644 --- a/htdocs/adherents/subscription.php +++ b/htdocs/adherents/subscription.php @@ -68,7 +68,7 @@ $extrafields = new ExtraFields($db); $adht = new AdherentType($db); // fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); $errmsg=''; $errmsgs=array(); diff --git a/htdocs/adherents/subscription/list.php b/htdocs/adherents/subscription/list.php index 5d8bbdad08d..dbc14e2999e 100644 --- a/htdocs/adherents/subscription/list.php +++ b/htdocs/adherents/subscription/list.php @@ -68,7 +68,7 @@ $hookmanager->initHooks(array('subscriptionlist')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index ac15e8d28ae..7b540a92d18 100644 --- a/htdocs/adherents/type.php +++ b/htdocs/adherents/type.php @@ -73,7 +73,7 @@ $object = new AdherentType($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers { @@ -113,7 +113,7 @@ if ($action == 'add' && $user->rights->adherent->configurer) { $object->vote = (int) $vote; // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; if (empty($object->label)) { @@ -168,7 +168,7 @@ if ($action == 'update' && $user->rights->adherent->configurer) $object->vote = (boolean) trim($vote); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; $ret=$object->update($user); diff --git a/htdocs/admin/emailcollector_card.php b/htdocs/admin/emailcollector_card.php index 24aa836a038..a2416dfc90f 100644 --- a/htdocs/admin/emailcollector_card.php +++ b/htdocs/admin/emailcollector_card.php @@ -57,7 +57,7 @@ $diroutputmassaction = $conf->emailcollector->dir_output . '/temp/massgeneration $hookmanager->initHooks(array('emailcollectorcard')); // Note that conf->hooks_modules contains array // Fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); diff --git a/htdocs/admin/emailcollector_list.php b/htdocs/admin/emailcollector_list.php index b9804e57f03..09ba5f7224f 100644 --- a/htdocs/admin/emailcollector_list.php +++ b/htdocs/admin/emailcollector_list.php @@ -68,7 +68,7 @@ $diroutputmassaction = $conf->emailcollector->dir_output . '/temp/massgeneration $hookmanager->initHooks(array('emailcollectorlist')); // Note that conf->hooks_modules contains array // Fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); diff --git a/htdocs/admin/mails_senderprofile_list.php b/htdocs/admin/mails_senderprofile_list.php index 2250980a98d..0aa53b11b8d 100644 --- a/htdocs/admin/mails_senderprofile_list.php +++ b/htdocs/admin/mails_senderprofile_list.php @@ -61,7 +61,7 @@ $diroutputmassaction=$conf->admin->dir_output . '/temp/massgeneration/'.$user->i $hookmanager->initHooks(array('emailsenderprofilelist')); // Note that conf->hooks_modules contains array // Fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); diff --git a/htdocs/asset/card.php b/htdocs/asset/card.php index 77fb734be54..7c2f1b42f32 100644 --- a/htdocs/asset/card.php +++ b/htdocs/asset/card.php @@ -45,7 +45,7 @@ $diroutputmassaction=$conf->asset->dir_output . '/temp/massgeneration/'.$user->i $hookmanager->initHooks(array('assetcard')); // Note that conf->hooks_modules contains array // Fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); @@ -64,9 +64,6 @@ if (empty($action) && empty($id) && empty($ref)) $action='view'; //if ($user->societe_id > 0) $socid = $user->societe_id; //$result = restrictedArea($user, 'asset', $id); -// fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - // Load object include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. @@ -207,7 +204,7 @@ if (($id || $ref) && $action == 'edit') // Part to show record if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) { - $res = $object->fetch_optionals($object->id, $extralabels); + $res = $object->fetch_optionals($object->id); $head = asset_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("Asset"), -1, 'generic'); diff --git a/htdocs/asset/document.php b/htdocs/asset/document.php index 3fc0b1efe3d..d1fa8c1e04b 100644 --- a/htdocs/asset/document.php +++ b/htdocs/asset/document.php @@ -62,7 +62,7 @@ $diroutputmassaction=$conf->assets->dir_output . '/temp/massgeneration/'.$user-> $hookmanager->initHooks(array('assetdocument')); // Note that conf->hooks_modules contains array // Fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Load object include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals diff --git a/htdocs/asset/list.php b/htdocs/asset/list.php index fb752b00087..6c4e5e92f20 100644 --- a/htdocs/asset/list.php +++ b/htdocs/asset/list.php @@ -62,7 +62,7 @@ $diroutputmassaction=$conf->asset->dir_output . '/temp/massgeneration/'.$user->i $hookmanager->initHooks(array('assetlist')); // Note that conf->hooks_modules contains array // Fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); diff --git a/htdocs/asset/note.php b/htdocs/asset/note.php index b09ade8715b..a2b3672c983 100644 --- a/htdocs/asset/note.php +++ b/htdocs/asset/note.php @@ -43,7 +43,7 @@ $diroutputmassaction=$conf->asset->dir_output . '/temp/massgeneration/'.$user->i $hookmanager->initHooks(array('assetnote')); // Note that conf->hooks_modules contains array // Fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Security check - Protection if external user //if ($user->societe_id > 0) access_forbidden(); diff --git a/htdocs/asset/type.php b/htdocs/asset/type.php index 8be5cdc104e..6803f9d65e7 100644 --- a/htdocs/asset/type.php +++ b/htdocs/asset/type.php @@ -65,7 +65,7 @@ $object = new AssetType($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers { @@ -102,7 +102,7 @@ if ($action == 'add' && $user->rights->asset->write) $object->note = trim($comment); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; if (empty($object->label)) { @@ -155,7 +155,7 @@ if ($action == 'update' && $user->rights->asset->write) $object->note = trim($comment); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; $ret=$object->update($user); diff --git a/htdocs/bom/bom_agenda.php b/htdocs/bom/bom_agenda.php index 3ef8c38f364..6b72b0a6712 100644 --- a/htdocs/bom/bom_agenda.php +++ b/htdocs/bom/bom_agenda.php @@ -74,7 +74,7 @@ $extrafields = new ExtraFields($db); $diroutputmassaction=$conf->bom->dir_output . '/temp/massgeneration/'.$user->id; $hookmanager->initHooks(array('bomagenda','globalcard')); // Note that conf->hooks_modules contains array // Fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label('bom'); +$extrafields->fetch_name_optionals_label($object->table_element); // Load object include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 1496ba56851..5cc6f7e8a57 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -48,7 +48,7 @@ $extrafields = new ExtraFields($db); $diroutputmassaction=$conf->bom->dir_output . '/temp/massgeneration/'.$user->id; $hookmanager->initHooks(array('bomcard', 'globalcard')); // Note that conf->hooks_modules contains array // Fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // Initialize array of search criterias diff --git a/htdocs/bom/bom_document.php b/htdocs/bom/bom_document.php index dadf92ea6d0..826222af8b0 100644 --- a/htdocs/bom/bom_document.php +++ b/htdocs/bom/bom_document.php @@ -63,7 +63,7 @@ $extrafields = new ExtraFields($db); $diroutputmassaction=$conf->bom->dir_output . '/temp/massgeneration/'.$user->id; $hookmanager->initHooks(array('bomdocument', 'globalcard')); // Note that conf->hooks_modules contains array // Fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Load object include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals diff --git a/htdocs/bom/bom_list.php b/htdocs/bom/bom_list.php index d7fce692f07..4b0a6ff29be 100644 --- a/htdocs/bom/bom_list.php +++ b/htdocs/bom/bom_list.php @@ -62,7 +62,7 @@ $diroutputmassaction = $conf->bom->dir_output . '/temp/massgeneration/'.$user->i $hookmanager->initHooks(array('bomlist')); // Note that conf->hooks_modules contains array // Fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); // Load $extrafields->attributes['bom'] +$extrafields->fetch_name_optionals_label($object->table_element); $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); diff --git a/htdocs/bom/bom_note.php b/htdocs/bom/bom_note.php index 6e8d63ab851..914dfcfa4e8 100644 --- a/htdocs/bom/bom_note.php +++ b/htdocs/bom/bom_note.php @@ -44,7 +44,7 @@ $diroutputmassaction=$conf->bom->dir_output . '/temp/massgeneration/'.$user->id; $hookmanager->initHooks(array('bomnote','globalcard')); // Note that conf->hooks_modules contains array // Fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Security check - Protection if external user //if ($user->societe_id > 0) access_forbidden(); diff --git a/htdocs/bom/tpl/objectline_create.tpl.php b/htdocs/bom/tpl/objectline_create.tpl.php index 5fbc0877927..b574efc81df 100644 --- a/htdocs/bom/tpl/objectline_create.tpl.php +++ b/htdocs/bom/tpl/objectline_create.tpl.php @@ -140,7 +140,7 @@ if ($nolinesbefore) { showOptionals($extrafieldsline, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1); + print $objectline->showOptionals($extrafields, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1); } ?> diff --git a/htdocs/bom/tpl/objectline_edit.tpl.php b/htdocs/bom/tpl/objectline_edit.tpl.php index a650b585740..05b9094d10e 100644 --- a/htdocs/bom/tpl/objectline_edit.tpl.php +++ b/htdocs/bom/tpl/objectline_edit.tpl.php @@ -138,7 +138,7 @@ $coldisplay=0; showOptionals($extrafieldsline, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1); + print $objectline->showOptionals($extrafields, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1); } ?> diff --git a/htdocs/bom/tpl/objectline_view.tpl.php b/htdocs/bom/tpl/objectline_view.tpl.php index 49b6f0e6488..9582e69f967 100644 --- a/htdocs/bom/tpl/objectline_view.tpl.php +++ b/htdocs/bom/tpl/objectline_view.tpl.php @@ -149,9 +149,9 @@ $objectline = new BOMLine($object->db); showOptionals($extrafieldsline, 'view', array('style'=>'class="drag drop oddeven"','colspan'=>$coldisplay), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1); + print $line->showOptionals($extrafields, 'view', array('style'=>'class="drag drop oddeven"','colspan'=>$coldisplay), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1); } ?> diff --git a/htdocs/categories/card.php b/htdocs/categories/card.php index cf29dc38561..68e2ff5e1d0 100644 --- a/htdocs/categories/card.php +++ b/htdocs/categories/card.php @@ -68,7 +68,7 @@ if ($catorigin && $type == Categorie::TYPE_PRODUCT) $idCatOrigin = $catorigin; $object = new Categorie($db); $extrafields = new ExtraFields($db); -$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('categorycard')); @@ -137,7 +137,7 @@ if ($action == 'add' && $user->rights->categorie->creer) if ($parent != "-1") $object->fk_parent = $parent; - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; if (! $object->label) diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index 044d0c8c6d6..39db14a9613 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -62,7 +62,7 @@ if ($id > 0) } $extrafields = new ExtraFields($db); -$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('categorycard')); @@ -102,7 +102,7 @@ if ($action == 'update' && $user->rights->categorie->creer) } if (! $error && empty($object->error)) { - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; if (! $error && $object->update($user) > 0) diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index ec4998b6ea3..737b488c090 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -84,7 +84,7 @@ $type=$object->type; if (is_numeric($type)) $type=Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility $extrafields = new ExtraFields($db); -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('categorycard','globalcard')); diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 4bd5ceb4d8f..cf3b2e8cf3a 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -99,7 +99,7 @@ if ($id > 0 && $action!='add') { } // fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); //var_dump($_POST); @@ -361,7 +361,7 @@ if (empty($reshook) && $action == 'add') } // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; if (! $error) @@ -526,7 +526,7 @@ if (empty($reshook) && $action == 'update') } // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; if (!$error) { diff --git a/htdocs/comm/action/list.php b/htdocs/comm/action/list.php index 29a88111f17..efb11a7e22b 100644 --- a/htdocs/comm/action/list.php +++ b/htdocs/comm/action/list.php @@ -82,7 +82,7 @@ $hookmanager->initHooks(array('agendalist')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // If not choice done on calendar owner, we filter on user. diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 49a52188df9..9fa5f1eb86e 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -80,7 +80,7 @@ $object = new Client($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('thirdpartycomm','globalcard')); @@ -194,8 +194,7 @@ if (empty($reshook)) $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from update form - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none')); + $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none')); if ($ret < 0) $error++; if (! $error) { diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index 9609038ca41..33de68f22a1 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -51,7 +51,7 @@ $result=$object->fetch($id); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('mailingcard','globalcard')); diff --git a/htdocs/comm/mailing/class/advtargetemailing.class.php b/htdocs/comm/mailing/class/advtargetemailing.class.php index 006e009c78d..7346bf87543 100644 --- a/htdocs/comm/mailing/class/advtargetemailing.class.php +++ b/htdocs/comm/mailing/class/advtargetemailing.class.php @@ -544,7 +544,7 @@ class AdvanceTargetingMailing extends CommonObject public function query_thirdparty($arrayquery) { // phpcs:enable - global $langs,$conf; + global $langs,$conf,$extrafields; $sql = "SELECT"; $sql.= " t.rowid"; @@ -617,29 +617,29 @@ class AdvanceTargetingMailing extends CommonObject //Standard Extrafield feature if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { - // fetch optionals attributes and labels - dol_include_once('/core/class/extrafields.class.php'); - $extrafields = new ExtraFields($this->db); - $extralabels=$extrafields->fetch_name_optionals_label('societe'); - foreach($extralabels as $key=>$val) { + $elementtype = Societe::$table_element; - if (($extrafields->attribute_type[$key] == 'varchar') || - ($extrafields->attribute_type[$key] == 'text')) { + $extrafields->fetch_name_optionals_label($elementtype); + + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$val) { + + if (($extrafields->attributes[$elementtype]['type'][$key] == 'varchar') || + ($extrafields->attributes[$elementtype]['type'][$key] == 'text')) { if (!empty($arrayquery['options_'.$key])) { $sqlwhere[]= " (te.".$key." LIKE '".$arrayquery['options_'.$key]."')"; } - } elseif (($extrafields->attribute_type[$key] == 'int') || - ($extrafields->attribute_type[$key] == 'double')) { + } elseif (($extrafields->attributes[$elementtype]['type'][$key] == 'int') || + ($extrafields->attributes[$elementtype]['type'][$key] == 'double')) { if (!empty($arrayquery['options_'.$key.'_max'])) { $sqlwhere[]= " (te.".$key." >= ".$arrayquery['options_'.$key.'_max']." AND te.".$key." <= ".$arrayquery['options_'.$key.'_min'].")"; } - } elseif (($extrafields->attribute_type[$key] == 'date') || - ($extrafields->attribute_type[$key] == 'datetime')) { + } elseif (($extrafields->attributes[$elementtype]['type'][$key] == 'date') || + ($extrafields->attributes[$elementtype]['type'][$key] == 'datetime')) { if (!empty($arrayquery['options_'.$key.'_end_dt'])){ $sqlwhere[]= " (te.".$key." >= '".$this->db->idate($arrayquery['options_'.$key.'_st_dt'])."' AND te.".$key." <= '".$this->db->idate($arrayquery['options_'.$key.'_end_dt'])."')"; } - } elseif ($extrafields->attribute_type[$key] == 'boolean') { + } elseif ($extrafields->attributes[$elementtype]['type'][$key] == 'boolean') { if ($arrayquery['options_'.$key]!=''){ $sqlwhere[]= " (te.".$key." = ".$arrayquery['options_'.$key].")"; } @@ -757,29 +757,33 @@ class AdvanceTargetingMailing extends CommonObject //Standard Extrafield feature if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { + $elementtype = Contact::$table_element; + // fetch optionals attributes and labels dol_include_once('/core/class/extrafields.class.php'); $extrafields = new ExtraFields($this->db); - $extralabels=$extrafields->fetch_name_optionals_label('socpeople'); + $extrafields->fetch_name_optionals_label($elementtype); - foreach($extralabels as $key=>$val) { + $extrafields->fetch_name_optionals_label($elementtype); - if (($extrafields->attribute_type[$key] == 'varchar') || - ($extrafields->attribute_type[$key] == 'text')) { + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$val) { + + if (($extrafields->attributes[$elementtype]['type'][$key] == 'varchar') || + ($extrafields->attributes[$elementtype]['type'][$key] == 'text')) { if (!empty($arrayquery['options_'.$key.'_cnct'])) { $sqlwhere[]= " (te.".$key." LIKE '".$arrayquery['options_'.$key.'_cnct']."')"; } - } elseif (($extrafields->attribute_type[$key] == 'int') || - ($extrafields->attribute_type[$key] == 'double')) { + } elseif (($extrafields->attributes[$elementtype]['type'][$key] == 'int') || + ($extrafields->attributes[$elementtype]['type'][$key] == 'double')) { if (!empty($arrayquery['options_'.$key.'_max'.'_cnct'])) { $sqlwhere[]= " (te.".$key." >= ".$arrayquery['options_'.$key.'_max'.'_cnct']." AND te.".$key." <= ".$arrayquery['options_'.$key.'_min'.'_cnct'].")"; } - } elseif (($extrafields->attribute_type[$key] == 'date') || - ($extrafields->attribute_type[$key] == 'datetime')) { + } elseif (($extrafields->attributes[$elementtype]['type'][$key] == 'date') || + ($extrafields->attributes[$elementtype]['type'][$key] == 'datetime')) { if (!empty($arrayquery['options_'.$key.'_end_dt'.'_cnct'])){ $sqlwhere[]= " (te.".$key." >= '".$this->db->idate($arrayquery['options_'.$key.'_st_dt'.'_cnct'])."' AND te.".$key." <= '".$this->db->idate($arrayquery['options_'.$key.'_end_dt'.'_cnct'])."')"; } - } elseif ($extrafields->attribute_type[$key] == 'boolean') { + } elseif ($extrafields->attributes[$elementtype]['type'][$key] == 'boolean') { if ($arrayquery['options_'.$key.'_cnct']!=''){ if ($arrayquery['options_'.$key.'_cnct']==0) { $sqlwhere[]= " (te.".$key." = ".$arrayquery['options_'.$key.'_cnct']." OR ((te.".$key." IS NULL) AND (te.fk_object IS NOT NULL)))"; @@ -857,29 +861,32 @@ class AdvanceTargetingMailing extends CommonObject //Standard Extrafield feature if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { + $elementtype = Societe::$table_element; + // fetch optionals attributes and labels dol_include_once('/core/class/extrafields.class.php'); $extrafields = new ExtraFields($this->db); - $extralabels=$extrafields->fetch_name_optionals_label('societe'); - foreach($extralabels as $key=>$val) { + $extrafields->fetch_name_optionals_label($elementtype); - if (($extrafields->attribute_type[$key] == 'varchar') || - ($extrafields->attribute_type[$key] == 'text')) { + foreach($extrafields->attributes[$elementtype]['label'] as $key=>$val) { + + if (($extrafields->attributes[$elementtype]['type'][$key] == 'varchar') || + ($extrafields->attributes[$elementtype]['type'][$key] == 'text')) { if (!empty($arrayquery['options_'.$key])) { $sqlwhere[]= " (tse.".$key." LIKE '".$arrayquery['options_'.$key]."')"; } - } elseif (($extrafields->attribute_type[$key] == 'int') || - ($extrafields->attribute_type[$key] == 'double')) { + } elseif (($extrafields->attributes[$elementtype]['type'][$key] == 'int') || + ($extrafields->attributes[$elementtype]['type'][$key] == 'double')) { if (!empty($arrayquery['options_'.$key.'_max'])) { $sqlwhere[]= " (tse.".$key." >= ".$arrayquery['options_'.$key.'_max']." AND tse.".$key." <= ".$arrayquery['options_'.$key.'_min'].")"; } - } elseif (($extrafields->attribute_type[$key] == 'date') || - ($extrafields->attribute_type[$key] == 'datetime')) { + } elseif (($extrafields->attributes[$elementtype]['type'][$key] == 'date') || + ($extrafields->attributes[$elementtype]['type'][$key] == 'datetime')) { if (!empty($arrayquery['options_'.$key.'_end_dt'])){ $sqlwhere[]= " (tse.".$key." >= '".$this->db->idate($arrayquery['options_'.$key.'_st_dt'])."' AND tse.".$key." <= '".$this->db->idate($arrayquery['options_'.$key.'_end_dt'])."')"; } - } elseif ($extrafields->attribute_type[$key] == 'boolean') { + } elseif ($extrafields->attributes[$elementtype]['type'][$key] == 'boolean') { if ($arrayquery['options_'.$key]!=''){ $sqlwhere[]= " (tse.".$key." = ".$arrayquery['options_'.$key].")"; } diff --git a/htdocs/comm/mailing/list.php b/htdocs/comm/mailing/list.php index 6e308100b5a..ff69bd00c0c 100644 --- a/htdocs/comm/mailing/list.php +++ b/htdocs/comm/mailing/list.php @@ -53,7 +53,7 @@ $hookmanager->initHooks(array('mailinglist')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 39c80269d8f..b60ebff3e4d 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -93,7 +93,7 @@ $object = new Propal($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Load object if ($id > 0 || ! empty($ref)) { @@ -410,7 +410,7 @@ if (empty($reshook)) } // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) { $error ++; $action = 'create'; @@ -841,9 +841,8 @@ if (empty($reshook)) if (empty($remise_percent)) $remise_percent=0; // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options = $extrafieldsline->getOptionalsFromPost($object->table_element_line, $predef); + $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef); // Unset extrafield if (is_array($extralabelsline)) { // Get extra fields @@ -1210,9 +1209,8 @@ if (empty($reshook)) $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options = $extrafieldsline->getOptionalsFromPost($object->table_element_line); + $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafields->getOptionalsFromPost($object->table_element_line); // Unset extrafield if (is_array($extralabelsline)) { // Get extra fields @@ -1379,8 +1377,7 @@ if (empty($reshook)) $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from update form - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none')); + $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none')); if ($ret < 0) $error++; if (! $error) { diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index 112cc76527d..f81949fb11d 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -129,7 +129,7 @@ $hookmanager->initHooks(array('propallist')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index ff4606655a5..da676fda4b4 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -88,7 +88,7 @@ $object = new Commande($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Load object include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once @@ -284,7 +284,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form if (! $error) { - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; } @@ -673,9 +673,8 @@ if (empty($reshook)) $remise_percent = (GETPOST('remise_percent'.$predef) != '' ? GETPOST('remise_percent'.$predef) : 0); // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options = $extrafieldsline->getOptionalsFromPost($object->table_element_line, $predef); + $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef); // Unset extrafield if (is_array($extralabelsline)) { // Get extra fields @@ -1037,9 +1036,8 @@ if (empty($reshook)) $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value // Extrafields Lines - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options = $extrafieldsline->getOptionalsFromPost($object->table_element_line); + $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafields->getOptionalsFromPost($object->table_element_line); // Unset extrafield POST Data if (is_array($extralabelsline)) { foreach ($extralabelsline as $key => $value) { @@ -1297,8 +1295,7 @@ if (empty($reshook)) $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from update form - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none')); + $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none')); if ($ret < 0) $error++; if (! $error) diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 6db881a656d..75304d34eb2 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -111,7 +111,7 @@ $hookmanager->initHooks(array('orderlist')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label('commande'); +$extrafields->fetch_name_optionals_label('commande'); $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // List of fields to search into when doing a "search in all" diff --git a/htdocs/commande/orderstoinvoice.php b/htdocs/commande/orderstoinvoice.php index da9af8b3569..fae23fa8bcd 100644 --- a/htdocs/commande/orderstoinvoice.php +++ b/htdocs/commande/orderstoinvoice.php @@ -72,8 +72,10 @@ $date_endy = dol_mktime(23, 59, 59, $_REQUEST["date_end_delymonth"], $_REQUEST[" $extrafields = new ExtraFields($db); +$object=new Facture($db); + // fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label('facture'); +$extrafields->fetch_name_optionals_label($object->table_element); if ($action == 'create') { @@ -141,7 +143,6 @@ if (($action == 'create' || $action == 'add') && !$error) $result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid); $usehm=$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE; - $object=new Facture($db); // Insert new invoice in database if ($action == 'add' && $user->rights->facture->creer) @@ -177,7 +178,7 @@ if (($action == 'create' || $action == 'add') && !$error) $object->remise_absolue = $_POST['remise_absolue']; $object->remise_percent = $_POST['remise_percent']; - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; if ($_POST['origin'] && $_POST['originid']) diff --git a/htdocs/compta/bank/bankentries_list.php b/htdocs/compta/bank/bankentries_list.php index 3b2a63cd839..c1b7483ecfd 100644 --- a/htdocs/compta/bank/bankentries_list.php +++ b/htdocs/compta/bank/bankentries_list.php @@ -137,7 +137,7 @@ $hookmanager->initHooks(array('banktransactionlist', $contextpage)); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label('banktransaction'); +$extrafields->fetch_name_optionals_label('banktransaction'); $search_array_options=$extrafields->getOptionalsFromPost('banktransaction', '', 'search_'); $arrayfields=array( diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index 023a757ce73..fd5a2b42723 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -57,8 +57,9 @@ $result=restrictedArea($user, 'banque', $id, 'bank_account&bank_account', '', '' $object = new Account($db); $extrafields = new ExtraFields($db); + // fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('bankcard','globalcard')); @@ -136,7 +137,7 @@ if ($action == 'add') } // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if (! $error) { @@ -241,7 +242,7 @@ if ($action == 'update') if (! $error) { // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); } if (! $error) @@ -433,7 +434,7 @@ if ($action == 'create') print $hookmanager->resPrint; if (empty($reshook)) { - print $object->showOptionals($extrafields, 'edit', $parameters); + print $object->showOptionals($extrafields, 'edit'); } print ''; diff --git a/htdocs/compta/bank/list.php b/htdocs/compta/bank/list.php index 2bdea48487e..77971439f75 100644 --- a/htdocs/compta/bank/list.php +++ b/htdocs/compta/bank/list.php @@ -73,7 +73,7 @@ $hookmanager->initHooks(array('bankaccountlist')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label('bank_account'); +$extrafields->fetch_name_optionals_label('bank_account'); $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // List of fields to search into when doing a "search in all" diff --git a/htdocs/compta/cashcontrol/cashcontrol_card.php b/htdocs/compta/cashcontrol/cashcontrol_card.php index d27f915fe33..aef5c0573f9 100644 --- a/htdocs/compta/cashcontrol/cashcontrol_card.php +++ b/htdocs/compta/cashcontrol/cashcontrol_card.php @@ -72,7 +72,7 @@ $object= new CashControl($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('cashcontrolcard','globalcard')); diff --git a/htdocs/compta/cashcontrol/cashcontrol_list.php b/htdocs/compta/cashcontrol/cashcontrol_list.php index 00ba378c3b4..6b767bc3949 100644 --- a/htdocs/compta/cashcontrol/cashcontrol_list.php +++ b/htdocs/compta/cashcontrol/cashcontrol_list.php @@ -78,8 +78,10 @@ $object=new CashControl($db); $extrafields = new ExtraFields($db); $diroutputmassaction=$conf->monmodule->dir_output . '/temp/massgeneration/'.$user->id; $hookmanager->initHooks(array('cashcontrol')); // Note that conf->hooks_modules contains array + // Fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label('cashcontrol'); // Load $extrafields->attributes['cashcontrol'] +$extrafields->fetch_name_optionals_label($object->table_element); + $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // Default sort order (if not yet defined by previous GETPOST) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index f2b1d12ebde..8cdcb79ff9c 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -902,8 +902,7 @@ if (empty($reshook)) $error = 0; $originentity = GETPOST('originentity'); // Fill array 'array_options' with data from add form - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; // Replacement invoice @@ -1679,8 +1678,8 @@ if (empty($reshook)) $nextSituationInvoice = new Facture($db); $nextSituationInvoice->fetch($id); // create extrafields with data from create form - $extralabels = $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels, $nextSituationInvoice); + $extrafields->fetch_name_optionals_label($nextSituationInvoice->table_element); + $ret = $extrafields->setOptionalsFromPost(null, $nextSituationInvoice); if ($ret > 0) { $nextSituationInvoice->insertExtraFields(); } @@ -1752,9 +1751,8 @@ if (empty($reshook)) $remise_percent = GETPOST('remise_percent' . $predef); // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options = $extrafieldsline->getOptionalsFromPost($object->table_element_line, $predef); + $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef); // Unset extrafield if (is_array($extralabelsline)) { // Get extra fields @@ -2075,9 +2073,8 @@ if (empty($reshook)) $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options = $extrafieldsline->getOptionalsFromPost($object->table_element_line); + $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafields->getOptionalsFromPost($object->table_element_line); // Unset extrafield if (is_array($extralabelsline)) { // Get extra fields @@ -2496,8 +2493,7 @@ if (empty($reshook)) $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from add form - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none')); + $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none')); if ($ret < 0) $error++; if (! $error) @@ -2585,7 +2581,7 @@ llxHeader('', $title, $helpurl); if ($action == 'create') { $facturestatic = new Facture($db); - $extralabels = $extrafields->fetch_name_optionals_label($facturestatic->table_element); + $extrafields->fetch_name_optionals_label($facturestatic->table_element); print load_fiche_titre($langs->trans('NewBill'), '', 'invoicing'); @@ -3460,7 +3456,7 @@ elseif ($id > 0 || ! empty($ref)) } // fetch optionals attributes and labels - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + $extrafields->fetch_name_optionals_label($object->table_element); if ($user->societe_id > 0 && $user->societe_id != $object->socid) { diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 0d8959196ee..a71860c01c1 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -518,14 +518,19 @@ class FactureRec extends CommonInvoice */ public function fetch_lines() { + global $extrafields; + // phpcs:enable $this->lines=array(); // Retreive all extrafield for line // fetch optionals attributes and labels - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; - $extrafieldsline=new ExtraFields($this->db); - $extrafieldsline=$extrafieldsline->fetch_name_optionals_label('facturedet_rec', true); + if (! is_object($extrafields)) + { + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + $extrafields=new ExtraFields($this->db); + } + $extrafields->fetch_name_optionals_label($this->table_element_line, true); $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx, '; $sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,'; @@ -599,7 +604,7 @@ class FactureRec extends CommonInvoice $line->price = $objp->price; $line->remise = $objp->remise; - $extralabelsline = $line->fetch_optionals($line->id); + $line->fetch_optionals($line->id); // Multicurrency $line->fk_multicurrency = $objp->fk_multicurrency; diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 171174ebd04..1bd83bda72b 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -93,7 +93,8 @@ $hookmanager->initHooks(array('invoicereccard','globalcard')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label('facture_rec'); +$extrafields->fetch_name_optionals_label($object->table_element); + $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); $permissionnote = $user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php @@ -426,8 +427,7 @@ if (empty($reshook)) $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from update form - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none')); + $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none')); if ($ret < 0) $error++; if (! $error) @@ -468,9 +468,8 @@ if (empty($reshook)) $remise_percent = GETPOST('remise_percent' . $predef); // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options = $extrafieldsline->getOptionalsFromPost($object->table_element_line, $predef); + $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef); // Unset extrafield if (is_array($extralabelsline)) { @@ -771,9 +770,8 @@ if (empty($reshook)) $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options = $extrafieldsline->getOptionalsFromPost($object->table_element_line); + $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafields->getOptionalsFromPost($object->table_element_line); $objectline = new FactureLigneRec($db); if ($objectline->fetch(GETPOST('lineid', 'int'))) diff --git a/htdocs/compta/facture/invoicetemplate_list.php b/htdocs/compta/facture/invoicetemplate_list.php index 14dec82f40c..cab7f36a5a7 100644 --- a/htdocs/compta/facture/invoicetemplate_list.php +++ b/htdocs/compta/facture/invoicetemplate_list.php @@ -108,7 +108,8 @@ $hookmanager->initHooks(array('invoicereccard','globalcard')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label('facture_rec'); +$extrafields->fetch_name_optionals_label('facture_rec'); + $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); $permissionnote = $user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index d6bbc4d09fe..9fc33015245 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -141,7 +141,8 @@ $hookmanager->initHooks(array('invoicelist')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label('facture'); +$extrafields->fetch_name_optionals_label('facture'); + $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // List of fields to search into when doing a "search in all" diff --git a/htdocs/contact/agenda.php b/htdocs/contact/agenda.php index 64404d2e684..30efcd28632 100644 --- a/htdocs/contact/agenda.php +++ b/htdocs/contact/agenda.php @@ -59,7 +59,7 @@ $object = new Contact($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $object->getCanvas($id); diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index e18332da0ad..1682abf336e 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -60,7 +60,7 @@ $object = new Contact($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $object->getCanvas($id); @@ -206,7 +206,7 @@ if (empty($reshook)) $object->birthday_alert = GETPOST("birthday_alert", 'alpha'); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) { $error++; @@ -373,7 +373,7 @@ if (empty($reshook)) $object->note_private = GETPOST("note_private", 'none'); // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) $error++; if (! $error) diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index b378c8e2626..fdbcb9ee6a6 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -136,7 +136,8 @@ $hookmanager->initHooks(array('contactlist')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label('contact'); +$extrafields->fetch_name_optionals_label('contact'); + $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // List of fields to search into when doing a "search in all" diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index b1903c0d406..691951f2571 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -81,11 +81,10 @@ if ($id > 0 || ! empty($ref) && $action!='add') { } // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label($object->table_element); +$extrafields->fetch_name_optionals_label($object->table_element); // fetch optionals attributes lines and labels -$extrafieldsline = new ExtraFields($db); -$extralabelslines=$extrafieldsline->fetch_name_optionals_label($object->table_element_line); +$extralabelslines=$extrafields->fetch_name_optionals_label($object->table_element_line); $permissionnote=$user->rights->contrat->creer; // Used by the include of actions_setnotes.inc.php $permissiondellink=$user->rights->contrat->creer; // Used by the include of actions_dellink.inc.php @@ -217,7 +216,7 @@ if (empty($reshook)) } // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object); if ($ret < 0) { $error ++; $action = 'create'; @@ -455,9 +454,8 @@ if (empty($reshook)) } // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); - $array_options = $extrafieldsline->getOptionalsFromPost($object->table_element_line, $predef); + $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef); // Unset extrafield if (is_array($extralabelsline)) { // Get extra fields @@ -736,9 +734,8 @@ if (empty($reshook)) } // Extrafields - $extrafieldsline = new ExtraFields($db); - $extralabelsline = $extrafieldsline->fetch_name_optionals_label($objectline->table_element); - $array_options = $extrafieldsline->getOptionalsFromPost($object->table_element_line, $predef); + $extralabelsline = $extrafields->fetch_name_optionals_label($objectline->table_element); + $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef); $objectline->array_options=$array_options; // TODO verifier price_min si fk_product et multiprix @@ -876,8 +873,7 @@ if (empty($reshook)) $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from update form - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute', 'none')); + $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'none')); if ($ret < 0) $error++; if (! $error) { @@ -1712,7 +1708,7 @@ else if (is_array($extralabelslines) && count($extralabelslines)>0) { $line = new ContratLigne($db); $line->fetch_optionals($objp->rowid); - print $line->showOptionals($extrafieldsline, 'view', array('style'=>'class="oddeven"', 'colspan'=>$colspan), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1); + print $line->showOptionals($extrafields, 'view', array('style'=>'class="oddeven"', 'colspan'=>$colspan), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1); } } // Ligne en mode update @@ -1786,7 +1782,7 @@ else if (is_array($extralabelslines) && count($extralabelslines)>0) { $line = new ContratLigne($db); $line->fetch_optionals($objp->rowid); - print $line->showOptionals($extrafieldsline, 'edit', array('style'=>'class="oddeven"', 'colspan'=>$colspan), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1); + print $line->showOptionals($extrafields, 'edit', array('style'=>'class="oddeven"', 'colspan'=>$colspan), '', '', empty($conf->global->MAIN_EXTRAFIELDS_IN_ONE_TD)?0:1); } } diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index cb44f6d3262..c6462cba9b9 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -745,8 +745,9 @@ class Contrat extends CommonObject */ public function fetch_lines($only_product = 0, $loadalsotranslation = 0) { - global $langs, $conf; - // phpcs:enable + // phpcs:enable + global $langs, $conf, $extrafields; + $this->nbofserviceswait=0; $this->nbofservicesopened=0; $this->nbofservicesexpired=0; @@ -758,10 +759,14 @@ class Contrat extends CommonObject $now=dol_now(); - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; - $extrafieldsline=new ExtraFields($this->db); + if (! is_object($extrafields)) + { + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + $extrafields=new ExtraFields($this->db); + } + $line = new ContratLigne($this->db); - $extralabelsline=$extrafieldsline->fetch_name_optionals_label($line->table_element, true); + $extrafields->fetch_name_optionals_label($line->table_element, true); $this->lines=array(); $pos = 0; diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 4aa8fee1983..c6ef860176d 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -100,7 +100,8 @@ $hookmanager->initHooks(array('contractlist')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label('contrat'); +$extrafields->fetch_name_optionals_label('contrat'); + $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // List of fields to search into when doing a "search in all" $fieldstosearchall = array( diff --git a/htdocs/contrat/services_list.php b/htdocs/contrat/services_list.php index d8b4e6814cd..a09b86be590 100644 --- a/htdocs/contrat/services_list.php +++ b/htdocs/contrat/services_list.php @@ -84,7 +84,8 @@ $hookmanager->initHooks(array('contractservicelist')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label('contratdet'); +$extrafields->fetch_name_optionals_label('contratdet'); + $search_array_options=$extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // Security check diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 3183db931f4..74253a19f51 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -163,7 +163,7 @@ abstract class CommonDocGenerator /** * Define array with couple subtitution key => subtitution value * - * @param Object $object Object + * @param Societe $object Object * @param Translate $outputlangs Language object for output * @return array Array of substitution key->code */ @@ -221,7 +221,7 @@ abstract class CommonDocGenerator { require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); - $extralabels = $extrafields->fetch_name_optionals_label('societe', true); + $extrafields->fetch_name_optionals_label($object->table_element, true); $object->fetch_optionals(); foreach($extrafields->attribute_label as $key=>$label) @@ -295,7 +295,7 @@ abstract class CommonDocGenerator // Retrieve extrafields require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); - $extralabels = $extrafields->fetch_name_optionals_label('socpeople', true); + $extrafields->fetch_name_optionals_label($object->table_element, true); $object->fetch_optionals(); foreach($extrafields->attribute_label as $key => $label) @@ -517,7 +517,7 @@ abstract class CommonDocGenerator require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); - $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey, true); + $extrafields->fetch_name_optionals_label($extrafieldkey, true); $object->fetch_optionals(); $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs); @@ -592,7 +592,7 @@ abstract class CommonDocGenerator $array_key="line"; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); - $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey, true); + $extrafields->fetch_name_optionals_label($extrafieldkey, true); $line->fetch_optionals(); $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs); @@ -662,7 +662,7 @@ abstract class CommonDocGenerator { require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); - $extralabels = $extrafields->fetch_name_optionals_label('expedition', true); + $extrafields->fetch_name_optionals_label('expedition', true); $object->fetch_optionals(); $array_shipment = $this->fill_substitutionarray_with_extrafields($object, $array_shipment, $extrafields, $array_key, $outputlangs); @@ -712,7 +712,7 @@ abstract class CommonDocGenerator $array_key = "line"; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); - $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey, true); + $extrafields->fetch_name_optionals_label($extrafieldkey, true); $line->fetch_optionals(); $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 686f3d4f5d9..673baa7c24e 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3918,13 +3918,16 @@ abstract class CommonObject */ public function formAddObjectLine($dateSelector, $seller, $buyer, $defaulttpldir = '/core/tpl') { - global $conf,$user,$langs,$object,$hookmanager; + global $conf,$user,$langs,$object,$hookmanager,$extrafields; global $form,$bcnd,$var; // Line extrafield - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; - $extrafieldsline = new ExtraFields($this->db); - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); + if (! is_object($extrafields)) + { + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + $extrafields = new ExtraFields($this->db); + } + $extrafields->fetch_name_optionals_label($this->table_element_line); // Output template part (modules that overwrite templates must declare this into descriptor) // Use global variables + $dateSelector + $seller and $buyer @@ -3970,7 +3973,7 @@ abstract class CommonObject */ public function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0, $defaulttpldir = '/core/tpl') { - global $conf, $hookmanager, $langs, $user, $object, $form; + global $conf, $hookmanager, $langs, $user, $object, $form, $extrafields; // TODO We should not use global var for this global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax; @@ -3981,11 +3984,14 @@ abstract class CommonObject $num = count($this->lines); // Line extrafield - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; - $extrafieldsline = new ExtraFields($this->db); - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); + if (! is_object($extrafields)) + { + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + $extrafields = new ExtraFields($this->db); + } + $extrafields->fetch_name_optionals_label($this->table_element_line); - $parameters = array('num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); + $parameters = array('num'=>$num, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'table_element_line'=>$this->table_element_line); $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { @@ -4025,18 +4031,18 @@ abstract class CommonObject { if (empty($line->fk_parent_line)) { - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); + $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'table_element_line'=>$line->table_element); $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks } else { - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline, 'fk_parent_line'=>$line->fk_parent_line); + $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'table_element_line'=>$line->table_element, 'fk_parent_line'=>$line->fk_parent_line); $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks } } if (empty($reshook)) { - $this->printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafieldsline, $defaulttpldir); + $this->printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafields, $defaulttpldir); } $i++; @@ -4057,11 +4063,11 @@ abstract class CommonObject * @param string $seller Object of seller third party * @param string $buyer Object of buyer third party * @param int $selected Object line selected - * @param int $extrafieldsline Object of extrafield line attribute + * @param Extrafields $extrafields Object of extrafields * @param string $defaulttpldir Directory where to find the template * @return void */ - public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafieldsline = 0, $defaulttpldir = '/core/tpl') + public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafields = null, $defaulttpldir = '/core/tpl') { global $conf,$langs,$user,$object,$hookmanager; global $form,$bc,$bcdd; @@ -4897,6 +4903,8 @@ abstract class CommonObject public function fetch_optionals($rowid = null, $optionsArray = null) { // phpcs:enable + global $extrafields; + if (empty($rowid)) $rowid=$this->id; // To avoid SQL errors. Probably not the better solution though @@ -4909,7 +4917,6 @@ abstract class CommonObject if (! is_array($optionsArray)) { // If $extrafields is not a known object, we initialize it. Best practice is to have $extrafields defined into card.php or list.php page. - global $extrafields; if (! isset($extrafields) || ! is_object($extrafields)) { require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; @@ -6591,8 +6598,8 @@ abstract class CommonObject //$out .= "titlefield"; //if (GETPOST('action', 'none') == 'create') $out.='create'; // BUG #11554 : For public page, use red dot for required fields, instead of bold label - $context = isset($params["context"]) ? $params["context"] : "none"; - if ($context=="public") { // Public page : red dot instead of bold ble characters + $tpl_context = isset($params["tpl_context"]) ? $params["tpl_context"] : "none"; + if ($tpl_context=="public") { // Public page : red dot instead of fieldrequired characters $out .= '">'; if (! empty($extrafields->attributes[$this->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$this->table_element]['help'][$key]); else $out .= $labeltoshow; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index ee41d96c2af..e465742cfef 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -825,7 +825,7 @@ class ExtraFields * Load array this->attributes, or old this->attribute_xxx like attribute_label, attribute_type, ... * * @param string $elementtype Type of element ('adherent', 'commande', 'thirdparty', 'facture', 'propal', 'product', ...). - * @param boolean $forceload Force load of extra fields whatever is option MAIN_EXTRAFIELDS_DISABLED. Deprecated. Should not be required. + * @param boolean $forceload Force load of extra fields whatever is status of cache. * @return array Array of attributes keys+label for all extra fields. */ public function fetch_name_optionals_label($elementtype, $forceload = false) @@ -835,14 +835,18 @@ class ExtraFields if (empty($elementtype)) return array(); - if ($elementtype == 'thirdparty') $elementtype='societe'; - if ($elementtype == 'contact') $elementtype='socpeople'; + if ($elementtype == 'thirdparty') $elementtype='societe'; + if ($elementtype == 'contact') $elementtype='socpeople'; if ($elementtype == 'order_supplier') $elementtype='commande_fournisseur'; $array_name_label=array(); // To avoid conflicts with external modules. TODO Remove this. - if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label; + if (empty($forceload) && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label; + + // If already loaded + // TODO Enable this cache test + // if (empty($forceload) && ! empty($this->attributes[$tab->elementtype]['loaded'])) return $array_name_label; // Set array of label of entity // TODO Remove completely loading of label. This should be done by presentation. @@ -2007,14 +2011,15 @@ class ExtraFields /** * Fill array_options property of object by extrafields value (using for data sent by forms) * - * @param array $extralabels Deprecated $array of extrafields + * @param array $extralabels Deprecated (old $array of extrafields, now set this to null) * @param object $object Object - * @param string $onlykey Only following key is filled. When we make update of only one extrafield ($action = 'update_extras'), calling page must must set this to avoid to have other extrafields being reset. + * @param string $onlykey Only the following key is filled. When we make update of only one extrafield ($action = 'update_extras'), calling page must set this to avoid to have other extrafields being reset. * @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example) */ public function setOptionalsFromPost($extralabels, &$object, $onlykey = '') { global $_POST, $langs; + $nofillrequired=0;// For error when required field left blank $error_field_required = array(); diff --git a/htdocs/core/class/html.formactions.class.php b/htdocs/core/class/html.formactions.class.php index fb3841e8088..b0fb1131f17 100644 --- a/htdocs/core/class/html.formactions.class.php +++ b/htdocs/core/class/html.formactions.class.php @@ -241,7 +241,7 @@ class FormActions // Ref print ''.$ref.''; // Onwer - print ''; + print ''; if (! empty($action->userownerid)) { if (is_object($cacheusers[$action->userownerid])) diff --git a/htdocs/core/class/html.formticket.class.php b/htdocs/core/class/html.formticket.class.php index 49c7a28f1e1..8d0c45bbb41 100644 --- a/htdocs/core/class/html.formticket.class.php +++ b/htdocs/core/class/html.formticket.class.php @@ -145,7 +145,7 @@ class FormTicket $ticketstat = new Ticket($this->db); $extrafields = new ExtraFields($this->db); - $extralabels = $extrafields->fetch_name_optionals_label($ticketstat->table_element); + $extrafields->fetch_name_optionals_label($ticketstat->table_element); print "\n\n"; diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 6d8e396c361..30cd6178944 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -913,7 +913,7 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '') $contactstatic = new Contact($db); - $extralabels=$extrafields->fetch_name_optionals_label($contactstatic->table_element); + $extrafields->fetch_name_optionals_label($contactstatic->table_element); $contactstatic->fields=array( 'name' =>array('type'=>'varchar(128)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1), diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 66b20707ecb..d6dc59d1dcc 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -972,11 +972,10 @@ function projectLinesPerAction(&$inc, $parent, $fuser, $lines, &$level, &$projec * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon * @param int $oldprojectforbreak Old project id of last project break * @param array $arrayfields Array of additional column - * @param array $extrafields Array of additional column - * @param array $extralabels Array of additional column + * @param Extrafields $extrafields Object extrafields * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks */ -function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak = 0, $arrayfields = array(), $extrafields = '', $extralabels = array()) +function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak = 0, $arrayfields = array(), $extrafields = null) { global $conf, $db, $user, $bc, $langs; global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic; @@ -1314,7 +1313,7 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr { //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level); //var_dump($totalforeachday); - $ret = projectLinesPerDay($inc, $lines[$i]->id, $fuser, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $isavailable, $oldprojectforbreak, $arrayfields, $extrafields, $extralabels); + $ret = projectLinesPerDay($inc, $lines[$i]->id, $fuser, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $isavailable, $oldprojectforbreak, $arrayfields, $extrafields); //var_dump('ret with parent='.$lines[$i]->id.' level='.$level); //var_dump($ret); foreach($ret as $key => $val) @@ -1352,11 +1351,10 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr * @param array $isavailable Array with data that say if user is available for several days for morning and afternoon * @param int $oldprojectforbreak Old project id of last project break * @param array $arrayfields Array of additional column - * @param array $extrafields Array of additional column - * @param array $extralabels Array of additional column + * @param Extrafields $extrafields Object extrafields * @return array Array with time spent for $fuser for each day of week on tasks in $lines and substasks */ -function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak = 0, $arrayfields = array(), $extrafields = '', $extralabels = array()) +function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak = 0, $arrayfields = array(), $extrafields = null) { global $conf, $db, $user, $bc, $langs; global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic; @@ -1684,7 +1682,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ { //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level); //var_dump($totalforeachday); - $ret = projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak, $arrayfields, $extrafields, $extralabels); + $ret = projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak, $arrayfields, $extrafields); //var_dump('ret with parent='.$lines[$i]->id.' level='.$level); //var_dump($ret); foreach($ret as $key => $val) diff --git a/htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php b/htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php index 5389846c51a..6883a089bda 100644 --- a/htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php +++ b/htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php @@ -148,7 +148,7 @@ class doc_generic_project_odt extends ModelePDFProjects require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element, true); + $extrafields->fetch_name_optionals_label($object->table_element, true); $object->fetch_optionals(); $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs); @@ -189,8 +189,8 @@ class doc_generic_project_odt extends ModelePDFProjects require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); - $extralabels = $extrafields->fetch_name_optionals_label($task->table_element, true); - $task->fetch_optionals($task->id, $extralabels); + $extrafields->fetch_name_optionals_label($task->table_element, true); + $task->fetch_optionals($task->id); $resarray = $this->fill_substitutionarray_with_extrafields($task, $resarray, $extrafields, 'task', $outputlangs); @@ -235,7 +235,7 @@ class doc_generic_project_odt extends ModelePDFProjects // fetch external user extrafields require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields=new ExtraFields($this->db); - $extralabels=$extrafields->fetch_name_optionals_label($ct->table_element, true); + $extrafields->fetch_name_optionals_label($ct->table_element, true); $extrafields_num = $ct->fetch_optionals(); //dol_syslog(get_class($this)."::get_substitutionarray_project_contacts: ===== Number of Extrafields found: ".$extrafields_num, LOG_DEBUG); foreach($ct->array_options as $efkey => $efval) { diff --git a/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php b/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php index d0e7285febf..78e8312b0bb 100644 --- a/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php +++ b/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php @@ -154,7 +154,7 @@ class doc_generic_task_odt extends ModelePDFTask require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); - $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey, true); + $extrafields->fetch_name_optionals_label($extrafieldkey, true); $object->fetch_optionals(); $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs); diff --git a/htdocs/core/modules/stock/doc/pdf_stdmovement.modules.php b/htdocs/core/modules/stock/doc/pdf_stdmovement.modules.php index 35f87889a6e..6a924658f2c 100644 --- a/htdocs/core/modules/stock/doc/pdf_stdmovement.modules.php +++ b/htdocs/core/modules/stock/doc/pdf_stdmovement.modules.php @@ -245,7 +245,7 @@ class pdf_stdmovement extends ModelePDFMovement $extrafields = new ExtraFields($db); // fetch optionals attributes and labels - $extralabels = $extrafields->fetch_name_optionals_label('movement'); + $extrafields->fetch_name_optionals_label('movement'); $search_array_options=$extrafields->getOptionalsFromPost('movement', '', 'search_'); $productlot=new ProductLot($db); diff --git a/htdocs/core/tpl/advtarget.tpl.php b/htdocs/core/tpl/advtarget.tpl.php index ac1eed387a4..312ba8ea78e 100644 --- a/htdocs/core/tpl/advtarget.tpl.php +++ b/htdocs/core/tpl/advtarget.tpl.php @@ -261,26 +261,27 @@ print '