From 841acf9a85c94faa99a2886b421c4c70bc1abac6 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Wed, 24 Jun 2026 01:56:38 -0500 Subject: [PATCH] =?UTF-8?q?feat(turnero):=20filtrar=20sidebar=20por=20rol?= =?UTF-8?q?=20=E2=80=94=20recep=20ve=20solo=20sus=20desks,=20bacteriologo?= =?UTF-8?q?=20ve=20sus=20estaciones?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- modules/turnero/module.php | 82 +++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/modules/turnero/module.php b/modules/turnero/module.php index a6b9994..5273f7c 100644 --- a/modules/turnero/module.php +++ b/modules/turnero/module.php @@ -1,27 +1,35 @@ 'Dashboard', 'icon' => 'fas fa-tachometer-alt', 'route' => '/erp.php?m=turnero&v=dashboard'], - ['name' => 'Historial', 'icon' => 'fas fa-history', 'route' => '/erp.php?m=turnero&v=historial'], - ['name' => 'Configuración', 'icon' => 'fas fa-sliders-h', 'route' => '/erp.php?m=turnero&v=configuracion'], - ['name' => 'Kiosko', 'icon' => 'fas fa-desktop', 'route' => '/erp.php?m=turnero&v=kiosko'], - ['name' => 'Pantalla TV Global', 'icon' => 'fas fa-th-large', 'route' => '/erp.php?m=turnero&v=display_global'], -]; +$_trRole = $_SESSION['admin_user']['role'] ?? 'admin'; +$_trAdminRoles = ['superadmin', 'admin', 'supervisor']; +$_trIsAdmin = in_array($_trRole, $_trAdminRoles, true); +$_trIsRecep = $_trRole === 'recepcionista'; +$_trIsBacte = $_trRole === 'bacteriologo'; -// ── Links dinámicos: un enlace por escritorio de Recepción ──── try { - $_trPdo = Database::getInstance()->getConnection(); + $_trPdo = Database::getInstance()->getConnection(); + $_trDesks = $_trPdo->query( - "SELECT id, nombre FROM turnero_lugares - WHERE activo = 1 AND tipo = 'recepcion' - ORDER BY sort_order ASC" + "SELECT id, nombre FROM turnero_lugares WHERE activo=1 AND tipo='recepcion' ORDER BY sort_order" )->fetchAll(PDO::FETCH_ASSOC); + $_trMuestras = $_trPdo->query( + "SELECT id, nombre FROM turnero_lugares WHERE activo=1 AND tipo='muestras' ORDER BY sort_order" + )->fetchAll(PDO::FETCH_ASSOC); +} catch (\Throwable $_) { + $_trDesks = []; + $_trMuestras = []; +} + +$_trLinks = []; + +// ── Recepcionista: solo sus escritorios + pantalla TV ───────── +if ($_trIsRecep) { + $_trLinks[] = ['name' => 'Pantalla TV', 'icon' => 'fas fa-tv', 'route' => '/erp.php?m=turnero&v=display_global']; if (!empty($_trDesks)) { foreach ($_trDesks as $_d) { $_trLinks[] = [ @@ -31,22 +39,14 @@ try { ]; } } else { - // Sin escritorios configurados: enlace genérico $_trLinks[] = ['name' => 'Recepción', 'icon' => 'fas fa-concierge-bell', 'route' => '/erp.php?m=turnero&v=recepcion']; } -} catch (\Throwable $_) { - // BD no disponible todavía (instalación inicial) - $_trLinks[] = ['name' => 'Recepción', 'icon' => 'fas fa-concierge-bell', 'route' => '/erp.php?m=turnero&v=recepcion']; -} - -// ── Links dinámicos: un enlace por estación de Muestras ────── -try { - $_trMuestras = $_trPdo->query( - "SELECT id, nombre FROM turnero_lugares - WHERE activo = 1 AND tipo = 'muestras' - ORDER BY sort_order ASC" - )->fetchAll(PDO::FETCH_ASSOC); +// ── Bacteriólogo: dashboard, historial, TV + sus estaciones ── +} elseif ($_trIsBacte) { + $_trLinks[] = ['name' => 'Dashboard', 'icon' => 'fas fa-tachometer-alt', 'route' => '/erp.php?m=turnero&v=dashboard']; + $_trLinks[] = ['name' => 'Historial', 'icon' => 'fas fa-history', 'route' => '/erp.php?m=turnero&v=historial']; + $_trLinks[] = ['name' => 'Pantalla TV', 'icon' => 'fas fa-tv', 'route' => '/erp.php?m=turnero&v=display_global']; foreach ($_trMuestras as $_m) { $_trLinks[] = [ 'name' => $_m['nombre'], @@ -54,7 +54,33 @@ try { 'route' => '/erp.php?m=turnero&v=lugar&lugar_id=' . (int)$_m['id'], ]; } -} catch (\Throwable $_) {} + +// ── Admin / Supervisor / otros: acceso completo ─────────────── +} else { + $_trLinks[] = ['name' => 'Dashboard', 'icon' => 'fas fa-tachometer-alt', 'route' => '/erp.php?m=turnero&v=dashboard']; + $_trLinks[] = ['name' => 'Historial', 'icon' => 'fas fa-history', 'route' => '/erp.php?m=turnero&v=historial']; + $_trLinks[] = ['name' => 'Configuración', 'icon' => 'fas fa-sliders-h', 'route' => '/erp.php?m=turnero&v=configuracion']; + $_trLinks[] = ['name' => 'Kiosko', 'icon' => 'fas fa-desktop', 'route' => '/erp.php?m=turnero&v=kiosko']; + $_trLinks[] = ['name' => 'Pantalla TV Global', 'icon' => 'fas fa-th-large', 'route' => '/erp.php?m=turnero&v=display_global']; + if (!empty($_trDesks)) { + foreach ($_trDesks as $_d) { + $_trLinks[] = [ + 'name' => $_d['nombre'], + 'icon' => 'fas fa-concierge-bell', + 'route' => '/erp.php?m=turnero&v=recepcion&desk_id=' . (int)$_d['id'], + ]; + } + } else { + $_trLinks[] = ['name' => 'Recepción', 'icon' => 'fas fa-concierge-bell', 'route' => '/erp.php?m=turnero&v=recepcion']; + } + foreach ($_trMuestras as $_m) { + $_trLinks[] = [ + 'name' => $_m['nombre'], + 'icon' => 'fas fa-flask', + 'route' => '/erp.php?m=turnero&v=lugar&lugar_id=' . (int)$_m['id'], + ]; + } +} return [ 'slug' => 'turnero',