mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-05 17:18:13 +01:00
FIX Quick search sellist extrafield (#35070)
* FIX Quick search sellist extrafield * Update functions.lib.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
@@ -13096,6 +13096,22 @@ function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
|
||||
$newres .= (($i2 > 0 || $i3 > 0) ? ' OR ' : '');
|
||||
}
|
||||
|
||||
$isSellist = false;
|
||||
$table = $label = $key = null;
|
||||
|
||||
if (strpos($field, 'ef.') === 0) {
|
||||
$extrafieldName = substr($field, 3);
|
||||
$extrafields = new ExtraFields($db);
|
||||
$extrafields->fetch_name_optionals_label('product');
|
||||
|
||||
if (isset($extrafields->attributes['product']['type'][$extrafieldName]) && $extrafields->attributes['product']['type'][$extrafieldName] === 'sellist') {
|
||||
$isSellist = true;
|
||||
$paramArray = $extrafields->attributes['product']['param'][$extrafieldName]['options'] ?? [];
|
||||
$param = array_key_first($paramArray);
|
||||
list($table, $label, $key) = explode(':', $param);
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match('/\.(id|rowid)$/', $field)) { // Special case for rowid that is sometimes a ref so used as a search field
|
||||
$newres .= $db->sanitize($field) . " = " . (is_numeric($tmpcrit) ? ((float) $tmpcrit) : '0');
|
||||
} else {
|
||||
@@ -13104,33 +13120,37 @@ function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
|
||||
$tmpafter = '%';
|
||||
$tmps = '';
|
||||
|
||||
if (preg_match('/^!/', $tmpcrit)) {
|
||||
$tmps .= $db->sanitize($field) . " NOT LIKE "; // ! as exclude character
|
||||
$tmpcrit2 = preg_replace('/^!/', '', $tmpcrit2);
|
||||
if ($isSellist) {
|
||||
$newres .= $field." IN (SELECT t.".$key." FROM ".$db->prefix().$table." AS t WHERE t.".$label." LIKE '%".$db->escape($tmpcrit2)."%')";
|
||||
} else {
|
||||
$tmps .= $db->sanitize($field) . " LIKE ";
|
||||
}
|
||||
$tmps .= "'";
|
||||
if (preg_match('/^!/', $tmpcrit)) {
|
||||
$tmps .= $db->sanitize($field) . " NOT LIKE "; // ! as exclude character
|
||||
$tmpcrit2 = preg_replace('/^!/', '', $tmpcrit2);
|
||||
} else {
|
||||
$tmps .= $db->sanitize($field) . " LIKE ";
|
||||
}
|
||||
$tmps .= "'";
|
||||
|
||||
if (preg_match('/^[\^\$]/', $tmpcrit)) {
|
||||
$tmpbefore = '';
|
||||
$tmpcrit2 = preg_replace('/^[\^\$]/', '', $tmpcrit2);
|
||||
}
|
||||
if (preg_match('/[\^\$]$/', $tmpcrit)) {
|
||||
$tmpafter = '';
|
||||
$tmpcrit2 = preg_replace('/[\^\$]$/', '', $tmpcrit2);
|
||||
}
|
||||
if (preg_match('/^[\^\$]/', $tmpcrit)) {
|
||||
$tmpbefore = '';
|
||||
$tmpcrit2 = preg_replace('/^[\^\$]/', '', $tmpcrit2);
|
||||
}
|
||||
if (preg_match('/[\^\$]$/', $tmpcrit)) {
|
||||
$tmpafter = '';
|
||||
$tmpcrit2 = preg_replace('/[\^\$]$/', '', $tmpcrit2);
|
||||
}
|
||||
|
||||
if ($tmpcrit2 == '' || preg_match('/^!/', $tmpcrit)) {
|
||||
$tmps = "(" . $tmps;
|
||||
}
|
||||
$newres .= $tmps;
|
||||
$newres .= $tmpbefore;
|
||||
$newres .= $db->escape($tmpcrit2);
|
||||
$newres .= $tmpafter;
|
||||
$newres .= "'";
|
||||
if ($tmpcrit2 == '' || preg_match('/^!/', $tmpcrit)) {
|
||||
$newres .= " OR " . $field . " IS NULL)";
|
||||
if ($tmpcrit2 == '' || preg_match('/^!/', $tmpcrit)) {
|
||||
$tmps = "(" . $tmps;
|
||||
}
|
||||
$newres .= $tmps;
|
||||
$newres .= $tmpbefore;
|
||||
$newres .= $db->escape($tmpcrit2);
|
||||
$newres .= $tmpafter;
|
||||
$newres .= "'";
|
||||
if ($tmpcrit2 == '' || preg_match('/^!/', $tmpcrit)) {
|
||||
$newres .= " OR " . $field . " IS NULL)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user