Vista información general

This commit is contained in:
2025-05-19 12:18:02 -06:00
parent 35b18f5808
commit 8b1e3a2810
7 changed files with 384 additions and 103 deletions

View File

@@ -1,5 +1,4 @@
<?php
session_start();
require_once __DIR__ . '/../../vendor/autoload.php';
@@ -9,13 +8,11 @@ require_once __DIR__ . '/../helpers/crypto.php';
require_once __DIR__ . '/../helpers/bitacoras.php';
require_once __DIR__ . '/../helpers/env.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
loadEnv();
function dashboard() {
if (!isset($_SESSION['usuario_id']) || $_SESSION['tipo_usuario'] !== 'agente_aduanal') {
header("Location: /IMPORTADORES/login");
@@ -31,8 +28,6 @@ function dashboard() {
include __DIR__ . '/../../views/agentes/dashboard.php';
}
function importadores_activos() {
if (!($_SESSION['usuario_id'] ?? false) || $_SESSION['tipo_usuario'] !== 'agente_aduanal') {
header('Location: /IMPORTADORES/login');
@@ -55,7 +50,6 @@ function importadores_activos() {
include __DIR__ . '/../../views/agentes/importadores_activos.php';
}
function solicitudes_pendientes() {
if (!($_SESSION['usuario_id'] ?? false) || $_SESSION['tipo_usuario'] !== 'agente_aduanal') {
header('Location: /IMPORTADORES/login');
@@ -79,12 +73,8 @@ function solicitudes_pendientes() {
include __DIR__ . '/../../views/agentes/solicitudes_pendientes.php';
}
function aprobar_solicitud()
{
$conn = getConnection();
$id = $_GET['id'] ?? null;
@@ -129,7 +119,7 @@ function aprobar_solicitud()
if (!$stmtInsert) {
die("❌ Error al crear usuario: " . print_r(sqlsrv_errors(), true));
}
// Actualizar solicitud
$sqlUpdate = "UPDATE solicitudes_importadores
SET request_status = 'approved', approval_date = GETDATE(), approved_by = ?
@@ -185,7 +175,6 @@ function aprobar_solicitud()
exit;
}
function activos() {
if (!($_SESSION['usuario_id'] ?? false)) {
@@ -214,7 +203,6 @@ function activos() {
include __DIR__ . '/../../views/agentes/importadores_activos.php';
}
function toggle_estado() {
@@ -252,6 +240,4 @@ function toggle_estado() {
header("Location: /IMPORTADORES/agentes/activos");
exit;
}
}

View File

@@ -5,9 +5,34 @@ require_once __DIR__ . '/../helpers/crypto.php';
function index()
{
$conn = getConnection();
$id_usuario = $_SESSION['usuario_id'] ?? null;
if (!$id_usuario) {
die("ID de usuario no disponible en la sesión.");
}
$sql = "SELECT * FROM informacion_general WHERE id_usuario = ?";
$params = [$id_usuario];
$stmt = sqlsrv_query($conn, $sql, $params);
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
$datos = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
include __DIR__ . '/../../views/configuracion/dashboard_configuracion.php';
}
function editar()
{
include __DIR__ . '/../../views/configuracion/editar.php';
}
function automatizaciones()
{
include __DIR__ . '/../../views/configuracion/automatizaciones.php';

View File

@@ -32,9 +32,10 @@ function validar()
$emailEncrypted = encrypt($email);
// Obtenemos el usuario
$sql = "SELECT id_usuario, nombre, email, password_hash, tipo_usuario, activo
FROM usuarios_sistema
WHERE email = ?";
FROM usuarios_sistema WHERE email = ?";
$stmt = sqlsrv_query($conn, $sql, [$emailEncrypted]);
if ($stmt && $row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
@@ -54,6 +55,38 @@ function validar()
registrarBitacora($conn, $row['id_usuario'], $email, $ip, 1, 'Login exitoso');
// Buscar RFC y teléfono desde solicitudes_importadores
$sqlSolicitudes = "SELECT rfc, phone FROM solicitudes_importadores WHERE email = ?";
$stmtSolicitudes = sqlsrv_query($conn, $sqlSolicitudes, [$email]);
if ($stmtSolicitudes && $solRow = sqlsrv_fetch_array($stmtSolicitudes, SQLSRV_FETCH_ASSOC)) {
// Desencriptar RFC
$rfc = strtoupper(decrypt(trim($solRow['rfc'])));
// Validar teléfono (ej. 123 4567890)
$telefono = trim($solRow['phone']);
if (!preg_match('/^\d{3}\s\d{7}$/', $telefono)) {
$telefono = null; // o puedes dejarlo como ''
}
}
$nombreUsuario = decrypt($row['nombre']);
$sqlCheck = "SELECT COUNT(*) AS total FROM informacion_general WHERE id_usuario = ?";
$stmtCheck = sqlsrv_query($conn, $sqlCheck, [$row['id_usuario']]);
$checkRow = sqlsrv_fetch_array($stmtCheck, SQLSRV_FETCH_ASSOC);
if ($checkRow['total'] == 0) {
$sqlInsert = "INSERT INTO informacion_general (id_usuario, nombre, rfc, telefono, correo)
VALUES (?, ?, ?, ?, ?)";
$paramsInsert = [$row['id_usuario'], $nombreUsuario, $rfc, $telefono, $email];
sqlsrv_query($conn, $sqlInsert, $paramsInsert);
} else {
$sqlUpdate = "UPDATE informacion_general SET rfc = ?, telefono = ? WHERE id_usuario = ?";
$paramsUpdate = [$rfc, $telefono, $row['id_usuario']];
sqlsrv_query($conn, $sqlUpdate, $paramsUpdate);
}
// Redirección por rol
if ($row['tipo_usuario'] === 'importador') {
header('Location: /IMPORTADORES/importadores/dashboard');

View File

@@ -1,27 +1,20 @@
<?php
require_once __DIR__ . '/../../vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once __DIR__ . '/../../config/database.php';
function index() {
include __DIR__ . '/../../views/registro/form.php';
}
require_once __DIR__ . '/../helpers/crypto.php';
require_once __DIR__ . '/../helpers/env.php';
loadEnv();
function enviar() {
// Validar reCAPTCHA
$captchaResponse = $_POST['g-recaptcha-response'] ?? '';
@@ -82,7 +75,6 @@ function enviar() {
die("❌ Archivo inválido. Solo se permiten PDFs.");
}
// Guardar archivo
$nombreArchivo = uniqid() . '_' . basename($archivo['name']);
$rutaDestino = __DIR__ . '/../../storage/opiniones/' . $nombreArchivo;
@@ -98,32 +90,32 @@ function enviar() {
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
}
$mail = new PHPMailer(true);
$mail = new PHPMailer(true);
try {
// Configuración SMTP
$mail->isSMTP();
$mail->Host = 'secure.emailsrvr.com';
$mail->SMTPAuth = true;
$mail->Username = 'noreply@aduanasoft.com.mx';
$mail->Password = $_ENV['SMTP_PASS']; // desde el .env
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
try {
// Configuración SMTP
$mail->isSMTP();
$mail->Host = 'secure.emailsrvr.com';
$mail->SMTPAuth = true;
$mail->Username = 'noreply@aduanasoft.com.mx';
$mail->Password = $_ENV['SMTP_PASS']; // desde el .env
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
// Correo remitente y destinatario
$mail->setFrom('noreply@aduanasoft.com.mx', 'SIIH | AduanaSoft');
$mail->addAddress($email); // destinatario principal
// Correo remitente y destinatario
$mail->setFrom('noreply@aduanasoft.com.mx', 'SIIH | AduanaSoft');
$mail->addAddress($email); // destinatario principal
// Formato y contenido
$mail->CharSet = 'UTF-8';
$mail->isHTML(true);
$mail->Subject = 'Confirmación de solicitud de registro | SIIH';
// Formato y contenido
$mail->CharSet = 'UTF-8';
$mail->isHTML(true);
$mail->Subject = 'Confirmación de solicitud de registro | SIIH';
$fechaRegistro = date('d/m/Y H:i');
// Consulta configuración institucional
$fechaRegistro = date('d/m/Y H:i');
// Consulta configuración institucional
$sqlConf = "SELECT TOP 1 * FROM configuracion_sistema";
$stmtConf = sqlsrv_query($conn, $sqlConf);
$conf = sqlsrv_fetch_array($stmtConf, SQLSRV_FETCH_ASSOC);
@@ -134,43 +126,41 @@ try {
$color1 = explode(',', $conf['colores_primarios'] ?? '#003366,#0055A5')[0];
$color2 = explode(',', $conf['colores_primarios'] ?? '#003366,#0055A5')[1];
$mail->Body = "
<div style='font-family: Segoe UI, sans-serif; background-color: #f4f6f9; padding: 40px;'>
<div style='max-width: 600px; margin: auto; background: #fff; border: 1px solid #ddd; border-radius: 10px; overflow: hidden;'>
<div style='background: linear-gradient(to right, #FFF, $color2); padding: 20px; text-align: center;'>
<img src='http://{$_SERVER['HTTP_HOST']}/IMPORTADORES/public/$logoUrl' alt='Logo $siglas' style='height: 140px;'>
<h2 style='color: #fff; margin-top: 10px;'>Confirmación de Registro</h2>
$mail->Body = "
<div style='font-family: Segoe UI, sans-serif; background-color: #f4f6f9; padding: 40px;'>
<div style='max-width: 600px; margin: auto; background: #fff; border: 1px solid #ddd; border-radius: 10px; overflow: hidden;'>
<div style='background: linear-gradient(to right, #FFF, $color2); padding: 20px; text-align: center;'>
<img src='http://{$_SERVER['HTTP_HOST']}/IMPORTADORES/public/$logoUrl' alt='Logo $siglas' style='height: 140px;'>
<h2 style='color: #fff; margin-top: 10px;'>Confirmación de Registro</h2>
</div>
<div style='padding: 30px; color: #333;'>
<p style='font-size: 16px;'>¡Hola!</p>
<p style='font-size: 15px;'>Tu solicitud de registro ha sido recibida exitosamente en <strong>$nombrePlataforma</strong>.</p>
<hr style='margin: 20px 0;'>
<p><strong>📋 Empresa:</strong> " . htmlspecialchars($_POST['company_name']) . "</p>
<p><strong>📞 Teléfono:</strong> " . htmlspecialchars($telefono) . "</p>
<p><strong>🕓 Fecha de registro:</strong> $fechaRegistro</p>
<hr style='margin: 20px 0;'>
<p style='font-size: 14px;'>Un agente aduanal revisará tu información y te notificará por este medio cuando tu solicitud sea aprobada.</p>
<p style='font-size: 14px;'>Por favor, mantente atento a tu correo (y revisa también tu carpeta de spam o promociones).</p>
<p style='margin-top: 30px; font-size: 13px; color: #888;'>Este es un mensaje automático enviado por el sistema de registro de importadores.</p>
</div>
<div style='background: #f1f1f1; text-align: center; padding: 15px; font-size: 12px; color: #666;'>
&copy; " . date('Y') . " $siglas · Desarrollado por AduanaSoft
</div>
</div>
<div style='padding: 30px; color: #333;'>
<p style='font-size: 16px;'>¡Hola!</p>
<p style='font-size: 15px;'>Tu solicitud de registro ha sido recibida exitosamente en <strong>$nombrePlataforma</strong>.</p>
<hr style='margin: 20px 0;'>
<p><strong>📋 Empresa:</strong> " . htmlspecialchars($_POST['company_name']) . "</p>
<p><strong>📞 Teléfono:</strong> " . htmlspecialchars($telefono) . "</p>
<p><strong>🕓 Fecha de registro:</strong> $fechaRegistro</p>
<hr style='margin: 20px 0;'>
<p style='font-size: 14px;'>Un agente aduanal revisará tu información y te notificará por este medio cuando tu solicitud sea aprobada.</p>
<p style='font-size: 14px;'>Por favor, mantente atento a tu correo (y revisa también tu carpeta de spam o promociones).</p>
<p style='margin-top: 30px; font-size: 13px; color: #888;'>Este es un mensaje automático enviado por el sistema de registro de importadores.</p>
</div>
<div style='background: #f1f1f1; text-align: center; padding: 15px; font-size: 12px; color: #666;'>
&copy; " . date('Y') . " $siglas · Desarrollado por AduanaSoft
</div>
</div>
</div>
";
$mail->send();
} catch (Exception $e) {
error_log("Error al enviar correo: {$mail->ErrorInfo}");
}
";
$mail->send();
} catch (Exception $e) {
error_log("Error al enviar correo: {$mail->ErrorInfo}");
}
include __DIR__ . '/../../views/registro/gracias.php';
}
}