From 94c7940cc0a801b63d4762dedf5a5641deeb8ee5 Mon Sep 17 00:00:00 2001 From: Markines16 <80280295+Markines16@users.noreply.github.com> Date: Sun, 11 Apr 2021 19:55:21 +0200 Subject: [PATCH] Add files via upload --- panel_manager/edit_sessions.php | 71 ++++++++++++++++++++++++-- panel_manager/includes/formSession.php | 51 +++++++++++++----- panel_manager/includes/room_dao.php | 25 +-------- panel_manager/includes/session_dao.php | 49 +++++++++--------- panel_manager/manage_sessions.php | 11 ++-- panel_manager/validate.php | 15 +++++- 6 files changed, 147 insertions(+), 75 deletions(-) diff --git a/panel_manager/edit_sessions.php b/panel_manager/edit_sessions.php index ebcfaff..faafca8 100644 --- a/panel_manager/edit_sessions.php +++ b/panel_manager/edit_sessions.php @@ -2,6 +2,7 @@ require('./includes/room_dto.php'); require('./includes/session_dto.php'); require('../panel_admin/includes/film_dto.php'); + include_once('./includes/session_dao.php'); $r1 = new RoomDTO(1,20,20,30); //Esto se deberia cambiar por una llamada a una lista de salas $r2 = new RoomDTO(2,10,30,30); @@ -11,10 +12,66 @@ $filmList = new ListFilms(); $films = $filmList->getArray(); - + //DISCLAIMER; sabemos que si se edita la ulr se pueden acceder a datos de una sesion que no pertenece al usuario y que incluso puede hasta editarlas/borrarlas en la base de datos if(isset($_REQUEST['option']) && $_REQUEST['option'] == 'edit') { - echo "

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

"; - } + $bd = new sessionDAO('complucine'); + if($bd){ + $session = ($bd->sessionData($_GET["id"]))->fetch_assoc(); + echo "

Editar/Eliminar Sesion

+
+
+
+ Datos + + +
+ +
+ +
+ +
+ Horario +
+ +
+
+ +
+
+
Introducir un numero para añadir esta sesion a los futuros X dias + +
+
+
+ + + +
+ +
+
+
+
+
+
Introducir un numero para añadir esta sesion a los futuros X dias + +
- - + +
diff --git a/panel_manager/includes/formSession.php b/panel_manager/includes/formSession.php index 64541db..b3f34cf 100644 --- a/panel_manager/includes/formSession.php +++ b/panel_manager/includes/formSession.php @@ -8,7 +8,7 @@ class FormSession extends Form { //Atributes: private $correct; // Indicates if the session is correct. private $reply; // Validation response - + private $option; //Constructor: public function __construct() { parent::__construct('formSession'); @@ -22,9 +22,19 @@ class FormSession extends Form { //Habria que comprobar si realmente se ha validado la respuesta antes de escribir una respuesta correcta if($this->correct){ - $this->reply = "

Operacion realizada con exito


+ if($this->option == "new"){ + $this->reply = "

Operacion realizada con exito


Se ha añadido la sesion correctamente en la base de datos.

"; + }else if($this->option == "edit"){ + $this->reply = "

Operacion realizada con exito


+

Se ha editado la sesion correctamente en la base de datos.

+ "; + }else if($this->option == "del"){ + $this->reply = "

Operacion realizada con exito


+

Se ha eliminado la sesion correctamente en la base de datos.

+ "; + } } else { $this->reply = "

ERROR


Ha habido un error en la operacion. Revisa los datos introducidos o ponte en contacto con el administrador de la base de datos.

@@ -35,26 +45,39 @@ class FormSession extends Form { } //Process form: - public function processesForm($film, $hall, $cinema, $date, $start, $price, $format) { + public function processesForm($id, $film, $hall, $cinema, $date, $start, $price, $format, $repeat, $option) { $this->correct = true; + $this->option = $option; //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); + if($bd ){ + 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); } - - mysqli_free_result($selectSession); - } + + if($repeat > "0"){ + $repeat--; + $date = date('Y-m-d', strtotime( $date. ' +1 day') ); + $this->processesForm($film, $hall, $cinema, $date, $start, $price, $format, $repeat); + } + } else {$this->correct = false;} + + + } } diff --git a/panel_manager/includes/room_dao.php b/panel_manager/includes/room_dao.php index 0990b94..7661e82 100644 --- a/panel_manager/includes/room_dao.php +++ b/panel_manager/includes/room_dao.php @@ -15,7 +15,7 @@ public function createRoom($id, $idcinema, $numCol, $numRows){ $sql = sprintf( "INSERT INTO rooms( id, idcinema, numCol, numRows) - VALUES ( '%d', '%d', '%i', '%i')", + VALUES ( '%s', '%s', '%i', '%i')", $id, $idcinema, $numCol, $numRows ); return $sql; @@ -34,29 +34,6 @@ return new RoomDTO($id, $idcinema, $numCol, $numRows); } - //Edit Hall. - public function editHall($id, $idcinema, $numCol, $numRows){ - - $sql = sprintf( "UPDATE `hall` - SET `numrows` = '%i' , `numcolumns` = '%i' - WHERE `hall`.`number` = '%d' AND `hall`.`idcinema` = '%d';", - $numRows,$numCol,$id, $idcinema ); - - $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); - - return $resul; - } - - //Delete Hall. - public function deleteHall($id, $idcinema){ - - $sql = sprintf( "DELETE FROM `hall` WHERE `hall`.`number` = '%d' AND `hall`.`idcinema` = '%d';",$id,$idcinema); - - $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); - - return $resul; - } - } ?> \ No newline at end of file diff --git a/panel_manager/includes/session_dao.php b/panel_manager/includes/session_dao.php index 17af748..bea63b6 100644 --- a/panel_manager/includes/session_dao.php +++ b/panel_manager/includes/session_dao.php @@ -26,31 +26,7 @@ //Returns a query to get the session's data. public function sessionData($id){ $sql = sprintf( "SELECT * FROM `session` WHERE id = '%d'", $id ); - $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); - - return $resul; - } - - //Edit Session. - public function editSession($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){ - - $sql = sprintf( "UPDATE `session` - SET `idfilm` = '%d' , `idhall` = '%d', `idcinema` = '%d', `date` = '%s', - `start_time` = '%s', `seat_price` = '%d', `format` = '%s' - WHERE `session`.`id` = '%d';", - $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $id); - - $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); - - return $resul; - } - - //Delete Session. - public function deleteSession($id){ - - $sql = sprintf( "DELETE FROM `session` WHERE `session`.`id` = '%d'",$id); - - $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database en sessionData con la id '. $id); return $resul; } @@ -70,6 +46,29 @@ return $resul; } + //Edit Session. + public function editSession($id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){ + + $sql = sprintf( "UPDATE `session` + SET `idfilm` = '%d' , `idhall` = '%d', `idcinema` = '%d', `date` = '%s', + `start_time` = '%s', `seat_price` = '%d', `format` = '%s' + WHERE `session`.`id` = '%d';", + $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $id); + + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + return $resul; + } + + //Delete Session. + public function deleteSession($id){ + + $sql = sprintf( "DELETE FROM `session` WHERE `session`.`id` = '%d';",$id); + + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + return $resul; + } //Create a new Session Data Transfer Object. diff --git a/panel_manager/manage_sessions.php b/panel_manager/manage_sessions.php index 964ed34..fce7a50 100644 --- a/panel_manager/manage_sessions.php +++ b/panel_manager/manage_sessions.php @@ -60,10 +60,10 @@ $fila = ($bd->FilmData($s->getIdfilm()))->fetch_assoc(); echo " - " . $s->getStartTime() . " - " .$fila['tittle'] . " - " . $s->getFormat() . " - ". $s->getSeatPrice() . " + " . $s->getStartTime() . " + " .$fila['tittle'] . " + ". $s->getSeatPrice() . " + getid() ."\"/> "; } echo " @@ -75,8 +75,9 @@ if($bd){ drawSessions($sessions,$bd); echo " - \n"; + "; } + } echo " "; diff --git a/panel_manager/validate.php b/panel_manager/validate.php index 6755457..1d55f6d 100644 --- a/panel_manager/validate.php +++ b/panel_manager/validate.php @@ -9,11 +9,22 @@ //HTML template: require_once('../assets/php/template.php'); $template = new Template(); - + $action =""; + $id = null; + if(isset($_POST['new'])){ + $action = "new"; + } else if (isset($_POST['edit'])){ + $action = "edit"; + $id = $_POST["id"]; + } else if (isset($_POST['del'])){ + $action = "del"; + $id = $_POST["id"]; + } + //Login form validate: require_once('./includes/formSession.php'); $session = new FormSession(); - $session->processesForm($_POST["film"], $_POST["hall"], $_POST["cinema"],$_POST["date"],$_POST["start"],$_POST["price"],$_POST["format"]); + $session->processesForm($id, $_POST["film"], $_POST["hall"], $_POST["cinema"],$_POST["date"],$_POST["start"],$_POST["price"],$_POST["format"],$_POST["repeat"], $action); $reply = $session->getReply(); ?>