From 2b910679660b57748c802e265eadbd9fa389e67e Mon Sep 17 00:00:00 2001 From: Vaadasch Date: Sat, 27 Oct 2018 19:31:50 +0200 Subject: [PATCH] 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 9ebdbd22836..2a11af3c616 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1334,7 +1334,55 @@ class ExtraFields 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