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 {
'.$errorPromo.'- +
'.$errorCode.''; } else { $html = '
'.$htmlErroresGlobales.'+ +
Dirección: '.$cinema_address.'
+Teléfono: '.$cinema_tlf.'
+