Add/edit/del manager todavia incompleto
falta terminar y probar
This commit is contained in:
148
panel_admin/includes/formManager.php
Normal file
148
panel_admin/includes/formManager.php
Normal file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
include_once('../assets/php/config.php');
|
||||
include_once('../assets/php/common/manager_dao.php');
|
||||
include_once('../assets/php/common/manager.php');
|
||||
include_once('../assets/php/form.php');
|
||||
|
||||
class FormManager extends Form {
|
||||
|
||||
//Atributes:
|
||||
private $correct; // Indicates if the session is correct.
|
||||
private $reply; // Validation response
|
||||
private $option;
|
||||
|
||||
//Constructor:
|
||||
public function __construct() {
|
||||
parent::__construct('formManager');
|
||||
$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, $_username, $_email, $_pass, $_rol) {
|
||||
$this->correct = true;
|
||||
$this->option = $_option;
|
||||
|
||||
$id= $this->test_input($_id);
|
||||
$tittle=$this->test_input($_username);
|
||||
$description=$this->test_input($_email);
|
||||
$code=$this->test_input($_pass);
|
||||
$active=$this->test_input($_rol);
|
||||
|
||||
//Habria que validar todo para que encaje en la base de datos
|
||||
|
||||
$bd = new Manager_DAO('complucine');
|
||||
if($bd){
|
||||
if($this->option == "new"){
|
||||
//Check if any var is empty
|
||||
if(!empty($_username)&&!empty($_email)&&!empty($_pass)&&!empty($_rol)){
|
||||
// check if already exist a manager with same name
|
||||
$exist = $bd->selectManager($_username);
|
||||
if( mysqli_num_rows($exist) != 0){
|
||||
$this->correct =false;
|
||||
}
|
||||
else{
|
||||
$bd->createManager(null, $_username, $_email, $_pass, $_rol);
|
||||
|
||||
}
|
||||
$exist->free();
|
||||
}
|
||||
else{
|
||||
$this->correct =false;
|
||||
}
|
||||
} else if ($this->option == "del"){
|
||||
//Check if exist a manager with this id
|
||||
$exist = $bd-> GetManager($id);
|
||||
if( mysqli_num_rows($exist) == 1){
|
||||
$bd->deleteManager($id);
|
||||
}
|
||||
else{
|
||||
$this->correct =false;
|
||||
}
|
||||
} else if ($this->option == "edit"){
|
||||
//Check if any var is empty
|
||||
if(!empty($_username)&&!empty($_email)&&!empty($_pass)&&!empty($_rol)){
|
||||
//Check if exist a manager with this id
|
||||
$exist = $bd-> PromotionData($id);
|
||||
if( mysqli_num_rows($exist) == 1){
|
||||
$bd->editManager($id,$_username, $_email, $_pass, $_rol);
|
||||
}
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
186
panel_admin/manage_managers.php
Normal file
186
panel_admin/manage_managers.php
Normal file
@ -0,0 +1,186 @@
|
||||
<?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_managers(){
|
||||
$manager = new Manager_DAO("complucine");
|
||||
$managers = $manager->allManagersData();
|
||||
$ids = array();
|
||||
$usernames = array();
|
||||
$email = array();
|
||||
$pass = array();
|
||||
$rol = array();
|
||||
|
||||
foreach($managers as $key => $value){
|
||||
$ids[$key] = $value->getId();
|
||||
$usernames[$key] = $value->getUsername();
|
||||
$email[$key] = $value->getEmail();
|
||||
$pass[$key] = $value->getPass();
|
||||
$rol[$key] = $value->getRoll();
|
||||
}
|
||||
|
||||
|
||||
echo "<div class='row'>
|
||||
<div class='column side'></div>
|
||||
<div class='column middle'>
|
||||
<table class='alt'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Nombre</th>
|
||||
<th>Email</th>
|
||||
<th>password</th>
|
||||
<th>Rol</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
";
|
||||
for($i = 0; $i < count($promos); $i++){
|
||||
echo '<tr>
|
||||
<td>'. $ids[$i] .'</td>
|
||||
<td>'. $usernames[$i] .'</td>
|
||||
<td>'. $email[$i] .'</td>
|
||||
<td>'. $pass[$i] .'</td>
|
||||
<td>'. $rol[$i] .'</td>
|
||||
<td>
|
||||
<form method="post" action="index.php?state=mp">
|
||||
<input name="id" type="hidden" value="'.$ids[$i].'">
|
||||
<input name="username" type="hidden" value="'.$usernames[$i].'">
|
||||
<input name="email" type="hidden" value="'.$email[$i].'">
|
||||
<input name="pass" type="hidden" value="'.$pass[$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=mp">
|
||||
<input name="id" type="hidden" value="'.$ids[$i].'">
|
||||
<input name="username" type="hidden" value="'.$usernames[$i].'">
|
||||
<input name="email" type="hidden" value="'.$email[$i].'">
|
||||
<input name="pass" type="hidden" value="'.$pass[$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>
|
||||
</div>
|
||||
<div class="column side"></div>
|
||||
';
|
||||
|
||||
}
|
||||
|
||||
function addManager(){
|
||||
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="username" id="username" placeholder="Nombre" />
|
||||
</div>
|
||||
<div>
|
||||
<input type="email" name="email" id="email" placeholder="email" />
|
||||
</div>
|
||||
<div>
|
||||
<input type="text" name="password" id="pass" placeholder="pass" />
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="actions">
|
||||
<input type="submit" id="submit" value="Añadir gerente" name="add_manager" class="primary" />
|
||||
<input type="reset" id="reset" value="Borrar" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="column side"></div>
|
||||
</div>
|
||||
';
|
||||
}
|
||||
function deleteManager() {
|
||||
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 este gerente?</legend>
|
||||
<input type="hidden" name="id" value='.$_POST['id'].'/>
|
||||
<p>Id: '.$_POST['id'].' </p>
|
||||
<p>Nombre: '.$_POST['username'].' </p>
|
||||
<p>Email: '.$_POST['email'].' </p>
|
||||
<p>Password: '.$_POST['pass'].' </p>
|
||||
<p>Rol: '.$_POST['rol'].' </p>
|
||||
</fieldset>
|
||||
<div class="actions">
|
||||
<input type="submit" id="submit" value="Eliminar" name="confirm_delete_manager" class="primary" />
|
||||
<input type="submit" id="submit" value="Cancelar" name="cancel_delete_manager" class="primary" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="column side"></div>
|
||||
';
|
||||
}
|
||||
function editManager() {
|
||||
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="username" value="'.$_POST['username'].'" />
|
||||
</div>
|
||||
<div>
|
||||
<input type="email" name="email" value='.$_POST['email'].' />
|
||||
</div>
|
||||
<div>
|
||||
<input type="text" name="pass" value='.$_POST['pass'].' />
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="actions">
|
||||
<input type="submit" id="submit" value="Editar" name="confirm_edit_manager" 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['username'], $_POST['email'], $_POST['pass'],"manager","edit");
|
||||
$_SESSION['message']= $cine->getReply();
|
||||
header('Location: ../panel_admin/index.php?state=mp');
|
||||
}
|
||||
function confirmAdd() {
|
||||
$cine = new FormPromotion();
|
||||
$cine->processesForm(null,$_POST['username'], $_POST['email'], $_POST['pass'],"manager","new");
|
||||
$_SESSION['message'] = $cine->getReply();
|
||||
header('Location: ../panel_admin/index.php?state=mp');
|
||||
}
|
||||
|
||||
|
||||
?>
|
Reference in New Issue
Block a user