fromHalls funciona con ->gestiona
This commit is contained in:
parent
57ef61e293
commit
a1d04a6eae
@ -1,50 +1,97 @@
|
||||
<?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');
|
||||
|
||||
ini_set('display_errors', 0);
|
||||
error_reporting(E_ERROR | E_WARNING | E_PARSE);
|
||||
|
||||
class FormHall extends Form {
|
||||
|
||||
private $option;
|
||||
|
||||
//Constructor:
|
||||
public function __construct() {
|
||||
parent::__construct('formHall');
|
||||
public function __construct($option) {
|
||||
$this->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';
|
||||
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';
|
||||
$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">
|
||||
<form method="post" id="seat_filter" action="./?state='.$data['option'].'"\>
|
||||
//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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
$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>
|
||||
<input type="number" name="rows" value="'.$rows.'" min="1" placeholder="Numero de filas" required/> <br>
|
||||
<input type="number" name="cols" value="'.$cols.'" min="1" placeholder="Numero de cols" required/> <br>
|
||||
<button type="submit" name="seat_filter" class="button large">Actualizar</button><br>
|
||||
</fieldset>
|
||||
</form>
|
||||
<br>
|
||||
<br>
|
||||
<form method="post" id="'.$data['option'].'" action="./includes/processForm.php"\>
|
||||
<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>
|
||||
<input type="number" name="number" value="'.$number.'" min="1" placeholder="Numero de la sala" required/> <br>
|
||||
<input type="hidden" name="rows" value="'.$rows.'" min="1"/>
|
||||
<input type="hidden" name="cols" value="'.$cols.'" min="1"/>
|
||||
';
|
||||
if($data['option'] == "new_hall")
|
||||
$htmlform .= '<button type="submit" name="new_hall" class="button large">Crear</button><br>';
|
||||
if($data['option'] == "edit_hall"){
|
||||
$htmlform .= '
|
||||
<button type="submit" name="edit_hall" class="button large">Editar</button><br>
|
||||
<button type="submit" name="delete_hall" class="primary">Borrar</button><br>';
|
||||
}
|
||||
|
||||
$htmlform .= '
|
||||
<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>
|
||||
|
||||
</div>
|
||||
';
|
||||
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">
|
||||
<h3 class="table_title"> Pantalla </h3>
|
||||
<table class="seat">
|
||||
@ -52,49 +99,95 @@ class FormHall extends Form {
|
||||
<tr>
|
||||
<th></th>';
|
||||
for($j = 1; $j<=$cols; $j++){
|
||||
$htmlform .= '<th>'.$j.'</th>';
|
||||
$html .= '<th>'.$j.'</th>';
|
||||
}
|
||||
$htmlform .= '</tr>
|
||||
$html .= '</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
for($i = 1;$i<=$rows;$i++){
|
||||
$htmlform .= '
|
||||
$html .= '
|
||||
<tr>
|
||||
<td>'.$i.'</td>
|
||||
';
|
||||
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>';
|
||||
}
|
||||
|
||||
$htmlform .= '
|
||||
$html .= '
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
';
|
||||
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 if($data["option"] == "delete_hall") {
|
||||
$_SESSION['msg'] = Hall::delete_hall($data);
|
||||
header( "Location: ../?state=success" );
|
||||
}else{
|
||||
$seats_map[$i][$j] = "-1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
<!DOCTYPE HTML>
|
||||
<?php
|
||||
|
||||
ini_set('display_errors', 0);
|
||||
error_reporting(E_ERROR | E_WARNING | E_PARSE);
|
||||
|
||||
//General Config File:
|
||||
require_once('../assets/php/config.php');
|
||||
//Controller file:
|
||||
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"){
|
||||
|
||||
$_SESSION["cinema"] = 1;
|
||||
switch($_GET["state"]){
|
||||
case "view_ruser":
|
||||
case "view_user":
|
||||
|
@ -36,7 +36,15 @@
|
||||
}
|
||||
|
||||
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">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -47,7 +55,8 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
foreach(Hall::getListHalls($_SESSION["cinema"]) as $hall){
|
||||
|
||||
foreach($listhall as $hall){
|
||||
$panel .='
|
||||
<tr>
|
||||
<td> '. $hall->getNumber().'</td>
|
||||
@ -59,32 +68,39 @@
|
||||
<input name="rows" type="hidden" value="'. $hall->getNumRows().'">
|
||||
<input name="cols" type="hidden" value="'. $hall->getNumCol().'">
|
||||
<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>
|
||||
</tr>';
|
||||
}
|
||||
$panel.='
|
||||
</tbody>
|
||||
</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>
|
||||
</div>
|
||||
<div class="column side"></div>
|
||||
';
|
||||
return $panel;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static function edit_hall(){
|
||||
$data = array("option" => "edit_hall", "number" => $_POST["number"],"cols" => $_POST["cols"], "rows" => $_POST["rows"], "seats" => $_POST["seats"]);
|
||||
$panel = '<h1>Editar una sala.</h1><hr/></br>
|
||||
'. FormHall::generaCampoFormulario($data, null);
|
||||
$formHall = new FormHall("edit_hall");
|
||||
|
||||
$panel = '<h1>Editar una sala.</h1><hr/></br>'
|
||||
.$formHall->gestiona();
|
||||
return $panel;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user