unified code

This commit is contained in:
Daniel Muñoz Garcia 2021-04-13 22:29:25 +02:00 committed by GitHub
parent 45d0570e62
commit ce6c3a92e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 13 deletions

View File

@ -13,17 +13,11 @@
//Create a new Session. //Create a new Session.
public function createFilm($id, $tittle, $duration, $language,$description){ public function createFilm($id, $tittle, $duration, $language,$description){
$exist = sprintf( "SELECT * FROM film WHERE tittle = '%s'", $tittle );
$film =mysqli_query($this->mysqli, $exist) ;
if($film.is_null() ||$film["language"]!=$language){
$sql = sprintf( "INSERT INTO `film`( `id`, `tittle`, `duration`, `language`,`description`) $sql = sprintf( "INSERT INTO `film`( `id`, `tittle`, `duration`, `language`,`description`)
VALUES ( '%d', '%s', '%d', '%s','%s')", VALUES ( '%d', '%s', '%d', '%s','%s')",
$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');
}else{
die ('Error into query database film already exist');
}
return $sql; return $sql;
} }

View File

@ -55,6 +55,7 @@ class FormFilm extends Form {
$bd = new Film_DAO('complucine'); $bd = new Film_DAO('complucine');
if($bd ){ if($bd ){
if($option == "new"){ if($option == "new"){
//Primero comprobar si existe una pelicula con el mismo titulo e idioma
$bd->createFilm(null, $title,$duration,$languaje,$description); $bd->createFilm(null, $title,$duration,$languaje,$description);
} else if ($option == "del"){ } else if ($option == "del"){
$bd->deleteFilm($id); $bd->deleteFilm($id);

View File

@ -6,8 +6,6 @@
require_once('../panel_admin/panelAdmin.php'); require_once('../panel_admin/panelAdmin.php');
$template = new Template(); $template = new Template();
if(isset($_SESSION["login"]) && $_SESSION["rol"] == "admin") $login = true;
if(isset($_REQUEST['state'])) { if(isset($_REQUEST['state'])) {
$panel = new Panel($_REQUEST['state']); $panel = new Panel($_REQUEST['state']);
} }

View File

@ -35,7 +35,7 @@
<td>'. $f->getLanguage() .'</td> <td>'. $f->getLanguage() .'</td>
<td>'. $f->getDescription().'</td> <td>'. $f->getDescription().'</td>
<td> <td>
<form method="post" action="./index.php?state=ef"> <form method="post" action="./index.php?state=uf">
<input name="id" type="hidden" value="'.$f->getId().'"> <input name="id" type="hidden" value="'.$f->getId().'">
<input name="tittle" type="hidden" value="'.$f->getTittle().'"> <input name="tittle" type="hidden" value="'.$f->getTittle().'">
<input name="duration" type="hidden" value="'.$f->getDuration().'"> <input name="duration" type="hidden" value="'.$f->getDuration().'">
@ -45,7 +45,7 @@
</form> </form>
</td> </td>
<td> <td>
<form method="post" action="./index.php?state=df"> <form method="post" action="./index.php?state=uf">
<input name="id" type="hidden" value="'.$f->getId().'"> <input name="id" type="hidden" value="'.$f->getId().'">
<input name="tittle" type="hidden" value="'.$f->getTittle().'"> <input name="tittle" type="hidden" value="'.$f->getTittle().'">
<input name="duration" type="hidden" value="'.$f->getDuration().'"> <input name="duration" type="hidden" value="'.$f->getDuration().'">
@ -62,7 +62,7 @@
function addFilm(){ function addFilm(){
echo'<div class="column size"> echo'<div class="column size">
<h2>Añadir pelicula</h2> <h2>Añadir pelicula</h2>
<form method="post" action="add_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>

View File

@ -8,8 +8,7 @@
function showPanel() { function showPanel() {
switch($this->state) { switch($this->state) {
case 'df': require('deleteFilm.php');break; case 'uf': require('updateFilm.php');break;
case 'ef': require('editFilm.php');break;
case 'mc': require('manage_cinemas.php'); break; case 'mc': require('manage_cinemas.php'); break;
case 'mf': require('manage_films.php'); break; case 'mf': require('manage_films.php'); break;
case 'md': require('manage_discounts.php'); break; case 'md': require('manage_discounts.php'); break;

View File

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

View File

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