2021-05-13 11:27:17 +02:00
|
|
|
<?php
|
|
|
|
//General Config File:
|
|
|
|
include_once('../assets/php/config.php');
|
|
|
|
include_once('../assets/php/common/cinema_dao.php');
|
|
|
|
include_once('../assets/php/common/cinema.php');
|
|
|
|
include_once('../assets/php/form.php');
|
|
|
|
|
|
|
|
class formAddCinema extends Form{
|
|
|
|
|
|
|
|
public function __construct(){
|
2021-05-13 12:39:12 +02:00
|
|
|
$op = array("action"=>"./?state=mc");
|
2021-05-13 11:39:54 +02:00
|
|
|
parent::__construct('formAddCinema',$op);
|
2021-05-13 11:27:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function generaCamposFormulario($datos,$errores=array()){
|
|
|
|
|
|
|
|
$htmlErroresGlobales = self::generaListaErroresGlobales($errores);
|
|
|
|
$errorName = self::createMensajeError($errores,'name','span',array('class'=>'error'));
|
|
|
|
$errorDirection = self::createMensajeError($errores,'direction','span',array('class'=>'error'));
|
|
|
|
$errrorPhone = self ::createMensajeError($errores,'phone',array('class'=>'error'));
|
|
|
|
|
2021-05-13 11:39:54 +02:00
|
|
|
$html = '<div class="row"></div>
|
2021-05-13 11:27:17 +02:00
|
|
|
<fieldset id = "cinema_form">'.$htmlErroresGlobales.'</pre>
|
|
|
|
<legend>Añadir cine</legend>
|
|
|
|
<input type="text" name="name" id="name" placeholder="Nombre" required/><pre>'.$errorName.'</pre>
|
|
|
|
<input type="text" name="direction" id="direction" placeholder="Direccion" required/><pre>'.$errorDirection.'</pre>
|
|
|
|
<input type="text" name="phone" id="phone" placeholder="Teléfono" required/><pre>'.$errrorPhone.'</pre>
|
|
|
|
</fieldset>
|
|
|
|
<div class="actions">
|
2021-05-13 17:37:09 +02:00
|
|
|
<input type="submit" id="submit" value="Añadir cine" class="primary" />
|
2021-05-13 11:27:17 +02:00
|
|
|
<input type="reset" id="reset" value="Borrar" />
|
|
|
|
</div>
|
|
|
|
</div> ';
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Process form:
|
|
|
|
public function procesaFormulario($datos) {
|
|
|
|
$result =array();
|
|
|
|
|
|
|
|
$name = $this->test_input($datos['name'])??null;
|
|
|
|
|
|
|
|
if(empty($name)){
|
|
|
|
$result['name']= "El nombre no es válido";
|
|
|
|
}
|
|
|
|
|
|
|
|
$direction = $this -> test_input($datos['direction']) ?? null;
|
|
|
|
|
|
|
|
if(empty($direction)){
|
|
|
|
$result['direction'] = "La dirección no es valida";
|
|
|
|
}
|
|
|
|
|
|
|
|
$phone = $this -> test_input($datos['phone']) ?? null;
|
|
|
|
|
|
|
|
if(empty($phone)){
|
|
|
|
$result['phone'] = "El teléfono no es valido";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(count($result)===0){
|
|
|
|
|
|
|
|
$bd = new Cinema_DAO('complucine');
|
|
|
|
$exist = $bd -> GetCinema($name,$direction);
|
|
|
|
if(mysqli_num_rows($exist)!=0){
|
|
|
|
$result[] = "Ya existe un cine con ese nombre o dirección";
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$bd->createCinema(null,$name,$direction,$phone);
|
|
|
|
$_SESSION['message'] = "<div class='row'>
|
|
|
|
<div class='column side'></div>
|
|
|
|
<div class='column middle'>
|
|
|
|
<div class='code info'>
|
|
|
|
<h1> Operacion realizada con exito </h1><hr />
|
|
|
|
<p> Se ha añadido el cine correctamente en la base de datos.</p>
|
|
|
|
<a href='../panel_admin/index.php?state=mc'><button>Cerrar Mensaje</button></a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class='column side'></div>
|
|
|
|
</div>
|
|
|
|
";
|
|
|
|
$result = './?state=mc';
|
|
|
|
}
|
|
|
|
$exist->free();
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function test_input($input){
|
|
|
|
return htmlspecialchars(trim(strip_tags($input)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|