From 2b910679660b57748c802e265eadbd9fa389e67e Mon Sep 17 00:00:00 2001 From: Vaadasch Date: Sat, 27 Oct 2018 19:31:50 +0200 Subject: [PATCH 1/3] Update working chkbxlst filter Update line 1337 to make the filtering on chkbxlst working --- htdocs/core/class/extrafields.class.php | 50 ++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 9ebdbd2283601..2a11af3c61674 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1334,7 +1334,55 @@ function showInputField($key, $value, $moreparam='', $keysuffix='', $keyprefix=' if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); } else { - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); + // Pattern for word=$ID$ + $word = '\b[a-zA-Z0-9-\.-_]+\b=\$ID\$'; + + // Removing space arount =, ( and ) + $InfoFieldList[4]=preg_replace('# *(=|\(|\)) *#','$1', $InfoFieldList[4]); + + $nbPreg = 1; + // While we have parenthesis + while ($nbPreg!=0) { + // Init des compteurs + $nbPregRepl = $nbPregSel = 0; + // On retire toutes les parenthèses sans = avant + $InfoFieldList[4]=preg_replace( '#([^=])(\([^)^(]*(' . $word . ')[^)^(]*\))#','$1 $3 ',$InfoFieldList[4],-1,$nbPregRepl); + // On retire les espaces autour des = et parenthèses + $InfoFieldList[4]=preg_replace('# *(=|\(|\)) *#','$1', $InfoFieldList[4]); + // On retire toutes les parenthèses avec = avant + $InfoFieldList[4]=preg_replace( '#\b[a-zA-Z0-9-\.-_]+\b=\([^)^(]*(' . $word . ')[^)^(]*\)#','$1 ',$InfoFieldList[4], -1, $nbPregSel); + // On retire les espaces autour des = et parenthèses + $InfoFieldList[4]=preg_replace('# *(=|\(|\)) *#','$1', $InfoFieldList[4]); + + // Calcul du compteur général pour la boucle + $nbPreg = $nbPregRepl + $nbPregSel; + } + + // Si l'on a un AND ou un OR, avant ou après + preg_match( '#(AND|OR|) *(' . $word . ') *(AND|OR|)#' ,$InfoFieldList[4],$matchCondition); + while(!empty($matchCondition[0])) { + // If the two sides differ but are not empty + if (! empty($matchCondition[1]) && ! empty($matchCondition[3]) && $matchCondition[1] != $matchCondition[3] ) { + // Nobody sain would do that without parentheses + $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); + } + else { + if (! empty($matchCondition[1])) { + $boolCond =(( $matchCondition[1] == "AND" )?' AND 1 ':' OR 0 '); + $InfoFieldList[4]=str_replace($matchCondition[0],$boolCond.$matchCondition[3] ,$InfoFieldList[4]); + } + else if (! empty($matchCondition[3])) { + $boolCond =(( $matchCondition[3] == "AND" )?' 1 AND ':' 0 OR'); + $InfoFieldList[4]=str_replace($matchCondition[0],$boolCond,$InfoFieldList[4]); + } + else { + $InfoFieldList[4] = 1; + } + } + + // Si l'on a un AND ou un OR, avant ou après + preg_match( '#(AND|OR|) *(' . $word . ') *(AND|OR|)#' ,$InfoFieldList[4],$matchCondition); + } } // We have to join on extrafield table From a4c7787d8c23a97e0cec9e3bd59c197147dcdb86 Mon Sep 17 00:00:00 2001 From: Vaadasch Date: Mon, 29 Oct 2018 22:00:08 +0100 Subject: [PATCH 2/3] Update extrafields.class.php --- htdocs/core/class/extrafields.class.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 2a11af3c61674..a6af735fb3ee2 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1333,7 +1333,7 @@ function showInputField($key, $value, $moreparam='', $keysuffix='', $keyprefix=' // current object id can be use into filter if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); - } else { + } else if (preg_match("#^.*list.php$#",$_SERVER["DOCUMENT_URI"])) { // Pattern for word=$ID$ $word = '\b[a-zA-Z0-9-\.-_]+\b=\$ID\$'; @@ -1359,7 +1359,7 @@ function showInputField($key, $value, $moreparam='', $keysuffix='', $keyprefix=' } // Si l'on a un AND ou un OR, avant ou après - preg_match( '#(AND|OR|) *(' . $word . ') *(AND|OR|)#' ,$InfoFieldList[4],$matchCondition); + preg_match('#(AND|OR|) *('.$word.') *(AND|OR|)#',$InfoFieldList[4],$matchCondition); while(!empty($matchCondition[0])) { // If the two sides differ but are not empty if (! empty($matchCondition[1]) && ! empty($matchCondition[3]) && $matchCondition[1] != $matchCondition[3] ) { @@ -1369,7 +1369,7 @@ function showInputField($key, $value, $moreparam='', $keysuffix='', $keyprefix=' else { if (! empty($matchCondition[1])) { $boolCond =(( $matchCondition[1] == "AND" )?' AND 1 ':' OR 0 '); - $InfoFieldList[4]=str_replace($matchCondition[0],$boolCond.$matchCondition[3] ,$InfoFieldList[4]); + $InfoFieldList[4]=str_replace($matchCondition[0],$boolCond.$matchCondition[3],$InfoFieldList[4]); } else if (! empty($matchCondition[3])) { $boolCond =(( $matchCondition[3] == "AND" )?' 1 AND ':' 0 OR'); @@ -1381,9 +1381,12 @@ function showInputField($key, $value, $moreparam='', $keysuffix='', $keyprefix=' } // Si l'on a un AND ou un OR, avant ou après - preg_match( '#(AND|OR|) *(' . $word . ') *(AND|OR|)#' ,$InfoFieldList[4],$matchCondition); + preg_match('#(AND|OR|) *('.$word.') *(AND|OR|)#',$InfoFieldList[4],$matchCondition); } } + else { + $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); + } // We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra') !== false) { From 0d7dbace6388683650bf41dd51724ebc5bd56efb Mon Sep 17 00:00:00 2001 From: Vaadasch Date: Tue, 30 Oct 2018 07:20:42 +0100 Subject: [PATCH 3/3] Update extrafields.class.php --- htdocs/core/class/extrafields.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index a6af735fb3ee2..7bb2ff87487d5 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1384,7 +1384,7 @@ function showInputField($key, $value, $moreparam='', $keysuffix='', $keyprefix=' preg_match('#(AND|OR|) *('.$word.') *(AND|OR|)#',$InfoFieldList[4],$matchCondition); } } - else { + else { $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); }