Add files via upload

This commit is contained in:
Daniel Muñoz Garcia 2021-04-13 13:50:23 +02:00 committed by GitHub
parent a5f92c9bb0
commit 19168d2f8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 126 additions and 93 deletions

13
panel_admin/add_film.php Normal file
View File

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

37
panel_admin/editFilm.php Normal file
View File

@ -0,0 +1,37 @@
<?php
include_once('./includes/film_dto.php');
include_once('./includes/formFilm.php');
if($_REQUEST['edit_film']) {
echo'<div class="column size">
<h2>Editar pelicula</h2>
<form method="post" action="edit_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>';
}
?>

View File

@ -1,40 +1,11 @@
<?php
session_start();
include_once('./includes/film_dto.php');
include_once('./includes/film_dao.php');
$bd = new FilmDAO("complucine");
if( $_REQUEST['option'] == 'edit') {
$film = ($bd->FilmData($_GET["id"]));
$filmDto=$bd->loadFilm($film['id'],$film['title'],$film['duration'],$film['languaje'].$film['description']);
echo'<div class="column size">
<h2>Editar pelicula</h2>
<form method="post" action="../panel_admin/validate.php">
<div class="row">
<fieldset id="film_form">
<legend>Datos de pelicula</legend>
<div>
<input type="text" name="title" id="title" value=\"".$filmDto.getTittle()."\" placeholder="Título" />
</div>
<div>
<input type="number" name="duration" id="duration" value=\"".$filmDto.getDuration()."\" placeholder="Duración" />
</div>
<div>
<input type="text" name="lenguage" id="language" value=\"".$filmDto.getLanguage()."\" placeholder="Idioma" />
</div>
<div>
<input type="text" name="description" id="description" value=\"".$filmDto.getDescription()."\" placeholder="Descripción" />
</div>
</fieldset>
<div class="actions">
<input type="submit" id="submit" value="Editar pelicula" name="edit_film" class="primary" />
<input type="reset" id="reset" value="Borrar" />
</div>
</div>
</form>
</div>'."\n";
}
include_once('./includes/formFilm.php');
if($_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");
}
?>

View File

@ -14,12 +14,11 @@
//Create a new Session.
public function createFilm($id, $tittle, $duration, $language, $description){
$sql = sprintf( "INSERT INTO film( $id, $tittle, $duration, $language, $description)
VALUES ( '%d', '%s', '%d', '%s', '%d')",
$id, $tittle, $duration, $language, $description);
return $sql;
$sql = sprintf( "INSERT INTO film(tittle, duration, language, description)
VALUES ('%s', '%d', '%s', '%s')",
$tittle, $duration, $language, $description);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Returns a query to get the film's data.
@ -52,19 +51,18 @@
public function deleteFilm($id){
$sql = sprintf( "DELETE FROM `film` WHERE `film`.`id` = '%d' ;",$id);
$sql = sprintf( "DELETE FROM film WHERE film.id = '%d' ;",$id);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
public function editFilm($id, $title, $duration, $lenguaje,$description){
public function editFilm($id, $tittle, $duration, $language,$description){
$sql = sprintf( "UPDATE film
SET title = '%s' , duration = '%d', lenguaje ='%s' ,`description` ='%s'
WHERE `film`.`id` = '%d';",
$title,$duration,$lenguaje, $description,$id );
SET tittle = '%s' , duration = '%d', language ='%s' , description ='%s'
WHERE film.id = '%d';",
$tittle,$duration,$language, $description,$id);
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');

View File

@ -9,6 +9,7 @@ class FormFilm extends Form {
private $correct; // Indicates if the session is correct.
private $reply; // Validation response
private $option;
private $array;
//Constructor:
public function __construct() {
parent::__construct('formFilm');
@ -18,26 +19,27 @@ class FormFilm extends Form {
public function getReply() {
if($this->correct){
if($this->option == "new"){
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
<p> Se ha añadido la pelicula correctamente en la base de datos.</p>
<a href='../panel_admin/index.php'><button>Panel Admin</button></a>";
<a href='../panel_admin/index.php?state=mf'><button>Cerrar Mensaje</button></a>";
}else if($this->option == "edit"){
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
<p> Se ha editado la pelicula correctamente en la base de datos.</p>
<a href='../panel_admin/index.php'><button>Panel Admin</button></a>";
<a href='../panel_admin/index.php?state=mf'><button>Cerrar Mensaje</button></a>";
}else if($this->option == "del"){
$this->reply = "<h1> Operacion realizada con exito </h1><hr />
<p> Se ha eliminado la pelicula correctamente en la base de datos.</p>
<a href='../panel_admin/index.php'><button>Panel Admin</button></a>";
<a href='../panel_admin/index.php?state=mf'><button>Cerrar Mensaje</button></a>";
} else if($this->option == "show"){
$this->reply= $this->array;
}
} else {
$this->reply = "<h1> ERROR </h1><hr />
<p> Ha habido un error en la operacion. Revisa los datos introducidos</p>
<a href='../panel_admin/index.php'><button>Panel Admin</button></a>";
<a href='../panel_admin/index.php?state=mf'><button>Panel Admin</button></a>";
}
return $this->reply;
@ -47,27 +49,20 @@ class FormFilm extends Form {
public function processesForm($id,$title,$duration,$languaje,$description, $option) {
$this->correct = true;
$this->option = $option;
//Habria que validar todo para que encaje en la base de datos
$start = date('H:i:s', strtotime( $start ) );
$date = date('Y-m-d', strtotime( $date ) );
//Habria que validar todo para que encaje en la base de datos
$bd = new FilmDAO('complucine');
if($bd ){
if($option == "new"){
$selectFilm = $bd->selectSession($cinema, $hall, $start, $date);
if($selectSession && $selectSession->num_rows >= 1) {
$this->correct = false;
} else{
$bd->createFilm(null, $title,$duration,$languaje,$description);
}
mysqli_free_result($selectSession);
} else if ($option == "del"){
$bd->deleteFilm($id);
} else if ($option == "edit"){
$bd->editFilm($id,$title,$duration,$languaje,$description);
} else if($this->option == "show") {
$this->array = $bd->allFilmData();
}
} else {$this->correct = false;}
}

View File

@ -1,7 +1,6 @@
<?php
session_start();
require('./includes/film_dto.php');
require('./includes/film_dao.php');
require('./includes/formFilm.php');
/*$f1 = new FilmDTO(1000,"Los vengadores",183,"español","");
$f2 = new FilmDTO(2001,"Mecernarios",140,"español","");
$f3 = new FilmDTO(3022,"Monster hunter",104,"español","");
@ -10,8 +9,11 @@
$f6 = new FilmDTO(4606,"Pequeños Detalles",127,"inglés","");
$film= array($f1, $f2, $f3, $f4,$f5,$f6); */
$bd = new FilmDAO("complucine");
$film = new FormFilm();
$film->processesForm(null, null, null, null, null, "show");
function drawFilms($films){
echo "
<table class='alt'>
<thead>
@ -25,38 +27,47 @@
</thead>
<tbody>";
foreach($films as $f){
echo "
echo '
<tr>
<td>" . $f->getId() . "</td>
<td>" . $f->getTittle() . "</td>
<td>" . $f->getDuration() . "</td>
<td>". $f->getLanguage() . "</td>
<td>". $f->getDescription()."</td>
<td> <input type=submit name=\"submit\" value=\"Editar\" class=\"button\" formaction=\"./?state=edit_film&option=edit&id=". $f->getId()."\"/> </td>
<td> <input type=submit name=\"submit\" value=\"Borrar\" class=\"button\" formaction=\"./?state=validate&option=del&id=" . $f->getId()."\"/> </td>
</tr>";
<td>'. $f->getId() .'</td>
<td>'. $f->getTittle() .'</td>
<td>'. $f->getDuration() .'</td>
<td>'. $f->getLanguage() .'</td>
<td>'. $f->getDescription().'</td>
<td>
<form method="post" action="./index.php?state=ef">
<input name="id" type="hidden" value="'.$f->getId().'">
<input name="tittle" type="hidden" value="'.$f->getTittle().'">
<input name="duration" type="hidden" value="'.$f->getDuration().'">
<input name="language" type="hidden" value="'.$f->getLanguage().'">
<input name="description" type="hidden" value="'.$f->getDescription().'">
<input type="submit" id="submit" value="Editar" name="edit_film" class="primary" />
</form>
</td>
<td> <input type=submit name="submit" value="Borrar" class="button" formaction="delete_film.php"> </td>
</tr>';
}
echo "<tbody>
</table>\n";
echo'<tbody>
</table>';
}
function addFilm(){
echo'<div class="column size">
<h2>Añadir pelicula</h2>
<form method=\"post\" action="../panel_admin/validades.php">
<form method="post" action="add_film.php">
<div class="row">
<fieldset id="film_form">
<legend>Datos de pelicula</legend>
<div>
<input type="text" name="title" id="title" value="" placeholder="Título" />
<input type="text" name="tittle" id="tittle" placeholder="Título" />
</div>
<div>
<input type="number" name="duration" id="duration" value="" placeholder="Duración" />
<input type="number" name="duration" id="duration" placeholder="Duración" />
</div>
<div>
<input type="text" name="lenguage" id="language" value="" placeholder="Idioma" />
<input type="text" name="language" id="language" placeholder="Idioma" />
</div>
<div>
<input type="text" name="description" id="description" value="" placeholder="Descripción" />
<input type="text" name="description" id="description" placeholder="Descripción" />
</div>
</fieldset>
<div class="actions">
@ -65,11 +76,18 @@
</div>
</div>
</form>
</div>'."\n";
</div>';
}
drawFilms($bd->allFilmData());
function showmessage() {
if(isset($_SESSION['message'])){
echo '<div>
<h3>'.$_SESSION["message"].'</h3>
</div>';
unset($_SESSION['message']);
}
}
showmessage();
drawFilms($film->getReply());
addFilm();
?>

View File

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