From d0e9290dafaed4b781425b0d23da6a7bf4339413 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 25 Jan 2023 15:27:10 +0100 Subject: [PATCH] NEW An external module can modify the quick search fields --- htdocs/bom/bom_list.php | 2 +- htdocs/bookcal/availabilities_list.php | 2 +- htdocs/bookcal/booking_list.php | 2 +- .../compta/cashcontrol/cashcontrol_list.php | 2 +- htdocs/contrat/class/contrat.class.php | 9 ++++---- htdocs/contrat/list.php | 23 ++++++++++++------- .../conferenceorbooth_list.php | 2 +- .../knowledgerecord_list.php | 2 +- .../modulebuilder/template/myobject_list.php | 9 +++++++- htdocs/partnership/partnership_list.php | 2 +- .../recruitmentcandidature_list.php | 2 +- htdocs/ticket/list.php | 2 +- htdocs/user/group/list.php | 2 +- 13 files changed, 38 insertions(+), 23 deletions(-) diff --git a/htdocs/bom/bom_list.php b/htdocs/bom/bom_list.php index 601eb9b75b3..c5e5491dff8 100644 --- a/htdocs/bom/bom_list.php +++ b/htdocs/bom/bom_list.php @@ -517,7 +517,7 @@ if ($search_all) { $fieldstosearchall[$key] = $langs->trans($val); $setupstring .= $key."=".$val.";"; } - print ''."\n"; + print ''."\n"; print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'."\n"; } diff --git a/htdocs/bookcal/availabilities_list.php b/htdocs/bookcal/availabilities_list.php index 26d66ce0ca4..414faf2dc5a 100644 --- a/htdocs/bookcal/availabilities_list.php +++ b/htdocs/bookcal/availabilities_list.php @@ -470,7 +470,7 @@ if ($search_all) { $fieldstosearchall[$key] = $langs->trans($val); $setupstring .= $key."=".$val.";"; } - print ''."\n"; + print ''."\n"; print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'."\n"; } diff --git a/htdocs/bookcal/booking_list.php b/htdocs/bookcal/booking_list.php index 2e4fbfccd16..3c78ffea120 100644 --- a/htdocs/bookcal/booking_list.php +++ b/htdocs/bookcal/booking_list.php @@ -470,7 +470,7 @@ if ($search_all) { $fieldstosearchall[$key] = $langs->trans($val); $setupstring .= $key."=".$val.";"; } - print ''."\n"; + print ''."\n"; print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'."\n"; } diff --git a/htdocs/compta/cashcontrol/cashcontrol_list.php b/htdocs/compta/cashcontrol/cashcontrol_list.php index a1e5dae0c91..05612f54166 100644 --- a/htdocs/compta/cashcontrol/cashcontrol_list.php +++ b/htdocs/compta/cashcontrol/cashcontrol_list.php @@ -423,7 +423,7 @@ if ($search_all) { $fieldstosearchall[$key] = $langs->trans($val); $setupstring .= $key."=".$val.";"; } - print ''."\n"; + print ''."\n"; print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'."\n"; } diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 4d08fdb96cd..bf945eeae96 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -225,9 +225,10 @@ class Contrat extends CommonObject */ public $fields = array( 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10), - 'ref' =>array('type'=>'varchar(50)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>-1, 'showoncombobox'=>1, 'position'=>15), + 'ref' =>array('type'=>'varchar(50)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>-1, 'showoncombobox'=>1, 'position'=>15, 'searchall'=>1), 'ref_ext' =>array('type'=>'varchar(255)', 'label'=>'Ref ext', 'enabled'=>1, 'visible'=>0, 'position'=>20), - 'ref_supplier' =>array('type'=>'varchar(50)', 'label'=>'Ref supplier', 'enabled'=>1, 'visible'=>-1, 'position'=>25), + 'ref_customer' =>array('type'=>'varchar(50)', 'label'=>'RefCustomer', 'enabled'=>1, 'visible'=>-1, 'position'=>25, 'searchall'=>1), + 'ref_supplier' =>array('type'=>'varchar(50)', 'label'=>'RefSupplier', 'enabled'=>1, 'visible'=>-1, 'position'=>26, 'searchall'=>1), 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>30, 'index'=>1), 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>35), 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>40), @@ -237,8 +238,8 @@ class Contrat extends CommonObject 'fk_commercial_signature' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'SaleRepresentative Signature', 'enabled'=>1, 'visible'=>-1, 'position'=>80), 'fk_commercial_suivi' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'SaleRepresentative follower', 'enabled'=>1, 'visible'=>-1, 'position'=>85), 'fk_user_author' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>90), - 'note_public' =>array('type'=>'text', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>105), - 'note_private' =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>110), + 'note_public' =>array('type'=>'text', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>105, 'searchall'=>1), + 'note_private' =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>110, 'searchall'=>1), 'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>1, 'visible'=>0, 'position'=>115), 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>120), 'extraparams' =>array('type'=>'varchar(255)', 'label'=>'Extraparams', 'enabled'=>1, 'visible'=>-1, 'position'=>125), diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index f24bbad4a85..31d489c4b1f 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -133,16 +133,23 @@ $extrafields->fetch_name_optionals_label($object->table_element); $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); // List of fields to search into when doing a "search in all" -$fieldstosearchall = array( - 'c.ref'=>'Ref', - 'c.ref_customer'=>'RefCustomer', - 'c.ref_supplier'=>'RefSupplier', - 's.nom'=>"ThirdParty", - 'c.note_public'=>'NotePublic', -); +$fieldstosearchall = array(); +foreach ($object->fields as $key => $val) { + if (!empty($val['searchall'])) { + $fieldstosearchall['c.'.$key] = $val['label']; + } +} +$fieldstosearchall["s.nom"] = "ThirdParty"; if (empty($user->socid)) { $fieldstosearchall["c.note_private"] = "NotePrivate"; } +$parameters = array('fieldstosearchall'=>$fieldstosearchall); +$reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook > 0) { + $fieldstosearchall = $hookmanager->resArray['fieldstosearchall']; +} elseif ($reshook == 0) { + $fieldstosearchall = array_merge($fieldstosearchall, $hookmanager->resArray['fieldstosearchall']); +} $arrayfields = array( 'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1, 'position'=>10), @@ -651,7 +658,7 @@ if ($search_all) { $fieldstosearchall[$key] = $langs->trans($val); $setupstring .= $key."=".$val.";"; } - print ''."\n"; + print ''."\n"; print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'."\n"; } diff --git a/htdocs/eventorganization/conferenceorbooth_list.php b/htdocs/eventorganization/conferenceorbooth_list.php index 21172d774d9..06fb65a8b10 100644 --- a/htdocs/eventorganization/conferenceorbooth_list.php +++ b/htdocs/eventorganization/conferenceorbooth_list.php @@ -721,7 +721,7 @@ if ($search_all) { $fieldstosearchall[$key] = $langs->trans($val); $setupstring .= $key."=".$val.";"; } - print ''."\n"; + print ''."\n"; print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'."\n"; } diff --git a/htdocs/knowledgemanagement/knowledgerecord_list.php b/htdocs/knowledgemanagement/knowledgerecord_list.php index 7f3e3cec2c1..7cd5a24c764 100644 --- a/htdocs/knowledgemanagement/knowledgerecord_list.php +++ b/htdocs/knowledgemanagement/knowledgerecord_list.php @@ -469,7 +469,7 @@ if ($search_all) { $fieldstosearchall[$key] = $langs->trans($val); $setupstring .= $key."=".$val.";"; } - print ''."\n"; + print ''."\n"; print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'."\n"; } diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 88775b823f5..66aa7b0b35e 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -118,7 +118,7 @@ $pagenext = $page + 1; $object = new MyObject($db); $extrafields = new ExtraFields($db); $diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id; -$hookmanager->initHooks(array('myobjectlist')); // Note that conf->hooks_modules contains array +$hookmanager->initHooks(array($contextpage)); // Note that conf->hooks_modules contains array of activated contexes // Fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); @@ -155,6 +155,13 @@ foreach ($object->fields as $key => $val) { $fieldstosearchall['t.'.$key] = $val['label']; } } +$parameters = array('fieldstosearchall'=>$fieldstosearchall); +$reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook > 0) { + $fieldstosearchall = $hookmanager->resArray['fieldstosearchall']; +} elseif ($reshook == 0) { + $fieldstosearchall = array_merge($fieldstosearchall, $hookmanager->resArray['fieldstosearchall']); +} // Definition of array of fields for columns $arrayfields = array(); diff --git a/htdocs/partnership/partnership_list.php b/htdocs/partnership/partnership_list.php index a795d8d33f4..7144f201022 100644 --- a/htdocs/partnership/partnership_list.php +++ b/htdocs/partnership/partnership_list.php @@ -664,7 +664,7 @@ if ($search_all) { $fieldstosearchall[$key] = $langs->trans($val); $setupstring .= $key."=".$val.";"; } - print ''."\n"; + print ''."\n"; print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'."\n"; } diff --git a/htdocs/recruitment/recruitmentcandidature_list.php b/htdocs/recruitment/recruitmentcandidature_list.php index aff8c86a955..95b6ac6203d 100644 --- a/htdocs/recruitment/recruitmentcandidature_list.php +++ b/htdocs/recruitment/recruitmentcandidature_list.php @@ -571,7 +571,7 @@ if ($search_all) { $fieldstosearchall[$key] = $langs->trans($val); $setupstring .= $key."=".$val.";"; } - print ''."\n"; + print ''."\n"; print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'."\n"; } diff --git a/htdocs/ticket/list.php b/htdocs/ticket/list.php index 1d2cefaf622..f3e2c82d703 100644 --- a/htdocs/ticket/list.php +++ b/htdocs/ticket/list.php @@ -782,7 +782,7 @@ if ($search_all) { $fieldstosearchall[$key] = $langs->trans($val); $setupstring .= $key."=".$val.";"; } - print ''."\n"; + print ''."\n"; print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'."\n"; } diff --git a/htdocs/user/group/list.php b/htdocs/user/group/list.php index 7e707b6b4fc..b0327eebe08 100644 --- a/htdocs/user/group/list.php +++ b/htdocs/user/group/list.php @@ -285,7 +285,7 @@ if ($search_all) { $fieldstosearchall[$key] = $langs->trans($val); $setupstring .= $key."=".$val.";"; } - print ''."\n"; + print ''."\n"; print '
'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'
'."\n"; }