2021-04-26 22:40:34 +02:00
< ? php
2021-05-10 16:45:36 +02:00
include_once ( $prefix . 'assets/php/common/hall.php' );
include_once ( $prefix . 'assets/php/common/seat.php' );
2021-05-05 16:52:04 +02:00
include_once ( $prefix . 'assets/php/form.php' );
2021-05-10 16:45:36 +02:00
2021-04-26 22:40:34 +02:00
class FormHall extends Form {
2021-05-10 16:45:36 +02:00
private $option ;
2021-05-13 14:06:48 +02:00
private $cinema ;
2021-05-10 16:45:36 +02:00
2021-04-26 22:40:34 +02:00
//Constructor:
2021-05-13 14:06:48 +02:00
public function __construct ( $option , $cinema ) {
2021-05-10 16:45:36 +02:00
$this -> option = $option ;
2021-05-13 14:06:48 +02:00
$this -> cinema = $cinema ;
2021-05-10 16:45:36 +02:00
$options = array ( " action " => " ./?state= " . $option );
parent :: __construct ( 'formHall' , $options );
2021-04-26 22:40:34 +02:00
}
2021-05-03 12:40:59 +02:00
2021-05-10 16:45:36 +02:00
protected function generaCamposFormulario ( $data , $errores = array ()){
//Prepare the data
if ( $this -> option == " new_hall " ){
$number = $data [ 'number' ] ? ? " " ;
$rows = $data [ 'rows' ] ? ? '12' ;
$cols = $data [ 'cols' ] ? ? '8' ;
} else {
$number = $data [ 'number' ] ? ? $_POST [ " number " ];
$rows = $data [ 'rows' ] ? ? $_POST [ " rows " ];
$cols = $data [ 'cols' ] ? ? $_POST [ " cols " ];
}
2021-05-03 12:40:59 +02:00
2021-05-13 14:06:48 +02:00
$og_number = $data [ 'og_number' ] ? ? $number ;
2021-05-10 16:45:36 +02:00
//Seats_map
$seats = 0 ;
$seats_map = array ();
//Show the original seats_map once u click restart or the first time u enter this form from manage_halls's form
if ( $data [ " restart " ] || $_POST [ " edit_hall " ] ){
2021-05-13 14:06:48 +02:00
foreach ( Seat :: getSeatsMap ( $og_number , $this -> cinema ) as $seat ){
2021-05-10 16:45:36 +02:00
$seats_map [ $seat -> getNumRows ()][ $seat -> getNumCol ()] = $seat -> getState ();
if ( $seat -> getState () >= 0 ){
$seats ++ ;
}
}
} //Show the checkbox seats_map updated and everything to selected if alltoone was pressed
else {
$alltoone = $_POST [ " alltoone " ] ? ? 0 ;
for ( $i = 1 ; $i <= $rows ; $i ++ ){
for ( $j = 1 ; $j <= $cols ; $j ++ ){
2021-05-13 14:06:48 +02:00
if ( $alltoone || isset ( $data [ " checkbox " . $i . $j ])) {
2021-05-10 16:45:36 +02:00
$seats_map [ $i ][ $j ] = $data [ " checkbox " . $i . $j ] ? ? " 0 " ;
$seats ++ ;
2021-05-13 14:06:48 +02:00
if ( $seats_map [ $i ][ $j ] == " -1 " ){
$seats_map [ $i ][ $j ] = " 0 " ;
}
2021-05-10 16:45:36 +02:00
} else
$seats_map [ $i ][ $j ] = " -1 " ;
}
2021-05-13 14:06:48 +02:00
}
2021-05-07 19:07:03 +02:00
}
2021-05-03 12:40:59 +02:00
2021-05-10 16:45:36 +02:00
$htmlErroresGlobales = self :: generaListaErroresGlobales ( $errores );
$errorNumber = self :: createMensajeError ( $errores , 'number' , 'span' , array ( 'class' => 'error' ));
$errorSeats = self :: createMensajeError ( $errores , 'seats' , 'span' , array ( 'class' => 'error' ));
2021-05-13 14:06:48 +02:00
$html = '
< div class = " column left " > '.$htmlErroresGlobales.' '.$errorSeats.' '. $errorManager.'
2021-05-10 16:45:36 +02:00
< fieldset >
2021-05-13 14:06:48 +02:00
< legend > Mapa de Asientos </ legend >
2021-05-10 16:45:36 +02:00
< label > Filas : </ label > < input type = " number " name = " rows " min = " 1 " id = " rows " value = " '. $rows .' " required /> < br >
< label > Columnas : </ label > < input type = " number " name = " cols " min = " 1 " id = " cols " value = " '. $cols .' " required /> < br >
< label > Asientos totales : '.$seats.' </ label > < input type = " hidden " name = " seats " id = " seats " value = " '. $seats .' " readonly /> < br >
2021-05-13 14:06:48 +02:00
< input type = " submit " name = " alltoone " value = " Activar todos los asientos " class = " button large " /> ' ;
2021-05-10 16:45:36 +02:00
if ( $this -> option == " edit_hall " )
2021-05-13 14:06:48 +02:00
$html .= ' <input type="submit" id="restart" name="restart" value="Restaurar mapa original" class="black button" />' ;
$html .= '
</ fieldset >
< input type = " submit " name = " filter " value = " Actualizar mapa de la sala " class = " button large " /> '.$errorNumber.'
2021-05-10 16:45:36 +02:00
< fieldset >
< label > Numero de sala : </ label >
< input type = " number " min = " 1 " name = " number " id = " number " value = " '. $number .' " placeholder = " Numero de la Sala " />< br >
2021-05-13 14:06:48 +02:00
< input type = " hidden " name = " og_number " value = " '. $og_number .' " />< br >
2021-05-10 16:45:36 +02:00
</ fieldset >
' ;
if ( $this -> option == " new_hall " )
2021-05-13 14:06:48 +02:00
$html .= ' < input type = " submit " id = " submit " name = " sumbit " value = " Crear Sala " class = " primary " />
' ;
2021-05-10 16:45:36 +02:00
if ( $this -> option == " edit_hall " ){
$html .= ' < input type = " submit " id = " submit " name = " sumbit " value = " Editar Sala " class = " primary " />
2021-05-13 14:06:48 +02:00
< input type = " submit " id = " submit " name = " delete " onclick = " return confirm( \ 'Seguro que quieres borrar esta sala? \ ') " value = " Eliminar Sala " class = " black button " />
2021-05-10 16:45:36 +02:00
' ;
}
2021-05-13 14:06:48 +02:00
$html .= ' </ div >
2021-05-06 23:25:38 +02:00
< div class = " column right " >
< h3 class = " table_title " > Pantalla </ h3 >
< table class = " seat " >
2021-05-13 14:06:48 +02:00
< thead >
< tr >
< th > </ th >
' ;
2021-05-06 23:25:38 +02:00
for ( $j = 1 ; $j <= $cols ; $j ++ ){
2021-05-13 14:06:48 +02:00
$html .= '<th>' . $j . ' </ th >
' ;
2021-05-06 23:25:38 +02:00
}
2021-05-13 14:06:48 +02:00
$html .= ' </ tr >
</ thead >
< tbody > ' ;
2021-05-06 23:25:38 +02:00
for ( $i = 1 ; $i <= $rows ; $i ++ ){
2021-05-10 16:45:36 +02:00
$html .= '
2021-05-13 14:06:48 +02:00
< tr >
< td > '.$i.' </ td >
' ;
2021-05-06 23:25:38 +02:00
for ( $j = 1 ; $j <= $cols ; $j ++ ){
2021-05-10 16:45:36 +02:00
if ( $seats_map [ $i ][ $j ] >= 0 ){
$html .= '<td> <input type="checkbox" class="check_box" name="checkbox' . $i . $j . '" value="' . $seats_map [ $i ][ $j ] . '" id="checkbox' . $i . $j . '" checked> <label for="checkbox' . $i . $j . ' " > </td>
2021-05-13 14:06:48 +02:00
' ;}
2021-05-10 16:45:36 +02:00
else {
$html .= '<td> <input type="checkbox" class="check_box" name="checkbox' . $i . $j . '" value="' . $seats_map [ $i ][ $j ] . '" id="checkbox' . $i . $j . '" > <label for="checkbox' . $i . $j . ' " > </td>
2021-05-13 14:06:48 +02:00
' ;}
2021-05-06 23:25:38 +02:00
}
2021-05-13 14:06:48 +02:00
$html .= '</tr>' ;
2021-05-06 23:25:38 +02:00
}
2021-05-10 16:45:36 +02:00
$html .= '
2021-05-13 14:06:48 +02:00
</ tbody >
2021-05-06 23:25:38 +02:00
</ table >
2021-05-13 14:06:48 +02:00
</ div > ' ;
2021-05-10 16:45:36 +02:00
return $html ;
2021-05-03 12:40:59 +02:00
}
2021-05-10 16:45:36 +02:00
2021-04-26 22:40:34 +02:00
//Methods:
//Process form:
2021-05-10 16:45:36 +02:00
protected function procesaFormulario ( $datos ){
$result = array ();
$rows = $datos [ 'rows' ];
$cols = $datos [ 'cols' ];
$og_number = $datos [ " og_number " ];
//Prepare the seat_map
$seats_map = array ();
$seats = 0 ;
for ( $i = 1 ; $i <= $rows ; $i ++ ){
for ( $j = 1 ; $j <= $cols ; $j ++ ){
if ( isset ( $datos [ " checkbox " . $i . $j ])){
$seats_map [ $i ][ $j ] = $datos [ " checkbox " . $i . $j ];
$seats ++ ;
if ( $seats_map [ $i ][ $j ] == " -1 " ){
$seats_map [ $i ][ $j ] = " 0 " ;
}
} else {
$seats_map [ $i ][ $j ] = " -1 " ;
}
}
2021-05-07 19:07:03 +02:00
}
2021-05-10 16:45:36 +02:00
if ( $seats == 0 && isset ( $datos [ " sumbit " ]) ) {
$result [ 'seats' ] = " <li> No puede haber 0 asientos disponibles. </li> <br> " ;
}
2021-05-13 14:06:48 +02:00
2021-05-10 16:45:36 +02:00
$number = $datos [ 'number' ] ? ? null ;
if ( empty ( $number ) && isset ( $datos [ " sumbit " ])) {
$result [ 'number' ] = " <li> El numero de sala tiene que ser mayor que 0. </li> <br> " ;
}
if ( count ( $result ) === 0 && isset ( $datos [ " sumbit " ]) ) {
2021-05-13 14:06:48 +02:00
if ( $this -> option == " new_hall " ){
$_SESSION [ 'msg' ] = Hall :: create_hall ( $number , $this -> cinema , $rows , $cols , $seats , $seats_map );
$result = './?state=success' ;
}
if ( $this -> option == " edit_hall " ){
$_SESSION [ 'msg' ] = Hall :: edit_hall ( $number , $this -> cinema , $rows , $cols , $seats , $seats_map , $og_number );
$result = './?state=success' ;
}
2021-05-10 16:45:36 +02:00
}
if ( ! isset ( $result [ 'number' ]) && isset ( $datos [ " delete " ]) ) {
if ( $this -> option == " edit_hall " ){
2021-05-13 14:06:48 +02:00
$_SESSION [ 'msg' ] = Hall :: delete_hall ( $number , $this -> cinema , $rows , $cols , $seats , $seats_map , $og_number );
2021-05-10 16:45:36 +02:00
$result = './?state=success' ;
}
}
return $result ;
2021-04-26 22:40:34 +02:00
}
}
?>