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' );
require_once ( $prefix . 'assets/php/common/session.php' );
require_once ( $prefix . 'assets/php/form.php' );
2021-05-12 10:40:22 +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
//Constructor:
2021-05-12 10:40:22 +02:00
public function __construct () {
parent :: __construct ( 'formSession' );
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-12 10:40:22 +02:00
public static function generaCampoFormulario ( $data , $errores = array ()){
2021-05-05 21:10:46 +02:00
2021-05-12 10:40:22 +02:00
$cinema = $data [ 'cinema' ] ? ? '' ;
$film = $data [ 'film' ] ? ? '' ;
$hall = $data [ 'hall' ] ? ? '' ;
$date = $data [ 'date' ] ? ? '' ;
$start = $data [ 'start' ] ? ? '' ;
$price = $data [ 'price' ] ? ? '' ;
$format = $data [ 'format' ] ? ? '' ;
$htmlform .= ' < div class = " column left " >
< form method = " post " id = " '. $data['option'] .' " action = " ./includes/processForm.php " \ >
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-05 21:10:46 +02:00
< input type = " text " name = " format " value = " '. $format .' " placeholder = " Formato de pelicula " required /> < br >
2021-05-12 10:40:22 +02:00
< input type = " hidden " name = " film " value = " '. $film["idfilm"] .' " />
2021-05-05 21:10:46 +02:00
< select name = " hall " class = " button large " > ' ;
2021-05-12 10:40:22 +02:00
foreach ( Hall :: getListHalls ( $cinema ) as $hll ){
2021-05-05 21:10:46 +02:00
if ( $hll -> getNumber () == $hall ){
2021-05-12 10:40:22 +02:00
$htmlform .= '
2021-05-05 21:10:46 +02:00
< option value = " '. $hll->getNumber () .' " selected > Sala '. $hll->getNumber() .' </ option > ' ;
} else {
2021-05-12 10:40:22 +02:00
$htmlform .= '
2021-05-05 21:10:46 +02:00
< option value = " '. $hll->getNumber () .' " > Sala '. $hll->getNumber() .' </ option > ' ;
}
}
2021-05-12 10:40:22 +02:00
$htmlform .= '
2021-05-05 21:10:46 +02:00
</ select >
</ fieldset >
< fieldset >
< legend > Horario </ legend >
< input type = " time " name = " start " value = " '. $start .' " placeholder = " Hora de inicio " required /> < br >
< input type = " date " name = " date " value = " '. $date .' " placeholder = " Fecha de inicio " required /> < br >
</ fieldset >
' ;
2021-05-09 17:50:30 +02:00
if ( $film ){
2021-05-12 10:40:22 +02:00
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 > ' ;
2021-05-09 17:50:30 +02:00
2021-05-12 10:40:22 +02:00
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 > ' ;
2021-05-09 17:50:30 +02:00
}
2021-05-07 13:48:20 +02:00
}
2021-05-12 10:40:22 +02:00
$htmlform .= "
< input type = 'reset' value = 'Limpiar Campos' >
</ form >
2021-05-05 21:10:46 +02:00
</ div >
2021-05-12 10:40:22 +02:00
< 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 >
" ;
2021-05-07 13:48:20 +02:00
}
2021-05-12 10:40:22 +02:00
$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 ;
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-12 10:40:22 +02:00
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 " );
2021-05-06 18:12:46 +02:00
}
2021-05-12 10:40:22 +02:00
else if ( $data [ " option " ] == " delete_session " ) {
$_SESSION [ 'msg' ] = Session :: delete_session ( $data );
header ( " Location: ../?state=success " );
}
2021-04-26 22:40:34 +02:00
}
}
2021-05-06 23:25:38 +02:00
?>