Add files via upload
This commit is contained in:
@ -6,15 +6,22 @@ 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 $film; // Film to be purchased.
|
||||
private $years; // Actual year.
|
||||
private $months; // Months of the year.
|
||||
private $_TODAY; // Actual date.
|
||||
|
||||
public function __construct() {
|
||||
//$options = array("action" => $_SERVER['PHP_SELF']);
|
||||
@ -29,9 +36,14 @@ class FormPurchase extends Form {
|
||||
$cinemaDAO = new Cinema_DAO("complucine");
|
||||
$this->cinema = $cinemaDAO->cinemaData($this->session->getIdcinema());
|
||||
|
||||
$hallDAO = new HallDAO("complucine");
|
||||
$this->hall = $hallDAO->HallData($this->session->getIdhall());
|
||||
|
||||
$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);
|
||||
|
||||
@ -44,6 +56,10 @@ class FormPurchase extends Form {
|
||||
// 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){
|
||||
@ -55,7 +71,13 @@ class FormPurchase extends Form {
|
||||
$yearsHTML .= "<option>".$value."</option>";
|
||||
}
|
||||
|
||||
$html = "<div class='row'>
|
||||
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()."' />
|
||||
@ -70,16 +92,19 @@ class FormPurchase extends Form {
|
||||
<legend>Datos Bancarios</legend>
|
||||
<label for='card-holder'>Titular de la Tarjeta:</label><pre>".$errorNombre."</pre><br />
|
||||
<input type='text' name='card-holder' id='card-holder' class='card-holder' placeholder='NOMBRE APELLIDO1 APELLIDO2' required />
|
||||
<span id='cardNameValid'>✔</span><span id='cardNameInvalid'>❌</span>
|
||||
<br />
|
||||
<label for='card-number'>Número de Tarjeta: </label><br />
|
||||
<label for='card-number'>Número de Tarjeta: </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 />
|
||||
<span id='carNumberValid'>✔</span><span id='cardNumerInvalid'>❌</span>
|
||||
<label for='card-cvv'>CVV: </label>
|
||||
<input type='text' name='card-cvv' id='card-cvv' class='fieldset-cvv' maxlength='3' placeholder='XXX' required />
|
||||
<input type='text' name='card-cvv' id='card-cvv' class='fieldset-cvv' maxlength='3' placeholder='XXX' required /><pre>".$errorCVV."</pre>
|
||||
<span id='cvvValid'>✔</span><span id='cvvInvalid'>❌</span>
|
||||
<br />
|
||||
<label for='card-expiration'>Fecha de Expiración:</label><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>
|
||||
@ -93,7 +118,7 @@ class FormPurchase extends Form {
|
||||
<input type='reset' id='reset' value='Borrar' />
|
||||
</div>
|
||||
</div>";
|
||||
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
@ -105,9 +130,44 @@ class FormPurchase extends Form {
|
||||
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) {
|
||||
$result[] = "La compra aun está en desarrollo. Vuelva en unos días.";
|
||||
if(isset($_SESSION["login"]) && $_SESSION["login"] == true){
|
||||
$purchaseDAO = new PurchaseDAO("complucine");
|
||||
$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 {
|
||||
$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;
|
||||
|
Reference in New Issue
Block a user