2021-04-26 22:40:34 +02:00
< ? php
2021-05-05 21:10:46 +02:00
require_once ( $prefix . 'assets/php/common/session_dao.php' );
2021-05-13 10:13:03 +02:00
require_once ( $prefix . 'assets/php/common/film_dao.php' );
2021-05-05 21:10:46 +02:00
require_once ( $prefix . 'assets/php/common/session.php' );
require_once ( $prefix . 'assets/php/form.php' );
2021-05-13 10:13:03 +02:00
2021-04-26 22:40:34 +02:00
//Receive data from froms and prepare the correct response
class FormSession extends Form {
2021-05-05 21:10:46 +02:00
2021-05-13 10:13:03 +02:00
private $option ;
2021-05-05 21:10:46 +02:00
//Constructor:
2021-05-13 10:13:03 +02:00
public function __construct ( $option ) {
$this -> option = $option ;
$options = array ( " action " => " ./?state= " . $option );
parent :: __construct ( 'formSession' , $options );
2021-04-26 22:40:34 +02:00
}
2021-05-09 17:50:30 +02:00
//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
2021-05-13 10:13:03 +02:00
protected function generaCamposFormulario ( $data , $errores = array ()){
$filmList = new Film_DAO ( 'complucine' );
$films = $filmList -> allFilmData ();
2021-05-12 10:40:22 +02:00
2021-05-13 10:13:03 +02:00
if ( $this -> option == " new_session " ) {
$cinema = $data [ 'cinema' ] ? ? $_SESSION [ " cinema " ];
$film = $data [ 'film' ] ? ? 1 ;
$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 );
$errorPrice = self :: createMensajeError ( $errores , 'price' , 'span' , array ( 'class' => 'error' ));
$html .= ' < div class = " column left " >
'.$htmlErroresGlobales.'
'.$errorPrice.'
2021-05-05 21:10:46 +02:00
< fieldset >
< legend > Datos </ legend >
2021-05-09 17:50:30 +02:00
< input type = " number " step = " 0.01 " name = " price " value = " '. $price .' " min = " 0 " placeholder = " Precio de la entrada " required /> < br >
2021-05-13 10:13:03 +02:00
'.$errorFormat.'
2021-05-05 21:10:46 +02:00
< input type = " text " name = " format " value = " '. $format .' " placeholder = " Formato de pelicula " required /> < br >
2021-05-13 10:13:03 +02:00
< input type = " hidden " name = " film " value = " '. $film .' " />
2021-05-05 21:10:46 +02:00
< select name = " hall " class = " button large " > ' ;
2021-05-13 10:13:03 +02:00
foreach ( Hall :: getListHalls ( $cinema ) as $hll ){
2021-05-05 21:10:46 +02:00
if ( $hll -> getNumber () == $hall ){
2021-05-13 10:13:03 +02:00
$html .= '
2021-05-05 21:10:46 +02:00
< option value = " '. $hll->getNumber () .' " selected > Sala '. $hll->getNumber() .' </ option > ' ;
} else {
2021-05-13 10:13:03 +02:00
$html .= '
2021-05-05 21:10:46 +02:00
< option value = " '. $hll->getNumber () .' " > Sala '. $hll->getNumber() .' </ option > ' ;
}
}
2021-05-13 10:13:03 +02:00
$html .= '
2021-05-05 21:10:46 +02:00
</ select >
2021-05-13 10:13:03 +02:00
< input type = " hidden " name = " or_hall " value = " '. $or_hall .' " />
2021-05-05 21:10:46 +02:00
</ fieldset >
< fieldset >
< legend > Horario </ legend >
< input type = " time " name = " start " value = " '. $start .' " placeholder = " Hora de inicio " required /> < br >
2021-05-13 10:13:03 +02:00
< input type = " hidden " name = " or_start " value = " '. $or_start .' " />
2021-05-05 21:10:46 +02:00
< input type = " date " name = " date " value = " '. $date .' " placeholder = " Fecha de inicio " required /> < br >
2021-05-13 10:13:03 +02:00
< input type = " hidden " name = " or_date " value = " '. $or_date .' " />
2021-05-05 21:10:46 +02:00
</ fieldset >
' ;
2021-05-09 17:50:30 +02:00
if ( $film ){
2021-05-13 10:13:03 +02:00
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 > ' ;
2021-05-12 10:40:22 +02:00
2021-05-13 10:13:03 +02:00
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 > ' ;
2021-05-09 17:50:30 +02:00
}
2021-05-07 13:48:20 +02:00
}
2021-05-13 10:13:03 +02:00
$html .= '
< input type = " reset " value = " Limpiar Campos " >
2021-05-05 21:10:46 +02:00
</ div >
2021-05-13 10:13:03 +02:00
< 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> " ;
}
2021-05-07 13:48:20 +02:00
}
2021-05-13 10:13:03 +02:00
return $html ;
2021-05-05 21:10:46 +02:00
}
//Methods:
2021-04-26 22:40:34 +02:00
2021-05-05 21:10:46 +02:00
//Process form:
2021-05-13 10:13:03 +02:00
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 " ] ;
if (( $price == 0 || empty ( $price )) && isset ( $data [ " sumbit " ]) ) {
$result [ 'price' ] = " <li> No puede haber 0 euros. </li> <br> " ;
}
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' ;
2021-05-06 18:12:46 +02:00
}
2021-05-13 10:13:03 +02:00
return $result ;
2021-04-26 22:40:34 +02:00
}
}
2021-05-06 23:25:38 +02:00
?>