Forms restructuring
This commit is contained in:
parent
4c7c93d691
commit
657d1cc0fe
111
panel_admin/includes/formAddFilm.php
Normal file
111
panel_admin/includes/formAddFilm.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
//General Config File:
|
||||
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 formAddFilm extends Form{
|
||||
//Constants:
|
||||
const HTML5_EMAIL_REGEXP = '^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$';
|
||||
|
||||
public function __construct() {
|
||||
$options = array("action" => "./?state=mf");
|
||||
parent::__construct('formAddFilm', $options);
|
||||
}
|
||||
|
||||
protected function generaCamposFormulario($datos, $errores = array()){
|
||||
|
||||
|
||||
// Se generan los mensajes de error si existen.
|
||||
$htmlErroresGlobales = self::generaListaErroresGlobales($errores);
|
||||
$errorTittle = self::createMensajeError($errores, 'tittle', 'span', array('class' => 'error'));
|
||||
$errorDuration = self::createMensajeError($errores, 'duration', 'span', array('class' => 'error'));
|
||||
$errorLanguage = self::createMensajeError($errores, 'language', 'span', array('class' => 'error'));
|
||||
$errorDescription = self::createMensajeError($errores, 'description', 'span', array('class' => 'error'));
|
||||
//$errorImage = self::createMensajeError($errores, 'image', 'span', array('class' => 'error'));
|
||||
|
||||
$html = '<div class="row">
|
||||
<fieldset id="film_form"><pre>'.$htmlErroresGlobales.'</pre>
|
||||
<legend>AÑADIR PELÍCULA</legend>
|
||||
<input type="text" name="tittle" id="tittle" placeholder="Título" required/><pre>'.$errorTittle.'</pre>
|
||||
<input type="number" name="duration" id="duration" placeholder="Duración" required/><pre>'.$errorDuration.'</pre>
|
||||
<input type="text" name="language" id="language" placeholder="Idioma" required/><pre>'.$errorLanguage.'</pre>
|
||||
<input type="text" name="description" id="description" placeholder="Descripción" required/><pre>'.$errorDescription.'</pre>
|
||||
<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>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
protected function procesaFormulario($datos){
|
||||
$result = array();
|
||||
|
||||
$tittle = $this->test_input($datos['tittle']) ?? null;
|
||||
//|| !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $tittle)
|
||||
if ( empty($tittle) ) {
|
||||
$result['tittle'] = "El título no es válido";
|
||||
}
|
||||
|
||||
$duration = $this->test_input($datos['duration']) ?? null;
|
||||
//||!mb_ereg_match(self::HTML5_EMAIL_REGEXP, $duration)
|
||||
if ( empty($duration) || $duration <0) {
|
||||
$result['duration'] = "La duración no es válida";
|
||||
}
|
||||
|
||||
$language = $this->test_input($datos['language']) ?? null;
|
||||
//|| !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $language)
|
||||
if ( empty($language) ) {
|
||||
$result['language'] = "El idioma no es válido";
|
||||
}
|
||||
|
||||
$description = $this->test_input($datos['description']) ?? null;
|
||||
//|| !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $description)
|
||||
if ( empty($language)) {
|
||||
$result['language'] = "La descripcion no es válida";
|
||||
}
|
||||
|
||||
if (count($result) === 0) {
|
||||
$bd = new Film_DAO("complucine");
|
||||
|
||||
//FALTARIA SUBIR LA IMAGEN
|
||||
$exist = $bd-> GetFilm($tittle,$language);
|
||||
if(mysqli_num_rows($exist) != 0){
|
||||
$result[] = "Ya existe una nueva pelicula con el mismo titulo e idioma.";
|
||||
}
|
||||
else{
|
||||
$bd->createFilm(null, $tittle,$duration,$language,$description);
|
||||
$_SESSION['message'] = "<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>
|
||||
";
|
||||
$result = './?state=mf';
|
||||
|
||||
}
|
||||
$exist->free();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function test_input($input){
|
||||
return htmlspecialchars(trim(strip_tags($input)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
89
panel_admin/includes/formDeleteFilm.php
Normal file
89
panel_admin/includes/formDeleteFilm.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
//General Config File:
|
||||
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 formDeleteFilm extends Form{
|
||||
//Constants:
|
||||
const HTML5_EMAIL_REGEXP = '^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$';
|
||||
|
||||
public function __construct() {
|
||||
$options = array("action" => "./?state=mf");
|
||||
parent::__construct('formDeleteFilm', $options);
|
||||
}
|
||||
|
||||
protected function generaCamposFormulario($datos, $errores = array()){
|
||||
|
||||
|
||||
// Se generan los mensajes de error si existen.
|
||||
$htmlErroresGlobales = self::generaListaErroresGlobales($errores);
|
||||
//$errorTittle = self::createMensajeError($errores, 'tittle', 'span', array('class' => 'error'));
|
||||
//$errorDuration = self::createMensajeError($errores, 'duration', 'span', array('class' => 'error'));
|
||||
//$errorLanguage = self::createMensajeError($errores, 'language', 'span', array('class' => 'error'));
|
||||
//$errorDescription = self::createMensajeError($errores, 'description', 'span', array('class' => 'error'));
|
||||
//$errorImage = self::createMensajeError($errores, 'image', 'span', array('class' => 'error'));
|
||||
|
||||
$html = '<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="delete_film" class="primary" />
|
||||
<input type="submit" id="submit" value="Cancelar" class="primary" />
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
protected function procesaFormulario($datos){
|
||||
$result = array();
|
||||
$id = $this->test_input($_POST['id']) ?? null;
|
||||
if ( empty($id)) {
|
||||
$result[] = "La pelicula seleccionada no existe.";
|
||||
}
|
||||
|
||||
if (count($result) === 0) {
|
||||
$bd = new Film_DAO("complucine");
|
||||
$exist = $bd-> FilmData($id);
|
||||
if( mysqli_num_rows($exist) == 1){
|
||||
$bd->deleteFilm($id);
|
||||
$_SESSION['message'] = "<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>
|
||||
";
|
||||
$result = './?state=mf';
|
||||
}
|
||||
else{
|
||||
$result[] = "La pelicula seleccionada no existe.";
|
||||
}
|
||||
|
||||
$exist->free();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function test_input($input){
|
||||
return htmlspecialchars(trim(strip_tags($input)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
123
panel_admin/includes/formEditFilm.php
Normal file
123
panel_admin/includes/formEditFilm.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
//General Config File:
|
||||
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 formEditFilm extends Form{
|
||||
//Constants:
|
||||
const HTML5_EMAIL_REGEXP = '^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$';
|
||||
|
||||
public function __construct() {
|
||||
$options = array("action" => "./?state=mf");
|
||||
parent::__construct('formEditFilm', $options);
|
||||
}
|
||||
|
||||
protected function generaCamposFormulario($datos, $errores = array()){
|
||||
|
||||
|
||||
// Se generan los mensajes de error si existen.
|
||||
$htmlErroresGlobales = self::generaListaErroresGlobales($errores);
|
||||
$errorTittle = self::createMensajeError($errores, 'tittle', 'span', array('class' => 'error'));
|
||||
$errorDuration = self::createMensajeError($errores, 'duration', 'span', array('class' => 'error'));
|
||||
$errorLanguage = self::createMensajeError($errores, 'language', 'span', array('class' => 'error'));
|
||||
$errorDescription = self::createMensajeError($errores, 'description', 'span', array('class' => 'error'));
|
||||
$errorImage = self::createMensajeError($errores, 'image', 'span', array('class' => 'error'));
|
||||
|
||||
$html = '<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'].' required/><pre>'.$errorTittle.'</pre>
|
||||
<input type="number" name="duration" id="duration" value='.$_POST['duration'].' required/><pre>'.$errorDuration.'</pre>
|
||||
<input type="text" name="language" id="language" value="'.$_POST['language'].'" required/><pre>'.$errorLanguage.'</pre>
|
||||
<input type="text" name="description" id="description" value="'.$_POST['description'].'"required/><pre>'.$errorDescription.'</pre>
|
||||
<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="edit_film" class="primary" />
|
||||
<input type="reset" id="reset" value="Borrar" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="column side"></div>
|
||||
';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
protected function procesaFormulario($datos){
|
||||
$result = array();
|
||||
|
||||
$id = $this->test_input($_POST['id']) ?? null;
|
||||
if ( empty($id)) {
|
||||
$result[] = "La pelicula seleccionada no existe.";
|
||||
}
|
||||
|
||||
$tittle = $this->test_input($datos['tittle']) ?? null;
|
||||
//|| !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $tittle)
|
||||
if ( empty($tittle) ) {
|
||||
$result['tittle'] = "El título no es válido";
|
||||
}
|
||||
|
||||
$duration = $this->test_input($datos['duration']) ?? null;
|
||||
//||!mb_ereg_match(self::HTML5_EMAIL_REGEXP, $duration)
|
||||
if ( empty($duration) || $duration <0) {
|
||||
$result['duration'] = "La duración no es válida";
|
||||
}
|
||||
|
||||
$language = $this->test_input($datos['language']) ?? null;
|
||||
//|| !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $language)
|
||||
if ( empty($language) ) {
|
||||
$result['language'] = "El idioma no es válido";
|
||||
}
|
||||
|
||||
$description = $this->test_input($datos['description']) ?? null;
|
||||
//|| !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $description)
|
||||
if ( empty($language)) {
|
||||
$result['language'] = "La descripcion no es válida";
|
||||
}
|
||||
|
||||
|
||||
if (count($result) === 0) {
|
||||
$bd = new Film_DAO("complucine");
|
||||
$exist = $bd-> FilmData($id);
|
||||
if( mysqli_num_rows($exist) == 1){
|
||||
$bd->editFilm($id,$tittle,$duration,$language,$description);
|
||||
$_SESSION['message'] = "<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>
|
||||
";
|
||||
$result = './?state=mf';
|
||||
}
|
||||
else{
|
||||
$result[] = "La pelicula seleccionada no existe.";
|
||||
}
|
||||
$exist->free();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function test_input($input){
|
||||
return htmlspecialchars(trim(strip_tags($input)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -90,7 +90,7 @@ class FormManager extends Form {
|
||||
if($bd){
|
||||
if($this->option == "new"){
|
||||
//Check if any var is empty
|
||||
if(!is_null($id)&&!is_null($idcinema)){
|
||||
if(!is_null($id)&&!empty($idcinema)){
|
||||
// check if already exist a manager with same name
|
||||
$exist = $bd->GetManagerCinema($id, $idcinema);
|
||||
if( mysqli_num_rows($exist) != 0){
|
||||
|
@ -21,16 +21,16 @@
|
||||
$usernames = array();
|
||||
$email = array();
|
||||
$rol = array();
|
||||
if(is_array($managers)){
|
||||
foreach($managers as $key => $value){
|
||||
$ids[$key] = $value->getId();
|
||||
$idscinemas[$key] = $value->getIdcinema();
|
||||
$usernames[$key] = $value->getUsername();
|
||||
$email[$key] = $value->getEmail();
|
||||
$rol[$key] = $value->getRoll();
|
||||
}
|
||||
|
||||
foreach($managers as $key => $value){
|
||||
$ids[$key] = $value->getId();
|
||||
$idscinemas[$key] = $value->getIdcinema();
|
||||
$usernames[$key] = $value->getUsername();
|
||||
$email[$key] = $value->getEmail();
|
||||
$rol[$key] = $value->getRoll();
|
||||
}
|
||||
|
||||
|
||||
echo "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
@ -47,37 +47,35 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
";
|
||||
if(is_array($managers)){
|
||||
for($i = 0; $i < count($managers); $i++){
|
||||
echo '<tr>
|
||||
<td>'. $ids[$i] .'</td>
|
||||
<td>'. $idscinemas[$i] .'</td>
|
||||
<td>'. $usernames[$i] .'</td>
|
||||
<td>'. $email[$i] .'</td>
|
||||
<td>'. $rol[$i] .'</td>
|
||||
<td>
|
||||
<form method="post" action="index.php?state=mg">
|
||||
<input name="id" type="hidden" value="'.$ids[$i].'">
|
||||
<input name="idcinema" type="hidden" value="'.$idscinemas[$i].'">
|
||||
<input name="username" type="hidden" value="'.$usernames[$i].'">
|
||||
<input name="email" type="hidden" value="'.$email[$i].'">
|
||||
<input name="rol" type="hidden" value="'.$rol[$i].'">
|
||||
<input type="submit" id="submit" value="Editar" name="edit_manager" class="primary" />
|
||||
</form>
|
||||
</td>
|
||||
<td>
|
||||
<form method="post" action="index.php?state=mg">
|
||||
<input name="id" type="hidden" value="'.$ids[$i].'">
|
||||
<input name="idcinema" type="hidden" value="'.$idscinemas[$i].'">
|
||||
<input name="username" type="hidden" value="'.$usernames[$i].'">
|
||||
<input name="email" type="hidden" value="'.$email[$i].'">
|
||||
<input name="rol" type="hidden" value="'.$rol[$i].'">
|
||||
<input type="submit" id="submit" value="Eliminar" name="delete_manager" class="primary" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
';
|
||||
}
|
||||
for($i = 0; $i < count($managers); $i++){
|
||||
echo '<tr>
|
||||
<td>'. $ids[$i] .'</td>
|
||||
<td>'. $idscinemas[$i] .'</td>
|
||||
<td>'. $usernames[$i] .'</td>
|
||||
<td>'. $email[$i] .'</td>
|
||||
<td>'. $rol[$i] .'</td>
|
||||
<td>
|
||||
<form method="post" action="index.php?state=mg">
|
||||
<input name="id" type="hidden" value="'.$ids[$i].'">
|
||||
<input name="idcinema" type="hidden" value="'.$idscinemas[$i].'">
|
||||
<input name="username" type="hidden" value="'.$usernames[$i].'">
|
||||
<input name="email" type="hidden" value="'.$email[$i].'">
|
||||
<input name="rol" type="hidden" value="'.$rol[$i].'">
|
||||
<input type="submit" id="submit" value="Editar" name="edit_manager" class="primary" />
|
||||
</form>
|
||||
</td>
|
||||
<td>
|
||||
<form method="post" action="index.php?state=mg">
|
||||
<input name="id" type="hidden" value="'.$ids[$i].'">
|
||||
<input name="idcinema" type="hidden" value="'.$idscinemas[$i].'">
|
||||
<input name="username" type="hidden" value="'.$usernames[$i].'">
|
||||
<input name="email" type="hidden" value="'.$email[$i].'">
|
||||
<input name="rol" type="hidden" value="'.$rol[$i].'">
|
||||
<input type="submit" id="submit" value="Eliminar" name="delete_manager" class="primary" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
';
|
||||
}
|
||||
echo'</tbody>
|
||||
</table>
|
||||
|
@ -33,24 +33,18 @@
|
||||
|
||||
};
|
||||
break;
|
||||
case 'mf': require_once('manage_films.php');
|
||||
if(isset($_POST['edit_film'])) {
|
||||
editFilm();
|
||||
case 'mf': if(isset($_POST['edit_film'])) {
|
||||
$this->editFilm();
|
||||
}
|
||||
else if(isset($_POST['delete_film'])) {
|
||||
deleteFilm();
|
||||
$this->deleteFilm();
|
||||
}
|
||||
else if(isset($_POST['add_film'])) {
|
||||
confirmAdd();
|
||||
}
|
||||
else if(isset($_POST['confirm_delete_film'])) {
|
||||
confirmDelete();
|
||||
}
|
||||
else if(isset($_POST['confirm_edit_film'])) {
|
||||
confirmEdit();
|
||||
$this->addFilm();
|
||||
$template->print_fimls();
|
||||
}
|
||||
else {
|
||||
addFilm();
|
||||
$this->addFilm();
|
||||
$template->print_fimls();
|
||||
};
|
||||
break;
|
||||
@ -119,6 +113,40 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user