From a1d04a6eaeab02e52c41091f07261a8fe72046c7 Mon Sep 17 00:00:00 2001 From: Markines16 <80280295+Markines16@users.noreply.github.com> Date: Mon, 10 May 2021 16:45:36 +0200 Subject: [PATCH] fromHalls funciona con ->gestiona --- panel_manager/includes/formHall.php | 207 ++++++++++++++++++++-------- panel_manager/index.php | 8 +- panel_manager/panel_manager.php | 50 ++++--- 3 files changed, 187 insertions(+), 78 deletions(-) diff --git a/panel_manager/includes/formHall.php b/panel_manager/includes/formHall.php index 7c33f54..8e12789 100644 --- a/panel_manager/includes/formHall.php +++ b/panel_manager/includes/formHall.php @@ -1,50 +1,97 @@ option = $option; + $options = array("action" => "./?state=".$option); + parent::__construct('formHall',$options); } - public static function generaCampoFormulario($data, $errores = array()){ - - $number = $data['number'] ?? ''; - $rows = $data['rows'] ?? '14'; - $cols = $data['cols'] ?? '8'; - $seats = $data['seats'] ?? ''; + 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"]; + } + $og_number = $data['og_number'] ?? $number; - $htmlform .= '
-
-
- Configuracion -
-
-
-
-
-
-
-
-
-
- - - '; - if($data['option'] == "new_hall") - $htmlform .= '
'; - if($data['option'] == "edit_hall"){ - $htmlform .= ' -
-
'; + //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"] ){ + foreach(Seat::getSeatsMap($og_number, $_SESSION["cinema"]) 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{ + $alltoone = $_POST["alltoone"] ?? 0; + for($i = 1;$i <= $rows; $i++){ + for($j = 1; $j <= $cols; $j++){ + echo "El valor de la data: ".$data["checkbox".$i.$j]; + if($alltoone || ( $data["checkbox".$i.$j] >= "0")){ + $seats_map[$i][$j] = $data["checkbox".$i.$j] ?? "0"; + $seats++; + }else + $seats_map[$i][$j] = "-1"; + } + } + + + } - $htmlform .= ' -
- -
+ $htmlErroresGlobales = self::generaListaErroresGlobales($errores); + $errorNumber = self::createMensajeError($errores, 'number', 'span', array('class' => 'error')); + $errorSeats = self::createMensajeError($errores, 'seats', 'span', array('class' => 'error')); + + $html = '
+ '.$htmlErroresGlobales.' + '.$errorSeats.' +
+ Configuracion +
+
+
+ '; + if($this->option == "edit_hall") + $html .= ' '; + $html .='
+ + '.$errorNumber.' +
+ +
+
+
+ '; + if($this->option == "new_hall") + $html .=''; + if($this->option == "edit_hall"){ + $html .=' + + '; + } + $html .='

Pantalla

@@ -52,47 +99,93 @@ class FormHall extends Form { '; for($j = 1; $j<=$cols; $j++){ - $htmlform .= ''; + $html .= ''; } - $htmlform .= ' + $html .= ''; for($i = 1;$i<=$rows;$i++){ - $htmlform .= ' + $html .= ' '; for($j=1; $j<=$cols; $j++){ - $htmlform .= '' - ; + if($seats_map[$i][$j]>=0){ + $html .= ' + ';} + else { + $html .= ' + ';} } - $htmlform .=' + $html .=' '; } - $htmlform .= ' + $html .= '
'.$j.''.$j.'
'.$i.'
-
'; - return $htmlform; + + return $html; } + //Methods: //Process form: - public static function processesForm($data){ - if($data["option"] == "new_hall"){ - $_SESSION['msg'] = Hall::create_hall($data); - header( "Location: ../?state=success" ); - }else if($data["option"] == "edit_hall"){ - $_SESSION['msg'] = Hall::edit_hall($data); - header( "Location: ../?state=success" ); + 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"; + } + } } - else if($data["option"] == "delete_hall") { - $_SESSION['msg'] = Hall::delete_hall($data); - header( "Location: ../?state=success" ); - } + + if ($seats == 0 && isset($datos["sumbit"]) ) { + $result['seats'] = "
  • No puede haber 0 asientos disponibles.

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

  • "; + } + + if (count($result) === 0 && isset($datos["sumbit"]) ) { + if($this->option == "new_hall"){ + $_SESSION['msg'] = Hall::create_hall($number, $_SESSION["cinema"], $rows, $cols, $seats, $seats_map); + $result = './?state=success'; + } + if($this->option == "edit_hall"){ + $_SESSION['msg'] = Hall::edit_hall($number, $_SESSION["cinema"], $rows, $cols, $seats, $seats_map, $og_number); + $result = './?state=success'; + } + } + + if (!isset($result['number']) && isset($datos["delete"]) ) { + if($this->option == "edit_hall"){ + $_SESSION['msg'] = Hall::delete_hall($number, $_SESSION["cinema"], $rows, $cols, $seats, $seats_map, $og_number); + $result = './?state=success'; + } + } + + + return $result; } } diff --git a/panel_manager/index.php b/panel_manager/index.php index 0d6b56b..010818a 100644 --- a/panel_manager/index.php +++ b/panel_manager/index.php @@ -1,16 +1,16 @@ + static function manage_halls(){ + + $panel = '
    +
    '; + $listhall = Hall::getListHalls($_SESSION["cinema"]); + if(!$listhall){ + $panel .= "

    No hay ninguna sala en este cine"; + }else{ + $panel .= ' + @@ -47,7 +55,8 @@ '; - foreach(Hall::getListHalls($_SESSION["cinema"]) as $hall){ + + foreach($listhall as $hall){ $panel .=' @@ -59,32 +68,39 @@ - + + '; } $panel.='
    '. $hall->getNumber().'
    - - -'; + '; + } + $panel.='
    + +
    +

    +
    + '; return $panel; } static function new_hall(){ - $data = array("option" => "new_hall", "cols" => $_POST["cols"], "rows" => $_POST["rows"]); - $panel = '

    Crear una sala.



    - '. FormHall::generaCampoFormulario($data, null); - + + $formHall = new FormHall("new_hall"); + + $panel = '

    Crear una sala.



    ' + .$formHall->gestiona(); return $panel; } static function edit_hall(){ - $data = array("option" => "edit_hall", "number" => $_POST["number"],"cols" => $_POST["cols"], "rows" => $_POST["rows"], "seats" => $_POST["seats"]); - $panel = '

    Editar una sala.



    - '. FormHall::generaCampoFormulario($data, null); - + $formHall = new FormHall("edit_hall"); + + $panel = '

    Editar una sala.



    ' + .$formHall->gestiona(); return $panel; }