Muchas conexiones con la base de datos.

Ahora se pueden añadir sesiones (para una sala, cine y fecha predeterminada en el codigo). El "escoger" la pelicula es simplemente meter el id de la pelicula en cuestion.
La lista de sesiones en la vista de las sesiones hace recibe un array desde la base de datos (para una sala,cine y fecha predeterminada en el codigo). Lo que muestra la tabla tambien es solo la id de la pelicula.
This commit is contained in:
Markines16 2021-04-10 20:54:56 +02:00 committed by GitHub
parent d8184c40b3
commit a7575ba942
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 337 additions and 68 deletions

View File

@ -1,8 +1,40 @@
<?php
require('./includes/room_dto.php');
require('./includes/session_dto.php');
?>
<p> Este es el panel de editar/añadir o eliminar sesiones </p>
if(isset($_REQUEST['option']) && $_REQUEST['option'] == 'edit') {
echo "<p> Este es el panel de editar o eliminar una sesion. Deberia tener el formulario de crear una sesion nueva pero con los datos ya situados y quizas que solo aqui aparezca el boton de eliminar </p>";
}
else{
echo "<h2>Crear Session</h2>
<form method=\"post\" action=\"validate.php\">
<div class=\"row\">
<fieldset id=\"datos\">
<legend>Datos</legend>
<div class=\"_price\">
<input type=\"number\" name=\"price\" id=\"price\" min=\"0\" placeholder=\"Precio de la entrada\" required/>
</div>
<div class=\"_film\">
<input type=\"text\" name=\"film\" id=\"film\" value=\"\" placeholder=\"ID de la pelicula\" required/>
</div>
<div class=\"_format\">
<input type=\"text\" name=\"format\" id=\"format\" value=\"\" placeholder=\"Formato\" required/>
</div>
</fieldset>
<fieldset id=\"Horario\">
<legend>Horario</legend>
<div class=\"_start_time\">
<input type=\"time\" name=\"start\" id=\"start_time\" value=\"\" placeholder=\"Hora de inicio\" required/>
</div>
</fieldset>
<div class=\"actions\">
<input type=\"submit\" id=\"submit\" value=\"Añadir\" class=\"primary\" />
<input type=\"reset\" id=\"reset\" value=\"Borrar\" />
</div>
</div>
</form>";
}
echo "</div>"
?>

View File

@ -0,0 +1,66 @@
<?php
include_once('session_dao.php');
include_once('../assets/php/form.php');
class FormSession extends Form {
//Atributes:
private $correct; // Indicates if the session is correct.
private $reply; // Validation response
//Constructor:
public function __construct() {
parent::__construct('formSession');
$this->reply = array();
}
//Methods:
//Returns validation response:
public function getReply() {
//Habria que comprobar si realmente se ha validado la respuesta antes de escribir una respuesta correcta
if($this->correct){
$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 {
$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 function processesForm($price, $film, $format, $start) {
$this->correct = true;
$hall = 2;
$cinema = 1;
$date = "2021-04-10";
//Habria que validar todo para que encaje en la base de datos
$start = date('H:i:s', strtotime( $start ) );
$date = date('Y-m-d', strtotime( $date ) );
$bd = new sessionDAO('complucine');
if($bd){
$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);
}
}
}
?>

View File

@ -0,0 +1,67 @@
<?php
include_once('session_dao.php');
class ListSessions{
//Atributes:
private $array;
private $size;
private $cinema;
private $hall;
private $date;
//Constructor:
public function __construct($cinema,$hall,$date) {
$this->array = array();
$this->cinema = $cinema;
$this->hall = $hall;
$this->date = $date;
}
//Methods:
//Returns the whole session array
public function getArray() {
return $this->array;
}
//Returns the value i from the array
public function getiArray($i) {
if($i < $size){
return $this->array($i);
} else {
return null;
}
}
//Change the patterns of the filter
public function setCinema($cinema){$this->cinema = $cinema;}
public function setHall($hall){$this->hall = $hall;}
public function setDate($date){$this->date = $date;}
//Update the array with current filter values
public function filterList() {
$this->date = date('Y-m-d', strtotime( $this->date ) );
$bd = new sessionDAO('complucine');
if($bd){
$selectSession = $bd->selectSession($this->cinema, $this->hall, null, $this->date);
$selectSession->data_seek(0);
$this->size = 0;
while ($fila = $selectSession->fetch_assoc()) {
$this->array[]= new SessionDTO($fila['id'], $fila['idfilm'], $fila['idhall'], $fila['idcinema'], $fila['date'], date('h:i', strtotime( $fila['start_time'])) , $fila['seat_price'], $fila['format']);
$this->size++;
}
mysqli_free_result($selectSession);
}
}
}
?>

View File

@ -12,11 +12,13 @@
//Methods:
//Create a new Session.
public function createSession($id, $idfilm, $idhall, $date, $startTime, $seatPrice, $format){
public function createSession($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
$sql = sprintf( "INSERT INTO sessions( $id, $idfilm, $idhall, $date, $startTime, $seatPrice, $format)
VALUES ( '%s', '%s', '%s', '%date', '%time', '%d', '%s')",
$id, $idfilm, $idhall, $date, $startTime, $seatPrice, $format );
$sql = sprintf( "INSERT INTO `session` (`id`, `idfilm`, `idhall`, `idcinema`, `date`, `start_time`, `seat_price`, `format`)
VALUES ('%d', '%d', '%d', '%d', '%s', '%s', '%d', '%s')",
$id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $sql;
}
@ -29,6 +31,24 @@
return $resul;
}
//Returns a query to check if the session in this cinema, hall and scheudle exists.
public function selectSession($cinema, $hall, $start, $date){
if($start == null){
$sql = sprintf( "SELECT * FROM session WHERE
idcinema = '%s' AND idhall = '%s' AND date = '%s'",
$cinema, $hall, $date);
}else{
$sql = sprintf( "SELECT * FROM session WHERE
idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'",
$cinema, $hall, $date, $start);
}
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Create a new Session Data Transfer Object.
public function loadSession( $id, $idfilm, $idhall, $date, $startTime, $seatPrice, $format){
return new SessionDTO( $id, $idfilm, $idhall, $date, $startTime, $seatPrice, $format);

View File

@ -5,18 +5,20 @@
//Attributes:
private $_id; //Session Id.
private $_idfilm; //Film Id
private $_idhall //Hall id
private $_idfilm; //Film Id -> deberia ser un objeto tipo pelicula? para poder sacar el nombre de la pelicula en cuestion
private $_idhall; //Hall id -> deberia ser un objeto tipo room/hall/sala de cine por lo mismo
private $_idcinema;
private $_date; //Session date.
private $_startTime; //Session start time.
private $_seatPrice; //Seat price.
private $_format; //Type of film: 3D | 4D | normal | subtitle | mute.
//Constructor:
function __construct($id, $idfilm, $idhall, $date, $startTime, $seatPrice, $format){
function __construct($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){
$this->_id = $id;
$this->_idfilm = $idfilm;
$this->_idhall = $idhall;
$this->_idcinema = $idcinema;
$this->_date = $date;
$this->_startTime = $startTime;
$this->_seatPrice = $seatPrice;
@ -32,9 +34,12 @@
public function setIdfilm($idfilm){ $this->_idfilm = $idfilm; }
public function getIdfilm(){ return $this->_idfilm; }
public function setIdhall($film){ $this->_idhall = $idhall; }
public function setIdhall($idhall){ $this->_idhall = $idhall; }
public function getIdhall(){ return $this->_idhall; }
public function setIdcinema($cinema){ $this->_idcinema = $idcinema; }
public function getIdcinema(){ return $this->_idcinema; }
public function setDate($date){ $this->_date = $date; }
public function getDate(){ return $this->_date; }

View File

@ -6,12 +6,15 @@
require_once('./panel_manager.php');
$template = new Template();
$login = false;
if(isset($_SESSION["login"]) && $_SESSION["nombre"] == "manager") $login = true;
if(isset($_REQUEST['state'])) {
$panel = new Panel($_REQUEST['state']);
$panel = new Panel($_REQUEST['state'],$login);
}
else {
$panel = new Panel('');
$panel = new Panel('',$login);
}
// IMPORTANTE:
// VERIFICAR QUE ES MANAGER(GERENTE), SI NO, MOSTRAR MENSAJE DE "ERROR"
@ -38,27 +41,30 @@
<!-- Panel -->
<div class="row">
<!-- Left Sidebar -->
<!--Left Sidebar -->
<div class="sidebar left">
<ul>
<li>Ver como:</li>
<ul>
<li><a href="index.php?state=us_u">Usuario no registrado</a></li>
<li><a href="index.php?state=us_r">Usuario registrado</a></li>
<li><a href='./?state=us_u'>Usuario no registrado</a></li>
<li><a href='./?state=us_r'>Usuario registrado</a></li>
</ul><br />
<li>Añadir/Editar/Eliminar:</li>
<ul>
<li><a href="index.php?state=rooms">Salas</a></li>
<li><a href="index.php?state=sessions">Películas</a></li>
<li><a href='./?state=rooms'>Salas</a></li>
<li><a href='./?state=sessions&login=".$this->login."'>Sesiones</a></li>
</ul>
</ul>
</div>
<!-- Contents -->
<!--Contents -->
<div class="row">
<div class="column middle">
<?php
$panel->showPanel();
?>
</div>
</div>
<!-- Footer -->
<?php

View File

@ -1,10 +1,10 @@
<?php
require('./includes/room_dto.php');
$r1 = new RoomDTO(0,20,20);
$r2 = new RoomDTO(1,10,30);
$r3 = new RoomDTO(2,30,10);
$r4 = new RoomDTO(3,15,15);
$r1 = new RoomDTO(0,20,20,30);
$r2 = new RoomDTO(1,10,30,30);
$r3 = new RoomDTO(2,30,10,30);
$r4 = new RoomDTO(3,15,15,30);
$rooms = array($r1, $r2, $r3, $r4);
function drawRooms($ros){

View File

@ -1,13 +1,18 @@
<?php
require('./includes/room_dto.php');
require('./includes/session_dto.php');
//Login form validate:
require_once('./includes/listSessions.php');
$sessionList = new ListSessions("1", "1", "2021-04-10");
?>
<input type="date" name="fecha" min="2021-01-01" max="2031-12-31">
<?php
$r1 = new RoomDTO(0,20,20);
$r2 = new RoomDTO(1,10,30);
$r3 = new RoomDTO(2,30,10);
$r4 = new RoomDTO(3,15,15);
$r1 = new RoomDTO(0,20,20,30);
$r2 = new RoomDTO(1,10,30,30);
$r3 = new RoomDTO(2,30,10,30);
$r4 = new RoomDTO(3,15,15,30);
$rooms = array($r1, $r2, $r3, $r4);
function drawRooms($ros){
@ -26,13 +31,8 @@
</div>
<div class="column side">
<?php
$s1 = new SessionDTO(0,"HOY","10:00","9,99€","normal","Los vengativos: final del juego");
$s2 = new SessionDTO(1,"HOY","12:00","10€","3D","Los vengativos: final del juego");
$s3 = new SessionDTO(2,"HOY","14:00","10€","subtitulado","Los vengativos: final del juego");
$s4 = new SessionDTO(3,"HOY","16:00","9,99€","normal","Los vengativos: final del juego");
$s5 = new SessionDTO(4,"HOY","18:00","9,99€","normal","Los vengativos: final del juego");
$s6 = new SessionDTO(5,"HOY","20:00","20€","4D","Los vengativos: final del juego");
$sessions = array($s1, $s2, $s3, $s4, $s5, $s6);
$sessionList->filterList();
$sessions = $sessionList->getArray();
function drawSessions($ses){
@ -41,28 +41,28 @@
<thead>
<tr>
<th>Hora</th>
<th>Película</th>
<th>Tipo</th>
<th>idPelícula</th>
<th>Formato</th>
<th>Precio</th>
<!-- <th>Opción</th> --> <!-- HAY QUE ELIMINAR ESTA COLUMNA, COMO EXPLICÓ IVÁN EN CLASE, -->
<!-- LAS TABLAS TIENEN EL PROBLEMA DE QUE CON MUCHAS COLUMNAS SE EXPANDEN FUERA DE LOS LÍMITES -->
</tr>
</thead>
<tbody>";
foreach($ses as $s){
echo "
<tr>
<td>" . $s->getStartTime() . "</td>
<td>" . $s->getFilm() . "</td>
<td>" . $s->getFormat() . "</td>
<td>". $s->getSeatPrice() . "</td>
<!-- <td> <button type=\"button\" onClick=\"Javascript:window.location.href = 'index.php?edit_sessions=true';\")\">Editar</button> </td> -->
<!-- LA SOLUCIÓN PUEDE SER PONER EN ELACE DE EDICIÓN EN CADA UNO DE LOS ELEMENTOS DE LA COLUMNA -->
</tr>";
<td><a href=\"./?state=edit_session&option=edit\">" . $s->getStartTime() . "</a></td>
<td><a href=\"./?state=edit_session&option=edit\">" . $s->getIdfilm() . "</a></td>
<td><a href=\"./?state=edit_session&option=edit\">" . $s->getFormat() . "</a></td>
<td><a href=\"./?state=edit_session&option=edit\">". $s->getSeatPrice() . "</a></td>
</tr>"
;
}
echo "<tbody>
</table>\n";
echo "<a href=\"index.php?state=edit_session&option=new\" class='button large'>Añadir</a>";
echo "<a href=\"./?state=edit_session&option=new\" class='button large'>Añadir</a>";
}
drawSessions($sessions);
?>

View File

@ -1,12 +1,15 @@
<?php
class Panel {
public $state;
public $login;
function __construct($panel){
function __construct($panel,$log){
$this->state = $panel;
$this->login = $log;
}
function showPanel() {
if($this->login){
switch($this->state) {
case 'us_u': require('user_unregistered_view.php'); break;
case 'us_r': require('user_registered_view.php'); break;
@ -19,5 +22,12 @@
</div>"; break;
}
}
else{
echo "<h1>ERROR </h1>
<br>
<p> No tiene permiso en esta sección de la pagina web </p>
</div>";
}
}
}
?>

View File

@ -0,0 +1,63 @@
<?php
session_start();
//Depuración (BORRAR):
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
//HTML template:
require_once('../assets/php/template.php');
$template = new Template();
//Login form validate:
require_once('./includes/formSession.php');
$session = new FormSession();
$session->processesForm($_POST["price"], $_POST["film"], $_POST["format"],$_POST["start"]);
$reply = $session->getReply();
?>
<!DOCTYPE HTML>
<!--
Práctica 2 - Sistemas Web | Grupo D
CompluCine - FDI-cines
-->
<html lang="es">
<!-- Head -->
<?php
$template->print_head();
?>
<body>
<!-- Header -->
<?php
$template->print_header();
?>
<!-- Main -->
<div class="main">
<div class="image"><img src="../img/logo_trasparente.png" /></div>
</div>
<!-- Reply -->
<section class="reply">
<div class ="row">
<div class="column side"></div>
<div class="column middle">
<div class="code info">
<?php
echo $reply;
?>
</div>
</div>
<div class="column side"></div>
</div>
</section>
<!-- Footer -->
<?php
$template->print_footer();
?>
</body>
</html>