up
This commit is contained in:
+44
-7
@@ -4,6 +4,9 @@
|
||||
* Solo accesible para administradores.
|
||||
*/
|
||||
require_once 'config/config.php';
|
||||
if (file_exists(__DIR__ . '/core/ModuleRegistry.php')) {
|
||||
require_once __DIR__ . '/core/ModuleRegistry.php';
|
||||
}
|
||||
|
||||
if (!isUserLoggedIn()) { header('Location: login.php'); exit; }
|
||||
if (isEnfermero()) { header('Location: enfermero_portal.php'); exit; }
|
||||
@@ -12,6 +15,20 @@ $adminNombre = $_SESSION['admin_user']['full_name'] ?? $_SESSION['admin_user']['
|
||||
|
||||
// Catálogo de módulos disponible desde PHP (para el <script>)
|
||||
$systemModules = SYSTEM_MODULES;
|
||||
|
||||
// Lista enriquecida de módulos para el select de home_page (slug → ruta)
|
||||
$systemModulesRaw = [];
|
||||
if (class_exists('ModuleRegistry')) {
|
||||
foreach (ModuleRegistry::getAll() as $slug => $mod) {
|
||||
if (!empty($mod['route'])) {
|
||||
$systemModulesRaw[] = ['name' => $mod['name'], 'route' => $mod['route']];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach (SYSTEM_MODULES as $slug => $label) {
|
||||
$systemModulesRaw[] = ['name' => $label, 'route' => '/' . $slug . '.php'];
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
@@ -223,6 +240,23 @@ require_once __DIR__ . '/shared/components/sidebar.php';
|
||||
<label class="form-label fw-semibold">Descripción</label>
|
||||
<textarea id="r_description" class="form-control" rows="2" placeholder="Descripción corta del rol"></textarea>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<label class="form-label fw-semibold">
|
||||
<i class="fas fa-home me-1 text-primary"></i>
|
||||
Página de inicio al hacer login
|
||||
</label>
|
||||
<select id="r_home_page" class="form-select">
|
||||
<option value="">— Automático (según módulos asignados) —</option>
|
||||
<?php foreach ($systemModulesRaw as $sm): ?>
|
||||
<option value="<?= htmlspecialchars($sm['route'], ENT_QUOTES, 'UTF-8') ?>">
|
||||
<?= htmlspecialchars($sm['name'], ENT_QUOTES, 'UTF-8') ?>
|
||||
(<?= htmlspecialchars($sm['route'], ENT_QUOTES, 'UTF-8') ?>)
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
<option value="/index.php">Panel principal (/index.php)</option>
|
||||
</select>
|
||||
<div class="form-text">Al iniciar sesión, el usuario con este rol será redirigido a la página seleccionada.</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label class="form-label fw-semibold">Módulos permitidos</label>
|
||||
@@ -303,6 +337,7 @@ const roles = {
|
||||
document.getElementById('r_slug').value = '';
|
||||
document.getElementById('r_description').value = '';
|
||||
document.getElementById('r_color').value = '#0d6efd';
|
||||
document.getElementById('r_home_page').value = '';
|
||||
document.getElementById('r_error').classList.add('d-none');
|
||||
this._buildModuleGrid([]);
|
||||
document.getElementById('modalRolTitulo').textContent = 'Nuevo Rol';
|
||||
@@ -317,6 +352,7 @@ const roles = {
|
||||
document.getElementById('r_slug').value = r.slug;
|
||||
document.getElementById('r_description').value = r.description ?? '';
|
||||
document.getElementById('r_color').value = r.color ?? '#0d6efd';
|
||||
document.getElementById('r_home_page').value = r.home_page ?? '';
|
||||
document.getElementById('r_error').classList.add('d-none');
|
||||
this._buildModuleGrid(r.modules);
|
||||
document.getElementById('modalRolTitulo').textContent = 'Editar Rol: ' + r.name;
|
||||
@@ -345,17 +381,18 @@ const roles = {
|
||||
},
|
||||
|
||||
async guardar() {
|
||||
const id = document.getElementById('r_id').value;
|
||||
const name = document.getElementById('r_name').value.trim();
|
||||
const slug = document.getElementById('r_slug').value.trim();
|
||||
const desc = document.getElementById('r_description').value.trim();
|
||||
const color = document.getElementById('r_color').value;
|
||||
const errEl = document.getElementById('r_error');
|
||||
const id = document.getElementById('r_id').value;
|
||||
const name = document.getElementById('r_name').value.trim();
|
||||
const slug = document.getElementById('r_slug').value.trim();
|
||||
const desc = document.getElementById('r_description').value.trim();
|
||||
const color = document.getElementById('r_color').value;
|
||||
const homePage = document.getElementById('r_home_page').value.trim() || null;
|
||||
const errEl = document.getElementById('r_error');
|
||||
errEl.classList.add('d-none');
|
||||
|
||||
const modules = [...document.querySelectorAll('#r_modules_grid input:checked')].map(el => el.value);
|
||||
|
||||
const body = { name, slug, description: desc, color, modules };
|
||||
const body = { name, slug, description: desc, color, home_page: homePage, modules };
|
||||
if (id) body.id = parseInt(id);
|
||||
|
||||
const res = await fetch('api/lab/save_role.php', {
|
||||
|
||||
Reference in New Issue
Block a user