-
Notifications
You must be signed in to change notification settings - Fork 0
/
usuario.php
360 lines (322 loc) · 15.8 KB
/
usuario.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<?php
require_once 'appConfig.php';
if(empty($_SESSION['key'])) {
header ('location:./');
}
$menu = 4;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title><?php echo $cfg['head_title']; ?></title>
<!-- Tell the browser to be responsive to screen width -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Favicon -->
<link rel="icon" type="image/png" href="dist/img/favicon.png">
<!-- Font Awesome -->
<link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<!-- DataTables -->
<link rel="stylesheet" href="plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
<!-- SweetAlert2 -->
<link rel="stylesheet" href="plugins/sweetalert2-theme-bootstrap-4/bootstrap-4.min.css">
<!-- AdminLTE App -->
<link rel="stylesheet" href="dist/css/adminlte.min.css">
<!-- Custom App -->
<link rel="stylesheet" href="dist/css/main.css">
<!-- Google Font: Source Sans Pro -->
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
</head>
<body class="hold-transition layout-navbar-fixed sidebar-mini sidebar-collapse text-sm">
<!-- Site wrapper -->
<div class="wrapper">
<?php
include_once 'appNavbar.php';
include_once 'appSidebar.php';
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-12">
<h1>
<span>Usuário</span>
<span class="float-right">
<a href="#" class="btn btn-primary" title="Clique para cadastrar um novo usuário" data-toggle="modal" data-target="#modal-new-usuario">
<i class="fas fa-user"></i> Novo usuário
</a>
</span>
<span></span>
</h1>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<!-- Main content -->
<section class="content">
<?php include_once 'appSearch.php'; ?>
<!-- Default box -->
<div class="card">
<div class="card-body">
<div class="div-load-page d-none"></div>
<table class="table table-bordered table-hover table-data d-none">
<thead>
<tr>
<th>Nome</th>
<th>Usuário</th>
<th>Email</th>
<th style="max-width: 100px;width: 90px;"></th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th>Nome</th>
<th>Usuário</th>
<th>Email</th>
<th style="max-width: 100px;width: 90px;"></th>
</tr>
</tfoot>
</table>
<blockquote class="blockquote-data d-none">
<h5>Nada encontrado</h5>
<p>Nenhum cadastrado.</p>
</blockquote>
</div>
</div>
<!-- /.card -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<div class="modal fade" id="modal-new-usuario">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-new-usuario">
<div class="modal-header">
<h4 class="modal-title">
<span>Novo usuário</span>
<span class="text-muted">
<small>(<i class="fas fa-bell"></i> Campo obrigatório)</small>
</span>
</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<input type="hidden" name="rand" id="rand" value="<?php echo md5(mt_rand()); ?>">
<div class="form-group">
<label for="nome"><i class="fas fa-bell"></i> Nome</label>
<input type="text" name="nome" id="nome" maxlength="200" class="form-control" placeholder="Nome" required>
</div>
<div class="form-group">
<label for="usuario"><i class="fas fa-bell"></i> Usuário</label>
<input type="text" name="usuario" id="usuario" maxlength="10" class="form-control" placeholder="Usuário" required>
</div>
<div class="form-group">
<label for="senha"><i class="fas fa-bell"></i> Senha</label>
<input type="password" name="senha" id="senha" maxlength="10" class="form-control" autocomplete="senha" spellcheck="false" autocorrect="off" autocapitalize="off" placeholder="Senha" required>
</div>
<div class="form-group">
<label for="email"><i class="fas fa-bell"></i> Email</label>
<input type="email" name="email" id="email" maxlength="100" class="form-control" placeholder="Email" required>
</div>
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
<button type="submit" class="btn btn-primary btn-new-usuario">Salvar</button>
</div>
</form>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<div class="modal fade" id="modal-edit-usuario">
<div class="modal-dialog">
<div class="modal-content"></div>
</div>
</div>
<?php include_once 'appFootbar.php'; ?>
</div>
<!-- ./wrapper -->
<!-- jQuery -->
<script src="plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- DataTables -->
<script src="plugins/datatables/jquery.dataTables.js"></script>
<script src="plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<!-- Password Toggle -->
<script src="plugins/bootstrap-show-password/bootstrap.show.password.min.js"></script>
<!-- SweetAlert2 -->
<script src="plugins/sweetalert2/sweetalert2.min.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
<!-- Custom App -->
<script defer src="dist/js/main.js"></script>
<script defer>
$(document).ready(function() {
const fade = 150, delay = 100, timeout = 60000,
Toast = Swal.mixin({
toast: true,
position: 'top-end',
showConfirmButton: false,
timer: 1000
});
/* PULL DATA */
(function pullData() {
$.ajax({
type: 'GET',
url: 'api/usuario/readAll.php',
dataType: 'json',
cache: false,
beforeSend: function(result) {
$('.div-load-page').removeClass('d-none').append('<p class="lead text-center"><i class="fas fa-cog fa-spin"></i></p>');
},
error: function(result) {
Swal.fire({icon: 'error',html: result.responseText,showConfirmButton: false});
},
success: function(data) {
if(!data[0]) {
$('.div-load-page').addClass('d-none');
$('.table-data').addClass('d-none');
$('.blockquote-data').removeClass('d-none');
Swal.fire({icon: 'error',title: 'Nenhum usuário encontrado.'}).then((result) => {
window.setTimeout("location.href='sair'", delay);
});
} else {
if(data[0].status == true) {
let response = '', logon = <?php echo $_SESSION['id']; ?>;
for (let i in data) {
if (data[i].idusuario != logon) {
if (data[i].nome != 'Root') {
response += '<tr>'
+ '<td>' + data[i].nome + '</td>'
+ '<td>' + data[i].usuario + '</td>'
+ '<td>' + data[i].email + '</td>'
+ '<td class="td-action">'
+ '<span class="bg bg-warning"><a class="fas fa-pen a-edit-usuario" href="usuarioEdit.php?78eafd55d38a6cdcf6611ca998b01e44=' + data[i].idusuario + '" title="Editar usuário"></a></span>'
+ '<span class="bg bg-danger"><a class="fas fa-trash a-delete-usuario" id="78eafd55d38a6cdcf6611ca998b01e44-' + data[i].idusuario + '" href="#" title="Excluir usuário"></a></span>'
+ '</td></tr>';
}
} else {
response += '<tr>'
+ '<td>' + data[i].nome + ' <span class="bg-success">Logado</span></td>'
+ '<td>' + data[i].usuario + '</td>'
+ '<td>' + data[i].email + '</td>'
+ '<td class="td-action">'
+ '<span class="bg bg-warning"><a class="fas fa-pen a-edit-usuario" href="usuarioEdit.php?78eafd55d38a6cdcf6611ca998b01e44=' + data[i].idusuario + '&f8032d5cae3de20fcec887f395ec9a6a=' + data[i].usuario + '" title="Editar usuário"></a></span>'
+ '</td></tr>';
}
}
$('.div-load-page').addClass('d-none');
$('.blockquote-data').addClass('d-none');
$('.table-data').removeClass('d-none');
//$(response).appendTo($('.table-data'));
$('.table-data tbody').html(response);
/* TOOLTIP */
$('div a, td span a, span a').tooltip({boundary: 'window'});
/* DATATABLE */
$('.table-data').DataTable({
"paging": true,
"lengthChange": false,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": false,
"responsive": true,
"destroy": true
});
} else {
$('.div-load-page').addClass('d-none');
$('.table-data').addClass('d-none');
$('.blockquote-data').removeClass('d-none');
Swal.fire({icon: 'error',title: 'Nenhum usuário encontrado.'}).then((result) => {
window.setTimeout("location.href='sair'", delay);
});
}
}
},
complete: setTimeout(function() { pullData(); }, timeout),
timeout: timeout
});
})();
/* SHOW PASS */
$('#senha').password();
/* MODAL */
$('.table-data').on('click', '.a-edit-usuario', function(e) {
e.preventDefault();
$('#modal-edit-usuario').modal('show').find('.modal-content').load($(this).attr('href'));
});
/* NOVO USUÁRIO */
$('.form-new-usuario').submit(function(e) {
e.preventDefault();
$.post('api/usuario/insert.php', $(this).serialize(), function(data) {
$('.btn-new-usuario').html('<img src="dist/img/rings.svg" class="loader-svg">').fadeTo(fade, 1);
switch(data) {
case 'true':
Toast.fire({icon: 'success',title: 'Usuário cadastrado.'}).then((result) => {
window.setTimeout("location.href='usuario'", delay);
});
break;
default:
Toast.fire({icon: 'error',title: data});
break;
}
$('.btn-new-usuario').html('Salvar').fadeTo(fade, 1);
});
return false;
});
/* DELETE USUÁRIO */
$('.table-data').on('click', '.a-delete-usuario', function(e) {
e.preventDefault();
let click = this.id.split('-'),
py = click[0],
id = click[1];
Swal.fire({
icon: 'question',
title: 'Excluir o usuário',
showCancelButton: true,
confirmButtonText: 'Sim',
cancelButtonText: 'Não',
}).then((result) => {
if(result.value == true) {
$.ajax({
type: 'GET',
url: 'api/usuario/delete.php?' + py + '=' + id,
dataType: 'json',
cache: false,
error: function(result) {
Swal.fire({icon: 'error',html: result.responseText,showConfirmButton: false});
},
success: function(data) {
if(data == true) {
Toast.fire({icon: 'success',title: 'Usuário excluído.'}).then((result) => {
window.setTimeout("location.href='usuario'", delay);
});
} else {
Toast.fire({icon: 'success',title: 'Usuário excluído.'}).then((result) => {
window.setTimeout("location.href='index'", delay);
});
}
}
});
}
});
});
});
</script>
</body>
</html>