2021-05-17 15:29:29 +02:00
< ? php
2021-05-20 15:29:49 +02:00
require_once ( $prefix . 'assets/php/includes/session_dao.php' );
require_once ( $prefix . 'assets/php/includes/session.php' );
2021-05-17 15:29:29 +02:00
require_once ( $prefix . 'assets/php/form.php' );
//Receive data from froms and prepare the correct response
class FormSession extends Form {
private $option ;
private $cinema ;
2021-05-20 11:45:16 +02:00
private $formID ;
2021-05-17 15:29:29 +02:00
//Constructor:
public function __construct ( $option , $cinema ) {
$this -> option = $option ;
$this -> cinema = $cinema ;
2021-05-20 11:45:16 +02:00
$this -> formID = 'formSession1' ;
2021-05-17 15:29:29 +02:00
$options = array ( " action " => " ./?state= " . $option );
parent :: __construct ( 'formSession' , $options );
}
//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 ()){
2021-05-20 11:45:16 +02:00
$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 " ] ? ? " " ;
2021-05-17 15:29:29 +02:00
$or_hall = $data [ " or_hall " ] ? ? $hall ;
$or_date = $data [ " or_date " ] ? ? $date ;
$or_start = $data [ " or_start " ] ? ? $start ;
2021-05-20 11:45:16 +02:00
$film = $data [ 'film' ] ? ? $_POST [ " film " ] ? ? " " ;
$tittle = $data [ 'tittle' ] ? ? $_POST [ " tittle " ] ? ? " " ;
$duration = $data [ 'duration' ] ? ? $_POST [ " duration " ] ? ? " " ;
$language = $data [ 'language' ] ? ? $_POST [ " language " ] ? ? " " ;
$description = $data [ 'description' ] ? ? $_POST [ " description " ] ? ? " " ;
2021-05-17 15:29:29 +02:00
$htmlErroresGlobales = self :: generaListaErroresGlobales ( $errores );
$errorPrice = self :: createMensajeError ( $errores , 'price' , 'span' , array ( 'class' => 'error' ));
$errorFormat = self :: createMensajeError ( $errores , 'format' , 'span' , array ( 'class' => 'error' ));
2021-05-20 11:45:16 +02:00
$errorDate = self :: createMensajeError ( $errores , 'date' , 'span' , array ( 'class' => 'error' ));
$errorStart = self :: createMensajeError ( $errores , 'start' , 'span' , array ( 'class' => 'error' ));
2021-05-17 15:29:29 +02:00
$html = '
2021-05-20 11:45:16 +02:00
< div class = " column left " > '.$htmlErroresGlobales.'
2021-05-17 15:29:29 +02:00
< fieldset >
< legend > Datos </ legend >
2021-05-20 11:45:16 +02:00
'.$errorPrice.'
< input type = " number " step = " 0.01 " name = " price " value = " '. $price .' " min = " 0 " placeholder = " Precio de la entrada " /> < br > '
. $errorFormat . '
< input type = " text " name = " format " value = " '. $format .' " placeholder = " Formato de pelicula " /> < br >
2021-05-17 15:29:29 +02:00
< input type = " hidden " name = " film " value = " '. $film .' " />
2021-05-20 11:45:16 +02:00
< input type = " hidden " name = " option " value = " '. $this->option .' " />
2021-05-17 15:29:29 +02:00
< select name = " hall " class = " button large " > ' ;
foreach ( Hall :: getListHalls ( $this -> cinema ) as $hll ){
if ( $hll -> getNumber () == $hall ){
$html .= '
< option value = " '. $hll->getNumber () .' " selected > Sala '. $hll->getNumber() .' </ option > ' ;
} else {
$html .= '
< option value = " '. $hll->getNumber () .' " > Sala '. $hll->getNumber() .' </ option > ' ;
}
}
$html .= '
</ select >
< input type = " hidden " name = " or_hall " value = " '. $or_hall .' " />
</ fieldset >
< fieldset >
< legend > Horario </ legend >
2021-05-20 11:45:16 +02:00
'.$errorStart.'
< input type = " time " name = " start " value = " '. $start .' " placeholder = " Hora de inicio " /> < br >
2021-05-17 15:29:29 +02:00
< input type = " hidden " name = " or_start " value = " '. $or_start .' " />
2021-05-20 11:45:16 +02:00
'.$errorDate.'
< input type = " date " name = " date " value = " '. $date .' " placeholder = " Fecha de inicio " /> < br >
2021-05-17 15:29:29 +02:00
< 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 >
< input type = " submit " id = " submit " name = " sumbit " class = " primary " value = " Crear " /> < br > ' ;
if ( $this -> option == " edit_session " ){
$html .= ' < input type = " submit " id = " submit " name = " sumbit " class = " primary " value = " Editar " />< br >
< input type = " submit " name = " delete " class = " black button " onclick = " return confirm( \ 'Seguro que quieres borrar esta sesion? \ ') " value = " Borrar " />< br > ' ;
}
}
2021-05-20 11:45:16 +02:00
$html .= "
< input type = 'reset' id = 'reset' value = 'Limpiar Campos' >
</ form >
2021-05-17 15:29:29 +02:00
</ div >
2021-05-20 11:45:16 +02:00
< div class = 'column side' > " ;
if ( $film ){
$html .= " <section id=' " . $tittle . " '>
< div class = 'code showtimes' >
< div class = 'image' >< img src = '../img/films/".$tittle.".jpg' alt = '".$tittle."' /></ div >
< h2 > " .str_replace('_', ' ', $tittle ). " </ h2 >
< hr />
< div class = 'blockquote' >
< p > " . $description . " </ p >
</ div >
< li > Duración : " . $duration . " minutos </ li >
< li > Duración : " . $language . " minutos </ li >
</ div >
</ section >
" ;
2021-05-17 15:29:29 +02:00
}
2021-05-20 11:45:16 +02:00
$html .= '<input type="submit" name="select_film" form="' . $this -> formID . ' " formaction= " ? state = select_film " class= " button large " Value= " Seleccionar una Pelicula " /><br>
</ div >
' ;
2021-05-17 15:29:29 +02:00
return $html ;
}
//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' ] ;
$repeat = $data [ 'repeat' ] ? ? 0 ;
$or_hall = $data [ " or_hall " ] ;
$or_date = $data [ " or_date " ] ;
$or_start = $data [ " or_start " ] ;
2021-05-20 11:45:16 +02:00
if (( $price <= 0 || empty ( $price )) && isset ( $data [ " sumbit " ]) ) {
$result [ 'price' ] = " <li> No puede haber 0 o menos euros. </li> <br> " ;
}
if (( empty ( $format )) && isset ( $data [ " sumbit " ]) ) {
$result [ 'format' ] = " <li> El formato no puede estar vacio. </li> <br> " ;
}
if (( empty ( $date )) && isset ( $data [ " sumbit " ]) ) {
$ result [ 'date' ] = " <li> No hay una fecha seleccionada. </li> <br> " ;
}
if (( empty ( $start )) && isset ( $data [ " sumbit " ]) ) {
$result [ 'start' ] = " <li> No hay una hora inicial seleccionada. </li> <br> " ;
2021-05-17 15:29:29 +02:00
}
if ( count ( $result ) === 0 && isset ( $data [ " sumbit " ]) ) {
if ( $this -> option == " new_session " ){
$_SESSION [ 'msg' ] = Session :: create_session ( $this -> cinema , $hall , $start , $date , $film , $price , $format , $repeat );
$result = './?state=success' ;
}
if ( $this -> option == " edit_session " ){
$_SESSION [ 'msg' ] = Session :: edit_session ( $this -> 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 ( $this -> cinema , $or_hall , $or_start , $or_date );
$result = './?state=success' ;
}
return $result ;
}
}
?>