SW/purchase/index.php

151 lines
6.8 KiB
PHP
Raw Normal View History

2021-05-23 16:23:25 +02:00
<?php
//General Config File:
require_once('../assets/php/config.php');
//Get Film to purchase:
include_once($prefix.'assets/php/includes/film_dao.php');
include_once($prefix.'assets/php/includes/film.php');
2021-05-24 12:43:25 +02:00
include_once($prefix.'assets/php/includes/cinema_dao.php');
2021-05-23 16:23:25 +02:00
include_once($prefix.'assets/php/includes/cinema.php');
2021-05-25 17:02:29 +02:00
include_once($prefix.'assets/php/includes/session_dao.php');
2021-05-24 12:43:25 +02:00
include_once($prefix.'assets/php/includes/session.php');
2021-05-23 16:23:25 +02:00
2021-05-25 12:21:50 +02:00
$TODAY = getdate();
$TODAY = "$TODAY[mday]"."-"."$TODAY[mon]"."-"."$TODAY[year]";
2021-05-24 13:38:19 +02:00
$pay = true;
2021-05-23 16:23:25 +02:00
$film = null;
$cinemas = [];
2021-05-24 13:28:35 +02:00
$sessions = [];
2021-05-23 16:23:25 +02:00
if(isset($_GET["film"])){
$filmDAO = new Film_DAO("complucine");
$film = $filmDAO->FilmData($_GET["film"]);
2021-05-24 13:38:19 +02:00
if($film){
$tittle = $film->getTittle();
2021-05-23 16:23:25 +02:00
2021-05-24 13:38:19 +02:00
$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 = '<select name="cinemas">';
foreach($cinemasIT as $value){
if($value == reset($cinemasIT)){
$cinemasListHTML .= '<option value="'.$value["cID"].'" selected>'.$value["NAME"].'</option>';
} else {
$cinemasListHTML .='<option value="'.$value["cID"].'">'.$value["NAME"].'</option>';
}
2021-05-24 10:18:17 +02:00
}
2021-05-24 13:38:19 +02:00
$cinemasListHTML .= '</select>';
} else {
$cinemasListHTML = '<select name="cinemas"><option value="" selected>No hay cines disponibles para esta película.</option></select>';
2021-05-24 10:18:17 +02:00
}
2021-05-24 12:43:25 +02:00
2021-05-24 13:38:19 +02:00
$fiml_id = $film->getId();
$cinema_id = $value["cID"];
2021-05-24 13:28:35 +02:00
2021-05-25 17:02:29 +02:00
$sessionsDAO = new SessionDAO("complucine");
$sessions = $sessionsDAO->getSessions_Film_Cinema($fiml_id, $cinema_id);
//print_r($sessions);
2021-05-24 13:38:19 +02:00
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();
2021-05-25 12:21:50 +02:00
$sessionsDates[$key] = date_format(date_create($value->getDate()), 'j-n-Y');
2021-05-24 13:38:19 +02:00
$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");
2021-05-24 12:43:25 +02:00
2021-05-24 13:38:19 +02:00
$sessionsListHTML = '<select name="sessions">';
foreach ($sessionsIT as $value) {
2021-05-25 12:21:50 +02:00
if($TODAY <= $value["DATE"]){
2021-05-25 17:02:29 +02:00
if($value === reset($sessionsIT)){
$sessionsListHTML .= '<option value="'.$value["sID"].'" selected>Fecha: '.$value["DATE"].' || Hora: '.$value["HOUR"].' || Sala: '.$value["HALL"].'</option>';
2021-05-25 12:21:50 +02:00
} else {
2021-05-25 17:02:29 +02:00
$sessionsListHTML .='<option value="'.$value["sID"].'">Fecha: '.$value["DATE"].' || Hora:'.$value["HOUR"].' || Sala: '.$value["HALL"].'</option>';
2021-05-25 12:21:50 +02:00
}
2021-05-24 13:38:19 +02:00
}
2021-05-24 12:43:25 +02:00
}
2021-05-24 13:38:19 +02:00
$sessionsListHTML .= '</select>';
} else {
$sessionsListHTML = '<select name="sessions"><option value="" selected>No hay sesiones disponibles para esta película.</option></select>';
2021-05-24 12:43:25 +02:00
}
2021-05-24 13:28:35 +02:00
2021-05-24 13:38:19 +02:00
$session_id = $value["sID"];
$hall_id = $value["HALL"];
2021-05-25 12:21:50 +02:00
$date_ = $value["DATE"];
$hour_ = $value["HOUR"];
2021-05-23 16:23:25 +02:00
2021-05-24 13:38:19 +02:00
//Reply: Depends on whether the purchase is to be made from a selected movie or a cinema.
$reply = '<div class="column left">
2021-05-23 16:23:25 +02:00
<h2>Película seleccionada: '.str_replace('_', ' ', $tittle).'</h2><hr />
<div class="image"><img src="'.$prefix.'img/films/'.$tittle.'.jpg" alt="'.$tittle.'" /></div>
2021-05-24 10:18:17 +02:00
<p>Duración: '.$film->getDuration().' minutos</p>
2021-05-23 16:23:25 +02:00
<p>Idioma: '.$film->getLanguage().'</p>
</div>
<div class="column right">
2021-05-24 10:18:17 +02:00
<h2>Seleccione un Cine y una Sesión</h2><hr />
2021-05-25 17:02:29 +02:00
<h3>Cines</h3>
'.$cinemasListHTML.'
<h3>Sesiones</h3>
2021-05-24 12:43:25 +02:00
'.$sessionsListHTML.'
2021-05-23 16:23:25 +02:00
</div>
';
2021-05-24 13:38:19 +02:00
} else {
$reply = '<h1>No existe la película.</h1>';
$pay = false;
}
2021-05-24 14:07:18 +02:00
} else if(isset($_GET["cinema"])) {
$reply = '<h1>ESTAMOS TRABAJANDO EN ELLO</h1>';
$pay = false;
} else {
2021-05-24 17:02:40 +02:00
$reply = '<h1>No se ha encontrado película ni cine.</h1>';
2021-05-24 14:07:18 +02:00
$pay = false;
2021-05-24 13:38:19 +02:00
}
2021-05-23 16:23:25 +02:00
2021-05-24 14:07:18 +02:00
2021-05-24 13:38:19 +02:00
//Pay button:
if($pay){
$pay = '<form action="confirm.php" method="post">
<input type="hidden" name="film_id" id="film_id" value='.$fiml_id.' />
<input type="hidden" name="cinema_id" id="cinema_id" value='.$cinema_id.' />
<input type="hidden" name="session_id" id="session_id" value='.$session_id.' />
<input type="hidden" name="hall_id" id="hall_id" value='.$hall_id.' />
2021-05-25 12:21:50 +02:00
<input type="hidden" name="date_" id="date_" value='.$date_.' />
<input type="hidden" name="hour_" id="hour_" value='.$hour_.' />
2021-05-24 13:38:19 +02:00
<input type="submit" id="submit" value="Pagar" />
</form>';
}
2021-05-23 16:23:25 +02:00
//Page-specific content:
$section = '<!-- Purchase -->
<section id="purchase">
<div class="row">
2021-05-24 10:18:17 +02:00
<section class="code purchase">
2021-05-23 16:23:25 +02:00
'.$reply.'
</section>
2021-05-24 13:28:35 +02:00
<section class="code purchase">
2021-05-24 13:38:19 +02:00
'.$pay.'
2021-05-24 13:28:35 +02:00
</section>
2021-05-23 16:23:25 +02:00
</div>
</section>
';
//General page content:
require RAIZ_APP.'/HTMLtemplate.php';
?>