From 425af67eb54965b92ee25b5074314d00bad76e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20M=C3=A9ndez?= <45081533+FerMdez@users.noreply.github.com> Date: Mon, 31 May 2021 12:05:22 +0200 Subject: [PATCH] Add files via upload --- assets/js/checkPay.js | 2 +- assets/js/selectTicket.js | 24 +++--- assets/php/includes/cinema_dao.php | 20 ++++- purchase/includes/formSelectCinemaSession.php | 85 ++++++++++++++++--- 4 files changed, 109 insertions(+), 22 deletions(-) diff --git a/assets/js/checkPay.js b/assets/js/checkPay.js index a1e9567..11811db 100644 --- a/assets/js/checkPay.js +++ b/assets/js/checkPay.js @@ -157,7 +157,7 @@ $(document).ready(function() { $("#codeValid").show(); $("#codeInvalid").hide(); code[0].setCustomValidity(""); - } else if(code.val().length > 0 ){ + } else if(code.val().length > 0 && data === "!avaliable" ){ $("#codeValid").hide(); $("#codeInvalid").show(); code[0].setCustomValidity("El código promocional no es válido."); diff --git a/assets/js/selectTicket.js b/assets/js/selectTicket.js index 8e2f1b8..b04ee79 100644 --- a/assets/js/selectTicket.js +++ b/assets/js/selectTicket.js @@ -11,24 +11,28 @@ window.onload = function(){ } } +var select_ = document.getElementById("select_film"); +select_.onchange = function(){ + location.href += "&film=" + $('select[id=films]').val(); +} + // Método 2: enviar una petición AJAX con POST. ==> (NO FUNCIONA, PERO LA IDEA ERA HACERLO ASÍ PARA EVITAR REFRESCAR LA PÁGINA Y LLENAR LA URL) /* $(document).ready(function(){ - $("#select_cinema_session").change(function(){ + $("#select_cinema").change(function(){ var cinema = $('select[id=cinemas]').val(); //console.log($('select[id=cinemas]').val()); + $.ajax({ - url : 'index.php', - type : 'POST', - dataType : 'text', - data : 'cinema='+cinema, - cache : false, - async : false, - success: function(data){ + url : "index.php", + type : "post", + dataType : "html", + data : "", + success: function(response){ + $("#cinemas > option[value="+ cinema +"]").attr("selected", true); console.log(cinema); }, - error: function(response) - { + error: function(response){ console.log(response + ' ==> Error al seleccionar el cine') } }); diff --git a/assets/php/includes/cinema_dao.php b/assets/php/includes/cinema_dao.php index ee0dd92..b590fa2 100644 --- a/assets/php/includes/cinema_dao.php +++ b/assets/php/includes/cinema_dao.php @@ -34,7 +34,7 @@ } //Returns a film data . - public function GetCinema($name,$direction){ + public function GetCinema($name, $direction){ $sql = sprintf( "SELECT * FROM cinema WHERE cinema.name = '%s'AND cinema.direction='%s'", $name,$direction ); $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); return $resul; @@ -102,6 +102,24 @@ return $sessions; } + + //Get films associated with a cinema. + public function getFilms($id){ + include_once('film_dao.php'); + $film = new Film_DAO("complucine"); + + $sql = sprintf( " SELECT DISTINCT * FROM film WHERE film.id in + (SELECT session.idfilm FROM session JOIN cinema ON session.idcinema = cinema.id WHERE cinema.id = '%d'); ", $id); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + $films = null; + while($fila = $resul->fetch_assoc()){ + $films[] = $film->loadFilm($fila["id"], $fila["tittle"], $fila["duration"], $fila["language"], $fila["description"], $fila["img"]); + } + $resul->free(); + + return $films; + } //Create a new film Data Transfer Object. public function loadCinema($id, $name, $direction, $phone){ diff --git a/purchase/includes/formSelectCinemaSession.php b/purchase/includes/formSelectCinemaSession.php index fe9493c..5fc233a 100644 --- a/purchase/includes/formSelectCinemaSession.php +++ b/purchase/includes/formSelectCinemaSession.php @@ -10,10 +10,10 @@ include_once($prefix.'assets/php/includes/session.php'); class FormSelectCinemaSession extends Form { //Atributes: - private $session; // Session of the film to be purchased. - private $cinema; // Cinema of the film to be purchased. - private $hall; // Hall of the film to be purchased. - private $film; // Film to be purchased. + //private $session; // Session of the film to be purchased. + //private $cinema; // Cinema of the film to be purchased. + //private $hall; // Hall of the film to be purchased. + //private $film; // Film to be purchased. private $_TODAY; // Actual date. public function __construct() { @@ -22,9 +22,6 @@ class FormSelectCinemaSession extends Form { $TODAY = getdate(); $this->_TODAY = "$TODAY[mday]"."-"."$TODAY[mon]"."-"."$TODAY[year]"; - - $filmDAO = new Film_DAO("complucine"); - $this->film = $filmDAO->FilmData($_GET["film"]); } @@ -35,6 +32,7 @@ class FormSelectCinemaSession extends Form { // Se generan los mensajes de error, si existen. $htmlErroresGlobales = self::generaListaErroresGlobales($errores); $errorCinema = self::createMensajeError($errores, 'cinemas', 'span', array('class' => 'error')); + $errorFilm = self::createMensajeError($errores, 'films', 'span', array('class' => 'error')); $errorSession = self::createMensajeError($errores, 'sessions', 'span', array('class' => 'error')); $errorCode = self::createMensajeError($errores, 'code', 'span', array('class' => 'error')); @@ -144,16 +142,78 @@ class FormSelectCinemaSession extends Form {

Sesiones

'.$sessionsListHTML.'

Aplicar código promocional

-
'.$errorPromo.'
- +
'.$errorCode.'
'; } else { $html = '

No existe la película.

'; $pay = false; } } else if(isset($_GET["cinema"])) { - $html = '

ESTAMOS TRABAJANDO EN ELLO

'; $pay = false; + $cinemaDAO = new Cinema_DAO("complucine"); + $cinema = $cinemaDAO->cinemaData($_GET["cinema"]); + if($cinema){ + $cinema_name = $cinema->getName(); + $cinema_address = $cinema->getDirection(); + $cinema_tlf = $cinema->getPhone(); + + $films = $cinemaDAO->getFilms($_GET["cinema"]); + $film_id = $_GET["film"]; + if(!empty($films)){ + $filmsNames = new ArrayIterator(array()); + $filmsIDs = new ArrayIterator(array()); + foreach($films as $key=>$value){ + $filmsIDs[$key] = $value->getId(); + $filmsNames[$key] = str_replace('_', ' ', $value->getTittle()); + } + $filmsIT = new MultipleIterator(MultipleIterator::MIT_KEYS_ASSOC); + $filmsIT->attachIterator($filmsIDs, "fID"); + $filmsIT->attachIterator($filmsNames, "NAME"); + + $filmsListHTML = '
'.$htmlErroresGlobales.'
+ +
'; + + } else { + $filmsListHTML = ''; + } + + //Reply: Depends on whether the purchase is to be made from a selected movie or a cinema. + $html = '
+

Cine seleccionado: '.$cinema_name.'


+
'.$cinema_name.'
+

Dirección: '.$cinema_address.'

+

Teléfono: '.$cinema_tlf.'

+
+
+

Seleccione una Película y una Sesión


+

Películas

+ '.$filmsListHTML.' +

Sesiones

+ +
'; + + } else { + $html = '

No existe el cine.

'; + $pay = false; + } } else { $html = '

No se ha encontrado película ni cine.

'; $pay = false; @@ -181,6 +241,11 @@ class FormSelectCinemaSession extends Form { $result['cinemas'] = "Selecciona un cine."; } + $films = $this->test_input($datos['films']) ?? null; + if ( empty($films) ) { + $result['films'] = "Selecciona una película."; + } + $session = $this->test_input($datos['sessions']) ?? null; if ( empty($session) ) { $result['sessions'] = "Selecciona una sesión.";