forked from Wavyzz/dolibarr
NEW Can use ^ and $ (to say start with or end with like regex syntax)
into search fields when search field is text. Bonus: ^$ can filter all lines with field not defined.
This commit is contained in:
@@ -5471,14 +5471,36 @@ function natural_search($fields, $value, $mode=0, $nofirstand=0)
|
||||
$newres .= ($i2 > 0 ? ' OR ' : '') . $field . " IN (" . $db->escape(trim($crit)) . ")";
|
||||
$i2++; // a criteria was added to string
|
||||
}
|
||||
else
|
||||
else // $mode=0
|
||||
{
|
||||
$textcrit = '';
|
||||
$tmpcrits = explode('|',$crit);
|
||||
$i3 = 0;
|
||||
foreach($tmpcrits as $tmpcrit)
|
||||
{
|
||||
$newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '') . $field . " LIKE '%" . $db->escape(trim($tmpcrit)) . "%'";
|
||||
$newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '') . $field . " LIKE '";
|
||||
|
||||
$tmpcrit=trim($tmpcrit);
|
||||
$tmpcrit2=$tmpcrit;
|
||||
$tmpbefore='%'; $tmpafter='%';
|
||||
if (preg_match('/^[\^\$]/', $tmpcrit))
|
||||
{
|
||||
$tmpbefore='';
|
||||
$tmpcrit2 = preg_replace('/^[\^\$]/', '', $tmpcrit2);
|
||||
}
|
||||
if (preg_match('/[\^\$]$/', $tmpcrit))
|
||||
{
|
||||
$tmpafter='';
|
||||
$tmpcrit2 = preg_replace('/[\^\$]$/', '', $tmpcrit2);
|
||||
}
|
||||
$newres .= $tmpbefore;
|
||||
$newres .= $db->escape($tmpcrit2);
|
||||
$newres .= $tmpafter;
|
||||
$newres .= "'";
|
||||
if (empty($tmpcrit2))
|
||||
{
|
||||
$newres .= ' OR ' . $field . " IS NULL";
|
||||
}
|
||||
$i3++;
|
||||
}
|
||||
$i2++; // a criteria was added to string
|
||||
|
||||
Reference in New Issue
Block a user