Estructura terminada
Sigue faltando edit/delete halls y sessions
This commit is contained in:
parent
fbd5227780
commit
1c5e449cdb
@ -4,105 +4,42 @@ include_once($prefix.'assets/php/form.php');
|
||||
|
||||
class FormHall extends Form {
|
||||
|
||||
//Atributes:
|
||||
private $correct;
|
||||
private $reply;
|
||||
private $option;
|
||||
private $halls;
|
||||
|
||||
//Constructor:
|
||||
public function __construct() {
|
||||
parent::__construct('formSession');
|
||||
$this->reply = array();
|
||||
parent::__construct('formHall');
|
||||
}
|
||||
|
||||
public static function generaCampoFormulario($datos, $errores = array(), $option){
|
||||
if($option == "new"){
|
||||
$number = $datos['number'] ?? '';
|
||||
$rows = $datos['rows'] ?? '';
|
||||
$cols = $datos['cols'] ?? '';
|
||||
$seats = $datos['seats'] ?? '';
|
||||
|
||||
|
||||
$htmlform .= '
|
||||
<form method="post" id="new_hall" action="./includes/processForm.php"\>
|
||||
<fieldset>
|
||||
<label>Numero de sala:</label> <input type="number" name="number" value="'.$number.'" required/> <br>
|
||||
<label>Filas:</label> <input type="number" name="rows" value= "'.$rows.'" required/><br>
|
||||
<label>Columnas:</label> <input type="number" name="cols" value= "'.$cols.'" required/><br>
|
||||
<label>Butacas totales:</label> <input type="number" name="seats" value= "'.$seats.'"/><br>
|
||||
<button type="submit" name="new_hall" class="button large">Crear</button></div><br>
|
||||
</fieldset>
|
||||
</form>
|
||||
';
|
||||
}
|
||||
public static function generaCampoFormulario($data, $errores = array()){
|
||||
|
||||
$number = $data['number'] ?? '';
|
||||
$rows = $data['rows'] ?? '';
|
||||
$cols = $data['cols'] ?? '';
|
||||
$seats = $data['seats'] ?? '';
|
||||
|
||||
$htmlform .= '<form method="post" id="'.$data['option'].'" action="./includes/processForm.php"\>
|
||||
<fieldset>
|
||||
<input type="number" name="number" value="'.$number.'" min="1" placeholder="Numero de la sala" required/> <br>
|
||||
<input type="number" name="rows" value= "'.$rows.'" min="1" placeholder="Filas" required/><br>
|
||||
<input type="number" name="cols" value= "'.$cols.'" min="1" placeholder="Columnas" required/><br>
|
||||
<input type="number" name="seats" value= "'.$seats.'" min="1" placeholder="Total de butacas?" /><br>
|
||||
';
|
||||
if($data['option'] == "new_hall")
|
||||
$htmlform .= '<button type="submit" name="new_hall" class="button large">Crear</button></div><br>';
|
||||
|
||||
$htmlform .= '
|
||||
</fieldset>
|
||||
</form>';
|
||||
return $htmlform;
|
||||
}
|
||||
//Methods:
|
||||
|
||||
//Returns validation response:
|
||||
public function getReply() {
|
||||
|
||||
if($this->correct){
|
||||
if($this->option == "new"){
|
||||
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
|
||||
<p> Se ha añadido la sala correctamente en la base de datos.</p>
|
||||
<a href='../panel_manager/index.php'><button>Panel Gerente</button></a>";
|
||||
}else if($this->option == "edit"){
|
||||
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
|
||||
<p> Se ha editado la sala correctamente en la base de datos.</p>
|
||||
<a href='../panel_manager/index.php'><button>Panel Gerente</button></a>";
|
||||
}else if($this->option == "del"){
|
||||
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
|
||||
<p> Se ha eliminado la sala correctamente en la base de datos.</p>
|
||||
<a href='../panel_manager/index.php'><button>Panel Gerente</button></a>";
|
||||
}else if($this->option == "list"){
|
||||
$this->reply = $this->halls;
|
||||
}
|
||||
} else {
|
||||
$this->reply = "<h1> ERROR </h1><hr />
|
||||
<p> Ha habido un error en la operacion. Revisa los datos introducidos o ponte en contacto con el administrador de la base de datos.</p>
|
||||
<a href='../panel_manager/index.php'><button>Panel Gerente</button></a>";
|
||||
}
|
||||
return $this->reply;
|
||||
}
|
||||
|
||||
//Process form:
|
||||
public static function processesForm($data){
|
||||
if($data["option"] == "new"){
|
||||
Hall::create_hall($data);
|
||||
$_SESSION['msg'] = "La sala se ha añadido correctamente";
|
||||
if($data["option"] == "new_hall"){
|
||||
$_SESSION['msg'] = Hall::create_hall($data);
|
||||
header( "Location: ../?state=success" );
|
||||
}else {
|
||||
/* TODO
|
||||
$start = date('H:i:s', strtotime( $start ) );
|
||||
|
||||
if($option == "new"){
|
||||
|
||||
$selectSession = $bd->selectSession($cinema, $hall, $start, $date);
|
||||
if($selectSession && $selectSession->num_rows >= 1) {
|
||||
$this->correct = false;
|
||||
} else{
|
||||
$bd->createSession(null, $film, $hall,$cinema, $date, $start, $price, $format);
|
||||
}
|
||||
|
||||
mysqli_free_result($selectSession);
|
||||
|
||||
} else if ($option == "del"){
|
||||
$bd->deleteSession($id);
|
||||
|
||||
} else if ($option == "edit"){
|
||||
$bd->editSession($id, $film, $hall, $cinema, $date, $start, $price, $format);
|
||||
}
|
||||
|
||||
if($repeat > "0"){
|
||||
$repeat--;
|
||||
$date = date('Y-m-d', strtotime( $date. ' +1 day') );
|
||||
$this->processesForm($film, $hall, $cinema, $date, $start, $price, $format, $repeat);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,81 +1,94 @@
|
||||
<?php
|
||||
include_once('../assets/php/common/session_dao.php');
|
||||
include_once('../assets/php/form.php');
|
||||
require_once($prefix.'assets/php/common/session_dao.php');
|
||||
require_once($prefix.'assets/php/common/session.php');
|
||||
require_once($prefix.'assets/php/form.php');
|
||||
|
||||
require_once($prefix.'panel_admin/includes/film.php');
|
||||
require_once($prefix.'assets/php/common/film_dao.php');
|
||||
|
||||
//Receive data from froms and prepare the correct response
|
||||
class FormSession extends Form {
|
||||
//Atributes
|
||||
private $correct;
|
||||
private $reply;
|
||||
private $option;
|
||||
private $sessions;
|
||||
|
||||
//Constructor:
|
||||
|
||||
//Constructor:
|
||||
public function __construct() {
|
||||
parent::__construct('formSession');
|
||||
$this->reply = array();
|
||||
}
|
||||
|
||||
//Methods:
|
||||
public function getReply() {
|
||||
if($this->correct){
|
||||
if($this->option == "new"){
|
||||
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
|
||||
<p> Se ha añadido la sesion correctamente en la base de datos.</p>
|
||||
<a href='../panel_manager/index.php'><button>Panel Gerente</button></a>";
|
||||
}else if($this->option == "edit"){
|
||||
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
|
||||
<p> Se ha editado la sesion correctamente en la base de datos.</p>
|
||||
<a href='../panel_manager/index.php'><button>Panel Gerente</button></a>";
|
||||
}else if($this->option == "del"){
|
||||
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
|
||||
<p> Se ha eliminado la sesion correctamente en la base de datos.</p>
|
||||
<a href='../panel_manager/index.php'><button>Panel Gerente</button></a>";
|
||||
}else if($this->option == "list"){
|
||||
$this->reply = $this->sessions;
|
||||
}
|
||||
} else if($this->correct == false) {
|
||||
$this->reply = "<h1> ERROR </h1><hr />
|
||||
<p> Ha habido un error en la operacion. Revisa los datos introducidos o ponte en contacto con el administrador de la base de datos.</p>
|
||||
<a href='../panel_manager/index.php'><button>Panel Gerente</button></a>";
|
||||
}
|
||||
return $this->reply;
|
||||
}
|
||||
|
||||
public function processesForm($film, $hall, $cinema, $date, $start, $price, $format, $repeat, $option) {
|
||||
$this->option = $option;
|
||||
$this->correct = true;
|
||||
|
||||
$bd = new sessionDAO('complucine');
|
||||
|
||||
if($bd ){
|
||||
if($option == "list"){
|
||||
$this->sessions = $bd->getAllSessionsFromACinemaHallDate($cinema, $hall, $date);
|
||||
|
||||
}else {
|
||||
if($option == "new"){
|
||||
$searchSession = $bd->searchSession($cinema, $hall, $start, $date);
|
||||
if($searchSession) {
|
||||
$this->correct = false;
|
||||
} else{
|
||||
$bd->createSession(null,$film, $hall,$cinema, $date, $start, $price, $format);
|
||||
}
|
||||
|
||||
} else if ($option == "del"){
|
||||
$bd->deleteSession($hall, $cinema, $date, $start);
|
||||
|
||||
} else if ($option == "edit"){
|
||||
$bd->editSession($film, $hall, $cinema, $date, $start, $price, $format);
|
||||
public static function generaCampoFormulario($data, $errores = array()){
|
||||
|
||||
$cinema = $data['cinema'] ?? '';
|
||||
$film = $data['film'] ?? '1';
|
||||
$hall = $data['hall'] ?? '1';
|
||||
$date = $data['date'] ?? '';
|
||||
$start = $data['start'] ?? '';
|
||||
$price = $data['price'] ?? '';
|
||||
$format = $data['format'] ?? '';
|
||||
|
||||
$filmList = new Film_DAO('complucine');
|
||||
$films = $filmList->allFilmData();
|
||||
|
||||
$htmlform .= '<div class="column left">
|
||||
<form method="post" id="'.$data['option'].'" action="./includes/processForm.php"\>
|
||||
<fieldset>
|
||||
<legend>Datos</legend>
|
||||
<input type="number" name="price" value="'.$number.'" min="0" placeholder="Precio de la entrada" required/> <br>
|
||||
<input type="text" name="format" value="'.$format.'" placeholder="Formato de pelicula" required/> <br>
|
||||
<select name="hall" class="button large">';
|
||||
foreach(Hall::getListHalls($cinema) as $hll){
|
||||
if($hll->getNumber() == $hall){
|
||||
$htmlform.= '
|
||||
<option value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> ';
|
||||
}else{
|
||||
$htmlform.= '
|
||||
<option value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>';
|
||||
}
|
||||
|
||||
if($repeat > "0"){
|
||||
$repeat--;
|
||||
$date = date('Y-m-d', strtotime( $date. ' +1 day') );
|
||||
$this->processesForm($film, $hall, $cinema, $date, $start, $price, $format, $repeat, $option);
|
||||
}
|
||||
}
|
||||
} else {$this->correct = false;}
|
||||
}
|
||||
$htmlform.= '
|
||||
</select>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Horario</legend>
|
||||
<input type="time" name="start" value="'.$start.'" placeholder="Hora de inicio" required/> <br>
|
||||
<input type="date" name="date" value="'.$date.'" placeholder="Fecha de inicio" required/> <br>
|
||||
</fieldset>
|
||||
<input type="number" name="repeat" value="" min="0" title="Añadir esta sesion durante los proximos X dias" min="0" max="31" placeholder="Añadir X dias"/> <br>
|
||||
<input type="reset" value="Limpiar Campos" >
|
||||
';
|
||||
if($data['option'] == "new_session")
|
||||
$htmlform .= '<button type="submit" name="new_session" class="button large">Crear</button><br>';
|
||||
if($data['option'] == "edit_session")
|
||||
$htmlform .= '<button type="submit" name="edit_session" class="button large">Editar</button><br>
|
||||
<button type="submit" name="delete_session" class="primary">Borrar</button><br>';
|
||||
$htmlform .= '
|
||||
</form>
|
||||
</div>
|
||||
<div class="column right">
|
||||
<select name="film" form="'.$data['option'].'" class="button large">';
|
||||
foreach($films as $f){
|
||||
if($f->getId() == $film){
|
||||
$htmlform.= '
|
||||
<option value="'. $f->getId() .'" selected> '.$f->getId().' | '.str_replace('_', ' ',$f->getTittle()).' Idioma: '.$f->getLanguage().' </option>';
|
||||
}else {
|
||||
$htmlform.= '
|
||||
<option value="'. $f->getId() .'"> '.$f->getId().' | '.str_replace('_', ' ',$f->getTittle()).' Idioma: '.$f->getLanguage().' </option>';
|
||||
}
|
||||
}
|
||||
$htmlform .= '
|
||||
</select>
|
||||
</div>
|
||||
';
|
||||
return $htmlform;
|
||||
}
|
||||
//Methods:
|
||||
|
||||
//Process form:
|
||||
public static function processesForm($data){
|
||||
if($data["option"] == "new_session"){
|
||||
$_SESSION['msg'] = Session::create_session($data);
|
||||
header( "Location: ../?state=success" );
|
||||
}else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,19 @@
|
||||
<?php
|
||||
//General Config File:
|
||||
//General Config File:
|
||||
require_once('../../assets/php/config.php');
|
||||
|
||||
$prefix ="../../";
|
||||
include_once('formHall.php');
|
||||
include_once('formSession.php');
|
||||
|
||||
if(isset($_POST['new_hall'])){
|
||||
$data = array("option" => "new","number" => $_POST["number"],"cols" => $_POST["cols"],"rows" => $_POST["rows"], "cinema" => "1");
|
||||
$data = array("option" => "new_hall","number" => $_POST["number"],"cols" => $_POST["cols"],"rows" => $_POST["rows"], "cinema" => $_SESSION["cinema"]);
|
||||
FormHall::processesForm($data);
|
||||
}
|
||||
|
||||
if(isset($_POST['new_session'])){
|
||||
$data = array("option" => "new_session","film" => $_POST["film"],"hall" => $_POST["hall"],"date" => $_POST["date"],"start" => $_POST["start"]
|
||||
,"price" => $_POST["price"],"format" => $_POST["format"],"repeat" => $_POST["repeat"], "cinema" => $_SESSION["cinema"]);
|
||||
FormSession::processesForm($data);
|
||||
}
|
||||
?>
|
@ -9,6 +9,7 @@
|
||||
include_once('panel_manager.php');
|
||||
|
||||
if($_SESSION["login"] && $_SESSION["rol"] === "manager"){
|
||||
$_SESSION["cinema"] = "1";
|
||||
switch($_GET["state"]){
|
||||
case "view_ruser":
|
||||
case "view_user":
|
||||
@ -31,6 +32,12 @@
|
||||
break;
|
||||
case "manage_sessions":
|
||||
$panel = Manager_panel::manage_sessions();
|
||||
break;
|
||||
case "new_session":
|
||||
$panel = Manager_panel::new_session();
|
||||
break;
|
||||
case "edit_session":
|
||||
$panel = Manager_panel::edit_session();
|
||||
break;
|
||||
case "success":
|
||||
$panel = Manager_panel::success();
|
||||
@ -75,14 +82,13 @@
|
||||
<!-- Panel -->
|
||||
<div class="row">
|
||||
<!-- Panel Menu -->
|
||||
<?php
|
||||
$template->print_panelMenu($_SESSION["rol"]);
|
||||
?>
|
||||
<?php $template->print_panelMenu($_SESSION["rol"]); ?>
|
||||
</div>
|
||||
<!--Contents -->
|
||||
<div class="row">
|
||||
<?php echo $panel; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<?php echo $panel; ?>
|
||||
</div>
|
||||
|
||||
<!-- Footer -->
|
||||
<?php
|
||||
$template->print_footer();
|
||||
|
@ -1,11 +1,12 @@
|
||||
<?php
|
||||
include_once('../assets/php/common/hall.php');
|
||||
include_once('../assets/php/common/session.php');
|
||||
include_once('./includes/formHall.php');
|
||||
|
||||
include_once('./includes/formSession.php');
|
||||
|
||||
|
||||
class Manager_panel {
|
||||
|
||||
private $form;
|
||||
|
||||
function __construct($panel,$log){
|
||||
$this->state = $panel;
|
||||
$this->login = $log;
|
||||
@ -38,39 +39,39 @@
|
||||
|
||||
static function manage_halls(){
|
||||
$panel = '<form method="post" action="./?state=new_hall">
|
||||
<table class="alt">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Numero</th>
|
||||
<th>Filas</th>
|
||||
<th>Columnas</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
foreach(Hall::getListHalls("1") as $hall){
|
||||
<table class="alt">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Numero</th>
|
||||
<th>Filas</th>
|
||||
<th>Columnas</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
foreach(Hall::getListHalls($_SESSION["cinema"]) as $hall){
|
||||
$panel .='
|
||||
<tr>
|
||||
<td> '. $hall->getNumber().'</td>
|
||||
<td> '. $hall->getNumRows().'</td>
|
||||
<td> '. $hall->getNumCol().'</td>
|
||||
<td> <input type="submit" name="edit" value="Editar" class="button" formaction="./?state=edit_hall&number='.$hall->getNumber().'" ></td>
|
||||
</tr>';
|
||||
<tr>
|
||||
<td> '. $hall->getNumber().'</td>
|
||||
<td> '. $hall->getNumRows().'</td>
|
||||
<td> '. $hall->getNumCol().'</td>
|
||||
<td> <input type="submit" name="edit" value="Editar" class="button" formaction="./?state=edit_hall&number='.$hall->getNumber().'" ></td>
|
||||
</tr>';
|
||||
}
|
||||
$panel.='
|
||||
</tbody>
|
||||
</table>
|
||||
<input type="submit" name="new" value="Añadir" class="button large" >
|
||||
</form>';
|
||||
</tbody>
|
||||
</table>
|
||||
<input type="submit" name="new" value="Añadir" class="button large" >
|
||||
</form>
|
||||
';
|
||||
return $panel;
|
||||
}
|
||||
|
||||
static function new_hall(){
|
||||
$data = array("option" => "new_hall");
|
||||
$panel = '<div class="column side"></div>
|
||||
<div class="column middle">
|
||||
<div class="column middle">
|
||||
<h1>Crear una sala.</h1><hr /></br>
|
||||
'.
|
||||
FormHall::generaCampoFormulario(null, null, "new");
|
||||
'.
|
||||
'. FormHall::generaCampoFormulario($data, null).'
|
||||
</div>
|
||||
<div class="column side"></div>'."\n";
|
||||
|
||||
@ -81,6 +82,7 @@
|
||||
$panel = '<div class="column side"></div>
|
||||
<div class="column middle">
|
||||
<h1>Editar una sala.</h1><hr /></br>
|
||||
<p> En desarrollo... </p>
|
||||
</div>
|
||||
<div class="column side"></div>'."\n";
|
||||
|
||||
@ -88,16 +90,93 @@
|
||||
}
|
||||
|
||||
static function manage_sessions(){
|
||||
$name = strtoupper($_SESSION['nombre']);
|
||||
|
||||
$panel = '<div class="code info">
|
||||
<h1>Bienvenido '.$name.' a tu Panel de Manager.</h1>
|
||||
<hr />
|
||||
<p>Usuario: '.$name.'</p>
|
||||
<p>Espero que estes pasando un buen dia</p>
|
||||
</div>'."\n";
|
||||
//Base filtering values
|
||||
$date = isset($_POST['date']) ? $_POST['date'] : date("Y-m-d");
|
||||
$hall = isset($_POST['hall']) ? $_POST['hall'] : "1";
|
||||
|
||||
//Session filter
|
||||
$panel='<div class = "column left">
|
||||
<form method="post" id="filter" action="./?state=manage_sessions">
|
||||
<input type="date" name="date" value="'.$date.'" min="2021-01-01" max="2031-12-31">
|
||||
<select name="hall" class="button large">';
|
||||
|
||||
foreach(Hall::getListHalls($_SESSION["cinema"]) as $hll){
|
||||
if($hll->getNumber() == $hall){
|
||||
$panel.= '
|
||||
<option value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> ';
|
||||
}else{
|
||||
$panel.= '
|
||||
<option value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>';
|
||||
}
|
||||
}
|
||||
$panel.='
|
||||
</select>
|
||||
<input type="submit" name="filter" value="Filtrar" class="button large"/>
|
||||
</form>
|
||||
</div>
|
||||
';
|
||||
//Session list
|
||||
$panel .='<div class = "column right">';
|
||||
$sessions = Session::getListSessions($hall,$_SESSION["cinema"],$date);
|
||||
|
||||
if($sessions) {
|
||||
$panel .='
|
||||
<form method="post" action="./?state=edit_session">
|
||||
<table class="alt">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Hora</th>
|
||||
<th>Pelicula</th>
|
||||
<th>Formato</th>
|
||||
<th>Precio</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
|
||||
|
||||
foreach($sessions as $session){
|
||||
$panel .='
|
||||
<tr>
|
||||
<td> '.date("H:i", strtotime( $session->getStartTime())).' </td>
|
||||
<td> '. str_replace('_', ' ', Session::getFilmTitle($session->getIdfilm())) .' </td>
|
||||
<td> '.$session->getFormat().' </td>
|
||||
<td> '.$session->getSeatPrice().' </td>
|
||||
<td> <input type="submit" name="edit" value="Editar" class="button" ></td>
|
||||
</tr>';
|
||||
}
|
||||
$panel.='
|
||||
</tbody>
|
||||
</table>
|
||||
</form>';
|
||||
} else {
|
||||
$panel.=' <h3> No hay ninguna sesion </h3>';
|
||||
}
|
||||
$panel.='
|
||||
<input type="submit" name="submit" form="filter" value="Añadir" class="button large" formaction="./?state=new_session">
|
||||
</div>
|
||||
';
|
||||
|
||||
return $panel;
|
||||
}
|
||||
|
||||
static function new_session(){
|
||||
$data = array("option" => "new_session","hall" => $_POST['hall'],"cinema" => $_SESSION["cinema"],"date" => $_POST['date']);
|
||||
|
||||
$panel = '<h1>Crear una sesión.</h1><hr /></br>
|
||||
'.FormSession::generaCampoFormulario($data, null);
|
||||
|
||||
return $panel;
|
||||
}
|
||||
|
||||
static function edit_session(){
|
||||
$panel = '<div class="column side"></div>
|
||||
<div class="column middle">
|
||||
<h1>Editar una session.</h1><hr /></br>
|
||||
<p> En desarrollo... </p>
|
||||
</div>
|
||||
<div class="column side"></div>'."\n";
|
||||
|
||||
return $panel;
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user