|
@@ -10431,16 +10431,20 @@ class Form
|
|
|
/**
|
|
|
* Output the component to make advanced search criteries
|
|
|
*
|
|
|
- * @param array $arrayofcriterias Array of available search criterias. Example: array($object->element => $object->fields, 'otherfamily' => otherarrayoffields, ...)
|
|
|
- * @param array $search_component_params Array of selected search criterias
|
|
|
- * @param array $arrayofinputfieldsalreadyoutput Array of input fields already inform. The component will not generate a hidden input field if it is in this list.
|
|
|
- * @param string $search_component_params_hidden String with $search_component_params criterias
|
|
|
- * @return string HTML component for advanced search
|
|
|
+ * @param array $arrayofcriterias Array of available search criterias. Example: array($object->element => $object->fields, 'otherfamily' => otherarrayoffields, ...)
|
|
|
+ * @param array $search_component_params Array of selected search criterias
|
|
|
+ * @param array $arrayofinputfieldsalreadyoutput Array of input fields already inform. The component will not generate a hidden input field if it is in this list.
|
|
|
+ * @param string $search_component_params_hidden String with $search_component_params criterias
|
|
|
+ * @return string HTML component for advanced search
|
|
|
*/
|
|
|
public function searchComponent($arrayofcriterias, $search_component_params, $arrayofinputfieldsalreadyoutput = array(), $search_component_params_hidden = '')
|
|
|
{
|
|
|
global $langs;
|
|
|
|
|
|
+ if (!preg_match('/^\(.*\)$/', $search_component_params_hidden)) { // If $search_component_params_hidden does not start and end with ()
|
|
|
+ $search_component_params_hidden = '(' . $search_component_params_hidden . ')';
|
|
|
+ }
|
|
|
+
|
|
|
$ret = '';
|
|
|
|
|
|
$ret .= '<div class="divadvancedsearchfieldcomp inline-block">';
|
|
@@ -10456,13 +10460,54 @@ class Form
|
|
|
$ret .= '<div name="divsearch_component_params" class="noborderbottom search_component_params inline-block valignmiddle">';
|
|
|
|
|
|
if ($search_component_params_hidden) {
|
|
|
- $errormessage = '';
|
|
|
- $searchtags = forgeSQLFromUniversalSearchCriteria($search_component_params_hidden, $errormessage);
|
|
|
- if ($errormessage) {
|
|
|
- $this->error = 'ERROR in parsing search string: '.$errormessage;
|
|
|
+ // Split the criteria on each AND
|
|
|
+ //var_dump($search_component_params_hidden);
|
|
|
+
|
|
|
+ $nbofchars = dol_strlen($search_component_params_hidden);
|
|
|
+ $arrayofandtags = array();
|
|
|
+ $i = 0; $s = '';
|
|
|
+ $countparenthesis = 0;
|
|
|
+ while ($i < $nbofchars) {
|
|
|
+ if ($search_component_params_hidden[$i] == '(') {
|
|
|
+ $countparenthesis++;
|
|
|
+ } elseif ($search_component_params_hidden[$i] == ')') {
|
|
|
+ $countparenthesis--;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($countparenthesis == 0) {
|
|
|
+ if (!empty($search_component_params_hidden[$i]) && !empty($search_component_params_hidden[$i+1]) && !empty($search_component_params_hidden[$i+2])
|
|
|
+ && $search_component_params_hidden[$i] == 'A' && $search_component_params_hidden[$i+1] == 'N' && $search_component_params_hidden[$i+2] == 'D') {
|
|
|
+ // We found a AND
|
|
|
+ $arrayofandtags[] = trim($s);
|
|
|
+ $s = '';
|
|
|
+ $i+=2;
|
|
|
+ } else {
|
|
|
+ $s .= $search_component_params_hidden[$i];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $s .= $search_component_params_hidden[$i];
|
|
|
+ }
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+ if ($s) {
|
|
|
+ $arrayofandtags[] = trim($s);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Show each AND part
|
|
|
+ foreach ($arrayofandtags as $tmpkey => $tmpval) {
|
|
|
+ $errormessage = '';
|
|
|
+ $searchtags = forgeSQLFromUniversalSearchCriteria($tmpval, $errormessage, 1, 1);
|
|
|
+ if ($errormessage) {
|
|
|
+ $this->error = 'ERROR in parsing search string: '.$errormessage;
|
|
|
+ }
|
|
|
+ $searchtags = preg_replace('/^\(/', '', $searchtags);
|
|
|
+ $searchtags = preg_replace('/\)$/', '', $searchtags);
|
|
|
+
|
|
|
+ $ret .= '<span class="marginleftonlyshort valignmiddle tagsearch" data-ufilterid="'.($tmpkey+1).'" data-ufilter="'.dol_escape_htmltag($tmpval).'">';
|
|
|
+ $ret .= '<span class="tagsearchdelete select2-selection__choice__remove" data-ufilterid="'.($tmpkey+1).'">x</span> ';
|
|
|
+ $ret .= dol_escape_htmltag($searchtags);
|
|
|
+ $ret .= '</span>';
|
|
|
}
|
|
|
- //var_dump($searchtags);
|
|
|
- $ret .= '<span class="marginleftonlyshort valignmiddle tagsearch"><span class="tagsearchdelete select2-selection__choice__remove">x</span> ' . dol_escape_htmltag($searchtags) . '</span>';
|
|
|
}
|
|
|
|
|
|
//$ret .= '<button type="submit" class="liste_titre button_search paddingleftonly" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
|
|
@@ -10475,9 +10520,11 @@ class Form
|
|
|
if ($show_search_component_params_hidden) {
|
|
|
$ret .= '<input type="hidden" name="show_search_component_params_hidden" value="1">';
|
|
|
}
|
|
|
- $ret .= "<!-- We store the full search string into this field. For example: (t.ref:like:'SO-%') and ((t.ref:like:'CO-%') or (t.ref:like:'AA%')) -->";
|
|
|
+ $ret .= "<!-- We store the full Universal Search String into this field. For example: (t.ref:like:'SO-%') AND ((t.ref:like:'CO-%') OR (t.ref:like:'AA%')) -->";
|
|
|
$ret .= '<input type="hidden" name="search_component_params_hidden" value="' . dol_escape_htmltag($search_component_params_hidden) . '">';
|
|
|
- // For compatibility with forms that show themself the search criteria in addition of this component, we output the fields
|
|
|
+ // $ret .= "<!-- sql= ".forgeSQLFromUniversalSearchCriteria($search_component_params_hidden, $errormessage)." -->";
|
|
|
+
|
|
|
+ // For compatibility with forms that show themself the search criteria in addition of this component, we output these fields
|
|
|
foreach ($arrayofcriterias as $criterias) {
|
|
|
foreach ($criterias as $criteriafamilykey => $criteriafamilyval) {
|
|
|
if (in_array('search_' . $criteriafamilykey, $arrayofinputfieldsalreadyoutput)) {
|
|
@@ -10503,12 +10550,23 @@ class Form
|
|
|
|
|
|
$ret .= '</div>';
|
|
|
|
|
|
- $ret .= "<!-- Syntax of Generic filter string: t.ref:like:'SO-%', t.date_creation:<:'20160101', t.date_creation:<:'2016-01-01 12:30:00', t.nature:is:NULL, t.field2:isnot:NULL -->\n";
|
|
|
+ $ret .= "<!-- Field to enter a generic filter string: t.ref:like:'SO-%', t.date_creation:<:'20160101', t.date_creation:<:'2016-01-01 12:30:00', t.nature:is:NULL, t.field2:isnot:NULL -->\n";
|
|
|
$ret .= '<input type="text" placeholder="' . $langs->trans("Search") . '" name="search_component_params_input" class="noborderbottom search_component_input" value="">';
|
|
|
|
|
|
$ret .= '</div>';
|
|
|
$ret .= '</div>';
|
|
|
|
|
|
+ $ret .= '<script>
|
|
|
+ jQuery(".tagsearchdelete").click(function() {
|
|
|
+ var filterid = $(this).parents().data("ufilterid");
|
|
|
+ console.log("We click to delete a criteria nb "+filterid);
|
|
|
+ // TODO Update the search_component_params_hidden with all data-ufilter except the one delete and post page
|
|
|
+
|
|
|
+ });
|
|
|
+ </script>
|
|
|
+ ';
|
|
|
+
|
|
|
+
|
|
|
return $ret;
|
|
|
}
|
|
|
|