This commit is contained in:
marian1010 2021-04-12 23:23:55 +02:00
parent d216398b3a
commit 50de669747
6 changed files with 292 additions and 73 deletions

40
panel_admin/edit_film.php Normal file
View File

@ -0,0 +1,40 @@
<?php
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";
}
}
?>

View File

@ -50,6 +50,28 @@
return $resul;
}*/
public function deleteFilm($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){
$sql = sprintf( "UPDATE film
SET title = '%s' , duration = '%d', lenguaje ='%s' ,`description` ='%s'
WHERE `film`.`id` = '%d';",
$title,$duration,$lenguaje, $description,$id );
$resul = mysqli_query($this->mysqli, $sql) or die ('Error into query database');
return $resul;
}
//Returns a query to get all films tittles.
public function tittleFilmData(){
$sql = sprintf( "SELECT tittle FROM film ");

View File

@ -0,0 +1,77 @@
<?php
include_once('film_dao.php');
include_once('../assets/php/form.php');
class FormFilm extends Form {
//Atributes:
private $correct; // Indicates if the session is correct.
private $reply; // Validation response
private $option;
//Constructor:
public function __construct() {
parent::__construct('formFilm');
$this->reply = array();
}
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>";
}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>";
}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>";
}
} 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>";
}
return $this->reply;
}
//Process 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 ) );
$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 {$this->correct = false;}
}
}
?>

View File

@ -1,73 +1,75 @@
<?php
require('./includes/film_dto.php');
require('./includes/film_dao.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","");
$f4 = new FilmDTO(4560,"Godzilla vs kong",113,"inglés","");
$f5 = new FilmDTO(4260,"Tom y Jerry",131,"inglés","");
$f6 = new FilmDTO(4606,"Pequeños Detalles",127,"inglés","");
$film= array($f1, $f2, $f3, $f4,$f5,$f6); */
$bd = new FilmDAO("complucine");
function drawFilms($films){
echo "
<table class='alt'>
<thead>
<tr>
<th>Id</th>
<th>Título</th>
<th>Duracion</th>
<th>Idioma</th>
<th>Descripcion</th>
</tr>
</thead>
<tbody>";
foreach($films as $f){
echo "
<tr>
<td>" . $f->getId() . "</td>
<td>" . $f->getTittle() . "</td>
<td>" . $f->getDuration() . "</td>
<td>". $f->getLanguage() . "</td>
<td>". $f->getDescription()."</td>
<td> <button type=\"button\">Editar</button> </td>
</tr>";
}
echo "<tbody>
</table>\n";
}
function addFilm(){
echo'<div class="column size">
<h2>Añadir pelicula</h2>
<form method="post" action="../panel_admin/manage_films/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" />
</div>
<div>
<input type="number" name="duration" id="duration" value="" placeholder="Duración" />
</div>
<div>
<input type="text" name="lenguage" id="language" value="" placeholder="Idioma" />
</div>
<div>
<input type="text" name="lenguage" id="description" value="" placeholder="Descripción" />
</div>
</fieldset>
<div class="actions">
<input type="submit" id="submit" value="Añadir pelicula" name="add_film" class="primary" />
<input type="reset" id="reset" value="Borrar" />
</div>
</div>
</form>
</div>'."\n";
}
drawFilms($bd->allFilmData());
addFilm();
?>
<?php
session_start();
require('./includes/film_dto.php');
require('./includes/film_dao.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","");
$f4 = new FilmDTO(4560,"Godzilla vs kong",113,"inglés","");
$f5 = new FilmDTO(4260,"Tom y Jerry",131,"inglés","");
$f6 = new FilmDTO(4606,"Pequeños Detalles",127,"inglés","");
$film= array($f1, $f2, $f3, $f4,$f5,$f6); */
$bd = new FilmDAO("complucine");
function drawFilms($films){
echo "
<table class='alt'>
<thead>
<tr>
<th>Id</th>
<th>Título</th>
<th>Duracion</th>
<th>Idioma</th>
<th>Descripcion</th>
</tr>
</thead>
<tbody>";
foreach($films as $f){
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>";
}
echo "<tbody>
</table>\n";
}
function addFilm(){
echo'<div class="column size">
<h2>Añadir pelicula</h2>
<form method=\"post\" action="../panel_admin/validades.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" />
</div>
<div>
<input type="number" name="duration" id="duration" value="" placeholder="Duración" />
</div>
<div>
<input type="text" name="lenguage" id="language" value="" placeholder="Idioma" />
</div>
<div>
<input type="text" name="description" id="description" value="" placeholder="Descripción" />
</div>
</fieldset>
<div class="actions">
<input type="submit" id="submit" value="Añadir pelicula" name="add_film" class="primary" />
<input type="reset" id="reset" value="Borrar" />
</div>
</div>
</form>
</div>'."\n";
}
drawFilms($bd->allFilmData());
addFilm();
?>

View File

@ -0,0 +1,12 @@
<?php
include_once('./includes/film_dto.php');
include_once('./includes/film_dao.php');
$bd = new FilmDAO("complucine");
//siempre accedemos a traves de los nombres de los formularios o div
if(isset($_REQUEST['delete_film'])) {
$bd->deleteFilm($_REQUEST['id']);
}
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>