Skip to content

Commit

Permalink
Add admin
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusHT committed Oct 22, 2022
1 parent 8a436ee commit 2a287ee
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 79 deletions.
4 changes: 3 additions & 1 deletion config/session.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

// Valida si existe una session de no existir te envia al login y si sirve extrae los datos del usuario para poder usarlos déspues

session_start();
if (session_status() == PHP_SESSION_NONE){
session_start();
}

$db = new Database();

Expand Down
15 changes: 11 additions & 4 deletions controllers/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Admin extends Controller {

function __construct(){
parent::__construct();
if (session_status() == PHP_SESSION_NONE) {
if (session_status() == PHP_SESSION_NONE){
session_start();
}
$tabla = $this -> tableUsers();
Expand All @@ -13,16 +13,23 @@ function __construct(){

function tableUsers(){
$query = new UserModel();

if ($this -> existPOST(['busqueda'])) {
$busqueda = $this -> getPost('busqueda');
return $query -> busqueda($busqueda, $_SESSION['user']);
return $query -> tableUsers($busqueda, $_SESSION['user']);
}

return $query -> tableUsers($_SESSION['user']);
return $query -> tableUsers(NULL,$_SESSION['user']);
}

function delete(){


header('Content-Type: application/json');

if ($this -> existPOST(['passEjecutivo','eliminar'])) {
$data = "Hola!";
echo json_encode($data);
}
}

function update(){
Expand Down
2 changes: 1 addition & 1 deletion controllers/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function authenticate(){


} else {
$this->redirect('', ['error' => Errors::ERROR_LOGIN_LOGIN]);
$this-redirect('', ['error' => Errors::ERROR_LOGIN_LOGIN]);
}
}

Expand Down
4 changes: 3 additions & 1 deletion libs/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ function render($nombre, $data = []){
$this->d = $data;
$this->handleMessages();


if (!empty($_GET['url']) && $_GET['url'] !== 'recuperar') {
require_once 'config/session.php';
}

require 'views/' . $nombre . '.php';
}
Expand Down
86 changes: 18 additions & 68 deletions models/usermodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,77 +194,30 @@ function escape($value){

return $return;
}

function busqueda($busqueda, $id){
$q = $this -> escape($busqueda);
function tableUsers($busqueda, $id){

$this -> getUsers($id);
$num_client = $this -> getNum_Client();
$id_client = $num_client[0];
$status = "activo";

try {
$query = $this -> prepare("SELECT * FROM users WHERE num_client LIKE '%". $id_client ."%' AND name LIKE '%". $q ."%'");
$query -> execute();

$results = $query -> fetchAll(PDO::FETCH_OBJ);

if (is_countable($results) > 0) {
$i = 1;
$data = '';
foreach($results as $cliente){

if($cliente -> num_client !== $num_client)
$data .=
'<tr>
<td>'. $i .'</td>
<td>'. $cliente -> name .'</td>
<td>'. $cliente -> num_client .'</td>
<td>
<form action="'. constant('URL') .'admin/delete" method="POST">
<input type="hidden" name="eliminar" value="'. $user -> id .'">
<button type="submit" class="btn"><i class="fa-solid fa-trash-can"></i></button>
</form>
</td>
<td>
<form action="'. constant('URL') .'admin/update" method="POST">
<input type="hidden" name="actualizar" value="'. $user -> id .'">
<button type="submit" class="btn"><i class="fa-solid fa-pencil"></i></button>
</form>
</td>
<td>
<form action="'. constant('URL') .'ver" method="POST">
<input type="hidden" name="ver" value="'. $user -> id .'">
<button type="submit" class="btn"><i class="fa-solid fa-eye"></i></button>
</form>
</td>
</tr>';
$i++;
}
$sql = "SELECT * FROM users WHERE num_client LIKE '%" . $id_client ."%' AND status LIKE '%". $status ."%' ORDER BY id";

return $data;
}

if (empty($results)) {
return "<tr><td><td>No se encontraron coincidencias con sus criterios de búsqueda!</td></tr>";
}
} catch (PDOException $e){
echo $e;
if ($busqueda !== NULL) {
$q = $this -> escape($busqueda);
$sql = "SELECT * FROM users WHERE num_client LIKE '%". $id_client ."%' AND name LIKE '%". $q ."%' AND status LIKE '%". $status ."%'";
}
}

function tableUsers($id){
$this -> getUsers($id);
$num_client = $this -> getNum_Client();
$id_client = $num_client[0];

try {
$query = $this -> prepare("SELECT * FROM users WHERE num_client LIKE '%" . $id_client ."%' ORDER BY id");
$query = $this -> prepare($sql);
$query -> execute();

$results = $query -> fetchAll(PDO::FETCH_OBJ);
$data = '';

if (is_countable($results) > 0) {
$data = '';
$i = 1;
if (count($results) > 0) {
$i = 0;
foreach($results as $user){

if($user -> num_client !== $num_client)
Expand All @@ -273,11 +226,8 @@ function tableUsers($id){
<td>'. $i .'</td>
<td>'. $user -> name .'</td>
<td>'. $user -> num_client .'</td>
<td>
<form action="'. constant('URL') .'admin/delete" method="POST">
<input type="hidden" name="eliminar" value="'. $user -> id .'">
<button type="submit" class="btn"><i class="fa-solid fa-trash-can"></i></button>
</form>
<td>
<button type="button" class="btn" onclick="openModal('.$user -> id.')"><i class="fa-solid fa-trash-can"></i></button>
</td>
<td>
<form action="'. constant('URL') .'admin/update" method="POST">
Expand All @@ -287,7 +237,7 @@ function tableUsers($id){
</td>
<td>
<form action="'. constant('URL') .'ver" method="POST">
<input type="hidden" name="ver" value="'. $user -> id .'">
<input type="hidden" id="" name="ver" value="'. $user -> id .'">
<button type="submit" class="btn"><i class="fa-solid fa-eye"></i></button>
</form>
</td>
Expand All @@ -298,9 +248,9 @@ function tableUsers($id){
return $data;
}

if (empty($results)) {
return "<tr><td><td>No se encontraron coincidencias con sus criterios de búsqueda!</td></tr>";
}
return '<p class="bg-Error">No se encontraron coincidencias con sus criterios de búsqueda</p><br>';


} catch (PDOException $e){
echo $e;
}
Expand Down
Binary file not shown.
Binary file not shown.
25 changes: 25 additions & 0 deletions public/css/admin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions public/css/admin.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/css/nav.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/css/nav.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions public/js/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var borrar = document.getElementById("eliminar");
var modal = document.getElementById("myModal");

function openModal(id){
modal.style.display = "block";
borrar.value = id;
console.log(id);
}

function closedModal(){
modal.style.display = "none";
}
35 changes: 35 additions & 0 deletions public/sass/admin.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Importamos el css global

@import url(../css/global.css);

//Background-color

$bg-content-modal:#fefefe;
$bg-body-modal:rgba(0,0,0,0.4);
$bg-secondary-modal:rgb(0,0,0);

// Classes
.modal {
display: none;
position: fixed;
margin:auto 0;
z-index: 2;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: $bg-secondary-modal;
background-color: $bg-body-modal;

.modal-content {
position: relative;
background-color: $bg-content-modal;
margin: auto;
padding: 0;
width: 40%;
}

.modal-header {padding: 2px 16px;}
.modal-body {padding: 5px 15px;}
}
2 changes: 1 addition & 1 deletion public/sass/nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
-webkit-transition:width .05s linear;
transition:width .05s linear;
//-webkit-transform:translateZ(0) scale(1,1);
z-index:1000;
z-index:1;

&:hover, &.expanded {
width:250px;
Expand Down
41 changes: 40 additions & 1 deletion views/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="<?php echo constant('URL'); ?>public/img/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="<?php echo constant('URL'); ?>public/css/global.css">
<link rel="stylesheet" href="<?php echo constant('URL'); ?>public/css/admin.css">
<title>JADAR BANK</title>
</head>
<body>
Expand All @@ -32,5 +32,44 @@
</tbody>
</table>
</div>
<div id="myModal" class="modal">
<div class="modal-content">
<div class="modal-header bg-Warning">
<h2>Dar debaja a un cliente</h2>
</div>
<div class="modal-body">
<div id="respustaCrear">

</div>
<p>Esta acción es irreversible. ¿Estás seguro que quieres dar debaja a este cliente?</p><br>
<form id="FormDelete" method="POST">
<input type="hidden" name="eliminar" id="eliminar" value="">
<label for="passEjecutivo">Ingrese su contraseña</label><br>
<input type="text" id="passEjecutivo" name="passEjecutivo" required> <br>
<br>
<div style="text-align: right;">
<button type="button" onclick="crearPost()" class="btn">Eliminar</button>
<button type="button" onclick="closedModal()" class="btn">Cancelar</button>
</div>
</form>
</div>
</div>
</div>
<script src="<?php echo constant('URL'); ?>public/js/admin.js"></script>
<script>
function crearPost(){

let datos = new FormData(document.getElementById("FormDelete"));

fetch('admin/delete', {
method: "post",
body: datos
}).then((response) => {
return response.json();
}).then((data) => {
document.getElementById("respustaCrear").innerHTML = data
}).catch(err => console.error(err));
}
</script>
</body>
</html>

0 comments on commit 2a287ee

Please sign in to comment.