Add files via upload

This commit is contained in:
Fernando Méndez 2021-05-31 12:05:22 +02:00 committed by GitHub
parent af0d9ccd25
commit 425af67eb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 109 additions and 22 deletions

View File

@ -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.");

View File

@ -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')
}
});

View File

@ -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){

View File

@ -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 {
<h3>Sesiones</h3>
'.$sessionsListHTML.'
<h3>Aplicar código promocional<span id="codeValid">&#x2714;</span><span id="codeInvalid">&#x274C;</span></h3>
<input type="text" name="code" id="code" value="" placeholder="Código pormocional" /><pre>'.$errorPromo.'</pre>
<input type="text" name="code" id="code" value="" placeholder="Código pormocional" /><pre>'.$errorCode.'</pre>
</div>';
} else {
$html = '<h1>No existe la película.</h1>';
$pay = false;
}
} else if(isset($_GET["cinema"])) {
$html = '<h1>ESTAMOS TRABAJANDO EN ELLO</h1>';
$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 = '<section id="select_film"><pre>'.$htmlErroresGlobales.'</pre>
<select name="films" id="films"><pre>'.$errorFilm.'</pre>';
if(!empty($films)){
$filmsListHTML .= '<option value="" selected>Selecciona una película</option>';
foreach($filmsIT as $value){
$filmsListHTML .='<option value="'.$value["fID"].'">'.$value["NAME"].'</option>';
}
} else {
foreach($filmsIT as $value){
if($value["cID"] == $film_id){
$filmsListHTML .= '<option value="'.$value["fID"].'" selected>'.$value["NAME"].'</option>';
} else {
$filmsListHTML .='<option value="'.$value["fID"].'">'.$value["NAME"].'</option>';
}
}
}
$filmsListHTML .= '</select>
</section>';
} else {
$filmsListHTML = '<select name="films"><option value="" selected>No hay películas disponibles para este cine.</option></select>';
}
//Reply: Depends on whether the purchase is to be made from a selected movie or a cinema.
$html = '<div class="column left">
<h2>Cine seleccionado: '.$cinema_name.'</h2><hr />
<div class="image"><img src="../img/sala1.jpg" alt="'.$cinema_name.'" /></div>
<p>Dirección: '.$cinema_address.'</p>
<p>Teléfono: '.$cinema_tlf.'</p>
</div>
<div class="column right">
<h2>Seleccione una Película y una Sesión</h2><hr />
<h3>Películas</h3>
'.$filmsListHTML.'
<h3>Sesiones</h3>
<select>
<option value="" selected>Primero selecione una película.</option>
<select>
</div>';
} else {
$html = '<h1>No existe el cine.</h1>';
$pay = false;
}
} else {
$html = '<h1>No se ha encontrado película ni cine.</h1>';
$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.";