From d10d68f6073be24f75fc5050936391cec54849cc Mon Sep 17 00:00:00 2001 From: Alexeer Date: Wed, 21 May 2025 10:41:17 -0600 Subject: [PATCH] Editar - Insertar info. faltante --- app/controllers/configuracion.php | 63 +++++++++++++++++- informacion_general.txt | 9 +++ views/configuracion/editar.php | 92 +++++++++++++++++++++------ views/solicitud_importacion/crear.php | 28 +++++--- 4 files changed, 162 insertions(+), 30 deletions(-) diff --git a/app/controllers/configuracion.php b/app/controllers/configuracion.php index 15f77f4..f7fc6f1 100644 --- a/app/controllers/configuracion.php +++ b/app/controllers/configuracion.php @@ -29,8 +29,69 @@ function index() function editar() { - include __DIR__ . '/../../views/configuracion/editar.php'; + $conn = getConnection(); + $id_usuario = $_SESSION['usuario_id'] ?? null; + if (!$id_usuario) { + die("ID de usuario no disponible en la sesión."); + } + + // Traer los datos existentes del usuario + $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/editar.php'; +} + +function guardar() +{ + $conn = getConnection(); + $id_usuario = $_SESSION['usuario_id'] ?? null; + + if (!$id_usuario) { + die("ID de usuario no disponible en la sesión."); + } + + // Captura los datos del formulario + $campos = [ + 'clave', 'tipo_identificador', 'curp', 'calle', 'num_exterior', 'num_interior', + 'ciudad', 'colonia', 'pais', 'codigo_postal', 'municipio', 'estado', 'fax', 'observaciones' + ]; + + $sql_parts = []; + $params = []; + + foreach ($campos as $campo) { + if (isset($_POST[$campo]) && $_POST[$campo] !== '') { + $sql_parts[] = "$campo = ?"; + $params[] = $_POST[$campo]; + } + } + + // Si no hay datos que actualizar + if (empty($sql_parts)) { + header("Location: /IMPORTADORES/configuracion"); + exit; + } + + $sql = "UPDATE informacion_general SET " . implode(", ", $sql_parts) . " WHERE id_usuario = ?"; + $params[] = $id_usuario; + + $stmt = sqlsrv_query($conn, $sql, $params); + + if ($stmt === false) { + die(print_r(sqlsrv_errors(), true)); + } + + header("Location: /IMPORTADORES/configuracion/index"); + exit; } function automatizaciones() diff --git a/informacion_general.txt b/informacion_general.txt index 83b5abc..3ce2885 100644 --- a/informacion_general.txt +++ b/informacion_general.txt @@ -21,3 +21,12 @@ CREATE TABLE informacion_general ( observaciones TEXT, FOREIGN KEY (id_usuario) REFERENCES usuarios_sistema(id_usuario) ); + +ALTER TABLE informacion_general +ALTER COLUMN tipo_identificador INT; + +ALTER TABLE informacion_general +ALTER COLUMN num_exterior INT; + +ALTER TABLE informacion_general +ALTER COLUMN codigo_postal INT; \ No newline at end of file diff --git a/views/configuracion/editar.php b/views/configuracion/editar.php index a8c15d0..c008269 100644 --- a/views/configuracion/editar.php +++ b/views/configuracion/editar.php @@ -83,130 +83,154 @@ include __DIR__ . '/../partials/sidebar_configuracion.php';

✏️ Editar Información

-
+
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- + +
@@ -216,6 +240,36 @@ include __DIR__ . '/../partials/sidebar_configuracion.php';
+ \ No newline at end of file diff --git a/views/solicitud_importacion/crear.php b/views/solicitud_importacion/crear.php index 302c812..c65a6fd 100644 --- a/views/solicitud_importacion/crear.php +++ b/views/solicitud_importacion/crear.php @@ -183,20 +183,28 @@ - +
+ +
- +
+ +