Add files via upload

This commit is contained in:
Fernando Méndez 2021-05-30 21:52:43 +02:00 committed by GitHub
parent 8d21c86642
commit 4a7f89bdbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 89 additions and 14 deletions

View File

@ -6,6 +6,9 @@
//Expresión regular para validar nombre y apellidos: //Expresión regular para validar nombre y apellidos:
const regExpr = /^([A-Za-zÁÉÍÓÚñáéíóúÑ]{0}?[A-Za-zÁÉÍÓÚñáéíóúÑ\']+[\s])+([A-Za-zÁÉÍÓÚñáéíóúÑ]{0}?[A-Za-zÁÉÍÓÚñáéíóúÑ\'])+[\s]?([A-Za-zÁÉÍÓÚñáéíóúÑ]{0}?[A-Za-zÁÉÍÓÚñáéíóúÑ\'])?$/g; const regExpr = /^([A-Za-zÁÉÍÓÚñáéíóúÑ]{0}?[A-Za-zÁÉÍÓÚñáéíóúÑ\']+[\s])+([A-Za-zÁÉÍÓÚñáéíóúÑ]{0}?[A-Za-zÁÉÍÓÚñáéíóúÑ\'])+[\s]?([A-Za-zÁÉÍÓÚñáéíóúÑ]{0}?[A-Za-zÁÉÍÓÚñáéíóúÑ\'])?$/g;
//Expresión regular para validar un código promocional:
const refExprCode = /^0?[xX]?[0-9a-fA-F]*$/;
$(document).ready(function() { $(document).ready(function() {
//Iconos para validar el titular de la tarjeta: //Iconos para validar el titular de la tarjeta:
@ -20,6 +23,10 @@ $(document).ready(function() {
$("#cvvValid").hide(); $("#cvvValid").hide();
$("#cvvInvalid").hide(); $("#cvvInvalid").hide();
//Iconos para validar el código promocional:
$("#codeValid").hide();
$("#codeInvalid").hide();
//Comprueba que el titular de la tarjeta es válido. //Comprueba que el titular de la tarjeta es válido.
$("#card-holder").change(function(){ $("#card-holder").change(function(){
@ -118,14 +125,46 @@ $(document).ready(function() {
$("#cvvInvalid").hide(); $("#cvvInvalid").hide();
cvv[0].setCustomValidity(""); cvv[0].setCustomValidity("");
} else { } else {
$("#carcvvValiddNameValid").hide(); $("#cvvValid").hide();
$("#cvvInvalid").show(); $("#cvvInvalid").show();
cvv[0].setCustomValidity("El CVV debe tener 3 dígitos."); cvv[0].setCustomValidity("El CVV debe tener 3 dígitos.");
} }
}); });
//Comprueba el código promocional introducido:
$("#code").change(function(){
var url = "../assets/php/common/checkPromo.php?code=" + $("#code").val();
$.get(url, codeCheck);
});
//Devuelve true si el nombre y apellidos del titular son válidos, false en caso contrario. //Devuelve true si el nombre y apellidos del titular son válidos, false en caso contrario.
function holderCheck(name) { function holderCheck(name) {
return regExpr.test(name) ? true : false; return regExpr.test(name) ? true : false;
} }
})
//Devuelve true si el código promocional es válido, false en caso contrario.
function holderCheck(code) {
return regExprCode.test(code) ? true : false;
}
//Muestra si el código promocional introducido existe o no.
function codeCheck(data, status) {
const code = $("#code");
code[0].setCustomValidity("");
if(code.val().length === 8 && data === "avaliable"){
$("#codeValid").show();
$("#codeInvalid").hide();
code[0].setCustomValidity("");
} else if(code.val().length > 0 ){
$("#codeValid").hide();
$("#codeInvalid").show();
code[0].setCustomValidity("El código promocional no es válido.");
} else if(code.val().length === 0 ){
$("#codeValid").hide();
$("#codeInvalid").hide();
code[0].setCustomValidity("");
}
}
});

View File

@ -0,0 +1,15 @@
<?php
include('../../../assets/php/config.php');
include('../includes/promotion_dao.php');
$bd = new Promotion_DAO('complucine');
if($bd){
$promo = $bd->GetPromotionObj($_GET["code"]);
if ($promo && $promo->getActive()) {
echo "avaliable";
}
else{
echo "!avaliable";
}
}
?>

View File

@ -27,7 +27,7 @@
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
while($fila=$resul->fetch_assoc()){ while($fila=$resul->fetch_assoc()){
$promotions[] = $this->loadPromotion($fila["id"], $fila["tittle"], $fila["description"], $fila["code"], $fila["active"], $fila["img"],); $promotions[] = $this->loadPromotion($fila["id"], $fila["tittle"], $fila["description"], $fila["code"], $fila["active"], $fila["img"]);
} }
$resul->free(); $resul->free();
return $promotions; return $promotions;
@ -77,6 +77,20 @@
return $resul; return $resul;
} }
//Returns a film data .
public function GetPromotionObj($code){
$sql = sprintf( "SELECT * FROM promotion WHERE promotion.code = '%s'", $code );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
$promo = null;
while($fila = $resul->fetch_assoc()){
$promo = $this->loadPromotion($fila["id"], $fila["tittle"], $fila["description"], $fila["code"], $fila["active"], $fila["img"]);
}
$resul->free();
return $promo;
}
//Create a new film Data Transfer Object. //Create a new film Data Transfer Object.
public function loadPromotion($id, $tittle, $description, $code, $active, $img){ public function loadPromotion($id, $tittle, $description, $code, $active, $img){
return new Promotion($id, $tittle, $description, $code, $active, $img); return new Promotion($id, $tittle, $description, $code, $active, $img);

View File

@ -89,19 +89,16 @@ class FormPurchase extends Form {
</fieldset> </fieldset>
<fieldset id='pagar_entrada'><pre>".$htmlErroresGlobales."</pre> <fieldset id='pagar_entrada'><pre>".$htmlErroresGlobales."</pre>
<legend>Datos Bancarios</legend> <legend>Datos Bancarios</legend>
<label for='card-holder'>Titular de la Tarjeta:</label><pre>".$errorNombre."</pre><br /> <label for='card-holder'>Titular de la Tarjeta: <span id='cardNameValid'>&#x2714;</span><span id='cardNameInvalid'>&#x274C;</span></label><pre>".$errorNombre."</pre><br />
<input type='text' name='card-holder' id='card-holder' class='card-holder' placeholder='NOMBRE APELLIDO1 APELLIDO2' required /> <input type='text' name='card-holder' id='card-holder' class='card-holder' placeholder='NOMBRE APELLIDO1 APELLIDO2' required />
<span id='cardNameValid'>&#x2714;</span><span id='cardNameInvalid'>&#x274C;</span>
<br /> <br />
<label for='card-number'>Número de Tarjeta: </label><pre>".$errorCardNumber."</pre><br /> <label for='card-number'>Número de Tarjeta: <span id='carNumberValid'>&#x2714;</span><span id='cardNumerInvalid'>&#x274C;</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-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-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-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 /> <input type='num' name='card-number-3' id='card-number-3' class='input-cart-number' placeholder='XXXX' maxlength='4' required />
<span id='carNumberValid'>&#x2714;</span><span id='cardNumerInvalid'>&#x274C;</span> <label for='card-cvv'>CVV: <span id='cvvValid'>&#x2714;</span><span id='cvvInvalid'>&#x274C;</span></label>
<label for='card-cvv'>CVV: </label>
<input type='text' name='card-cvv' id='card-cvv' class='fieldset-cvv' maxlength='3' placeholder='XXX' required /><pre>".$errorCVV."</pre> <input type='text' name='card-cvv' id='card-cvv' class='fieldset-cvv' maxlength='3' placeholder='XXX' required /><pre>".$errorCVV."</pre>
<span id='cvvValid'>&#x2714;</span><span id='cvvInvalid'>&#x274C;</span>
<br /> <br />
<label for='card-expiration'>Fecha de Expiración:</label><pre>".$errorCardExpirationMonth.$errorCardExpirationYear."</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> <select name='card-expiration-month' id='card-expiration-month' required>

View File

@ -32,10 +32,11 @@ class FormSelectCinemaSession extends Form {
$cinemas = []; $cinemas = [];
$sessions = []; $sessions = [];
// Se generan los mensajes de error si existen. // Se generan los mensajes de error, si existen.
$htmlErroresGlobales = self::generaListaErroresGlobales($errores); $htmlErroresGlobales = self::generaListaErroresGlobales($errores);
$errorCinema = self::createMensajeError($errores, 'cinemas', 'span', array('class' => 'error')); $errorCinema = self::createMensajeError($errores, 'cinemas', 'span', array('class' => 'error'));
$errorSession = self::createMensajeError($errores, 'sessions', 'span', array('class' => 'error')); $errorSession = self::createMensajeError($errores, 'sessions', 'span', array('class' => 'error'));
$errorCode = self::createMensajeError($errores, 'code', 'span', array('class' => 'error'));
$pay = true; $pay = true;
if(isset($_GET["film"])){ if(isset($_GET["film"])){
@ -58,8 +59,8 @@ class FormSelectCinemaSession extends Form {
$cinemasIT->attachIterator($cinemasIDs, "cID"); $cinemasIT->attachIterator($cinemasIDs, "cID");
$cinemasIT->attachIterator($cinemasNames, "NAME"); $cinemasIT->attachIterator($cinemasNames, "NAME");
$cinemasListHTML = '<section id="select_cinema"> $cinemasListHTML = '<section id="select_cinema"><pre>'.$htmlErroresGlobales.'</pre>
<select name="cinemas" id="cinemas">'; <select name="cinemas" id="cinemas"><pre>'.$errorCinema.'</pre>';
if(!isset($cinema_id)){ if(!isset($cinema_id)){
$cinemasListHTML .= '<option value="" selected>Selecciona un cine</option>'; $cinemasListHTML .= '<option value="" selected>Selecciona un cine</option>';
foreach($cinemasIT as $value){ foreach($cinemasIT as $value){
@ -103,7 +104,7 @@ class FormSelectCinemaSession extends Form {
$sessionsIT->attachIterator($sessionsStarts, "HOUR"); $sessionsIT->attachIterator($sessionsStarts, "HOUR");
$count = 0; $count = 0;
$sessionsListHTML = '<select name="sessions" id="sessions">'; $sessionsListHTML = '<select name="sessions" id="sessions"><pre>'.$errorSession.'</pre>';
foreach ($sessionsIT as $value) { foreach ($sessionsIT as $value) {
if($this->_TODAY <= $value["DATE"]){ if($this->_TODAY <= $value["DATE"]){
if($value === reset($sessionsIT)){ if($value === reset($sessionsIT)){
@ -142,6 +143,9 @@ class FormSelectCinemaSession extends Form {
'.$cinemasListHTML.' '.$cinemasListHTML.'
<h3>Sesiones</h3> <h3>Sesiones</h3>
'.$sessionsListHTML.' '.$sessionsListHTML.'
<h3>Aplicar código promocional<span id="codeValid">&#x2714;</span><span id="codeInvalid">&#x274C;</span></h3>
<input type="text" name="code" id="code" value="" placeholder="Código pormocional" /><pre>'.$errorPromo.'</pre>
</div>'; </div>';
} else { } else {
$html = '<h1>No existe la película.</h1>'; $html = '<h1>No existe la película.</h1>';
@ -182,6 +186,12 @@ class FormSelectCinemaSession extends Form {
$result['sessions'] = "Selecciona una sesión."; $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) { if (count($result) === 0) {
$result = "confirm.php"; $result = "confirm.php";
} }

View File

@ -19,5 +19,5 @@
//General page content: //General page content:
require RAIZ_APP.'/HTMLtemplate.php'; require RAIZ_APP.'/HTMLtemplate.php';
//TO-DO: añadir elegir promociones y enviar con el POST. //TO-DO: añadir selección de butaca y elegir promociones y enviar con el POST.
?> ?>