different changes

- change from $ _REQUEST to $ _POST / $ _ GET
- Session messages are managed globally by template
This commit is contained in:
Daniel Muñoz Garcia 2021-04-14 11:38:51 +02:00 committed by GitHub
parent 5ad88e6e35
commit 4968bc8e25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 95 additions and 63 deletions

View File

@ -18,13 +18,7 @@
$id, $tittle, $duration, $language,$description); $id, $tittle, $duration, $language,$description);
$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; return $sql;
}
//Returns
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. //Returns a query to get the film's data.
@ -35,8 +29,6 @@
return $resul; return $resul;
} }
//Returns a query to get All the films. //Returns a query to get All the films.
public function allFilmData(){ public function allFilmData(){
$sql = sprintf( "SELECT * FROM film "); $sql = sprintf( "SELECT * FROM film ");

View File

@ -46,7 +46,7 @@ class FormFilm extends Form {
} }
//Process form: //Process form:
public function processesForm($id,$tittle,$duration,$language,$description, $option) { public function processesForm($id,$title,$duration,$languaje,$description, $option) {
$this->correct = true; $this->correct = true;
$this->option = $option; $this->option = $option;
@ -56,29 +56,11 @@ class FormFilm extends Form {
if($bd ){ if($bd ){
if($option == "new"){ if($option == "new"){
//Primero comprobar si existe una pelicula con el mismo titulo e idioma //Primero comprobar si existe una pelicula con el mismo titulo e idioma
$exist = $bd-> GetFilm($tittle,$language); $bd->createFilm(null, $title,$duration,$languaje,$description);
if( mysqli_num_rows($exist) != 0){
$this->correct =false;
}
else{
$bd->createFilm(null, $tittle,$duration,$language,$description);
}
} else if ($option == "del"){ } else if ($option == "del"){
$exist = $bd-> FilmData($id);
if( mysqli_num_rows($exist) != 0){
$bd->deleteFilm($id); $bd->deleteFilm($id);
}
else{
$this->correct =false;
}
} else if ($option == "edit"){ } else if ($option == "edit"){
$exist = $bd-> FilmData($id); $bd->editFilm($id,$title,$duration,$languaje,$description);
if( mysqli_num_rows($exist) != 0){
$bd->editFilm($id,$tittle,$duration,$language,$description);
}
else{
$this->correct =false;
}
} else if($this->option == "show") { } else if($this->option == "show") {
$this->array = $bd->allFilmData(); $this->array = $bd->allFilmData();
} }

View File

@ -6,8 +6,8 @@
require_once('../panel_admin/panelAdmin.php'); require_once('../panel_admin/panelAdmin.php');
$template = new Template(); $template = new Template();
if(isset($_REQUEST['state'])) { if(isset($_GET['state'])) {
$panel = new Panel($_REQUEST['state']); $panel = new Panel($_GET['state']);
} }
else { else {
$panel = new Panel(''); $panel = new Panel('');
@ -66,6 +66,7 @@
<div class="column side"></div> <div class="column side"></div>
<div class="column middle"> <div class="column middle">
<?php <?php
$template->print_msg();
$panel->showPanel(); $panel->showPanel();
?> ?>
</div> </div>

View File

@ -87,15 +87,6 @@
</form> </form>
</div>'; </div>';
} }
function showmessage() {
if(isset($_SESSION['message'])){
echo '<div>
<h3>'.$_SESSION["message"].'</h3>
</div>';
unset($_SESSION['message']);
}
}
showmessage();
drawFilms($film->getReply()); drawFilms($film->getReply());
addFilm(); addFilm();

View File

@ -2,25 +2,25 @@
include_once('./includes/film_dto.php'); include_once('./includes/film_dto.php');
include_once('./includes/formFilm.php'); include_once('./includes/formFilm.php');
if(isset($_REQUEST['edit_film'])) { if(isset($_POST['edit_film'])) {
echo'<div class="column size"> echo'<div class="column size">
<h2>Editar pelicula</h2> <h2>Editar pelicula</h2>
<form method="post" action="update_film.php"> <form method="post" action="update_film.php">
<div class="row"> <div class="row">
<fieldset id="film_form"> <fieldset id="film_form">
<legend>Datos de pelicula</legend> <legend>Datos de pelicula</legend>
<input type="hidden" name="id" value='.$_REQUEST['id'].'/> <input type="hidden" name="id" value='.$_POST['id'].'/>
<div> <div>
<input type="text" name="tittle" value='.$_REQUEST['tittle'].' /> <input type="text" name="tittle" value='.$_POST['tittle'].' />
</div> </div>
<div> <div>
<input type="number" name="duration" id="duration" value='.$_REQUEST['duration'].' /> <input type="number" name="duration" id="duration" value='.$_POST['duration'].' />
</div> </div>
<div> <div>
<input type="text" name="language" id="language" value='.$_REQUEST['language'].' /> <input type="text" name="language" id="language" value='.$_POST['language'].' />
</div> </div>
<div> <div>
<input type="text" name="description" id="description" value="'.$_REQUEST['description'].'"/> <input type="text" name="description" id="description" value="'.$_POST['description'].'"/>
</div> </div>
</fieldset> </fieldset>
<div class="actions"> <div class="actions">
@ -32,19 +32,19 @@
</div>'; </div>';
} }
else if(isset($_REQUEST['delete_film'])) { else if(isset($_POST['delete_film'])) {
echo'<div class="column size"> echo'<div class="column size">
<h2>Editar pelicula</h2> <h2>Editar pelicula</h2>
<form method="post" action="update_film.php"> <form method="post" action="update_film.php">
<div class="row"> <div class="row">
<fieldset id="film_form"> <fieldset id="film_form">
<legend>¿Estás seguro de que quieres eliminar esta pelicula?</legend> <legend>¿Estás seguro de que quieres eliminar esta pelicula?</legend>
<input type="hidden" name="id" value='.$_REQUEST['id'].'/> <input type="hidden" name="id" value='.$_POST['id'].'/>
<p>Id: '.$_REQUEST['id'].' </p> <p>Id: '.$_POST['id'].' </p>
<p>Título: '.$_REQUEST['tittle'].' </p> <p>Título: '.$_POST['tittle'].' </p>
<p>Duración: '.$_REQUEST['duration'].' </p> <p>Duración: '.$_POST['duration'].' </p>
<p>Idioma: '.$_REQUEST['language'].' </p> <p>Idioma: '.$_POST['language'].' </p>
<p>Descripción: '.$_REQUEST['description'].' </p> <p>Descripción: '.$_POST['description'].' </p>
</fieldset> </fieldset>
<div class="actions"> <div class="actions">
<input type="submit" id="submit" value="Eliminar" name="confirm_delete_film" class="primary" /> <input type="submit" id="submit" value="Eliminar" name="confirm_delete_film" class="primary" />

View File

@ -3,21 +3,21 @@
include_once('./includes/film_dto.php'); include_once('./includes/film_dto.php');
include_once('./includes/formFilm.php'); include_once('./includes/formFilm.php');
if(isset($_REQUEST['add_film'])) { if(isset($_POST['add_film'])) {
$film = new FormFilm(); $film = new FormFilm();
$film->processesForm(null, $_REQUEST['tittle'], $_REQUEST['duration'], $_REQUEST['language'], $_REQUEST['description'], "new"); $film->processesForm(null, $_POST['tittle'], $_POST['duration'], $_POST['language'], $_POST['description'], "new");
$_SESSION['message'] = $film->getReply(); $_SESSION['message'] = $film->getReply();
} }
else if(isset($_REQUEST['confirm_delete_film'])) { else if(isset($_POST['confirm_delete_film'])) {
$film = new FormFilm(); $film = new FormFilm();
$film->processesForm($_REQUEST['id'],null,null,null,null,"del"); $film->processesForm($_POST['id'],null,null,null,null,"del");
$_SESSION['message'] = $film->getReply(); $_SESSION['message'] = $film->getReply();
} }
else if(isset($_REQUEST['confirm_edit_film'])) { else if(isset($_POST['confirm_edit_film'])) {
$film = new FormFilm(); $film = new FormFilm();
$film->processesForm($_REQUEST['id'], $_REQUEST['tittle'], $_REQUEST['duration'], $_REQUEST['language'], $_REQUEST['description'], "edit"); $film->processesForm($_POST['id'], $_POST['tittle'], $_POST['duration'], $_POST['language'], $_POST['description'], "edit");
$_SESSION['message']= $film->getReply(); $_SESSION['message']= $film->getReply();
} }
header("Location: ../panel_admin/index.php?state=mf"); header('Location: ../panel_admin/index.php?state=mf');
?> ?>

66
panel_admin/validade.php Normal file
View File

@ -0,0 +1,66 @@
<?php
session_start();
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/formFilm.php');
$session = new FormFilm();
$session->processesForm($id, $_POST["title"], $_POST["duration"], $_POST["languaje"],$_POST["description"], $action);
$reply = $session->getReply();
?>
<!DOCTYPE HTML>
<!--
Práctica 2 - Sistemas Web | Grupo D
CompluCine - FDI-cines
-->
<html lang="es">
<!-- Head -->
<?php
$template->print_head();
?>
<body>
<!-- Header -->
<?php
$template->print_header();
?>
<!-- Main -->
<div class="main">
<div class="image"><img src="../img/logo_trasparente.png" /></div>
</div>
<!-- Reply -->
<section class="reply">
<div class ="row">
<div class="column side"></div>
<div class="column middle">
<div class="code info">
<?php
echo $reply;
?>
</div>
</div>
<div class="column side"></div>
</div>
</section>
<!-- Footer -->
<?php
$template->print_footer();
?>
</body>
</html>