Avances bitácoras
This commit is contained in:
@@ -500,7 +500,7 @@ function aprobar_agencia()
|
||||
}
|
||||
|
||||
// Actualizar agencia con el ID del administrador
|
||||
$sqlUpdateAgencia = "UPDATE agencias_aduanales SET id_administrador = ? WHERE id_agencia = ?";
|
||||
$sqlUpdateAgencia = "UPDATE agencias_aduanales SET id_administrador = ? WHERE id_agencia = ?";
|
||||
$stmtUpdateAgencia = sqlsrv_query($conn, $sqlUpdateAgencia, [$id_usuario, $id_agencia]);
|
||||
|
||||
if (!$stmtUpdateAgencia) {
|
||||
@@ -520,9 +520,9 @@ function aprobar_agencia()
|
||||
}
|
||||
|
||||
// Actualizar solicitud
|
||||
$sqlUpdate = "UPDATE solicitudes_agencias
|
||||
SET request_status = 'approved', approval_date = GETDATE(), approved_by = ?
|
||||
WHERE request_id = ?";
|
||||
$sqlUpdate = "UPDATE solicitudes_agencias
|
||||
SET request_status = 'approved', approval_date = GETDATE(), approved_by = ?
|
||||
WHERE request_id = ?";
|
||||
$stmtUpdate = sqlsrv_query($conn, $sqlUpdate, [$usuario_id, $id]);
|
||||
|
||||
if (!$stmtUpdate) {
|
||||
@@ -570,6 +570,8 @@ function aprobar_agencia()
|
||||
} catch (Exception $e) {
|
||||
error_log("Error al enviar correo: {$mail->ErrorInfo}");
|
||||
}
|
||||
// Registrar en bitácora
|
||||
registrar_bitacora_agencia($id_agencia, $nombre, 'CREACION', $usuario_id);
|
||||
|
||||
header("Location: /IMPORTADORES/administrador/agenciasActivas");
|
||||
exit;
|
||||
@@ -659,7 +661,7 @@ function guardar_agencia()
|
||||
";
|
||||
|
||||
$paramsAdmin = [$nombre_admin_enc, $correo_admin_enc, $password_hash, $_SESSION['usuario_id']];
|
||||
$stmtAdmin = sqlsrv_query($conn, $sqlInsertAdmin, $paramsAdmin);
|
||||
$stmtAdmin = sqlsrv_query($conn, $sqlInsertAdmin, $paramsAdmin);
|
||||
|
||||
if (!$stmtAdmin) {
|
||||
$errors = sqlsrv_errors();
|
||||
@@ -730,6 +732,9 @@ function guardar_agencia()
|
||||
|
||||
error_log("Transacción confirmada exitosamente");
|
||||
|
||||
// Registrar en bitácora
|
||||
registrar_bitacora_agencia($id_agencia, $nombre_agencia, 'CREACION', $_SESSION['usuario_id']);
|
||||
|
||||
// 7️⃣ Enviar correo (DESPUÉS de confirmar transacción)
|
||||
if (class_exists('PHPMailer\PHPMailer\PHPMailer')) {
|
||||
$mail = new PHPMailer(true);
|
||||
@@ -836,7 +841,7 @@ function suspender()
|
||||
}
|
||||
|
||||
// Obtener el estado actual
|
||||
$sqlEstado = "SELECT activo FROM usuarios_sistema WHERE id_usuario = ?";
|
||||
$sqlEstado = "SELECT activo FROM usuarios_sistema WHERE id_usuario = ?";
|
||||
$stmtEstado = sqlsrv_query($conn, $sqlEstado, [$id]);
|
||||
|
||||
if (!$stmtEstado || !($row = sqlsrv_fetch_array($stmtEstado, SQLSRV_FETCH_ASSOC))) {
|
||||
@@ -847,7 +852,7 @@ function suspender()
|
||||
$nuevoEstado = $row['activo'] ? 0 : 1;
|
||||
|
||||
// Actualizar estado
|
||||
$sqlUpdate = "UPDATE usuarios_sistema SET activo = ? WHERE id_usuario = ?";
|
||||
$sqlUpdate = "UPDATE usuarios_sistema SET activo = ? WHERE id_usuario = ?";
|
||||
$stmtUpdate = sqlsrv_query($conn, $sqlUpdate, [$nuevoEstado, $id]);
|
||||
|
||||
if (!$stmtUpdate) {
|
||||
@@ -879,7 +884,7 @@ function activar()
|
||||
}
|
||||
|
||||
// Obtener el estado actual
|
||||
$sqlEstado = "SELECT activo FROM usuarios_sistema WHERE id_usuario = ?";
|
||||
$sqlEstado = "SELECT activo FROM usuarios_sistema WHERE id_usuario = ?";
|
||||
$stmtEstado = sqlsrv_query($conn, $sqlEstado, [$id]);
|
||||
|
||||
if (!$stmtEstado || !($row = sqlsrv_fetch_array($stmtEstado, SQLSRV_FETCH_ASSOC))) {
|
||||
@@ -890,7 +895,7 @@ function activar()
|
||||
$nuevoEstado = $row['activo'] ? 0 : 1;
|
||||
|
||||
// Actualizar estado
|
||||
$sqlUpdate = "UPDATE usuarios_sistema SET activo = ? WHERE id_usuario = ?";
|
||||
$sqlUpdate = "UPDATE usuarios_sistema SET activo = ? WHERE id_usuario = ?";
|
||||
$stmtUpdate = sqlsrv_query($conn, $sqlUpdate, [$nuevoEstado, $id]);
|
||||
|
||||
if (!$stmtUpdate) {
|
||||
@@ -923,13 +928,13 @@ function reset_password()
|
||||
|
||||
// 🔐 Generar contraseña aleatoria de 10 caracteres
|
||||
$randomPassword = bin2hex(random_bytes(5)); // genera algo como 'a8c4f1b92d'
|
||||
$passwordHash = password_hash($randomPassword, PASSWORD_DEFAULT);
|
||||
$passwordHash = password_hash($randomPassword, PASSWORD_DEFAULT);
|
||||
|
||||
$sqlEmail = "SELECT email FROM usuarios_sistema WHERE id_usuario = ?";
|
||||
$sqlEmail = "SELECT email FROM usuarios_sistema WHERE id_usuario = ?";
|
||||
$stmtEmail = sqlsrv_query($conn, $sqlEmail, [$id]);
|
||||
$row = sqlsrv_fetch_array($stmtEmail, SQLSRV_FETCH_ASSOC);
|
||||
|
||||
$sql = "UPDATE usuarios_sistema SET password_hash = ? WHERE id_usuario = ?";
|
||||
$sql = "UPDATE usuarios_sistema SET password_hash = ? WHERE id_usuario = ?";
|
||||
$stmt = sqlsrv_query($conn, $sql, [$passwordHash, $id]);
|
||||
|
||||
if (!$stmt) {
|
||||
@@ -1001,7 +1006,7 @@ function suspenderAgencia()
|
||||
|
||||
$conn = getConnection();
|
||||
|
||||
$id = $_GET['id'] ?? null;
|
||||
$id = $_GET['id'] ?? null;
|
||||
|
||||
if (!$id || !is_numeric($id)) {
|
||||
header("Location: /IMPORTADORES/administrador/agenciasActivas?error=invalid_id");
|
||||
@@ -1009,7 +1014,7 @@ function suspenderAgencia()
|
||||
}
|
||||
|
||||
// Obtener el estado actual
|
||||
$sqlEstado = "SELECT activo FROM agencias_aduanles WHERE id_usuario = ?";
|
||||
$sqlEstado = "SELECT activo FROM agencias_aduanles WHERE id_usuario = ?";
|
||||
$stmtEstado = sqlsrv_query($conn, $sqlEstado, [$id]);
|
||||
|
||||
if (!$stmtEstado || !($row = sqlsrv_fetch_array($stmtEstado, SQLSRV_FETCH_ASSOC))) {
|
||||
@@ -1020,7 +1025,7 @@ function suspenderAgencia()
|
||||
$nuevoEstado = $row['activo'] ? 0 : 1;
|
||||
|
||||
// Actualizar estado
|
||||
$sqlUpdate = "UPDATE agencias_aduanles SET activo = ? WHERE id_usuario = ?";
|
||||
$sqlUpdate = "UPDATE agencias_aduanles SET activo = ? WHERE id_usuario = ?";
|
||||
$stmtUpdate = sqlsrv_query($conn, $sqlUpdate, [$nuevoEstado, $id]);
|
||||
|
||||
if (!$stmtUpdate) {
|
||||
@@ -1045,10 +1050,9 @@ function configuracion()
|
||||
die("ID de usuario no disponible en la sesión.");
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM informacion_general WHERE id_usuario = ?";
|
||||
$sql = "SELECT * FROM informacion_general WHERE id_usuario = ?";
|
||||
$params = [$id_usuario];
|
||||
|
||||
$stmt = sqlsrv_query($conn, $sql, $params);
|
||||
$stmt = sqlsrv_query($conn, $sql, $params);
|
||||
|
||||
if ($stmt === false) {
|
||||
die(print_r(sqlsrv_errors(), true));
|
||||
|
||||
@@ -11,16 +11,49 @@ function index()
|
||||
|
||||
function sistema()
|
||||
{
|
||||
if (!isset($_SESSION['usuario_id']) || $_SESSION['tipo_usuario'] !== 'super_admin') {
|
||||
header('Location: /IMPORTADORES/login');
|
||||
exit;
|
||||
}
|
||||
|
||||
$conn = getConnection();
|
||||
$sql = "SELECT bl.*, u.nombre
|
||||
FROM bitacora_login bl
|
||||
INNER JOIN usuarios_sistema u
|
||||
ON bl.id_usuario = u.id_usuario
|
||||
ORDER BY fecha DESC";
|
||||
$stmt = sqlsrv_query($conn, $sql);
|
||||
|
||||
$registros = [];
|
||||
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
|
||||
$registros[] = $row;
|
||||
}
|
||||
|
||||
include __DIR__ . '/../../views/bitacoras/bitacora_sistema.php';
|
||||
}
|
||||
|
||||
function sistemaAgencia()
|
||||
{
|
||||
|
||||
include __DIR__ . '/../../views/bitacoras/sistema_agencia.php';
|
||||
}
|
||||
|
||||
function usuarios()
|
||||
{
|
||||
if (!isset($_SESSION['usuario_id']) || $_SESSION['tipo_usuario'] !== 'super_admin') {
|
||||
header('Location: /IMPORTADORES/login');
|
||||
exit;
|
||||
}
|
||||
|
||||
$conn = getConnection();
|
||||
$sql = "SELECT * FROM bitacora_usuarios ORDER BY fecha DESC";
|
||||
$stmt = sqlsrv_query($conn, $sql);
|
||||
|
||||
$registros = [];
|
||||
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
|
||||
$registros[] = $row;
|
||||
}
|
||||
|
||||
include __DIR__ . '/../../views/bitacoras/bitacora_usuarios.php';
|
||||
}
|
||||
|
||||
@@ -36,6 +69,24 @@ function vinculacionesUsuario()
|
||||
|
||||
function agencias()
|
||||
{
|
||||
if (!isset($_SESSION['usuario_id']) || $_SESSION['tipo_usuario'] !== 'super_admin') {
|
||||
header('Location: /IMPORTADORES/login');
|
||||
exit;
|
||||
}
|
||||
|
||||
$conn = getConnection();
|
||||
$sql = "SELECT ba.*, u.nombre
|
||||
FROM bitacora_login ba
|
||||
INNER JOIN usuarios_sistema u
|
||||
ON bl.id_usuario = u.id_usuario
|
||||
ORDER BY fecha DESC";
|
||||
$stmt = sqlsrv_query($conn, $sql);
|
||||
|
||||
$registros = [];
|
||||
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
|
||||
$registros[] = $row;
|
||||
}
|
||||
|
||||
include __DIR__ . '/../../views/bitacoras/bitacora_agencias.php';
|
||||
}
|
||||
|
||||
@@ -57,3 +108,10 @@ function miAcceso()
|
||||
|
||||
include __DIR__ . '/../../views/bitacoras/bitacora_usuario.php';
|
||||
}
|
||||
|
||||
function bitacoraUsuarios()
|
||||
{
|
||||
|
||||
|
||||
include __DIR__ . '/../../views/admin/bitacora_usuarios.php';
|
||||
}
|
||||
@@ -1,28 +1,36 @@
|
||||
<?php
|
||||
|
||||
function registrarBitacora($conn, $idUsuario, $email, $ip, $exito, $detalle) {
|
||||
$sql = "INSERT INTO bitacora_login (id_usuario, email, ip, exito, detalle)
|
||||
VALUES (?, ?, ?, ?, ?)";
|
||||
function registrarBitacora($conn, $idUsuario, $email, $ip, $exito, $detalle)
|
||||
{
|
||||
$sql = "INSERT INTO bitacora_login (id_usuario, email, ip, exito, detalle)
|
||||
VALUES (?, ?, ?, ?, ?)";
|
||||
$params = [$idUsuario, $email, $ip, $exito, $detalle];
|
||||
sqlsrv_query($conn, $sql, $params);
|
||||
}
|
||||
|
||||
function registrar_bitacora_usuario($usuarioId, $accion, $descripcion) {
|
||||
$conn = getConnection();
|
||||
function registrar_bitacora_usuario($usuarioId, $accion, $descripcion)
|
||||
{
|
||||
$conn = getConnection();
|
||||
|
||||
$sql = "INSERT INTO bitacora_usuarios (usuario_id, accion, descripcion)
|
||||
VALUES (?, ?, ?)";
|
||||
$sql = "INSERT INTO bitacora_usuarios (usuario_id, accion, descripcion)
|
||||
VALUES (?, ?, ?)";
|
||||
$params = [$usuarioId, $accion, $descripcion];
|
||||
|
||||
sqlsrv_query($conn, $sql, $params);
|
||||
}
|
||||
|
||||
function registrar_bitacora_agencia($agenciaId, $nombreAgencia, $accion, $idAdmin) {
|
||||
$conn = getConnection();
|
||||
function registrar_bitacora_agencia($agenciaId, $nombreAgencia, $accion, $idAdmin)
|
||||
{
|
||||
$conn = getConnection();
|
||||
|
||||
$sql = "INSERT INTO bitacora_agencias (id_agencia, nombre, accion, realizado_por)
|
||||
VALUES (?, ?, ?, ?)";
|
||||
$params = [$usuarioId, $nombre, $accion, $idAdmin];
|
||||
$sql = "INSERT INTO bitacora_agencias (id_agencia, nombre, accion, realizado_por, fecha)
|
||||
VALUES (?, ?, ?, ?, GETDATE())";
|
||||
$params = [$agenciaId, $nombreAgencia, $accion, $idAdmin];
|
||||
$stmt = sqlsrv_query($conn, $sql, $params);
|
||||
|
||||
sqlsrv_query($conn, $sql, $params);
|
||||
if (!$stmt) {
|
||||
error_log("Error al registrar bitácora de agencia: " . print_r(sqlsrv_errors(), true));
|
||||
}
|
||||
|
||||
sqlsrv_close($conn);
|
||||
}
|
||||
@@ -34,5 +34,47 @@
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="content">
|
||||
<h4 class="mb-4">🏪 Registro de Agencias</h4>
|
||||
|
||||
<div class="card p-3 shadow-sm">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped" id="tabla-registros-agencias">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Nombre</th>
|
||||
<th>Acción</th>
|
||||
<th>Registrada por</th>
|
||||
<th>Fecha</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($registros as $r): ?>
|
||||
<tr>
|
||||
<td><?= htmlspecialchars($r['id_agencia'] ?? '') ?></td>
|
||||
<td><?= htmlspecialchars(decrypt($r['nombre'] ?? '')) ?></td>
|
||||
<td><?= htmlspecialchars($r['accion'] ?? '') ?></td>
|
||||
<td><?= htmlspecialchars(decrypt($r['realizado_por'] ?? '')) ?></td>
|
||||
<td><?= htmlspecialchars($r['fecha'] ? $r['fecha']->format('Y-m-d H:i:s') : '') ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('#tabla-registros-agencias').DataTable({
|
||||
order: [],
|
||||
language: {
|
||||
url: 'https://cdn.datatables.net/plug-ins/1.13.4/i18n/es-ES.json'
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -52,17 +52,17 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($bitacoras as $b): ?>
|
||||
<?php foreach ($registros as $r): ?>
|
||||
<tr>
|
||||
<td><?= htmlspecialchars($b['id_usuario']) ?></td>
|
||||
<td><?= htmlspecialchars($b['nombre']) ?></td>
|
||||
<td><?= htmlspecialchars($b['email']) ?></td>
|
||||
<td><?= htmlspecialchars($b['ip']) ?></td>
|
||||
<td><?= $b['fecha']->format('Y-m-d H:i:s') ?></td>
|
||||
<td><?= htmlspecialchars($r['id_usuario'] ?? '') ?></td>
|
||||
<td><?= htmlspecialchars(decrypt($r['nombre'] ?? '')) ?></td>
|
||||
<td><?= htmlspecialchars($r['email'] ?? '') ?></td>
|
||||
<td><?= htmlspecialchars($r['ip'] ?? '') ?></td>
|
||||
<td><?= $r['fecha']->format('Y-m-d H:i:s') ?></td>
|
||||
<td>
|
||||
<?= $b['exito'] == 1 ? 'Éxito' : 'Fallido' ?>
|
||||
<?= $r['exito'] == 1 ? 'Éxito' : 'Fallido' ?>
|
||||
</td>
|
||||
<td><?= htmlspecialchars($b['detalle']) ?></td>
|
||||
<td><?= htmlspecialchars($r['detalle']) ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
@@ -74,6 +74,7 @@
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('#tabla-logins').DataTable({
|
||||
order: [],
|
||||
language: {
|
||||
url: 'https://cdn.datatables.net/plug-ins/1.13.4/i18n/es-ES.json'
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<link href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css" rel="stylesheet">
|
||||
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
|
||||
<style>
|
||||
body { font-family: 'Segoe UI', sans-serif; background-color: #f4f6f9; }
|
||||
.sidebar { width: 220px; height: 100vh; background-color: #343a40; position: fixed; top: 0; left: 0; padding-top: 56px; z-index: 1040; }
|
||||
@@ -31,32 +34,47 @@
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="content px-4 pt-5 mt-4">
|
||||
<h4>🛠️ Bitácora de Cambios de Usuario</h4>
|
||||
<div class="content">
|
||||
<h4 class="mb-4">🛠️ Cambios de Usuario</h4>
|
||||
|
||||
<table class="table table-hover mt-3 align-middle">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>ID Usuario</th>
|
||||
<th>Acción</th>
|
||||
<th>Descripción</th>
|
||||
<th>Fecha</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($registros as $r): ?>
|
||||
<tr>
|
||||
<td><?= $r['id_bitacora'] ?></td>
|
||||
<td><?= $r['usuario_id'] ?></td>
|
||||
<td><strong><?= htmlspecialchars($r['accion']) ?></strong></td>
|
||||
<td><?= nl2br(htmlspecialchars($r['descripcion'])) ?></td>
|
||||
<td><?= $r['fecha'] instanceof DateTime ? $r['fecha']->format('Y-m-d H:i') : htmlspecialchars($r['fecha']) ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="card p-3 shadow-sm">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped align-middle" id="tabla-bitacora-usuarios">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>ID Usuario</th>
|
||||
<th>Acción</th>
|
||||
<th>Descripción</th>
|
||||
<th>Fecha</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($registros as $r): ?>
|
||||
<tr>
|
||||
<td><?= $r['id_bitacora'] ?></td>
|
||||
<td><?= $r['usuario_id'] ?></td>
|
||||
<td><strong><?= htmlspecialchars($r['accion']) ?></strong></td>
|
||||
<td><?= nl2br(htmlspecialchars($r['descripcion'])) ?></td>
|
||||
<td><?= $r['fecha'] instanceof DateTime ? $r['fecha']->format('Y-m-d H:i') : htmlspecialchars($r['fecha']) ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('#tabla-bitacora-usuarios').DataTable({
|
||||
order: [],
|
||||
language: {
|
||||
url: 'https://cdn.datatables.net/plug-ins/1.13.4/i18n/es-ES.json'
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -84,7 +84,7 @@ $cantidadBitacoras = contarBitacorasDisponibles($permisosBitacoras);
|
||||
function obtenerTextoPermiso($permiso, $tipoUsuario) {
|
||||
$textos = [
|
||||
'registro_accesos' => ($tipoUsuario === 'super_admin') ? 'Registro de accesos' : null,
|
||||
'registro_usuarios' => ($tipoUsuario === 'super_admin') ? 'Registro de usuarios' : null,
|
||||
'registro_usuarios' => ($tipoUsuario === 'super_admin') ? 'Registro de cambios de usuarios' : null,
|
||||
'registro_agencias' => ($tipoUsuario === 'super_admin') ? 'Registro de agencias' : null,
|
||||
'acceso_usuarios_agencias' => ($tipoUsuario === 'admin_agencia' || $tipoUsuario === 'agente_aduanal') ? 'Registros de accesos' : null,
|
||||
'registro_vinculaciones' => ($tipoUsuario === 'admin_agencia' || $tipoUsuario === 'agente_aduanal') ? 'Vinculaciones (Agencia)' : null,
|
||||
|
||||
Reference in New Issue
Block a user