-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcad-log-frame.php
298 lines (254 loc) · 9.02 KB
/
cad-log-frame.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
<?php
$subsys="cad";
require_once('db-open.php');
include('local-dls.php');
require_once('session.inc');
require_once('functions.php');
// Prepare page GET/POST input
$filterdate = '';
$filterhour = '';
$filterunit = '';
$filtermpp = '';
$start = '';
// If apply was POSTed...
if (isset($_POST['apply_filters'])) {
if ($_POST['date'] != "") {
$filterdate = MysqlClean($_POST, 'date', 20);
}
if ($_POST['hour'] != "") {
$filterhour = MysqlClean($_POST, 'hour', 5);
}
if ($_POST['funit'] != "") {
$filterunit = MysqlClean($_POST, 'funit', 100);
}
if ($_POST['mpp'] != "") {
$filtermpp = MysqlClean($_POST,'mpp',10);
}
}
// 'owever... if the remove filters button was posted, reset all filters (redundant now that we're setting before assigning to, rev 185)
elseif (isset($_POST['remove_filters'])) {
$filterdate = '';
$filterhour = '';
$filterunit = '';
$filtermpp = '';
}
// Otherwise, process GETs
else {
if (isset ($_GET['date']) && $_GET['date'] != "") {
$filterdate = MysqlClean($_GET,'date',20);
}
if (isset ($_GET['hour']) && $_GET['hour'] != "") {
$filterhour = MysqlClean($_GET,'hour',5);
}
if (isset ($_GET['unit']) && $_GET['unit'] != "") {
$filterunit = MysqlClean($_GET,'unit',100);
}
if (isset ($_GET['mpp']) && $_GET['mpp'] != "") {
$filtermpp = MysqlClean($_GET,'mpp',10);
}
if (isset ($_GET['start']) && $_GET['start'] != "") {
$start = MysqlClean($_GET,'start',10);
}
}
// Set default MPP
if (!isset($filtermpp)) $filtermpp = 10;
// Prepare refreshURI
$refreshURI = $_SERVER["PHP_SELF"]."?".
"date=$filterdate&hour=$filterhour&unit=$filterunit&mpp=$filtermpp&start=$start";
header_html("Dispatch :: Log Viewer"," <base target=\"_parent\">",$refreshURI);
?>
<body vlink="blue" link="blue" alink="cyan">
<!-- Begin Log Messages Outer Table -->
<table width="100%">
<tr>
<td bgcolor="#aaaaaa">
<!-- Begin Log Messages Inner Table -->
<table width="100%" cellpadding="1" cellspacing="1">
<tr>
<?php
if (!isset($_COOKIE['cad_show_creator']) || $_COOKIE['cad_show_creator'] == 'yes') {
print ' <td bgcolor="#cccccc" class="text" nowrap><font color="gray">Logged By</font></td>';
}
print " <td bgcolor=\"#cccccc\" class=\"text\"><b>Time</b></td>\n";
print " <td bgcolor=\"#cccccc\" class=\"text\"><b>Unit</b></td>\n";
if ($USE_MESSAGE_TYPE) {
if (!isset($_COOKIE['cad_show_message_type']) || $_COOKIE['cad_show_message_type'] == 'yes') {
print ' <td bgcolor="#cccccc" class="text"><b>Type</b></td>';
}
}
print " <td width=\"100%\" bgcolor=\"#cccccc\" class=\"text\"><b>Message</b></td>\n";
?>
</tr>
<?php
// Prepare unit query
$unitquery = "SELECT unit,status,role FROM units";
$unitresult = MysqlQuery($unitquery);
while ($unitrow = mysql_fetch_array($unitresult, MYSQL_ASSOC)) {
$unitExists[$unitrow["unit"]] = 1;
$unitstatus[$unitrow["unit"]] = $unitrow["status"];
$unitrole[$unitrow["unit"]] = $unitrow["role"];
}
mysql_free_result($unitresult);
// Prepare unit color query
$unitcolorquery = "SELECT role, color_html FROM unit_roles";
$unitcolorresult = MysqlQuery($unitcolorquery);
while ($line = mysql_fetch_array($unitcolorresult, MYSQL_ASSOC)) {
$unitrolecolor[$line["role"]] = $line["color_html"];
}
mysql_free_result($unitcolorresult);
// Prepare main query
// Start query string
$logquery = "SELECT * FROM messages WHERE deleted=0";
// Prepare date/hour filter
if (!empty($filterhour)) {
if ($filterhour < 9) {
$filterhourpadded = "0$filterhour";
}
else {
$filterhourpadded = $filterhour;
}
}
if (!empty($filterdate) && !empty($filterhour)) {
$logquery .= " AND DATE_FORMAT(ts, '%Y-%m-%d %H') = '$filterdate $filterhourpadded'";
}
elseif (!empty($filterdate)) {
$logquery .= " AND DATE_FORMAT(ts, '%Y-%m-%d') = '$filterdate'";
}
elseif (!empty($filterhour)) {
$logquery .= " AND DATE_FORMAT(ts, '%H') = '$filterhourpadded'";
}
// Prepare unit filter
if (!empty($filterunit)) {
$logquery .= " AND unit = '$filterunit'";
}
// Prepare order direction
$logquery .= " ORDER BY oid DESC";
// Prepare count of how many total results this query would return
$howmanyquery = $logquery;
$howmanyquery = str_replace("SELECT *", "SELECT COUNT(*) AS howmany", $howmanyquery);
// Prepare start and limit
if (!empty($filtermpp)) {
if (!empty($start)) {
$logquery .= " LIMIT $start, $filtermpp";
}
else {
$logquery .= " LIMIT $filtermpp";
}
}
// Issue Query
$logresult = MysqlQuery($logquery);
$td = " <td class=\"message\">";
// MAIN DISPLAY TABLE
if (mysql_num_rows($logresult) > 0) {
for ($i=1; $line = mysql_fetch_array($logresult, MYSQL_ASSOC); $i++) {
((int)THIS_PAGETS - date("U", strtotime($line["ts"]))) < 300 ? $quality="<b>" : $quality="";
echo "<tr>\n";
if (!isset($_COOKIE['cad_show_creator']) || $_COOKIE['cad_show_creator'] == 'yes') {
if (isset($line["creator"]) && $line["creator"] != "NULL" && $line["creator"] != "") {
echo $td, "<font color=\"gray\">", $line["creator"], "</font></td>\n";
} else {
echo $td, "</td>\n";
}
}
echo $td, $quality, dls_utime($line["ts"]), "</td>\n";
if (isset($unitExists[$line["unit"]])) {
echo $td,
$quality,
"<a href=\"edit-unit.php?unit=",$line["unit"],"\" onClick=\"return popup('edit-unit.php?unit=".$line["unit"]."','unit',500,700)\" TARGET=\"_blank\">";
if ($unitstatus[$line["unit"]] == "Off Duty" ||
$unitstatus[$line["unit"]] == "Out of Service" ||
$unitstatus[$line["unit"]] == "Off Playa") {
echo "<span style='color: gray;'>", dls_ustr($line["unit"]), "</span>";
}
elseif ( ((isset($_COOKIE["units_color"]) && $_COOKIE["units_color"] == "yes") ||
!isset($_COOKIE["units_color"]))
&&
isset($unitrolecolor[$unitrole[$line["unit"]]])) {
echo "<span style='color: ", $unitrolecolor[$unitrole[$line["unit"]]], ";'>", dls_ustr($line["unit"]), "</span>";
}
else {
echo dls_ustr($line["unit"]);
}
echo "</a></td>\n";
}
else {
echo $td, $quality, dls_ustr($line["unit"]), "</td>\n";
}
if ($USE_MESSAGE_TYPE) {
if (!isset($_COOKIE['cad_show_message_type']) || $_COOKIE['cad_show_message_type'] == 'yes') {
if (isset($line["message_type"]) && $line["message_type"] != "NULL" && $line["message_type"] != "") {
echo $td, "<font color=\"gray\">", $line["message_type"], "</font></td>\n";
} else {
echo $td, "</td>\n";
}
}
}
echo $td, "\n <table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n";
echo " <tr><td align=left class=\"message\">", $quality, $line["message"], "</td>\n";
echo " <td align=right><a href=\"edit-message.php?oid=".$line["oid"]."\" onClick=\"return popup('edit-message.php?oid=".$line["oid"]."', 'edit-message', 200, 900)\" TARGET=\"_blank\"><font color=\"gray\" size=\"-2\">[edit]</font></a></td>\n";
echo " </tr>\n </table>\n </td>\n";
echo "</tr>\n\n";
}
}
else {
echo "<tr>\n";
echo "<td class=\"message\" colspan=5>",
"<font color=\"gray\" size=\"-1\">No logged messages based on current filters</font>";
echo "</tr>\n";
}
?>
</table>
<!-- End Log Messages Inner Table -->
</tr>
</table>
<!-- End Log Messages Outer Table -->
<?php
// Issue Howmany Query
$howmanyresult = MysqlQuery($howmanyquery);
$howmanyline = mysql_fetch_array($howmanyresult);
$howmany = $howmanyline['howmany'];
// Print page back / page forward links
echo "<center class=\"text\" style=\"margin-top: 8px;\">";
$prevpage = $start - $filtermpp;
if ($filtermpp > 0 && $start >= $filtermpp) {
echo "<a href=\"".$_SERVER["PHP_SELF"].
"?date=$filterdate&hour=$filterhour&unit=$filterunit&mpp=$filtermpp".
"&start=$prevpage".
"\" TARGET=\"log\"><<</a> | ";
}
else {
echo "<< | ";
}
echo "<a href=\"".$_SERVER["PHP_SELF"].
"?date=$filterdate&hour=$filterhour&unit=$filterunit&mpp=$filtermpp".
"\" TARGET=\"log\">First Page</a> | ";
if ($filtermpp > 0) {
$pages = ceil($howmany / $filtermpp);
}
else {
$pages = 1;
}
echo "Current filter will display $howmany message";
if ($howmany != 1) echo "s";
echo " on $pages page";
if ($pages != 1) echo "s";
echo " | ";
$nextpage = $start + $filtermpp;
if ($filtermpp > 0 && $nextpage < $howmany) {
echo "<a href=\"".$_SERVER["PHP_SELF"].
"?date=$filterdate&hour=$filterhour&unit=$filterunit&mpp=$filtermpp".
"&start=$nextpage".
"\" TARGET=\"log\">>></a>";
}
else {
echo ">>";
}
echo "</center>\n";
mysql_free_result($howmanyresult);
?>
<?php
mysql_free_result($logresult);
mysql_close($link);
?>
</body>
</html>