Promotion

This commit is contained in:
marian1010 2021-05-13 12:29:47 +02:00
parent 60d6bdbd36
commit 2a89128d0b
5 changed files with 436 additions and 13 deletions

View File

@ -0,0 +1,111 @@
<?php
//General Config File:
include_once('../assets/php/config.php');
include_once('../assets/php/common/promotion_dao.php');
include_once('../assets/php/common/promotion.php');
include_once('../assets/php/form.php');
class formAddPromotion extends Form{
//Constants:
public function __construct() {
$op = array("action" => "./?state=mp");
parent::__construct('formAddPromotion', $op);
}
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'));
$errorDescription = self::createMensajeError($errores, 'description', 'span', array('class' => 'error'));
$errorCode = self::createMensajeError($errores, 'code', 'span', array('class' => 'error'));
$errorActive = self::createMensajeError($errores, 'active', 'span', array('class' => 'error'));
//$errorImage = self::createMensajeError($errores, 'image', 'span', array('class' => 'error'));
$html = '<div class="row">
<fieldset id="promotion_form"><pre>'.$htmlErroresGlobales.'</pre>
<legend>AÑADIR PROMOCIÓN</legend>
<input type="text" name="tittle" id="tittle" placeholder="Título" required/><pre>'.$errorTittle.'</pre>
<input type="text" name="description" id="description" placeholder="Descripción" required/><pre>'.$errorDescription.'</pre>
<input type="text" name="code" id="code" placeholder="Codigo" required/><pre>'.$errorCode.'</pre>
<input type="text" name="active" id="active" placeholder="Activo" required/><pre>'.$errorActive.'</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 promocion" name="add_promotion" 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;
if ( empty($tittle) ) {
$result['tittle'] = "El título no es válido";
}
$description = $this->test_input($datos['description']) ?? null;
if ( empty($description)) {
$result['description'] = "La descripcion no es válida";
}
$code = $this->test_input($datos['code']) ?? null;
if ( empty($code) ) {
$result['code'] = "El idioma no es válido";
}
$active = $this->test_input($datos['active']) ?? null;
//|| !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $description)
if ( $active>1 ||$active<0 ) {
$result['active'] = "La descripcion no es válida";
}
if (count($result) === 0) {
$bd = new Pomotion_DAO("complucine");
//FALTARIA SUBIR LA IMAGEN
$exist = $bd-> GetPromotion($code);
if(mysqli_num_rows($exist) != 0){
$result[] = "Ya existe una nueva promocion con el mismo codigo.";
}
else{
$bd->createPromotion(null, $tittle,$description,$code,$active);
$_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 promocion correctamente en la base de datos.</p>
<a href='../panel_admin/index.php?state=mp'><button>Cerrar Mensaje</button></a>
</div>
</div>
<div class='column side'></div>
</div>
";
$result = './?state=mp';
}
$exist->free();
}
return $result;
}
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
}
?>

View File

@ -0,0 +1,94 @@
<?php
//General Config File:
include_once('../assets/php/config.php');
include_once('../assets/php/common/promotion_dao.php');
include_once('../assets/php/common/promotion.php');
include_once('../assets/php/form.php');
class formDeletePromotion extends Form{
//Constants:
public function __construct() {
$op = array("action" => "./?state=mp");
parent::__construct('formEditPromotion', $op);
}
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'));
//$errorDescription = self::createMensajeError($errores, 'description', 'span', array('class' => 'error'));
//$errorCode = self::createMensajeError($errores, 'code', 'span', array('class' => 'error'));
//$errorActive = self::createMensajeError($errores, 'active', 'span', array('class' => 'error'));
//$errorImage = self::createMensajeError($errores, 'image', 'span', array('class' => 'error'));
$html = '<div class="row">
<fieldset id= "promotion_form">
<legend>¿Estás seguro de que quieres eliminar esta promocion?</legend>
<input type="hidden" name="id" value='.$_POST['id'].'/>
<p>Id: '.$_POST['id'].' </p>
<p>Nombre: '.$_POST['tittle']'</p>
<p>Description:'.$_POST['description']'</p>
<p>Codigo: '.$_POST['code']'</p>
<p>Activa: '.$_POST['active']'</p>
<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="Eliminar" name="delete_promotion" class="primary" />
<input type="submit" id="submit" value="Cancelar" class="primary" />
</div>
</div>
</div>';
return $html;
}
protected function procesaFormulario($datos){
$result = array();
$id = $this->test_input($_POST['id']) ?? null;
if ( is_null($id)) {
$result[] = "La promoción seleccionada no existe.";
}
if (count($result) === 0) {
$bd = new Pomotion_DAO("complucine");
//FALTARIA SUBIR LA IMAGEN
$exist = $bd-> promotionData($id);
if(mysqli_num_rows($exist) == 1){
$bd->deletePromotion($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 promocion correctamente en la base de datos.</p>
<a href='../panel_admin/index.php?state=mp'><button>Cerrar Mensaje</button></a>
</div>
</div>
<div class='column side'></div>
</div>
";
$result = './?state=mp';
}
else{
$result[] = "La promocion seleccionada no existe.";
}
$exist->free();
}
return $result;
}
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
}
?>

View File

@ -57,7 +57,7 @@ class formEditFilm extends Form{
$result = array(); $result = array();
$id = $this->test_input($_POST['id']) ?? null; $id = $this->test_input($_POST['id']) ?? null;
if ( empty($id)) { if ( is_null($id)) {
$result[] = "La pelicula seleccionada no existe."; $result[] = "La pelicula seleccionada no existe.";
} }

View File

@ -0,0 +1,118 @@
<?php
//General Config File:
include_once('../assets/php/config.php');
include_once('../assets/php/common/promotion_dao.php');
include_once('../assets/php/common/promotion.php');
include_once('../assets/php/form.php');
class formEditPromotion extends Form{
//Constants:
public function __construct() {
$op = array("action" => "./?state=mp");
parent::__construct('formEditPromotion', $op);
}
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'));
$errorDescription = self::createMensajeError($errores, 'description', 'span', array('class' => 'error'));
$errorCode = self::createMensajeError($errores, 'code', 'span', array('class' => 'error'));
$errorActive = self::createMensajeError($errores, 'active', 'span', array('class' => 'error'));
//$errorImage = self::createMensajeError($errores, 'image', 'span', array('class' => 'error'));
$html = '<div class="row">
<fieldset id="promotion_form"><pre>'.$htmlErroresGlobales.'</pre>
<fieldset id="film_form">
<legend>Datos de promocion</legend>
<input type="hidden" name="id" value='.$_POST['id'].'/>
<input type="text" name="tittle" id="tittle"value="'.$_POST['tittle'].'"required/><pre>'.$errorTittle.'</pre>
<input type="text" name="description" id="description" value="'.$_POST['description'].'" required/><pre>'.$errorDescription.'</pre>
<input type="text" name="code" id="code" value="'.$_POST['code'].'" required/><pre>'.$errorCode.'</pre>
<input type="text" name="active" id="active" value="'.$_POST['active'].'"required/><pre>'.$errorActive.'</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 promocion" name="edit_promotion" class="primary" />
<input type="reset" id="reset" value="Borrar" />
</div>
</div>
</div>';
return $html;
}
protected function procesaFormulario($datos){
$result = array();
$id = $this->test_input($_POST['id']) ?? null;
if ( is_null($id)) {
$result[] = "La promoción seleccionada no existe.";
}
$tittle = $this->test_input($datos['tittle']) ?? null;
if ( empty($tittle) ) {
$result['tittle'] = "El título no es válido";
}
$description = $this->test_input($datos['description']) ?? null;
if ( empty($description)) {
$result['description'] = "La descripcion no es válida";
}
$code = $this->test_input($datos['code']) ?? null;
if ( empty($code) ) {
$result['code'] = "El idioma no es válido";
}
$active = $this->test_input($datos['active']) ?? null;
//|| !mb_ereg_match(self::HTML5_EMAIL_REGEXP, $description)
if ( $active>1 ||$active<0 ) {
$result['active'] = "La descripcion no es válida";
}
if (count($result) === 0) {
$bd = new Pomotion_DAO("complucine");
//FALTARIA SUBIR LA IMAGEN
$exist = $bd-> promotionData($id);
if(mysqli_num_rows($exist) == 1){
$bd->editPromotion($id, $tittle,$description,$code,$active);
$_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 modificado la promocion correctamente en la base de datos.</p>
<a href='../panel_admin/index.php?state=mp'><button>Cerrar Mensaje</button></a>
</div>
</div>
<div class='column side'></div>
</div>
";
$result = './?state=mp';
}
else{
$result[] = "La promocion seleccionada no existe.";
}
$exist->free();
}
return $result;
}
protected function test_input($input){
return htmlspecialchars(trim(strip_tags($input)));
}
}
?>

View File

@ -44,23 +44,17 @@
break; break;
case 'mp': require_once('manage_promotions.php'); case 'mp': require_once('manage_promotions.php');
if(isset($_POST['edit_promotion'])) { if(isset($_POST['edit_promotion'])) {
editPromotion(); $this->editPromotion();
} }
else if(isset($_POST['delete_promotion'])) { else if(isset($_POST['delete_promotion'])) {
deletePromotion(); $this->deletePromotion();
} }
else if(isset($_POST['add_promotion'])) { else if(isset($_POST['add_promotion'])) {
confirmAdd(); $this->addPromotion();
}
else if(isset($_POST['confirm_delete_promotion'])) {
confirmDelete();
}
else if(isset($_POST['confirm_edit_promotion'])) {
confirmEdit();
} }
else { else {
addPromotion(); $this->addPromotion();
print_promotions(); $this->print_promotions();
}; };
break; break;
@ -277,8 +271,114 @@
</div>'."\n"; </div>'."\n";
} }
function addPromotion(){
include_once('./includes/formAddPromotion.php');
$formAP = new formAddPromotion();
$htmlAForm = $formAP->gestiona();
echo '<!-- ADD PROMOTION -->
<div class="column side"></div>
<div class="column middle">
<h3>AÑADIR PROMOCIÓN</h3>
'.$htmlAForm.'
</div>'."\n";
}
function editPromotion(){
include_once('./includes/formEditPromotion.php');
$formEP = new formEditPromotion();
$htmlEForm = $formEP->gestiona();
echo '<!-- EDIT MANAGER -->
<div class="column side"></div>
<div class="column middle">
<h3>EDITAR PROMOCIÓN</h3>
'.$htmlEForm.'
</div>'."\n";
}
function deletePromotion(){
include_once('./includes/formDeletePromotion.php');
$formDP = new formDeletePromotion();
$htmlDForm = $formDP->gestiona();
echo '<!-- DELETE MANAGER -->
<div class="column side"></div>
<div class="column middle">
<h3>ELIMINAR PROMOCIÓN</h3>
'.$htmlDForm.'
</div>'."\n";
}
function print_promotions(){
$promo = new Promotion_DAO("complucine");
$promos = $promo->allPromotionData();
$ids = array();
$tittles = array();
$descriptions = array();
$codes = array();
$actives = array();
if(is_array($promos)){
foreach($promos as $key => $value){
$ids[$key] = $value->getId();
$tittles[$key] = $value->getTittle();
$descriptions[$key] = $value->getDescription();
$codes[$key] = $value->getCode();
$actives[$key] = $value->getActive();
}
}
echo "<div class='row'>
<div class='column side'></div>
<div class='column middle'>
<table class='alt'>
<thead>
<tr>
<th>Id</th>
<th>Título</th>
<th>Descripcion</th>
<th>Código</th>
<th>Activo</th>
</tr>
</thead>
<tbody>
";
if(is_array($promos)){
for($i = 0; $i < count($promos); $i++){
echo '<tr>
<td>'. $ids[$i] .'</td>
<td>'. $tittles[$i] .'</td>
<td>'. $descriptions[$i] .'</td>
<td>'. $codes[$i] .'</td>
<td>'. $actives[$i] .'</td>
<td>
<form method="post" action="index.php?state=mp">
<input name="id" type="hidden" value="'.$ids[$i].'">
<input name="tittle" type="hidden" value="'.$tittles[$i].'">
<input name="description" type="hidden" value="'.$descriptions[$i].'">
<input name="code" type="hidden" value="'.$codes[$i].'">
<input name="active" type="hidden" value="'.$actives[$i].'">
<input type="submit" id="submit" value="Editar" name="edit_promotion" class="primary" />
</form>
</td>
<td>
<form method="post" action="index.php?state=mp">
<input name="id" type="hidden" value="'.$ids[$i].'">
<input name="tittle" type="hidden" value="'.$tittles[$i].'">
<input name="description" type="hidden" value="'.$descriptions[$i].'">
<input name="code" type="hidden" value="'.$codes[$i].'">
<input name="active" type="hidden" value="'.$actives[$i].'">
<input type="submit" id="submit" value="Eliminar" name="delete_promotion" class="primary" />
</form>
</td>
</tr>
';
}
}
echo'</tbody>
</table>
</div>
<div class="column side"></div>
';
}
} }
?> ?>