diff --git a/panel_admin/includes/formAddPromotion.php b/panel_admin/includes/formAddPromotion.php
new file mode 100644
index 0000000..41599d7
--- /dev/null
+++ b/panel_admin/includes/formAddPromotion.php
@@ -0,0 +1,111 @@
+ "./?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 = '
+ ';
+
+ 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'] = "
+
+
+
+
Operacion realizada con exito
+
Se ha añadido la promocion correctamente en la base de datos.
+
+
+
+
+
+ ";
+ $result = './?state=mp';
+
+ }
+ $exist->free();
+ }
+ return $result;
+ }
+
+ protected function test_input($input){
+ return htmlspecialchars(trim(strip_tags($input)));
+ }
+
+
+}
+
+?>
\ No newline at end of file
diff --git a/panel_admin/includes/formDeletePromotion.php b/panel_admin/includes/formDeletePromotion.php
new file mode 100644
index 0000000..84d8704
--- /dev/null
+++ b/panel_admin/includes/formDeletePromotion.php
@@ -0,0 +1,94 @@
+ "./?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 = '
+
+
+
+
+
+
+ ';
+
+ 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'] = "
+
+
+
+
Operacion realizada con exito
+
Se ha eliminado la promocion correctamente en la base de datos.
+
+
+
+
+
+ ";
+ $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)));
+ }
+
+
+}
+
+?>
\ No newline at end of file
diff --git a/panel_admin/includes/formEditFilm.php b/panel_admin/includes/formEditFilm.php
index 2bde6cc..288d694 100644
--- a/panel_admin/includes/formEditFilm.php
+++ b/panel_admin/includes/formEditFilm.php
@@ -57,7 +57,7 @@ class formEditFilm extends Form{
$result = array();
$id = $this->test_input($_POST['id']) ?? null;
- if ( empty($id)) {
+ if ( is_null($id)) {
$result[] = "La pelicula seleccionada no existe.";
}
diff --git a/panel_admin/includes/formEditPromotion.php b/panel_admin/includes/formEditPromotion.php
new file mode 100644
index 0000000..21cba3f
--- /dev/null
+++ b/panel_admin/includes/formEditPromotion.php
@@ -0,0 +1,118 @@
+ "./?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 = '
+ ';
+
+ 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'] = "
+
+
+
+
Operacion realizada con exito
+
Se ha modificado la promocion correctamente en la base de datos.
+
+
+
+
+
+ ";
+ $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)));
+ }
+
+
+}
+
+?>
\ No newline at end of file
diff --git a/panel_admin/panelAdmin.php b/panel_admin/panelAdmin.php
index 6d35ad1..aae7736 100644
--- a/panel_admin/panelAdmin.php
+++ b/panel_admin/panelAdmin.php
@@ -44,23 +44,17 @@
break;
case 'mp': require_once('manage_promotions.php');
if(isset($_POST['edit_promotion'])) {
- editPromotion();
+ $this->editPromotion();
}
else if(isset($_POST['delete_promotion'])) {
- deletePromotion();
+ $this->deletePromotion();
}
else if(isset($_POST['add_promotion'])) {
- confirmAdd();
- }
- else if(isset($_POST['confirm_delete_promotion'])) {
- confirmDelete();
- }
- else if(isset($_POST['confirm_edit_promotion'])) {
- confirmEdit();
+ $this->addPromotion();
}
else {
- addPromotion();
- print_promotions();
+ $this->addPromotion();
+ $this->print_promotions();
};
break;
@@ -277,8 +271,114 @@
'."\n";
}
+ function addPromotion(){
+ include_once('./includes/formAddPromotion.php');
+ $formAP = new formAddPromotion();
+ $htmlAForm = $formAP->gestiona();
+ echo '
+
+
+
AÑADIR PROMOCIÓN
+ '.$htmlAForm.'
+ '."\n";
+ }
+ function editPromotion(){
+ include_once('./includes/formEditPromotion.php');
+ $formEP = new formEditPromotion();
+ $htmlEForm = $formEP->gestiona();
+ echo '
+
+
+
EDITAR PROMOCIÓN
+ '.$htmlEForm.'
+ '."\n";
+ }
-
+ function deletePromotion(){
+ include_once('./includes/formDeletePromotion.php');
+ $formDP = new formDeletePromotion();
+ $htmlDForm = $formDP->gestiona();
+ echo '
+
+
+
ELIMINAR PROMOCIÓN
+ '.$htmlDForm.'
+ '."\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 "
+
+
+
+
+
+ Id |
+ Título |
+ Descripcion |
+ Código |
+ Activo |
+
+
+
+ ";
+ if(is_array($promos)){
+ for($i = 0; $i < count($promos); $i++){
+ echo '
+ '. $ids[$i] .' |
+ '. $tittles[$i] .' |
+ '. $descriptions[$i] .' |
+ '. $codes[$i] .' |
+ '. $actives[$i] .' |
+
+
+ |
+
+
+ |
+
+ ';
+ }
+ }
+ echo'
+
+
+
+ ';
+
+ }
}
?>