2
0
forked from Wavyzz/dolibarr

Merge branch '17.0' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur
2023-04-08 15:13:44 +02:00
8 changed files with 30 additions and 28 deletions

View File

@@ -9884,10 +9884,10 @@ function dol_getmypid()
* like "keyword1 keyword2" = We want record field like keyword1 AND field like keyword2
* or like "keyword1|keyword2" = We want record field like keyword1 OR field like keyword2
* If param $mode is 1, can contains an operator <, > or = like "<10" or ">=100.5 < -1000"
* If param $mode is 2, can contains a list of int id separated by comma like "1,3,4"
* If param $mode is 3, can contains a list of string separated by comma like "a,b,c"
* @param integer $mode 0=value is list of keyword strings, 1=value is a numeric test (Example ">5.5 <10"), 2=value is a list of ID separated with comma (Example '1,3,4')
* 3=value is list of string separated with comma (Example 'text 1,text 2'), 4=value is a list of ID separated with comma (Example '2,7') to be used to search into a multiselect string '1,2,3,4'
* If param $mode is 2 or -2, can contains a list of int id separated by comma like "1,3,4"
* If param $mode is 3 or -3, can contains a list of string separated by comma like "a,b,c".
* @param integer $mode 0=value is list of keyword strings, 1=value is a numeric test (Example ">5.5 <10"), 2=value is a list of ID separated with comma (Example '1,3,4'), -2 is for exclude list,
* 3=value is list of string separated with comma (Example 'text 1,text 2'), -3 if for exclude list, 4=value is a list of ID separated with comma (Example '2,7') to be used to search into a multiselect string '1,2,3,4'
* @param integer $nofirstand 1=Do not output the first 'AND'
* @return string $res The statement to append to the SQL query
* @see dolSqlDateFilter()
@@ -9902,7 +9902,7 @@ function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
$value = preg_replace('/\*/', '%', $value); // Replace * with %
}
if ($mode == 1) {
$value = preg_replace('/([!<>=]+)\s+([0-9'.preg_quote($langs->trans("DecimalSeparator"), '/').'\-])/', '\1\2', $value); // Clean string '< 10' into '<10' so we can the explode on space to get all tests to do
$value = preg_replace('/([!<>=]+)\s+([0-9'.preg_quote($langs->trans("DecimalSeparator"), '/').'\-])/', '\1\2', $value); // Clean string '< 10' into '<10' so we can then explode on space to get all tests to do
}
$value = preg_replace('/\s*\|\s*/', '|', $value);
@@ -9913,16 +9913,15 @@ function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
$fields = array($fields);
}
$j = 0;
foreach ($crits as $crit) {
$i1 = 0; // count the nb of and criteria added (all fields / criterias)
foreach ($crits as $crit) { // Loop on each AND criteria
$crit = trim($crit);
$i = 0;
$i2 = 0;
$i2 = 0; // count the nb of valid criteria added for this this first criteria
$newres = '';
foreach ($fields as $field) {
if ($mode == 1) {
$tmpcrits = explode('|', $crit);
$i3 = 0; // count the nb of valid criteria added for this field
$i3 = 0; // count the nb of valid criteria added for this current field
foreach ($tmpcrits as $tmpcrit) {
if ($tmpcrit !== '0' && empty($tmpcrit)) {
continue;
@@ -9949,7 +9948,7 @@ function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
$i3++; // a criteria was added to string
}
}
$i2++;
$i2++; // a criteria for 1 more field was added to string
} elseif ($mode == 2 || $mode == -2) {
$crit = preg_replace('/[^0-9,]/', '', $crit); // ID are always integer
$newres .= ($i2 > 0 ? ' OR ' : '').$field." ".($mode == -2 ? 'NOT ' : '');
@@ -9957,7 +9956,7 @@ function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
if ($mode == -2) {
$newres .= ' OR '.$field.' IS NULL';
}
$i2++; // a criteria was added to string
$i2++; // a criteria for 1 more field was added to string
} elseif ($mode == 3 || $mode == -3) {
$tmparray = explode(',', $crit);
if (count($tmparray)) {
@@ -9970,7 +9969,7 @@ function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
}
}
$newres .= ($i2 > 0 ? ' OR ' : '').$field." ".($mode == -3 ? 'NOT ' : '')."IN (".$db->sanitize($listofcodes, 1).")";
$i2++; // a criteria was added to string
$i2++; // a criteria for 1 more field was added to string
}
if ($mode == -3) {
$newres .= ' OR '.$field.' IS NULL';
@@ -9987,20 +9986,20 @@ function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
$newres .= ' OR '.$field." LIKE '%,".$db->escape($val)."'";
$newres .= ' OR '.$field." LIKE '%,".$db->escape($val).",%'";
$newres .= ')';
$i2++;
$i2++; // a criteria for 1 more field was added to string (we can add several citeria for the same field as it is a multiselect search criteria)
}
}
}
} else { // $mode=0
$tmpcrits = explode('|', $crit);
$i3 = 0; // count the nb of valid criteria added for this field
foreach ($tmpcrits as $tmpcrit) {
$i3 = 0; // count the nb of valid criteria added for the current couple criteria/field
foreach ($tmpcrits as $tmpcrit) { // loop on each OR criteria
if ($tmpcrit !== '0' && empty($tmpcrit)) {
continue;
}
$tmpcrit = trim($tmpcrit);
if ($tmpcrit == '^$') { // If we search empty, we must combined different fields with AND
if ($tmpcrit == '^$' || strpos($crit, '!') === 0) { // If we search empty, we must combined different OR fields with AND
$newres .= (($i2 > 0 || $i3 > 0) ? ' AND ' : '');
} else {
$newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
@@ -10046,15 +10045,15 @@ function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
$i3++;
}
$i2++; // a criteria was added to string
$i2++; // a criteria for 1 more field was added to string
}
$i++;
}
if ($newres) {
$res = $res.($res ? ' AND ' : '').($i2 > 1 ? '(' : '').$newres.($i2 > 1 ? ')' : '');
}
$j++;
$i1++;
}
$res = ($nofirstand ? "" : " AND ")."(".$res.")";