Add files via upload

This commit is contained in:
Fernando Méndez 2021-05-12 10:40:22 +02:00 committed by GitHub
parent b6ea25caa1
commit 1b64bce911
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 170 additions and 178 deletions

View File

@ -328,6 +328,13 @@
text-align: center;
height: 250px;
}
.code.info #register{
border: 1px solid#d3ebff;
}
.code.info #register:hover {
color: #1f2c3d;
background-color: #d3ebff;
}
.code.showtimes{
height: 600px;
}
@ -532,7 +539,7 @@
color: rgb(138, 150, 32);
}
#submit {
#submit, #register {
width: 100%;
height: 35px;
border: 1px solid #dadada;
@ -544,7 +551,7 @@
filter: brightness(105%);
cursor: pointer;
}
#submit:hover {
#submit:hover, #register:hover {
color: #dadada;
background-color: #1f2c3d;
}

View File

@ -327,6 +327,9 @@ main img {
text-align: center;
height: 250px;
}
.code.info #register{
border: 1px solid#d3ebff;
}
.code.showtimes{
height: 600px;
}
@ -526,7 +529,7 @@ textarea {
color: rgb(138, 150, 32);
}
#submit {
#submit, #register {
width: 100%;
height: 35px;
border: 1px solid #000000;
@ -538,7 +541,7 @@ textarea {
filter: brightness(105%);
cursor: pointer;
}
#submit:hover {
#submit:hover, #register:hover {
background-color: #d3ebff;
}

View File

@ -33,17 +33,18 @@
return "";
}
public static function create_session($cinema, $hall, $start, $date, $film, $price, $format,$repeat){
public static function create_session($session){
$bd = new SessionDAO('complucine');
if($bd ){
if(!$bd->searchSession($cinema, $hall, $start, $date)){
$bd->createSession(null,$film, $hall, $cinema, $date, $start, $price, $format);
if(!$bd->searchSession($session['cinema'], $session['hall'],$session['start'],$session['date'])){
$bd->createSession(null,$session['film'], $session['hall'], $session['cinema'], $session['date'],
$session['start'], $session['price'], $session['format']);
if($repeat > "0") {
$repeats = $repeat;
$repeat = $repeat - 1;
$date = date('Y-m-d', strtotime( $date . ' +1 day') );
self::create_session($cinema, $hall, $start, $date, $film, $price, $format,$repeat);
if($session['repeat'] > "0") {
$repeat = $session['repeat'];
$session['repeat'] = $session['repeat'] - 1;
$session['date'] = date('Y-m-d', strtotime( $session['date'] . ' +1 day') );
self::create_session($session);
return "Se han creado las ".$repeat ." sesiones con exito";
}
@ -55,13 +56,13 @@
} else return "Error al conectarse a la base de datos";
}
public static function edit_session($cinema, $or_hall, $or_date, $or_start, $hall, $start, $date, $film, $price, $format){
public static function edit_session($session){
$bd = new SessionDAO('complucine');
if($bd ){
if($bd->searchSession($cinema, $or_hall, $or_start, $or_date)){
$origin = array("cinema" => $cinema,"hall" => $or_hall,"start" => $or_start,"date" => $or_date);
$bd->editSession($film, $hall, $cinema, $date,
$start, $price, $format,$origin);
if($bd->searchSession($session['cinema'], $session['origin_hall'],$session['origin_start'],$session['origin_date'])){
$origin = array("cinema" => $session['cinema'],"hall" => $session['origin_hall'],"start" => $session['origin_start'],"date" => $session['origin_date']);
$bd->editSession($session['film'], $session['hall'], $session['cinema'], $session['date'],
$session['start'], $session['price'], $session['format'],$origin);
return "Se ha editado la session con exito";
} else
return "Esta session no existe";
@ -69,11 +70,11 @@
} else return "Error al conectarse a la base de datos";
}
public static function delete_session($cinema, $hall, $start, $date){
public static function delete_session($session){
$bd = new SessionDAO('complucine');
if($bd ){
if($bd->searchSession($cinema, $hall, $start, $date)){
$bd->deleteSession($hall, $cinema, $date, $start);
if($bd->searchSession($session['cinema'], $session['hall'],$session['start'],$session['date'])){
$bd->deleteSession($session['hall'], $session['cinema'], $session['date'], $session['start']);
return "Se ha eliminado la session con exito";
} else
return "Esta session no existe";

View File

@ -46,4 +46,9 @@
* @see http://php.net/manual/en/language.types.callable.php
*/
register_shutdown_function(array($app, 'shutdown'));
//Depuración (BORRAR):
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>

View File

@ -335,4 +335,9 @@ abstract class Form {
return $result;
}
//Test some form input.
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
}

View File

@ -24,12 +24,12 @@ class FormLogin extends Form {
$html = "<div class='row'>
<fieldset id='nombre_usuario'><pre>".$htmlErroresGlobales."</pre>
<legend>Nuevo Nombre de usuario</legend>
<legend>Datos Personales</legend>
<input type='text' name='name' id='name' value='' placeholder='Nombre' required/><pre>".$errorNombre."</pre>
<input type='password' name='pass' id='pass' value='' placeholder='Contraseña' required/><pre>".$errorPassword."</pre>
</fieldset>
<div class='actions'>
<input type='submit' id='submit' value='Cambiar Nombre de Usuario' class='primary' />
<input type='submit' id='submit' value='Iniciar Sesión' class='primary' />
<input type='reset' id='reset' value='Borrar' />
</div>
</div>";
@ -65,7 +65,7 @@ class FormLogin extends Form {
$_SESSION["login"] = true;
$result = 'validate.php';
} else {
$result[] = "El usuario o el password no coinciden.";
$result[] = "El usuario o el password\nno coinciden.";
}
} else {
$result[] = "Error al conectar con la BD.";
@ -75,10 +75,6 @@ class FormLogin extends Form {
return $result;
}
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
//Returns validation response:
static public function getReply() {

View File

@ -17,7 +17,7 @@
$isLogin = $view->getIsLogin();
//Forms:
require('includes/formLogin.php');
require('../register/includes/formRegister.php');
require($prefix.'register/includes/formRegister.php');
$formLogin = new FormLogin();
$htmlFormLogin = $formLogin->gestiona();
$formRegister = new FormRegister();

View File

@ -1,148 +1,107 @@
<?php
require_once($prefix.'assets/php/common/session_dao.php');
require_once($prefix.'assets/php/common/film_dao.php');
require_once($prefix.'assets/php/common/session.php');
require_once($prefix.'assets/php/form.php');
//Receive data from froms and prepare the correct response
class FormSession extends Form {
private $option;
//Constructor:
public function __construct($option) {
$this->option = $option;
$options = array("action" => "./?state=".$option);
parent::__construct('formSession',$options);
public function __construct() {
parent::__construct('formSession');
}
//TODO Edit session no funciona correctamente con el seleccionar una pelicula distinta, hay que guardar la id de la sesion de alguna forma y usarla o guardar en la sesion
protected function generaCamposFormulario($data, $errores = array()){
public static function generaCampoFormulario($data, $errores = array()){
$filmList = new Film_DAO('complucine');
$films = $filmList->allFilmData();
if($this->option == "new_session") {
$cinema = $data['cinema'] ?? $_SESSION["cinema"];
$film = $data['film'] ?? 1;
$cinema = $data['cinema'] ?? '';
$film = $data['film'] ?? '';
$hall = $data['hall'] ?? '';
$date = $data['date'] ?? '';
$start = $data['start'] ?? '';
$price = $data['price'] ?? '';
$format = $data['format'] ?? '';
}
else {
$cinema = $data['cinema'] ?? $_SESSION["cinema"];
$film = $data['film'] ?? $_POST["film"];
$hall = $data['hall'] ?? $_POST["hall"];
$date = $data['date'] ?? $_POST["date"];
$start = $data['start'] ?? $_POST["start"];
$price = $data['price'] ?? $_POST["price"];
$format = $data['format'] ?? $_POST["format"];
}
$or_hall = $data["or_hall"] ?? $hall;
$or_date = $data["or_date"] ?? $date;
$or_start = $data["or_start"] ?? $start;
$htmlErroresGlobales = self::generaListaErroresGlobales($errores);
$html .= '<div class="column left">
'.$htmlErroresGlobales.'
$htmlform .= '<div class="column left">
<form method="post" id="'.$data['option'].'" action="./includes/processForm.php"\>
<fieldset>
<legend>Datos</legend>
<input type="number" step="0.01" name="price" value="'.$price.'" min="0" placeholder="Precio de la entrada" required/> <br>
<input type="text" name="format" value="'.$format.'" placeholder="Formato de pelicula" required/> <br>
<input type="hidden" name="film" value="'.$film.'"/>
<input type="hidden" name="film" value="'.$film["idfilm"].'"/>
<select name="hall" class="button large">';
foreach(Hall::getListHalls($cinema) as $hll){
if($hll->getNumber() == $hall){
$html.= '
$htmlform.= '
<option value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> ';
}else{
$html.= '
$htmlform.= '
<option value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>';
}
}
$html.= '
$htmlform.= '
</select>
<input type="hidden" name="or_hall" value="'.$or_hall.'"/>
</fieldset>
<fieldset>
<legend>Horario</legend>
<input type="time" name="start" value="'.$start.'" placeholder="Hora de inicio" required/> <br>
<input type="hidden" name="or_start" value="'.$or_start.'"/>
<input type="date" name="date" value="'.$date.'" placeholder="Fecha de inicio" required/> <br>
<input type="hidden" name="or_date" value="'.$or_date.'"/>
</fieldset>
';
if($film){
if($this->option == "new_session")
$html .= '<input type="number" name="repeat" value="" min="0" title="Añadir esta sesion durante los proximos X dias" min="0" max="31" placeholder="Añadir X dias"/> <br>
<button type="submit" id="submit" name="sumbit" class="button large">Crear</button><br>';
if($data['option'] == "new_session")
$htmlform .= '<input type="number" name="repeat" value="" min="0" title="Añadir esta sesion durante los proximos X dias" min="0" max="31" placeholder="Añadir X dias"/> <br>
<button type="submit" name="new_session" class="button large">Crear</button><br>';
if($this->option == "edit_session"){
$html .= '
<button type="submit" id="submit" name="sumbit" class="button large">Editar</button><br>
<button type="submit" id="submit" name="delete" class="primary">Borrar</button><br>';
if($data['option'] == "edit_session"){
if(!$_SESSION["or_hall"]) $_SESSION["or_hall"] = $hall;
if(!$_SESSION["or_date"]) $_SESSION["or_date"] = $date;
if(!$_SESSION["or_start"])$_SESSION["or_start"] = $start;
$htmlform .= '
<button type="submit" name="edit_session" class="button large">Editar</button><br>
<button type="submit" name="delete_session" class="primary">Borrar</button><br>';
}
}
$html .= '
<input type="reset" value="Limpiar Campos" >
$htmlform .= "
<input type='reset' value='Limpiar Campos' >
</form>
</div>
<div class="column side">
<select name="film" class="button large">';
foreach($films as $f){
if($f->getId() == $film){
$html .= "<option value=\"". $f->getId() ." \"selected> " . $f->getId() . "|" . $f->getTittle() ." Idioma: " . $f->getLanguage() . "</option>";
}else{
$html .= "<option value=\"". $f->getId() ." \"> " . $f->getId() . "|" . $f->getTittle() ." Idioma: " . $f->getLanguage() . "</option>";
<div class='column side'>";
if($film["tittle"]){
$htmlform .= " <section id='".$film["tittle"]."'>
<div class='code showtimes'>
<div class='image'><img src='../img/".$film["tittle"].".jpg' alt='".$film["tittle"]."' /></div>
<h2>".str_replace('_', ' ',$film["tittle"])."</h2>
<hr />
<div class='blockquote'>
<p>".$film["description"]."</p>
</div>
<p>Duración: ".$film["duration"]." minutos</p>
</div>
</section>
";
}
}
return $html;
$htmlform .= '<button type="submit" name="select_films" form="'.$data['option'].'" formaction="?state=select_film&option='.$data['option'].'" class="button large">Seleccionar una Pelicula</button><br>
</div>
';
return $htmlform;
}
//Methods:
//Process form:
protected function procesaFormulario($data){
$result = array();
$film = $data['film'] ;
$hall = $data['hall'] ;
$date = $data['date'] ;
$start = $data['start'];
$price = $data['price'] ;
$format = $data['format'] ?? null ;
$repeat = $data['repeat'] ?? 0;
$or_hall = $data["or_hall"] ;
$or_date = $data["or_date"] ;
$or_start = $data["or_start"] ;
if (($price == 0 || empty($price))&& isset($data["sumbit"]) ) {
$result['price'] = "<li> No puede haber 0 euros. </li> <br>";
public static function processesForm($data){
if($data["option"] == "new_session"){
$_SESSION['msg'] = Session::create_session($data);
header( "Location: ../?state=success" );
}else if($data["option"] == "edit_session"){
$_SESSION['msg'] = Session::edit_session($data);
header( "Location: ../?state=success" );
}
if (empty($format) && isset($data["sumbit"])) {
$result['format'] = "<li> El formato no puede estar vacio. </li> <br>";
else if($data["option"] == "delete_session") {
$_SESSION['msg'] = Session::delete_session($data);
header( "Location: ../?state=success" );
}
if (count($result) === 0 && isset($data["sumbit"]) ) {
if($this->option == "new_session"){
$_SESSION['msg'] = Session::create_session($_SESSION["cinema"], $hall, $start, $date, $film, $price, $format,$repeat);
$result = './?state=success';
}
if($this->option == "edit_session"){
$_SESSION['msg'] = Session::edit_session($_SESSION["cinema"], $or_hall, $or_date, $or_start, $hall, $start, $date, $film, $price, $format);
$result = './?state=success';
}
}
if(!isset($result['hall']) && !isset($result['start']) && !isset($result['date']) && isset($data["delete"])) {
$_SESSION['msg'] = Session::delete_session($_SESSION["cinema"], $or_hall, $or_start, $or_date);
$result = './?state=success';
}
return $result;
}
}

View File

@ -1,4 +1,8 @@
<?php
ini_set('display_errors', 0);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
//General Config File:
require_once('../assets/php/config.php');
//Controller file:

View File

@ -183,18 +183,48 @@
}
static function new_session(){
$formSession = new FormSession("new_session");
echo "inicio";
if(isset($_POST["new_session"])){
$data = array("option" => "new_session","hall" => $_POST['hall'],"cinema" => $_SESSION["cinema"],"date" => $_POST['date']);
}else if(isset($_POST["select_film"])){
$film = array("idfilm" => $_POST["id"],"tittle" => $_POST["tittle"], "description" => $_POST["description"], "duration" => $_POST["duration"]);
$data = array("option" => "new_session","hall" => $_POST['hall'],"cinema" => $_SESSION["cinema"],"date" => $_POST['date'],"film" => $film, "start" => $_POST['start']
, "price" => $_POST['price'], "format" => $_POST['format']);
}
if($data){
$panel = '<h1>Crear una sesión.</h1><hr /></br>
'.FormSession::generaCampoFormulario($data, null);
}else $panel = self::warning();
$panel = '<h1>Crear una sesion.</h1><hr/></br>'
.$formSession->gestiona();
return $panel;
}
static function edit_session(){
$formSession = new FormSession("edit_session");
if(isset($_POST["edit_session"])){
$panel = '<h1>Editar una sesion.</h1><hr/></br>'
.$formSession->gestiona();
$_SESSION["or_hall"] = "";
$_SESSION["or_date"] = "";
$_SESSION["or_start"] = "";
$film = Session::getThisSessionFilm($_POST["film"]);
$data = array("option" => "edit_session","hall" => $_POST["hall"],"cinema" => $_SESSION["cinema"],"date" => $_POST['date'],"film" => $film,
"start" => $_POST['start'],"price" => $_POST['price'],"format" => $_POST['format']);
}else if(isset($_SESSION["session"])){
$film = array("idfilm" => $_POST["id"],"tittle" => $_POST["tittle"], "description" => $_POST["description"], "duration" => $_POST["duration"]);
$data = array("option" => "edit_session","hall" => $_POST['hall'],"cinema" => $_SESSION["cinema"],"date" => $_POST['date'],"film" => $film, "start" => $_POST['start']
, "price" => $_POST['price'], "format" => $_POST['format']);
}
if($data){
$panel = '<h1>Editar una sesión.</h1><hr /></br>
'.FormSession::generaCampoFormulario($data, null);
} else $panel = self::warning();
return $panel;
}

View File

@ -40,17 +40,17 @@ class FormChangeEmail extends Form {
protected function procesaFormulario($datos){
$result = array();
$email = $datos['new_email'] ?? null;
$email = $this->test_input($datos['new_email']) ?? null;
if ( empty($email) || !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $email) ) {
$result['new_email'] = "El nuevo email no es válido.";
}
$email2 = $datos['remail'] ?? null;
$email2 = $this->test_input($datos['remail']) ?? null;
if ( empty($email2) || strcmp($email, $email2) !== 0 ) {
$result['remail'] = "Los emails deben coincidir";
}
$password = $datos['pass'] ?? null;
$password = $this->test_input($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.";
}

View File

@ -38,18 +38,18 @@ class FormChangeName extends Form {
protected function procesaFormulario($datos){
$result = array();
$nombre = $datos['new_name'] ?? null;
$nombre = $this->test_input($datos['new_name']) ?? null;
$nombre = strtolower($nombre);
if ( empty($nombre) || mb_strlen($nombre) < 3 || mb_strlen($nombre) > 8 ) {
$result['new_name'] = "El nombre tiene que tener\n una longitud de al menos\n 3 caracteres\n y menos de 8 caracteres.";
}
$nombre2 = $datos['rename'] ?? null;
$nombre2 = $this->test_input($datos['rename']) ?? null;
if ( empty($nombre2) || strcmp($nombre, $nombre2) !== 0 ) {
$result['rename'] = "Los nombres deben coincidir.";
}
$password = $datos['pass'] ?? null;
$password = $this->test_input($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.";
}
@ -99,9 +99,5 @@ class FormChangeName extends Form {
}
return $result;
}
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
}
?>

View File

@ -36,16 +36,16 @@ class FormChangePass extends Form {
protected function procesaFormulario($datos){
$result = array();
$old_pass = $datos['old_pass'] ?? null;
$old_pass = $this->test_input($datos['old_pass']) ?? null;
if ( empty($old_pass) || mb_strlen($old_pass) < 4 ) {
$result['old_pass'] = "El password tiene que tener\n una longitud de al menos\n 4 caracteres.";
}
$password = $datos['pass'] ?? null;
$password = $this->test_input($datos['pass']) ?? null;
if ( empty($password) || mb_strlen($password) < 4 ) {
$result['pass'] = "El password tiene que tener una\n longitud de al menos\n 4 caracteres.";
}
$password2 = $datos['repass'] ?? null;
$password2 = $this->test_input($datos['repass']) ?? null;
if ( empty($password2) || strcmp($password, $password2) !== 0 ) {
$result['repass'] = "Los passwords deben coincidir.";
}
@ -87,9 +87,5 @@ class FormChangePass extends Form {
}
return $result;
}
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
}
?>

View File

@ -46,22 +46,22 @@ class FormDeleteAccount extends Form {
protected function procesaFormulario($datos){
$result = array();
$nombre = $datos['name'] ?? null;
$nombre = $this->test_input($datos['name']) ?? null;
$nombre = strtolower($nombre);
if ( empty($nombre) || mb_strlen($nombre) < 3 || mb_strlen($nombre) > 8 ) {
$result['new_name'] = "El nombre tiene que tener\n una longitud de al menos\n 3 caracteres\n y menos de 8 caracteres.";
}
$email = $datos['email'] ?? null;
$email = $this->test_input($datos['email']) ?? null;
if ( empty($email) || !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $email) ) {
$result['email'] = "El email no es válido.";
}
$password = $datos['pass'] ?? null;
$password = $this->test_input($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.";
}
$password2 = $datos['repass'] ?? null;
$password2 = $this->test_input($datos['repass']) ?? null;
if ( empty($password2) || strcmp($password, $password2) !== 0 ) {
$result['repass'] = "Los passwords deben coincidir.";
}
@ -87,9 +87,5 @@ class FormDeleteAccount extends Form {
}
return $result;
}
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
}
?>

View File

@ -12,8 +12,7 @@ class FormRegister extends Form {
//Constructor:
public function __construct() {
$options = array("action" => "../register/register.php");
parent::__construct('formRegister', $options);
parent::__construct('formRegister');
}
//Methods:
@ -41,7 +40,7 @@ class FormRegister extends Form {
<label for='terms'><a href ='../fdicines/terms_conditions/' target='_blank'>Marque esta casilla para verificar que ha leído nuestros términos y condiciones del servicio.</a></label>
</div>
<div class='actions'>
<input type='submit' id='submit' value='Registrarse' class='primary' />
<input type='submit' name='register' id='register' value='Registrarse' class='primary' />
<input type='reset' id='reset' value='Borrar' />
</div>
</div>";
@ -85,11 +84,11 @@ class FormRegister extends Form {
$_SESSION["nombre"] = $this->user->getName();
$_SESSION["rol"] = $this->user->getRol();
$_SESSION["login"] = true;
$result = '../register/register.php';
$result = "../register/register.php";
}
}
else{
$result[] = "El nombre de usuario ya existe.";
$result[] = "El usuario ya existe.";
}
} else {
$result[] = "Error al conectar con la BD.";
@ -111,9 +110,8 @@ class FormRegister extends Form {
<a href='../../panel_{$_SESSION["rol"]}'><button>Mi Panel</button></a>\n";
}
else if(!isset($_SESSION["login"])){
$reply = "<h1>ERROR</h1><hr />".
"<p>Ha ocurrido un problema y no hemos podido completar el registro.</p>
<p>Puede que el nombre de usuario ya esté registrado.</p>
$reply = "<h1>ERROR</h1><hr />
<p>Ha ocurrido un problema y no hemos podido completar el registro</p>
<p>Vuelve a intetarlo o inicia sesión si tienes una cuenta de usuario.</p>
<a href='../login/'><button>Iniciar Sesión</button></a>
<form method='post' action='../login/'><button name='register' id='register'>Registro</button></form>\n";
@ -122,9 +120,5 @@ class FormRegister extends Form {
return $reply;
}
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
}
?>

View File

@ -4,8 +4,6 @@
//Login form validate:
require_once('./includes/formRegister.php');
//$register = new FormRegister();
//$register->processesForm($_POST["name"], $_POST["email"], $_POST["pass"], $_POST["repass"]);
$reply = FormRegister::getReply();
?>
@ -38,6 +36,8 @@
<div class="code info">
<?php
echo $reply;
//$formRegister = new FormRegister();
//echo $htmlFormRegister = $formRegister->gestiona();
?>
</div>
</div>