fix: sidebar marca activo solo el item actual, no todos los de erp.php
This commit is contained in:
@@ -34,17 +34,23 @@ $_current_script = basename($_SERVER['PHP_SELF']);
|
||||
*/
|
||||
$_isActive = function (string $route) use ($_current_script): string {
|
||||
if ($route === '') return '';
|
||||
// Para rutas como /lab_domicilios.php: comparar con basename
|
||||
$routeBase = basename(parse_url($route, PHP_URL_PATH) ?? '');
|
||||
if ($routeBase === $_current_script) {
|
||||
$parsed = parse_url($route);
|
||||
$routeBase = basename($parsed['path'] ?? '');
|
||||
|
||||
// Rutas ERP con query params: comparar script Y cada param de la ruta
|
||||
if (!empty($parsed['query'])) {
|
||||
$uriParsed = parse_url($_SERVER['REQUEST_URI'] ?? '');
|
||||
if ($routeBase !== basename($uriParsed['path'] ?? '')) return '';
|
||||
parse_str($parsed['query'], $routeParams);
|
||||
parse_str($uriParsed['query'] ?? '', $uriParams);
|
||||
foreach ($routeParams as $k => $v) {
|
||||
if (($uriParams[$k] ?? null) !== $v) return '';
|
||||
}
|
||||
return ' active';
|
||||
}
|
||||
// Para rutas con parámetros ERP (?m=&v=): comparar con REQUEST_URI
|
||||
$uri = $_SERVER['REQUEST_URI'] ?? '';
|
||||
if ($route !== '/' && str_contains($uri, ltrim($route, '/'))) {
|
||||
return ' active';
|
||||
}
|
||||
return '';
|
||||
|
||||
// Rutas directas como /lab_domicilios.php
|
||||
return $routeBase === $_current_script ? ' active' : '';
|
||||
};
|
||||
|
||||
// Título del sidebar: prioridad al nombre definido por el módulo, luego el genérico
|
||||
|
||||
Reference in New Issue
Block a user