From 8a0baaad170b30573507be6385ece30b7fcacb74 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Tue, 10 Apr 2018 16:25:06 +0200 Subject: [PATCH 1/2] fix #8480 --- htdocs/core/lib/functions.lib.php | 21 +++++++++++++++++++ .../tpl/extrafields_list_search_sql.tpl.php | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index a75c9176893..a598d6a83d6 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6727,6 +6727,27 @@ function natural_search($fields, $value, $mode=0, $nofirstand=0) $i2++; // a criteria was added to string } } + else if ($mode == 4) + { + $tmparray=explode(',',trim($crit)); + + if (count($tmparray)) + { + $listofcodes=''; + + foreach($tmparray as $val) + { + if ($val) + { + $newres .= ($i2 > 0 ? ' OR ' : '') . $field . ' LIKE \'' . $db->escape(trim($val)) . ',%\''; + $newres .= ' OR '. $field . ' = \'' . $db->escape(trim($val)) . '\''; + $newres .= ' OR '. $field . ' LIKE \'%,' . $db->escape(trim($val)) . '\''; + $newres .= ' OR '. $field . ' LIKE \'%,' . $db->escape(trim($val)) . ',%\''; + $i2++; + } + } + } + } else // $mode=0 { $textcrit = ''; diff --git a/htdocs/core/tpl/extrafields_list_search_sql.tpl.php b/htdocs/core/tpl/extrafields_list_search_sql.tpl.php index 7006a54351b..e40ac5f2a07 100644 --- a/htdocs/core/tpl/extrafields_list_search_sql.tpl.php +++ b/htdocs/core/tpl/extrafields_list_search_sql.tpl.php @@ -15,7 +15,8 @@ foreach ($search_array_options as $key => $val) $typ=$extrafields->attribute_type[$tmpkey]; $mode_search=0; if (in_array($typ, array('int','double','real'))) $mode_search=1; // Search on a numeric - if (in_array($typ, array('sellist','link','chkbxlst','checkbox')) && $crit != '0' && $crit != '-1') $mode_search=2; // Search on a foreign key int + if (in_array($typ, array('sellist','link')) && $crit != '0' && $crit != '-1') $mode_search=2; // Search on a foreign key int + if (in_array($typ, array('chkbxlst','checkbox'))) $mode_search=4; // Search on a multiselect field with sql type = text if ($crit != '' && (! in_array($typ, array('select','sellist')) || $crit != '0') && (! in_array($typ, array('link')) || $crit != '-1')) { $sql .= natural_search('ef.'.$tmpkey, $crit, $mode_search); From 1aace69b1a6ebbfdb234257cecf48a9b6b38bfe8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 11 Apr 2018 17:37:00 +0200 Subject: [PATCH 2/2] Update functions.lib.php --- htdocs/core/lib/functions.lib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index a598d6a83d6..fd358a04717 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6739,10 +6739,11 @@ function natural_search($fields, $value, $mode=0, $nofirstand=0) { if ($val) { - $newres .= ($i2 > 0 ? ' OR ' : '') . $field . ' LIKE \'' . $db->escape(trim($val)) . ',%\''; + $newres .= ($i2 > 0 ? ' OR (' : '(') . $field . ' LIKE \'' . $db->escape(trim($val)) . ',%\''; $newres .= ' OR '. $field . ' = \'' . $db->escape(trim($val)) . '\''; $newres .= ' OR '. $field . ' LIKE \'%,' . $db->escape(trim($val)) . '\''; $newres .= ' OR '. $field . ' LIKE \'%,' . $db->escape(trim($val)) . ',%\''; + $newres .= ')'; $i2++; } }