This commit is contained in:
marian1010 2021-05-13 12:31:06 +02:00
parent 2a89128d0b
commit 2b99c192b7
4 changed files with 0 additions and 604 deletions

View File

@ -1,147 +0,0 @@
<?php
include_once('../assets/php/config.php');
include_once('../assets/php/common/cinema_dao.php');
include_once('../assets/php/common/cinema.php');
include_once('../assets/php/form.php');
class FormCinema 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('formCinema');
$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 el cine correctamente en la base de datos.</p>
<a href='../panel_admin/index.php?state=mc'><button>Cerrar Mensaje</button></a>
</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 el cine correctamente en la base de datos.</p>
<a href='../panel_admin/index.php?state=mc'><button>Cerrar Mensaje</button></a>
</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 el cine correctamente en la base de datos.</p>
<a href='../panel_admin/index.php?state=mc'><button>Cerrar Mensaje</button></a>
</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=mc'><button>Panel Admin</button></a>
</div>
<div class='column side'></div>
</div>
";
}
return $this->reply;
}
//Process form:
public function processesForm($_id, $_name, $_direction, $_phone, $_option) {
$this->correct = true;
$this->option = $_option;
$id= $this->test_input($_id);
$name=$this->test_input($_name);
$direction=$this->test_input($_direction);
$phone=$this->test_input($_phone);
//Habria que validar todo para que encaje en la base de datos
$bd = new Cinema_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($name)&&!empty($direction)&&!empty($phone)){
// comprobar si existe una pelicula con el mismo nombre y direccion
$exist = $bd->GetCinema($name,$direction);
if( mysqli_num_rows($exist) != 0){
$this->correct =false;
}
else{
$bd->createCinema(null, $name, $direction, $phone);
}
$exist->free();
}
else{
$this->correct =false;
}
} else if ($this->option == "del"){
//Primero comprobar si existe una pelicula con el mismo id
$exist = $bd-> CinemaData($id);
if( mysqli_num_rows($exist) == 1){
$bd->deleteCinema($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($name)&&!empty($direction)&&!empty($phone)){
//comprobar si existe una pelicula con el mismo id
$exist = $bd-> CinemaData($id);
if( mysqli_num_rows($exist) == 1){
$bd->editCinema($id,$name,$direction,$phone);
}
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)));
}
}
?>

View File

@ -1,148 +0,0 @@
<?php
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 FormPromotion extends Form {
//Atributes:
private $correct; // Indicates if the session is correct.
private $reply; // Validation response
private $option;
//Constructor:
public function __construct() {
parent::__construct('formCinema');
$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 promoción correctamente en la base de datos.</p>
<a href='../panel_admin/index.php?state=mp'><button>Cerrar Mensaje</button></a>
</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 promoción correctamente en la base de datos.</p>
<a href='../panel_admin/index.php?state=mp'><button>Cerrar Mensaje</button></a>
</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 promoción correctamente en la base de datos.</p>
<a href='../panel_admin/index.php?state=mp'><button>Cerrar Mensaje</button></a>
</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=mp'><button>Panel Admin</button></a>
</div>
<div class='column side'></div>
</div>
";
}
return $this->reply;
}
//Process form:
public function processesForm($_id, $_tittle, $_description, $_code, $_active, $_option) {
$this->correct = true;
$this->option = $_option;
$id= $this->test_input($_id);
$tittle=$this->test_input($_tittle);
$description=$this->test_input($_description);
$code=$this->test_input($_code);
$active=$this->test_input($_active);
//Habria que validar todo para que encaje en la base de datos
$bd = new Promotion_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)&&!empty($description)&&!empty($code)&&!empty($active)){
// comprobar si existe una pelicula con el mismo nombre y direccion
$exist = $bd->GetPromotion($code);
if( mysqli_num_rows($exist) != 0){
$this->correct =false;
}
else{
$bd->createPromotion(null, $tittle, $description, $code, $active);
}
$exist->free();
}
else{
$this->correct =false;
}
} else if ($this->option == "del"){
//Primero comprobar si existe una pelicula con el mismo id
$exist = $bd-> PromotionData($id);
if( mysqli_num_rows($exist) == 1){
$bd->deletePromotion($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)&&!empty($description)&&!empty($code)&&!empty($active)){
//comprobar si existe una pelicula con el mismo id
$exist = $bd-> PromotionData($id);
if( mysqli_num_rows($exist) == 1){
$bd->editPromotion($id, $tittle, $description, $code, $active);
}
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)));
}
}
?>

View File

@ -1,114 +0,0 @@
<?php
//General Config File:
include_once('../assets/php/config.php');
include_once('../assets/php/common/cinema.php');
include_once(__DIR__.'/includes/formCinema.php');
// View functions
function addCinema(){
echo' <div class="column side"></div>
<div class="column middle">
<h2>Añadir cine</h2>
<form method="post" action="index.php?state=mc">
<fieldset id="cinema_form">
<legend>Datos del Cine</legend>
<div>
<input type="text" name="name" id="name" placeholder="Nombre" />
</div>
<div>
<input type="text" name="direction" id="direction" placeholder="Direccion" />
</div>
<div>
<input type="text" name="phone" id="phone" placeholder="Teléfono" />
</div>
</fieldset>
<div class="actions">
<input type="submit" id="submit" value="Añadir cine" name="add_cinema" class="primary" />
<input type="reset" id="reset" value="Borrar" />
</div>
</form>
</div>
<div class="column side"></div>
</div>
';
}
function deleteCinema() {
echo'<div class="column side"></div>
<div class="column middle">
<h2>Editar cine</h2>
<form method="post" action="index.php?state=mc">
<div class="row">
<fieldset id="cinema_form">
<legend>¿Estás seguro de que quieres eliminar este cine?</legend>
<input type="hidden" name="id" value='.$_POST['id'].'/>
<p>Id: '.$_POST['id'].' </p>
<p>Nombre: '.$_POST['name'].' </p>
<p>Dirección: '.$_POST['direction'].' </p>
<p>Teléfono: '.$_POST['phone'].' </p>
</fieldset>
<div class="actions">
<input type="submit" id="submit" value="Eliminar" name="confirm_delete_cinema" class="primary" />
<input type="submit" id="submit" value="Cancelar" name="cancel_delete_cinema" class="primary" />
</div>
</div>
</form>
</div>
<div class="column side"></div>
';
}
function editCinema() {
echo'<div class="column side"></div>
<div class="column middle">
<h2>Editar cine</h2>
<form method="post" action="index.php?state=mc">
<div class="row">
<fieldset id="cinema_form">
<legend>Datos del cine</legend>
<input type="hidden" name="id" value='.$_POST['id'].'/>
<div>
<input type="text" name="name" value="'.$_POST['name'].'" />
</div>
<div>
<input type="text" name="direction" value='.$_POST['direction'].' />
</div>
<div>
<input type="text" name="phone" value='.$_POST['phone'].' />
</div>
</fieldset>
<div class="actions">
<input type="submit" id="submit" value="Editar" name="confirm_edit_cinema" class="primary" />
<input type="reset" id="reset" value="Borrar" />
</div>
</div>
</form>
</div>
<div class="column side"></div>
';
}
// Logic Functions
function confirmDelete() {
$cine = new FormCinema();
$cine->processesForm($_POST['id'],null,null,null,"del");
$_SESSION['message'] = $cine->getReply();
header('Location: ../panel_admin/index.php?state=mc');
}
function confirmEdit() {
$cine = new FormCinema();
$cine->processesForm($_POST['id'], $_POST['name'], $_POST['direction'], $_POST['phone'],"edit");
$_SESSION['message']= $cine->getReply();
header('Location: ../panel_admin/index.php?state=mc');
}
function confirmAdd() {
$cine = new FormCinema();
$cine->processesForm(null, $_POST['name'], $_POST['direction'], $_POST['phone'],"new");
$_SESSION['message'] = $cine->getReply();
header('Location: ../panel_admin/index.php?state=mc');
}
?>

View File

@ -1,195 +0,0 @@
<?php
//General Config File:
include_once('../assets/php/config.php');
include_once('../assets/php/common/promotion.php');
include_once(__DIR__.'/includes/formPromotion.php');
// View functions
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>
';
}
function addPromotion(){
echo' <div class="column side"></div>
<div class="column middle">
<h2>Añadir promoción</h2>
<form method="post" action="index.php?state=mp">
<fieldset id="promotion_form">
<legend>Datos dela Promoción</legend>
<div>
<input type="text" name="tittle" id="tittle" placeholder="Nombre" />
</div>
<div>
<input type="text" name="description" id="description" placeholder="Descripción" />
</div>
<div>
<input type="text" name="code" id="code" placeholder="Código" />
</div>
<div>
<input type="text" name="active" id="active" placeholder="Activo" />
</div>
</fieldset>
<div class="actions">
<input type="submit" id="submit" value="Añadir promoción" name="add_promotion" class="primary" />
<input type="reset" id="reset" value="Borrar" />
</div>
</form>
</div>
<div class="column side"></div>
</div>
';
}
function deletePromotion() {
echo'<div class="column side"></div>
<div class="column middle">
<h2>Editar Promoción</h2>
<form method="post" action="index.php?state=mp">
<div class="row">
<fieldset id="promotion_form">
<legend>¿Estás seguro de que quieres eliminar esta promoción?</legend>
<input type="hidden" name="id" value='.$_POST['id'].'/>
<p>Id: '.$_POST['id'].' </p>
<p>Título: '.$_POST['tittle'].' </p>
<p>Descripción: '.$_POST['description'].' </p>
<p>Código: '.$_POST['code'].' </p>
<p>Activa: '.$_POST['active'].' </p>
</fieldset>
<div class="actions">
<input type="submit" id="submit" value="Eliminar" name="confirm_delete_promotion" class="primary" />
<input type="submit" id="submit" value="Cancelar" name="cancel_delete_promotion" class="primary" />
</div>
</div>
</form>
</div>
<div class="column side"></div>
';
}
function editPromotion() {
echo'<div class="column side"></div>
<div class="column middle">
<h2>Editar promoción</h2>
<form method="post" action="index.php?state=mp">
<div class="row">
<fieldset id="promotion_form">
<legend>Datos de la promoción</legend>
<input type="hidden" name="id" value='.$_POST['id'].'/>
<div>
<input type="text" name="tittle" value="'.$_POST['tittle'].'" />
</div>
<div>
<input type="text" name="description" value='.$_POST['description'].' />
</div>
<div>
<input type="text" name="code" value='.$_POST['code'].' />
</div>
<div>
<input type="text" name="active" value='.$_POST['active'].' />
</div>
</fieldset>
<div class="actions">
<input type="submit" id="submit" value="Editar" name="confirm_edit_promotion" class="primary" />
<input type="reset" id="reset" value="Borrar" />
</div>
</div>
</form>
</div>
<div class="column side"></div>
';
}
// Logic Functions
function confirmDelete() {
$cine = new FormPromotion();
$cine->processesForm($_POST['id'],null,null,null,null,"del");
$_SESSION['message'] = $cine->getReply();
header('Location: ../panel_admin/index.php?state=mp');
}
function confirmEdit() {
$cine = new FormPromotion();
$cine->processesForm($_POST['id'], $_POST['tittle'], $_POST['description'], $_POST['code'],$_POST['active'],"edit");
$_SESSION['message']= $cine->getReply();
header('Location: ../panel_admin/index.php?state=mp');
}
function confirmAdd() {
$cine = new FormPromotion();
$cine->processesForm(null,$_POST['tittle'], $_POST['description'], $_POST['code'],$_POST['active'],"new");
$_SESSION['message'] = $cine->getReply();
header('Location: ../panel_admin/index.php?state=mp');
}
?>