-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusuarios.php
279 lines (278 loc) · 11.4 KB
/
usuarios.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
<?php
include 'classes/usuario.class.php';
include 'classes/log.class.php';
include 'classes/ocorrencia.class.php';
$pageTitle = "Usuários · Visão Geral";
include 'nucleo/cabecario.php';
include("nucleo/barraLateral.php");
if ($_SESSION['tipo_usuario'] != 1){
header("Location: ../restart/painel.php");
exit;
}
if (isset($_POST['filtro'])){
$filtro = $_POST['filtro'];
} else {
$filtro = 0;
}
if (!empty($_POST)) {
$LOG = new LOG;
//MODELO COM ARRAY
/*if (isset($_POST['matUsuario'])) {
$del_matricula = $_POST['matUsuario'];
} else if (isset($_POST['checkbox'])){
$del_matricula = $_POST['checkbox'];
$sql = implode ("','", array($_POST['checkbox']));
$del_matricula = $sql;
}
$delUser = new Usuario;
$delUser->deletarUsuario($del_matricula);
unset($delUser);
*/
//MODELO SIMPLES
if (isset($_POST['matUsuario'])) {
$del_matricula = $_POST['matUsuario'];
$delUser = new Usuario;
$result = $delUser->deletarUsuario($del_matricula);
if (is_bool($result)) {
echo "<!-- Modal -->
<div class='modal fade bs-modal-sm' id='modal_excUsuario' tabindex='-1' role='dialog' aria-labelledby='modal_excUsuarioLabel' aria-hidden='true'>
<div class='modal-dialog modal-sm'>
<div class='modal-content panel-success'>
<div class='modal-header panel-heading'>
<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
<h4 class='modal-title' id='modal_excUsuarioLabel'>Usuário excluído!</h4>
</div>
</div>
</div>
</div>";
$LOG->gerarLOG($_SESSION['matricula'], $_SERVER['REMOTE_ADDR'], 'DEL_USU', $result);
}
else {
echo "<!-- Modal -->
<div class='modal fade' id='modal_excUsuario' tabindex='-1' role='dialog' aria-labelledby='modal_excUsuarioLabel' aria-hidden='true'>
<div class='modal-dialog'>
<div class='modal-content panel-danger'>
<div class='modal-header panel-heading'>
<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
<h4 class='modal-title' id='modal_excUsuarioLabel'>Não foi possível excluir o usuário</h4>
</div>
<div class='modal-body'>
<p>".$result."</p>
</div>
</div>
</div>
</div>";
}
unset($delUser);
echo "<script>$('#modal_excUsuario').modal('show');</script>";
}
}
?>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-6">
<h1>Usuários <small>Visão geral</small></h1>
</div>
<div class="col-lg-6" align="right">
<a href="cadUsuario.php"><button type="button" class="btn btn-primary"><i class="glyphicon glyphicon-plus-sign"></i> Novo usuário</button></a>
</div>
</div><!-- /.row -->
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<li class="active"><i class="glyphicon glyphicon-user"></i> Usuários</li>
</ol>
</div>
</div><!-- /.row -->
<div class="row">
<div class="col-lg-12">
<table>
<tr>
<th colspan="2"></th>
</tr>
<tr>
<td>
<input type='checkbox' id="toggle" name="toggle" onClick="toggle(this)"> Exibição:
</td>
<td>
<form role="form" action="usuarios.php" method="POST">
<select style="font-weight:bold" id="filtro" name="filtro" class="form-control" onchange="this.form.submit();">
<option <?php if ($filtro == 0 ){echo "selected";}?> value="0">Todos</option>
<option <?php if ($filtro == 2 ){echo "selected";}?> value="2">Bolsistas</option>
<option <?php if ($filtro == 3 ){echo "selected";}?> value="3">Professores</option>
</select>
</form>
</td>
<td>
<a data-toggle='modal' href='#modal_excUsuarioMultiplos' class='abre-excluirModal'>
<button type="button" id="exc" class="btn btn-primary" onclick="getCheckboxValues(this); return false;">
<i class='glyphicon glyphicon-remove'></i> Excluir
</button>
</a>
</td>
</tr>
</table>
<div class="table-responsive">
<table id="" class="table table-striped table-hover ">
<p>
<tr>
<th></th>
<th colspan="3">Operações</th>
<th>Matrícula</th>
<th>Nome</th>
<th>Tipo de usuário</th>
<th>Email</th>
<th>Data de atualização</th>
</tr>
<tbody>
<?php
$listaUser = new Usuario;
$result = $listaUser->listarUsuarios($_SESSION['matricula'], $filtro);
if (is_array($result)) {
foreach ($result as $row) {
if ($row['tipo_usuario'] == 2){
$tipo = "Bolsista";
} if ( $row['tipo_usuario'] == 3){
$tipo = "Professor";
}
if($row['data_atualizacao']===null){echo "<tr id='fooTr'class='danger'>";} else echo "<tr id='fooTr'>";
echo "
<td><input type='checkbox' name='foo[]' id='foo[]' value='".$row['matricula']."'></td>
<td>
<a title='Ver usuário' href='verUsuario.php?m=".$row['matricula']."' >
<i class='glyphicon glyphicon-search'></i>
</a>
</td>
<td>
<a title='Editar usuário' href='alterarUsuario.php?m=".$row['matricula']."' >
<i class='glyphicon glyphicon-pencil'></i>
</a>
</td>
<td>
<a title='Excluir usuário' data-toggle='modal' data-id='".$row['matricula']."' href='#modal_excUsuarioSimples' class='abre-excluirModal'>
<i class='glyphicon glyphicon-remove'></i>
</a>
</td>
<td>" . $row['matricula'] . "</td>
<td>". $row['nome'] . " ".$row['sobrenome']."</td>
<td>" . $tipo . "</td>
<td>" . $row['email'] . "</td>
<td>"; if ($row['data_atualizacao']===null){echo "Pendente";} else {echo date('d/m/Y', strtotime($row['data_atualizacao']));} echo "</td>
</tr>";
}
} else echo
" <tr>
<td></td>
<td>". $result."</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>";
unset($listaUser);
?>
</tbody>
</table>
</div>
</div>
</div><!-- /.row -->
<div class='modal fade' id='modal_excUsuarioMultiplos' tabindex='-1' role='dialog' aria-labelledby='modal_excUsuarioMultiplosLabel' aria-hidden='true'>
<div class='modal-dialog'>
<div class='modal-content panel-danger'>
<div class='modal-header panel-heading'>
<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
<h4 class='modal-title' id='modal_excUsuarioLabel'>Os usuários serão excluídos</h4>
</div>
<div class='modal-body'>
Você realmente deseja excluir as contas relacionada às seguintes matrículas?
<div id="linhas">
<?php
echo
"<script>
function getCheckboxValues() {
var values = [];
var matriculas = document.getElementsByName('foo[]');
var cont = 0;
for (var i=0, iLen=matriculas.length; i<iLen; i++) {
if (matriculas[i].checked) {
values[i]= matriculas[i].value;
cont++;
}
}
$('#linhas').html('');
for (i=0;i<values.length; i++){
$('#linhas').append(values[i]+'<br>');
}
}
</script>";
?>
</div>
</div>
<div class="modal-footer">
<form id="confirm" method="post" action="usuarios.php">
<button type="button" class="btn btn-default" data-dismiss="modal">Não</button>
<button id="submit-modal" class="btn btn-danger">Sim</button>
</form>
</div>
</div>
</div>
</div>
<div class='modal fade' id='modal_excUsuarioSimples' tabindex='-1' role='dialog' aria-labelledby='modal_excUsuarioSimplesLabel' aria-hidden='true'>
<div class='modal-dialog'>
<div class='modal-content panel-danger'>
<div class='modal-header panel-heading'>
<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
<h4 class='modal-title' id='modal_excUsuarioLabel'>O usuário será excluído</h4>
</div>
<div class='modal-body'>
Você realmente deseja excluir a conta relacionada à matrícula?
</div>
<div class="modal-footer">
<form id="confirm" method="post" action="usuarios.php">
<input type="hidden" name="matUsuario" id="matUsuario" value=""/>
<button type="button" class="btn btn-default" data-dismiss="modal">Não</button>
<button id="submit-modal" class="btn btn-danger">Sim</button>
</form>
</div>
</div>
</div>
</div>
</div><!-- /#page-wrapper -->
</div><!-- /#wrapper -->
<script language="JavaScript">
$(document).ready(function() {
var $submit = $("#exc").hide(),
$cbs = $('input[name="foo[]"]').click(function() {
$submit.toggle( $cbs.is(":checked") );
var count=0;
checkboxes = document.getElementsByName('foo[]');
for (var i=0, n=checkboxes.length;i<n;i++) {
if(checkboxes[i].checked)
{
count = count+1;}
}
if (count!=checkboxes.length) { $("#toggle").prop('checked',false);}
else{ $("#toggle").prop('checked',true);}
});
});
function toggle(source) {
checkboxes = document.getElementsByName('foo[]');
for (var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}$("#exc").toggle('show');
}
window.addEventListener("DOMContentLoaded", function () {
var confirm = document.getElementById("confirm");
document.getElementById("submit-modal").addEventListener("click", function () {
confirm.submit();
});
});
$(document).on("click", ".abre-excluirModal", function () {
var matUser = $(this).data('id');
$(".modal-footer #matUsuario").val(matUser);
});
</script>
</body>
</html>