This commit is contained in:
Daniel Muñoz Garcia 2021-05-06 12:18:20 +02:00 committed by GitHub
parent 042333b96c
commit 5ee09a12de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 146 additions and 58 deletions

View File

@ -5,8 +5,11 @@
include_once('../assets/php/common/manager.php'); include_once('../assets/php/common/manager.php');
include_once(__DIR__.'/includes/formManager.php'); include_once('../assets/php/common/cinema_dao.php');
include_once('../assets/php/common/user_dao.php');
include_once(__DIR__.'/includes/formManager.php');
// View functions // View functions
@ -14,16 +17,16 @@
$manager = new Manager_DAO("complucine"); $manager = new Manager_DAO("complucine");
$managers = $manager->allManagersData(); $managers = $manager->allManagersData();
$ids = array(); $ids = array();
$idscinemas = array();
$usernames = array(); $usernames = array();
$email = array(); $email = array();
$pass = array();
$rol = array(); $rol = array();
foreach($managers as $key => $value){ foreach($managers as $key => $value){
$ids[$key] = $value->getId(); $ids[$key] = $value->getId();
$idscinemas[$key] = $value->getIdcinema();
$usernames[$key] = $value->getUsername(); $usernames[$key] = $value->getUsername();
$email[$key] = $value->getEmail(); $email[$key] = $value->getEmail();
$pass[$key] = $value->getPass();
$rol[$key] = $value->getRoll(); $rol[$key] = $value->getRoll();
} }
@ -35,6 +38,7 @@
<thead> <thead>
<tr> <tr>
<th>Id</th> <th>Id</th>
<th>IdCinema</th>
<th>Nombre</th> <th>Nombre</th>
<th>Email</th> <th>Email</th>
<th>password</th> <th>password</th>
@ -43,29 +47,29 @@
</thead> </thead>
<tbody> <tbody>
"; ";
for($i = 0; $i < count($promos); $i++){ for($i = 0; $i < count($managers); $i++){
echo '<tr> echo '<tr>
<td>'. $ids[$i] .'</td> <td>'. $ids[$i] .'</td>
<td>'. $idscinemas[$i] .'</td>
<td>'. $usernames[$i] .'</td> <td>'. $usernames[$i] .'</td>
<td>'. $email[$i] .'</td> <td>'. $email[$i] .'</td>
<td>'. $pass[$i] .'</td>
<td>'. $rol[$i] .'</td> <td>'. $rol[$i] .'</td>
<td> <td>
<form method="post" action="index.php?state=mp"> <form method="post" action="index.php?state=mg">
<input name="id" type="hidden" value="'.$ids[$i].'"> <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="username" type="hidden" value="'.$usernames[$i].'">
<input name="email" type="hidden" value="'.$email[$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 name="rol" type="hidden" value="'.$rol[$i].'">
<input type="submit" id="submit" value="Editar" name="edit_manager" class="primary" /> <input type="submit" id="submit" value="Editar" name="edit_manager" class="primary" />
</form> </form>
</td> </td>
<td> <td>
<form method="post" action="index.php?state=mp"> <form method="post" action="index.php?state=mg">
<input name="id" type="hidden" value="'.$ids[$i].'"> <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="username" type="hidden" value="'.$usernames[$i].'">
<input name="email" type="hidden" value="'.$email[$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 name="rol" type="hidden" value="'.$rol[$i].'">
<input type="submit" id="submit" value="Eliminar" name="delete_manager" class="primary" /> <input type="submit" id="submit" value="Eliminar" name="delete_manager" class="primary" />
</form> </form>
@ -79,31 +83,17 @@
<div class="column side"></div> <div class="column side"></div>
'; ';
} }
function addManager(){ function addManager(){
echo' <div class="column side"></div> echo' <div class="column side"></div>
<div class="column middle"> <div class="column middle">
<h2>Añadir gerente</h2> <h2>Añadir gerente</h2>
<form method="post" action="index.php?state=mp"> <form method="post" action="index.php?state=mg">
<fieldset id="manager_form">
<legend>Datos del manager </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="pass" id="pass" placeholder="password" />
</div>
<div>
<input type="text" name="pass2" id="pass2" placeholder="confirm password" />
</div>
</fieldset>
<div class="actions"> <div class="actions">
<input type="submit" id="submit" value="Añadir gerente" name="add_manager" class="primary" /> <input type="submit" id="submit" value="Añadir gerente" name="select_user" class="primary" />
<input type="reset" id="reset" value="Borrar" />
</div> </div>
</form> </form>
</div> </div>
@ -111,19 +101,66 @@
</div> </div>
'; ';
} }
function selectUser() {
echo'<div class="column side"></div>
<div class="column middle">
<h2>Selecciona el usuario al que quieres dar privilegios.</h2>
<form method="post" action="index.php?state=mg">
<div class="row">
<fieldset id="manager_form">
<legend>Selecciona usuario.</legend>';
showUsers();
echo '</fieldset>
<div class="actions">
<input type="submit" id="submit" value="Seleccionar" name="select_cinema" class="primary" />
<input type="reset" id="reset" value="Borrar" />
</div>
</div>
</form>
</div>
<div class="column side"></div>
';
}
function selectCinema() {
echo'<div class="column side"></div>
<div class="column middle">
<h2>Selecciona el cine asociado al nuevo manager.</h2>
<form method="post" action="index.php?state=mg">
<div class="row">
<fieldset id="manager_form">
<legend>Selecciona cine.</legend>';
showCinemas();
echo '</fieldset>
<div class="actions">
<input name="iduser" type="hidden" value="'.$_POST['iduser'].'">
<input type="submit" id="submit" value="Seleccionar" name="add_manager" class="primary" />
<input type="reset" id="reset" value="Borrar" />
</div>
</div>
</form>
</div>
<div class="column side"></div>
';
}
function deleteManager() { function deleteManager() {
echo'<div class="column side"></div> echo'<div class="column side"></div>
<div class="column middle"> <div class="column middle">
<h2>Borrar gerente</h2> <h2>Borrar gerente</h2>
<form method="post" action="index.php?state=mp"> <form method="post" action="index.php?state=mg">
<div class="row"> <div class="row">
<fieldset id="promotion_form"> <fieldset id="promotion_form">
<legend>¿Estás seguro de que quieres eliminar este gerente?</legend> <legend>¿Estás seguro de que quieres eliminar este gerente?</legend>
<input type="hidden" name="id" value='.$_POST['id'].'/> <input type="hidden" name="id" value='.$_POST['id'].'/>
<p>Id: '.$_POST['id'].' </p> <p>Id: '.$_POST['id'].' </p>
<p>IdCinema: '.$_POST['idcinema'].' </p>
<p>Nombre: '.$_POST['username'].' </p> <p>Nombre: '.$_POST['username'].' </p>
<p>Email: '.$_POST['email'].' </p> <p>Email: '.$_POST['email'].' </p>
<p>Password: '.$_POST['pass'].' </p>
<p>Rol: '.$_POST['rol'].' </p> <p>Rol: '.$_POST['rol'].' </p>
</fieldset> </fieldset>
<div class="actions"> <div class="actions">
@ -136,26 +173,21 @@
<div class="column side"></div> <div class="column side"></div>
'; ';
} }
function editManager() { function editManager() {
echo'<div class="column side"></div> echo'<div class="column side"></div>
<div class="column middle"> <div class="column middle">
<h2>Editar gerente</h2> <h2>Editar gerente ID: '.$_POST['id'].'</h2>
<form method="post" action="index.php?state=mp"> <form method="post" action="index.php?state=mg">
<div class="row"> <div class="row">
<fieldset id="promotion_form"> <fieldset id="promotion_form">
<legend>Datos de la promoción</legend> <legend>Selecciona su cine.</legend>';
<input type="hidden" name="id" value='.$_POST['id'].'/> showCinemas();
<div> echo '</fieldset>
<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"> <div class="actions">
<input type="hidden" name="id" value='.$_POST['id'].'/>
<input type="submit" id="submit" value="Editar" name="confirm_edit_manager" class="primary" /> <input type="submit" id="submit" value="Editar" name="confirm_edit_manager" class="primary" />
<input type="reset" id="reset" value="Borrar" /> <input type="reset" id="reset" value="Borrar" />
</div> </div>
@ -164,26 +196,72 @@
</div> </div>
<div class="column side"></div> <div class="column side"></div>
'; ';
}
// Show cinemas and users functions
function showCinemas() {
$cine = new Cinema_DAO("complucine");
$cinemas = $cine->allCinemaData();
$ids = array();
$names = array();
$directions = array();
$phones = array();
foreach($cinemas as $key => $value){
$ids[$key] = $value->getId();
$names[$key] = $value->getName();
$directions[$key] = $value->getDirection();
$phones[$key] = $value->getPhone();
}
for($i = 0; $i < count($cinemas); $i++){
echo '
<input type="radio" name="idcinema" value='.$ids[$i].' > <label> '.$ids[$i].', '.$names[$i].'
</label>
';
}
}
function showUsers() {
$user = new UserDAO("complucine");
$users = $user->allUsersNotM();
$ids = array();
$usernames = array();
$emails = array();
$roles = array();
foreach($users as $key => $value){
$ids[$key] = $value->getId();
$usernames[$key] = $value->getName();
$emails[$key] = $value->getEmail();
$roles[$key] = $value->getRol();
}
for($i = 0; $i < count($users); $i++){
echo '
<input type="radio" name="iduser" value='.$ids[$i].' > <label> '.$ids[$i].', '.$usernames[$i].', '.$usernames[$key].'
</label>
';
}
} }
// Logic Functions // Logic Functions
function confirmDelete() { function confirmDelete() {
$cine = new FormPromotion(); $cine = new FormManager();
$cine->processesForm($_POST['id'],null,null,null,null,"del"); $cine->processesForm($_POST['id'], null,"del");
$_SESSION['message'] = $cine->getReply(); $_SESSION['message'] = $cine->getReply();
header('Location: ../panel_admin/index.php?state=mp'); header('Location: ../panel_admin/index.php?state=mg');
} }
function confirmEdit() { function confirmEdit() {
$cine = new FormPromotion(); $manager = new FormManager();
$cine->processesForm($_POST['id'], $_POST['username'], $_POST['email'], $_POST['pass'],"manager","edit"); $manager->processesForm($_POST['id'], $_POST['idcinema'],"edit");
$_SESSION['message']= $cine->getReply(); $_SESSION['message']= $manager->getReply();
header('Location: ../panel_admin/index.php?state=mp'); header('Location: ../panel_admin/index.php?state=mg');
} }
function confirmAdd() { function confirmAdd() {
$cine = new FormPromotion(); $manager = new FormManager();
$cine->processesForm(null,$_POST['username'], $_POST['email'], $_POST['pass'],"manager","new"); $manager->processesForm($_POST['iduser'], $_POST['idcinema'],"new");
$_SESSION['message'] = $cine->getReply(); $_SESSION['message'] = $manager->getReply();
header('Location: ../panel_admin/index.php?state=mp'); header('Location: ../panel_admin/index.php?state=mg');
} }

View File

@ -34,6 +34,9 @@
}; };
break; break;
case 'mf': require_once('manage_films.php'); case 'mf': require_once('manage_films.php');
//echo $_SERVER['DOCUMENT_ROOT']."/../img";
echo TMP_DIR;
//echo $_SERVER['PHP_SELF'];
if(isset($_POST['edit_film'])) { if(isset($_POST['edit_film'])) {
editFilm(); editFilm();
} }
@ -83,9 +86,16 @@
else if(isset($_POST['delete_manager'])) { else if(isset($_POST['delete_manager'])) {
deleteManager(); deleteManager();
} }
else if(isset($_POST['select_user'])) {
selectUser();
}
else if(isset($_POST['select_cinema'])) {
selectCinema();
}
else if(isset($_POST['add_manager'])) { else if(isset($_POST['add_manager'])) {
confirmAdd(); confirmAdd();
} }
else if(isset($_POST['confirm_delete_manager'])) { else if(isset($_POST['confirm_delete_manager'])) {
confirmDelete(); confirmDelete();
} }