diff --git a/htdocs/core/class/menubase.class.php b/htdocs/core/class/menubase.class.php index f011119e08e..a96f62e8cbc 100644 --- a/htdocs/core/class/menubase.class.php +++ b/htdocs/core/class/menubase.class.php @@ -520,8 +520,8 @@ class Menubase $sql.= " ORDER BY m.position, m.rowid"; //print $sql; -//$tmp1=microtime(true); -//print '>>> 1 0
'; + //$tmp1=microtime(true); + //print '>>> 1 0
'; dol_syslog(get_class($this)."::menuLoad mymainmenu=".$mymainmenu." myleftmenu=".$myleftmenu." type_user=".$type_user." menu_handler=".$menu_handler." tabMenu size=".count($tabMenu)."", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) @@ -558,7 +558,8 @@ class Menubase // Define $title if ($enabled) { - $title = $langs->trans($menu['titre']); + $title = $langs->trans($menu['titre']); // If $menu['titre'] start with $, a dol_eval is done. + //var_dump($title.'-'.$menu['titre']); if ($title == $menu['titre']) // Translation not found { if (! empty($menu['langs'])) // If there is a dedicated translation file @@ -567,6 +568,9 @@ class Menubase $langs->load($menu['langs']); } + $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user); + $menu['titre'] = make_substitutions($menu['titre'], $substitarray); + if (preg_match("/\//",$menu['titre'])) // To manage translation when title is string1/string2 { $tab_titre = explode("/",$menu['titre']); @@ -584,8 +588,8 @@ class Menubase $title = $langs->trans($menu['titre']); } } -//$tmp4=microtime(true); -//print '>>> 3 '.($tmp4 - $tmp3).'
'; + //$tmp4=microtime(true); + //print '>>> 3 '.($tmp4 - $tmp3).'
'; // We complete tabMenu $tabMenu[$b]['rowid'] = $menu['rowid']; diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index 94dce163921..04d65fa74e8 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -635,7 +635,7 @@ class Translate } else // Translation is not available { - if ($key[0] == '$') { return dol_eval($key,1); } + //if ($key[0] == '$') { return dol_eval($key,1); } return $this->getTradFromKey($key); } } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 9683517f377..1ee42f0e88e 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -467,7 +467,7 @@ function GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NU } // Substitution variables for GETPOST (used to get final url with variable parameters or final default value with variable paramaters) - // Example of variables: __DAY__, __MONTH__, __YEAR__, __MYCOUNTRYID__, __USERID__, __ENTITYID__, ... + // Example of variables: __DAY__, __MONTH__, __YEAR__, __MYCOMPANY_COUNTRY_ID__, __USER_ID__, ... // We do this only if var is a GET. If it is a POST, may be we want to post the text with vars as the setup text. if (! is_array($out) && empty($_POST[$paramname]) && empty($noreplace)) { @@ -485,7 +485,7 @@ function GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NU elseif ($reg[1] == 'NEXT_DAY') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_day($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['day']; } elseif ($reg[1] == 'NEXT_MONTH') { $tmp=dol_getdate(dol_now(), true); $tmp2=dol_get_next_month($tmp['mday'], $tmp['mon'], $tmp['year']); $newout = $tmp2['month']; } elseif ($reg[1] == 'NEXT_YEAR') { $tmp=dol_getdate(dol_now(), true); $newout = ($tmp['year'] + 1); } - elseif ($reg[1] == 'MYCOUNTRY_ID' || $reg[1] == 'MYCOUNTRYID') + elseif ($reg[1] == 'MYCOMPANY_COUNTRY_ID' || $reg[1] == 'MYCOUNTRY_ID' || $reg[1] == 'MYCOUNTRYID') { $newout = $mysoc->country_id; } @@ -493,11 +493,11 @@ function GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NU { $newout = $user->id; } - elseif ($reg[1] == 'SUPERVISOR_ID' || $reg[1] == 'SUPERVISORID') + elseif ($reg[1] == 'USER_SUPERVISOR_ID' || $reg[1] == 'SUPERVISOR_ID' || $reg[1] == 'SUPERVISORID') { $newout = $user->fk_user; } - elseif ($reg[1] == 'ENTITYID') + elseif ($reg[1] == 'ENTITY_ID' || $reg[1] == 'ENTITYID') { $newout = $conf->entity; } diff --git a/htdocs/core/menus/standard/auguria.lib.php b/htdocs/core/menus/standard/auguria.lib.php index 90089488389..4dae9628c30 100644 --- a/htdocs/core/menus/standard/auguria.lib.php +++ b/htdocs/core/menus/standard/auguria.lib.php @@ -73,12 +73,9 @@ function print_auguria_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$m $showmode=dol_auguria_showmenu($type_user,$newTabMenu[$i],$listofmodulesforexternal); if ($showmode == 1) { - // $menu_array[$i]['url'] can be a relative url, a full external url or a dynamic value like '$conf->global->APARAM) - if (preg_match('/^\$conf->global->([^\?]+)/', $newTabMenu[$i]['url'], $reg)) - { - $keyforsconst=$reg[1]; - $newTabMenu[$i]['url'] = $conf->global->$keyforsconst; - } + $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user); + $substitarray['__USERID__'] = $user->id; // For backward compatibility + $newTabMenu[$i]['url'] = make_substitutions($newTabMenu[$i]['url'], $substitarray); $url = $shorturl = $newTabMenu[$i]['url']; @@ -105,11 +102,6 @@ function print_auguria_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$m if (DOL_URL_ROOT) $shorturl = preg_replace('/^'.preg_quote(DOL_URL_ROOT,'/').'/','',$shorturl); } - $url=preg_replace('/__LOGIN__/',$user->login,$url); - $shorturl=preg_replace('/__LOGIN__/',$user->login,$shorturl); - $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)) { @@ -511,10 +503,13 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM } } + // $menu_array[$i]['url'] can be a relative url, a full external url. We try substitution + $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user); + $substitarray['__USERID__'] = $user->id; // For backward compatibility + $menu_array[$i]['url'] = make_substitutions($menu_array[$i]['url'], $substitarray); + // Add mainmenu in GET url. This make to go back on correct menu even when using Back on browser. $url=dol_buildpath($menu_array[$i]['url'],1); - $url=preg_replace('/__LOGIN__/',$user->login,$url); - $url=preg_replace('/__USERID__/',$user->id,$url); if (! preg_match('/mainmenu=/i',$menu_array[$i]['url'])) { diff --git a/htdocs/core/menus/standard/auguria_menu.php b/htdocs/core/menus/standard/auguria_menu.php index 648d76f327e..080e9ef81dc 100644 --- a/htdocs/core/menus/standard/auguria_menu.php +++ b/htdocs/core/menus/standard/auguria_menu.php @@ -157,9 +157,11 @@ class MenuManager print '
  • '; if ($val['enabled'] == 1) { + $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user); + $substitarray['__USERID__'] = $user->id; // For backward compatibility + $val['url'] = make_substitutions($val['url'], $substitarray); + $relurl=dol_buildpath($val['url'],1); - $relurl=preg_replace('/__LOGIN__/',$user->login,$relurl); - $relurl=preg_replace('/__USERID__/',$user->id,$relurl); $canonurl=preg_replace('/\?.*$/','',$val['url']); print ''; @@ -233,9 +235,11 @@ class MenuManager if ($showmenu) // Visible (option to hide when not allowed is off or allowed) { + $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user); + $substitarray['__USERID__'] = $user->id; // For backward compatibility + $val2['url'] = make_substitutions($val2['url'], $substitarray); + $relurl2=dol_buildpath($val2['url'],1); - $relurl2=preg_replace('/__LOGIN__/',$user->login,$relurl2); - $relurl2=preg_replace('/__USERID__/',$user->id,$relurl2); $canonurl2=preg_replace('/\?.*$/','',$val2['url']); //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']); if (in_array($canonurl2,array('/admin/index.php','/admin/tools/index.php','/core/tools.php'))) $relurl2=''; diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 1ecc84f5c2b..28726d461f4 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -273,7 +273,6 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode $menu->add('/adherents/index.php?mainmenu=members&leftmenu=', $langs->trans("MenuMembers"), 0, $showmode, $atarget, "members", '', 100, $id, $idsel, $classname); } - // Show personalized menus $menuArbo = new Menubase($db,'eldy'); $newTabMenu = $menuArbo->menuTopCharger('','',$type_user,'eldy',$tabMenu); // Return tabMenu with only top entries @@ -286,6 +285,10 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode $showmode=isVisibleToUserType($type_user,$newTabMenu[$i],$listofmodulesforexternal); if ($showmode == 1) { + $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user); + $substitarray['__USERID__'] = $user->id; // For backward compatibility + $newTabMenu[$i]['url'] = make_substitutions($newTabMenu[$i]['url'], $substitarray); + // url = url from host, shorturl = relative path into dolibarr sources $url = $shorturl = $newTabMenu[$i]['url']; if (! preg_match("/^(http:\/\/|https:\/\/)/i",$newTabMenu[$i]['url'])) // Do not change url content for external links @@ -301,10 +304,6 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode $shorturl = $url; if (DOL_URL_ROOT) $shorturl = preg_replace('/^'.preg_quote(DOL_URL_ROOT,'/').'/','',$shorturl); } - $url=preg_replace('/__LOGIN__/',$user->login,$url); - $shorturl=preg_replace('/__LOGIN__/',$user->login,$shorturl); - $url=preg_replace('/__USERID__/',$user->id,$url); - $shorturl=preg_replace('/__USERID__/',$user->id,$shorturl); // Define the class (top menu selected or not) if (! empty($_SESSION['idmenu']) && $newTabMenu[$i]['rowid'] == $_SESSION['idmenu']) $classname='class="tmenusel"'; @@ -1598,12 +1597,10 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu } } - // $menu_array[$i]['url'] can be a relative url, a full external url or a dynamic value like '$conf->global->APARAM) - if (preg_match('/^\$conf->global->([^\?]+)/', $menu_array[$i]['url'], $reg)) - { - $keyforsconst=$reg[1]; - $menu_array[$i]['url'] = $conf->global->$keyforsconst; - } + // $menu_array[$i]['url'] can be a relative url, a full external url. We try substitution + $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user); + $substitarray['__USERID__'] = $user->id; // For backward compatibility + $menu_array[$i]['url'] = make_substitutions($menu_array[$i]['url'], $substitarray); $url = $shorturl = $menu_array[$i]['url']; @@ -1626,11 +1623,8 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $url = dol_buildpath($url,1).($param?'?'.$param:''); $shorturl = $shorturl.($param?'?'.$param:''); } + //var_dump($url); - $url=preg_replace('/__LOGIN__/',$user->login,$url); - $shorturl=preg_replace('/__LOGIN__/',$user->login,$shorturl); - $url=preg_replace('/__USERID__/',$user->id,$url); - $shorturl=preg_replace('/__USERID__/',$user->id,$shorturl); print ''."\n"; @@ -1656,6 +1650,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu print ''."\n"; } } + // Menu level > 0 if ($menu_array[$i]['level'] > 0) { diff --git a/htdocs/core/menus/standard/eldy_menu.php b/htdocs/core/menus/standard/eldy_menu.php index 2d41edd2d14..9ef1421daf2 100644 --- a/htdocs/core/menus/standard/eldy_menu.php +++ b/htdocs/core/menus/standard/eldy_menu.php @@ -165,9 +165,11 @@ class MenuManager if ($val['enabled'] == 1) { + $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user); + $substitarray['__USERID__'] = $user->id; // For backward compatibility + $val['url'] = make_substitutions($val['url'], $substitarray); + $relurl=dol_buildpath($val['url'],1); - $relurl=preg_replace('/__LOGIN__/',$user->login,$relurl); - $relurl=preg_replace('/__USERID__/',$user->id,$relurl); $canonurl=preg_replace('/\?.*$/','',$val['url']); print ''; @@ -243,9 +245,11 @@ class MenuManager if ($showmenu) // Visible (option to hide when not allowed is off or allowed) { + $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user); + $substitarray['__USERID__'] = $user->id; // For backward compatibility + $val2['url'] = make_substitutions($val2['url'], $substitarray); + $relurl2=dol_buildpath($val2['url'],1); - $relurl2=preg_replace('/__LOGIN__/',$user->login,$relurl2); - $relurl2=preg_replace('/__USERID__/',$user->id,$relurl2); $canonurl2=preg_replace('/\?.*$/','',$val2['url']); //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']); if (in_array($canonurl2,array('/admin/index.php','/admin/tools/index.php','/core/tools.php'))) $relurl2=''; diff --git a/htdocs/core/menus/standard/empty.php b/htdocs/core/menus/standard/empty.php index 9de1ee345c2..ce85e583432 100644 --- a/htdocs/core/menus/standard/empty.php +++ b/htdocs/core/menus/standard/empty.php @@ -150,11 +150,13 @@ class MenuManager print '