mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-17 23:11:29 +01:00
Debug custom report filter management
This commit is contained in:
@@ -12517,9 +12517,10 @@ function jsonOrUnserialize($stringtodecode)
|
||||
/**
|
||||
* forgeSQLFromUniversalSearchCriteria
|
||||
*
|
||||
* @param string $filter String with universal search string. Must be '(aaa:bbb:...) OR (ccc:ddd:...) ...' with
|
||||
* @param string $filter String with universal search string. Must be '(aaa:bbb:ccc) OR (ddd:eeee:fff) ...' with
|
||||
* aaa is a field name (with alias or not) and
|
||||
* bbb is one of this operator '=', '<', '>', '<=', '>=', '!=', 'in', 'notin', 'like', 'notlike', 'is', 'isnot'.
|
||||
* ccc must not contains ( or )
|
||||
* Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')'
|
||||
* @param string $errorstr Error message string
|
||||
* @param int $noand 1=Do not add the AND before the condition string.
|
||||
@@ -12535,8 +12536,9 @@ function forgeSQLFromUniversalSearchCriteria($filter, &$errorstr = '', $noand =
|
||||
}
|
||||
|
||||
$regexstring = '\(([a-zA-Z0-9_\.]+:[<>!=insotlke]+:[^\(\)]+)\)'; // Must be (aaa:bbb:...) with aaa is a field name (with alias or not) and bbb is one of this operator '=', '<', '>', '<=', '>=', '!=', 'in', 'notin', 'like', 'notlike', 'is', 'isnot'
|
||||
$firstandlastparenthesis = 0;
|
||||
|
||||
if (!dolCheckFilters($filter, $errorstr)) {
|
||||
if (!dolCheckFilters($filter, $errorstr, $firstandlastparenthesis)) {
|
||||
if ($noerror) {
|
||||
return '1 = 2';
|
||||
} else {
|
||||
@@ -12560,35 +12562,118 @@ function forgeSQLFromUniversalSearchCriteria($filter, &$errorstr = '', $noand =
|
||||
return ($noand ? "" : " AND ").($nopar ? "" : '(').preg_replace_callback('/'.$regexstring.'/i', 'dolForgeCriteriaCallback', $filter).($nopar ? "" : ')');
|
||||
}
|
||||
|
||||
/**
|
||||
* Explode an universal search string with AND parts
|
||||
*
|
||||
* @param string $sqlfilters Universal SQL filter string. Must have been trimmed before.
|
||||
* @return array Array of AND
|
||||
*/
|
||||
function dolForgeExplodeAnd($sqlfilters)
|
||||
{
|
||||
$arrayofandtags = array();
|
||||
$nbofchars = dol_strlen($sqlfilters);
|
||||
|
||||
$i = 0;
|
||||
$s = '';
|
||||
$countparenthesis = 0;
|
||||
while ($i < $nbofchars) {
|
||||
$char = dol_substr($sqlfilters, $i, 1);
|
||||
|
||||
if ($char == '(') {
|
||||
$countparenthesis++;
|
||||
} elseif ($char == ')') {
|
||||
$countparenthesis--;
|
||||
}
|
||||
|
||||
if ($countparenthesis == 0) {
|
||||
$char2 = dol_substr($sqlfilters, $i+1, 1);
|
||||
$char3 = dol_substr($sqlfilters, $i+2, 1);
|
||||
if ($char == 'A' && $char2 == 'N' && $char3 == 'D') {
|
||||
// We found a AND
|
||||
$s = trim($s);
|
||||
if (!preg_match('/^\(.*\)$/', $s)) {
|
||||
$s = '('.$s.')';
|
||||
}
|
||||
$arrayofandtags[] = $s;
|
||||
$s = '';
|
||||
$i+=2;
|
||||
} else {
|
||||
$s .= $char;
|
||||
}
|
||||
} else {
|
||||
$s .= $char;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
if ($s) {
|
||||
$s = trim($s);
|
||||
if (!preg_match('/^\(.*\)$/', $s)) {
|
||||
$s = '('.$s.')';
|
||||
}
|
||||
$arrayofandtags[] = $s;
|
||||
}
|
||||
|
||||
return $arrayofandtags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if a $sqlfilters parameter has a valid balance of parenthesis
|
||||
*
|
||||
* @param string $sqlfilters sqlfilter string
|
||||
* @param string $error Error message
|
||||
* @return boolean True if valid, False if not valid ($error is filled with the reason in such a case)
|
||||
* @param string $sqlfilters Universal SQL filter string. Must have been trimmed before.
|
||||
* @param string $error Returned error message
|
||||
* @param int $parenthesislevel Returned level of global parenthesis that we can remove/siplify, 0 if error or we cant simplify.
|
||||
* @return boolean True if valid, False if not valid ($error returned parameter is filled with the reason in such a case)
|
||||
*/
|
||||
function dolCheckFilters($sqlfilters, &$error = '')
|
||||
function dolCheckFilters($sqlfilters, &$error = '', &$parenthesislevel = 0)
|
||||
{
|
||||
//$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
|
||||
//$tmp=preg_replace_all('/'.$regexstring.'/', '', $sqlfilters);
|
||||
$tmp = $sqlfilters;
|
||||
$i = 0;
|
||||
$nb = strlen($tmp);
|
||||
|
||||
$nb = dol_strlen($tmp);
|
||||
$counter = 0;
|
||||
$parenthesislevel = 0;
|
||||
|
||||
$error = '';
|
||||
|
||||
$i = 0;
|
||||
while ($i < $nb) {
|
||||
if ($tmp[$i] == '(') {
|
||||
$char = dol_substr($tmp, $i, 1);
|
||||
|
||||
if ($char == '(') {
|
||||
if ($i == $parenthesislevel && $parenthesislevel == $counter) {
|
||||
// We open a parenthesis and it is the first char
|
||||
$parenthesislevel++;
|
||||
}
|
||||
$counter++;
|
||||
}
|
||||
if ($tmp[$i] == ')') {
|
||||
} elseif ($char == ')') {
|
||||
$nbcharremaining = ($nb - $i - 1);
|
||||
if ($nbcharremaining >= $counter) {
|
||||
$parenthesislevel = min($parenthesislevel, $counter - 1);
|
||||
}
|
||||
if ($parenthesislevel > $counter && $nbcharremaining >= $counter) {
|
||||
$parenthesislevel = $counter;
|
||||
}
|
||||
$counter--;
|
||||
}
|
||||
|
||||
if ($counter < 0) {
|
||||
$error = "Wrond balance of parenthesis in sqlfilters=".$sqlfilters;
|
||||
$error = "Wrong balance of parenthesis in sqlfilters=".$sqlfilters;
|
||||
$parenthesislevel = 0;
|
||||
dol_syslog($error, LOG_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($counter > 0) {
|
||||
$error = "Wrong balance of parenthesis in sqlfilters=".$sqlfilters;
|
||||
$parenthesislevel = 0;
|
||||
dol_syslog($error, LOG_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -12703,7 +12788,7 @@ function dolForgeCriteriaCallback($matches)
|
||||
*/
|
||||
function getTimelineIcon($actionstatic, &$histo, $key)
|
||||
{
|
||||
global $conf, $langs;
|
||||
global $langs;
|
||||
|
||||
$out = '<!-- timeline icon -->'."\n";
|
||||
$iconClass = 'fa fa-comments';
|
||||
|
||||
Reference in New Issue
Block a user