-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_log_up.php
124 lines (120 loc) · 4.61 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
<?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>Serial Number</th>
<th>Card UID</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 = " ";
$Card_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."'";
}
}
//Card filter
if ($_POST['card_sel'] != 0) {
$Card_sel = $_POST['card_sel'];
$_SESSION['searchQuery'] .= " AND card_uid='".$Card_sel."'";
}
//Department filter
if ($_POST['dev_uid'] != 0) {
$dev_uid = $_POST['dev_uid'];
$_SESSION['searchQuery'] .= " AND device_uid='".$dev_uid."'";
}
}
if ($_POST['select_date'] == 1) {
$Start_date = date("Y-m-d");
$_SESSION['searchQuery'] = "checkindate='".$Start_date."'";
}
// $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['serialnumber'];?></TD>
<TD><?php echo $row['card_uid'];?></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>