From b04da3bead0d65abe8216cff843ec3837d66d29e Mon Sep 17 00:00:00 2001 From: "maria.ruiz" <zs22016128@estudiantes.uv.mx> Date: Thu, 13 Mar 2025 06:33:21 +0000 Subject: [PATCH] Actualizar Interfaz/verificar_e_insertar_asientos.php --- Interfaz/verificar_e_insertar_asientos.php | 108 ++++++++++----------- 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/Interfaz/verificar_e_insertar_asientos.php b/Interfaz/verificar_e_insertar_asientos.php index 4dde4cd..3ec0fdf 100644 --- a/Interfaz/verificar_e_insertar_asientos.php +++ b/Interfaz/verificar_e_insertar_asientos.php @@ -1,55 +1,53 @@ -<?php -require 'conexionbd.php'; - -$data = json_decode(file_get_contents('php://input'), true); -$artista = $data['artista'] ?? ''; -$dias = $data['dias'] ?? []; -$filas = $data['filas'] ?? 0; -$columnas = $data['columnas'] ?? 0; - -if (empty($artista) || empty($dias) || $filas <= 0 || $columnas <= 0) { - die(json_encode(['error' => 'Faltan parámetros (artista, dias, filas, columnas).'])); -} - -try { - // Verificar si ya existen asientos para el artista y los días especificados - $stmt = $conn->prepare("SELECT COUNT(*) AS total FROM asientos WHERE artista = :artista AND dia IN (" . implode(',', $dias) . ")"); - $stmt->execute([':artista' => $artista]); - $resultado = $stmt->fetch(PDO::FETCH_ASSOC); - - if ($resultado['total'] > 0) { - echo json_encode(['message' => 'Los asientos ya existen en la base de datos.']); - exit; - } - - // Insertar los asientos para cada día - $stmt = $conn->prepare("INSERT INTO asientos (artista, dia, asiento, estado, precio) VALUES (:artista, :dia, :asiento, 'disponible', :precio)"); - - foreach ($dias as $dia) { - for ($i = 1; $i <= $filas; $i++) { - for ($j = 0; $j < $columnas; $j++) { - $asiento = $i . chr(65 + $j); // Ej: 1A, 1B, ..., 10L - $precio = obtenerPrecio($i); // Función para calcular el precio según la fila - $stmt->execute([ - ':artista' => $artista, - ':dia' => $dia, - ':asiento' => $asiento, - ':precio' => $precio - ]); - } - } - } - - echo json_encode(['message' => 'Asientos insertados correctamente.']); -} catch (PDOException $e) { - die(json_encode(['error' => 'Error al insertar los asientos: ' . $e->getMessage()])); -} - -// Función para calcular el precio según la fila -function obtenerPrecio($fila) { - if ($fila >= 1 && $fila <= 3) return 4500; - if ($fila >= 4 && $fila <= 7) return 2600; - if ($fila >= 8 && $fila <= 10) return 1300; - return 0; -} -?> \ No newline at end of file +<?php +require 'conexionbd.php'; + +$data = json_decode(file_get_contents('php://input'), true); +$artista = $data['artista'] ?? ''; +$dias = $data['dias'] ?? []; +$filas = $data['filas'] ?? 0; +$columnas = $data['columnas'] ?? 0; + +if (empty($artista) || empty($dias) || $filas <= 0 || $columnas <= 0) { + die(json_encode(['error' => 'Faltan parámetros (artista, dias, filas, columnas).'])); +} + +try { + $stmt = $conn->prepare("SELECT COUNT(*) AS total FROM asientos WHERE artista = :artista AND dia IN (" . implode(',', $dias) . ")"); + $stmt->execute([':artista' => $artista]); + $resultado = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($resultado['total'] > 0) { + echo json_encode(['message' => 'Los asientos ya existen en la base de datos.']); + exit; + } + + $stmt = $conn->prepare("INSERT INTO asientos (artista, dia, asiento, estado, precio) VALUES (:artista, :dia, :asiento, 'disponible', :precio)"); + + foreach ($dias as $dia) { + for ($i = 1; $i <= $filas; $i++) { + for ($j = 0; $j < $columnas; $j++) { + $asiento = $i . chr(65 + $j); + $precio = obtenerPrecio($i); + $stmt->execute([ + ':artista' => $artista, + ':dia' => $dia, + ':asiento' => $asiento, + ':precio' => $precio + ]); + } + } + } + + echo json_encode(['message' => 'Asientos insertados correctamente.']); +} catch (PDOException $e) { + die(json_encode(['error' => 'Error al insertar los asientos: ' . $e->getMessage()])); +} + +function obtenerPrecio($fila) { + if ($fila >= 1 && $fila <= 3) return 4500; + if ($fila >= 4 && $fila <= 7) return 2600; + if ($fila >= 8 && $fila <= 10) return 1300; + return 0; +} +?> +