Fix the "back to list" link also restore the contextpage

This commit is contained in:
Laurent Destailleur
2018-06-23 11:55:04 +02:00
parent f2ac5dab4a
commit 4dcc74d08f
5 changed files with 62 additions and 33 deletions

View File

@@ -293,7 +293,6 @@ function GETPOST($paramname, $check='none', $method=0, $filter=null, $options=nu
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);
@@ -303,15 +302,17 @@ function GETPOST($paramname, $check='none', $method=0, $filter=null, $options=nu
//var_dump($user->default_values);
// Code for search criteria persistence.
// Retrieve values if restore_lastsearch_values is set and there is saved values
if (! empty($_GET['restore_lastsearch_values']) && ! empty($_SESSION['lastsearch_values_'.$relativepathstring])) // Keep $_GET here
// Retrieve values if restore_lastsearch_values
if (! empty($_GET['restore_lastsearch_values'])) // Use $_GET here and not GETPOST
{
if (! empty($_SESSION['lastsearch_values_'.$relativepathstring])) // If there is saved values
{
$tmp=json_decode($_SESSION['lastsearch_values_'.$relativepathstring], true);
if (is_array($tmp))
{
foreach($tmp as $key => $val)
{
if ($key == $paramname)
if ($key == $paramname) // We are on the requested parameter
{
$out=$val;
break;
@@ -319,6 +320,15 @@ function GETPOST($paramname, $check='none', $method=0, $filter=null, $options=nu
}
}
}
if (! empty($_SESSION['lastsearch_contextpage_'.$relativepathstring])) // If there is saved contextpage
{
if ($paramname == 'contextpage')
{
$out = $_SESSION['lastsearch_contextpage_'.$relativepathstring];
//var_dump($paramname.' '.$out);
}
}
}
// Else, retreive default values if we are not doing a sort
elseif (! isset($_GET['sortfield'])) // 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
{

View File

@@ -71,11 +71,11 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->societe->enabled', __HANDLER__, 'left', 500__+MAX_llx_menu__, 'companies', 'thirdparties', 2__+MAX_llx_menu__, '/societe/index.php?leftmenu=thirdparties', 'ThirdParty', 0, 'companies', '$user->rights->societe->lire', '', 2, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->societe->enabled', __HANDLER__, 'left', 501__+MAX_llx_menu__, 'companies', '', 500__+MAX_llx_menu__, '/societe/card.php?action=create', 'MenuNewThirdParty', 1, 'companies', '$user->rights->societe->lire', '', 2, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->societe->enabled', __HANDLER__, 'left', 502__+MAX_llx_menu__, 'companies', '', 500__+MAX_llx_menu__, '/societe/list.php?action=create', 'List', 1, 'companies', '$user->rights->societe->lire', '', 2, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->societe->enabled && $conf->fournisseur->enabled', __HANDLER__, 'left', 503__+MAX_llx_menu__, 'companies', '', 500__+MAX_llx_menu__, '/societe/list.php?type=f&leftmenu=suppliers&contextpage=supplierslist', 'ListSuppliersShort', 1, 'suppliers', '$user->rights->societe->lire && $user->rights->fournisseur->lire', '', 2, 5, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->societe->enabled && $conf->fournisseur->enabled', __HANDLER__, 'left', 503__+MAX_llx_menu__, 'companies', '', 500__+MAX_llx_menu__, '/societe/list.php?type=f&leftmenu=suppliers', 'ListSuppliersShort', 1, 'suppliers', '$user->rights->societe->lire && $user->rights->fournisseur->lire', '', 2, 5, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->societe->enabled && $conf->fournisseur->enabled', __HANDLER__, 'left', 504__+MAX_llx_menu__, 'companies', '', 503__+MAX_llx_menu__, '/societe/card.php?leftmenu=supplier&action=create&type=f', 'NewSupplier', 2, 'suppliers', '$user->rights->societe->creer', '', 2, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->societe->enabled', __HANDLER__, 'left', 506__+MAX_llx_menu__, 'companies', '', 500__+MAX_llx_menu__, '/societe/list.php?type=p&leftmenu=prospects&contextpage=prospectslist', 'ListProspectsShort', 1, 'companies', '$user->rights->societe->lire', '', 2, 3, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->societe->enabled', __HANDLER__, 'left', 506__+MAX_llx_menu__, 'companies', '', 500__+MAX_llx_menu__, '/societe/list.php?type=p&leftmenu=prospects', 'ListProspectsShort', 1, 'companies', '$user->rights->societe->lire', '', 2, 3, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->societe->enabled', __HANDLER__, 'left', 507__+MAX_llx_menu__, 'companies', '', 506__+MAX_llx_menu__, '/societe/card.php?leftmenu=prospects&action=create&type=p', 'MenuNewProspect', 2, 'companies', '$user->rights->societe->creer', '', 2, 0, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->societe->enabled', __HANDLER__, 'left', 509__+MAX_llx_menu__, 'companies', '', 500__+MAX_llx_menu__, '/societe/list.php?type=c&leftmenu=customers&contextpage=customerslist', 'ListCustomersShort', 1, 'companies', '$user->rights->societe->lire', '', 2, 4, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->societe->enabled', __HANDLER__, 'left', 509__+MAX_llx_menu__, 'companies', '', 500__+MAX_llx_menu__, '/societe/list.php?type=c&leftmenu=customers', 'ListCustomersShort', 1, 'companies', '$user->rights->societe->lire', '', 2, 4, __ENTITY__);
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->societe->enabled', __HANDLER__, 'left', 510__+MAX_llx_menu__, 'companies', '', 509__+MAX_llx_menu__, '/societe/card.php?leftmenu=customers&action=create&type=c', 'MenuNewCustomer', 2, 'companies', '$user->rights->societe->creer', '', 2, 0, __ENTITY__);
-- Third parties - Contacts
insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->societe->enabled', __HANDLER__, 'left', 600__+MAX_llx_menu__, 'companies', 'contacts', 2__+MAX_llx_menu__, '/contact/list.php?leftmenu=contacts', 'ContactsAddresses', 0, 'companies', '$user->rights->societe->lire', '', 2, 1, __ENTITY__);

View File

@@ -637,7 +637,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
if (! empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
{
$langs->load("commercial");
$newmenu->add("/societe/list.php?type=p&leftmenu=prospects&contextpage=customerslist", $langs->trans("ListProspectsShort"), 1, $user->rights->societe->lire, '', $mainmenu, 'prospects');
$newmenu->add("/societe/list.php?type=p&leftmenu=prospects", $langs->trans("ListProspectsShort"), 1, $user->rights->societe->lire, '', $mainmenu, 'prospects');
/* no more required, there is a filter that can do more
if ($usemenuhider || empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/societe/list.php?type=p&sortfield=s.datec&sortorder=desc&begin=&search_stcomm=-1", $langs->trans("LastProspectDoNotContact"), 2, $user->rights->societe->lire);
if ($usemenuhider || empty($leftmenu) || $leftmenu=="prospects") $newmenu->add("/societe/list.php?type=p&sortfield=s.datec&sortorder=desc&begin=&search_stcomm=0", $langs->trans("LastProspectNeverContacted"), 2, $user->rights->societe->lire);
@@ -653,7 +653,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
if (! empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))
{
$langs->load("commercial");
$newmenu->add("/societe/list.php?type=c&leftmenu=customers&contextpage=customerslist", $langs->trans("ListCustomersShort"), 1, $user->rights->societe->lire, '', $mainmenu, 'customers');
$newmenu->add("/societe/list.php?type=c&leftmenu=customers", $langs->trans("ListCustomersShort"), 1, $user->rights->societe->lire, '', $mainmenu, 'customers');
$newmenu->add("/societe/card.php?leftmenu=customers&action=create&type=c", $langs->trans("MenuNewCustomer"), 2, $user->rights->societe->creer);
//$newmenu->add("/contact/list.php?leftmenu=customers&type=c", $langs->trans("Contacts"), 2, $user->rights->societe->contact->lire);
@@ -663,7 +663,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
if (! empty($conf->societe->enabled) && ! empty($conf->fournisseur->enabled))
{
$langs->load("suppliers");
$newmenu->add("/societe/list.php?type=f&leftmenu=suppliers&contextpage=supplierlist", $langs->trans("ListSuppliersShort"), 1, $user->rights->fournisseur->lire, '', $mainmenu, 'suppliers');
$newmenu->add("/societe/list.php?type=f&leftmenu=suppliers", $langs->trans("ListSuppliersShort"), 1, $user->rights->fournisseur->lire, '', $mainmenu, 'suppliers');
$newmenu->add("/societe/card.php?leftmenu=suppliers&action=create&type=f",$langs->trans("MenuNewSupplier"), 2, $user->rights->societe->creer && $user->rights->fournisseur->lire);
}

View File

@@ -707,7 +707,7 @@ if (! defined('NOLOGIN'))
$hookmanager->initHooks(array('main'));
// Code for search criteria persistence.
if (! empty($_GET['save_lastsearch_values'])) // Keep $_GET here
if (! empty($_GET['save_lastsearch_values'])) // We must use $_GET here
{
$relativepathstring = preg_replace('/\?.*$/','',$_SERVER["HTTP_REFERER"]);
$relativepathstring = preg_replace('/^https?:\/\/[^\/]*/','',$relativepathstring); // Get full path except host server
@@ -723,6 +723,12 @@ if (! defined('NOLOGIN'))
$_SESSION['lastsearch_values_'.$relativepathstring]=$_SESSION['lastsearch_values_tmp_'.$relativepathstring];
unset($_SESSION['lastsearch_values_tmp_'.$relativepathstring]);
}
// We also save contextpage
if (! empty($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]))
{
$_SESSION['lastsearch_contextpage_'.$relativepathstring]=$_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring];
unset($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]);
}
}
$action = '';
@@ -1928,7 +1934,7 @@ if (! function_exists("llxFooter"))
function llxFooter($comment='',$zone='private', $disabledoutputofmessages=0)
{
global $conf, $langs, $user, $object;
global $delayedhtmlcontent;
global $delayedhtmlcontent, $contextpage;
$ext='layout='.$conf->browser->layout.'&version='.urlencode(DOL_VERSION);
@@ -1936,24 +1942,37 @@ if (! function_exists("llxFooter"))
dol_htmloutput_events($disabledoutputofmessages);
// Code for search criteria persistence.
// Save $user->lastsearch_values if defined (define on list pages when a form field search_xxx exists)
// $user->lastsearch_values was set by the GETPOST when form field search_xxx exists
if (is_object($user) && ! empty($user->lastsearch_values_tmp) && is_array($user->lastsearch_values_tmp))
{
// Clean data
// Clean and save data
foreach($user->lastsearch_values_tmp as $key => $val)
{
unset($_SESSION['lastsearch_values_tmp_'.$key]); // Clean arry to rebuild it just after
unset($_SESSION['lastsearch_values_tmp_'.$key]); // Clean array to rebuild it just after
if (count($val) && empty($_POST['button_removefilter'])) // If there is search criteria to save and we did not click on 'Clear filter' button
{
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)." (systematic recording of last search criteria)");
dol_syslog('Save lastsearch_values_tmp_'.$key.'='.json_encode($val, 0)." (systematic recording of last search criterias)");
$_SESSION['lastsearch_values_tmp_'.$key]=json_encode($val);
unset($_SESSION['lastsearch_values_'.$key]);
}
}
}
$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);
if (preg_match('/list\.php$/', $relativepathstring))
{
unset($_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]);
if (! empty($contextpage)) $_SESSION['lastsearch_contextpage_tmp_'.$relativepathstring]=$contextpage;
unset($_SESSION['lastsearch_contextpage_'.$relativepathstring]);
}
// Core error message
if (! empty($conf->global->MAIN_CORE_ERROR))
{

View File

@@ -91,9 +91,9 @@ $search_level_to = GETPOST("search_level_to","alpha");
$search_stcomm=GETPOST('search_stcomm','int');
$search_import_key = GETPOST("search_import_key","alpha");
$type=GETPOST('type');
$type=GETPOST('type','alpha');
$optioncss=GETPOST('optioncss','alpha');
$mode=GETPOST("mode");
$mode=GETPOST("mode",'');
$diroutputmassaction=$conf->societe->dir_output . '/temp/massgeneration/'.$user->id;
@@ -108,9 +108,9 @@ $offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if ($type == 'c') { $contextpage='customerlist'; if ($search_type=='') $search_type='1,3'; }
if ($type == 'p') { $contextpage='prospectlist'; if ($search_type=='') $search_type='2,3'; }
if ($type == 'f') { $contextpage='supplierlist'; if ($search_type=='') $search_type='4'; }
if ($type == 'c' && (empty($contextpage) || $contextpage == 'thirdpartylist')) { $contextpage='customerlist'; if ($search_type=='') $search_type='1,3'; }
if ($type == 'p' && (empty($contextpage) || $contextpage == 'thirdpartylist')) { $contextpage='prospectlist'; if ($search_type=='') $search_type='2,3'; }
if ($type == 'f' && (empty($contextpage) || $contextpage == 'thirdpartylist')) { $contextpage='supplierlist'; if ($search_type=='') $search_type='4'; }
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$object = new Societe($db);
@@ -533,13 +533,13 @@ $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('',$langs->trans("ThirdParty"),$help_url);
$param='';
if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
if ($search_all != '') $param = "&sall=".urlencode($search_all);
if ($sall != '') $param.= "&sall=".urlencode($sall);
if ($search_categ_cus > 0) $param.='&search_categ_cus='.urlencode($search_categ_cus);
if ($search_categ_sup > 0) $param.='&search_categ_sup='.urlencode($search_categ_sup);
if ($search_sale > 0) $param.='&search_sale='.urlencode($search_sale);
if ($search_categ_cus > 0) $param.= '&search_categ_cus='.urlencode($search_categ_cus);
if ($search_categ_sup > 0) $param.= '&search_categ_sup='.urlencode($search_categ_sup);
if ($search_sale > 0) $param.= '&search_sale='.urlencode($search_sale);
if ($search_id > 0) $param.= "&search_id=".urlencode($search_id);
if ($search_nom != '') $param.= "&search_nom=".urlencode($search_nom);
if ($search_alias != '') $param.= "&search_alias=".urlencode($search_alias);