diff --git a/Vue/gabarit.php b/Vue/gabarit.php index 518e8ea..f065044 100755 --- a/Vue/gabarit.php +++ b/Vue/gabarit.php @@ -10,21 +10,44 @@ $_SESSION['firstLevelMenu'] = $activeLink; $companyDisplayName = htmlspecialchars($_SESSION['nomSociete'], ENT_QUOTES); $imgData = $_SESSION['photoAssureCrypte'] ?? ''; -// Détection automatique des menus actifs +// Détection automatique des menus actifs - VERSION CORRIGÉE $activeParentId = null; $activeChildId = null; foreach ($menus as $key0 => $menuParent) { $menuChildrenLevelOne = $gabary->get_menus_by_parent_code($menuParent['vue']); - foreach ($menuChildrenLevelOne as $key1 => $menuChild) { - if ((explode('/', $menuChild['lienMenu'])[0] ?? '') == $activeLink) { + // 1. Vérifier si c'est un lien DIRECT (comme "Accueil") + if (empty($menuChildrenLevelOne)) { + // Menu sans enfants = lien direct + $parentLink = explode('/', $menuParent['lienMenu'])[0] ?? ''; + if (!empty($parentLink) && $parentLink == $activeLink) { $activeParentId = $key0; - $activeChildId = $key1; - break 2; + break; + } + } + // 2. Vérifier les SOUS-MENUS (enfants) + else { + foreach ($menuChildrenLevelOne as $key1 => $menuChild) { + $childLink = explode('/', $menuChild['lienMenu'])[0] ?? ''; + if ($childLink == $activeLink) { + $activeParentId = $key0; + $activeChildId = $key1; + break 2; + } } } } + +// CORRECTION IMPORTANTE : Si c'est "Accueil" et pas trouvé, c'est menu 0 +if ($activeParentId === null && $activeLink == 'Accueil') { + $activeParentId = 0; +} + +// Toujours avoir une valeur +if ($activeParentId === null) { + $activeParentId = 0; +} ?>