diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d99eed9aa62..fc961779ba9 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7145,6 +7145,28 @@ 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)) . ',%\''; + $newres .= ')'; + $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);