172 lines
10 KiB
PHP
172 lines
10 KiB
PHP
<?php
|
|
require_once 'config/database.php';
|
|
require_once 'includes/header.php';
|
|
|
|
// Filtros básicos
|
|
$type_filter = $_GET['type'] ?? '';
|
|
$search = $_GET['search'] ?? '';
|
|
|
|
try {
|
|
$query = "SELECT d.*, u.name as user_name FROM documents d LEFT JOIN users u ON d.uploaded_by = u.id WHERE 1=1";
|
|
$params = [];
|
|
|
|
if ($type_filter) {
|
|
$query .= " AND d.type = :type";
|
|
$params['type'] = $type_filter;
|
|
}
|
|
|
|
if ($search) {
|
|
$query .= " AND (d.reference_number LIKE :search OR d.title LIKE :search OR d.description LIKE :search)";
|
|
$params['search'] = "%$search%";
|
|
}
|
|
|
|
$query .= " ORDER BY d.created_at DESC";
|
|
|
|
$stmt = $db->prepare($query);
|
|
$stmt->execute($params);
|
|
$documents = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
$error = "Error al cargar los documentos.";
|
|
}
|
|
?>
|
|
|
|
<div class="mb-8 flex flex-col md:flex-row md:justify-between md:items-end gap-4 animate-fade-in">
|
|
<div>
|
|
<h1 class="text-3xl font-bold text-slate-800 tracking-tight">Archivos y Expedientes</h1>
|
|
<p class="text-slate-500 mt-2">Consulta y gestiona el archivo digital de la dirección.</p>
|
|
</div>
|
|
|
|
<?php if(hasRole(['superadmin', 'admin', 'supervisor'])): ?>
|
|
<a href="document_add.php" class="bg-primary hover:bg-slate-800 text-white px-6 py-2.5 rounded-xl font-bold text-sm tracking-wider uppercase transition-all shadow-lg hover:shadow-xl hover:-translate-y-0.5 flex items-center justify-center gap-2">
|
|
<i class="fas fa-file-upload"></i> Registrar Oficio
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<!-- Filtros -->
|
|
<div class="bg-white p-4 rounded-2xl shadow-sm border border-slate-100 mb-6 animate-fade-in-delayed">
|
|
<form method="GET" class="flex flex-col md:flex-row gap-4">
|
|
<div class="flex-1">
|
|
<div class="relative">
|
|
<div class="absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none">
|
|
<i class="fas fa-search text-slate-400"></i>
|
|
</div>
|
|
<input type="text" name="search" value="<?= htmlspecialchars($search) ?>" placeholder="Buscar por referencia, asunto o descripción..."
|
|
class="block w-full pl-11 pr-3 py-2.5 border border-slate-300 rounded-xl focus:ring-accent focus:border-accent text-sm bg-slate-50 text-slate-800 transition-colors shadow-inner font-medium">
|
|
</div>
|
|
</div>
|
|
<div class="md:w-56">
|
|
<select name="type" class="block w-full px-4 py-2.5 border border-slate-300 rounded-xl focus:ring-accent focus:border-accent text-sm bg-slate-50 text-slate-800 transition-colors shadow-inner font-medium">
|
|
<option value="">Todos los tipos</option>
|
|
<option value="entrada" <?= $type_filter == 'entrada' ? 'selected' : '' ?>>Entrada (Recibidos)</option>
|
|
<option value="salida" <?= $type_filter == 'salida' ? 'selected' : '' ?>>Salida (Emitidos)</option>
|
|
<option value="archivo_interno" <?= $type_filter == 'archivo_interno' ? 'selected' : '' ?>>Archivo Interno</option>
|
|
</select>
|
|
</div>
|
|
<button type="submit" class="px-6 py-2.5 bg-slate-800 hover:bg-slate-900 text-white font-bold text-sm uppercase tracking-wider rounded-xl transition-colors shadow-md">
|
|
Filtrar
|
|
</button>
|
|
<?php if($search || $type_filter): ?>
|
|
<a href="documents.php" class="px-6 py-2.5 bg-red-50 hover:bg-red-100 text-red-600 font-bold text-sm uppercase tracking-wider rounded-xl transition-colors border border-red-200 text-center">
|
|
Limpiar
|
|
</a>
|
|
<?php endif; ?>
|
|
</form>
|
|
</div>
|
|
|
|
<?php if (isset($_SESSION['success'])): ?>
|
|
<div class="bg-emerald-50 border-l-4 border-emerald-500 p-4 mb-6 rounded-r-lg shadow-sm">
|
|
<p class="text-sm text-emerald-700 font-medium"><?= htmlspecialchars($_SESSION['success']); unset($_SESSION['success']); ?></p>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if (isset($_SESSION['error'])): ?>
|
|
<div class="bg-red-50 border-l-4 border-red-500 p-4 mb-6 rounded-r-lg shadow-sm">
|
|
<p class="text-sm text-red-700 font-medium"><?= htmlspecialchars($_SESSION['error']); unset($_SESSION['error']); ?></p>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="bg-white rounded-2xl shadow-sm border border-slate-100 overflow-hidden animate-fade-in-delayed">
|
|
<div class="overflow-x-auto">
|
|
<table class="w-full text-left border-collapse">
|
|
<thead>
|
|
<tr>
|
|
<th class="px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider bg-slate-50 border-b border-slate-100">Referencia / Expediente</th>
|
|
<th class="px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider bg-slate-50 border-b border-slate-100">Asunto</th>
|
|
<th class="px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider bg-slate-50 border-b border-slate-100">Clasificación</th>
|
|
<th class="px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider bg-slate-50 border-b border-slate-100">Registrado por</th>
|
|
<th class="px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider bg-slate-50 border-b border-slate-100 text-right">Acciones</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-slate-100">
|
|
<?php if(empty($documents)): ?>
|
|
<tr>
|
|
<td colspan="5" class="px-6 py-16 text-center">
|
|
<div class="flex flex-col items-center justify-center text-slate-300">
|
|
<i class="fas fa-folder-open text-6xl mb-4 text-slate-200"></i>
|
|
<p class="text-lg font-bold text-slate-400">No se encontraron documentos.</p>
|
|
<p class="text-sm text-slate-400 mt-1">Ajusta los filtros o registra un nuevo oficio.</p>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach($documents as $doc): ?>
|
|
<tr class="hover:bg-slate-50 transition-colors group">
|
|
<td class="px-6 py-4">
|
|
<span class="inline-flex items-center gap-2 font-bold text-slate-800">
|
|
<i class="fas fa-file-pdf text-red-500 text-lg group-hover:scale-110 transition-transform"></i>
|
|
<?= htmlspecialchars($doc['reference_number']) ?>
|
|
</span>
|
|
<div class="text-[10px] text-slate-400 mt-1 uppercase font-bold tracking-widest flex items-center gap-1">
|
|
<i class="far fa-calendar-alt"></i> <?= date('d/m/Y', strtotime($doc['created_at'])) ?>
|
|
<i class="far fa-clock ml-2"></i> <?= date('H:i', strtotime($doc['created_at'])) ?>
|
|
</div>
|
|
</td>
|
|
<td class="px-6 py-4 max-w-[200px] md:max-w-xs">
|
|
<p class="text-sm text-slate-800 font-bold truncate" title="<?= htmlspecialchars($doc['title']) ?>"><?= htmlspecialchars($doc['title']) ?></p>
|
|
<p class="text-xs text-slate-500 mt-1 line-clamp-2 leading-relaxed" title="<?= htmlspecialchars($doc['description']) ?>"><?= htmlspecialchars($doc['description']) ?></p>
|
|
</td>
|
|
<td class="px-6 py-4">
|
|
<?php
|
|
$typeClasses = [
|
|
'entrada' => 'bg-emerald-100 text-emerald-800 border-emerald-200',
|
|
'salida' => 'bg-amber-100 text-amber-800 border-amber-200',
|
|
'archivo_interno' => 'bg-slate-100 text-slate-800 border-slate-200'
|
|
];
|
|
$typeLabels = [
|
|
'entrada' => 'Entrada',
|
|
'salida' => 'Salida',
|
|
'archivo_interno' => 'Archivo Interno'
|
|
];
|
|
$class = $typeClasses[$doc['type']] ?? 'bg-gray-100';
|
|
$label = $typeLabels[$doc['type']] ?? ucfirst($doc['type']);
|
|
?>
|
|
<span class="px-3 py-1.5 rounded-full text-[10px] font-bold border <?= $class ?> uppercase tracking-wider shadow-sm flex items-center gap-1.5 w-fit">
|
|
<?php if($doc['type'] == 'entrada') echo '<i class="fas fa-arrow-down"></i>'; ?>
|
|
<?php if($doc['type'] == 'salida') echo '<i class="fas fa-arrow-up"></i>'; ?>
|
|
<?php if($doc['type'] == 'archivo_interno') echo '<i class="fas fa-archive"></i>'; ?>
|
|
<?= $label ?>
|
|
</span>
|
|
</td>
|
|
<td class="px-6 py-4">
|
|
<div class="flex items-center gap-2.5">
|
|
<div class="w-7 h-7 rounded-full bg-slate-200 flex items-center justify-center text-xs font-bold text-slate-600 shadow-inner border border-slate-300">
|
|
<?= strtoupper(substr($doc['user_name'] ?? 'S', 0, 1)) ?>
|
|
</div>
|
|
<span class="text-xs font-semibold text-slate-700"><?= htmlspecialchars($doc['user_name'] ?? 'Sistema') ?></span>
|
|
</div>
|
|
</td>
|
|
<td class="px-6 py-4 text-right">
|
|
<a href="actions/document_download.php?id=<?= $doc['id'] ?>" class="inline-flex items-center gap-2 px-4 py-2 bg-slate-800 text-white hover:bg-accent hover:text-white rounded-xl transition-all text-[11px] font-bold uppercase tracking-wider shadow-md hover:shadow-lg hover:-translate-y-0.5">
|
|
<i class="fas fa-download"></i> Descargar
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once 'includes/footer.php'; ?>
|