diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 99ad792c217..cb910ef7ae5 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -277,12 +277,14 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL) if (empty($method) || $method == 3 || $method == 4) { + $relativepathstring = $_SERVER["PHP_SELF"]; // Clean $relativepathstring if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring); $relativepathstring = preg_replace('/^\//', '', $relativepathstring); $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring); - //var_dump($relativepathstring); + //var_dump($relativepathstring); + //var_dump($user->default_values); // Code for search criteria persistence. // Retrieve values if restore_lastsearch_values is set and there is saved values @@ -319,46 +321,85 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL) if (! empty($user->default_values)) // $user->default_values defined from menu default values { //var_dump($user->default_values[$relativepathstring]); - if ($paramname == 'sortfield') + if ($paramname == 'sortfield') // Sorted on which fields ? { - if (isset($user->default_values[$relativepathstring]['sortorder'])) // We will use the key of $user->default_values[path][sortorder] - { - $forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","="); // we accept _, -, . and , - foreach($user->default_values[$relativepathstring]['sortorder'] as $key => $val) - { - if ($out) $out.=', '; - $out.=dol_string_nospecial($key, '', $forbidden_chars_to_replace); - } - } + $qualified=1; + if (isset($user->default_values[$relativepathstring]['sortorder_queries'])) // Even if paramname is sortfield, data are stored into ['sortorder...'] + { + $tmpqueryarraytohave=explode('&', $user->default_values[$relativepathstring]['sortorder_queries']); + $tmpqueryarraywehave=explode('&', $_SERVER['QUERY_STRING']); + foreach($tmpqueryarraytohave as $tmpquerytohave) + { + if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) $qualified=0; + } + } + if ($qualified) + { + if (isset($user->default_values[$relativepathstring]['sortorder'])) // We will use the key of $user->default_values[path][sortorder] + { + $forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","="); // we accept _, -, . and , + foreach($user->default_values[$relativepathstring]['sortorder'] as $key => $val) + { + if ($out) $out.=', '; + $out.=dol_string_nospecial($key, '', $forbidden_chars_to_replace); + } + } + } } - elseif ($paramname == 'sortorder') + elseif ($paramname == 'sortorder') // ASC or DESC ? { - if (isset($user->default_values[$relativepathstring]['sortorder'])) // We will use the val of $user->default_values[path][sortorder] - { - $forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","="); // we accept _, -, . and , - foreach($user->default_values[$relativepathstring]['sortorder'] as $key => $val) - { - if ($out) $out.=', '; - $out.=dol_string_nospecial($val, '', $forbidden_chars_to_replace); - } - } + $qualified=1; + if (isset($user->default_values[$relativepathstring]['sortorder_queries'])) + { + $tmpqueryarraytohave=explode('&', $user->default_values[$relativepathstring]['sortorder_queries']); + $tmpqueryarraywehave=explode('&', $_SERVER['QUERY_STRING']); + foreach($tmpqueryarraytohave as $tmpquerytohave) + { + if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) $qualified=0; + } + } + if ($qualified) + { + if (isset($user->default_values[$relativepathstring]['sortorder'])) // We will use the val of $user->default_values[path][sortorder] + { + $forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","="); // we accept _, -, . and , + foreach($user->default_values[$relativepathstring]['sortorder'] as $key => $val) + { + if ($out) $out.=', '; + $out.=dol_string_nospecial($val, '', $forbidden_chars_to_replace); + } + } + } } elseif (isset($user->default_values[$relativepathstring]['filters'][$paramname])) { - if (isset($_POST['sall']) || isset($_POST['search_all']) || isset($_GET['sall']) || isset($_GET['search_all'])) + $qualified=1; + if (isset($user->default_values[$relativepathstring]['filters_queries'])) { - // We made a search from quick search menu, do we still use default filter ? - if (empty($conf->global->MAIN_DISABLE_DEFAULT_FILTER_FOR_QUICK_SEARCH)) + $tmpqueryarraytohave=explode('&', $user->default_values[$relativepathstring]['filters_queries']); + $tmpqueryarraywehave=explode('&', $_SERVER['QUERY_STRING']); + foreach($tmpqueryarraytohave as $tmpquerytohave) { - $forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","="); // we accept _, -, . and , - $out = dol_string_nospecial($user->default_values[$relativepathstring]['filters'][$paramname], '', $forbidden_chars_to_replace); + if (! in_array($tmpquerytohave, $tmpqueryarraywehave)) $qualified=0; } } - else - { - $forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","="); // we accept _, -, . and , - $out = dol_string_nospecial($user->default_values[$relativepathstring]['filters'][$paramname], '', $forbidden_chars_to_replace); - } + if ($qualified) + { + if (isset($_POST['sall']) || isset($_POST['search_all']) || isset($_GET['sall']) || isset($_GET['search_all'])) + { + // We made a search from quick search menu, do we still use default filter ? + if (empty($conf->global->MAIN_DISABLE_DEFAULT_FILTER_FOR_QUICK_SEARCH)) + { + $forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","="); // we accept _, -, . and , + $out = dol_string_nospecial($user->default_values[$relativepathstring]['filters'][$paramname], '', $forbidden_chars_to_replace); + } + } + else + { + $forbidden_chars_to_replace=array(" ","'","/","\\",":","*","?","\"","<",">","|","[","]",";","="); // we accept _, -, . and , + $out = dol_string_nospecial($user->default_values[$relativepathstring]['filters'][$paramname], '', $forbidden_chars_to_replace); + } + } } } } diff --git a/htdocs/product/canvas/service/actions_card_service.class.php b/htdocs/product/canvas/service/actions_card_service.class.php index f053e6f8d0b..355ecad14c2 100644 --- a/htdocs/product/canvas/service/actions_card_service.class.php +++ b/htdocs/product/canvas/service/actions_card_service.class.php @@ -298,7 +298,7 @@ class ActionsCardService function LoadListDatas($limit, $offset, $sortfield, $sortorder) { global $conf; - global $search_categ,$sall,$sref,$sbarcode,$snom,$catid; + global $search_categ,$sall,$sref,$search_barcode,$snom,$catid; $this->getFieldList(); @@ -320,7 +320,7 @@ class ActionsCardService $sql.= " AND (p.ref LIKE '%".$this->db->escape($sall)."%' OR p.label LIKE '%".$this->db->escape($sall)."%' OR p.description LIKE '%".$this->db->escape($sall)."%' OR p.note LIKE '%".$this->db->escape($sall)."%')"; } if ($sref) $sql.= " AND p.ref LIKE '%".$sref."%'"; - if ($sbarcode) $sql.= " AND p.barcode LIKE '%".$sbarcode."%'"; + if ($search_barcode) $sql.= " AND p.barcode LIKE '%".$search_barcode."%'"; if ($snom) $sql.= " AND p.label LIKE '%".$this->db->escape($snom)."%'"; if (isset($_GET["tosell"]) && dol_strlen($_GET["tosell"]) > 0) { diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 26e2cb84afb..1191000059e 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -52,9 +52,9 @@ $confirm=GETPOST('confirm','alpha'); $toselect = GETPOST('toselect', 'array'); $sall=GETPOST('sall', 'alphanohtml'); -$sref=GETPOST("sref"); -$sbarcode=GETPOST("sbarcode"); -$snom=GETPOST("snom"); +$search_ref=GETPOST("search_ref"); +$search_barcode=GETPOST("search_barcode"); +$search_label=GETPOST("search_label"); $search_type = GETPOST("search_type",'int'); $search_sale = GETPOST("search_sale"); $search_categ = GETPOST("search_categ",'int'); @@ -209,9 +209,9 @@ if (empty($reshook)) if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers { $sall=""; - $sref=""; - $snom=""; - $sbarcode=""; + $search_ref=""; + $search_label=""; + $search_barcode=""; $search_categ=0; $tosell=""; $tobuy=""; @@ -298,9 +298,9 @@ else if ($search_type == 1) $sql.= " AND p.fk_product_type = 1"; else $sql.= " AND p.fk_product_type <> 1"; } - if ($sref) $sql .= natural_search('p.ref', $sref); - if ($snom) $sql .= natural_search('p.label', $snom); - if ($sbarcode) $sql .= natural_search('p.barcode', $sbarcode); + if ($search_ref) $sql .= natural_search('p.ref', $search_ref); + if ($search_label) $sql .= natural_search('p.label', $search_label); + if ($search_barcode) $sql .= natural_search('p.barcode', $search_barcode); if (isset($tosell) && dol_strlen($tosell) > 0 && $tosell!=-1) $sql.= " AND p.tosell = ".$db->escape($tosell); if (isset($tobuy) && dol_strlen($tobuy) > 0 && $tobuy!=-1) $sql.= " AND p.tobuy = ".$db->escape($tobuy); if (dol_strlen($canvas) > 0) $sql.= " AND p.canvas = '".$db->escape($canvas)."'"; @@ -396,22 +396,22 @@ else $param=''; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage); if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); - if ($search_categ > 0) $param.="&search_categ=".urlencode($search_categ); - if ($sref) $param="&sref=".urlencode($sref); - if ($search_ref_supplier) $param="&search_ref_supplier=".urlencode($search_ref_supplier); - if ($sbarcode) $param.=($sbarcode?"&sbarcode=".urlencode($sbarcode):""); - if ($snom) $param.="&snom=".urlencode($snom); - if ($sall) $param.="&sall=".urlencode($sall); - if ($tosell != '') $param.="&tosell=".urlencode($tosell); - if ($tobuy != '') $param.="&tobuy=".urlencode($tobuy); - if ($fourn_id > 0) $param.=($fourn_id?"&fourn_id=".$fourn_id:""); - if ($seach_categ) $param.=($search_categ?"&search_categ=".urlencode($search_categ):""); - if ($type != '') $param.='&type='.urlencode($type); - if ($search_type != '') $param.='&search_type='.urlencode($search_type); + if ($sall) $param.="&sall=".urlencode($sall); + if ($search_categ > 0) $param.="&search_categ=".urlencode($search_categ); + if ($search_ref) $param="&search_ref=".urlencode($search_ref); + if ($search_ref_supplier) $param="&search_ref_supplier=".urlencode($search_ref_supplier); + if ($search_barcode) $param.=($search_barcode?"&search_barcode=".urlencode($search_barcode):""); + if ($search_label) $param.="&search_label=".urlencode($search_label); + if ($tosell != '') $param.="&tosell=".urlencode($tosell); + if ($tobuy != '') $param.="&tobuy=".urlencode($tobuy); + if ($fourn_id > 0) $param.=($fourn_id?"&fourn_id=".$fourn_id:""); + if ($seach_categ) $param.=($search_categ?"&search_categ=".urlencode($search_categ):""); + if ($type != '') $param.='&type='.urlencode($type); + if ($search_type != '') $param.='&search_type='.urlencode($search_type); if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); - if ($search_tobatch) $param="&search_ref_supplier=".urlencode($search_ref_supplier); - if ($search_accountancy_code_sell) $param="&search_accountancy_code_sell=".urlencode($search_accountancy_code_sell); - if ($search_accountancy_code_buy) $param="&search_accountancy_code_buy=".urlencode($search_accountancy_code_buy); + if ($search_tobatch) $param="&search_ref_supplier=".urlencode($search_ref_supplier); + if ($search_accountancy_code_sell) $param="&search_accountancy_code_sell=".urlencode($search_accountancy_code_sell); + if ($search_accountancy_code_buy) $param="&search_accountancy_code_buy=".urlencode($search_accountancy_code_buy); // Add $param from extra fields foreach ($search_array_options as $key => $val) { @@ -517,7 +517,7 @@ else if (! empty($arrayfields['p.ref']['checked'])) { print '