-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistaUsuarios.php
73 lines (65 loc) · 2.28 KB
/
listaUsuarios.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
<?php
$titulo = "Lista Usuários";
include __DIR__ . '/header.php';
?>
<div class="container">
<h1>Lista Usuários</h1>
<table class="table">
<thead>
<tr>
<th>Nome</th>
<th>E-mail</th>
<th>Ações</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM usuarios";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$usuarios = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($usuarios as $usuario) :
?>
<tr>
<td><?php echo $usuario['nome']; ?></td>
<td><?php echo $usuario['email']; ?></td>
<td><button onclick="excluirUsuario(<?php echo $usuario['id_usu']; ?>);" class="btn btn-danger">Excluir</button>
<button onclick="editarUsuario();" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#editar_usuario">Editar</button>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<!-- Modal -->
<div class="modal fade" id="editar_usuario" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<script>
function excluirUsuario(idUsu) {
if (confirm('Deseja realmente excluir este usuário?')) {
fetch('<?php echo URL_BASE; ?>api.php?acao=excluir&idUsu=' + idUsu)
.then(response => response.json())
.then(data => {
console.log(data);
if (data) {
alert('Usuário excluído com sucesso!');
window.location.reload();
} else {
alert('Erro ao excluir usuário!');
}
});
}
}
</script>
<?php
include __DIR__ . '/footer.php';
?>