Add files via upload
This commit is contained in:
		
							
								
								
									
										187
									
								
								root/purchase/includes/formPurchase-FER_SURFACE-2.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										187
									
								
								root/purchase/includes/formPurchase-FER_SURFACE-2.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,187 @@
 | 
			
		||||
<?php
 | 
			
		||||
include_once($prefix.'assets/php/form.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/hall_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/hall.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/purchase_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/purchase.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/user.php');
 | 
			
		||||
 | 
			
		||||
class FormPurchase 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 $seat;          // Seat of the film to be purchased. 
 | 
			
		||||
    private $row;           // Row of the seat.
 | 
			
		||||
    private $years;         // Actual year.
 | 
			
		||||
    private $months;        // Months of the year.
 | 
			
		||||
    private $_TODAY;         // Actual date.
 | 
			
		||||
 | 
			
		||||
    public function __construct() {
 | 
			
		||||
        parent::__construct('formPurchase');
 | 
			
		||||
 | 
			
		||||
        $sessionDAO = new SessionDAO("complucine");
 | 
			
		||||
        $this->session = $sessionDAO->sessionData($_POST["sessions"]);
 | 
			
		||||
 | 
			
		||||
        $filmDAO = new Film_DAO("complucine");  
 | 
			
		||||
        $this->film = $filmDAO->FilmData($this->session->getIdfilm());
 | 
			
		||||
 | 
			
		||||
        $cinemaDAO = new Cinema_DAO("complucine");  
 | 
			
		||||
        $this->cinema = $cinemaDAO->cinemaData($this->session->getIdcinema());
 | 
			
		||||
 | 
			
		||||
        $hallDAO = new HallDAO("complucine");
 | 
			
		||||
        $this->hall = $hallDAO->HallData($this->session->getIdhall());
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        $rows = $this->hall->getNumRows();
 | 
			
		||||
        $cols = $this->hall->getNumCol();
 | 
			
		||||
        for($i = 0; $i <= $rows; $i++){
 | 
			
		||||
            for($j = 0; $j <= $cols; $j++){
 | 
			
		||||
                $seat = $i.$j;
 | 
			
		||||
                if(isset($_POST["checkbox".$seat])){ $this->seat = $seat; }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $TODAY = getdate();
 | 
			
		||||
        $year = "$TODAY[year]";
 | 
			
		||||
 | 
			
		||||
        $this->_TODAY = "$TODAY[year]-$TODAY[month]-$TODAY[mday] $TODAY[hours]:$TODAY[minutes]:$TODAY[seconds]";
 | 
			
		||||
 | 
			
		||||
        $this->years = array();
 | 
			
		||||
        for($i = $year; $i < $year+10; $i++) array_push($this->years, $i);
 | 
			
		||||
 | 
			
		||||
        $this->months = array();
 | 
			
		||||
        for($i = 1; $i <= 12; $i++) array_push($this->months, $i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function generaCamposFormulario($datos, $errores = array()){
 | 
			
		||||
 | 
			
		||||
        // Se generan los mensajes de error si existen.
 | 
			
		||||
        $htmlErroresGlobales = self::generaListaErroresGlobales($errores);
 | 
			
		||||
        $errorNombre = self::createMensajeError($errores, 'card-holder', 'span', array('class' => 'error'));
 | 
			
		||||
        $errorCardNumber = self::createMensajeError($errores, 'card-number-0', 'span', array('class' => 'error'));
 | 
			
		||||
        $errorCVV = self::createMensajeError($errores, 'card-cvv', 'span', array('class' => 'error'));
 | 
			
		||||
        $errorCardExpirationMonth = self::createMensajeError($errores, 'card-expiration-month', 'span', array('class' => 'error'));
 | 
			
		||||
        $errorCardExpirationYear = self::createMensajeError($errores, 'card-expiration-year', 'span', array('class' => 'error'));
 | 
			
		||||
 | 
			
		||||
        $monthsHTML = "";
 | 
			
		||||
        foreach($this->months as $value){
 | 
			
		||||
            $monthsHTML .= "<option>".$value."</option>";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $yearsHTML = "";
 | 
			
		||||
        foreach($this->years as $value){
 | 
			
		||||
            $yearsHTML .= "<option>".$value."</option>";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if($this->session->getSeatsFull()){
 | 
			
		||||
            $html = "<div class='code info'>
 | 
			
		||||
                       <h2>La sesión está llena, no quedan asientos disponibles.</h2><hr />
 | 
			
		||||
                       <p>Vuelva atrás para selecionar otra sesión.</p>
 | 
			
		||||
                    </div>";
 | 
			
		||||
        } else {
 | 
			
		||||
            $html = "<div class='row'>
 | 
			
		||||
                            <fieldset id='datos_entrada'>
 | 
			
		||||
                                <legend>Resumen de la Compra</legend>
 | 
			
		||||
                                <img src='"."../img/films/".$this->film->getImg()."' alt='".$this->film->getTittle()."' />
 | 
			
		||||
                                <p>Película: ".str_replace('_', ' ', strtoupper($this->film->getTittle()))."</p>
 | 
			
		||||
                                <p>Cine: ".$this->cinema->getName()."</p>
 | 
			
		||||
                                <p>Sala: ".$this->session->getIdhall()."</p>
 | 
			
		||||
                                <p>Asiento: ".$this->seat."</p>
 | 
			
		||||
                                <p>Fecha: ".date_format(date_create($this->session->getDate()), 'd-m-Y')."</p>
 | 
			
		||||
                                <p>Hora: ".$this->session->getStartTime()."</p>
 | 
			
		||||
                                <p>Precio: ".$this->session->getSeatPrice()."€</p>
 | 
			
		||||
                            </fieldset>
 | 
			
		||||
                            <fieldset id='pagar_entrada'><pre>".$htmlErroresGlobales."</pre>
 | 
			
		||||
                                <legend>Datos Bancarios</legend>
 | 
			
		||||
                                <label for='card-holder'>Titular de la Tarjeta:  <span id='cardNameValid'>✔</span><span id='cardNameInvalid'>❌</span></label><pre>".$errorNombre."</pre><br />
 | 
			
		||||
                                    <input type='text' name='card-holder' id='card-holder' class='card-holder' placeholder='NOMBRE APELLIDO1 APELLIDO2' required />
 | 
			
		||||
                                <br />
 | 
			
		||||
                                <label for='card-number'>Número de Tarjeta: <span id='carNumberValid'>✔</span><span id='cardNumerInvalid'>❌</span></label><pre>".$errorCardNumber."</pre><br />
 | 
			
		||||
                                    <input type='num' name='card-number-0' id='card-number-0' class='input-cart-number' placeholder='XXXX' maxlength='4' required />
 | 
			
		||||
                                    <input type='num' name='card-number-1' id='card-number-1' class='input-cart-number' placeholder='XXXX' maxlength='4' required />
 | 
			
		||||
                                    <input type='num' name='card-number-2' id='card-number-2' class='input-cart-number' placeholder='XXXX' maxlength='4' required />
 | 
			
		||||
                                    <input type='num' name='card-number-3' id='card-number-3' class='input-cart-number' placeholder='XXXX' maxlength='4' required />    
 | 
			
		||||
                                <label for='card-cvv'>CVV: <span id='cvvValid'>✔</span><span id='cvvInvalid'>❌</span></label>
 | 
			
		||||
                                    <input type='text' name='card-cvv' id='card-cvv' class='fieldset-cvv' maxlength='3' placeholder='XXX' required /><pre>".$errorCVV."</pre>
 | 
			
		||||
                                <br />
 | 
			
		||||
                                <label for='card-expiration'>Fecha de Expiración:</label><pre>".$errorCardExpirationMonth.$errorCardExpirationYear."</pre><br />
 | 
			
		||||
                                    <select name='card-expiration-month' id='card-expiration-month' required>
 | 
			
		||||
                                    ".$monthsHTML."
 | 
			
		||||
                                    </select>
 | 
			
		||||
                                    <select name='card-expiration-year' id='card-expiration-year' required>
 | 
			
		||||
                                    ".$yearsHTML."
 | 
			
		||||
                                    </select>
 | 
			
		||||
                            </fieldset>
 | 
			
		||||
                            <div class='actions'> 
 | 
			
		||||
                                <input type='hidden' name='sessions' id='sessions' value='".$_POST["sessions"]."' />
 | 
			
		||||
                                <input type='submit' id='submit' value='Pagar' class='primary' />
 | 
			
		||||
                                <input type='reset' id='reset' value='Borrar' />       
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </div>";
 | 
			
		||||
        }
 | 
			
		||||
        return $html;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function procesaFormulario($datos){
 | 
			
		||||
        $result = array();
 | 
			
		||||
        
 | 
			
		||||
        $nombre = $this->test_input($datos['card-holder']) ?? null;
 | 
			
		||||
        $nombre = strtolower($nombre);
 | 
			
		||||
        if ( empty($nombre) ) {
 | 
			
		||||
            $result['card-holder'] = "El nombre no puede estar vacío.";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for($i = 0; $i < 4; $i++){
 | 
			
		||||
            $card_numer = $this->test_input($datos['card-number-'.$i]) ?? null;
 | 
			
		||||
            if ( empty($card_numer) || mb_strlen($card_numer) < 4 ) {
 | 
			
		||||
                $result['card-number-0'] = "La tarjeta debe tener 16 dígitos.";
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $cvv = $this->test_input($datos['card-cvv']) ?? null;
 | 
			
		||||
        if ( empty($cvv) || mb_strlen($cvv) < 3 ) {
 | 
			
		||||
            $result['card-cvv'] = "El CVV debe tener 3 números.";
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        $month = $this->test_input($datos['card-expiration-month']) ?? null;
 | 
			
		||||
        if ( empty($month) ) {
 | 
			
		||||
            $result['card-expiration-month'] = "El mes de expiración no es correcto.";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $year = $this->test_input($datos['card-expiration-year']) ?? null;
 | 
			
		||||
        if ( empty($year) ) {
 | 
			
		||||
            $result['card-expiration-year'] = "El año de expiración no es correcto.";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (count($result) === 0) {
 | 
			
		||||
           if(isset($_SESSION["login"]) && $_SESSION["login"] == true){
 | 
			
		||||
                $purchaseDAO = new PurchaseDAO("complucine");
 | 
			
		||||
                if($purchaseDAO->createPurchase(unserialize($_SESSION["user"])->getId(), $this->session->getId(), $this->session->getIdhall(), $this->cinema->getId(), rand(1, $this->hall->getNumRows()), rand(1, $this->hall->getNumCol()), date("Y-m-d H:i:s"))){
 | 
			
		||||
                    $purchase = new Purchase(unserialize($_SESSION["user"])->getId(), $this->session->getId(), $this->session->getIdhall(), $this->cinema->getId(), rand(1, $this->hall->getNumRows()), rand(1, $this->hall->getNumCol()), strftime("%A %e de %B de %Y a las %H:%M"));
 | 
			
		||||
 | 
			
		||||
                    $_SESSION["purchase"] = serialize($purchase);
 | 
			
		||||
                    $_SESSION["film_purchase"] = serialize($this->film);
 | 
			
		||||
                    $result = "resume.php";
 | 
			
		||||
                } else {
 | 
			
		||||
                    $result[] = "Error al realizar la compra.";
 | 
			
		||||
                }
 | 
			
		||||
           } else {
 | 
			
		||||
            $purchase = new Purchase("null", $this->session->getId(), $this->session->getIdhall(), $this->cinema->getId(), rand(1, $this->hall->getNumRows()), rand(1, $this->hall->getNumCol()), strftime("%A %e de %B de %Y a las %H:%M"));
 | 
			
		||||
                $_SESSION["purchase"] = serialize($purchase);
 | 
			
		||||
                $_SESSION["film_purchase"] = serialize($this->film);
 | 
			
		||||
                $result = "resume.php";
 | 
			
		||||
           }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										230
									
								
								root/purchase/includes/formPurchase-FER_SURFACE-3.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										230
									
								
								root/purchase/includes/formPurchase-FER_SURFACE-3.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,230 @@
 | 
			
		||||
<?php
 | 
			
		||||
include_once($prefix.'assets/php/form.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/hall_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/hall.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/purchase_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/purchase.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/promotion_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/user.php');
 | 
			
		||||
 | 
			
		||||
class FormPurchase extends Form {
 | 
			
		||||
 | 
			
		||||
    //Atributes:
 | 
			
		||||
    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 $seat;          // Seat of the film to be purchased. 
 | 
			
		||||
    private $row;           // Row of the seat.
 | 
			
		||||
    private $col;           // Column of the seat.
 | 
			
		||||
    private $code;          // Promotional code.
 | 
			
		||||
    private $years;         // Actual year.
 | 
			
		||||
    private $months;        // Months of the year.
 | 
			
		||||
    private $_TODAY;        // Actual date.
 | 
			
		||||
 | 
			
		||||
    public function __construct() {
 | 
			
		||||
        parent::__construct('formPurchase');
 | 
			
		||||
 | 
			
		||||
        $sessionDAO = new SessionDAO("complucine");
 | 
			
		||||
        $this->session = $sessionDAO->sessionData($_POST["sessions"]);
 | 
			
		||||
 | 
			
		||||
        $filmDAO = new Film_DAO("complucine");  
 | 
			
		||||
        $this->film = $filmDAO->FilmData($this->session->getIdfilm());
 | 
			
		||||
 | 
			
		||||
        $cinemaDAO = new Cinema_DAO("complucine");  
 | 
			
		||||
        $this->cinema = $cinemaDAO->cinemaData($this->session->getIdcinema());
 | 
			
		||||
 | 
			
		||||
        $hallDAO = new HallDAO("complucine");
 | 
			
		||||
        $this->hall = $hallDAO->HallData($this->session->getIdhall());
 | 
			
		||||
 | 
			
		||||
        $this->seat = array();
 | 
			
		||||
        $this->row = array();
 | 
			
		||||
        $this->col = array();
 | 
			
		||||
        $rows = $this->hall->getNumRows();
 | 
			
		||||
        $cols = $this->hall->getNumCol();
 | 
			
		||||
        for($i = 0; $i <= $rows; $i++){
 | 
			
		||||
            for($j = 0; $j <= $cols; $j++){
 | 
			
		||||
                $seat = $i.$j;
 | 
			
		||||
                if(isset($_POST["checkbox".$seat])){ 
 | 
			
		||||
                    array_push($this->seat, $i."-".$j);
 | 
			
		||||
                    array_push($this->row, $i); 
 | 
			
		||||
                    array_push($this->col, $j); 
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $promoDAO = new Promotion_DAO("complucine");
 | 
			
		||||
        $this->code = intval(0);
 | 
			
		||||
        if(isset($_POST["code"]) && $_POST["code"] !== ""){
 | 
			
		||||
            if($promoDAO->GetPromotion($_POST["code"])->data_seek(0)){
 | 
			
		||||
                $this->code = intval(2);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $TODAY = getdate();
 | 
			
		||||
        $year = "$TODAY[year]";
 | 
			
		||||
 | 
			
		||||
        $this->_TODAY = "$TODAY[year]-$TODAY[month]-$TODAY[mday] $TODAY[hours]:$TODAY[minutes]:$TODAY[seconds]";
 | 
			
		||||
 | 
			
		||||
        $this->years = array();
 | 
			
		||||
        for($i = $year; $i < $year+10; $i++) array_push($this->years, $i);
 | 
			
		||||
 | 
			
		||||
        $this->months = array();
 | 
			
		||||
        for($i = 1; $i <= 12; $i++) array_push($this->months, $i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function generaCamposFormulario($datos, $errores = array()){
 | 
			
		||||
 | 
			
		||||
        // Se generan los mensajes de error si existen.
 | 
			
		||||
        $htmlErroresGlobales = self::generaListaErroresGlobales($errores);
 | 
			
		||||
        $errorNombre = self::createMensajeError($errores, 'card-holder', 'span', array('class' => 'error'));
 | 
			
		||||
        $errorCardNumber = self::createMensajeError($errores, 'card-number-0', 'span', array('class' => 'error'));
 | 
			
		||||
        $errorCVV = self::createMensajeError($errores, 'card-cvv', 'span', array('class' => 'error'));
 | 
			
		||||
        $errorCardExpirationMonth = self::createMensajeError($errores, 'card-expiration-month', 'span', array('class' => 'error'));
 | 
			
		||||
        $errorCardExpirationYear = self::createMensajeError($errores, 'card-expiration-year', 'span', array('class' => 'error'));
 | 
			
		||||
 | 
			
		||||
        $monthsHTML = "";
 | 
			
		||||
        foreach($this->months as $value){
 | 
			
		||||
            $monthsHTML .= "<option>".$value."</option>";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $yearsHTML = "";
 | 
			
		||||
        foreach($this->years as $value){
 | 
			
		||||
            $yearsHTML .= "<option>".$value."</option>";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if($this->session->getSeatsFull()){
 | 
			
		||||
            $html = "<div class='code info'>
 | 
			
		||||
                       <h2>La sesión está llena, no quedan asientos disponibles.</h2><hr />
 | 
			
		||||
                       <p>Vuelva atrás para selecionar otra sesión.</p>
 | 
			
		||||
                    </div>";
 | 
			
		||||
        } else {
 | 
			
		||||
            if(!empty($this->seat)){
 | 
			
		||||
                $seats = "";
 | 
			
		||||
                foreach($this->seat as $value){
 | 
			
		||||
                    $seats .= $value.", ";
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                $promo = "";
 | 
			
		||||
                if($this->code > 0) $promo = "<pre>(Se ha aplicado un descuento por código promocional).</pre>";
 | 
			
		||||
 | 
			
		||||
                $html = "<div class='row'>
 | 
			
		||||
                                <fieldset id='datos_entrada'>
 | 
			
		||||
                                    <legend>Resumen de la Compra</legend>
 | 
			
		||||
                                    <img src='"."../img/films/".$this->film->getImg()."' alt='".$this->film->getTittle()."' />
 | 
			
		||||
                                    <p>Película: ".str_replace('_', ' ', strtoupper($this->film->getTittle()))."</p>
 | 
			
		||||
                                    <p>Cine: ".$this->cinema->getName()."</p>
 | 
			
		||||
                                    <p>Sala: ".$this->session->getIdhall()."</p>
 | 
			
		||||
                                    <p>Asiento(s):".$seats."</p>
 | 
			
		||||
                                    <p>Fecha: ".date_format(date_create($this->session->getDate()), 'd-m-Y')."</p>
 | 
			
		||||
                                    <p>Hora: ".$this->session->getStartTime()."</p>
 | 
			
		||||
                                    <p>Precio Total: ".intval($this->session->getSeatPrice()*count($this->seat)-$this->code)."€ (Precio por asiento: ".$this->session->getSeatPrice()." €)</p>
 | 
			
		||||
                                    <p>".$promo."</p>
 | 
			
		||||
                                </fieldset>
 | 
			
		||||
                                <fieldset id='pagar_entrada'><pre>".$htmlErroresGlobales."</pre>
 | 
			
		||||
                                    <legend>Datos Bancarios</legend>
 | 
			
		||||
                                    <label for='card-holder'>Titular de la Tarjeta:  <span id='cardNameValid'>✔</span><span id='cardNameInvalid'>❌</span></label><pre>".$errorNombre."</pre><br />
 | 
			
		||||
                                        <input type='text' name='card-holder' id='card-holder' class='card-holder' placeholder='NOMBRE APELLIDO1 APELLIDO2' required />
 | 
			
		||||
                                    <br />
 | 
			
		||||
                                    <label for='card-number'>Número de Tarjeta: <span id='carNumberValid'>✔</span><span id='cardNumerInvalid'>❌</span></label><pre>".$errorCardNumber."</pre><br />
 | 
			
		||||
                                        <input type='num' name='card-number-0' id='card-number-0' class='input-cart-number' placeholder='XXXX' maxlength='4' required />
 | 
			
		||||
                                        <input type='num' name='card-number-1' id='card-number-1' class='input-cart-number' placeholder='XXXX' maxlength='4' required />
 | 
			
		||||
                                        <input type='num' name='card-number-2' id='card-number-2' class='input-cart-number' placeholder='XXXX' maxlength='4' required />
 | 
			
		||||
                                        <input type='num' name='card-number-3' id='card-number-3' class='input-cart-number' placeholder='XXXX' maxlength='4' required />    
 | 
			
		||||
                                    <label for='card-cvv'>CVV: <span id='cvvValid'>✔</span><span id='cvvInvalid'>❌</span></label>
 | 
			
		||||
                                        <input type='text' name='card-cvv' id='card-cvv' class='fieldset-cvv' maxlength='3' placeholder='XXX' required /><pre>".$errorCVV."</pre>
 | 
			
		||||
                                    <br />
 | 
			
		||||
                                    <label for='card-expiration'>Fecha de Expiración: <span id='dateValid'>✔</span><span id='dateInvalid'>❌</span></label><pre>".$errorCardExpirationMonth.$errorCardExpirationYear."</pre><br />
 | 
			
		||||
                                        <select name='card-expiration-month' id='card-expiration-month' required>
 | 
			
		||||
                                        ".$monthsHTML."
 | 
			
		||||
                                        </select>
 | 
			
		||||
                                        <select name='card-expiration-year' id='card-expiration-year' required>
 | 
			
		||||
                                        ".$yearsHTML."
 | 
			
		||||
                                        </select>
 | 
			
		||||
                                </fieldset>
 | 
			
		||||
                                <div class='actions'> 
 | 
			
		||||
                                    <input type='hidden' name='sessions' id='sessions' value='".$_POST["sessions"]."' />
 | 
			
		||||
                                    <input type='hidden' name='row' id='row' value='".serialize($this->row)."' />
 | 
			
		||||
                                    <input type='hidden' name='col' id='col' value='".serialize($this->col)."' />
 | 
			
		||||
                                    <input type='submit' id='submit' value='Pagar' class='primary' />
 | 
			
		||||
                                    <input type='reset' id='reset' value='Borrar' />       
 | 
			
		||||
                                </div>
 | 
			
		||||
                            </div>";
 | 
			
		||||
            } else {
 | 
			
		||||
                $html = "<div class='code info'>
 | 
			
		||||
                       <h2>No se ha seleccionado asiento(s).</h2>
 | 
			
		||||
                       <p>Vuelva atrás para selecionar una butaca.</p>
 | 
			
		||||
                       <button id='go-back'>Volver</button>
 | 
			
		||||
                    </div>";
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return $html;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function procesaFormulario($datos){
 | 
			
		||||
        $result = array();
 | 
			
		||||
        
 | 
			
		||||
        $nombre = $this->test_input($datos['card-holder']) ?? null;
 | 
			
		||||
        $nombre = strtolower($nombre);
 | 
			
		||||
        if ( empty($nombre) ) {
 | 
			
		||||
            $result['card-holder'] = "El nombre no puede estar vacío.";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for($i = 0; $i < 4; $i++){
 | 
			
		||||
            $card_numer = $this->test_input($datos['card-number-'.$i]) ?? null;
 | 
			
		||||
            if ( empty($card_numer) || mb_strlen($card_numer) < 4 ) {
 | 
			
		||||
                $result['card-number-0'] = "La tarjeta debe tener 16 dígitos.";
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $cvv = $this->test_input($datos['card-cvv']) ?? null;
 | 
			
		||||
        if ( empty($cvv) || mb_strlen($cvv) < 3 ) {
 | 
			
		||||
            $result['card-cvv'] = "El CVV debe tener 3 números.";
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        $month = $this->test_input($datos['card-expiration-month']) ?? null;
 | 
			
		||||
        //$TODAY = getdate();
 | 
			
		||||
        //$actualMonth = "$TODAY[month]";
 | 
			
		||||
        if ( empty($month) /*|| $month < $actualMonth*/) {
 | 
			
		||||
            $result['card-expiration-month'] = "El mes de expiración no es correcto.";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $year = $this->test_input($datos['card-expiration-year']) ?? null;
 | 
			
		||||
        if ( empty($year) ) {
 | 
			
		||||
            $result['card-expiration-year'] = "El año de expiración no es correcto.";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (count($result) === 0) {
 | 
			
		||||
           if(isset($_SESSION["login"]) && $_SESSION["login"] == true){
 | 
			
		||||
                $purchaseDAO = new PurchaseDAO("complucine");
 | 
			
		||||
                $count = count(unserialize($datos["row"]));
 | 
			
		||||
                $rows =  unserialize($datos["row"]); $cols =  unserialize($datos["col"]);
 | 
			
		||||
                for($i = 0; $i < $count; $i++){
 | 
			
		||||
                    if($purchaseDAO->createPurchase(unserialize($_SESSION["user"])->getId(), $this->session->getId(), $this->session->getIdhall(), $this->cinema->getId(), $rows[$i], $cols[$i], date("Y-m-d H:i:s"))){
 | 
			
		||||
                        $purchase = new Purchase(unserialize($_SESSION["user"])->getId(), $this->session->getId(), $this->session->getIdhall(), $this->cinema->getId(), $datos["row"], $datos["col"], strftime("%A %e de %B de %Y a las %H:%M"));
 | 
			
		||||
 | 
			
		||||
                        $_SESSION["purchase"] = serialize($purchase);
 | 
			
		||||
                        $_SESSION["film_purchase"] = serialize($this->film);
 | 
			
		||||
                        $result = "resume.php";
 | 
			
		||||
                    } else {
 | 
			
		||||
                        $result[] = "Error al realizar la compra.";
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
           } else {
 | 
			
		||||
            $purchase = new Purchase("null", $this->session->getId(), $this->session->getIdhall(), $this->cinema->getId(), $datos["row"], $datos["col"], strftime("%A %e de %B de %Y a las %H:%M"));
 | 
			
		||||
                $_SESSION["purchase"] = serialize($purchase);
 | 
			
		||||
                $_SESSION["film_purchase"] = serialize($this->film);
 | 
			
		||||
                $result = "resume.php";
 | 
			
		||||
           }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										121
									
								
								root/purchase/includes/formPurchase-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								root/purchase/includes/formPurchase-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,121 @@
 | 
			
		||||
<?php
 | 
			
		||||
include_once($prefix.'assets/php/form.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema.php');
 | 
			
		||||
 | 
			
		||||
class FormPurchase extends Form {
 | 
			
		||||
 | 
			
		||||
    //Atributes:
 | 
			
		||||
    private $session;       // Session of the film to be purchased.
 | 
			
		||||
    private $cinema;        // Cinema of the film to be purchased.
 | 
			
		||||
    private $film;          // Film to be purchased.
 | 
			
		||||
    private $years;         // Actual year.
 | 
			
		||||
    private $months;        // Months of the year.
 | 
			
		||||
 | 
			
		||||
    public function __construct() {
 | 
			
		||||
        parent::__construct('formPurchase');
 | 
			
		||||
 | 
			
		||||
        $sessionDAO = new SessionDAO("complucine");
 | 
			
		||||
        $this->session = $sessionDAO->sessionData($_POST["sessions"]);
 | 
			
		||||
 | 
			
		||||
        $filmDAO = new Film_DAO("complucine");  
 | 
			
		||||
        $this->film = $filmDAO->FilmData($this->session->getIdfilm());
 | 
			
		||||
 | 
			
		||||
        $cinemaDAO = new Cinema_DAO("complucine");  
 | 
			
		||||
        $this->cinema = $cinemaDAO->cinemaData($this->session->getIdcinema());
 | 
			
		||||
 | 
			
		||||
        $TODAY = getdate();
 | 
			
		||||
        $year = "$TODAY[year]";
 | 
			
		||||
 | 
			
		||||
        $this->years = array();
 | 
			
		||||
        for($i = $year; $i < $year+10; $i++) array_push($this->years, $i);
 | 
			
		||||
 | 
			
		||||
        $this->months = array();
 | 
			
		||||
        for($i = 1; $i <= 12; $i++) array_push($this->months, $i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function generaCamposFormulario($datos, $errores = array()){
 | 
			
		||||
 | 
			
		||||
        // Se generan los mensajes de error si existen.
 | 
			
		||||
        $htmlErroresGlobales = self::generaListaErroresGlobales($errores);
 | 
			
		||||
        $errorNombre = self::createMensajeError($errores, 'name', 'span', array('class' => 'error'));
 | 
			
		||||
        $errorPassword = self::createMensajeError($errores, 'pass', 'span', array('class' => 'error'));
 | 
			
		||||
 | 
			
		||||
        $monthsHTML = "";
 | 
			
		||||
        foreach($this->months as $value){
 | 
			
		||||
            $monthsHTML .= "<option>".$value."</option>";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $yearsHTML = "";
 | 
			
		||||
        foreach($this->years as $value){
 | 
			
		||||
            $yearsHTML .= "<option>".$value."</option>";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $html = "<div class='row'>
 | 
			
		||||
                            <fieldset id='datos_entrada'>
 | 
			
		||||
                                <legend>Resumen de la Compra</legend>
 | 
			
		||||
                                <p>Película: ".str_replace('_', ' ', strtoupper($this->film->getTittle()))."</p>
 | 
			
		||||
                                <p>Cine: ".$this->cinema->getName()."</p>
 | 
			
		||||
                                <p>Sala: ".$this->session->getIdhall()."</p>
 | 
			
		||||
                                <p>Fecha: ".date_format(date_create($this->session->getDate()), 'd-m-Y')."</p>
 | 
			
		||||
                                <p>Hora: ".$this->session->getStartTime()."</p>
 | 
			
		||||
                                <p>Precio: ".$this->session->getSeatPrice()."€</p>
 | 
			
		||||
                            </fieldset>
 | 
			
		||||
                            <fieldset id='pagar_entrada'><pre>".$htmlErroresGlobales."</pre>
 | 
			
		||||
                                <legend>Datos Bancarios</legend>
 | 
			
		||||
                                <label for='card-holder'>Titular de la Tarjeta:</label><br />
 | 
			
		||||
                                    <input type='text' id='card-holder' class='card-holder' placeholder='NOMBRE APELLIDO1 APELLIDO2' required />
 | 
			
		||||
                                <br />
 | 
			
		||||
                                <label for='card-number'>Número de Tarjeta: </label><br />
 | 
			
		||||
                                    <input type='num' id='card-number-0' class='input-cart-number' placeholder='XXXX' maxlength='4' required />
 | 
			
		||||
                                    <input type='num' id='card-number-1' class='input-cart-number' placeholder='XXXX' maxlength='4' required />
 | 
			
		||||
                                    <input type='num' id='card-number-2' class='input-cart-number' placeholder='XXXX' maxlength='4' required />
 | 
			
		||||
                                    <input type='num' id='card-number-3' class='input-cart-number' placeholder='XXXX' maxlength='4' required />    
 | 
			
		||||
                                <label for='card-cvv'>CVV: </label>
 | 
			
		||||
                                    <input type='text' id='card-cvv' class='fieldset-cvv' maxlength='3' placeholder='XXX' required />
 | 
			
		||||
                                <br />
 | 
			
		||||
                                <label for='card-expiration'>Fecha de Expiración:</label><br />
 | 
			
		||||
                                    <select id='card-expiration-month' required>
 | 
			
		||||
                                    ".$monthsHTML."
 | 
			
		||||
                                    </select>
 | 
			
		||||
                                    <select id='card-expiration-year' required>
 | 
			
		||||
                                    ".$yearsHTML."
 | 
			
		||||
                                    </select>
 | 
			
		||||
                            </fieldset>
 | 
			
		||||
                            <div class='actions'> 
 | 
			
		||||
                                <input type='submit' id='submit' value='Pagar' class='primary' />
 | 
			
		||||
                                <input type='reset' id='reset' value='Borrar' />       
 | 
			
		||||
                            </div>
 | 
			
		||||
                        </div>";
 | 
			
		||||
 | 
			
		||||
        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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										232
									
								
								root/purchase/includes/formPurchase.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										232
									
								
								root/purchase/includes/formPurchase.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,232 @@
 | 
			
		||||
<?php
 | 
			
		||||
include_once($prefix.'assets/php/form.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/hall_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/hall.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/seat_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/seat.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/purchase_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/purchase.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/promotion_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/user.php');
 | 
			
		||||
 | 
			
		||||
class FormPurchase extends Form {
 | 
			
		||||
 | 
			
		||||
    //Atributes:
 | 
			
		||||
    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 $seat;          // Seat of the film to be purchased. 
 | 
			
		||||
    private $row;           // Row of the seat.
 | 
			
		||||
    private $col;           // Column of the seat.
 | 
			
		||||
    private $code;          // Promotional code.
 | 
			
		||||
    private $years;         // Actual year.
 | 
			
		||||
    private $months;        // Months of the year.
 | 
			
		||||
    private $_TODAY;        // Actual date.
 | 
			
		||||
 | 
			
		||||
    public function __construct() {
 | 
			
		||||
        parent::__construct('formPurchase');
 | 
			
		||||
 | 
			
		||||
        $sessionDAO = new SessionDAO("complucine");
 | 
			
		||||
        $this->session = $sessionDAO->sessionData($_POST["sessions"]);
 | 
			
		||||
 | 
			
		||||
        $filmDAO = new Film_DAO("complucine");  
 | 
			
		||||
        $this->film = $filmDAO->FilmData($this->session->getIdfilm());
 | 
			
		||||
 | 
			
		||||
        $cinemaDAO = new Cinema_DAO("complucine");  
 | 
			
		||||
        $this->cinema = $cinemaDAO->cinemaData($this->session->getIdcinema());
 | 
			
		||||
 | 
			
		||||
        $hallDAO = new HallDAO("complucine");
 | 
			
		||||
        $this->hall = $hallDAO->HallData($this->session->getIdhall());
 | 
			
		||||
 | 
			
		||||
        $this->seat = array();
 | 
			
		||||
        $this->row = array();
 | 
			
		||||
        $this->col = array();
 | 
			
		||||
        $rows = $this->hall->getNumRows();
 | 
			
		||||
        $cols = $this->hall->getNumCol();
 | 
			
		||||
        for($i = 0; $i <= $rows; $i++){
 | 
			
		||||
            for($j = 0; $j <= $cols; $j++){
 | 
			
		||||
                $seat = $i.$j;
 | 
			
		||||
                if(isset($_POST["checkbox".$seat])){
 | 
			
		||||
                    array_push($this->seat, $i."-".$j);
 | 
			
		||||
                    array_push($this->row, $i); 
 | 
			
		||||
                    array_push($this->col, $j); 
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $promoDAO = new Promotion_DAO("complucine");
 | 
			
		||||
        $this->code = intval(0);
 | 
			
		||||
        if(isset($_POST["code"]) && $_POST["code"] !== ""){
 | 
			
		||||
            if($promoDAO->GetPromotion($_POST["code"])->data_seek(0)){
 | 
			
		||||
                $this->code = intval(2);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $TODAY = getdate();
 | 
			
		||||
        $year = "$TODAY[year]";
 | 
			
		||||
 | 
			
		||||
        $this->_TODAY = "$TODAY[year]-$TODAY[month]-$TODAY[mday] $TODAY[hours]:$TODAY[minutes]:$TODAY[seconds]";
 | 
			
		||||
 | 
			
		||||
        $this->years = array();
 | 
			
		||||
        for($i = $year; $i < $year+10; $i++) array_push($this->years, $i);
 | 
			
		||||
 | 
			
		||||
        $this->months = array();
 | 
			
		||||
        for($i = 1; $i <= 12; $i++) array_push($this->months, $i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function generaCamposFormulario($datos, $errores = array()){
 | 
			
		||||
 | 
			
		||||
        // Se generan los mensajes de error si existen.
 | 
			
		||||
        $htmlErroresGlobales = self::generaListaErroresGlobales($errores);
 | 
			
		||||
        $errorNombre = self::createMensajeError($errores, 'card-holder', 'span', array('class' => 'error'));
 | 
			
		||||
        $errorCardNumber = self::createMensajeError($errores, 'card-number-0', 'span', array('class' => 'error'));
 | 
			
		||||
        $errorCVV = self::createMensajeError($errores, 'card-cvv', 'span', array('class' => 'error'));
 | 
			
		||||
        $errorCardExpirationMonth = self::createMensajeError($errores, 'card-expiration-month', 'span', array('class' => 'error'));
 | 
			
		||||
        $errorCardExpirationYear = self::createMensajeError($errores, 'card-expiration-year', 'span', array('class' => 'error'));
 | 
			
		||||
 | 
			
		||||
        $monthsHTML = "";
 | 
			
		||||
        foreach($this->months as $value){
 | 
			
		||||
            $monthsHTML .= "<option>".$value."</option>";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $yearsHTML = "";
 | 
			
		||||
        foreach($this->years as $value){
 | 
			
		||||
            $yearsHTML .= "<option>".$value."</option>";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if($this->session->getSeatsFull()){
 | 
			
		||||
            $html = "<div class='code info'>
 | 
			
		||||
                       <h2>La sesión está llena, no quedan asientos disponibles.</h2><hr />
 | 
			
		||||
                       <p>Vuelva atrás para selecionar otra sesión.</p>
 | 
			
		||||
                    </div>";
 | 
			
		||||
        } else {
 | 
			
		||||
            if(!empty($this->seat)){
 | 
			
		||||
                $seats = "";
 | 
			
		||||
                foreach($this->seat as $value){
 | 
			
		||||
                    $seats .= $value.", ";
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                $promo = "";
 | 
			
		||||
                if($this->code > 0) $promo = "<pre>(Se ha aplicado un descuento por código promocional).</pre>";
 | 
			
		||||
 | 
			
		||||
                $html = "<div class='row'>
 | 
			
		||||
                                <fieldset id='datos_entrada'>
 | 
			
		||||
                                    <legend>Resumen de la Compra</legend>
 | 
			
		||||
                                    <img src='"."../img/films/".$this->film->getImg()."' alt='".$this->film->getTittle()."' />
 | 
			
		||||
                                    <p>Película: ".str_replace('_', ' ', strtoupper($this->film->getTittle()))."</p>
 | 
			
		||||
                                    <p>Cine: ".$this->cinema->getName()."</p>
 | 
			
		||||
                                    <p>Sala: ".$this->session->getIdhall()."</p>
 | 
			
		||||
                                    <p>Asiento(s):".$seats."</p>
 | 
			
		||||
                                    <p>Fecha: ".date_format(date_create($this->session->getDate()), 'd-m-Y')."</p>
 | 
			
		||||
                                    <p>Hora: ".$this->session->getStartTime()."</p>
 | 
			
		||||
                                    <p>Precio Total: ".intval($this->session->getSeatPrice()*count($this->seat)-$this->code)."€ (Precio por asiento: ".$this->session->getSeatPrice()." €)</p>
 | 
			
		||||
                                    <p>".$promo."</p>
 | 
			
		||||
                                </fieldset>
 | 
			
		||||
                                <fieldset id='pagar_entrada'><pre>".$htmlErroresGlobales."</pre>
 | 
			
		||||
                                    <legend>Datos Bancarios</legend>
 | 
			
		||||
                                    <label for='card-holder'>Titular de la Tarjeta:  <span id='cardNameValid'>✔</span><span id='cardNameInvalid'>❌</span></label><pre>".$errorNombre."</pre><br />
 | 
			
		||||
                                        <input type='text' name='card-holder' id='card-holder' class='card-holder' placeholder='NOMBRE APELLIDO1 APELLIDO2' required />
 | 
			
		||||
                                    <br />
 | 
			
		||||
                                    <label for='card-number'>Número de Tarjeta: <span id='carNumberValid'>✔</span><span id='cardNumerInvalid'>❌</span></label><pre>".$errorCardNumber."</pre><br />
 | 
			
		||||
                                        <input type='num' name='card-number-0' id='card-number-0' class='input-cart-number' placeholder='XXXX' maxlength='4' required />
 | 
			
		||||
                                        <input type='num' name='card-number-1' id='card-number-1' class='input-cart-number' placeholder='XXXX' maxlength='4' required />
 | 
			
		||||
                                        <input type='num' name='card-number-2' id='card-number-2' class='input-cart-number' placeholder='XXXX' maxlength='4' required />
 | 
			
		||||
                                        <input type='num' name='card-number-3' id='card-number-3' class='input-cart-number' placeholder='XXXX' maxlength='4' required />    
 | 
			
		||||
                                    <label for='card-cvv'>CVV: <span id='cvvValid'>✔</span><span id='cvvInvalid'>❌</span></label>
 | 
			
		||||
                                        <input type='text' name='card-cvv' id='card-cvv' class='fieldset-cvv' maxlength='3' placeholder='XXX' required /><pre>".$errorCVV."</pre>
 | 
			
		||||
                                    <br />
 | 
			
		||||
                                    <label for='card-expiration'>Fecha de Expiración: <span id='dateValid'>✔</span><span id='dateInvalid'>❌</span></label><pre>".$errorCardExpirationMonth.$errorCardExpirationYear."</pre><br />
 | 
			
		||||
                                        <select name='card-expiration-month' id='card-expiration-month' required>
 | 
			
		||||
                                        ".$monthsHTML."
 | 
			
		||||
                                        </select>
 | 
			
		||||
                                        <select name='card-expiration-year' id='card-expiration-year' required>
 | 
			
		||||
                                        ".$yearsHTML."
 | 
			
		||||
                                        </select>
 | 
			
		||||
                                </fieldset>
 | 
			
		||||
                                <div class='actions'> 
 | 
			
		||||
                                    <input type='hidden' name='sessions' id='sessions' value='".$_POST["sessions"]."' />
 | 
			
		||||
                                    <input type='hidden' name='row' id='row' value='".serialize($this->row)."' />
 | 
			
		||||
                                    <input type='hidden' name='col' id='col' value='".serialize($this->col)."' />
 | 
			
		||||
                                    <input type='submit' id='submit' value='Pagar' class='primary' />
 | 
			
		||||
                                    <input type='reset' id='reset' value='Borrar' />       
 | 
			
		||||
                                </div>
 | 
			
		||||
                            </div>";
 | 
			
		||||
            } else {
 | 
			
		||||
                $html = "<div class='code info'>
 | 
			
		||||
                       <h2>No se ha seleccionado asiento(s).</h2>
 | 
			
		||||
                       <p>Vuelva atrás para selecionar una butaca.</p>
 | 
			
		||||
                       <button id='go-back'>Volver</button>
 | 
			
		||||
                    </div>";
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return $html;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function procesaFormulario($datos){
 | 
			
		||||
        $result = array();
 | 
			
		||||
        
 | 
			
		||||
        $nombre = $this->test_input($datos['card-holder']) ?? null;
 | 
			
		||||
        $nombre = strtolower($nombre);
 | 
			
		||||
        if ( empty($nombre) ) {
 | 
			
		||||
            $result['card-holder'] = "El nombre no puede estar vacío.";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for($i = 0; $i < 4; $i++){
 | 
			
		||||
            $card_numer = $this->test_input($datos['card-number-'.$i]) ?? null;
 | 
			
		||||
            if ( empty($card_numer) || mb_strlen($card_numer) < 4 ) {
 | 
			
		||||
                $result['card-number-0'] = "La tarjeta debe tener 16 dígitos.";
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $cvv = $this->test_input($datos['card-cvv']) ?? null;
 | 
			
		||||
        if ( empty($cvv) || mb_strlen($cvv) < 3 ) {
 | 
			
		||||
            $result['card-cvv'] = "El CVV debe tener 3 números.";
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        $month = $this->test_input($datos['card-expiration-month']) ?? null;
 | 
			
		||||
        //$TODAY = getdate();
 | 
			
		||||
        //$actualMonth = "$TODAY[month]";
 | 
			
		||||
        if ( empty($month) /*|| $month < $actualMonth*/) {
 | 
			
		||||
            $result['card-expiration-month'] = "El mes de expiración no es correcto.";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $year = $this->test_input($datos['card-expiration-year']) ?? null;
 | 
			
		||||
        if ( empty($year) ) {
 | 
			
		||||
            $result['card-expiration-year'] = "El año de expiración no es correcto.";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (count($result) === 0) {
 | 
			
		||||
           if(isset($_SESSION["login"]) && $_SESSION["login"] == true){
 | 
			
		||||
                $purchaseDAO = new PurchaseDAO("complucine");
 | 
			
		||||
                $count = count(unserialize($datos["row"]));
 | 
			
		||||
                $rows =  unserialize($datos["row"]); $cols =  unserialize($datos["col"]);
 | 
			
		||||
                for($i = 0; $i < $count; $i++){
 | 
			
		||||
                    if($purchaseDAO->createPurchase(unserialize($_SESSION["user"])->getId(), $this->session->getId(), $this->session->getIdhall(), $this->cinema->getId(), $rows[$i], $cols[$i], date("Y-m-d H:i:s"))){
 | 
			
		||||
                        $purchase = new Purchase(unserialize($_SESSION["user"])->getId(), $this->session->getId(), $this->session->getIdhall(), $this->cinema->getId(), $datos["row"], $datos["col"], strftime("%A %e de %B de %Y a las %H:%M"));
 | 
			
		||||
                        
 | 
			
		||||
                        $_SESSION["purchase"] = serialize($purchase);
 | 
			
		||||
                        $_SESSION["film_purchase"] = serialize($this->film);
 | 
			
		||||
                        $result = "resume.php";
 | 
			
		||||
                    } else {
 | 
			
		||||
                        $result[] = "Error al realizar la compra.";
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
           } else {
 | 
			
		||||
            $purchase = new Purchase("null", $this->session->getId(), $this->session->getIdhall(), $this->cinema->getId(), $datos["row"], $datos["col"], strftime("%A %e de %B de %Y a las %H:%M"));
 | 
			
		||||
                $_SESSION["purchase"] = serialize($purchase);
 | 
			
		||||
                $_SESSION["film_purchase"] = serialize($this->film);
 | 
			
		||||
                $result = "resume.php";
 | 
			
		||||
           }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										269
									
								
								root/purchase/includes/formSelectCinemaSession-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										269
									
								
								root/purchase/includes/formSelectCinemaSession-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,269 @@
 | 
			
		||||
<?php
 | 
			
		||||
include_once($prefix.'assets/php/form.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/hall_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/hall.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 $_TODAY;         // Actual date.
 | 
			
		||||
 | 
			
		||||
    public function __construct() {
 | 
			
		||||
        $options = array("action" => "selectSeat.php");
 | 
			
		||||
        parent::__construct('formSelectCinemaSession', $options);
 | 
			
		||||
 | 
			
		||||
        $TODAY = getdate();
 | 
			
		||||
        $this->_TODAY = "$TODAY[mday]"."-"."$TODAY[mon]"."-"."$TODAY[year]";
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function generaCamposFormulario($datos, $errores = array()){
 | 
			
		||||
        $cinemas = [];
 | 
			
		||||
        $sessions = [];
 | 
			
		||||
 | 
			
		||||
        // 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'));
 | 
			
		||||
        
 | 
			
		||||
        $pay = true;
 | 
			
		||||
        if(isset($_GET["film"])){
 | 
			
		||||
            $filmDAO = new Film_DAO("complucine");
 | 
			
		||||
            $film = $filmDAO->FilmData($_GET["film"]);
 | 
			
		||||
            if($film){
 | 
			
		||||
                $tittle = $film->getTittle();
 | 
			
		||||
                $image = $film->getImg();
 | 
			
		||||
    
 | 
			
		||||
                $cinemas = $filmDAO->getCinemas($_GET["film"]);
 | 
			
		||||
                $cinema_id = $_GET["cinema"];
 | 
			
		||||
                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 = '<section id="select_cinema"><pre>'.$htmlErroresGlobales.'</pre>
 | 
			
		||||
                                        <select name="cinemas" id="cinemas"><pre>'.$errorCinema.'</pre>';
 | 
			
		||||
                    if(!isset($cinema_id)){
 | 
			
		||||
                        $cinemasListHTML .= '<option value="" selected>Selecciona un cine</option>';
 | 
			
		||||
                        foreach($cinemasIT as $value){
 | 
			
		||||
                            $cinemasListHTML .='<option value="'.$value["cID"].'">'.$value["NAME"].'</option>';
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
                        foreach($cinemasIT as $value){
 | 
			
		||||
                            if($value["cID"] == $cinema_id){
 | 
			
		||||
                                $cinemasListHTML .= '<option value="'.$value["cID"].'" selected>'.$value["NAME"].'</option>';
 | 
			
		||||
                            } else {
 | 
			
		||||
                                $cinemasListHTML .='<option value="'.$value["cID"].'">'.$value["NAME"].'</option>';
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    $cinemasListHTML .= '</select>
 | 
			
		||||
                                </section>';
 | 
			
		||||
                } else {
 | 
			
		||||
                    $cinemasListHTML = '<form><select name="cinemas"><option value="" selected>No hay cines disponibles para esta película.</option></select></form>';
 | 
			
		||||
                }
 | 
			
		||||
    
 | 
			
		||||
                $fiml_id = $film->getId();
 | 
			
		||||
    
 | 
			
		||||
                if(isset($cinema_id)){
 | 
			
		||||
                    $sessionsDAO = new SessionDAO("complucine");
 | 
			
		||||
                    $sessions = $sessionsDAO->getSessions_Film_Cinema($fiml_id, $cinema_id);
 | 
			
		||||
                    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");
 | 
			
		||||
    
 | 
			
		||||
                        $count = 0;
 | 
			
		||||
                        $sessionsListHTML = '<select name="sessions" id="sessions"><pre>'.$errorSession.'</pre>';
 | 
			
		||||
                        foreach ($sessionsIT as $value) {
 | 
			
		||||
                            if(strtotime($this->_TODAY) <= strtotime($value["DATE"])){
 | 
			
		||||
                                if($value === reset($sessionsIT)){
 | 
			
		||||
                                    $sessionsListHTML .= '<option value="'.$value["sID"].'" >Fecha: '.$value["DATE"].' | Hora: '.$value["HOUR"].' | Sala: '.$value["HALL"].'</option>';
 | 
			
		||||
                                } else {
 | 
			
		||||
                                    $sessionsListHTML .='<option value="'.$value["sID"].'">Fecha: '.$value["DATE"].' | Hora:'.$value["HOUR"].' | Sala: '.$value["HALL"].'</option>';
 | 
			
		||||
                                }
 | 
			
		||||
                                $count++;
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        $sessionsListHTML .= '</select>';
 | 
			
		||||
    
 | 
			
		||||
                        if($count == 0) {
 | 
			
		||||
                            $sessionsListHTML = '<select name="sessions"><option value="" selected>No hay sesiones disponibles para esta película.</option></select>'; 
 | 
			
		||||
                            $pay = false;
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
                        $sessionsListHTML = '<select name="sessions"><option value="" selected>No hay sesiones disponibles para esta película.</option></select>';
 | 
			
		||||
                        $pay = false;
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    $sessionsListHTML = '<select name="sessions"><option value="" selected>Primero seleccione un cine.</option></select>';
 | 
			
		||||
                    $pay = false;
 | 
			
		||||
                }
 | 
			
		||||
    
 | 
			
		||||
                //Reply: Depends on whether the purchase is to be made from a selected movie or a cinema.
 | 
			
		||||
                $html = '<div class="column left">
 | 
			
		||||
                            <h2>Película seleccionada: '.str_replace('_', ' ', $tittle).'</h2><hr />
 | 
			
		||||
                            <div class="image"><img src="../img/films/'.$image.'" alt="'.$tittle.'" /></div>
 | 
			
		||||
                            <p>Duración: '.$film->getDuration().' minutos</p>
 | 
			
		||||
                            <p>Idioma: '.$film->getLanguage().'</p>
 | 
			
		||||
                        </div>
 | 
			
		||||
                        <div class="column right">
 | 
			
		||||
                            <h2>Seleccione un Cine y una Sesión</h2><hr />
 | 
			
		||||
                                <h3>Cines</h3>        
 | 
			
		||||
                                '.$cinemasListHTML.'
 | 
			
		||||
                                <h3>Sesiones</h3>
 | 
			
		||||
                                '.$sessionsListHTML.'
 | 
			
		||||
                                <h3>Aplicar código promocional<span id="codeValid">✔</span><span id="codeInvalid">❌</span></h3>
 | 
			
		||||
                                <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"])) {
 | 
			
		||||
            $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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //Select seat button:
 | 
			
		||||
        if($pay){
 | 
			
		||||
            $pay = '<input type="submit" id="submit" value="Seleccionar Asiento" />';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
            return '
 | 
			
		||||
                    <section class="code purchase">
 | 
			
		||||
                        '.$html.'
 | 
			
		||||
                    </section>
 | 
			
		||||
                    <section class="code purchase">
 | 
			
		||||
                        '.$pay.'
 | 
			
		||||
                    </section>';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function procesaFormulario($datos){
 | 
			
		||||
        $result = array();
 | 
			
		||||
 | 
			
		||||
        $cinema = $this->test_input($datos['cinemas']) ?? null;
 | 
			
		||||
        if ( empty($cinema) ) {
 | 
			
		||||
            $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.";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $code = $this->test_input($datos['code']) ?? null;
 | 
			
		||||
        $avaliable = "../assets/php/common/checkPromo.php?code=".$code;
 | 
			
		||||
        if ( !empty($code) && mb_strlen($code) != 8 && $avaliable === "avaliable") {
 | 
			
		||||
            $result['code'] = "El código promocional no es válido.";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (count($result) === 0) {
 | 
			
		||||
            $result = "selectSeat.php";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										272
									
								
								root/purchase/includes/formSelectCinemaSession.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										272
									
								
								root/purchase/includes/formSelectCinemaSession.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,272 @@
 | 
			
		||||
<?php
 | 
			
		||||
include_once($prefix.'assets/php/form.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/hall_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/hall.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 $_TODAY;         // Actual date.
 | 
			
		||||
 | 
			
		||||
    public function __construct() {
 | 
			
		||||
        $options = array("action" => "selectSeat.php");
 | 
			
		||||
        parent::__construct('formSelectCinemaSession', $options);
 | 
			
		||||
 | 
			
		||||
        $TODAY = getdate();
 | 
			
		||||
        $this->_TODAY = "$TODAY[mday]"."-"."$TODAY[mon]"."-"."$TODAY[year]";
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function generaCamposFormulario($datos, $errores = array()){
 | 
			
		||||
        $cinemas = [];
 | 
			
		||||
        $sessions = [];
 | 
			
		||||
 | 
			
		||||
        // 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'));
 | 
			
		||||
        
 | 
			
		||||
        $pay = true;
 | 
			
		||||
        if(isset($_GET["film"])){
 | 
			
		||||
            $filmDAO = new Film_DAO("complucine");
 | 
			
		||||
            $film = $filmDAO->FilmData($_GET["film"]);
 | 
			
		||||
            if($film){
 | 
			
		||||
                $tittle = $film->getTittle();
 | 
			
		||||
                $image = $film->getImg();
 | 
			
		||||
    
 | 
			
		||||
                $cinemas = $filmDAO->getCinemas($_GET["film"]);
 | 
			
		||||
                $cinema_id = $_GET["cinema"];
 | 
			
		||||
                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 = '<section id="select_cinema"><pre>'.$htmlErroresGlobales.'</pre>
 | 
			
		||||
                                        <select name="cinemas" id="cinemas"><pre>'.$errorCinema.'</pre>';
 | 
			
		||||
                    if(!isset($cinema_id)){
 | 
			
		||||
                        $cinemasListHTML .= '<option value="" selected>Selecciona un cine</option>';
 | 
			
		||||
                        foreach($cinemasIT as $value){
 | 
			
		||||
                            $cinemasListHTML .='<option value="'.$value["cID"].'">'.$value["NAME"].'</option>';
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
                        foreach($cinemasIT as $value){
 | 
			
		||||
                            if($value["cID"] == $cinema_id){
 | 
			
		||||
                                $cinemasListHTML .= '<option value="'.$value["cID"].'" selected>'.$value["NAME"].'</option>';
 | 
			
		||||
                            } else {
 | 
			
		||||
                                $cinemasListHTML .='<option value="'.$value["cID"].'">'.$value["NAME"].'</option>';
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    $cinemasListHTML .= '</select>
 | 
			
		||||
                                </section>';
 | 
			
		||||
                } else {
 | 
			
		||||
                    $cinemasListHTML = '<select name="cinemas"><option value="" selected>No hay cines disponibles para esta película.</option></select>';
 | 
			
		||||
                }
 | 
			
		||||
    
 | 
			
		||||
                $fiml_id = $film->getId();
 | 
			
		||||
    
 | 
			
		||||
                if(isset($cinema_id)){
 | 
			
		||||
                    $sessionsDAO = new SessionDAO("complucine");
 | 
			
		||||
                    $sessions = $sessionsDAO->getSessions_Film_Cinema($fiml_id, $cinema_id);
 | 
			
		||||
                    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");
 | 
			
		||||
    
 | 
			
		||||
                        $count = 0;
 | 
			
		||||
                        $sessionsListHTML = '<select name="sessions" id="sessions"><pre>'.$errorSession.'</pre>';
 | 
			
		||||
                        foreach ($sessionsIT as $value) {
 | 
			
		||||
                            if(strtotime($this->_TODAY) <= strtotime($value["DATE"])){
 | 
			
		||||
                                if($value === reset($sessionsIT)){
 | 
			
		||||
                                    $sessionsListHTML .= '<option value="'.$value["sID"].'" >Fecha: '.$value["DATE"].' | Hora: '.$value["HOUR"].' | Sala: '.$value["HALL"].'</option>';
 | 
			
		||||
                                } else {
 | 
			
		||||
                                    $sessionsListHTML .='<option value="'.$value["sID"].'">Fecha: '.$value["DATE"].' | Hora:'.$value["HOUR"].' | Sala: '.$value["HALL"].'</option>';
 | 
			
		||||
                                }
 | 
			
		||||
                                $count++;
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        $sessionsListHTML .= '</select>';
 | 
			
		||||
    
 | 
			
		||||
                        if($count == 0) {
 | 
			
		||||
                            $sessionsListHTML = '<select name="sessions"><option value="" selected>No hay sesiones disponibles para esta película.</option></select>'; 
 | 
			
		||||
                            $pay = false;
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
                        $sessionsListHTML = '<select name="sessions"><option value="" selected>No hay sesiones disponibles para esta película.</option></select>';
 | 
			
		||||
                        $pay = false;
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    $sessionsListHTML = '<select name="sessions"><option value="" selected>Primero seleccione un cine.</option></select>';
 | 
			
		||||
                    $pay = false;
 | 
			
		||||
                }
 | 
			
		||||
    
 | 
			
		||||
                //Reply: Depends on whether the purchase is to be made from a selected movie or a cinema.
 | 
			
		||||
                $html = '<div class="column left">
 | 
			
		||||
                            <h2>Película seleccionada: '.str_replace('_', ' ', $tittle).'</h2><hr />
 | 
			
		||||
                            <div class="image"><img src="../img/films/'.$image.'" alt="'.$tittle.'" /></div>
 | 
			
		||||
                            <p>Duración: '.$film->getDuration().' minutos</p>
 | 
			
		||||
                            <p>Idioma: '.$film->getLanguage().'</p>
 | 
			
		||||
                        </div>
 | 
			
		||||
                        <div class="column right">
 | 
			
		||||
                            <h2>Seleccione un Cine y una Sesión</h2><hr />
 | 
			
		||||
                                <h3>Cines</h3>        
 | 
			
		||||
                                '.$cinemasListHTML.'
 | 
			
		||||
                                <h3>Sesiones</h3>
 | 
			
		||||
                                '.$sessionsListHTML.'
 | 
			
		||||
                                <h3><a href="../promotions/" target="_blank">Aplicar código promocional</a><span id="codeValid">✔</span><span id="codeInvalid">❌</span></h3>
 | 
			
		||||
                                <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"])) {
 | 
			
		||||
            $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>
 | 
			
		||||
                    <button id="go-back">Volver</button>';
 | 
			
		||||
            $pay = false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //Select seat button:
 | 
			
		||||
        if($pay){
 | 
			
		||||
            $pay = '<input type="submit" id="submit" value="Seleccionar Asiento" />';
 | 
			
		||||
        } else {
 | 
			
		||||
            $pay = '<button id="go-back">Volver</button>';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
            return '
 | 
			
		||||
                    <section class="code purchase">
 | 
			
		||||
                        '.$html.'
 | 
			
		||||
                    </section>
 | 
			
		||||
                    <section class="code purchase">
 | 
			
		||||
                        '.$pay.'
 | 
			
		||||
                    </section>';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function procesaFormulario($datos){
 | 
			
		||||
        $result = array();
 | 
			
		||||
 | 
			
		||||
        $cinema = $this->test_input($datos['cinemas']) ?? null;
 | 
			
		||||
        if ( empty($cinema) ) {
 | 
			
		||||
            $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.";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $code = $this->test_input($datos['code']) ?? null;
 | 
			
		||||
        $avaliable = "../assets/php/common/checkPromo.php?code=".$code;
 | 
			
		||||
        if ( !empty($code) && mb_strlen($code) != 8 && $avaliable === "avaliable") {
 | 
			
		||||
            $result['code'] = "El código promocional no es válido.";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (count($result) === 0) {
 | 
			
		||||
            $result = "selectSeat.php";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										107
									
								
								root/purchase/includes/formSelectSeat-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										107
									
								
								root/purchase/includes/formSelectSeat-FER_SURFACE.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,107 @@
 | 
			
		||||
<?php
 | 
			
		||||
include_once($prefix.'assets/php/form.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/hall_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/hall.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/seat_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/seat.php');
 | 
			
		||||
 | 
			
		||||
class FormSelectSeat extends Form {
 | 
			
		||||
 | 
			
		||||
    //Atributes:
 | 
			
		||||
 | 
			
		||||
    public function __construct() {
 | 
			
		||||
        $options = array("action" => "confirm.php");
 | 
			
		||||
        parent::__construct('formSelectSeat', $options);
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function generaCamposFormulario($datos, $errores = array()){
 | 
			
		||||
 | 
			
		||||
        // Se generan los mensajes de error, si existen.
 | 
			
		||||
        $htmlErroresGlobales = self::generaListaErroresGlobales($errores);
 | 
			
		||||
        $errorSeat = self::createMensajeError($errores, 'seats', 'span', array('class' => 'error'));
 | 
			
		||||
 | 
			
		||||
        $sessionDAO = new SessionDAO("complucine");
 | 
			
		||||
        $session = $sessionDAO->sessionData($_POST["sessions"]);
 | 
			
		||||
 | 
			
		||||
        $hallDAO = new HallDAO("complucine");
 | 
			
		||||
        $hall = $hallDAO->HallData($session->getIdhall());
 | 
			
		||||
 | 
			
		||||
        $seatDAO = new SeatDAO("complucine");
 | 
			
		||||
        $seats = $seatDAO->getAllSeats($session->getIdhall(), $session->getIdcinema());
 | 
			
		||||
 | 
			
		||||
        $rows = $hall->getNumRows(); 
 | 
			
		||||
        $cols = $hall->getNumCol();
 | 
			
		||||
 | 
			
		||||
        //$seats = $hall->getTotalSeats();
 | 
			
		||||
		$seats_map = array();
 | 
			
		||||
 | 
			
		||||
        for($i = 1; $i <= $rows; $i++){
 | 
			
		||||
            for($j = 1; $j <= $cols; $j++){ 
 | 
			
		||||
                $seats_map[$i][$j] = $seats[$i]->getState();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        $html ='<h2>Seleccionar un Asiento</h2><hr />
 | 
			
		||||
            <h3 class="table_title">Pantalla</h3>
 | 
			
		||||
            <table class="seat">
 | 
			
		||||
                <thead>
 | 
			
		||||
                    <tr>
 | 
			
		||||
                        <th> </th>
 | 
			
		||||
                        ';
 | 
			
		||||
        for($j = 1; $j <= $cols; $j++){
 | 
			
		||||
            $html .= '<th>'.$j.'</th>
 | 
			
		||||
                            ';	
 | 
			
		||||
        }
 | 
			
		||||
        $html .= '</tr>
 | 
			
		||||
                    </thead>
 | 
			
		||||
                    <tbody>';
 | 
			
		||||
            for($i = 1; $i <= $rows; $i++){
 | 
			
		||||
                    $html .= '
 | 
			
		||||
                        <tr>
 | 
			
		||||
                            <td>'.$i.'</td>
 | 
			
		||||
                            ';
 | 
			
		||||
                for($j = 1; $j <= $cols; $j++){
 | 
			
		||||
                    if($seats_map[$i][$j] >= 0){
 | 
			
		||||
                        $html .= '<td> <input type="checkbox" class="check_box" name="checkbox'.$i.$j.'" value="'.$seats_map[$i][$j].'" id="checkbox'.$i.$j.'" checked> <label for="checkbox'.$i.$j.'"> </td>
 | 
			
		||||
                            ';}
 | 
			
		||||
                    else {
 | 
			
		||||
                        $html .= '<td> <input type="checkbox" class="check_box" name="checkbox'.$i.$j.'" value="'.$seats_map[$i][$j].'" id="checkbox'.$i.$j.'" disabled> <label for="checkbox'.$i.$j.'"> </td>
 | 
			
		||||
                            ';}
 | 
			
		||||
                }
 | 
			
		||||
                    $html .='</tr>';
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
        $html .= '
 | 
			
		||||
                </tbody>
 | 
			
		||||
            </table>';
 | 
			
		||||
 | 
			
		||||
        //Pay button:
 | 
			
		||||
        $pay = '<input type="hidden" name="sessions" id="sessions" value="'.$_POST["sessions"].'" />
 | 
			
		||||
                <input type="submit" id="submit" value="Pagar" />';
 | 
			
		||||
 | 
			
		||||
        return '
 | 
			
		||||
                <section class="code purchase">
 | 
			
		||||
                    '.$html.'
 | 
			
		||||
                </section>
 | 
			
		||||
                <section class="code purchase">
 | 
			
		||||
                    '.$pay.'
 | 
			
		||||
                </section>';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function procesaFormulario($datos){
 | 
			
		||||
        $result = array();
 | 
			
		||||
 | 
			
		||||
        if (count($result) === 0) {
 | 
			
		||||
            $result = "confirm.php";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										108
									
								
								root/purchase/includes/formSelectSeat.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										108
									
								
								root/purchase/includes/formSelectSeat.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,108 @@
 | 
			
		||||
<?php
 | 
			
		||||
include_once($prefix.'assets/php/form.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/hall_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/hall.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/seat_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/seat.php');
 | 
			
		||||
 | 
			
		||||
class FormSelectSeat extends Form {
 | 
			
		||||
 | 
			
		||||
    //Atributes:
 | 
			
		||||
 | 
			
		||||
    public function __construct() {
 | 
			
		||||
        $options = array("action" => "confirm.php");
 | 
			
		||||
        parent::__construct('formSelectSeat', $options);
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function generaCamposFormulario($datos, $errores = array()){
 | 
			
		||||
 | 
			
		||||
        // Se generan los mensajes de error, si existen.
 | 
			
		||||
        $htmlErroresGlobales = self::generaListaErroresGlobales($errores);
 | 
			
		||||
        $errorSeat = self::createMensajeError($errores, 'seats', 'span', array('class' => 'error'));
 | 
			
		||||
 | 
			
		||||
        $sessionDAO = new SessionDAO("complucine");
 | 
			
		||||
        $session = $sessionDAO->sessionData($_POST["sessions"]);
 | 
			
		||||
 | 
			
		||||
        $hallDAO = new HallDAO("complucine");
 | 
			
		||||
        $hall = $hallDAO->HallData($session->getIdhall());
 | 
			
		||||
 | 
			
		||||
        $seatDAO = new SeatDAO("complucine");
 | 
			
		||||
        $seats = $seatDAO->getAllSeats($session->getIdhall(), $session->getIdcinema());
 | 
			
		||||
 | 
			
		||||
        $rows = $hall->getNumRows(); 
 | 
			
		||||
        $cols = $hall->getNumCol();
 | 
			
		||||
 | 
			
		||||
        //$seats = $hall->getTotalSeats();
 | 
			
		||||
		$seats_map = array();
 | 
			
		||||
 | 
			
		||||
        for($i = 1; $i <= $rows; $i++){
 | 
			
		||||
            for($j = 1; $j <= $cols; $j++){ 
 | 
			
		||||
                $seats_map[$i][$j] = $seats[$i]->getState();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        $html ='<h2>Seleccionar un Asiento</h2><hr />
 | 
			
		||||
            <h3 class="table_title">Pantalla</h3>
 | 
			
		||||
            <table class="seat">
 | 
			
		||||
                <thead>
 | 
			
		||||
                    <tr>
 | 
			
		||||
                        <th> </th>
 | 
			
		||||
                        ';
 | 
			
		||||
        for($j = 1; $j <= $cols; $j++){
 | 
			
		||||
            $html .= '<th>'.$j.'</th>
 | 
			
		||||
                            ';	
 | 
			
		||||
        }
 | 
			
		||||
        $html .= '</tr>
 | 
			
		||||
                    </thead>
 | 
			
		||||
                    <tbody>';
 | 
			
		||||
            for($i = 1; $i <= $rows; $i++){
 | 
			
		||||
                    $html .= '
 | 
			
		||||
                        <tr>
 | 
			
		||||
                            <td>'.$i.'</td>
 | 
			
		||||
                            ';
 | 
			
		||||
                for($j = 1; $j <= $cols; $j++){
 | 
			
		||||
                    if($seats_map[$i][$j] >= 0){
 | 
			
		||||
                        $html .= '<td> <input type="checkbox" class="check_box" name="checkbox'.$i.$j.'" value="'.$seats_map[$i][$j].'" id="checkbox'.$i.$j.'" /> <label for="checkbox'.$i.$j.'"> </td> <!-- checked -->
 | 
			
		||||
                            ';}
 | 
			
		||||
                    else {
 | 
			
		||||
                        $html .= '<td> <input type="checkbox" class="check_box" name="checkbox'.$i.$j.'" value="'.$seats_map[$i][$j].'" id="checkbox'.$i.$j.'" disabled /> <label for="checkbox'.$i.$j.'"> </td>
 | 
			
		||||
                            ';}
 | 
			
		||||
                }
 | 
			
		||||
                    $html .='</tr>';
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
        $html .= '
 | 
			
		||||
                </tbody>
 | 
			
		||||
            </table>';
 | 
			
		||||
 | 
			
		||||
        //Pay button:
 | 
			
		||||
        $pay = '<input type="hidden" name="sessions" id="sessions" value="'.$_POST["sessions"].'" />
 | 
			
		||||
                <input type="hidden" name="code" id="code" value="'.$_POST["code"].'" />
 | 
			
		||||
                <input type="submit" id="submit" value="Pagar" />';
 | 
			
		||||
 | 
			
		||||
        return '
 | 
			
		||||
                <section class="code purchase">
 | 
			
		||||
                    '.$html.'
 | 
			
		||||
                </section>
 | 
			
		||||
                <section class="code purchase">
 | 
			
		||||
                    '.$pay.'
 | 
			
		||||
                </section>';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function procesaFormulario($datos){
 | 
			
		||||
        $result = array();
 | 
			
		||||
 | 
			
		||||
        if (count($result) === 0) {
 | 
			
		||||
            $result = "confirm.php";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										50
									
								
								root/purchase/includes/formSelectTicket.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								root/purchase/includes/formSelectTicket.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,50 @@
 | 
			
		||||
<?php
 | 
			
		||||
include_once($prefix.'assets/php/form.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/session.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/film.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema_dao.php');
 | 
			
		||||
include_once($prefix.'assets/php/includes/cinema.php');
 | 
			
		||||
 | 
			
		||||
class FormSelectTicket extends Form {
 | 
			
		||||
 | 
			
		||||
    public function __construct() {
 | 
			
		||||
        parent::__construct('formSelectTicket');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function generaCamposFormulario($datos, $errores = array()){
 | 
			
		||||
 | 
			
		||||
        // Se generan los mensajes de error si existen.
 | 
			
		||||
        $htmlErroresGlobales = self::generaListaErroresGlobales($errores);
 | 
			
		||||
        //$errorNombre = self::createMensajeError($errores, 'name', 'span', array('class' => 'error'));
 | 
			
		||||
       
 | 
			
		||||
        $html = "";
 | 
			
		||||
 | 
			
		||||
        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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
		Reference in New Issue
	
	Block a user