2021-05-17 15:29:29 +02:00
< ? php
2021-05-20 15:29:49 +02:00
include_once ( $prefix . 'assets/php/includes/hall.php' );
include_once ( $prefix . 'assets/php/includes/seat.php' );
2021-05-17 15:29:29 +02:00
include_once ( $prefix . 'assets/php/form.php' );
class FormHall extends Form {
private $option ;
private $cinema ;
2021-05-25 00:51:11 +02:00
private $og_hall ;
2021-05-17 15:29:29 +02:00
//Constructor:
2021-05-25 00:51:11 +02:00
public function __construct ( $option , $cinema , $hall ) {
2021-05-17 15:29:29 +02:00
$this -> option = $option ;
$this -> cinema = $cinema ;
2021-05-27 20:41:59 +02:00
if ( $hall )
$this -> og_hall = $hall ;
2021-05-25 00:51:11 +02:00
if ( $option == " edit_hall " )
2021-05-27 14:18:25 +02:00
$options = array ( " action " => " ./?state= " . $option . " &number= " . $hall -> getNumber () . " &editing " );
else
$options = array ( " action " => " ./?state= " . $option . " &number= " . $hall -> getNumber () . " " );
2021-05-17 15:29:29 +02:00
parent :: __construct ( 'formHall' , $options );
}
protected function generaCamposFormulario ( $data , $errores = array ()){
//Prepare the data
2021-05-25 00:51:11 +02:00
$number = $data [ 'number' ] ? ? $this -> og_hall -> getNumber () ? ? " " ;
$rows = $data [ 'rows' ] ? ? $this -> og_hall -> getNumRows () ? ? " 12 " ;
$cols = $data [ 'cols' ] ? ? $this -> og_hall -> getNumCol () ? ? " 8 " ;
2021-05-20 12:00:33 +02:00
2021-06-06 13:35:19 +02:00
//Init Seats_map
2021-05-17 15:29:29 +02:00
$seats = 0 ;
$seats_map = array ();
for ( $i = 1 ; $i <= $rows ; $i ++ ){
for ( $j = 1 ; $j <= $cols ; $j ++ ){
$seats_map [ $i ][ $j ] = " -1 " ;
}
}
2021-05-27 14:18:25 +02:00
$alltozero = $_POST [ " alltozero " ] ? ? 0 ;
2021-05-17 15:29:29 +02:00
//Show the original seats_map once u click restart or the first time u enter this form from manage_halls's form
2021-05-27 20:41:59 +02:00
if ( $this -> option == " edit_hall " && ! isset ( $_GET [ " editing " ])){
2021-05-25 00:51:11 +02:00
$rows = $this -> og_hall -> getNumRows ();
$cols = $this -> og_hall -> getNumCol ();
$seat_list = Seat :: getSeatsMap ( $this -> og_hall -> getNumber (), $this -> cinema );
2021-05-17 15:29:29 +02:00
if ( $seat_list ){
foreach ( $seat_list as $seat ){
$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
2021-05-27 14:18:25 +02:00
else if ( ! $alltozero ){
2021-05-17 15:29:29 +02:00
$alltoone = $_POST [ " alltoone " ] ? ? 0 ;
for ( $i = 1 ; $i <= $rows ; $i ++ ){
for ( $j = 1 ; $j <= $cols ; $j ++ ){
if ( $alltoone || isset ( $data [ " checkbox " . $i . $j ])) {
$seats_map [ $i ][ $j ] = $data [ " checkbox " . $i . $j ] ? ? " 0 " ;
$seats ++ ;
if ( $seats_map [ $i ][ $j ] == " -1 " ){
$seats_map [ $i ][ $j ] = " 0 " ;
}
} else
$seats_map [ $i ][ $j ] = " -1 " ;
}
}
}
$htmlErroresGlobales = self :: generaListaErroresGlobales ( $errores );
$errorNumber = self :: createMensajeError ( $errores , 'number' , 'span' , array ( 'class' => 'error' ));
$errorSeats = self :: createMensajeError ( $errores , 'seats' , 'span' , array ( 'class' => 'error' ));
2021-05-20 12:00:33 +02:00
$errorRows = self :: createMensajeError ( $errores , 'rows' , 'span' , array ( 'class' => 'error' ));
$errorCols = self :: createMensajeError ( $errores , 'cols' , 'span' , array ( 'class' => 'error' ));
2021-05-17 15:29:29 +02:00
$html = '
2021-05-20 12:00:33 +02:00
< div class = " column left " > '.$htmlErroresGlobales.'
2021-05-17 15:29:29 +02:00
< fieldset >
< legend > Mapa de Asientos </ legend >
2021-05-20 12:00:33 +02:00
'.$errorSeats.' '.$errorRows.' '.$errorCols.'
2021-05-27 14:18:25 +02:00
< label > Filas : </ label > < input type = " number " name = " rows " min = " 1 " id = " rows " value = " '. $rows .' " /> < br >
< label > Columnas : </ label > < input type = " number " name = " cols " min = " 1 " id = " cols " value = " '. $cols .' " /> < br >
2021-05-17 15:29:29 +02:00
< label > Asientos totales : '.$seats.' </ label > < input type = " hidden " name = " seats " id = " seats " value = " '. $seats .' " readonly /> < br >
2021-05-25 00:51:11 +02:00
< input type = " submit " name = " filter " value = " Actualizar mapa de la sala " class = " button large " />
' ;
2021-05-17 15:29:29 +02:00
if ( $this -> option == " edit_hall " )
$html .= ' <input type="submit" id="restart" name="restart" value="Restaurar mapa original" class="black button" />' ;
$html .= '
2021-05-25 00:51:11 +02:00
</ fieldset >< br >
'.$errorNumber.'
2021-05-17 15:29:29 +02:00
< label > Numero de sala : </ label >
2021-05-27 14:18:25 +02:00
< input type = " number " name = " number " id = " number " value = " '. $number .' " placeholder = " Numero de la Sala " />< br >
2021-05-17 15:29:29 +02:00
' ;
if ( $this -> option == " new_hall " )
$html .= ' < input type = " submit " id = " submit " name = " sumbit " value = " Crear Sala " class = " primary " />
' ;
if ( $this -> option == " edit_hall " ){
$html .= ' < input type = " submit " id = " submit " name = " sumbit " value = " Editar Sala " class = " primary " />
< input type = " submit " id = " submit " name = " delete " onclick = " return confirm( \ 'Seguro que quieres borrar esta sala? \ ') " value = " Eliminar Sala " class = " black button " />
' ;
}
2021-05-20 12:00:33 +02:00
if ( ! $errorCols && ! $errorRows ){
2021-05-17 15:29:29 +02:00
$html .= ' </ div >
< div class = " column right " >
2021-05-25 00:51:11 +02:00
< input type = " submit " name = " alltoone " value = " Activar todos los asientos " class = " button large " />
2021-05-27 14:18:25 +02:00
< input type = " submit " name = " alltozero " value = " Desactivar todos los asientos " class = " button large " />
2021-05-17 15:29:29 +02:00
< h3 class = " table_title " > Pantalla </ h3 >
< table class = " seat " >
< thead >
< tr >
< th > </ th >
' ;
for ( $j = 1 ; $j <= $cols ; $j ++ ){
$html .= '<th>' . $j . ' </ th >
' ;
}
$html .= ' </ tr >
</ thead >
< tbody > ' ;
for ( $i = 1 ; $i <= $rows ; $i ++ ){
$html .= '
< tr >
< td > '.$i.' </ td >
' ;
for ( $j = 1 ; $j <= $cols ; $j ++ ){
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>
' ;}
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>
' ;}
}
$html .= '</tr>' ;
}
$html .= '
</ tbody >
</ table >
</ div > ' ;
2021-05-20 12:00:33 +02:00
} else
$html .= '</div>' ;
2021-05-17 15:29:29 +02:00
return $html ;
}
//Process form:
protected function procesaFormulario ( $datos ){
$result = array ();
$rows = $datos [ 'rows' ];
$cols = $datos [ 'cols' ];
//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-06-06 13:35:19 +02:00
//Check input errors
2021-05-17 15:29:29 +02:00
if ( $seats == 0 && isset ( $datos [ " sumbit " ]) ) {
$result [ 'seats' ] = " <li> No puede haber 0 asientos disponibles. </li> <br> " ;
}
2021-05-20 12:00:33 +02:00
if ( $rows <= 0 ) {
$result [ 'rows' ] = " <li> No puede haber 0 o menos filas. </li> <br> " ;
}
if ( $cols <= 0 ) {
$result [ 'cols' ] = " <li> No puede haber 0 o menos columnas. </li> <br> " ;
}
2021-05-17 15:29:29 +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> " ;
}
2021-05-27 14:18:25 +02:00
if ( isset ( $datos [ " restart " ])){
return $result = " ./?state= " . $this -> option . " &number= " . $this -> og_hall -> getNumber () . " " ;
}
2021-05-17 15:29:29 +02:00
if ( count ( $result ) === 0 && isset ( $datos [ " sumbit " ]) ) {
if ( $this -> option == " new_hall " ){
2021-06-08 11:30:10 +02:00
$msg = Hall :: create_hall ( $number , $this -> cinema , $rows , $cols , $seats , $seats_map );
return $result = './?state=success&msg=' . $msg ;
2021-05-17 15:29:29 +02:00
}
if ( $this -> option == " edit_hall " ){
2021-06-08 11:30:10 +02:00
$msg = Hall :: edit_hall ( $number , $this -> cinema , $rows , $cols , $seats , $seats_map , $this -> og_hall -> getNumber ());
return $result = './?state=success&msg=' . $msg ;
2021-05-17 15:29:29 +02:00
}
}
if ( ! isset ( $result [ 'number' ]) && isset ( $datos [ " delete " ]) ) {
if ( $this -> option == " edit_hall " ){
2021-06-08 11:30:10 +02:00
$msg = Hall :: delete_hall ( $number , $this -> cinema , $rows , $cols , $seats , $seats_map , $this -> og_hall -> getNumber ());
return $result = './?state=success&msg=' . $msg ;
2021-05-17 15:29:29 +02:00
}
}
2021-05-27 14:18:25 +02:00
2021-05-17 15:29:29 +02:00
return $result ;
}
}
?>