diff --git a/app/controllers/administrador.php b/app/controllers/administrador.php
index b88f283..19d840c 100644
--- a/app/controllers/administrador.php
+++ b/app/controllers/administrador.php
@@ -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));
diff --git a/app/controllers/bitacoras.php b/app/controllers/bitacoras.php
index d46b819..7e5dbc5 100644
--- a/app/controllers/bitacoras.php
+++ b/app/controllers/bitacoras.php
@@ -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';
}
@@ -56,4 +107,11 @@ function miAcceso()
}
include __DIR__ . '/../../views/bitacoras/bitacora_usuario.php';
+}
+
+function bitacoraUsuarios()
+{
+
+
+ include __DIR__ . '/../../views/admin/bitacora_usuarios.php';
}
\ No newline at end of file
diff --git a/app/helpers/bitacoras.php b/app/helpers/bitacoras.php
index 38f70a2..58c50e0 100644
--- a/app/helpers/bitacoras.php
+++ b/app/helpers/bitacoras.php
@@ -1,28 +1,36 @@
+
+
+
🏪 Registro de Agencias
+
+
+
+
+
+
+ | ID |
+ Nombre |
+ Acción |
+ Registrada por |
+ Fecha |
+
+
+
+
+
+ | = htmlspecialchars($r['id_agencia'] ?? '') ?> |
+ = htmlspecialchars(decrypt($r['nombre'] ?? '')) ?> |
+ = htmlspecialchars($r['accion'] ?? '') ?> |
+ = htmlspecialchars(decrypt($r['realizado_por'] ?? '')) ?> |
+ = htmlspecialchars($r['fecha'] ? $r['fecha']->format('Y-m-d H:i:s') : '') ?> |
+
+
+
+
+
+
+
+
+