option = $option; $this->cinema = $cinema; if($hall) $this->og_hall = $hall; if($option == "edit_hall") $options = array("action" => "./?state=".$option."&number=".$hall->getNumber()."&editing=true"); else $options = array("action" => "./?state=".$option."&number=".$hall->getNumber()."&editing=false"); parent::__construct('formHall',$options); } protected function generaCamposFormulario($data, $errores = array()){ //Prepare the data $number = $data['number'] ?? $this->og_hall->getNumber() ?? ""; $rows = $data['rows'] ?? $this->og_hall->getNumRows() ?? "12"; $cols = $data['cols'] ?? $this->og_hall->getNumCol() ?? "8"; //Init Seats_map $seats = 0; $seats_map = array(); for($i = 1;$i <= $rows; $i++){ for($j = 1; $j <= $cols; $j++){ $seats_map[$i][$j] = "-1"; } } $alltozero = $_POST["alltozero"] ?? 0; //Show the original seats_map once u click restart or the first time u enter this form from manage_halls's form if($this->option == "edit_hall" && !isset($_GET["editing"])){ $rows = $this->og_hall->getNumRows(); $cols = $this->og_hall->getNumCol(); $seat_list = Seat::getSeatsMap($this->og_hall->getNumber(), $this->cinema); 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 else if(!$alltozero){ $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')); $errorRows = self::createMensajeError($errores, 'rows', 'span', array('class' => 'error')); $errorCols = self::createMensajeError($errores, 'cols', 'span', array('class' => 'error')); $html = '
'.$htmlErroresGlobales.'
Mapa de Asientos '.$errorSeats.' '.$errorRows.' '.$errorCols.'


'; if($this->option == "edit_hall") $html .= ' '; $html .='

'.$errorNumber.'
'; if($this->option == "new_hall") $html .=' '; if($this->option == "edit_hall"){ $html .=' '; } if(!$errorCols && !$errorRows){ $html .='

Pantalla

'; for($j = 1; $j<=$cols; $j++){ $html .= ' '; } $html .= ''; for($i = 1;$i<=$rows;$i++){ $html .= ' '; for($j=1; $j<=$cols; $j++){ if($seats_map[$i][$j]>=0){ $html .= ' ';} else { $html .= ' ';} } $html .=''; } $html .= '
'.$j.'
'.$i.'
'; } else $html .=''; 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"; } } } //Check input errors if ($seats == 0 && isset($datos["sumbit"]) ) { $result['seats'] = "
  • No puede haber 0 asientos disponibles.

  • "; } if ($rows <= 0) { $result['rows'] = "
  • No puede haber 0 o menos filas.

  • "; } if ($cols <= 0) { $result['cols'] = "
  • No puede haber 0 o menos columnas.

  • "; } $number = $datos['number'] ?? null; if (empty($number) && isset($datos["sumbit"])) { $result['number'] = "
  • El numero de sala tiene que ser mayor que 0.

  • "; } else if (count($result) === 0 && isset($datos["sumbit"]) ) { if($this->option == "new_hall"){ $_SESSION['msg'] = Hall::create_hall($number, $this->cinema, $rows, $cols, $seats, $seats_map); //$result = './?state=success'; } else if($this->option == "edit_hall"){ $_SESSION['msg'] = Hall::edit_hall($number,$this->cinema, $rows, $cols, $seats, $seats_map, $this->og_hall->getNumber()); //$result = './?state=success'; } } else if (!isset($result['number']) && isset($datos["delete"]) ) { if($this->option == "edit_hall"){ $_SESSION['msg'] = Hall::delete_hall($number, $this->cinema, $rows, $cols, $seats, $seats_map, $this->og_hall->getNumber()); //$result = './?state=success'; } } else if(isset($datos["restart"])){ //$result = "./?state=".$this->option."&number=".$this->og_hall->getNumber().""; } return $result; } } ?>