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 = "

Operacion realizada con exito


+

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

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

Operacion realizada con exito


+

Se ha editado el cine correctamente en la base de datos.

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

Operacion realizada con exito


+

Se ha eliminado el cine correctamente en la base de datos.

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

ERROR


+

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 = "

Operacion realizada con exito


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=' -
-

Lista de cines

-

-
- - - - - - - - - - - - - - - - - + include_once('../assets/php/common/cinema.php'); + include_once(__DIR__.'/includes/formCinema.php'); - - - - + + + // View functions + /*function drawCinema(){ + $cine = new Cinema_DAO("complucine"); + $cinemas = $cine->allCinemaData(); + echo "
+
idCinenombreDirecciónTeléfono
'. $cinema['idCine'] .' '. $cinema['name'] .' '. $cinema['address'] .' '. $cinema['phone_number'] .'
+ + + + + + + + + "; + foreach($cinemas as $f){ + echo ' + + + + + + + + '; + } + echo'
IdNombreDireccionTelefono
'. $f->getId() .''. $f->getName() .''. $f->getDirection() .''. $f->getPhone() .' +
+ + + + + +
+
+
+ + + + + +
+
-
-
'."\n"; -$add_cinemas=' -
-

Añadir o modificar cine

-
+
'; + }*/ + function addCinema(){ + echo'
+

Añadir cine

+
-
- Datos del cine -
- -
-
- -
-
- -
-
- -
+
+ Datos del Cine +
+ +
+
+ +
+
+ +
- + +
-
- - '."\n"; -?> + + '; + } + function deleteCinema() { + echo'
+

Editar cine

+
+
+
+ ¿Estás seguro de que quieres eliminar este cine? + +

Id: '.$_POST['id'].'

+

Nombre: '.$_POST['name'].'

+

Dirección: '.$_POST['direction'].'

+

Teléfono: '.$_POST['phone'].'

+
+
+ + +
+
+
+
'; + } + function editCinema() { + echo'
+

Editar cine

+
+
+
+ Datos del cine + +
+ +
+
+ +
+
+ +
+
+
+ + +
+
+
+
'; + } + + // Logic Functions + function confirmDelete() { + $cine = new FormCinema(); + $cine->processesForm($_POST['id'],null,null,null,"del"); + $_SESSION['message'] = $cine->getReply(); + header('Location: ../panel_admin/index.php?state=mc'); + } + function confirmEdit() { + $cine = new FormCinema(); + $cine->processesForm($_POST['id'], $_POST['name'], $_POST['direction'], $_POST['phone'],"edit"); + $_SESSION['message']= $cine->getReply(); + header('Location: ../panel_admin/index.php?state=mc'); + } + function confirmAdd() { + $cine = new FormCinema(); + $cine->processesForm($_POST['id'], $_POST['name'], $_POST['direction'], $_POST['phone'],"new"); + $_SESSION['message'] = $cine->getReply(); + header('Location: ../panel_admin/index.php?state=mc'); + } + + +?> \ No newline at end of file diff --git a/panel_admin/manage_films.php b/panel_admin/manage_films.php index 53a38eb..c6f9f61 100644 --- a/panel_admin/manage_films.php +++ b/panel_admin/manage_films.php @@ -1,21 +1,16 @@ processesForm(null, null, null, null, null, "show"); - - /* - function drawFilms($films){ - echo "
+ //General Config File: + include_once('../assets/php/config.php'); + include_once('./includes/formFilm.php'); + require_once($prefix.'assets/php/common/film_dao.php'); + + + // View functions + /*function drawFilms(){ + $film = new Film_DAO("complucine"); + $films = $film->allFilmData(); + echo "
@@ -36,7 +31,7 @@
'. $f->getLanguage() .' '. $f->getDescription().' -
+ @@ -46,7 +41,7 @@
-
+ @@ -60,14 +55,11 @@ echo'
'; - } - */ - + }*/ function addFilm(){ - echo'
-
+ echo'

Añadir pelicula

- +
Datos de pelicula @@ -90,11 +82,79 @@
-
-
'; +
'; } - //addFilm(); - //drawFilms($film->getReply()); - + function deleteFilm() { + echo'
+

Editar pelicula

+
+
+
+ ¿Estás seguro de que quieres eliminar esta pelicula? + +

Id: '.$_POST['id'].'

+

Título: '.$_POST['tittle'].'

+

Duración: '.$_POST['duration'].'

+

Idioma: '.$_POST['language'].'

+

Descripción: '.$_POST['description'].'

+
+
+ + +
+
+
+
'; + } + function editFilm() { + echo'
+

Editar pelicula

+
+
+
+ Datos de pelicula + +
+ +
+
+ +
+
+ +
+
+ +
+
+
+ + +
+
+
+
'; + } + + // Logic Functions + function confirmDelete() { + $film = new FormFilm(); + $film->processesForm($_POST['id'],null,null,null,null,"del"); + $_SESSION['message'] = $film->getReply(); + header('Location: ../panel_admin/index.php?state=mf'); + } + function confirmEdit() { + $film = new FormFilm(); + $film->processesForm($_POST['id'], $_POST['tittle'], $_POST['duration'], $_POST['language'], $_POST['description'], "edit"); + $_SESSION['message']= $film->getReply(); + header('Location: ../panel_admin/index.php?state=mf'); + } + function confirmAdd() { + $film = new FormFilm(); + $film->processesForm(null, $_POST['tittle'], $_POST['duration'], $_POST['language'], $_POST['description'], "new"); + $_SESSION['message'] = $film->getReply(); + header('Location: ../panel_admin/index.php?state=mf'); + } + ?> \ No newline at end of file diff --git a/panel_admin/panelAdmin.php b/panel_admin/panelAdmin.php index 5af7a15..2557fae 100644 --- a/panel_admin/panelAdmin.php +++ b/panel_admin/panelAdmin.php @@ -11,12 +11,55 @@ function showPanel($template) { if($this->login){ switch($this->state) { - case 'uf': require_once('updateFilm.php'); break; - case 'mc': /*require_once('manage_cinemas.php')*/;echo"

En construcción

"; break; + case 'mc': require_once('manage_cinemas.php'); + if(isset($_POST['edit_cinema'])) { + editCinema(); + } + else if(isset($_POST['delete_cinema'])) { + deleteCinema(); + } + else if(isset($_POST['add_cinema'])) { + confirmAdd(); + header('Location: ../panel_admin/index.php?state=mc'); + } + else if(isset($_POST['confirm_delete_cinema'])) { + confirmDelete(); + header('Location: ../panel_admin/index.php?state=mc'); + } + else if(isset($_POST['confirm_edit_cinema'])) { + confirmEdit(); + header('Location: ../panel_admin/index.php?state=mc'); + } + else { + addCinema(); + $template->print_cinemas(); + + }; + break; case 'mf': require_once('manage_films.php'); + if(isset($_POST['edit_film'])) { + editFilm(); + } + else if(isset($_POST['delete_film'])) { + deleteFilm(); + } + else if(isset($_POST['add_film'])) { + confirmAdd(); + } + else if(isset($_POST['confirm_delete_film'])) { + confirmDelete(); + header('Location: ../panel_admin/index.php?state=mf'); + } + else if(isset($_POST['confirm_edit_film'])) { + confirmEdit(); + header('Location: ../panel_admin/index.php?state=mf'); + } + else { addFilm(); - $template->print_fimls(); - break; + $template->print_fimls(); + + }; + break; case 'md': /*require_once('manage_discounts.php')*/;echo"

En construcción

"; break; case 'mm': /*require_once('manage_managers.php')*/;echo"

En construcción

"; break; case 'un': echo"

En construcción

"; break;