Fix calculation of nb of top menu in CSS files.

This commit is contained in:
Laurent Destailleur 2020-09-25 14:09:51 +02:00
parent 3c6dda9dd5
commit 88b4c1e766
5 changed files with 39 additions and 25 deletions

View File

@ -120,7 +120,8 @@ class Menu
$nb = 0;
foreach ($this->liste as $val)
{
if (!empty($val['enabled'])) $nb++;
//if (dol_eval($val['enabled'], 1)) $nb++;
if (!empty($val['enabled'])) $nb++; // $val['enabled'] is already evaluated to 0 or 1, no need for dol_eval()
}
return $nb;
}

View File

@ -447,6 +447,7 @@ function print_eldy_menu($db, $atarget, $type_user, &$tabMenu, &$menu, $noout =
// Show personalized menus
$menuArbo = new Menubase($db, 'eldy');
$newTabMenu = $menuArbo->menuTopCharger('', '', $type_user, 'eldy', $tabMenu); // Return tabMenu with only top entries
$num = count($newTabMenu);
@ -455,34 +456,39 @@ function print_eldy_menu($db, $atarget, $type_user, &$tabMenu, &$menu, $noout =
//var_dump($type_user.' '.$newTabMenu[$i]['url'].' '.$showmode.' '.$newTabMenu[$i]['perms']);
$idsel = (empty($newTabMenu[$i]['mainmenu']) ? 'none' : $newTabMenu[$i]['mainmenu']);
$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
{
$tmp = explode('?', $newTabMenu[$i]['url'], 2);
$url = $shorturl = $tmp[0];
$param = (isset($tmp[1]) ? $tmp[1] : '');
if (!preg_match('/mainmenu/i', $param) || !preg_match('/leftmenu/i', $param)) $param .= ($param ? '&' : '').'mainmenu='.$newTabMenu[$i]['mainmenu'].'&leftmenu=';
//$url.="idmenu=".$newTabMenu[$i]['rowid']; // Already done by menuLoad
$url = dol_buildpath($url, 1).($param ? '?'.$param : '');
//$shorturl = $shorturl.($param?'?'.$param:'');
$shorturl = $url;
if (DOL_URL_ROOT) $shorturl = preg_replace('/^'.preg_quote(DOL_URL_ROOT, '/').'/', '', $shorturl);
}
$showmode = isVisibleToUserType($type_user, $newTabMenu[$i], $listofmodulesforexternal);
if ($showmode == 1)
{
$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
{
$tmp = explode('?', $newTabMenu[$i]['url'], 2);
$url = $shorturl = $tmp[0];
$param = (isset($tmp[1]) ? $tmp[1] : '');
if (!preg_match('/mainmenu/i', $param) || !preg_match('/leftmenu/i', $param)) $param .= ($param ? '&' : '').'mainmenu='.$newTabMenu[$i]['mainmenu'].'&leftmenu=';
//$url.="idmenu=".$newTabMenu[$i]['rowid']; // Already done by menuLoad
$url = dol_buildpath($url, 1).($param ? '?'.$param : '');
//$shorturl = $shorturl.($param?'?'.$param:'');
$shorturl = $url;
if (DOL_URL_ROOT) $shorturl = preg_replace('/^'.preg_quote(DOL_URL_ROOT, '/').'/', '', $shorturl);
}
// Define the class (top menu selected or not)
if (!empty($_SESSION['idmenu']) && $newTabMenu[$i]['rowid'] == $_SESSION['idmenu']) $classname = 'class="tmenusel"';
elseif (!empty($_SESSION["mainmenu"]) && $newTabMenu[$i]['mainmenu'] == $_SESSION["mainmenu"]) $classname = 'class="tmenusel"';
else $classname = 'class="tmenu"';
} elseif ($showmode == 2) $classname = 'class="tmenu"';
} elseif ($showmode == 2) {
$classname = 'class="tmenu"';
}
$menu->add($shorturl, $newTabMenu[$i]['titre'], 0, $showmode, ($newTabMenu[$i]['target'] ? $newTabMenu[$i]['target'] : $atarget), ($newTabMenu[$i]['mainmenu'] ? $newTabMenu[$i]['mainmenu'] : $newTabMenu[$i]['rowid']), ($newTabMenu[$i]['leftmenu'] ? $newTabMenu[$i]['leftmenu'] : ''), $newTabMenu[$i]['position'], $id, $idsel, $classname);
$menu->add($shorturl, $newTabMenu[$i]['titre'], 0, $showmode, ($newTabMenu[$i]['target'] ? $newTabMenu[$i]['target'] : $atarget),
($newTabMenu[$i]['mainmenu'] ? $newTabMenu[$i]['mainmenu'] : $newTabMenu[$i]['rowid']),
($newTabMenu[$i]['leftmenu'] ? $newTabMenu[$i]['leftmenu'] : ''),
$newTabMenu[$i]['position'], $id, $idsel, $classname);
}
// Sort on position
@ -517,7 +523,6 @@ function print_eldy_menu($db, $atarget, $type_user, &$tabMenu, &$menu, $noout =
print "\n".'<!-- Show logo on menu -->'."\n";
print_start_menu_entry('companylogo', 'class="tmenu tmenucompanylogo nohover"', 1);
print '<div class="center '.$logoContainerAdditionalClass.' menulogocontainer"><img class="mycompany" title="'.dol_escape_htmltag($title).'" alt="" src="'.$urllogo.'" style="max-width: 100px"></div>'."\n";
print_end_menu_entry(4);

View File

@ -147,7 +147,6 @@ class MenuManager
if ($mode == 'top') print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $this->menu, 0);
if ($mode == 'left') print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 0, $mode);
}
if ($mode == 'topnb')
{
print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode); // no output

View File

@ -31,8 +31,8 @@ if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1');
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled because need to do translations
if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', 1);
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1);
if (!defined('NOLOGIN')) define('NOLOGIN', 1); // File must be accessed by logon page so without login
//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1); // We need top menu content
if (!defined('NOLOGIN')) define('NOLOGIN', 1); // File must be accessed by logon page so without login.
//if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU',1); // We load menu manager class (note that object loaded may have wrong content because NOLOGIN is set and some values depends on login)
if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', 1);
if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
@ -55,6 +55,10 @@ if (empty($user->id) && !empty($_SESSION['dol_login']))
{
$user->fetch('', $_SESSION['dol_login'], '', 1);
$user->getrights();
// Reload menu now we have the good user (and we need the good menu to have ->showmenu('topnb') correct.
$menumanager = new MenuManager($db, empty($user->socid) ? 0 : 1);
$menumanager->loadMenu();
}
@ -190,6 +194,7 @@ $colortext = join(',', colorStringToArray($colortext));
$colortextlink = join(',', colorStringToArray($colortextlink));
$nbtopmenuentries = $menumanager->showmenu('topnb');
if ($conf->browser->layout == 'phone') $nbtopmenuentries = max($nbtopmenuentries, 10);

View File

@ -56,6 +56,10 @@ if (empty($user->id) && !empty($_SESSION['dol_login']))
{
$user->fetch('', $_SESSION['dol_login'], '', 1);
$user->getrights();
// Reload menu now we have the good user (and we need the good menu to have ->showmenu('topnb') correct.
$menumanager = new MenuManager($db, empty($user->socid) ? 0 : 1);
$menumanager->loadMenu();
}