-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_log_up.php
140 lines (136 loc) · 5.33 KB
/
user_log_up.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
<?php
session_start();
?>
<div class="table-responsive" style="max-height: 500px;">
<table class="table">
<thead class="table-primary">
<tr>
<th>ID</th>
<th>Name</th>
<th>Registration Number</th>
<th>Fingerprint ID</th>
<th>Device Dep</th>
<th>Date</th>
<th>Time In</th>
<th>Time Out</th>
</tr>
</thead>
<tbody class="table-secondary">
<?php
//Connect to database
require'connectDB.php';
$searchQuery = " ";
$Start_date = " ";
$End_date = " ";
$Start_time = " ";
$End_time = " ";
$Finger_sel = " ";
if (isset($_POST['log_date'])) {
//Start date filter
if ($_POST['date_sel_start'] != 0) {
$Start_date = $_POST['date_sel_start'];
$_SESSION['searchQuery'] = "checkindate='".$Start_date."'";
}
else{
$Start_date = date("Y-m-d");
$_SESSION['searchQuery'] = "checkindate='".date("Y-m-d")."'";
}
//End date filter
if ($_POST['date_sel_end'] != 0) {
$End_date = $_POST['date_sel_end'];
$_SESSION['searchQuery'] = "checkindate BETWEEN '".$Start_date."' AND '".$End_date."'";
}
//Time-In filter
if ($_POST['time_sel'] == "Time_in") {
//Start time filter
if ($_POST['time_sel_start'] != 0 && $_POST['time_sel_end'] == 0) {
$Start_time = $_POST['time_sel_start'];
$_SESSION['searchQuery'] .= " AND timein='".$Start_time."'";
}
elseif ($_POST['time_sel_start'] != 0 && $_POST['time_sel_end'] != 0) {
$Start_time = $_POST['time_sel_start'];
}
//End time filter
if ($_POST['time_sel_end'] != 0) {
$End_time = $_POST['time_sel_end'];
$_SESSION['searchQuery'] .= " AND timein BETWEEN '".$Start_time."' AND '".$End_time."'";
}
}
//Time-out filter
if ($_POST['time_sel'] == "Time_out") {
//Start time filter
if ($_POST['time_sel_start'] != 0 && $_POST['time_sel_end'] == 0) {
$Start_time = $_POST['time_sel_start'];
$_SESSION['searchQuery'] .= " AND timeout='".$Start_time."'";
}
elseif ($_POST['time_sel_start'] != 0 && $_POST['time_sel_end'] != 0) {
$Start_time = $_POST['time_sel_start'];
}
//End time filter
if ($_POST['time_sel_end'] != 0) {
$End_time = $_POST['time_sel_end'];
$_SESSION['searchQuery'] .= " AND timeout BETWEEN '".$Start_time."' AND '".$End_time."'";
}
}
//Fingerprint filter
if ($_POST['fing_sel'] != 0) {
$Finger_sel = $_POST['fing_sel'];
$_SESSION['searchQuery'] .= " AND fingerprint_id='".$Finger_sel."'";
}
//Department filter
if ($_POST['dev_id'] != 0) {
$dev_id = $_POST['dev_id'];
$sql = "SELECT device_uid FROM devices WHERE id=?";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo "SQL_Error";
exit();
}
else{
mysqli_stmt_bind_param($result, "i", $dev_id);
mysqli_stmt_execute($result);
$resultl = mysqli_stmt_get_result($result);
if ($row = mysqli_fetch_assoc($resultl)) {
$dev_uid = $row['device_uid'];
}
}
$_SESSION['searchQuery'] .= " AND device_uid='".$dev_uid."'";
}
}
if ($_POST['select_date'] == 1) {
$Start_date = date("Y-m-d");
$_SESSION['searchQuery'] = "checkindate='".$Start_date."'";
}
// echo $_SESSION['searchQuery'];
// $sql = "SELECT * FROM users_logs WHERE checkindate=? AND pic_date BETWEEN ? AND ? ORDER BY id ASC";
$sql = "SELECT * FROM users_logs WHERE ".$_SESSION['searchQuery']." ORDER BY id DESC";
$result = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($result, $sql)) {
echo '<p class="error">SQL Error</p>';
}
else{
mysqli_stmt_execute($result);
$resultl = mysqli_stmt_get_result($result);
if (mysqli_num_rows($resultl) > 0){
while ($row = mysqli_fetch_assoc($resultl)){
?>
<TR>
<TD><?php echo $row['id'];?></TD>
<TD><?php echo $row['username'];?></TD>
<TD><?php echo $row['registration
\number'];?></TD>
<TD><?php echo $row['fingerprint_id'];?></TD>
<TD><?php echo $row['device_dep'];?></TD>
<TD><?php echo $row['checkindate'];?></TD>
<TD><?php echo $row['timein'];?></TD>
<TD><?php echo $row['timeout'];?></TD>
</TR>
<?php
}
}
}
// echo $sql;
?>
</tbody>
</table>
</div>