Añadir/editar/borrar sesiones 100% funcional

This commit is contained in:
Markines16 2021-05-09 17:50:30 +02:00 committed by GitHub
parent 871a7e1a7f
commit e207fe0155
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 33 deletions

View File

@ -11,6 +11,7 @@ class FormSession extends Form {
parent::__construct('formSession'); parent::__construct('formSession');
} }
//TODO Edit session no funciona correctamente con el seleccionar una pelicula distinta, hay que guardar la id de la sesion de alguna forma y usarla o guardar en la sesion
public static function generaCampoFormulario($data, $errores = array()){ public static function generaCampoFormulario($data, $errores = array()){
$cinema = $data['cinema'] ?? ''; $cinema = $data['cinema'] ?? '';
@ -25,9 +26,9 @@ class FormSession extends Form {
<form method="post" id="'.$data['option'].'" action="./includes/processForm.php"\> <form method="post" id="'.$data['option'].'" action="./includes/processForm.php"\>
<fieldset> <fieldset>
<legend>Datos</legend> <legend>Datos</legend>
<input type="number" name="price" value="'.$price.'" min="0" placeholder="Precio de la entrada" required/> <br> <input type="number" step="0.01" name="price" value="'.$price.'" min="0" placeholder="Precio de la entrada" required/> <br>
<input type="text" name="format" value="'.$format.'" placeholder="Formato de pelicula" required/> <br> <input type="text" name="format" value="'.$format.'" placeholder="Formato de pelicula" required/> <br>
<input type="text" name="film" value="'.$film["idfilm"].'" placeholder="Selecciona una Pelicula" readonly/> <input type="hidden" name="film" value="'.$film["idfilm"].'"/>
<select name="hall" class="button large">'; <select name="hall" class="button large">';
foreach(Hall::getListHalls($cinema) as $hll){ foreach(Hall::getListHalls($cinema) as $hll){
if($hll->getNumber() == $hall){ if($hll->getNumber() == $hall){
@ -47,19 +48,20 @@ class FormSession extends Form {
<input type="date" name="date" value="'.$date.'" placeholder="Fecha de inicio" required/> <br> <input type="date" name="date" value="'.$date.'" placeholder="Fecha de inicio" required/> <br>
</fieldset> </fieldset>
'; ';
if($data['option'] == "new_session") if($film){
$htmlform .= '<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> if($data['option'] == "new_session")
<button type="submit" name="new_session" class="button large">Crear</button><br>'; $htmlform .= '<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>
if($data['option'] == "edit_session"){ <button type="submit" name="new_session" class="button large">Crear</button><br>';
$_SESSION["session"] = $data['id'] ?? Session::getThisSessionId($cinema, $hall, $start, $date)["id"];
if($data['option'] == "edit_session"){
$htmlform .= ' if(!$_SESSION["or_hall"]) $_SESSION["or_hall"] = $hall;
<input name="origin_hall" type="hidden" value="'.$hall.'"> if(!$_SESSION["or_date"]) $_SESSION["or_date"] = $date;
<input name="origin_date" type="hidden" value="'.$date.'"> if(!$_SESSION["or_start"])$_SESSION["or_start"] = $start;
<input name="origin_start" type="hidden" value="'.$start.'">
<button type="submit" name="edit_session" class="button large">Editar</button><br> $htmlform .= '
<button type="submit" name="delete_session" class="primary">Borrar</button><br>'; <button type="submit" name="edit_session" class="button large">Editar</button><br>
<button type="submit" name="delete_session" class="primary">Borrar</button><br>';
}
} }
$htmlform .= " $htmlform .= "
<input type='reset' value='Limpiar Campos' > <input type='reset' value='Limpiar Campos' >
@ -70,7 +72,7 @@ class FormSession extends Form {
$htmlform .= " <section id='".$film["tittle"]."'> $htmlform .= " <section id='".$film["tittle"]."'>
<div class='code showtimes'> <div class='code showtimes'>
<div class='image'><img src='../img/".$film["tittle"].".jpg' alt='".$film["tittle"]."' /></div> <div class='image'><img src='../img/".$film["tittle"].".jpg' alt='".$film["tittle"]."' /></div>
<h2>".$film["tittle"]."</h2> <h2>".str_replace('_', ' ',$film["tittle"])."</h2>
<hr /> <hr />
<div class='blockquote'> <div class='blockquote'>
<p>".$film["description"]."</p> <p>".$film["description"]."</p>
@ -80,7 +82,7 @@ class FormSession extends Form {
</section> </section>
"; ";
} }
$htmlform .= '<a href="?state=select_film&option='.$data['option'].'" <button name="select_film" class="button large">Seleccionar una Pelicula</button></a><br> $htmlform .= '<button type="submit" name="select_films" form="'.$data['option'].'" formaction="?state=select_film&option='.$data['option'].'" class="button large">Seleccionar una Pelicula</button><br>
</div> </div>
'; ';
return $htmlform; return $htmlform;

View File

@ -44,11 +44,15 @@
,"price" => $_POST["price"],"format" => $_POST["format"],"repeat" => $_POST["repeat"], "cinema" => $_SESSION["cinema"]); ,"price" => $_POST["price"],"format" => $_POST["format"],"repeat" => $_POST["repeat"], "cinema" => $_SESSION["cinema"]);
FormSession::processesForm($data); FormSession::processesForm($data);
} }
if(isset($_POST['edit_session'])){ if(isset($_POST['edit_session'])){
$data = array("option" => "edit_session","film" => $_POST["film"],"hall" => $_POST["hall"],"date" => $_POST["date"],"start" => $_POST["start"] $data = array("option" => "edit_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"] ,"price" => $_POST["price"],"format" => $_POST["format"],"repeat" => $_POST["repeat"], "cinema" => $_SESSION["cinema"]
, "origin_hall"=> $_POST["origin_hall"],"origin_date"=> $_POST["origin_date"],"origin_start"=> $_POST["origin_start"]); , "origin_hall"=>$_SESSION["or_hall"],"origin_date"=> $_SESSION["or_date"],"origin_start"=> $_SESSION["or_start"]);
$_SESSION["or_hall"] = "";
$_SESSION["or_date"] = "";
$_SESSION["or_start"] = "";
FormSession::processesForm($data); FormSession::processesForm($data);
} }

View File

@ -5,9 +5,15 @@
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";
if(!$_SESSION["cinema"])
$_SESSION["cinema"] = Manager::getManager(unserialize($_SESSION['user'])->getId())->getIdcinema();
switch($_GET["state"]){ switch($_GET["state"]){
case "view_ruser": case "view_ruser":
case "view_user": case "view_user":
@ -65,7 +71,7 @@
CompluCine - FDI-cines CompluCine - FDI-cines
--> -->
<html lang="es"> <html lang="es">
<link id='estilo' rel='stylesheet' type='text/css' href='includes/manager.css'> <link id='estilo' rel='stylesheet' type='text/css' href='../assets/css/manager.css'>
<!-- Head --> <!-- Head -->
<?php <?php
$template->print_head(); $template->print_head();

View File

@ -11,11 +11,13 @@
static function welcome(){ static function welcome(){
$name = strtoupper($_SESSION['nombre']); $name = strtoupper($_SESSION['nombre']);
$cinema = strtoupper($_SESSION['cinema']);
$panel = '<div class="code info"> $panel = '<div class="code info">
<h1>Bienvenido '.$name.' a tu Panel de Manager.</h1> <h1>Bienvenido '.$name.' a tu Panel de Manager.</h1>
<hr /> <hr />
<p>Usuario: '.$name.'</p> <p>Usuario: '.$name.'</p>
<p>Cine: '.$cinema.'</p>
<p>Espero que estes pasando un buen dia</p> <p>Espero que estes pasando un buen dia</p>
</div>'."\n"; </div>'."\n";
@ -138,7 +140,6 @@
<td> '. str_replace('_', ' ', Session::getThisSessionFilm($session->getIdfilm())["tittle"]) .' </td> <td> '. str_replace('_', ' ', Session::getThisSessionFilm($session->getIdfilm())["tittle"]) .' </td>
<td> '.$session->getFormat().' </td> <td> '.$session->getFormat().' </td>
<td> '.$session->getSeatPrice().' </td> <td> '.$session->getSeatPrice().' </td>
<td> <input type="date" name="date" value="'.$date.'">
<form method="post" action="./?state=edit_session"> <form method="post" action="./?state=edit_session">
<input name="film" type="hidden" value="'.$session->getIdfilm().'"> <input name="film" type="hidden" value="'.$session->getIdfilm().'">
<input name="hall" type="hidden" value="'.$session->getIdhall().'"> <input name="hall" type="hidden" value="'.$session->getIdhall().'">
@ -158,36 +159,50 @@
$panel.=' <h3> No hay ninguna sesion </h3>'; $panel.=' <h3> No hay ninguna sesion </h3>';
} }
$panel.=' $panel.='
<input type="submit" name="submit" form="filter" value="Añadir" class="button large" formaction="./?state=new_session"> <input type="submit" name="new_session" form="filter" value="Añadir" class="button large" formaction="./?state=new_session">
</div> </div>
'; ';
return $panel; return $panel;
} }
static function new_session(){ static function new_session(){
$data = array("option" => "new_session","hall" => $_POST['hall'],"cinema" => $_SESSION["cinema"],"date" => $_POST['date']); echo "inicio";
if(isset($_POST["new_session"])){
$data = array("option" => "new_session","hall" => $_POST['hall'],"cinema" => $_SESSION["cinema"],"date" => $_POST['date']);
}else if(isset($_POST["select_film"])){
$film = array("idfilm" => $_POST["id"],"tittle" => $_POST["tittle"], "description" => $_POST["description"], "duration" => $_POST["duration"]);
$data = array("option" => "new_session","hall" => $_POST['hall'],"cinema" => $_SESSION["cinema"],"date" => $_POST['date'],"film" => $film, "start" => $_POST['start']
, "price" => $_POST['price'], "format" => $_POST['format']);
}
$panel = '<h1>Crear una sesión.</h1><hr /></br> if($data){
'.FormSession::generaCampoFormulario($data, null); $panel = '<h1>Crear una sesión.</h1><hr /></br>
'.FormSession::generaCampoFormulario($data, null);
}else $panel = self::warning();
return $panel; return $panel;
} }
static function edit_session(){ static function edit_session(){
if(isset($_POST["edit_session"])){ if(isset($_POST["edit_session"])){
$_SESSION["or_hall"] = "";
$_SESSION["or_date"] = "";
$_SESSION["or_start"] = "";
$film = Session::getThisSessionFilm($_POST["film"]); $film = Session::getThisSessionFilm($_POST["film"]);
$data = array("option" => "edit_session","hall" => $_POST["hall"],"cinema" => $_SESSION["cinema"],"date" => $_POST['date'],"film" => $film, $data = array("option" => "edit_session","hall" => $_POST["hall"],"cinema" => $_SESSION["cinema"],"date" => $_POST['date'],"film" => $film,
"start" => $_POST['start'],"price" => $_POST['price'],"format" => $_POST['format']); "start" => $_POST['start'],"price" => $_POST['price'],"format" => $_POST['format']);
}else if(isset($_SESSION["session"])){ }else if(isset($_SESSION["session"])){
$session = Session::getThisSessionFromId($_SESSION["session"]);
$_SESSION["session"] = "";
$film = array("idfilm" => $_POST["id"],"tittle" => $_POST["tittle"], "description" => $_POST["description"], "duration" => $_POST["duration"]); $film = array("idfilm" => $_POST["id"],"tittle" => $_POST["tittle"], "description" => $_POST["description"], "duration" => $_POST["duration"]);
echo $film["id"] . " y el titulo es: " . $film["tittle"]; $data = array("option" => "edit_session","hall" => $_POST['hall'],"cinema" => $_SESSION["cinema"],"date" => $_POST['date'],"film" => $film, "start" => $_POST['start']
$data = array("option" => "edit_session","hall" => $session["idhall"],"cinema" => $_SESSION["cinema"],"date" => $session["date"],"film" => $film, , "price" => $_POST['price'], "format" => $_POST['format']);
"start" => $session["start_time"],"price" => $session["seat_price"],"format" => $session["format"]);
} }
if($data){ if($data){