<?php include(__DIR__ . "/../conexion.php"); // Normalizar cédula $cedula_raw = $_GET['cedula'] ?? ''; $cedula = preg_replace('/\D/', '', trim($cedula_raw)); if ($cedula === '') { echo "<div style='padding:20px;color:red;'>No se indicó cédula.</div>"; exit; } // Paginación $pagina = isset($_GET['pagina']) ? max(1,intval($_GET['pagina'])) : 1; $registros_por_pagina = 10; $offset = ($pagina-1)*$registros_por_pagina; // Filtros $fecha_inicio_filtro = $_GET['fecha_inicio'] ?? ''; $fecha_fin_filtro = $_GET['fecha_fin'] ?? ''; $where = "WHERE cedula = '".$conn->real_escape_string($cedula)."'"; if($fecha_inicio_filtro) $where .= " AND fecha_inicio >= '".$conn->real_escape_string($fecha_inicio_filtro)."'"; if($fecha_fin_filtro) $where .= " AND fecha_fin <= '".$conn->real_escape_string($fecha_fin_filtro)."'"; // Total registros (con verificación) $sql_total = "SELECT COUNT(*) as total FROM ausentismo $where"; $total_res = $conn->query($sql_total); $total_registros = ($total_res && $total_res->num_rows) ? intval($total_res->fetch_assoc()['total']) : 0; $total_paginas = $total_registros > 0 ? ceil($total_registros / $registros_por_pagina) : 1; // Obtener ausentismos $sql = "SELECT * FROM ausentismo $where ORDER BY fecha_registro DESC LIMIT $offset,$registros_por_pagina"; $res = $conn->query($sql); ?> <!DOCTYPE html> <html lang="es"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>Listado de Ausentismos</title> <!-- CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css"> <style> .table thead th { background-color: #e6f4ea !important; /* Verde pastel muy suave */ color: #3e4a3e !important; /* Gris verdoso elegante */ font-weight: 600; border-bottom: 2px solid #2d7a2e !important; /* Verde institucional */ } .table tbody tr:hover { background-color: #f2f7f2; } #visorArchivo { width: 100%; height: 600px; border:1px solid #ddd; border-radius: 8px; } .list-group-item { cursor: pointer; } .list-group-item:hover { background: #f5f5f5; } /* Panel de anexos */ .anexos-panel { border:1px solid #e9ecef; border-radius:6px; background:#fafafa; } .anexos-panel .panel-head { padding:6px 10px; border-bottom:1px solid #eee; display:flex; justify-content:space-between; align-items:center; } .anexos-panel .panel-body { padding:10px; } </style> </head> <body> <div class="container-fluid py-3"> <!-- FILTROS --> <form class="row g-2 mb-3"> <input type="hidden" name="cedula" value="<?= htmlspecialchars($cedula) ?>"> <div class="col-auto"> <input type="date" name="fecha_inicio" class="form-control form-control-sm" value="<?= htmlspecialchars($fecha_inicio_filtro) ?>"> </div> <div class="col-auto"> <input type="date" name="fecha_fin" class="form-control form-control-sm" value="<?= htmlspecialchars($fecha_fin_filtro) ?>"> </div> <div class="col-auto"> <button class="btn btn-sm btn-success"><i class="bi bi-search"></i> Buscar</button> <a href="../ausentismo_publico.php?cedula=<?=urlencode($cedula)?>" class="btn btn-sm btn-warning"> <i class="bi bi-plus-circle"></i> Agregar </a> <a href="../ausentismos/historico_completo.php?cedula=<?=urlencode($cedula)?>" class="btn btn-sm btn-primary"> <i class="bi bi-collection"></i> Histórico </a> </div> </form> <!-- TABLA --> <div class="table-responsive"> <table class="table table-hover table-bordered align-middle"> <thead> <tr> <th>#</th> <th>Fecha Registro</th> <th>Fecha Inicio</th> <th>Fecha Fin</th> <th>Días</th> <th>Tipo Incapacidad</th> <th>EPS</th> <th>Diagnósticos</th> <th>Anexos</th> </tr> </thead> <tbody> <?php if($res && $res->num_rows>0): ?> <?php while($row=$res->fetch_assoc()): ?> <tr> <td><?= htmlspecialchars($row['id']) ?></td> <td><?= htmlspecialchars($row['fecha_registro']) ?></td> <td><?= htmlspecialchars($row['fecha_inicio']) ?></td> <td><?= htmlspecialchars($row['fecha_fin']) ?></td> <td><?= htmlspecialchars($row['dias']) ?></td> <td><?= htmlspecialchars($row['tipo_incapacidad']) ?></td> <td><?= htmlspecialchars($row['eps']) ?></td> <td><?= htmlspecialchars($row['diagnosticos'] ?? '') ?></td> <!-- COLUMNA ANEXOS --> <td> <?php // Anexos posibles $archivos = [ "certificado" => "Certificado", "epicrisis" => "Epicrisis", "furips" => "FURIPS", "registro_civil" => "Registro Civil" ]; // Verificar anexos $hay = false; foreach ($archivos as $campo => $titulo) { if (!empty($row[$campo])) { $hay = true; break; } } if (!$hay) { echo "<small class='text-muted'>Sin anexos</small>"; } else { $unique = "anexos_" . preg_replace('/\D/','', $row['id']); ?> <button class="btn btn-sm btn-outline-secondary anexos-toggle" type="button" data-bs-toggle="collapse" data-bs-target="#<?= $unique ?>"> <i class="bi bi-folder2-open icono-anexo"></i> Ver Anexos </button> <div class="collapse mt-2" id="<?= $unique ?>"> <div class="anexos-panel"> <div class="panel-head"> <div><strong>Anexos</strong></div> <div> <button type="button" class="btn btn-sm btn-outline-danger cerrar-anexos" data-target="#<?= $unique ?>" title="Cerrar anexos"> <i class="bi bi-x-lg"></i> </button> </div> </div> <div class="panel-body"> <div class="d-grid gap-1"> <?php foreach ($archivos as $campo => $titulo): ?> <?php if (!empty($row[$campo])): ?> <a href="ver_anexo.php?id=<?=intval($row['id'])?>&campo=<?=$campo?>" target="_blank" class="btn btn-sm btn-outline-primary text-start"> <i class="bi bi-file-earmark"></i> <?=$titulo?> </a> <?php endif; ?> <?php endforeach; ?> </div> </div> </div> </div> <?php } ?> </td> </tr> <?php endwhile; ?> <?php else: ?> <tr><td colspan="9" class="text-center text-muted">No hay registros.</td></tr> <?php endif; ?> </tbody> </table> </div> <!-- PAGINACIÓN --> <?php if($total_paginas>1): ?> <nav> <ul class="pagination pagination-sm"> <?php for($p=1;$p<=$total_paginas;$p++): ?> <li class="page-item <?= $p==$pagina?'active':'' ?>"> <a class="page-link" href="?cedula=<?= urlencode($cedula) ?>&fecha_inicio=<?= urlencode($fecha_inicio_filtro) ?>&fecha_fin=<?= urlencode($fecha_fin_filtro) ?>&pagina=<?= $p ?>"> <?= $p ?> </a> </li> <?php endfor; ?> </ul> </nav> <?php endif; ?> </div> <!-- JS --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script> // Control de iconos y cierre manual (function(){ document.querySelectorAll('.anexos-toggle').forEach(btn => { const target = btn.dataset.bsTarget; const collapseEl = document.querySelector(target); if (!collapseEl) return; collapseEl.addEventListener('show.bs.collapse', () => { btn.querySelector('.icono-anexo').classList.replace('bi-folder2-open','bi-folder-symlink'); }); collapseEl.addEventListener('hide.bs.collapse', () => { btn.querySelector('.icono-anexo').classList.replace('bi-folder-symlink','bi-folder2-open'); }); }); document.querySelectorAll('.cerrar-anexos').forEach(b => { b.addEventListener('click', () => { const target = b.dataset.target; const el = document.querySelector(target); bootstrap.Collapse.getOrCreateInstance(el).hide(); }); }); })(); </script> </body> </html>