NEW Architecture to manage search criteria persistance (using
save_lastsearch_values=1 on exit links and restore_lastsearch_values=1 in entry links)
This commit is contained in:
parent
a28f8c84e4
commit
ff2a268831
@ -264,6 +264,8 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL)
|
||||
{
|
||||
global $mysoc,$user,$conf;
|
||||
|
||||
if (empty($paramname)) return 'BadFirstParameterForGETPOST';
|
||||
|
||||
if (empty($method)) $out = isset($_GET[$paramname])?$_GET[$paramname]:(isset($_POST[$paramname])?$_POST[$paramname]:'');
|
||||
elseif ($method==1) $out = isset($_GET[$paramname])?$_GET[$paramname]:'';
|
||||
elseif ($method==2) $out = isset($_POST[$paramname])?$_POST[$paramname]:'';
|
||||
@ -279,11 +281,11 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL)
|
||||
$relativepathstring = preg_replace('/^\//', '', $relativepathstring);
|
||||
|
||||
// Management of default values
|
||||
if (! isset($_GET['sortfield']) && ! empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) // If we did a click on a field to sort, we do no apply default values. Same if option MAIN_DISABLE_DEFAULT_VALUES is on
|
||||
if (! isset($_GET['sortfield']) && ! empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) // If we did a click on a field to sort, we do no apply default values. Same if option MAIN_ENABLE_DEFAULT_VALUES is not set
|
||||
{
|
||||
if (! empty($_GET['action']) && $_GET['action'] == 'create' && ! empty($paramname) && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
|
||||
if (! empty($_GET['action']) && $_GET['action'] == 'create' && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname]))
|
||||
{
|
||||
if (! empty($user->default_values)) // $user->default_values defined from menu default values, and values loaded not at first
|
||||
if (! empty($user->default_values)) // $user->default_values defined from menu default values
|
||||
{
|
||||
//var_dump($user->default_values[$relativepathstring]['createform']);
|
||||
if (isset($user->default_values[$relativepathstring]['createform'][$paramname])) $out = $user->default_values[$relativepathstring]['createform'][$paramname];
|
||||
@ -328,11 +330,34 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve values into restore_lastsearch_values
|
||||
if ($_GET['restore_lastsearch_values']) // Keep $_GET here
|
||||
{
|
||||
if (! empty($_SESSION['lastsearch_values_'.$relativepathstring]))
|
||||
{
|
||||
$tmp=json_decode($_SESSION['lastsearch_values_'.$relativepathstring], true);
|
||||
if (is_array($tmp))
|
||||
{
|
||||
foreach($tmp as $key => $val)
|
||||
{
|
||||
if ($key == $paramname)
|
||||
{
|
||||
$out=$val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (empty($check) && ! empty($conf->global->MAIN_FEATURES_LEVEL) && $conf->global->MAIN_FEATURES_LEVEL >= 2)
|
||||
{
|
||||
dol_syslog("Deprecated use of GETPOST, called with 1st param = ".$paramname." and 2nd param not defined, when calling page ".$_SERVER["PHP_SELF"], LOG_WARNING);
|
||||
// Enable this line to know who call the GETPOST with empty $check parameter.
|
||||
//var_dump(debug_backtrace()[0]);
|
||||
}
|
||||
|
||||
if (! empty($check))
|
||||
@ -423,14 +448,23 @@ function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL)
|
||||
}
|
||||
}
|
||||
|
||||
// Code for search criteria persistence.
|
||||
// Save data into session if key start with 'search_' or is 'smonth', 'syear', 'month', 'year'
|
||||
if (empty($method) || $method == 3 || $method == 4)
|
||||
{
|
||||
//if (preg_match('/^search_/', $paramname) || in_array($paramname, array('sortorder', 'sortfield", 'smonth', 'syear', 'month', 'year')))
|
||||
if (preg_match('/^search_/', $paramname) || in_array($paramname, array('sortorder','sortfield')))
|
||||
{
|
||||
//var_dump($user->default_values[$relativepathstring]);exit;
|
||||
//if ($paramname == 'sortorder') var_dump($paramname.' - '.$out);
|
||||
$user->lastsearch_values_tmp[$relativepathstring][$paramname]=$out;
|
||||
|
||||
// We save search key only if:
|
||||
// - not empty, or
|
||||
// - if value is empty and a default value exists that is not empty (it means we did a filter to an empty value when default was not).
|
||||
if (! empty($out) || ! empty($user->default_values[$relativepathstring][$paramname]))
|
||||
{
|
||||
$user->lastsearch_values_tmp[$relativepathstring][$paramname]=$out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -103,6 +103,14 @@ function print_auguria_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$m
|
||||
$url=preg_replace('/__USERID__/',$user->id,$url);
|
||||
$shorturl=preg_replace('/__USERID__/',$user->id,$shorturl);
|
||||
|
||||
// TODO Find a generic solution
|
||||
if (preg_match('/search_project_user=__search_project_user__/', $shorturl))
|
||||
{
|
||||
$search_project_user = GETPOST('search_project_user','int');
|
||||
if ($search_project_user) $shorturl=preg_replace('/search_project_user=__search_project_user__/', 'search_project_user='.$search_project_user, $shorturl);
|
||||
else $shorturl=preg_replace('/search_project_user=__search_project_user__/', '', $shorturl);
|
||||
}
|
||||
|
||||
// Define the class (top menu selected or not)
|
||||
if (! empty($_SESSION['idmenu']) && $newTabMenu[$i]['rowid'] == $_SESSION['idmenu']) $classname='class="tmenusel"';
|
||||
else if (! empty($_SESSION["mainmenu"]) && $newTabMenu[$i]['mainmenu'] == $_SESSION["mainmenu"]) $classname='class="tmenusel"';
|
||||
|
||||
@ -1299,11 +1299,13 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
|
||||
if (! empty($conf->projet->enabled))
|
||||
{
|
||||
$langs->load("projects");
|
||||
|
||||
|
||||
$search_project_user = GETPOST('search_project_user','int');
|
||||
|
||||
// Project affected to user
|
||||
$newmenu->add("/projet/index.php?leftmenu=projects&search_project_user=".GETPOST('search_project_user'), $langs->trans("Projects"), 0, $user->rights->projet->lire, '', $mainmenu, 'projects');
|
||||
$newmenu->add("/projet/card.php?leftmenu=projects&action=create&search_project_user=".GETPOST('search_project_user'), $langs->trans("NewProject"), 1, $user->rights->projet->creer);
|
||||
$newmenu->add("/projet/list.php?leftmenu=projects&search_project_user=".GETPOST('search_project_user')."&search_status=99", $langs->trans("List"), 1, $user->rights->projet->lire);
|
||||
$newmenu->add("/projet/index.php?leftmenu=projects".($search_project_user?'&search_project_user='.$search_project_user:''), $langs->trans("Projects"), 0, $user->rights->projet->lire, '', $mainmenu, 'projects');
|
||||
$newmenu->add("/projet/card.php?leftmenu=projects&action=create".($search_project_user?'&search_project_user='.$search_project_user:''), $langs->trans("NewProject"), 1, $user->rights->projet->creer);
|
||||
$newmenu->add("/projet/list.php?leftmenu=projects".($search_project_user?'&search_project_user='.$search_project_user:'')."&search_status=99", $langs->trans("List"), 1, $user->rights->projet->lire);
|
||||
|
||||
// All project i have permission on
|
||||
/*
|
||||
@ -1316,10 +1318,10 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
|
||||
if (empty($conf->global->PROJECT_HIDE_TASKS))
|
||||
{
|
||||
// Project affected to user
|
||||
$newmenu->add("/projet/activity/index.php?leftmenu=tasks&search_project_user=".GETPOST('search_project_user'), $langs->trans("Activities"), 0, $user->rights->projet->lire);
|
||||
$newmenu->add("/projet/activity/index.php?leftmenu=tasks".($search_project_user?'&search_project_user='.$search_project_user:''), $langs->trans("Activities"), 0, $user->rights->projet->lire);
|
||||
$newmenu->add("/projet/tasks.php?leftmenu=tasks&action=create", $langs->trans("NewTask"), 1, $user->rights->projet->creer);
|
||||
$newmenu->add("/projet/tasks/list.php?leftmenu=tasks&search_project_user=".GETPOST('search_project_user'), $langs->trans("List"), 1, $user->rights->projet->lire);
|
||||
$newmenu->add("/projet/activity/perweek.php?leftmenu=tasks&search_project_user=".GETPOST('search_project_user'), $langs->trans("NewTimeSpent"), 1, $user->rights->projet->lire);
|
||||
$newmenu->add("/projet/tasks/list.php?leftmenu=tasks".($search_project_user?'&search_project_user='.$search_project_user:''), $langs->trans("List"), 1, $user->rights->projet->lire);
|
||||
$newmenu->add("/projet/activity/perweek.php?leftmenu=tasks".($search_project_user?'&search_project_user='.$search_project_user:''), $langs->trans("NewTimeSpent"), 1, $user->rights->projet->lire);
|
||||
|
||||
// All project i have permission on
|
||||
/*$newmenu->add("/projet/activity/index.php", $langs->trans("Activities"), 0, $user->rights->projet->lire && $user->rights->projet->lire);
|
||||
|
||||
@ -646,6 +646,7 @@ if (! defined('NOLOGIN'))
|
||||
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
|
||||
$hookmanager->initHooks(array('main'));
|
||||
|
||||
// Code for search criteria persistence.
|
||||
if (! empty($_GET['save_lastsearch_values'])) // Keep $_GET here
|
||||
{
|
||||
$relativepathstring = preg_replace('/\?.*$/','',$_SERVER["HTTP_REFERER"]);
|
||||
@ -1886,6 +1887,7 @@ if (! function_exists("llxFooter"))
|
||||
// Global html output events ($mesgs, $errors, $warnings)
|
||||
dol_htmloutput_events();
|
||||
|
||||
// Code for search criteria persistence.
|
||||
// Save $user->lastsearch_values if defined (define on list pages when a form field search_xxx exists)
|
||||
if (is_object($user) && ! empty($user->lastsearch_values_tmp) && is_array($user->lastsearch_values_tmp))
|
||||
{
|
||||
@ -1897,7 +1899,7 @@ if (! function_exists("llxFooter"))
|
||||
{
|
||||
if (empty($val['sortfield'])) unset($val['sortfield']);
|
||||
if (empty($val['sortorder'])) unset($val['sortorder']);
|
||||
dol_syslog('Save lastsearch_values_tmp_'.$key.'='.json_encode($val, 0, 1));
|
||||
dol_syslog('Save lastsearch_values_tmp_'.$key.'='.json_encode($val, 0, 1)." (systematic recording of last search criteria)");
|
||||
$_SESSION['lastsearch_values_tmp_'.$key]=json_encode($val);
|
||||
unset($_SESSION['lastsearch_values_'.$key]);
|
||||
}
|
||||
|
||||
@ -837,7 +837,7 @@ elseif ($object->id > 0)
|
||||
{
|
||||
// Project card
|
||||
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
|
||||
|
||||
$morehtmlref='<div class="refidno">';
|
||||
// Title
|
||||
|
||||
@ -151,7 +151,7 @@ if ($id > 0 || ! empty($ref))
|
||||
|
||||
// Project card
|
||||
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
|
||||
|
||||
$morehtmlref='<div class="refidno">';
|
||||
// Title
|
||||
|
||||
@ -109,7 +109,7 @@ if ($object->id > 0)
|
||||
|
||||
// Project card
|
||||
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
|
||||
|
||||
$morehtmlref='<div class="refidno">';
|
||||
// Title
|
||||
|
||||
@ -128,7 +128,7 @@ dol_fiche_head($head, 'element', $langs->trans("Project"), -1, ($object->public?
|
||||
|
||||
// Project card
|
||||
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
|
||||
|
||||
$morehtmlref='<div class="refidno">';
|
||||
// Title
|
||||
|
||||
@ -102,7 +102,7 @@ if ($id > 0 || ! empty($ref))
|
||||
|
||||
// Project card
|
||||
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
|
||||
|
||||
$morehtmlref='<div class="refidno">';
|
||||
// Title
|
||||
|
||||
@ -33,7 +33,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
$langs->load("projects");
|
||||
$langs->load("companies");
|
||||
|
||||
$mine = GETPOST('mode')=='mine' ? 1 : 0;
|
||||
$mine = GETPOST('mode','aZ09')=='mine' ? 1 : 0;
|
||||
$search_project_user = GETPOST('search_project_user','int');
|
||||
|
||||
// Security check
|
||||
|
||||
@ -112,7 +112,7 @@ dol_fiche_head($head, 'agenda', $langs->trans("Project"), -1, ($object->public?'
|
||||
|
||||
// Project card
|
||||
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
|
||||
|
||||
$morehtmlref='<div class="refidno">';
|
||||
// Title
|
||||
|
||||
@ -30,7 +30,7 @@ $langs->load('projects');
|
||||
|
||||
$action=GETPOST('action','aZ09');
|
||||
$id = GETPOST('id','int');
|
||||
$ref= GETPOST('ref');
|
||||
$ref= GETPOST('ref','alpha');
|
||||
|
||||
$mine = $_REQUEST['mode']=='mine' ? 1 : 0;
|
||||
//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
|
||||
@ -82,7 +82,7 @@ if ($id > 0 || ! empty($ref))
|
||||
|
||||
// Project card
|
||||
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
|
||||
|
||||
$morehtmlref='<div class="refidno">';
|
||||
// Title
|
||||
|
||||
@ -225,7 +225,7 @@ if ($id > 0 || ! empty($ref))
|
||||
|
||||
// Project card
|
||||
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';
|
||||
$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
|
||||
|
||||
$morehtmlref='<div class="refidno">';
|
||||
// Title
|
||||
|
||||
Loading…
Reference in New Issue
Block a user