feat(turnero): recepcionista con restricción de desk por IP
- module.php: si la IP está registrada en turnero_dispositivos para un lugar de tipo recepción, el sidebar muestra solo ese desk; resto de vistas (chat, verificar, TV) siempre visibles - App.php: guard que redirige al recepcionista a su desk si intenta acceder manualmente a otro desk_id; IP libre no tiene restricción Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
b2e7130762
commit
b6179574c3
@@ -44,6 +44,19 @@ class App
|
||||
header('Location: ' . APP_ROOT . '/../enfermero_portal.php');
|
||||
exit;
|
||||
}
|
||||
// Recepcionistas con IP registrada: solo pueden acceder a su desk
|
||||
if (Auth::role() === 'recepcionista') {
|
||||
$mod = $router->getModule();
|
||||
$view = $router->getView();
|
||||
if ($mod === 'turnero' && $view === 'recepcion') {
|
||||
$deskId = (int)($_GET['desk_id'] ?? 0);
|
||||
$assignedDesk = self::recepIpDesk();
|
||||
if ($assignedDesk && $deskId !== $assignedDesk) {
|
||||
header('Location: /erp.php?m=turnero&v=recepcion&desk_id=' . $assignedDesk);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Bacteriólogos: sin dashboard ni historial; redirige según IP
|
||||
if (Auth::isBacteriologo()) {
|
||||
$mod = $router->getModule();
|
||||
@@ -112,6 +125,26 @@ class App
|
||||
|
||||
// ─── Helpers de rol ─────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Devuelve el lugar_id de recepción asignado a la IP del cliente, o null si no está registrada.
|
||||
*/
|
||||
private static function recepIpDesk(): ?int
|
||||
{
|
||||
try {
|
||||
$pdo = Database::getInstance()->getConnection();
|
||||
$st = $pdo->prepare(
|
||||
"SELECT d.lugar_id FROM turnero_dispositivos d
|
||||
JOIN turnero_lugares l ON l.id = d.lugar_id
|
||||
WHERE d.ip = ? AND d.activo = 1 AND l.tipo = 'recepcion' LIMIT 1"
|
||||
);
|
||||
$st->execute([$_SERVER['REMOTE_ADDR'] ?? '']);
|
||||
$id = $st->fetchColumn();
|
||||
return $id ? (int)$id : null;
|
||||
} catch (\Throwable $_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* URL de destino para bacteriólogo según IP del cliente.
|
||||
* IP registrada en turnero_dispositivos → ese lugar.
|
||||
|
||||
@@ -27,12 +27,38 @@ try {
|
||||
|
||||
$_trLinks = [];
|
||||
|
||||
// ── Recepcionista: solo sus escritorios + pantalla TV ─────────
|
||||
// ── Recepcionista: pantallas comunes + desks según IP ─────────
|
||||
if ($_trIsRecep) {
|
||||
$_trLinks[] = ['name' => 'Chat Turnero', 'icon' => 'fab fa-whatsapp', 'route' => '/erp.php?m=turnero&v=chat'];
|
||||
$_trLinks[] = ['name' => 'Verificar Paciente', 'icon' => 'fas fa-id-card', 'route' => '/erp.php?m=turnero&v=verificar_paciente'];
|
||||
$_trLinks[] = ['name' => 'Pantalla TV', 'icon' => 'fas fa-tv', 'route' => '/erp.php?m=turnero&v=display_global'];
|
||||
if (!empty($_trDesks)) {
|
||||
|
||||
// Detectar si la IP está asignada a un desk de recepción
|
||||
$_trRecepIpDesk = null;
|
||||
try {
|
||||
$_trRecepIpRow = $_trPdo->prepare(
|
||||
"SELECT d.lugar_id FROM turnero_dispositivos d
|
||||
JOIN turnero_lugares l ON l.id = d.lugar_id
|
||||
WHERE d.ip = ? AND d.activo = 1 AND l.tipo = 'recepcion' LIMIT 1"
|
||||
);
|
||||
$_trRecepIpRow->execute([$_SERVER['REMOTE_ADDR'] ?? '']);
|
||||
$_trRecepIpDesk = $_trRecepIpRow->fetchColumn() ?: null;
|
||||
} catch (\Throwable $_) {}
|
||||
|
||||
if ($_trRecepIpDesk) {
|
||||
// IP registrada: solo su desk
|
||||
foreach ($_trDesks as $_d) {
|
||||
if ((int)$_d['id'] === (int)$_trRecepIpDesk) {
|
||||
$_trLinks[] = [
|
||||
'name' => $_d['nombre'],
|
||||
'icon' => 'fas fa-concierge-bell',
|
||||
'route' => '/erp.php?m=turnero&v=recepcion&desk_id=' . (int)$_d['id'],
|
||||
];
|
||||
break;
|
||||
}
|
||||
}
|
||||
} elseif (!empty($_trDesks)) {
|
||||
// IP libre: todos los desks
|
||||
foreach ($_trDesks as $_d) {
|
||||
$_trLinks[] = [
|
||||
'name' => $_d['nombre'],
|
||||
|
||||
Reference in New Issue
Block a user