From 9756959978f583f40ae7be5316df476b024daea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20M=C3=A9ndez?= <45081533+FerMdez@users.noreply.github.com> Date: Wed, 28 Apr 2021 21:46:10 +0200 Subject: [PATCH] Add files via upload --- assets/php/common/film_dao.php | 103 +++++++++++++++++++ assets/php/common/film_dto.php | 37 +++++++ assets/php/common/film_dto_interface.php | 14 +++ assets/php/common/hall_dao.php | 73 ++++++++++++++ assets/php/common/hall_dto.php | 38 +++++++ assets/php/common/hall_dto_interface.php | 12 +++ assets/php/common/session_dao.php | 106 ++++++++++++++++++++ assets/php/common/session_dto.php | 56 +++++++++++ assets/php/common/session_dto_interface.php | 20 ++++ assets/php/common/user_dao.php | 95 ++++++++++++++++++ assets/php/common/user_dto.php | 37 +++++++ assets/php/common/users_dto_interface.php | 14 +++ assets/php/dao.php | 8 +- index.php | 6 +- login/includes/formLogin.php | 2 +- panel_admin/includes/formFilm.php | 5 +- panel_admin/index.php | 2 +- panel_admin/manage_films.php | 8 +- panel_admin/updateFilm.php | 2 +- panel_admin/update_film.php | 4 +- panel_manager/edit_sessions.php | 12 +-- panel_manager/includes/formHall.php | 2 +- panel_manager/includes/formSession.php | 2 +- panel_manager/manage_rooms.php | 2 +- panel_manager/manage_sessions.php | 8 +- register/includes/formRegister.php | 2 +- showtimes/index.php | 2 +- 27 files changed, 641 insertions(+), 31 deletions(-) create mode 100644 assets/php/common/film_dao.php create mode 100644 assets/php/common/film_dto.php create mode 100644 assets/php/common/film_dto_interface.php create mode 100644 assets/php/common/hall_dao.php create mode 100644 assets/php/common/hall_dto.php create mode 100644 assets/php/common/hall_dto_interface.php create mode 100644 assets/php/common/session_dao.php create mode 100644 assets/php/common/session_dto.php create mode 100644 assets/php/common/session_dto_interface.php create mode 100644 assets/php/common/user_dao.php create mode 100644 assets/php/common/user_dto.php create mode 100644 assets/php/common/users_dto_interface.php diff --git a/assets/php/common/film_dao.php b/assets/php/common/film_dao.php new file mode 100644 index 0000000..1bb9682 --- /dev/null +++ b/assets/php/common/film_dao.php @@ -0,0 +1,103 @@ +get_prefix(); + include_once($prefix.'assets/php/dao.php'); + + class Film_DAO extends DAO { + + //Constructor: + function __construct($bd_name){ + parent::__construct($bd_name); + } + + //Methods: + + //Create a new Session. + public function createFilm($id, $tittle, $duration, $language,$description){ + $sql = sprintf( "INSERT INTO `film`( `id`, `tittle`, `duration`, `language`,`description`) + VALUES ( '%d', '%s', '%d', '%s','%s')", + $id, $tittle, $duration, $language,$description); + + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + return $resul; + } + //Returns a film data . + public function GetFilm($tittle,$language){ + $sql = sprintf( "SELECT * FROM film WHERE film.tittle = '%s'AND film.language='%s'", $tittle,$language ); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + return $resul; + } + + //Returns a query to get the film's data. + public function FilmData($id){ + $sql = sprintf( "SELECT * FROM film WHERE id = '%d'", $id ); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + return $resul; + } + + //Returns a query to get All the films. + public function allFilmData(){ + $sql = sprintf( "SELECT * FROM film "); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + while($fila=$resul->fetch_assoc()){ + $films[] = $this->loadFilm($fila["id"], $fila["tittle"], $fila["duration"], $fila["language"], $fila["description"]); + } + $resul->free(); + return $films; + } + + + //Returns a query to get all films tittles. + public function tittleFilmData(){ + $sql = sprintf( "SELECT DISTINCT tittle FROM film "); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + return $resul; + } + + //Returns a query to get all films descriptions. + public function descriptionFilmData(){ + $sql = sprintf( "SELECT description FROM film "); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + return $resul; + } + + /* + public function addFilm($films) { + $resul = mysqli_query($this->mysqli, $this->createFilm($film.getId(), $film.getTittle(), $film.getDuration(), $film.getLanguage(), $film.getDescription())) or die ('Error into query database'); + return $resul; + } + */ + + //Deleted film by "id". + public function deleteFilm($id){ + $sql = sprintf( "DELETE FROM film WHERE film.id = '%d' ;",$id); + + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + return $resul; + } + + //Edit a film. + public function editFilm($id, $tittle, $duration, $language,$description){ + $sql = sprintf( "UPDATE film SET tittle = '%s' , duration = '%d', language ='%s' , description ='%s' + WHERE film.id = '%d';", + $tittle, $duration, $language, $description, $id); + + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + return $resul; + } + + //Create a new film Data Transfer Object. + public function loadFilm($id, $tittle, $duration, $language,$description){ + return new Film_DTO( $id, $tittle, $duration, $language,$description); + } + + } + +?> diff --git a/assets/php/common/film_dto.php b/assets/php/common/film_dto.php new file mode 100644 index 0000000..3b24897 --- /dev/null +++ b/assets/php/common/film_dto.php @@ -0,0 +1,37 @@ +_id = $id; + $this->_tittle = $tittle; + $this->_duration = $duration; + $this->_language = $language; + $this->_description = $description; + } + + //Methods: + + //Getters && Setters: + public function setId($id){ $this->_id = $id; } + public function getId(){ return $this->_id; } + public function setTittle($tittle) {$this->_tittle = $tittle; } + public function getTittle(){return $this->_tittle;} + public function setDuration($duration){$this->_duration = $duration; } + public function getDuration() {return $this->_duration;} + public function setLanguage($language) {$this->_language = $language; } + public function getLanguage(){return $this->_language;} + public function setDescription($description){ $this->_description = $description;} + public function getDescription(){return $this->_description;} + } +?> \ No newline at end of file diff --git a/assets/php/common/film_dto_interface.php b/assets/php/common/film_dto_interface.php new file mode 100644 index 0000000..23931f3 --- /dev/null +++ b/assets/php/common/film_dto_interface.php @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/assets/php/common/hall_dao.php b/assets/php/common/hall_dao.php new file mode 100644 index 0000000..4c85a7c --- /dev/null +++ b/assets/php/common/hall_dao.php @@ -0,0 +1,73 @@ +mysqli, $sql) or die ('Error into query database'); + + $hall = null; + + while($fila=mysqli_fetch_array($resul)){ + $hall[] = $this->loadHall($fila["number"], $fila["idcinema"], $fila["numrows"], $fila["numcolumns"]); + } + + mysqli_free_result($resul); + + return $hall; + } + + //Create a new Hall Data Transfer Object. + public function loadHall($number, $idcinema, $numrows, $numcolumns){ + return new HallDTO($number, $idcinema, $numrows, $numcolumns); + } + + //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/assets/php/common/hall_dto.php b/assets/php/common/hall_dto.php new file mode 100644 index 0000000..40eed19 --- /dev/null +++ b/assets/php/common/hall_dto.php @@ -0,0 +1,38 @@ +_number = $number; + $this->_idcinema = $idcinema; + $this->_numRows = $numRows; + $this->_numCol = $numCol; + } + + //Methods: + + //Getters && Setters: + public function setNumber($number){ $this->_number = $number; } + public function getNumber(){ return $this->_number; } + + public function setIdcinema($idcinema){ $this->_idcinema = $idcinema; } + public function getIdcinema(){ return $this->_idcinema; } + + public function setNumRows($numRows){ $this->_numRows = $numRows; } + public function getNumRows(){ return $this->_numRows; } + + public function setNumCol($numCol){ $this->_numCol = $numCol; } + public function getNumCol(){ return $this->_numCol; } + + + + } +?> \ No newline at end of file diff --git a/assets/php/common/hall_dto_interface.php b/assets/php/common/hall_dto_interface.php new file mode 100644 index 0000000..0489026 --- /dev/null +++ b/assets/php/common/hall_dto_interface.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/assets/php/common/session_dao.php b/assets/php/common/session_dao.php new file mode 100644 index 0000000..381e55a --- /dev/null +++ b/assets/php/common/session_dao.php @@ -0,0 +1,106 @@ +mysqli->real_escape_string($format); + $date = date('Y-m-d', strtotime( $date ) ); + $startTime = date('H:i:s', strtotime( $startTime ) ); + + $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; + } + + //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 en sessionData con la id '. $id); + + return $resul; + } + + //Returns the count of the session searched + public function searchSession($cinema, $hall, $startTime, $date){ + $date = date('Y-m-d', strtotime( $date ) ); + $startTime = date('H:i:s', strtotime( $startTime ) ); + + $sql = sprintf( "SELECT COUNT(*) FROM session WHERE + idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'", + $cinema, $hall, $date, $startTime); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + $session = null; + $session = mysqli_fetch_array($resul); + + mysqli_free_result($resul); + + return $session[0]; + } + + //Returns a query to get all the session's data. + public function getAllSessionsFromACinemaHallDate($cinema, $hall, $date){ + $date = date('Y-m-d', strtotime( $date ) ); + + $sql = sprintf( "SELECT * FROM session WHERE + idcinema = '%s' AND idhall = '%s' AND date = '%s'", + $cinema, $hall, $date); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + $sessions = null; + + while($fila=mysqli_fetch_array($resul)){ + $sessions[] = $this->loadSession($fila["id"], $fila["idfilm"], $fila["idhall"], $fila["idcinema"], $fila["date"], $fila["start_time"], $fila["seat_price"], $fila["format"]); + } + mysqli_free_result($resul); + + return $sessions; + } + + public function editSession($idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format){ + $format = $this->mysqli->real_escape_string($format); + $date = date('Y-m-d', strtotime( $date ) ); + $startTime = date('H:i:s', strtotime( $startTime ) ); + + $sql = sprintf( "UPDATE `session` + SET `idfilm` = '%d' , `idhall` = '%d', `idcinema` = '%d', `date` = '%s', + `start_time` = '%s', `seat_price` = '%d', `format` = '%s' + WHERE + idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'", + $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format, $_SESSION["cinema"],$_SESSION["hall"],$_SESSION["date"],$_SESSION["start"]); + + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + return $resul; + } + + public function deleteSession($hall, $cinema, $date, $startTime){ + + $sql = sprintf( "DELETE FROM `session` WHERE + idcinema = '%s' AND idhall = '%s' AND date = '%s' AND start_time = '%s'", + $cinema, $hall, $date, $startTime); + + $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, $idcinema, $date, $startTime, $seatPrice, $format){ + return new SessionDTO( $id, $idfilm, $idhall, $idcinema, $date, $startTime, $seatPrice, $format); + } + + } + +?> diff --git a/assets/php/common/session_dto.php b/assets/php/common/session_dto.php new file mode 100644 index 0000000..99ade75 --- /dev/null +++ b/assets/php/common/session_dto.php @@ -0,0 +1,56 @@ +_id = $id; + $this->_idfilm = $idfilm; + $this->_idhall = $idhall; + $this->_idcinema = $idcinema; + $this->_date = $date; + $this->_startTime = $startTime; + $this->_seatPrice = $seatPrice; + $this->_format = $format; + } + + //Methods: + + //Getters && Setters: + public function setId($id){ $this->_id = $id; } + public function getId(){ return $this->_id; } + + public function setIdfilm($idfilm){ $this->_idfilm = $idfilm; } + public function getIdfilm(){ return $this->_idfilm; } + + 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; } + + public function setStartTime($startTime){ $this->_startTime = $startTime; } + public function getStartTime(){ return $this->_startTime; } + + public function setSeatPrice($seatPrice){ $this->_seatPrice = $seatPrice; } + public function getSeatPrice(){ return $this->_seatPrice; } + + public function setFormat($format){ $this->_format = $format; } + public function getFormat(){ return $this->_format; } + + } +?> \ No newline at end of file diff --git a/assets/php/common/session_dto_interface.php b/assets/php/common/session_dto_interface.php new file mode 100644 index 0000000..651716f --- /dev/null +++ b/assets/php/common/session_dto_interface.php @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/assets/php/common/user_dao.php b/assets/php/common/user_dao.php new file mode 100644 index 0000000..3c8f7e3 --- /dev/null +++ b/assets/php/common/user_dao.php @@ -0,0 +1,95 @@ +encryptPass($password); + + $sql = sprintf( "INSERT INTO users( id, username, email, passwd, rol) + VALUES ( '%s', '%s', '%s', '%s', '%s')", + $id, $username, $email, $password, $rol ); + + $resul = mysqli_query($this->mysqli, $sql) /*or die ('Error into query database')*/; + + return $resul; + } + + //Returns a query to check if the user name exists. + public function selectUser($username, $password){ + $username = $this->mysqli->real_escape_string($username); + + $sql = sprintf( "SELECT * FROM users WHERE username = '%s'", $username ); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + $resul->data_seek(0); + while ($fila = $resul->fetch_assoc()) { + if($username === $fila['username'] && $this->verifyPass($password, $fila['passwd'])){ + $user = $this->loadUser($fila['id'], $fila['username'], $fila['email'], $fila['passwd'], $fila['rol']); + } + } + + //mysqli_free_result($selectUser); + $resul->free(); + + return $user; + } + + //Returns a query to check if the user pass matches. + public function selectPass($username, $password){ + $username = $this->mysqli->real_escape_string($username); + $password = $this->mysqli->real_escape_string($password); + $password = $this->encryptPass($password); + + $sql = sprintf( "SELECT * FROM users WHERE username = '%s' AND passwd = '%s'", $username, $password); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + //return $this->mysqli->query($sql); + return $resul; + } + + //Returns a query to get the user's data. + public function userData($id){ + $sql = sprintf( "SELECT * FROM users WHERE id = '%d'", $id ); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + return $resul; + } + + //Create a new User Data Transfer Object. + public function loadUser($id, $username, $email, $password, $rol){ + return new UserDTO($id, $username, $email, $password, $rol); + } + + } + +?> \ No newline at end of file diff --git a/assets/php/common/user_dto.php b/assets/php/common/user_dto.php new file mode 100644 index 0000000..342eac7 --- /dev/null +++ b/assets/php/common/user_dto.php @@ -0,0 +1,37 @@ + Será eliminado en la siguiente práctica para usar el modelo relacional de nuestra BD. + + //Constructor: + function __construct($id, $username, $email, $password, $rol){ + $this->_id = $id; + $this->_username = $username; + $this->_email = $email; + $this->_password = $password; + $this->_rol = $rol; + } + + //Methods: + + //Getters && Setters: + public function setId($id){ $this->_id = $id; } + public function getId(){ return $this->_id; } + public function setName($username){ $this->_username = $username; } + public function getName(){ return $this->_username; } + public function setEmail($email){ $this->_email = $email; } + public function getEmail(){ return $this->_email; } + public function setPass($passwd){ $this->_password = $passwd; } + public function getPass(){ return $this->_password; } + public function setRol($rol){ $this->_rol = $rol; } + public function getRol(){ return $this->_rol; } + + } +?> \ No newline at end of file diff --git a/assets/php/common/users_dto_interface.php b/assets/php/common/users_dto_interface.php new file mode 100644 index 0000000..4705352 --- /dev/null +++ b/assets/php/common/users_dto_interface.php @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/assets/php/dao.php b/assets/php/dao.php index bbee497..849ecbe 100644 --- a/assets/php/dao.php +++ b/assets/php/dao.php @@ -2,10 +2,10 @@ // TO-DO: Completar class DAO { //Constants: - private const _SERVERNAME = "localhost"; - private const _USERNAME = "sw"; - private const _PASSWORD = "_admin_"; - private const _BD = "complucine"; + private const _SERVERNAME = BD_HOST; + private const _USERNAME = BD_USER; + private const _PASSWORD = BD_PASS; + private const _BD = BD_NAME; //Atributes: public $mysqli; diff --git a/index.php b/index.php index c72a724..02b3a60 100644 --- a/index.php +++ b/index.php @@ -1,10 +1,10 @@ allFilmData(); $tittles = array(); diff --git a/login/includes/formLogin.php b/login/includes/formLogin.php index 01be373..a167386 100644 --- a/login/includes/formLogin.php +++ b/login/includes/formLogin.php @@ -1,6 +1,6 @@ processesForm(null, $_SESSION["cinema"], null, null, "list"); diff --git a/panel_manager/includes/formHall.php b/panel_manager/includes/formHall.php index 8bf817d..0972e16 100644 --- a/panel_manager/includes/formHall.php +++ b/panel_manager/includes/formHall.php @@ -1,5 +1,5 @@ allFilmData(); $titles = array();