-
Notifications
You must be signed in to change notification settings - Fork 1
/
reports_action.php
363 lines (328 loc) · 11.5 KB
/
reports_action.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
352
353
354
355
356
357
358
359
360
361
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Visitor Reports</title>
<style>
body{font-family:Sans-Serif;}
canvas{position:absolute; left: -9999em;}
#button{background-color: Yellow; color: Red; padding: 3px 10px; cursor:pointer; display: inline-block; border-radius: 5px;}
#mandatory{background-color: Green; color: Red; padding: 3px 10px; cursor:pointer; display: inline-block; border-radius: 5px;}
#preview{margin: 20px 0;}
label{display: block;}
/*
td {white-space:nowrap}
*/
th {white-space:nowrap}
</style>
<link rel="stylesheet" type="text/css" href="css/view.css" media="all">
<link rel="stylesheet" href="css/zdnet.css">
<link rel="stylesheet" href="css/slimbox2.css" type="text/css" media="screen" />
<script type="text/javascript" src="js/view.js"></script>
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="js/slimbox2.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="js/bootstrap.min.js"></script>
</head>
<body id="main_body" class="appnitro">
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
require_once 'meekrodb.2.2.class.php';
require_once("common.php");
?>
<div id="wide_container">
<?php
display_menu_common("Reports");
global $results;
require_once("parse_config.php");
require_once("common_lib.php"); // TODO: still not sanitized
$ini_array = parse_config();
DB::$user = $ini_array["username"];
DB::$password = $ini_array["password"];
DB::$dbName = $ini_array["db"];
DB::$host = $ini_array["host"];
#DB::$port = '12345'; // defaults to 3306 if omitted
#DB::$encoding = 'utf8'; // defaults to latin1 if omitted
$max_report_search_results = $ini_array["max_report_search_results"];
#$is_debug = true;
if (isset($is_debug) && $is_debug) {
echo "<table>";
// display details before inserting
foreach ($_REQUEST as $key => $value) {
$value = sanitize($value);
echo "<tr>";
echo "<td>";
echo $key;
echo "</td>";
echo "<td>";
echo $value;
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
$is_condition_present = false;
foreach($_REQUEST as $name=>$value){
$value = sanitize($value);
switch($name){
case "start_date":
if (!empty($_REQUEST["start_date"])) {
if (strstr($value, "/")) {
list($st_dd,$st_mm,$st_yyyy) = explode("/",$value);
} else if (strstr($value, "-")) {
list($st_dd,$st_mm,$st_yyyy) = explode("-",$value);
}
//$swizzled_value = $st_yyyy.$st_mm.$st_dd;
$swizzled_value = $st_yyyy.$st_mm.$st_dd."235959";
$arrFields[] = "vitime >= '".$swizzled_value."'";
$is_condition_present = true;
}
break;
case "end_date":
if (!empty($_REQUEST["end_date"])) {
if (strstr($value, "/")) {
list($end_dd,$end_mm,$end_yyyy) = explode("/",$value);
} else if (strstr($value, "-")) {
list($end_dd,$end_mm,$end_yyyy) = explode("-",$value);
}
//list($end_dd,$end_mm,$end_yyyy) = explode("/",$value);
//$swizzled_value = $end_yyyy.$end_mm.$end_dd;
$swizzled_value = $end_yyyy.$end_mm.$end_dd."235959";
$arrFields[] = "vitime <= '".$swizzled_value."'";
$is_condition_present = true;
}
break;
case "vehicle_reg_num":
if (!empty($_REQUEST["vehicle_reg_num"])) {
$arrFields[] = "vvehicle_reg_num LIKE '%".$value."%'";
$is_condition_present = true;
}
break;
case "block":
if (!empty($_REQUEST["block"])) {
$arrFields[] = "vblock LIKE '%".$value."%'";
$is_condition_present = true;
}
break;
case "flat_num":
if (!empty($_REQUEST["flat_num"])) {
$arrFields[] = "vflatnum LIKE '%".$value."%'";
$is_condition_present = true;
}
break;
case "purpose":
if (!empty($_REQUEST["purpose"])) {
$arrFields[] = "vpurpose = '" . $value ."'";
$is_condition_present = true;
}
break;
case "submit":
break;
case "form_id":
break;
}
}
/*
if (empty($arrFields) || count($arrFields) == 0) {
echo "Too few selectors to Match. Try <a href=\"find.php\">Searching Again</a> or <a href=\"visitor.php\">Register new Visitor</a>\n.";
exit(1);
}
*/
//$query = "SELECT DISTINCT(visitor.vid),vname,vphone,vcomments,vctime,vblock,vflatnum,vvehicle_reg_num FROM visitor,vrecord WHERE vrecord.vid=visitor.vid AND ".implode(" AND ",$arrFields);
//searching for only certain vrecords
//SELECT (visitor.vid),vrecordid,vname,vphone,vctime,vblock,vflatnum,vvehicle_reg_num FROM visitor,vrecord WHERE vrecord.vid=visitor.vid AND vrecordid>23;
//searching for records where visitor photo exists
//SELECT (visitor.vid),vrecordid,vname,vphone,vctime,vblock,vflatnum,vvehicle_reg_num FROM visitor,vrecord WHERE vrecord.vid=visitor.vid AND visitor.vphoto <>'';
//$query = "SELECT visitor.vid,vitime,vname,vphone,vctime,vblock,vflatnum,vtomeet,vvehicle_reg_num,vpurpose,vcomments FROM visitor,vrecord WHERE vrecord.vid=visitor.vid ";
//$query = "SELECT visitor.vid,vitime,vname,vphone,vctime,vblock,vflatnum,vtomeet,vvehicle_reg_num,vvehicle_type,vpurpose,vcomments FROM visitor,vrecord WHERE vrecord.vid=visitor.vid ";
$query = "SELECT visitor.vid,vgate,vitime,votime,vname,vphone,vctime,vblock,vflatnum,vtomeet,vvehicle_type,vvehicle_reg_num,vpurpose,vcomments FROM visitor,vrecord WHERE vrecord.vid=visitor.vid ";
if (isset($arrFields)) {
$query .= "AND ".implode(" AND ",$arrFields);
}
$query .= " LIMIT " . $max_report_search_results;
if (isset($is_debug) && $is_debug) {
echo "<br>\n$query<br>\n";
//exit;
if (isset($arrFields)) {
$is_first_criteria = true;
echo "Searching for records where ";
foreach ($arrFields as $criteria) {
if ($is_first_criteria) {
echo $criteria;
$is_first_criteria = false;
} else {
echo "AND ".$criteria;
}
}
}
echo "\n<BR>\n";
} else {
if ($is_condition_present) {
echo "Searching for records";
}
if (!empty($_REQUEST["block"])) {
echo " in block ".$_REQUEST["block"];
}
if (!empty($_REQUEST["flat_num"])) {
echo " in flat number ".$_REQUEST["flat_num"];
}
if (!empty($_REQUEST["vehicle_reg_num"])) {
echo " with vehicle number ".$_REQUEST["vehicle_reg_num"];
}
if (!empty($_REQUEST["start_date"])) {
if (strstr($_REQUEST["start_date"], "/")) {
list($st_dd,$st_mm,$st_yyyy) = explode("/",$_REQUEST["start_date"]);
} else if (strstr($_REQUEST["start_date"], "-")) {
list($st_dd,$st_mm,$st_yyyy) = explode("-",$_REQUEST["start_date"]);
}
//list($st_dd,$st_mm,$st_yyyy) = explode("/",$_REQUEST["start_date"]);
echo " after $st_dd.$st_mm.$st_yyyy";
}
if (!empty($_REQUEST["start_date"]) && (!empty($_REQUEST["end_date"]))) {
echo " and";
}
if (!empty($_REQUEST["end_date"])) {
if (strstr($_REQUEST["end_date"], "/")) {
list($end_dd,$end_mm,$end_yyyy) = explode("/",$_REQUEST["end_date"]);
} else if (strstr($_REQUEST["end_date"], "-")) {
list($end_dd,$end_mm,$end_yyyy) = explode("-",$_REQUEST["end_date"]);
}
//list($end_dd,$end_mm,$end_yyyy) = explode("/",$_REQUEST["end_date"]);
echo " ending not later than $end_dd.$end_mm.$end_yyyy" ;
}
echo "\n<BR>\n";
}
$results = DB::query($query);
$counter = DB::count();
if ($counter <= 0) {
echo "No Match. Try <a href=\"reports.php\">searching again</a>\n.";
} else {
echo $counter;
if ($counter >= $max_report_search_results) {
echo "(Maxlimit Reached) ";
}
echo " matches found. ";
echo "Click here to <a href=\"reports.php\">search again</a>\n.";
echo "<BR>\n";
}
$is_table_header_printed = false;
$row_num = 1;
//echo "\n<table cellpadding=\"0\" cellspacing=\"0\" width=\"33%\">";
echo "\n<table id=\"reports_action\" class=\"table-striped\" cellpadding=\"0\" cellspacing=\"0\" border=\"1\" style=\"font-size:65%;\">";
foreach ($results as $row) {
//echo "\n<table cellpadding=\"0\" cellspacing=\"0\" width=\"33%\">";
if ($is_table_header_printed == false) {
echo "\n<tr>\n";
if (isset($is_show_selector) && ($is_show_selector)) {
echo "<th>Selector</th>\n";
}
foreach ($row as $key => $value) {
$value = trim($value);
//if ($key == "vid") {
// echo "<th style=\"display:none;\">";
// echo $key;
// echo "<\th>\n";
//}
if ($key=="vctime") {
// do not print this field
continue;
}
if ($key=="vvehicle_type") {
//will be shown in the vehicle number column
continue;
}
//strip the first 'v' from each header name
//so vitime become itime
// replace underscores with spaces
// and then uppercase first letter of each word
$new_key = ucwords(str_replace('_', ' ', substr($key, 1)));
echo "<th>".$new_key."</th>\n";
}
echo "</tr>\n";
$is_table_header_printed = true;
}
// make a temp copy of vehicle type and remove the key
// since keeping the key causes issues
$tmp_vehicle_type = $row["vvehicle_type"];
unset($row["vvehicle_type"]);
#print_r($row);
echo "<tr>\n";
if (isset($is_show_selector) && ($is_show_selector)) {
echo "<td><input type=\"submit\" value=\"ShowPic\"></td>\n";
}
foreach ($row as $key => $value) {
$value = trim($value);
if ($key == "vgate") {
echo "<td>";
echo interpret_gate($value);
echo "</td>";
} else if ($value == "0") {
echo "<td></td>";
} else if ($key=="vname") {
//echo "<td><a href=\"find_action.php?phone_num=".$row['vphone']."\" >$value</a></td>";
$row['vname'] = ucwords($row['vname']);
$pic_title = $row['vname'];
echo "<td><a href=\"disp_photo.php?vid=".$row['vid']."\" rel=\"lightbox-pic\" title=\"".$pic_title."\">".$row['vname']."</a></td>\n";
} else if ($key=="vphone") {
echo "<td><a href=\"find_action.php?phone_num=".$row['vphone']."\" >$value</a></td>";
} else if ($key=="vctime") {
//do not print creation time
continue;
} else if (strpos($key,'itime') !== false) {
$weekday = get_weekday_by_date($value);
$value .= " " . $weekday;
//echo "<td>". $value . " " . $weekday . "</td>";
echo "<td>";
echo "<span title=\"".$row['vctime']."\">$value</span>";
echo "</td>";
} else if ($key=="vid") {
echo "<td>$row_num</td>";
} else if ($key=="vvehicle_reg_num") {
$value = strtoupper($value);
$img_size = 12;
echo "<td>";
echo get_image_by_vehicle_type($tmp_vehicle_type,$img_size);
echo $value;
echo "</td>";
} else if ($key=="vcomments") {
//echo "<td class=\"report_result\">$value</td>";
echo "<td class=\"report_result\" id=\"report_result\">$value</td>";
} else {
$value = ucwords($value);
echo "<td>$value</td>";
//echo "<td><input type=\"text\" name=\"".$key."\" value=\"". $value."\" readonly /></td>";
//echo "<td style=\"max-width: 150px;word-wrap: break-word;\">$value</td>";
//echo "<td class=\"report_result\" id=\"report_result\">$value</td>";
//echo "<td class=\"report_result\">$value</td>";
}
echo "\n";
}
$row_num++;
echo "</tr>\n";
//echo "<td><input type=\"submit\" value=\"Change\"></td>\n";
//echo "<td><input type=\"submit\" value=\"Delete\"></td>\n";
//echo "</tr>\n</table>\n";
//echo "</form>\n\n";
}
echo "</tr>\n</table>\n";
?>
</div>
<script> function goBack() { window.history.back() } </script>
<form>
<input type="button" value="Print this page" onClick="window.print()">
</form>
<form name="excel" method="post" action="export_xls.php">
<button type="submit" value="Submit">Export to Excel</button>
</form>
<form name="pdf" method="post" action="export_pdf.php">
<button type="submit" value="Submit">Export to PDF</button>
</form>
<button onclick="goBack()">Go Back and make Changes</button>
</body>
</html>