NEW Default filter and sort order can use partial list of query

parameters to set the qualified URLs.
This commit is contained in:
Laurent Destailleur 2017-09-11 00:02:52 +02:00
parent 903df90f8a
commit cf56da8102
7 changed files with 122 additions and 72 deletions

View File

@ -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);
}
}
}
}
}

View File

@ -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)
{

View File

@ -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.="&amp;search_categ=".urlencode($search_categ);
if ($sref) $param="&amp;sref=".urlencode($sref);
if ($search_ref_supplier) $param="&amp;search_ref_supplier=".urlencode($search_ref_supplier);
if ($sbarcode) $param.=($sbarcode?"&amp;sbarcode=".urlencode($sbarcode):"");
if ($snom) $param.="&amp;snom=".urlencode($snom);
if ($sall) $param.="&amp;sall=".urlencode($sall);
if ($tosell != '') $param.="&amp;tosell=".urlencode($tosell);
if ($tobuy != '') $param.="&amp;tobuy=".urlencode($tobuy);
if ($fourn_id > 0) $param.=($fourn_id?"&amp;fourn_id=".$fourn_id:"");
if ($seach_categ) $param.=($search_categ?"&amp;search_categ=".urlencode($search_categ):"");
if ($type != '') $param.='&amp;type='.urlencode($type);
if ($search_type != '') $param.='&amp;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="&amp;search_ref_supplier=".urlencode($search_ref_supplier);
if ($search_accountancy_code_sell) $param="&amp;search_accountancy_code_sell=".urlencode($search_accountancy_code_sell);
if ($search_accountancy_code_buy) $param="&amp;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 '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" name="sref" size="8" value="'.dol_escape_htmltag($sref).'">';
print '<input class="flat" type="text" name="search_ref" size="8" value="'.dol_escape_htmltag($search_ref).'">';
print '</td>';
}
if (! empty($arrayfields['pfp.ref_fourn']['checked']))
@ -529,7 +529,7 @@ else
if (! empty($arrayfields['p.label']['checked']))
{
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" name="snom" size="12" value="'.dol_escape_htmltag($snom).'">';
print '<input class="flat" type="text" name="search_label" size="12" value="'.dol_escape_htmltag($search_label).'">';
print '</td>';
}
// Type
@ -544,7 +544,7 @@ else
if (! empty($arrayfields['p.barcode']['checked']))
{
print '<td class="liste_titre">';
print '<input class="flat" type="text" name="sbarcode" size="6" value="'.dol_escape_htmltag($sbarcode).'">';
print '<input class="flat" type="text" name="search_barcode" size="6" value="'.dol_escape_htmltag($search_barcode).'">';
print '</td>';
}
// Duration

View File

@ -44,7 +44,7 @@ $sref=GETPOST("sref");
$snom=GETPOST("snom");
$sall=GETPOST('sall', 'alphanohtml');
$type=GETPOST("type","int");
$sbarcode=GETPOST("sbarcode");
$search_barcode=GETPOST("search_barcode");
$catid=GETPOST('catid','int');
$toolowstock=GETPOST('toolowstock');
$tosell = GETPOST("tosell");
@ -135,7 +135,7 @@ if (dol_strlen($type))
}
}
if ($sref) $sql.= natural_search('p.ref', $ref);
if ($sbarcode) $sql.= natural_search('p.barcode', $sbarcode);
if ($search_barcode) $sql.= natural_search('p.barcode', $search_barcode);
if ($snom) $sql.= natural_search('p.label', $snom);
if (! empty($tosell)) $sql.= " AND p.tosell = ".$tosell;
if (! empty($tobuy)) $sql.= " AND p.tobuy = ".$tobuy;

View File

@ -46,7 +46,7 @@ $sref=GETPOST("sref");
$snom=GETPOST("snom");
$sall=GETPOST('sall', 'alphanohtml');
$type=GETPOST("type","int");
$sbarcode=GETPOST("sbarcode",'alpha');
$search_barcode=GETPOST("search_barcode",'alpha');
$search_warehouse=GETPOST('search_warehouse','alpha');
$search_batch=GETPOST('search_batch','alpha');
$catid=GETPOST('catid','int');
@ -140,7 +140,7 @@ if (dol_strlen($type))
}
}
if ($sref) $sql.= natural_search("p.ref", $sref);
if ($sbarcode) $sql.= natural_search("p.barcode", $sbarcode);
if ($search_barcode) $sql.= natural_search("p.barcode", $search_barcode);
if ($snom) $sql.= natural_search("p.label", $snom);
if (! empty($tosell)) $sql.= " AND p.tosell = ".$tosell;
if (! empty($tobuy)) $sql.= " AND p.tobuy = ".$tobuy;

View File

@ -56,7 +56,7 @@ $search_id=trim(GETPOST("search_id","int"));
$search_nom=trim(GETPOST("search_nom"));
$search_alias=trim(GETPOST("search_alias"));
$search_nom_only=trim(GETPOST("search_nom_only"));
$search_barcode=trim(GETPOST("sbarcode"));
$search_barcode=trim(GETPOST("search_barcode"));
$search_customer_code=trim(GETPOST('search_customer_code'));
$search_supplier_code=trim(GETPOST('search_supplier_code'));
$search_account_customer_code=trim(GETPOST('search_account_customer_code'));
@ -542,7 +542,7 @@ if ($search_customer_code != '') $param.= "&search_customer_code=".urlencode($se
if ($search_supplier_code != '') $param.= "&search_supplier_code=".urlencode($search_supplier_code);
if ($search_account_customer_code != '') $param.= "&search_account_customer_code=".urlencode($search_account_customer_code);
if ($search_account_supplier_code != '') $param.= "&search_account_supplier_code=".urlencode($search_account_supplier_code);
if ($search_barcode != '') $param.= "&sbarcode=".urlencode($search_barcode);
if ($search_barcode != '') $param.= "&search_barcode=".urlencode($search_barcode);
if ($search_idprof1 != '') $param.= '&search_idprof1='.urlencode($search_idprof1);
if ($search_idprof2 != '') $param.= '&search_idprof2='.urlencode($search_idprof2);
if ($search_idprof3 != '') $param.= '&search_idprof3='.urlencode($search_idprof3);
@ -689,7 +689,7 @@ if (! empty($arrayfields['s.name_alias']['checked']))
if (! empty($arrayfields['s.barcode']['checked']))
{
print '<td class="liste_titre">';
print '<input class="flat searchstring" type="text" name="sbarcode" size="6" value="'.dol_escape_htmltag($search_barcode).'">';
print '<input class="flat searchstring" type="text" name="search_barcode" size="6" value="'.dol_escape_htmltag($search_barcode).'">';
print '</td>';
}
// Customer code

View File

@ -239,7 +239,7 @@ class User extends CommonObject
$sql.= " AND u.rowid = ".$id;
}
$sql.= " ORDER BY u.entity ASC"; // Avoid random result when there is 2 login in 2 different entities
$result = $this->db->query($sql);
if ($result)
{
@ -312,7 +312,7 @@ class User extends CommonObject
$this->contactid = $obj->fk_socpeople;
$this->fk_member = $obj->fk_member;
$this->fk_user = $obj->fk_user;
$this->default_range = $obj->default_range;
$this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
@ -384,7 +384,16 @@ class User extends CommonObject
{
if (! empty($obj->page) && ! empty($obj->type) && ! empty($obj->param))
{
$this->default_values[$obj->page][$obj->type][$obj->param]=$obj->value;
// $obj->page is relative URL with or without params, $obj->type can be 'filters', 'sortorder', 'createform', ...
$pagewithoutquerystring=$obj->page;
$pagequeries='';
if (preg_match('/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) // There is query param
{
$pagewithoutquerystring=$reg[1];
$pagequeries=$reg[2];
}
$this->default_values[$pagewithoutquerystring][$obj->type][$obj->param]=$obj->value;
if ($pagequeries) $this->default_values[$pagewithoutquerystring][$obj->type.'_queries']=$pagequeries;
}
}
$this->db->free($resql);
@ -1343,7 +1352,7 @@ class User extends CommonObject
$this->accountancy_code = trim($this->accountancy_code);
$this->color = empty($this->color)?'':$this->color;
$this->dateemployment = empty($this->dateemployment)?'':$this->dateemployment;
// Check parameters
if (! empty($conf->global->USER_MAIL_REQUIRED) && ! isValidEMail($this->email))
{
@ -1396,7 +1405,7 @@ class User extends CommonObject
$sql.= ", entity = '".$this->db->escape($this->entity)."'";
$sql.= ", default_range = ".($this->default_range > 0 ? $this->default_range : 'null');
$sql.= ", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat : 'null');
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::update", LOG_DEBUG);