diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 4240e5fbe60..04f202069dd 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -10731,7 +10731,7 @@ class Form $ret .= ''; } $ret .= ""; - $ret .= ''; + $ret .= ''; // $ret .= ""; // For compatibility with forms that show themself the search criteria in addition of this component, we output these fields @@ -10761,7 +10761,7 @@ class Form $ret .= ''; $ret .= "\n"; - $ret .= ''; + $ret .= ''; $ret .= ''; $ret .= ''; @@ -10774,7 +10774,6 @@ class Form // Regenerate the search_component_params_hidden with all data-ufilter except the one to delete, and post the page var newparamstring = \'\'; $(\'.tagsearch\').each(function(index, element) { - console.log(element); tmpfilterid = $(this).attr("data-ufilterid"); if (tmpfilterid != filterid) { // We keep this criteria @@ -10785,7 +10784,9 @@ class Form } } }); - console.log(newparamstring); + console.log("newparamstring = "+newparamstring); + + jQuery("#search_component_params_hidden").val(newparamstring); // We repost the form $(this).closest(\'form\').submit(); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 43da017f2db..534a8ad0c56 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -12573,6 +12573,16 @@ function dolForgeExplodeAnd($sqlfilters) $arrayofandtags = array(); $nbofchars = dol_strlen($sqlfilters); + $error = ''; + $parenthesislevel = 0; + $result = dolCheckFilters($sqlfilters, $error, $parenthesislevel); + if (!$result) { + return array(); + } + if ($parenthesislevel >= 1) { + $sqlfilters = preg_replace('/^\(/', '', preg_replace('/\)$/', '', $sqlfilters)); + } + $i = 0; $s = ''; $countparenthesis = 0; diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 204191e89b9..0c17a6a75a4 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -232,6 +232,48 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase $result = dolCheckFilters($sql, $error, $parenthesislevel); $this->assertEquals(0, $parenthesislevel); $this->assertFalse($result); + + return true; + } + + + /** + * testDolForgeExplodeAnd + * + * @return boolean + */ + public function testDolForgeExplodeAnd() + { + $tmp = dolForgeExplodeAnd(''); + $this->assertEquals(0, count($tmp)); + + $tmp = dolForgeExplodeAnd('(a:=:1)'); + $this->assertEquals('(a:=:1)', $tmp[0]); + + $tmp = dolForgeExplodeAnd('(a:=:1) AND (b:=:2)'); + $this->assertEquals('(a:=:1)', $tmp[0]); + $this->assertEquals('(b:=:2)', $tmp[1]); + + $tmp = dolForgeExplodeAnd('(a:=:1) AND ((b:=:2) OR (c:=:3))'); + $this->assertEquals('(a:=:1)', $tmp[0]); + $this->assertEquals('((b:=:2) OR (c:=:3))', $tmp[1]); + + $tmp = dolForgeExplodeAnd('(a:=:1) AND (b:=:2) OR (c:=:3)'); + $this->assertEquals('(a:=:1)', $tmp[0]); + $this->assertEquals('(b:=:2) OR (c:=:3)', $tmp[1]); + + $tmp = dolForgeExplodeAnd('(a:=:1) OR (b:=:2) AND (c:=:3)'); + $this->assertEquals('(a:=:1) OR (b:=:2)', $tmp[0]); + $this->assertEquals('(c:=:3)', $tmp[1]); + + $tmp = dolForgeExplodeAnd('(a:=:1) OR ((b:=:2) AND (c:=:3))'); + $this->assertEquals('(a:=:1) OR ((b:=:2) AND (c:=:3))', $tmp[0]); + + $tmp = dolForgeExplodeAnd('((y:=:1) AND (p:=:8))'); + $this->assertEquals('(y:=:1)', $tmp[0]); + $this->assertEquals('(p:=:8)', $tmp[1]); + + return true; } /**