2021-04-12 23:23:55 +02:00
|
|
|
<?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;
|
2021-04-13 13:50:23 +02:00
|
|
|
private $array;
|
2021-04-12 23:23:55 +02:00
|
|
|
//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>
|
2021-04-13 13:50:23 +02:00
|
|
|
<a href='../panel_admin/index.php?state=mf'><button>Cerrar Mensaje</button></a>";
|
2021-04-12 23:23:55 +02:00
|
|
|
}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>
|
2021-04-13 13:50:23 +02:00
|
|
|
<a href='../panel_admin/index.php?state=mf'><button>Cerrar Mensaje</button></a>";
|
2021-04-12 23:23:55 +02:00
|
|
|
}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>
|
2021-04-13 13:50:23 +02:00
|
|
|
<a href='../panel_admin/index.php?state=mf'><button>Cerrar Mensaje</button></a>";
|
|
|
|
} else if($this->option == "show"){
|
|
|
|
$this->reply= $this->array;
|
2021-04-12 23:23:55 +02:00
|
|
|
}
|
2021-04-13 13:50:23 +02:00
|
|
|
|
2021-04-12 23:23:55 +02:00
|
|
|
} else {
|
|
|
|
$this->reply = "<h1> ERROR </h1><hr />
|
|
|
|
<p> Ha habido un error en la operacion. Revisa los datos introducidos</p>
|
2021-04-13 13:50:23 +02:00
|
|
|
<a href='../panel_admin/index.php?state=mf'><button>Panel Admin</button></a>";
|
2021-04-12 23:23:55 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
return $this->reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Process form:
|
2021-04-14 12:39:32 +02:00
|
|
|
public function processesForm($id,$tittle,$duration,$language,$description, $option) {
|
|
|
|
$this->correct = true;
|
2021-04-12 23:23:55 +02:00
|
|
|
$this->option = $option;
|
2021-04-14 12:39:32 +02:00
|
|
|
|
2021-04-12 23:23:55 +02:00
|
|
|
//Habria que validar todo para que encaje en la base de datos
|
2021-04-14 12:39:32 +02:00
|
|
|
|
2021-04-13 21:49:29 +02:00
|
|
|
$bd = new Film_DAO('complucine');
|
2021-04-12 23:23:55 +02:00
|
|
|
if($bd ){
|
|
|
|
if($option == "new"){
|
2021-04-13 22:29:25 +02:00
|
|
|
//Primero comprobar si existe una pelicula con el mismo titulo e idioma
|
2021-04-14 12:39:32 +02:00
|
|
|
$exist = $bd-> GetFilm($tittle,$language);
|
|
|
|
if( mysqli_num_rows($exist) != 0){
|
|
|
|
$this->correct =false;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$bd->createFilm(null, $tittle,$duration,$language,$description);
|
|
|
|
}
|
2021-04-12 23:23:55 +02:00
|
|
|
} else if ($option == "del"){
|
2021-04-14 12:39:32 +02:00
|
|
|
//Primero comprobar si existe una pelicula con el mismo id
|
|
|
|
$exist = $bd-> FilmData($id);
|
|
|
|
if( mysqli_num_rows($exist) != 0){
|
|
|
|
$bd->deleteFilm($id);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$this->correct =false;
|
|
|
|
}
|
2021-04-12 23:23:55 +02:00
|
|
|
} else if ($option == "edit"){
|
2021-04-14 12:39:32 +02:00
|
|
|
//Primero comprobar si existe una pelicula con el mismo id
|
|
|
|
$exist = $bd-> FilmData($id);
|
|
|
|
if( mysqli_num_rows($exist) != 0){
|
|
|
|
$bd->editFilm($id,$tittle,$duration,$language,$description);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$this->correct =false;
|
|
|
|
}
|
2021-04-13 13:50:23 +02:00
|
|
|
} else if($this->option == "show") {
|
|
|
|
$this->array = $bd->allFilmData();
|
2021-04-12 23:23:55 +02:00
|
|
|
}
|
2021-04-14 18:32:12 +02:00
|
|
|
else {$this->correct = false;}
|
2021-04-14 12:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-04-12 23:23:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|