log_acessos.php
11.5 KB
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
<?
/*
Copyright 2000, 2001, 2002, 2003, 2004, 2005 Dataprev - Empresa de Tecnologia e Informações da Previdência Social, Brasil
Este arquivo é parte do programa CACIC - Configurador Automático e Coletor de Informações Computacionais
O CACIC é um software livre; você pode redistribui-lo e/ou modifica-lo dentro dos termos da Licença Pública Geral GNU como
publicada pela Fundação do Software Livre (FSF); na versão 2 da Licença, ou (na sua opnião) qualquer versão.
Este programa é distribuido na esperança que possa ser util, mas SEM NENHUMA GARANTIA; sem uma garantia implicita de ADEQUAÇÂO a qualquer
MERCADO ou APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU para maiores detalhes.
Você deve ter recebido uma cópia da Licença Pública Geral GNU, sob o título "LICENCA.txt", junto com este programa, se não, escreva para a Fundação do Software
Livre(FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
session_start();
/*
* verifica se houve login e também regras para outras verificações (ex: permissões do usuário)!
*/
if(!isset($_SESSION['id_usuario']))
die('Acesso negado!');
else { // Inserir regras para outras verificações (ex: permissões do usuário)!
}
include_once "../include/library.php";
// Comentado temporariamente - AntiSpy();
if (!$_REQUEST['date_input1'])
{
$from_usuarios = '';
$where_usuarios = '';
if ($_SESSION['cs_nivel_administracao']<>1 && $_SESSION['cs_nivel_administracao']<>2)
{
$from_usuarios = ', usuarios b';
$where_usuarios = ' AND a.id_usuario = b.id_usuario AND b.id_local = '.$_SESSION['id_local'];
if ($_SESSION['te_locais_secundarios'])
{
$where_usuarios = str_replace('b.id_local',' (b.id_local',$where_usuarios);
$where_usuarios .= ' OR (b.id_local IN ('.$_SESSION['te_locais_secundarios'].'))) ';
$whereLocais = ' WHERE id_local = '.$_SESSION['id_local'].' OR id_local IN ('.$_SESSION['te_locais_secundarios'].') ';
}
}
conecta_bd_cacic();
$query_minmax = 'SELECT DATE_FORMAT(min(a.dt_acao), "%d/%m/%Y") as minima,
DATE_FORMAT(max(a.dt_acao), "%d/%m/%Y") as maxima
FROM log a '.
$from_usuarios . '
WHERE cs_acao = "ACE" '.
$where_usuarios;
$result_minmax = mysql_query($query_minmax);
$row_minmax = mysql_fetch_array($result_minmax);
$date_input1 = date('d/m/Y');
$date_input2 = date('d/m/Y');
}
else
{
$date_input1 = $_REQUEST['date_input1'];
$date_input2 = $_REQUEST['date_input2'];
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" type="text/css" href="../include/cacic.css">
<title>Log de Atividades</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?
// JavaScripts para fazer a selecao entre os listbox, movendo itens entre eles.
require_once('../include/selecao_listbox.js');
?>
</head>
<body background="../imgs/linha_v.gif">
<script language="JavaScript" type="text/javascript" src="../include/cacic.js"></script>
<form name="form1" method="post" action="">
<table width="90%" border="0" align="center">
<tr>
<td class="cabecalho"><div align="left">Log de Acessos</div></td>
</tr>
<tr>
<td class="descricao">Este módulo permite a visualização
dos acessos efetuados no sistema. É possível visualizar
as atividades executadas pelo usuário na data, bastando clicar
sobre uma de suas informações.</td>
</tr>
</table>
<p><br></p>
<table width="90%" border="0" cellpadding="0" cellspacing="1" align="center">
<tr>
<td class="label" colspan="3">Selecione o período em que deverá
ser realizada a consulta:</td>
</tr>
<tr>
<td height="1" bgcolor="#333333" colspan="2"></td>
</tr>
<tr valign="middle">
<td width="33%" height="1" nowrap valign="middle">
<input name="whereLocais" type="hidden" value="<? echo $whereLocais;?>">
<input name="date_input1" type="text" size="10" class="normal" onFocus="SetaClassDigitacao(this);" onBlur="SetaClassNormal(this);" value="<? echo $date_input1;?>">
<? /*
<script type="text/javascript" language="JavaScript">
<!--
function calendar1Callback(date, month, year)
{
document.forms['form1'].date_input1.value = date + '/' + month + '/' + year;
}
calendar1 = new dynCalendar('calendar1', 'calendar1Callback');
//-->
</script>*/?> <font size="2" face="Verdana, Arial, Helvetica, sans-serif">a</font>
<input name="date_input2" type="text" size="10" class="normal" onFocus="SetaClassDigitacao(this);" onBlur="SetaClassNormal(this);" value="<? echo $date_input2;?>">
<? /*
<script type="text/javascript" language="JavaScript">
<!--
function calendar2Callback(date, month, year)
{
document.forms['form1'].date_input2.value = date + '/' + month + '/' + year;
}
calendar2 = new dynCalendar('calendar2', 'calendar2Callback');
//-->
</script>*/?> </td>
<td align="left" class="descricao"> (formato: dd/mm/aaaa)</td>
<td rowspan="2" align="left" valign="middle" class="descricao"><div align="center">
<input name="consultar" type="submit" value=" Filtrar " onClick="SelectAll(this.form.elements['list12[]'])">
</div></td>
</tr>
<?
if ($_SESSION['cs_nivel_administracao'] == 1 || $_SESSION['cs_nivel_administracao'] == 2 || ($_SESSION['cs_nivel_administracao'] == 3 && $_SESSION['te_locais_secundarios']<>''))
{
?>
<TR><td height="20"></td></TR>
<tr valign="middle">
<td height="1" colspan="2" valign="middle" nowrap><div align="left">
<?
include_once "../include/selecao_locais_inc.php";
?></div>
</td></tr>
<?
}
?>
<tr>
<td height="1" bgcolor="#333333" colspan="2"></td>
</tr>
</table>
<?
if ($_REQUEST['date_input1'])
{
$msg = '<div align="center">
<font color="red" size="1" face="Verdana, Arial, Helvetica, sans-serif">
Nenhum acesso realizado no período informado.</font><br><br></div>';
$where_usuarios = '';
if ($_SESSION['cs_nivel_administracao']<>1 && $_SESSION['cs_nivel_administracao']<>2)
{
$where_usuarios = ' AND b.id_local = '.$_SESSION['id_local'];
}
else
{
$itens_locais = '';
for ($i =0; $i < count($_POST['list12']);$i++)
{
if ($itens_locais)
$itens_locais .= ',';
$itens_locais .= $_POST['list12'][$i];
}
$where_usuarios = ' AND b.id_local IN ('.$itens_locais.')';
}
$OrderBy = ($_GET['OrderBy']<>''?$_GET['OrderBy']:'1');
$OrderBy = ($OrderBy=='1'?$OrderBy . ' DESC ':$OrderBy);
conecta_bd_cacic();
$query = 'SELECT DATE_FORMAT(a.dt_acao, "%y-%m-%d %H:%i") as dt_acao,
b.nm_usuario_completo,
a.te_ip_origem,
a.cs_acao,
b.id_usuario,
c.sg_local
FROM log a,
usuarios b,
locais c
WHERE a.id_usuario = b.id_usuario AND
b.id_local = c.id_local AND
a.dt_acao between "' . substr($_REQUEST['date_input1'],-4)."/".substr($_REQUEST['date_input1'],3,2)."/".substr($_REQUEST['date_input1'],0,2).' 00:00" AND "' . substr($_REQUEST['date_input2'],-4)."/".substr($_REQUEST['date_input2'],3,2)."/".substr($_REQUEST['date_input2'],0,2). ' 23:59" AND
a.cs_acao = "ACE" '.
$where_usuarios . '
ORDER BY '.$OrderBy;
$result = mysql_query($query);
$NumRegistro = mysql_num_rows($result);
if ($NumRegistro)
{
$msg = '';
?>
<p></p>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td height="10" colspan="3"> </td>
</tr>
<tr>
<td height="10" colspan="3"></td>
</tr>
<tr>
<td height="1" colspan="3" bgcolor="#333333"></td>
</tr>
<tr>
<td colspan="3">
<table width="90%" border="0" cellpadding="2" cellspacing="0" bordercolor="#333333" align="center">
<tr bgcolor="#E1E1E1">
<td colspan="3"></td>
<td nowrap class="cabecalho_tabela"><div align="left"><a href="log_acessos.php?OrderBy=1&date_input1=<? echo $date_input1;?>&date_input2=<? echo $date_input2;?>">Data</a></div></td>
<td></td>
<td nowrap class="cabecalho_tabela"><div align="left"><a href="log_acessos.php?OrderBy=2&date_input1=<? echo $date_input1;?>&date_input2=<? echo $date_input2;?>">Usuário</a></div></td>
<td></td>
<td nowrap class="cabecalho_tabela"><div align="left"><a href="log_acessos.php?OrderBy=3&date_input1=<? echo $date_input1;?>&date_input2=<? echo $date_input2;?>">IP Origem</a></div></td>
<td></td>
</tr>
<tr>
<td height="1" colspan="9" bgcolor="#333333"></td>
</tr>
<?
$Cor = 0;
$msg = ($NumRegistro > 1?'':$msg);
$arr_cs_acao = array();
$arr_nm_script = array();
$arr_nm_tabela = array();
$arr_nm_usuario = array();
while($row = mysql_fetch_array($result))
{
list($year, $month, $day) = explode("-", $row['dt_acao']);
list($day,$hour) = explode(" ",$day);
$nm_usuario_acessos = PrimUltNome($row['nm_usuario_completo']).'/'.$row['sg_local'];
if (array_search($row['cs_acao'],$arr_cs_acao))
$arr_cs_acao[$row['cs_acao']]=1;
else
$arr_cs_acao[$row['cs_acao']]++;
$nm_script = str_replace('.php','',$row['nm_script']);
if (array_search($nm_script,$arr_nm_script))
$arr_nm_script[$nm_script]=1;
else
$arr_nm_script[$nm_script]++;
if (array_search($row['nm_tabela'],$arr_nm_tabela))
$arr_nm_tabela[$row['nm_tabela']]=1;
else
$arr_nm_tabela[$row['nm_tabela']]++;
if (array_search($nm_usuario_acessos.'#'.$row['id_usuario'],$arr_nm_usuario))
$arr_nm_usuario[$nm_usuario_acessos.'#'.$row['id_usuario']]=1;
else
$arr_nm_usuario[$nm_usuario_acessos.'#'.$row['id_usuario']]++;
?>
<tr <? if ($Cor) { echo 'bgcolor="#E1E1E1"'; } ?>>
<td nowrap></td>
<td align="left" nowrap class="opcao_tabela"><? echo $NumRegistro; ?></td>
<td nowrap></td>
<td nowrap class="opcao_tabela"><a href="log_atividades.php?nm_chamador=Log_de_Acessos&date_input1=<? echo $date_input1;?>&date_input2=<? echo $date_input2;?>&id_usuario=<? echo $row['id_usuario'];?>"><? echo $day.'/'.$month.'/'.$year. ' '. substr($hour,0,5);?></a></td>
<td nowrap></td>
<td nowrap class="opcao_tabela"><a href="log_atividades.php?nm_chamador=Log_de_Acessos&date_input1=<? echo $date_input1;?>&date_input2=<? echo $date_input2;?>&id_usuario=<? echo $row['id_usuario'];?>"><? echo $nm_usuario_acessos;?></a></td>
<td nowrap></td>
<td nowrap class="opcao_tabela"><a href="log_atividades.php?nm_chamador=Log_de_Acessos&date_input1=<? echo $date_input1;?>&date_input2=<? echo $date_input2;?>&id_usuario=<? echo $row['id_usuario'];?>"><? echo $row['te_ip_origem'];?></a></td>
<td nowrap></td>
<?
$Cor=!$Cor;
$NumRegistro--;
}
arsort($arr_cs_acao,1);
arsort($arr_nm_tabela,1);
arsort($arr_nm_script,1);
arsort($arr_nm_usuario,1);
?>
</table></td>
</tr>
<tr>
<td height="1" colspan="3" bgcolor="#333333"></td>
</tr>
<?
}
?>
<tr>
<td height="10" colspan="3"><? echo $msg;?></td>
</tr>
<tr>
<td height="10" colspan="3"> </td>
</tr>
</table>
<?
}
?>
</form>
<p> </p>
</body>
</html>