-
Notifications
You must be signed in to change notification settings - Fork 3
/
logs.php
351 lines (308 loc) · 11.1 KB
/
logs.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
<?php
session_start();
include "class/db.class.php";
$selectedPage="configure";
$logs = new logs;
// When saving a group of logs to an event
if(isset($_GET['action']) && $_GET['action'] == "save_selection" && $_POST)
{
// these are the filter items associated
if(isset($_GET['userID']) && is_numeric($_GET['userID']))
$userID=$_GET['userID'];
else
$userID='0';
if(isset($_GET['hour']) && is_numeric($_GET['hour']))
$hour=$_GET['hour'];
else
$hour='0';
// retrieve a name if one was set
$selection_title = preg_replace("/([^a-zA-z0-9- _])/",'',$_POST['selection_name']);
unset($_POST['selection_name']);
if(!$selection_title)
$selection_title="Default Selection";
// loop over all the selected values and move them into an array
$selectedLogs=array();
foreach($_POST as $selection=>$val)
{
if(is_numeric($selection))
$selectedLogs[]=$selection;
}
// pass of Woop!
if($logs->saveEvent($selection_title,$selectedLogs))
header("Location: logs.php?selection=saved&hour=$hour&userID=$userID");
else
header("Location: logs.php?selection=error&hour=$hour&userID=$userID");
exit();
}
// delete a saved event
else if(isset($_GET['action']) && $_GET['action'] == "deleteSavedEvent" && is_numeric($_GET['eventID']))
{
if($logs->deleteSavedEvent($_GET['eventID']))
header("Location: logs.php?event=deleteSaved");
else
header("Location: logs.php?error=unableToDelete");
}
else
{
$globalTopic="Logs & Saved Events";
include "theme/" . $theme . "/top.php";
// retrieve and check the values used for filtering
if(isset($_GET['userID']) && is_numeric($_GET['userID']))
$userID=$_GET['userID'];
else
$userID='0';
if(isset($_GET['hour']) && is_numeric($_GET['hour']))
$hour=$_GET['hour'];
else
$hour='0';
if(isset($_GET['search']))
$search=htmlspecialchars($_GET['search']);
else
$search='0';
?>
<script language="javascript" type="text/javascript">
$(document).ready(function()
{
$("#statusLog tbody tr td:not('#nonselect')").click(function(event) {
$(this).closest("tr").toggleClass("selected");
if( $(this).closest("tr").find(':checkbox').attr('checked') == true)
$(this).closest("tr").find(':checkbox').attr('checked',false);
else
$(this).closest("tr").find(':checkbox').attr('checked',true);
});
$("#statusLog tbody tr td input:checkbox").click(function(event) {
$(this).closest("tr").toggleClass("selected");
});
$(":input[name=selection_name]").click(function ()
{
if(this.value == this.defaultValue)
$(this).attr("value","");
});
});
</script>
<div id="main">
<div id="left">
<div class="module" id="logs">
<strong>Logs</strong>
<div id="statusLog">
<table class="dataTable">
<colgroup align="left" class="tblfirstRow"></colgroup>
<thead>
<tr>
<th scope="col" align="center" style='padding:2px 0px 0px;'>
<input type="checkbox" onclick="var checked=$('input:checkbox').attr('checked'); $('input:checkbox').attr('checked',checked);" />
</th>
<th scope="col" width="15%" >Date</th>
<th scope="col" width="77%" >Event</th>
<th scope="col" width="8%" >User</th>
</tr>
</thead>
<form action="logs.php?action=save_selection&hour=<?php echo $hour;?>&userID=<?php echo $userID;?>" method="POST">
<tbody>
<?php
$results=0;
$no_results_flag=0; // set if any filters return null results
// retrieve a saved event
if(isset($_GET['savedEvent']) && is_numeric($_GET['savedEvent']))
{
$results = $logs->getEvent($_GET['savedEvent']);
if(!$results) $no_results_flag=1;
}
if(isset($search) && $search)
{
$results = $logs->filterByTerm($search);
if(!$results) $no_results_flag=1;
}
// Determine which filters to apply
if(isset($hour) && $hour)
{
$results = $logs->filterByHour($hour);
if(!$results) $no_results_flag=1;
}
if(isset($userID) && $userID)
{
$results = $logs->filterByUser($userID);
if(!$results) $no_results_flag=1;
}
// get the variables associated with paging
if(isset($_GET['offset']) && is_numeric($_GET['offset']))
$offset=(int)$_GET['offset'];
else
$offset=0;
if(isset($_GET['limit']) && is_numeric($_GET['limit']))
$limit=(int)$_GET['limit'];
else
$limit=30;
if(!$results)
$results = $logs->getAll($limit,$offset);
// If any of the filters returned no results we don't want to loop
if($no_results_flag)
echo "<tr><td colspan=\"4\" ><i><font color=\"#b33838\" >No events were found for your search</font></i></td></tr>";
else
{
$yesterday=strtotime("-1 day");
foreach($results as $log)
{
// look for events within the last day
if($log->timestamp>$yesterday)
$highlight=' class="selected"';
else
$highlight='';
echo " <tr ".$highlight.">
<td align=\"center\" id='nonselect' ><input type=\"checkbox\" name=\"".$log->logID."\" /></td>
<td align=\"center\">".$log->eventTime."</td>
<td>".$log->event."</td>
<td align=\"center\"><a href=\"logs.php?userID=".$log->userID."\">".$log->user()->UserName."</a></td>
</tr>\n";
}
if(!$results)
echo "<tr><td colspan='4' ><i>No logged events</i></td></tr>";
echo ' </tbody>
<tfoot>
<tr>';
if(!isset($_GET['savedEvent']))
{
echo '<td colspan="4" class="tblfirstRow"><input size="35" name="selection_name" value="Event Title" /><input type="submit" value="Save Selected Events" /></a>';
if(isset($_GET['selection']) && $_GET['selection']=="saved")
echo "<br/><strong>Selection Saved</strong>
</td>";
}
else
{
echo '<td colspan="4" class="tblfirstRow" >Viewing Saved Event: <strong>'.$logs->getEventName($_GET['savedEvent']).'</strong><br/>
'."<a href=\"#\" rel=\"nofollow\" onclick=\"if (confirm('Are you sure you want to delete this saved event?')) { location.href = 'logs.php?action=deleteSavedEvent&eventID=".$_GET['savedEvent']
."'; } \">[delete]</a>
</td>";
}
?>
</tr>
<tr><td colspan='4'>
<div style='float:left;'><?php
if(($offset-$limit) >= 0)
{ ?>
<a href='?limit=<?php echo $limit.'&offset='.($offset-$limit); ?>' ><< Back </a></div>
<?php } ?>
</a></div>
<div style='float:right;'><?php
if(count($results) == $limit)
{ ?>
<a href='?limit=<?php echo $limit.'&offset='.($limit+$offset); ?>' >Forward >> </a></div>
<?php } ?>
</td></tr>
</tfoot>
<?php
}
?>
</table>
</form>
</div>
</div>
</div>
<div id="right">
<div class="module" id="menuBox">
<strong>Devices & Templates</strong>
<p>
<ul>
<li><a href="manageTemplates.php">Create a new Template</a></li>
<li><a href="templates.php">Templates List</a></li>
<li><a href="templateMover.php">Import/Export Templates</a></li>
</ul>
</p>
</div>
<div class="module" id="menuBox">
<strong>System</strong>
<p>
<ul>
<a href="cables.php" ><li>Cable Types</li></a>
<a href="metadata.php" ><li>Device Information</li></a>
<a href="owners.php" ><li>Equipment Owners</li></a>
<a href="management.php?action=accounts" ><li>User Accounts</li></a>
<a href="system.php" ><li>System</li></a>
<a href="logs.php" ><li>Logs</li></a>
<a href="templateMover.php" ><li>Import / Export Templates</li></a>
</ul>
</p>
</div>
<div class="module" id="logFilter">
<strong>Filter Results</strong>
</p>
<form action="logs.php" method="get">
<table class="formTable">
<colgroup align="left" class="tblfirstRow"></colgroup>
<?php
// Don't allow timeframe selection for saved events
// the class doesn't support this anyway (time queries are detected within the DB)
if(!isset($_GET['savedEvent']))
{
echo '<tr><td>Timeframe:</td>
<td><select name="hour" >
<option value="" ></option>
<option value="1" '; if($hour==1) { echo "SELECTED"; } echo '>1 hour</option>
<option value="12" '; if($hour==12) { echo "SELECTED"; } echo '>12 hours</option>
<option value="24" '; if($hour==24) { echo "SELECTED"; } echo '>1 day</option>
<option value="48" '; if($hour==48) { echo "SELECTED"; } echo '>2 days</option>
<option value="168" '; if($hour==168) { echo "SELECTED"; } echo '>1 week</option>
<option value="730" '; if($hour==730) { echo "SELECTED"; } echo '>1 month</option>
</select></td></tr>';
}
echo '
<tr><td>User:</td>
<td><select name="userID" >
<option value="" ></option>';
// loop over users and allow them to be selected for the filter
$users = new users;
foreach($users->getAll() as $user)
{
echo '<option value="'.$user->userID.'"';
if($userID==$user->userID)
echo "SELECTED";
echo '>'.$user->UserName;
if($user->external!='0')
echo " via ".$user->external;
echo '</option>';
}
echo '<select>';
// If we are already viewing a saved event then pass the value as a hidden value so we can filter these results
if(isset($_GET['savedEvent']) && is_numeric($_GET['savedEvent']))
echo "<input type=\"hidden\" name=\"savedEvent\" value=\"".$_GET['savedEvent']."\" />";
?></td></tr>
<tr><td>Search</td><td><input type="text" name='search' style='width: 200px' value='<?php if(isset($_GET['search'])) { echo strip_tags($_GET['search']); }?>'/></td></tr>
<tr><td></td><td><input type="submit" value="filter" /></td></tr>
<?php
if($userID || $search || $hour)
{
echo "<tr><td colspan='2' ><a href='logs.php' ><img src='images/icons/delete_small.gif' alt='Clear Search' border='0' />
<font size='1px' >Clear Search</font></a></td></tr>";
}
?>
</table>
</form>
</p>
<p>
<strong>Saved Events</strong>
</p>
<p><ul>
<a href="logs.php" ><li>All Logs</li></a>
<?php
// List all saved events for the right menu
$events = $logs->listSavedEvents();
if($events)
foreach($events as $item)
echo "<a href=\"?savedEvent=".$item['eventID']."\" ><li>".stripslashes($item['name']).'</li></a>';
?>
</ul></p> </div>
<div class="module" id="logHelp" >
<strong>Help</strong>
<p>
<i>Saved Events</i>
</p>
<p>Save a selection of logs for future viewing.
In future outlines of physical work to be completed can be generated from here.
</p>
</div>
</div>
</div>
<?php
include "theme/".$theme."/base.php";
}
?>