Add files via upload

This commit is contained in:
Fernando Méndez
2021-05-17 15:29:29 +02:00
committed by GitHub
parent 4e92236fab
commit 6a9b6cd8a4
72 changed files with 8866 additions and 0 deletions

View File

@ -0,0 +1,201 @@
<?php
include_once($prefix.'assets/php/common/hall.php');
include_once($prefix.'assets/php/common/seat.php');
include_once($prefix.'assets/php/form.php');
class FormHall extends Form {
private $option;
private $cinema;
//Constructor:
public function __construct($option, $cinema) {
$this->option = $option;
$this->cinema = $cinema;
$options = array("action" => "./?state=".$option);
parent::__construct('formHall',$options);
}
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;
//Seats_map
$seats = 0;
$seats_map = array();
for($i = 1;$i <= $rows; $i++){
for($j = 1; $j <= $cols; $j++){
$seats_map[$i][$j] = "-1";
}
}
//Show the original seats_map once u click restart or the first time u enter this form from manage_halls's form
if(isset($data["restart"]) || isset($_POST["edit_hall"]) ){
$seat_list = Seat::getSeatsMap($og_number, $this->cinema);
if($seat_list){
foreach($seat_list 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++){
if($alltoone || isset($data["checkbox".$i.$j])) {
$seats_map[$i][$j] = $data["checkbox".$i.$j] ?? "0";
$seats++;
if($seats_map[$i][$j] == "-1"){
$seats_map[$i][$j] = "0";
}
}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>Mapa de Asientos</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" name="alltoone" value="Activar todos los asientos" class="button large" />';
if($this->option == "edit_hall")
$html .= ' <input type="submit" id="restart" name="restart" value="Restaurar mapa original" class="black button" />';
$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" 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" onclick="return confirm(\'Seguro que quieres borrar esta sala?\')" value="Eliminar Sala" class="black button" />
';
}
$html .='</div>
<div class="column right">
<h3 class="table_title"> Pantalla </h3>
<table class="seat">
<thead>
<tr>
<th> </th>
';
for($j = 1; $j<=$cols; $j++){
$html .= '<th>'.$j.'</th>
';
}
$html .= '</tr>
</thead>
<tbody>';
for($i = 1;$i<=$rows;$i++){
$html .= '
<tr>
<td>'.$i.'</td>
';
for($j=1; $j<=$cols; $j++){
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>
';}
}
$html .='</tr>';
}
$html .= '
</tbody>
</table>
</div>';
return $html;
}
//Methods:
//Process form:
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";
}
}
}
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, $this->cinema, $rows, $cols, $seats, $seats_map);
$result = './?state=success';
}
if($this->option == "edit_hall"){
$_SESSION['msg'] = Hall::edit_hall($number,$this->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, $this->cinema, $rows, $cols, $seats, $seats_map, $og_number);
$result = './?state=success';
}
}
return $result;
}
}
?>

View File

@ -0,0 +1,150 @@
<?php
require_once($prefix.'assets/php/common/session_dao.php');
require_once($prefix.'assets/php/common/film_dao.php');
require_once($prefix.'assets/php/common/session.php');
require_once($prefix.'assets/php/form.php');
//Receive data from froms and prepare the correct response
class FormSession extends Form {
private $option;
private $cinema;
//Constructor:
public function __construct($option, $cinema) {
$this->option = $option;
$this->cinema = $cinema;
$options = array("action" => "./?state=".$option);
parent::__construct('formSession',$options);
}
//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
protected function generaCamposFormulario($data, $errores = array()){
$filmList = new Film_DAO('complucine');
$films = $filmList->allFilmData();
if($this->option == "new_session") {
$film = $data['film'] ?? 1;
$hall = $data['hall'] ?? $_POST["hall"];
$date = $data['date'] ?? $_POST["date"];
$start = $data['start'] ?? '';
$price = $data['price'] ?? '';
$format = $data['format'] ?? '';
}
else {
$film = $data['film'] ?? $_POST["film"];
$hall = $data['hall'] ?? $_POST["hall"];
$date = $data['date'] ?? $_POST["date"];
$start = $data['start'] ?? $_POST["start"];
$price = $data['price'] ?? $_POST["price"];
$format = $data['format'] ?? $_POST["format"];
}
$or_hall = $data["or_hall"] ?? $hall;
$or_date = $data["or_date"] ?? $date;
$or_start = $data["or_start"] ?? $start;
$htmlErroresGlobales = self::generaListaErroresGlobales($errores);
$errorPrice = self::createMensajeError($errores, 'price', 'span', array('class' => 'error'));
$errorFormat = self::createMensajeError($errores, 'format', 'span', array('class' => 'error'));
$html = '
<div class="column left">'.$htmlErroresGlobales.' '.$errorPrice.'
<fieldset>
<legend>Datos</legend>
<input type="number" step="0.01" name="price" value="'.$price.'" min="0" placeholder="Precio de la entrada" required/> <br>'.$errorFormat.'
<input type="text" name="format" value="'.$format.'" placeholder="Formato de pelicula" required/> <br>
<input type="hidden" name="film" value="'.$film.'"/>
<select name="hall" class="button large">';
foreach(Hall::getListHalls($this->cinema) as $hll){
if($hll->getNumber() == $hall){
$html.= '
<option value="'. $hll->getNumber() .'"selected> Sala '. $hll->getNumber() .'</option> ';
}else{
$html.= '
<option value="'. $hll->getNumber() .'"> Sala '. $hll->getNumber() .'</option>';
}
}
$html.= '
</select>
<input type="hidden" name="or_hall" value="'.$or_hall.'"/>
</fieldset>
<fieldset>
<legend>Horario</legend>
<input type="time" name="start" value="'.$start.'" placeholder="Hora de inicio" required/> <br>
<input type="hidden" name="or_start" value="'.$or_start.'"/>
<input type="date" name="date" value="'.$date.'" placeholder="Fecha de inicio" required/> <br>
<input type="hidden" name="or_date" value="'.$or_date.'"/>
</fieldset>
';
if($film){
if($this->option == "new_session")
$html .= '<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="submit" id="submit" name="sumbit" class="primary" value="Crear" /> <br>';
if($this->option == "edit_session"){
$html .= '<input type="submit" id="submit" name="sumbit" class="primary" value="Editar" /><br>
<input type="submit" name="delete" class="black button" onclick="return confirm(\'Seguro que quieres borrar esta sesion?\')" value="Borrar" /><br>';
}
}
$html .= '
<input type="reset" id="reset" value="Limpiar Campos" />
</div>
<div class="column rigth">
<select name="film" class="button large">
';
foreach($films as $f){
if($f->getId() == $film){
$html .= "<option value=\"". $f->getId() ." \"selected> " . $f->getId() . "|" . $f->getTittle() ." Idioma: " . $f->getLanguage() . "</option>
";
}else{
$html .= "<option value=\"". $f->getId() ." \"> " . $f->getId() . "|" . $f->getTittle() ." Idioma: " . $f->getLanguage() . "</option>
";
}
}
$html .= '</select>';
return $html;
}
//Methods:
//Process form:
protected function procesaFormulario($data){
$result = array();
$film = $data['film'] ;
$hall = $data['hall'] ;
$date = $data['date'] ;
$start = $data['start'];
$price = $data['price'] ;
$format = $data['format'] ;
$repeat = $data['repeat'] ?? 0;
$or_hall = $data["or_hall"] ;
$or_date = $data["or_date"] ;
$or_start = $data["or_start"] ;
if (($price == 0 || empty($price))&& isset($data["sumbit"]) ) {
$result['price'] = "<li> No puede haber 0 euros. </li> <br>";
}
if (count($result) === 0 && isset($data["sumbit"]) ) {
if($this->option == "new_session"){
$_SESSION['msg'] = Session::create_session($this->cinema, $hall, $start, $date, $film, $price, $format,$repeat);
$result = './?state=success';
}
if($this->option == "edit_session"){
$_SESSION['msg'] = Session::edit_session($this->cinema, $or_hall, $or_date, $or_start, $hall, $start, $date, $film, $price, $format);
$result = './?state=success';
}
}
if(!isset($result['hall']) && !isset($result['start']) && !isset($result['date']) && isset($data["delete"])) {
$_SESSION['msg'] = Session::delete_session($this->cinema, $or_hall, $or_start, $or_date);
$result = './?state=success';
}
return $result;
}
}
?>

View File

@ -0,0 +1,65 @@
<?php
//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_hall","number" => $_POST["number"],"cols" => $_POST["cols"],"rows" => $_POST["rows"], "cinema" => $_SESSION["cinema"], "seats" => 0);
//Check what checkboxs are seats or not
for($i = 1;$i<=$data["rows"];$i++){
for($j=1; $j<=$data["cols"]; $j++){
if(!empty($_POST['checkbox'.$i.$j.''])){
$data[$i][$j] = $_POST['checkbox'.$i.$j.''];
$data["seats"]++;
} else $data[$i][$j] = "-1";
}
}
FormHall::processesForm($data);
}
if(isset($_POST['edit_hall'])){
$data = array("option" => "edit_hall","number" => $_POST["number"],"cols" => $_POST["cols"],"rows" => $_POST["rows"], "cinema" => $_SESSION["cinema"],"seats" => 0);
//Check what checkboxs are seats or not
for($i = 1;$i<=$data["rows"];$i++){
for($j=1; $j<=$data["cols"]; $j++){
if(!empty($_POST['checkbox'.$i.$j.''])){
$data[$i][$j] = $_POST['checkbox'.$i.$j.''];
$data["seats"]++;
} else $data[$i][$j] = "-1";
}
}
FormHall::processesForm($data);
}
if(isset($_POST['delete_hall'])){
$data = array("option" => "delete_hall","number" => $_POST["number"], "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);
}
if(isset($_POST['edit_session'])){
$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"]
, "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);
}
if(isset($_POST['delete_session'])){
$data = array("option" => "delete_session","cinema" => $_SESSION["cinema"], "hall"=> $_POST["origin_hall"]
,"date"=> $_POST["origin_date"],"start"=> $_POST["origin_start"]);
FormSession::processesForm($data);
}
?>

90
panel_manager/index.php Normal file
View File

@ -0,0 +1,90 @@
<?php
//General Config File:
require_once('../assets/php/config.php');
//Controller file:
require_once('panel_manager.php');
require_once('../assets/php/common/manager_dao.php');
require_once('../assets/php/common/manager.php');
require_once('../assets/php/common/user.php');
if($_SESSION["login"] && $_SESSION["rol"] === "manager"){
$bd = new Manager_DAO('complucine');
$manager = false;
if($bd && !$manager){
$user = unserialize($_SESSION["user"]);
$manager = $bd->GetManager($user->getId());
if($manager){
if($manager->num_rows == 1){
$fila = $manager->fetch_assoc();
$manager = new Manager($fila["id"], $fila["idcinema"], null, null, null);
}
}
}
$state = isset($_GET['state']) ? $_GET['state'] : '';
switch($state){
case "view_ruser":
case "view_user":
$panel = '<div class="column side"></div>
<div class="column middle">
<div class="code info">
<h1>Esta vista aun no esta implementada.</h1><hr />
</div>
</div>
<div class="column side"></div>'."\n";
break;
case "manage_halls":
$panel = Manager_panel::manage_halls($manager);
break;
case "new_hall":
$panel = Manager_panel::new_hall($manager);
break;
case "edit_hall":
$panel = Manager_panel::edit_hall($manager);
break;
case "manage_sessions":
$panel = Manager_panel::manage_sessions($manager);
break;
case "new_session":
$panel = Manager_panel::new_session($manager);
break;
case "edit_session":
$panel = Manager_panel::edit_session($manager);
break;
case "select_film":
$panel = Manager_panel::select_film($template,$manager);
break;
case "success":
$panel = Manager_panel::success();
break;
default:
$panel = Manager_panel::welcome($manager);
break;
}
}
else{
$panel = '<div class="column side"></div>
<div class="column middle">
<div class="code info">
<h1>Debes iniciar sesión para ver el Panel de Manager.</h1><hr />
<p>Inicia Sesión con una cuenta de Gerente.</p>
<a href="'.$prefix.'login/" ><button class="button large">Iniciar Sesión</button></a>
</div>
</div>
<div class="column side"></div>'."\n";
}
//Specific page content:
$section = '<!-- Manager Panel -->
<link rel="stylesheet" href="../assets/css/manager.css">
<section id="manager_panel">
<!-- Contents -->
<div class="row">
'.$panel.'
</div>
</section>';
//General page content:
require RAIZ_APP.'/HTMLtemplate.php';
?>

View File

@ -0,0 +1,223 @@
<?php
include_once($prefix.'assets/php/common/hall.php');
include_once($prefix.'assets/php/common/session.php');
require_once($prefix.'assets/php/common/manager.php');
include_once('./includes/formHall.php');
include_once('./includes/formSession.php');
class Manager_panel {
function __construct(){}
static function welcome($manager){
$name = strtoupper($_SESSION["nombre"]);
$cinema = strtoupper( $manager->getIdcinema());
$panel = '<div class="code info">
<h1>Bienvenido '.$name.' a tu Panel de Manager.</h1>
<hr />
<p>Usuario: '.$name.'</p>
<p>Cine: '.$cinema.'</p>
<p>Espero que estes pasando un buen dia</p>
</div>';
return $panel;
}
static function success(){
$panel = '<div class="code info">
<h1>Operacion completada.</h1>
<hr />
<p>'.$_SESSION['msg'].'</p>
</div>'."\n";
$_SESSION['msg'] = "";
return $panel;
}
static function manage_halls($manager){
$panel = '<div class="column side"></div>
<div class="column middle">';
$listhall = Hall::getListHalls($manager->getIdcinema());
if(!$listhall){
$panel .= "<h2> No hay ninguna sala en este cine";
}else{
$panel .= '
<table class="alt">
<thead>
<tr>
<th>Numero</th>
<th>Filas</th>
<th>Columnas</th>
<th>Asientos Disponibles</th>
</tr>
</thead>
<tbody>';
foreach($listhall as $hall){
$panel .='
<tr>
<td> '. $hall->getNumber().'</td>
<td> '. $hall->getNumRows().'</td>
<td> '. $hall->getNumCol().'</td>
<td> '.$hall->getTotalSeats().' </td>
<form method="post" action="./?state=edit_session">
<input name="number" type="hidden" value="'. $hall->getNumber().'"/>
<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" id="submit" name ="edit_hall" formaction="./?state=edit_hall&number='.$hall->getNumber().'" value="Editar" class="primary" /> </td>
</form>
</tr>';
}
$panel.='
</tbody>
</table>';
}
$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($manager){
$formHall = new FormHall("new_hall",$manager->getIdcinema());
$panel = '<h1>Crear una sala.</h1><hr/></br>
'.$formHall->gestiona();
return $panel;
}
static function edit_hall($manager){
$formHall = new FormHall("edit_hall",$manager->getIdcinema());
$panel = '<h1>Editar una sala.</h1><hr/></br>
'.$formHall->gestiona();
return $panel;
}
static function manage_sessions($manager){
//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($manager->getIdcinema()) 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,$manager->getIdcinema(),$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::getThisSessionFilm($session->getIdfilm())["tittle"]) .' </td>
<td> '.$session->getFormat().' </td>
<td> '.$session->getSeatPrice().' </td>
<form method="post" action="./?state=edit_session">
<input name="film" type="hidden" value="'.$session->getIdfilm().'">
<input name="hall" type="hidden" value="'.$session->getIdhall().'">
<input name="date" type="hidden" value="'.$session->getDate().'">
<input name="start" type="hidden" value="'.$session->getStartTime().'">
<input name="price" type="hidden" value="'.$session->getSeatPrice().'">
<input name="format" type="hidden" value="'.$session->getFormat().'">
<td> <input type="submit" id="submit" name ="edit_session" value="Editar" class="primary" /> </td>
</form>
</tr>';
}
$panel.='
</tbody>
</table>
</form>';
} else {
$panel.=' <h3> No hay ninguna sesion </h3>';
}
$panel.='
<input type="submit" name="new_session" form="filter" value="Añadir" class="button large" formaction="./?state=new_session">
</div>';
return $panel;
}
static function new_session($manager){
$formSession = new FormSession("new_session", $manager->getIdcinema() );
$panel = '<h1>Crear una sesion.</h1> <hr/> </br>
'.$formSession->gestiona();
return $panel;
}
static function edit_session($manager){
$formSession = new FormSession("edit_session", $manager->getIdcinema() );
$panel = '<h1>Editar una sesion.</h1><hr/></br>
'.$formSession->gestiona();
return $panel;
}
//TODO: estado al modificar sesiones para la seleccion de peliculas usando el template->print films
static function select_film($template,$manager){
if(isset($_GET["option"])){
$_SESSION["option"] = $_GET["option"];
$panel = '<h1>Seleccionar Pelicula.</h1><hr /></br>';
$panel .= $template->print_fimls();
$_SESSION["option"] = "";
} else $panel = self::warning($manager);
return $panel;
}
//Funcion que se envia cuando hay inconsistencia en el panel manager, principalmente por tocar cosas con la ulr
static function warning($manager){
$panel = '<div class="code info">
<h1>No deberias poder acceder aqui.</h1>
<hr />
<p> No uses la url para toquitear cosas >.< </p>
</div>'."\n";
return $panel;
}
}
?>