Skip to content

Commit

Permalink
Merge pull request #9897 from Vaadasch/develop
Browse files Browse the repository at this point in the history
NEW Update working chkbxlst filter for lists
  • Loading branch information
eldy committed Dec 14, 2018
2 parents 233e160 + 0d7dbac commit 59e38d4
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion htdocs/core/class/extrafields.class.php
Expand Up @@ -1333,7 +1333,58 @@ 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\$';

// 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);
}
}
else {
$InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
}

Expand Down

0 comments on commit 59e38d4

Please sign in to comment.