functional

This commit is contained in:
Daniel Muñoz Garcia 2021-04-15 11:02:38 +02:00 committed by GitHub
parent 79ae1b24db
commit 861430e017
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 25 deletions

View File

@ -39,9 +39,15 @@
public function allFilmData(){ public function allFilmData(){
$sql = sprintf( "SELECT * FROM film "); $sql = sprintf( "SELECT * FROM film ");
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database'); $resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
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. //Returns a query to get all films tittles.
public function tittleFilmData(){ public function tittleFilmData(){
$sql = sprintf( "SELECT DISTINCT tittle FROM film "); $sql = sprintf( "SELECT DISTINCT tittle FROM film ");

View File

@ -47,15 +47,21 @@ class FormFilm extends Form {
} }
//Process form: //Process form:
public function processesForm($id,$tittle,$duration,$language,$description, $option) { public function processesForm($_id,$_tittle,$_duration,$_language,$_description, $_option) {
$this->correct = true; $this->correct = true;
$this->option = $option; $this->option = $_option;
$id= $this->test_input($_id);
$tittle=$this->test_input($_tittle);
$duration=$this->test_input($_duration);
$language=$this->test_input($_language);
$description=$this->test_input($_description);
//Habria que validar todo para que encaje en la base de datos //Habria que validar todo para que encaje en la base de datos
$bd = new Film_DAO('complucine'); $bd = new Film_DAO('complucine');
if($bd ){ if($bd){
if($option == "new"){ if($this->option == "new"){
//Primero comprobar si los campos no son vacios y la duracion es mayor que 0 //Primero comprobar si los campos no son vacios y la duracion es mayor que 0
if(!empty($tittle)&&$duration>0&&!empty($language)&&!empty($description)){ if(!empty($tittle)&&$duration>0&&!empty($language)&&!empty($description)){
// comprobar si existe una pelicula con el mismo titulo e idioma // comprobar si existe una pelicula con el mismo titulo e idioma
@ -64,15 +70,15 @@ class FormFilm extends Form {
$this->correct =false; $this->correct =false;
} }
else{ else{
$resul=$bd->createFilm(null, $tittle,$duration,$language,$description); $bd->createFilm(null, $tittle,$duration,$language,$description);
$resul->free();
} }
$exist->free(); $exist->free();
} }
else{ else{
$this->correct =false; $this->correct =false;
} }
} else if ($option == "del"){ } else if ($this->option == "del"){
//Primero comprobar si existe una pelicula con el mismo id //Primero comprobar si existe una pelicula con el mismo id
$exist = $bd-> FilmData($id); $exist = $bd-> FilmData($id);
if( mysqli_num_rows($exist) == 1){ if( mysqli_num_rows($exist) == 1){
@ -81,14 +87,13 @@ class FormFilm extends Form {
else{ else{
$this->correct =false; $this->correct =false;
} }
} else if ($option == "edit"){ } else if ($this->option == "edit"){
//Primero comprobar si los campos no son vacios y la duracion es mayor que 0 //Primero comprobar si los campos no son vacios y la duracion es mayor que 0
if(!empty($tittle)&&$duration>0&&!empty($language)&&!empty($description)){ if(!empty($tittle)&&$duration>0&&!empty($language)&&!empty($description)){
//comprobar si existe una pelicula con el mismo id //comprobar si existe una pelicula con el mismo id
$exist = $bd-> FilmData($id); $exist = $bd-> FilmData($id);
if( mysqli_num_rows($exist) == 1){ if( mysqli_num_rows($exist) == 1){
$resul = $bd->editFilm($id,$tittle,$duration,$language,$description); $bd->editFilm($id,$tittle,$duration,$language,$description);
$resul->free();
} }
else{ else{
$this->correct =false; $this->correct =false;
@ -98,18 +103,19 @@ class FormFilm extends Form {
else{ else{
$this->correct =false; $this->correct =false;
} }
} else if($this->option == "show") { } else if($this->option == "show") {
$resul = $bd->allFilmData(); $this->array = $bd->allFilmData();
while($fila=mysqli_fetch_assoc($resul)){
$this->array = new FilmDTO($fila["id"], $fila["tittle"], $fila["duration"], $fila["language"], $fila["description"]);
}
$resul->free();
} }
else {$this->correct = false;} else {$this->correct = false;}
} }
$bd->__destruct();
} }
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
} }
?> ?>

View File

@ -5,12 +5,13 @@
require_once('../assets/php/template.php'); require_once('../assets/php/template.php');
require_once('../panel_admin/panelAdmin.php'); require_once('../panel_admin/panelAdmin.php');
$template = new Template(); $template = new Template();
$login=false;
if(isset($_SESSION["login"]) && $_SESSION["rol"] == "admin") $login = true;
if(isset($_GET['state'])) { if(isset($_GET['state'])) {
$panel = new Panel($_GET['state']); $panel = new Panel($_GET['state'], $login);
} }
else { else {
$panel = new Panel(''); $panel = new Panel('', $login);
} }
// IMPORTANTE: // IMPORTANTE:
// VERIFICAR QUE ES ADMIN, SI NO, MOSTRAR MENSAJE DE "ERROR" // VERIFICAR QUE ES ADMIN, SI NO, MOSTRAR MENSAJE DE "ERROR"

View File

@ -11,9 +11,8 @@
$film = new FormFilm(); $film = new FormFilm();
$film->processesForm(null, null, null, null, null, "show"); $film->processesForm(null, null, null, null, null, "show");
function drawFilms($films){ function drawFilms($films){
echo " echo "
<table class='alt'> <table class='alt'>
<thead> <thead>