fromHalls funciona con ->gestiona

This commit is contained in:
Markines16 2021-05-10 16:45:36 +02:00 committed by GitHub
parent 57ef61e293
commit a1d04a6eae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 187 additions and 78 deletions

View File

@ -1,50 +1,97 @@
<?php <?php
include_once($prefix.'assets/php/common/hall_dao.php'); include_once($prefix.'assets/php/common/hall.php');
include_once($prefix.'assets/php/common/seat.php');
include_once($prefix.'assets/php/form.php'); include_once($prefix.'assets/php/form.php');
ini_set('display_errors', 0);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
class FormHall extends Form { class FormHall extends Form {
private $option;
//Constructor: //Constructor:
public function __construct() { public function __construct($option) {
parent::__construct('formHall'); $this->option = $option;
$options = array("action" => "./?state=".$option);
parent::__construct('formHall',$options);
} }
public static function generaCampoFormulario($data, $errores = array()){ protected function generaCamposFormulario($data, $errores = array()){
//Prepare the data
$number = $data['number'] ?? ''; if($this->option == "new_hall"){
$rows = $data['rows'] ?? '14'; $number = $data['number'] ?? "";
$rows = $data['rows'] ?? '12';
$cols = $data['cols'] ?? '8'; $cols = $data['cols'] ?? '8';
$seats = $data['seats'] ?? ''; }else {
$number = $data['number'] ?? $_POST["number"];
$rows = $data['rows'] ?? $_POST["rows"];
$cols = $data['cols'] ?? $_POST["cols"];
}
$og_number = $data['og_number'] ?? $number;
$htmlform .= '<div class="column left"> //Seats_map
<form method="post" id="seat_filter" action="./?state='.$data['option'].'"\> $seats = 0;
<fieldset> $seats_map = array();
<legend> Configuracion </legend>
<input type="number" name="rows" value="'.$rows.'" min="1" placeholder="Numero de filas" required/> <br> //Show the original seats_map once u click restart or the first time u enter this form from manage_halls's form
<input type="number" name="cols" value="'.$cols.'" min="1" placeholder="Numero de cols" required/> <br> if($data["restart"] || $_POST["edit_hall"] ){
<button type="submit" name="seat_filter" class="button large">Actualizar</button><br> foreach(Seat::getSeatsMap($og_number, $_SESSION["cinema"]) as $seat){
</fieldset> $seats_map[$seat->getNumRows()][$seat->getNumCol()] = $seat->getState();
</form> if($seat->getState()>=0){
<br> $seats++;
<br> }
<form method="post" id="'.$data['option'].'" action="./includes/processForm.php"\> }
<fieldset> }//Show the checkbox seats_map updated and everything to selected if alltoone was pressed
<input type="number" name="number" value="'.$number.'" min="1" placeholder="Numero de la sala" required/> <br> else{
<input type="hidden" name="rows" value="'.$rows.'" min="1"/> $alltoone = $_POST["alltoone"] ?? 0;
<input type="hidden" name="cols" value="'.$cols.'" min="1"/> for($i = 1;$i <= $rows; $i++){
'; for($j = 1; $j <= $cols; $j++){
if($data['option'] == "new_hall") echo "El valor de la data: ".$data["checkbox".$i.$j];
$htmlform .= '<button type="submit" name="new_hall" class="button large">Crear</button><br>'; if($alltoone || ( $data["checkbox".$i.$j] >= "0")){
if($data['option'] == "edit_hall"){ $seats_map[$i][$j] = $data["checkbox".$i.$j] ?? "0";
$htmlform .= ' $seats++;
<button type="submit" name="edit_hall" class="button large">Editar</button><br> }else
<button type="submit" name="delete_hall" class="primary">Borrar</button><br>'; $seats_map[$i][$j] = "-1";
}
} }
$htmlform .= '
</fieldset>
</div>
}
$htmlErroresGlobales = self::generaListaErroresGlobales($errores);
$errorNumber = self::createMensajeError($errores, 'number', 'span', array('class' => 'error'));
$errorSeats = self::createMensajeError($errores, 'seats', 'span', array('class' => 'error'));
$html = '<div class="column left">
'.$htmlErroresGlobales.'
'.$errorSeats.'
<fieldset>
<legend>Configuracion</legend>
<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>
<input type="submit" id="submit" name="alltoone" value="Activar todos los asientos" class="primary" />';
if($this->option == "edit_hall")
$html .= '<input type="submit" id="restart" name="restart" value="Restaurar mapa original" class="primary" /> ';
$html .='</fieldset>
<input type="submit" name="filter" value="Actualizar mapa de la sala" class="button large" />
'.$errorNumber.'
<fieldset>
<label> Numero de sala: </label>
<input type="number" min="1" name="number" id="number" value="'.$number.'" placeholder="Numero de la Sala" /><br>
<input type="hidden" min="1" name="og_number" value="'.$og_number.'" /><br>
</fieldset>
';
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" value="Eliminar Sala" class="primary" />
';
}
$html .=' </div>
<div class="column right"> <div class="column right">
<h3 class="table_title"> Pantalla </h3> <h3 class="table_title"> Pantalla </h3>
<table class="seat"> <table class="seat">
@ -52,48 +99,94 @@ class FormHall extends Form {
<tr> <tr>
<th></th>'; <th></th>';
for($j = 1; $j<=$cols; $j++){ for($j = 1; $j<=$cols; $j++){
$htmlform .= '<th>'.$j.'</th>'; $html .= '<th>'.$j.'</th>';
} }
$htmlform .= '</tr> $html .= '</tr>
</thead> </thead>
<tbody>'; <tbody>';
for($i = 1;$i<=$rows;$i++){ for($i = 1;$i<=$rows;$i++){
$htmlform .= ' $html .= '
<tr> <tr>
<td>'.$i.'</td> <td>'.$i.'</td>
'; ';
for($j=1; $j<=$cols; $j++){ for($j=1; $j<=$cols; $j++){
$htmlform .= '<td> <input type="checkbox" class="check_box" name="checkbox'.$i.$j.'" id="checkbox'.$i.$j.'" value="1" checked> <label for="checkbox'.$i.$j.'"> </td>' 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>
';}
} }
$htmlform .=' $html .='
</tr>'; </tr>';
} }
$htmlform .= ' $html .= '
</tbody> </tbody>
</table> </table>
</form>
</div> </div>
'; ';
return $htmlform;
return $html;
} }
//Methods: //Methods:
//Process form: //Process form:
public static function processesForm($data){ protected function procesaFormulario($datos){
if($data["option"] == "new_hall"){ $result = array();
$_SESSION['msg'] = Hall::create_hall($data);
header( "Location: ../?state=success" ); $rows = $datos['rows'];
}else if($data["option"] == "edit_hall"){ $cols = $datos['cols'];
$_SESSION['msg'] = Hall::edit_hall($data); $og_number = $datos["og_number"];
header( "Location: ../?state=success" );
//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 if($data["option"] == "delete_hall") { }else{
$_SESSION['msg'] = Hall::delete_hall($data); $seats_map[$i][$j] = "-1";
header( "Location: ../?state=success" );
} }
} }
}
if ($seats == 0 && isset($datos["sumbit"]) ) {
$result['seats'] = "<li> No puede haber 0 asientos disponibles. </li> <br>";
}
$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"]) ) {
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;
}
} }
?> ?>

View File

@ -1,16 +1,16 @@
<!DOCTYPE HTML> <!DOCTYPE HTML>
<?php <?php
ini_set('display_errors', 0);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
//General Config File: //General Config File:
require_once('../assets/php/config.php'); require_once('../assets/php/config.php');
//Controller file: //Controller file:
include_once('panel_manager.php'); include_once('panel_manager.php');
//Manager data:
include_once('../assets/php/common/manager.php');
include_once('../assets/php/common/user.php');
if($_SESSION["login"] && $_SESSION["rol"] === "manager"){ if($_SESSION["login"] && $_SESSION["rol"] === "manager"){
$_SESSION["cinema"] = 1;
switch($_GET["state"]){ switch($_GET["state"]){
case "view_ruser": case "view_ruser":
case "view_user": case "view_user":

View File

@ -36,7 +36,15 @@
} }
static function manage_halls(){ static function manage_halls(){
$panel = '<form method="post" action="./?state=new_hall">
$panel = '<div class="column side"></div>
<div class="column middle">';
$listhall = Hall::getListHalls($_SESSION["cinema"]);
if(!$listhall){
$panel .= "<h2> No hay ninguna sala en este cine";
}else{
$panel .= '
<table class="alt"> <table class="alt">
<thead> <thead>
<tr> <tr>
@ -47,7 +55,8 @@
</tr> </tr>
</thead> </thead>
<tbody>'; <tbody>';
foreach(Hall::getListHalls($_SESSION["cinema"]) as $hall){
foreach($listhall as $hall){
$panel .=' $panel .='
<tr> <tr>
<td> '. $hall->getNumber().'</td> <td> '. $hall->getNumber().'</td>
@ -59,32 +68,39 @@
<input name="rows" type="hidden" value="'. $hall->getNumRows().'"> <input name="rows" type="hidden" value="'. $hall->getNumRows().'">
<input name="cols" type="hidden" value="'. $hall->getNumCol().'"> <input name="cols" type="hidden" value="'. $hall->getNumCol().'">
<input name="seats" type="hidden" value="'.$hall->getTotalSeats().'"> <input name="seats" type="hidden" value="'.$hall->getTotalSeats().'">
<td> <input type="submit" name="edit" value="Editar" class="button" formaction="./?state=edit_hall&number='.$hall->getNumber().'" ></td> <input name="object" type="hidden" value="'.serialize($cinema).'">
<td> <input type="submit" name="edit_hall" value="Editar" class="button" formaction="./?state=edit_hall&number='.$hall->getNumber().'" ></td>
</form> </form>
</tr>'; </tr>';
} }
$panel.=' $panel.='
</tbody> </tbody>
</table> </table>
<input type="submit" name="new" value="Añadir" class="button large" > ';
}
$panel.=' <form method="post" action="./?state=new_hall">
<input type="submit" name="new_hall" value="Añadir Sala" class="button large" >
</form> </form>
'; </div>
<div class="column side"></div>
';
return $panel; return $panel;
} }
static function new_hall(){ static function new_hall(){
$data = array("option" => "new_hall", "cols" => $_POST["cols"], "rows" => $_POST["rows"]);
$panel = '<h1>Crear una sala.</h1><hr/></br>
'. FormHall::generaCampoFormulario($data, null);
$formHall = new FormHall("new_hall");
$panel = '<h1>Crear una sala.</h1><hr/></br>'
.$formHall->gestiona();
return $panel; return $panel;
} }
static function edit_hall(){ static function edit_hall(){
$data = array("option" => "edit_hall", "number" => $_POST["number"],"cols" => $_POST["cols"], "rows" => $_POST["rows"], "seats" => $_POST["seats"]); $formHall = new FormHall("edit_hall");
$panel = '<h1>Editar una sala.</h1><hr/></br>
'. FormHall::generaCampoFormulario($data, null);
$panel = '<h1>Editar una sala.</h1><hr/></br>'
.$formHall->gestiona();
return $panel; return $panel;
} }