feat(turnero): bacteriólogo sin dashboard/historial, redirige por IP
- Auth: agrega isBacteriologo() - App: guard que bloquea dashboard e historial para bacteriólogo y redirige según IP (turnero_dispositivos); IP registrada → ese lugar, IP libre → primer lugar de muestras - module.php: sidebar bacteriólogo sin Dashboard/Historial; IP registrada muestra solo ese lugar, IP libre muestra TV + todos los lugares muestras Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
a776c5733c
commit
b2e7130762
@@ -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
|
||||
|
||||
@@ -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';
|
||||
|
||||
+32
-10
@@ -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 ───────────────
|
||||
|
||||
Reference in New Issue
Block a user