diff --git a/config/config.php b/config/config.php index 1139331..9cac115 100644 --- a/config/config.php +++ b/config/config.php @@ -544,6 +544,7 @@ function authenticateUser($username, $password) { 'role_id' => $admin['role_id'] ?? null, 'home_page' => $homePage, 'enfermera_id' => $admin['enfermera_id'] ?? null, + 'turnero_lugar_id' => $admin['turnero_lugar_id'] ?? null, 'modules' => $modules, 'module_permissions' => $modulePermissions, ]; diff --git a/login.php b/login.php index bf2aefd..ff24d9c 100644 --- a/login.php +++ b/login.php @@ -70,6 +70,22 @@ if ($_POST && !$loginBlocked) { exit; } } + // Usuario con lugar fijo asignado (sin IP registrada) + $_userLugarId = (int)($adminUser['turnero_lugar_id'] ?? 0); + if ($_userLugarId && in_array('turnero', $modules, true)) { + // Determinar si ese lugar es recepción o toma de muestras + try { + $_lugarTipo = Database::getInstance()->getConnection() + ->prepare("SELECT tipo FROM turnero_lugares WHERE id = ? LIMIT 1"); + $_lugarTipo->execute([$_userLugarId]); + $_tipo = $_lugarTipo->fetchColumn() ?: 'muestras'; + } catch (\Throwable $_) { $_tipo = 'muestras'; } + $url = $_tipo === 'recepcion' + ? BASE_URL . 'erp.php?m=turnero&v=recepcion&desk_id=' . $_userLugarId + : BASE_URL . 'erp.php?m=turnero&v=lugar&lugar_id=' . $_userLugarId; + header('Location: ' . $url); exit; + } + if ($roleSlug === 'enfermero') { header('Location: enfermero_portal.php'); } elseif (in_array('turnero', $modules, true)) { diff --git a/modules/turnero/views/recepcion.php b/modules/turnero/views/recepcion.php index f1d0a39..b44b292 100644 --- a/modules/turnero/views/recepcion.php +++ b/modules/turnero/views/recepcion.php @@ -10,6 +10,7 @@ if (!isUserLoggedIn()) { } // Tablet asignada → forzar su escritorio, bloquear cualquier otro +$_recepForzado = 0; if (!empty($_SESSION['turnero_dispositivo'])) { $_d = $_SESSION['turnero_dispositivo']; $_forzado = (int)$_d['lugar_id']; @@ -19,6 +20,17 @@ if (!empty($_SESSION['turnero_dispositivo'])) { if ((int)($_GET['desk_id'] ?? 0) !== $_forzado) { header('Location: ' . BASE_URL . 'erp.php?m=turnero&v=recepcion&desk_id=' . $_forzado); exit; } + $_recepForzado = $_forzado; +} +// Restricción a nivel de usuario (turnero_lugar_id en admin_users) +if (!$_recepForzado) { + $_userDesk = (int)($_SESSION['admin_user']['turnero_lugar_id'] ?? 0); + if ($_userDesk) { + if ((int)($_GET['desk_id'] ?? 0) !== $_userDesk) { + header('Location: ' . BASE_URL . 'erp.php?m=turnero&v=recepcion&desk_id=' . $_userDesk); exit; + } + $_recepForzado = $_userDesk; + } } // Cargar catálogos para la ficha