diff --git a/core/App.php b/core/App.php index 8edd367..3642527 100644 --- a/core/App.php +++ b/core/App.php @@ -44,6 +44,17 @@ class App header('Location: ' . APP_ROOT . '/../enfermero_portal.php'); exit; } + // Bacteriólogos: sin dashboard ni historial; redirige según IP + if (Auth::isBacteriologo()) { + $mod = $router->getModule(); + $view = $router->getView(); + $blocked = ($mod === 'dashboard') + || ($mod === 'turnero' && in_array($view, ['dashboard', 'historial'], true)); + if ($blocked) { + header('Location: ' . self::bacteDefaultUrl()); + exit; + } + } } self::dispatch($router); @@ -99,6 +110,40 @@ class App include $viewFile; } + // ─── Helpers de rol ───────────────────────────────────────────────────── + + /** + * URL de destino para bacteriólogo según IP del cliente. + * IP registrada en turnero_dispositivos → ese lugar. + * IP no registrada → primer lugar de tipo muestras. + */ + private static function bacteDefaultUrl(): string + { + $base = '/erp.php?m=turnero&v=lugar&lugar_id='; + try { + $pdo = Database::getInstance()->getConnection(); + $ip = $_SERVER['REMOTE_ADDR'] ?? ''; + // ¿IP registrada? + $dev = $pdo->prepare( + "SELECT lugar_id FROM turnero_dispositivos WHERE ip = ? AND activo = 1 LIMIT 1" + ); + $dev->execute([$ip]); + $row = $dev->fetch(PDO::FETCH_ASSOC); + if ($row) { + return $base . (int)$row['lugar_id']; + } + // Primer lugar de toma de muestras + $first = $pdo->query( + "SELECT id FROM turnero_lugares WHERE activo=1 AND tipo='muestras' ORDER BY sort_order LIMIT 1" + )->fetch(PDO::FETCH_ASSOC); + if ($first) { + return $base . (int)$first['id']; + } + } catch (\Throwable $_) {} + // Fallback: turnero sin vista específica + return '/erp.php?m=turnero'; + } + // ─── Páginas de error ──────────────────────────────────────────────────── private static function render404(string $module, string $view): void diff --git a/core/Auth.php b/core/Auth.php index 8b4c97a..cea1b55 100644 --- a/core/Auth.php +++ b/core/Auth.php @@ -67,6 +67,11 @@ class Auth return self::role() === 'enfermero'; } + public static function isBacteriologo(): bool + { + return self::role() === 'bacteriologo'; + } + public static function isAdmin(): bool { return self::role() === 'admin'; diff --git a/modules/turnero/module.php b/modules/turnero/module.php index e673b99..e792e83 100644 --- a/modules/turnero/module.php +++ b/modules/turnero/module.php @@ -44,17 +44,39 @@ if ($_trIsRecep) { $_trLinks[] = ['name' => 'Recepción', 'icon' => 'fas fa-concierge-bell', 'route' => '/erp.php?m=turnero&v=recepcion']; } -// ── Bacteriólogo: dashboard, historial, TV + sus estaciones ── +// ── Bacteriólogo: sin dashboard ni historial; vista según IP ── } 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'], - 'icon' => 'fas fa-flask', - 'route' => '/erp.php?m=turnero&v=lugar&lugar_id=' . (int)$_m['id'], - ]; + $_trIpLugar = null; + try { + $_trIpRow = $_trPdo->prepare( + "SELECT lugar_id FROM turnero_dispositivos WHERE ip = ? AND activo = 1 LIMIT 1" + ); + $_trIpRow->execute([$_SERVER['REMOTE_ADDR'] ?? '']); + $_trIpLugar = $_trIpRow->fetchColumn() ?: null; + } catch (\Throwable $_) {} + + if ($_trIpLugar) { + // IP registrada: solo ese lugar en el sidebar + foreach ($_trMuestras as $_m) { + if ((int)$_m['id'] === (int)$_trIpLugar) { + $_trLinks[] = [ + 'name' => $_m['nombre'], + 'icon' => 'fas fa-flask', + 'route' => '/erp.php?m=turnero&v=lugar&lugar_id=' . (int)$_m['id'], + ]; + break; + } + } + } else { + // IP no registrada: TV + todos los lugares muestras + $_trLinks[] = ['name' => 'Pantalla TV', 'icon' => 'fas fa-tv', 'route' => '/erp.php?m=turnero&v=display_global']; + foreach ($_trMuestras as $_m) { + $_trLinks[] = [ + 'name' => $_m['nombre'], + 'icon' => 'fas fa-flask', + 'route' => '/erp.php?m=turnero&v=lugar&lugar_id=' . (int)$_m['id'], + ]; + } } // ── Admin / Supervisor / otros: acceso completo ───────────────