diff --git a/assets/js/promotions.js b/assets/js/promotions.js index 782eaf0..ce59d65 100644 --- a/assets/js/promotions.js +++ b/assets/js/promotions.js @@ -1,4 +1,6 @@ -window.onload = function (promotions) { +window.onload = function () { + var promos = document.getElementById("promotions").value; + console.log(promos); // Promociones (Cambiar por el contenido del array "promotions") const IMAGENES = [ '../img/promos/promo_vuelve.jpg', diff --git a/assets/php/HTMLtemplate.php b/assets/php/HTMLtemplate.php index 9c7a654..1746700 100644 --- a/assets/php/HTMLtemplate.php +++ b/assets/php/HTMLtemplate.php @@ -29,6 +29,11 @@ print_footer(); ?> + + + print_scripts(); + ?> \ No newline at end of file diff --git a/assets/php/includes/film_dao.php b/assets/php/includes/film_dao.php index 9b4f77c..35d4c06 100644 --- a/assets/php/includes/film_dao.php +++ b/assets/php/includes/film_dao.php @@ -120,6 +120,24 @@ return $cinemas; } + + //Get sessions associated with a film. + public function getSessions($id){ + include_once('session_dao.php'); + $session = new SessionDAO("complucine"); + + $sql = sprintf( " SELECT DISTINCT * FROM session WHERE session.id in + (SELECT session.id FROM session JOIN film ON session.idfilm = film.id WHERE film.id = '%d'); ", $id); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + $sessions = null; + while($fila = $resul->fetch_assoc()){ + $sessions[] = $session->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]); + } + $resul->free(); + + return $sessions; + } //Create a new film Data Transfer Object. public function loadFilm($id, $tittle, $duration, $language,$description, $img){ diff --git a/assets/php/includes/session_dao.php b/assets/php/includes/session_dao.php index df86869..e7eb904 100644 --- a/assets/php/includes/session_dao.php +++ b/assets/php/includes/session_dao.php @@ -27,9 +27,12 @@ $sql = sprintf( "SELECT * FROM `session` WHERE id = '%d'", $id ); $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database en sessionData con la id '. $id); - $resul = mysqli_fetch_array($resul); + while($fila=$resul->fetch_assoc()){ + $session = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"], $fila["seats_full"]); + } + $resul->free(); - return $resul; + return $session; } public function filmTittle($idfilm){ @@ -57,6 +60,7 @@ return $session; } + //Returns a query to get all the session's data. public function getAllSessions($hall, $cinema, $date){ $date = date('Y-m-d', strtotime( $date ) ); diff --git a/assets/php/template.php b/assets/php/template.php index bf043e8..55db2fd 100644 --- a/assets/php/template.php +++ b/assets/php/template.php @@ -678,14 +678,18 @@ Contacto | \n"; + } - echo" - - - - + //Print JS scripts: + function print_scripts(){ + $prefix = $this->prefix; + $page = $this->page; + + echo" + + "; - if($page === "FDI-Cines") echo"\n"; + if($page === "FDI-Cines") echo"\n"; } } diff --git a/index.php b/index.php index 5473d1d..a34b1d4 100644 --- a/index.php +++ b/index.php @@ -2,6 +2,8 @@ //General Config File: require_once(__DIR__.'/assets/php/config.php'); + $promotions = "HOLA MUNDO"; + //Page-specific content: $section = '
@@ -13,6 +15,7 @@
+

Promociones

@@ -24,6 +27,7 @@
+ '; //General page content: diff --git a/promotions/index.php b/promotions/index.php index f66c6ff..4fe2cdf 100644 --- a/promotions/index.php +++ b/promotions/index.php @@ -4,11 +4,11 @@ //Specific page content: $section = ' -
+
'.$template->print_promotions().'
-
+ '; //General page content: diff --git a/purchase/confirm.php b/purchase/confirm.php index 15c5adc..401bd7b 100644 --- a/purchase/confirm.php +++ b/purchase/confirm.php @@ -1,3 +1,24 @@ loadSession($_POST["session_id"], $_POST["film_id"], $_POST["hall_id"], $_POST["cinema_id"], $_POST["date_"], $_POST["hour_"], "12", null, null); + $session = $sessionDAO->sessionData($_POST["session_id"]); + + + //Purchase form: + require_once('includes/formPurchase.php'); + $form = new FormPurchase(); + $formHTML = $form->gestiona(); + + //Page-specific content: + $section = '
+

Completar la Compra


+ + '.$formHTML.' +
'; + + //General page content: + require RAIZ_APP.'/HTMLtemplate.php'; ?> \ No newline at end of file diff --git a/purchase/includes/formPurchase.php b/purchase/includes/formPurchase.php new file mode 100644 index 0000000..b48d8e9 --- /dev/null +++ b/purchase/includes/formPurchase.php @@ -0,0 +1,66 @@ + 'error')); + $errorPassword = self::createMensajeError($errores, 'pass', 'span', array('class' => 'error')); + + $html = "
+
".$htmlErroresGlobales."
+ Resumen de la Compra +

Película: ".$session->getIdfilm()."

+

Cine: ".$session->getIdcinema()."

+

Sala: ".$session->getIdhall()."

+

Fecha: ".date_format(date_create($session->getDate()), 'd-m-Y')."

+

Hora: ".$session->getStartTime()."

+

Precio: ".$session->getSeatPrice()."€

+ Datos Bancarios +
".$errorNombre."
+
+
+ + +
+
"; + + return $html; + } + + protected function procesaFormulario($datos){ + $result = array(); + + //$nombre = $this->test_input($datos['name']) ?? null; + $nombre = $datos['name'] ?? null; + $nombre = strtolower($nombre); + if ( empty($nombre) || mb_strlen($nombre) < 3 || mb_strlen($nombre) > 15 ) { + $result['name'] = "El nombre tiene que tener\n una longitud de al menos\n 3 caracteres\n y menos de 15 caracteres."; + } + + //$password = $this->test_input($datos['pass']) ?? null; + $password = $datos['pass'] ?? null; + if ( empty($password) || mb_strlen($password) < 4 ) { + $result['pass'] = "El password tiene que tener\n una longitud de al menos\n 4 caracteres."; + } + + if (count($result) === 0) { + $result[] = "La compra aun está en desarrollo. Vuelva en unos días."; + } + + return $result; + } +} +?> \ No newline at end of file diff --git a/purchase/index copy.php b/purchase/index copy.php new file mode 100644 index 0000000..02eadce --- /dev/null +++ b/purchase/index copy.php @@ -0,0 +1,148 @@ +FilmData($_GET["film"]); + if($film){ + $tittle = $film->getTittle(); + + $cinemas = $filmDAO->getCinemas($_GET["film"]); + if(!empty($cinemas)){ + $cinemasNames = new ArrayIterator(array()); + $cinemasIDs = new ArrayIterator(array()); + foreach($cinemas as $key=>$value){ + $cinemasIDs[$key] = $value->getId(); + $cinemasNames[$key] = $value->getName(); + } + $cinemasIT = new MultipleIterator(MultipleIterator::MIT_KEYS_ASSOC); + $cinemasIT->attachIterator($cinemasIDs, "cID"); + $cinemasIT->attachIterator($cinemasNames, "NAME"); + + $cinemasListHTML = ''; + } else { + $cinemasListHTML = ''; + } + + $fiml_id = $film->getId(); + $cinema_id = $value["cID"]; + + $cinemaDAO = new Cinema_DAO("complucine"); + $sessions = $cinemaDAO->getSessions($value["cID"]); + if(!empty($sessions)){ + $sessionsDates = new ArrayIterator(array()); + $sessionsStarts = new ArrayIterator(array()); + $sessionsHalls = new ArrayIterator(array()); + $sessionsIDs = new ArrayIterator(array()); + foreach($sessions as $key=>$value){ + $sessionsIDs[$key] = $value->getId(); + $sessionsDates[$key] = date_format(date_create($value->getDate()), 'j-n-Y'); + $sessionsHalls[$key] = $value->getIdhall(); + $sessionsStarts[$key] = $value->getStartTime(); + } + $sessionsIT = new MultipleIterator(MultipleIterator::MIT_KEYS_ASSOC); + $sessionsIT->attachIterator($sessionsIDs, "sID"); + $sessionsIT->attachIterator($sessionsDates, "DATE"); + $sessionsIT->attachIterator($sessionsHalls, "HALL"); + $sessionsIT->attachIterator($sessionsStarts, "HOUR"); + + $sessionsListHTML = ''; + } else { + $sessionsListHTML = ''; + } + + $session_id = $value["sID"]; + $hall_id = $value["HALL"]; + $date_ = $value["DATE"]; + $hour_ = $value["HOUR"]; + + //Reply: Depends on whether the purchase is to be made from a selected movie or a cinema. + $reply = '
+

Película seleccionada: '.str_replace('_', ' ', $tittle).'


+
'.$tittle.'
+

Duración: '.$film->getDuration().' minutos

+

Idioma: '.$film->getLanguage().'

+
+
+

Seleccione un Cine y una Sesión


+

Cines

+ '.$cinemasListHTML.'
+

Sesiones

+ '.$sessionsListHTML.' +
+ '; + } else { + $reply = '

No existe la película.

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

ESTAMOS TRABAJANDO EN ELLO

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

No se ha encontrado película ni cine.

'; + $pay = false; + } + + + //Pay button: + if($pay){ + $pay = '
+ + + + + + + +
'; + } + //Page-specific content: + $section = ' +
+
+
+ '.$reply.' +
+
+ '.$pay.' +
+
+
+ '; + + //General page content: + require RAIZ_APP.'/HTMLtemplate.php'; +?> diff --git a/purchase/index.php b/purchase/index.php index 61edcba..2641f9f 100644 --- a/purchase/index.php +++ b/purchase/index.php @@ -9,6 +9,9 @@ include_once($prefix.'assets/php/includes/cinema.php'); include_once($prefix.'assets/php/includes/session.php'); + $TODAY = getdate(); + $TODAY = "$TODAY[mday]"."-"."$TODAY[mon]"."-"."$TODAY[year]"; + $pay = true; $film = null; $cinemas = []; @@ -47,8 +50,7 @@ $fiml_id = $film->getId(); $cinema_id = $value["cID"]; - $cinemaDAO = new Cinema_DAO("complucine"); - $sessions = $cinemaDAO->getSessions($value["cID"]); + $sessions = $filmDAO->getSessions($_GET["film"]); if(!empty($sessions)){ $sessionsDates = new ArrayIterator(array()); $sessionsStarts = new ArrayIterator(array()); @@ -56,7 +58,7 @@ $sessionsIDs = new ArrayIterator(array()); foreach($sessions as $key=>$value){ $sessionsIDs[$key] = $value->getId(); - $sessionsDates[$key] = $value->getDate(); + $sessionsDates[$key] = date_format(date_create($value->getDate()), 'j-n-Y'); $sessionsHalls[$key] = $value->getIdhall(); $sessionsStarts[$key] = $value->getStartTime(); } @@ -68,10 +70,12 @@ $sessionsListHTML = ''; @@ -81,6 +85,8 @@ $session_id = $value["sID"]; $hall_id = $value["HALL"]; + $date_ = $value["DATE"]; + $hour_ = $value["HOUR"]; //Reply: Depends on whether the purchase is to be made from a selected movie or a cinema. $reply = '
@@ -117,6 +123,8 @@ + + '; }