From dfbe2877b517f9be96efdec134730b39f424df1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mu=C3=B1oz=20Garcia?= <73303506+danimu03@users.noreply.github.com> Date: Sun, 2 May 2021 17:25:58 +0200 Subject: [PATCH] restructuring and functionality cinemas --- panel_admin/includes/cinema.php | 32 +++++ panel_admin/includes/cinema_dao.php | 66 +++++++++ panel_admin/includes/film.php | 3 +- panel_admin/includes/formCinema.php | 115 ++++++++++++++++ panel_admin/includes/formFilm.php | 8 +- panel_admin/manage_cinemas.php | 200 ++++++++++++++++++++-------- panel_admin/manage_films.php | 118 ++++++++++++---- panel_admin/panelAdmin.php | 51 ++++++- 8 files changed, 494 insertions(+), 99 deletions(-) create mode 100644 panel_admin/includes/cinema.php create mode 100644 panel_admin/includes/cinema_dao.php create mode 100644 panel_admin/includes/formCinema.php diff --git a/panel_admin/includes/cinema.php b/panel_admin/includes/cinema.php new file mode 100644 index 0000000..e23c70f --- /dev/null +++ b/panel_admin/includes/cinema.php @@ -0,0 +1,32 @@ +_id = $id; + $this->_name = $name; + $this->_direction = $direction; + $this->_phone = $phone; + } + + //Methods: + + //Getters && Setters: + public function setId($id){ $this->_id = $id; } + public function getId(){ return $this->_id; } + public function setName($name){ $this->_name = $name; } + public function getName(){ return $this->_name; } + public function setDirection($direction){ $this->_direction = $direction; } + public function getDirection(){ return $this->_direction; } + public function setPhone($phone){$this->_phone = $phone; } + public function getPhone(){ return $this->_phone; } + } +?> \ No newline at end of file diff --git a/panel_admin/includes/cinema_dao.php b/panel_admin/includes/cinema_dao.php new file mode 100644 index 0000000..966f6f2 --- /dev/null +++ b/panel_admin/includes/cinema_dao.php @@ -0,0 +1,66 @@ +get_prefix(); + include_once($prefix.'assets/php/dao.php'); + + class Cinema_DAO extends DAO { + + //Constructor: + function __construct($bd_name){ + parent::__construct($bd_name); + } + + //Methods: + + //Create a new Session. + public function createCinema($id, $name, $direction, $phone){ + $sql = sprintf( "INSERT INTO `cinema`( `id`, `name`, `direction`, `phone`) + VALUES ( '%d', '%s', '%s', '%s')", + $id, $name, $direction, $phone); + + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + return $resul; + } + + + //Returns a query to get All the films. + public function allCinemaData(){ + $sql = sprintf( "SELECT * FROM cinema "); + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + while($fila=$resul->fetch_assoc()){ + $films[] = $this->loadCinema($fila["id"], $fila["name"], $fila["direction"], $fila["phone"]); + } + $resul->free(); + return $films; + } + + //Deleted film by "id". + public function deleteCinema($id){ + $sql = sprintf( "DELETE FROM cinema WHERE cinema.id = '%d' ;",$id); + + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + return $resul; + } + + //Edit a film. + public function editCinema($id, $name, $direction, $phone){ + $sql = sprintf( "UPDATE cinema SET name = '%s' , direction = '%s', phone ='%s' + WHERE cinema.id = '%d';", + $name, $direction, $phone, $id); + + $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); + + return $resul; + } + + //Create a new film Data Transfer Object. + public function loadCinema($id, $name, $direction, $phone){ + return new Cinema($id, $name, $direction, $phone); + } + + } + +?> diff --git a/panel_admin/includes/film.php b/panel_admin/includes/film.php index 078c4be..f107954 100644 --- a/panel_admin/includes/film.php +++ b/panel_admin/includes/film.php @@ -1,5 +1,4 @@ _language;} public function setDescription($description){ $this->_description = $description;} public function getDescription(){return $this->_description;} + + } ?> \ No newline at end of file diff --git a/panel_admin/includes/formCinema.php b/panel_admin/includes/formCinema.php new file mode 100644 index 0000000..6ff9064 --- /dev/null +++ b/panel_admin/includes/formCinema.php @@ -0,0 +1,115 @@ +reply = array(); + } + + public function getReply() { + if($this->correct){ + if($this->option == "new"){ + $this->reply = "
Se ha añadido el cine correctamente en la base de datos.
+ "; + }else if($this->option == "edit"){ + $this->reply = "Se ha editado el cine correctamente en la base de datos.
+ "; + }else if($this->option == "del"){ + $this->reply = "Se ha eliminado el cine correctamente en la base de datos.
+ "; + } + + } else { + $this->reply = "Ha habido un error en la operacion. Revisa los datos introducidos
+ "; + + } + return $this->reply; + } + + //Process form: + public function processesForm($_id, $_name, $_direction, $_phone, $_option) { + $this->correct = true; + $this->option = $_option; + + $id= $this->test_input($_id); + $name=$this->test_input($_name); + $direction=$this->test_input($_direction); + $phone=$this->test_input($_phone); + + //Habria que validar todo para que encaje en la base de datos + + $bd = new Cinema_DAO('complucine'); + if($bd){ + if($this->option == "new"){ + //Primero comprobar si los campos no son vacios y la duracion es mayor que 0 + if(!empty($name)&&!empty($direction)&&!empty($phone)){ + // comprobar si existe una pelicula con el mismo nombre y direccion + $exist = $bd->GetCinema($name,$direction); + if( mysqli_num_rows($exist) != 0){ + $this->correct =false; + } + else{ + $bd->createCinema(null, $name, $direction, $phone); + + } + $exist->free(); + } + else{ + $this->correct =false; + } + } else if ($this->option == "del"){ + //Primero comprobar si existe una pelicula con el mismo id + $exist = $bd-> CinemaData($id); + if( mysqli_num_rows($exist) == 1){ + $bd->deleteCinema($id); + } + else{ + $this->correct =false; + } + } else if ($this->option == "edit"){ + //Primero comprobar si los campos no son vacios y la duracion es mayor que 0 + if(!empty($name)&&!empty($direction)&&!empty($phone)){ + //comprobar si existe una pelicula con el mismo id + $exist = $bd-> CinemaData($id); + if( mysqli_num_rows($exist) == 1){ + $bd->editCinema($id,$name,$direction,$phone); + } + else{ + $this->correct =false; + } + $exist->free(); + } + else{ + $this->correct =false; + } + } + else {$this->correct = false;} + } + + + } + + protected function test_input($input){ + return htmlspecialchars(trim(strip_tags($input))); + } +} + + +?> \ No newline at end of file diff --git a/panel_admin/includes/formFilm.php b/panel_admin/includes/formFilm.php index fa55f30..75104e3 100644 --- a/panel_admin/includes/formFilm.php +++ b/panel_admin/includes/formFilm.php @@ -18,8 +18,6 @@ class FormFilm extends Form { $this->reply = array(); } - - public function getReply() { if($this->correct){ if($this->option == "new"){ @@ -34,8 +32,6 @@ class FormFilm extends Form { $this->reply = "Se ha eliminado la pelicula correctamente en la base de datos.
"; - } else if($this->option == "show"){ - $this->reply= $this->array; } } else { @@ -104,9 +100,7 @@ class FormFilm extends Form { else{ $this->correct =false; } - } else if($this->option == "show") { - $this->array = $bd->allFilmData(); - } + } else {$this->correct = false;} } diff --git a/panel_admin/manage_cinemas.php b/panel_admin/manage_cinemas.php index 50f1c28..7eeba26 100644 --- a/panel_admin/manage_cinemas.php +++ b/panel_admin/manage_cinemas.php @@ -1,67 +1,151 @@ - "1234", - "name" => "cineJuan", - "address"=> "calle..", - "phone_number"=>"660099000", -); + //General Config File: + include_once('../assets/php/config.php'); -$delete_cinemas=' -idCine | -nombre | -Dirección | -Teléfono | -||
---|---|---|---|---|---|
'. $cinema['idCine'] .' | -'. $cinema['name'] .' | -'. $cinema['address'] .' | -'. $cinema['phone_number'] .' | -||
Id | +Nombre | +Direccion | +Telefono | +||
---|---|---|---|---|---|
'. $f->getId() .' | +'. $f->getName() .' | +'. $f->getDirection() .' | +'. $f->getPhone() .' | ++ + | ++ + | +
'. $f->getLanguage() .' | '. $f->getDescription().' | - | - |