Add files via upload
This commit is contained in:
38
panel_admin/includes/film.php
Normal file
38
panel_admin/includes/film.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
class Film{
|
||||
|
||||
//Attributes:
|
||||
private $_id; //Film ID.
|
||||
private $_tittle; //Film tittle.
|
||||
private $_duration; //Film duration.
|
||||
private $_language; //Film language.
|
||||
private $_description; //Film description.
|
||||
|
||||
|
||||
//Constructor:
|
||||
function __construct($id, $tittle, $duration, $language, $description){
|
||||
$this->_id = $id;
|
||||
$this->_tittle = $tittle;
|
||||
$this->_duration = $duration;
|
||||
$this->_language = $language;
|
||||
$this->_description = $description;
|
||||
}
|
||||
|
||||
//Methods:
|
||||
|
||||
//Getters && Setters:
|
||||
public function setId($id){ $this->_id = $id; }
|
||||
public function getId(){ return $this->_id; }
|
||||
public function setTittle($tittle) {$this->_tittle = $tittle; }
|
||||
public function getTittle(){return $this->_tittle;}
|
||||
public function setDuration($duration){$this->_duration = $duration; }
|
||||
public function getDuration() {return $this->_duration;}
|
||||
public function setLanguage($language) {$this->_language = $language; }
|
||||
public function getLanguage(){return $this->_language;}
|
||||
public function setDescription($description){ $this->_description = $description;}
|
||||
public function getDescription(){return $this->_description;}
|
||||
|
||||
|
||||
}
|
||||
?>
|
166
panel_admin/includes/formFilm.php
Normal file
166
panel_admin/includes/formFilm.php
Normal file
@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
include_once('../assets/php/config.php');
|
||||
include_once('../assets/php/common/film_dao.php');
|
||||
include_once('../assets/php/common/film.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;
|
||||
private $array;
|
||||
//Constructor:
|
||||
public function __construct() {
|
||||
parent::__construct('formFilm');
|
||||
$this->reply = array();
|
||||
}
|
||||
|
||||
public function getReply() {
|
||||
if($this->correct){
|
||||
if($this->option == "new"){
|
||||
$this->reply = "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
<div class='code info'>
|
||||
<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?state=mf'><button>Cerrar Mensaje</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class='column side'></div>
|
||||
</div>
|
||||
";
|
||||
}else if($this->option == "edit"){
|
||||
$this->reply = "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
<div class='code info'>
|
||||
<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?state=mf'><button>Cerrar Mensaje</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class='column side'></div>
|
||||
</div>
|
||||
";
|
||||
}else if($this->option == "del"){
|
||||
$this->reply = "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
<div class='code info'>
|
||||
<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?state=mf'><button>Cerrar Mensaje</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class='column side'></div>
|
||||
</div>
|
||||
";
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->reply = "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
<div class='code info'>
|
||||
<h1>ERROR</h1><hr />
|
||||
<p> Ha habido un error en la operacion. Revisa los datos introducidos</p>
|
||||
<a href='../panel_admin/index.php?state=mf'><button>Panel Admin</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class='column side'></div>
|
||||
</div>";
|
||||
|
||||
}
|
||||
return $this->reply;
|
||||
}
|
||||
|
||||
//Process form:
|
||||
public function processesForm($_id, $_tittle, $_duration, $_language, $_description, $_img, $_option) {
|
||||
$this->correct = true;
|
||||
$this->option = $_option;
|
||||
|
||||
$id= $this->test_input($_id);
|
||||
$tittle=$this->test_input($_tittle);
|
||||
$duration=$this->test_input($_duration);
|
||||
$language=$this->test_input($_language);
|
||||
$description=$this->test_input($_description);
|
||||
|
||||
//Validate promotional film image.
|
||||
$file_name = $_FILES['file']['name'];
|
||||
//$file_type = $_FILES['file']['type'];
|
||||
$file_size = $_FILES['file']['size'];
|
||||
if(isset($file_name) && $file_name != ""
|
||||
&& strpos($file_name, "jpg") && $file_size < 100000){
|
||||
$uploadFile = IMG_DIR . basename($_FILES['file'][$_tittle]);
|
||||
if (!move_uploaded_file($file_name, $uploadFile)){
|
||||
print_r($_FILES);
|
||||
}
|
||||
}
|
||||
else{
|
||||
$this->correct = false;
|
||||
}
|
||||
|
||||
//Habria que validar todo para que encaje en la base de datos
|
||||
|
||||
$bd = new Film_DAO('complucine');
|
||||
if($bd){
|
||||
if($this->option == "new"){
|
||||
//Primero comprobar si los campos no son vacios y la duracion es mayor que 0
|
||||
if(!empty($tittle)&&$duration>0&&!empty($language)&&!empty($description)){
|
||||
// comprobar si existe una pelicula con el mismo titulo e idioma
|
||||
$exist = $bd-> GetFilm($tittle,$language);
|
||||
if(mysqli_num_rows($exist) != 0){
|
||||
$this->correct =false;
|
||||
}
|
||||
else{
|
||||
$bd->createFilm(null, $tittle,$duration,$language,$description);
|
||||
|
||||
}
|
||||
$exist->free();
|
||||
}
|
||||
else{
|
||||
$this->correct =false;
|
||||
}
|
||||
} else if ($this->option == "del"){
|
||||
//Primero comprobar si existe una pelicula con el mismo id
|
||||
$exist = $bd-> FilmData($id);
|
||||
if( mysqli_num_rows($exist) == 1){
|
||||
$bd->deleteFilm($id);
|
||||
}
|
||||
else{
|
||||
$this->correct =false;
|
||||
}
|
||||
} else if ($this->option == "edit"){
|
||||
//Primero comprobar si los campos no son vacios y la duracion es mayor que 0
|
||||
if(!empty($tittle)&&$duration>0&&!empty($language)&&!empty($description)){
|
||||
//comprobar si existe una pelicula con el mismo id
|
||||
$exist = $bd-> FilmData($id);
|
||||
if( mysqli_num_rows($exist) == 1){
|
||||
$bd->editFilm($id,$tittle,$duration,$language,$description);
|
||||
}
|
||||
else{
|
||||
$this->correct =false;
|
||||
}
|
||||
$exist->free();
|
||||
}
|
||||
else{
|
||||
$this->correct =false;
|
||||
}
|
||||
}
|
||||
else {$this->correct = false;}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function test_input($input){
|
||||
return htmlspecialchars(trim(strip_tags($input)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
107
panel_admin/manage_films.php
Normal file
107
panel_admin/manage_films.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
//General Config File:
|
||||
include_once('../assets/php/config.php');
|
||||
include_once('./includes/formFilm.php');
|
||||
require_once($prefix.'assets/php/common/film_dao.php');
|
||||
|
||||
|
||||
// View functions
|
||||
function addFilm(){
|
||||
echo'<div class="column side"></div>
|
||||
<div class="column middle">
|
||||
<h2>Añadir pelicula</h2>
|
||||
<form method="post" enctype="multipart/form-data" action="index.php?state=mf">
|
||||
<div class="row">
|
||||
<fieldset id="film_form">
|
||||
<legend>Datos de pelicula</legend>
|
||||
<input type="text" name="tittle" id="tittle" placeholder="Título" />
|
||||
<input type="number" name="duration" id="duration" placeholder="Duración" />
|
||||
<input type="text" name="language" id="language" placeholder="Idioma" />
|
||||
<input type="text" name="description" id="description" placeholder="Descripción" />
|
||||
<div class="file">Imagen promocional:<input type="file" name="file" id="file" placeholder="Imagen promocional" /></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>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="column side"></div>
|
||||
';
|
||||
}
|
||||
function deleteFilm() {
|
||||
echo'<div class="column side"></div>
|
||||
<div class="column middle">
|
||||
<h2>Eliminar pelicula</h2>
|
||||
<form method="post" action="index.php?state=mf">
|
||||
<div class="row">
|
||||
<fieldset id="film_form">
|
||||
<legend>¿Estás seguro de que quieres eliminar esta pelicula?</legend>
|
||||
<input type="hidden" name="id" value='.$_POST['id'].'/>
|
||||
<p>Id: '.$_POST['id'].' </p>
|
||||
<p>Título: '.$_POST['tittle'].' </p>
|
||||
<p>Duración: '.$_POST['duration'].' </p>
|
||||
<p>Idioma: '.$_POST['language'].' </p>
|
||||
<p>Descripción: '.$_POST['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>
|
||||
<div class="column side"></div>
|
||||
';
|
||||
}
|
||||
function editFilm() {
|
||||
echo'<div class="column side"></div>
|
||||
<div class="column middle">
|
||||
<h2>Editar pelicula</h2>
|
||||
<form method="post" enctype="multipart/form-data" action="index.php?state=mf">
|
||||
<div class="row">
|
||||
<fieldset id="film_form">
|
||||
<legend>Datos de pelicula</legend>
|
||||
<input type="hidden" name="id" value='.$_POST['id'].'/>
|
||||
<input type="text" name="tittle" value="'.$_POST['tittle'].'" />
|
||||
<input type="number" name="duration" id="duration" value='.$_POST['duration'].' />
|
||||
<input type="text" name="language" id="language" value="'.$_POST['language'].'" />
|
||||
<input type="text" name="description" id="description" value="'.$_POST['description'].'"/>
|
||||
<div class="file">Imagen promocional:<input type="file" name="file" id="file" placeholder="Imagen promocional" /></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>
|
||||
<div class="column side"></div>
|
||||
';
|
||||
}
|
||||
|
||||
// Logic Functions
|
||||
function confirmDelete() {
|
||||
$film = new FormFilm();
|
||||
$film->processesForm($_POST['id'],null,null,null,null,null,"del");
|
||||
$_SESSION['message'] = $film->getReply();
|
||||
header('Location: ../panel_admin/index.php?state=mf');
|
||||
}
|
||||
function confirmEdit() {
|
||||
$film = new FormFilm();
|
||||
$film->processesForm($_POST['id'], $_POST['tittle'], $_POST['duration'], $_POST['language'], $_POST['description'], $_POST['file'], "edit");
|
||||
$_SESSION['message']= $film->getReply();
|
||||
header('Location: ../panel_admin/index.php?state=mf');
|
||||
}
|
||||
function confirmAdd() {
|
||||
$film = new FormFilm();
|
||||
$film->processesForm(null, $_POST['tittle'], $_POST['duration'], $_POST['language'], $_POST['description'], $_POST['file'], "new");
|
||||
$_SESSION['message'] = $film->getReply();
|
||||
header('Location: ../panel_admin/index.php?state=mf');
|
||||
}
|
||||
|
||||
|
||||
?>
|
@ -33,18 +33,24 @@
|
||||
|
||||
};
|
||||
break;
|
||||
case 'mf': if(isset($_POST['edit_film'])) {
|
||||
$this->editFilm();
|
||||
case 'mf': require_once('manage_films.php');
|
||||
if(isset($_POST['edit_film'])) {
|
||||
editFilm();
|
||||
}
|
||||
else if(isset($_POST['delete_film'])) {
|
||||
$this->deleteFilm();
|
||||
deleteFilm();
|
||||
}
|
||||
else if(isset($_POST['add_film'])) {
|
||||
$this->addFilm();
|
||||
$template->print_fimls();
|
||||
confirmAdd();
|
||||
}
|
||||
else if(isset($_POST['confirm_delete_film'])) {
|
||||
confirmDelete();
|
||||
}
|
||||
else if(isset($_POST['confirm_edit_film'])) {
|
||||
confirmEdit();
|
||||
}
|
||||
else {
|
||||
$this->addFilm();
|
||||
addFilm();
|
||||
$template->print_fimls();
|
||||
};
|
||||
break;
|
||||
@ -113,40 +119,6 @@
|
||||
function getTemplate(){
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
//Functions FILMS
|
||||
function addFilm(){
|
||||
include_once('./includes/formAddFilm.php');
|
||||
$formAF = new formAddFilm();
|
||||
$htmlAForm = $formAF->gestiona();
|
||||
echo '<!-- Add film -->
|
||||
<div class="column side"></div>
|
||||
<div class="column middle">
|
||||
'.$htmlAForm.'
|
||||
</div>'."\n";
|
||||
}
|
||||
|
||||
function deleteFilm() {
|
||||
include_once('./includes/formDeleteFilm.php');
|
||||
$formDF = new formDeleteFilm();
|
||||
$htmlDForm = $formDF->gestiona();
|
||||
echo '<!-- Add film -->
|
||||
<div class="column side"></div>
|
||||
<div class="column middle">
|
||||
'.$htmlDForm.'
|
||||
</div>'."\n";
|
||||
}
|
||||
function editFilm() {
|
||||
include_once('./includes/formEditFilm.php');
|
||||
$formEF = new formEditFilm();
|
||||
$htmlDForm = $formEF->gestiona();
|
||||
echo '<!-- Add film -->
|
||||
<div class="column side"></div>
|
||||
<div class="column middle">
|
||||
'.$htmlDForm.'
|
||||
</div>'."\n";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
Reference in New Issue
Block a user