From 17f77b8edb934d36fab2edcb707a7c8389d36259 Mon Sep 17 00:00:00 2001 From: abb Date: Tue, 9 Feb 2021 23:46:07 +0100 Subject: [PATCH 1/3] New : Hook selectForFormsListWhere --- htdocs/core/class/html.form.class.php | 51 +++++++++++++++------------ 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 4284b009019..4a5b7fcb443 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6300,7 +6300,7 @@ class Form */ public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0) { - global $conf, $langs, $user; + global $conf, $langs, $user,$hookmanager; //print "$objecttmp->filter, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled"; @@ -6346,27 +6346,34 @@ class Form } if ($objecttmp->ismultientitymanaged == 'fk_soc@societe') if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= " WHERE 1=1"; - if (isset($objecttmp->ismultientitymanaged) && $objecttmp->ismultientitymanaged == 1) $sql .= " AND t.entity IN (".getEntity($objecttmp->table_element).")"; - if (isset($objecttmp->ismultientitymanaged) && !is_numeric($objecttmp->ismultientitymanaged)) { - $sql .= ' AND parenttable.entity = t.'.$tmparray[0]; - } - if ($objecttmp->ismultientitymanaged == 1 && !empty($user->socid)) { - if ($objecttmp->element == 'societe') $sql .= " AND t.rowid = ".$user->socid; - else $sql .= " AND t.fk_soc = ".$user->socid; - } - if ($searchkey != '') $sql .= natural_search(explode(',', $fieldstoshow), $searchkey); - if ($objecttmp->ismultientitymanaged == 'fk_soc@societe') { - if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; - } - if ($objecttmp->filter) { // Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" - /*if (! DolibarrApi::_checkFilters($objecttmp->filter)) - { - throw new RestException(503, 'Error when validating parameter sqlfilters '.$objecttmp->filter); - }*/ - $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; - $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'Form::forgeCriteriaCallback', $objecttmp->filter).")"; - } + + // Add where from hooks + $parameters = array(); + $reshook = $hookmanager->executeHooks('selectForFormsListWhere', $parameters); // Note that $action and $object may have been modified by hook + if(!empty($hookmanager->resPrint)) $sql .= $hookmanager->resPrint; + else { + $sql .= " WHERE 1=1"; + if (isset($objecttmp->ismultientitymanaged) && $objecttmp->ismultientitymanaged == 1) $sql .= " AND t.entity IN (".getEntity($objecttmp->table_element).")"; + if (isset($objecttmp->ismultientitymanaged) && !is_numeric($objecttmp->ismultientitymanaged)) { + $sql .= ' AND parenttable.entity = t.'.$tmparray[0]; + } + if ($objecttmp->ismultientitymanaged == 1 && !empty($user->socid)) { + if ($objecttmp->element == 'societe') $sql .= " AND t.rowid = ".$user->socid; + else $sql .= " AND t.fk_soc = ".$user->socid; + } + if ($searchkey != '') $sql .= natural_search(explode(',', $fieldstoshow), $searchkey); + if ($objecttmp->ismultientitymanaged == 'fk_soc@societe') { + if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + } + if ($objecttmp->filter) { // Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" + /*if (! DolibarrApi::_checkFilters($objecttmp->filter)) + { + throw new RestException(503, 'Error when validating parameter sqlfilters '.$objecttmp->filter); + }*/ + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'Form::forgeCriteriaCallback', $objecttmp->filter).")"; + } + } $sql .= $this->db->order($fieldstoshow, "ASC"); //$sql.=$this->db->plimit($limit, 0); //print $sql; From 72bfa81082f3b539d7d85544fceed6e61eea1b12 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 10 Feb 2021 14:14:28 +0100 Subject: [PATCH 2/3] Update html.form.class.php --- htdocs/core/class/html.form.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 4a5b7fcb443..a68b67e1dde 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6350,7 +6350,7 @@ class Form // Add where from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('selectForFormsListWhere', $parameters); // Note that $action and $object may have been modified by hook - if(!empty($hookmanager->resPrint)) $sql .= $hookmanager->resPrint; + if (!empty($hookmanager->resPrint)) $sql .= $hookmanager->resPrint; else { $sql .= " WHERE 1=1"; if (isset($objecttmp->ismultientitymanaged) && $objecttmp->ismultientitymanaged == 1) $sql .= " AND t.entity IN (".getEntity($objecttmp->table_element).")"; From e37a4be1d62b4e3e4f1592fcef4663a7283a1a52 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 11 Feb 2021 20:10:15 +0100 Subject: [PATCH 3/3] Update html.form.class.php --- htdocs/core/class/html.form.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index a68b67e1dde..f31254a4c95 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6300,7 +6300,7 @@ class Form */ public function selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled = 0) { - global $conf, $langs, $user,$hookmanager; + global $conf, $langs, $user, $hookmanager; //print "$objecttmp->filter, $htmlname, $preselectedvalue, $showempty = '', $searchkey = '', $placeholder = '', $morecss = '', $moreparams = '', $forcecombo = 0, $outputmode = 0, $disabled";