-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs.php
167 lines (141 loc) · 4.64 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
<?php
// log.php
include 'config/db.php';
// Set the number of records to display per page
$recordsPerPage = 20;
// Determine the current page number
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Calculate the offset for the SQL query
$offset = ($page - 1) * $recordsPerPage;
// Fetch records for the current page
$loginHistoryQuery = "SELECT id, username, login_time FROM login_history ORDER BY login_time DESC LIMIT $recordsPerPage OFFSET $offset";
$result = $conn->query($loginHistoryQuery);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login History</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
justify-content: center;
align-items: center;
height: 100vh;
width: 100%;
}
table {
border-collapse: collapse;
width: 80%;
margin-top: 20px;
margin-left: auto;
margin-right: auto;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 12px;
text-align: left;
}
th {
background-color: #4CAF50;
color: white;
}
button {
background-color: #4CAF50;
color: white;
padding: 12px;
border: 1px solid #ddd;
margin-right: 200px;
float: right;
margin-top: -10px;
}
.centered-div {
text-align: center;
padding: 20px;
}
.pagination {
margin-top: 20px;
}
.pagination a {
padding: 8px 16px;
text-decoration: none;
color: #4CAF50;
border: 1px solid #ddd;
margin: 0 4px;
}
.pagination a:hover {
background-color: #ddd;
}
.pagination .active {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<div class="centered-div">
<h2>Login History</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Login Time</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>{$row['id']}</td>";
echo "<td>{$row['username']}</td>";
// Convert database time to DateTime object
$loginTime = new DateTime($row['login_time'], new DateTimeZone('UTC'));
$loginTime->setTimezone(new DateTimeZone('Asia/Kolkata')); // Adjust to your desired timezone
echo "<td>" . $loginTime->format('Y-m-d h:i A') . "</td>";
echo "<td><input type='checkbox' class='logCheckbox' value='{$row['id']}'></td>";
echo "</tr>";
}
?>
</tbody>
</table>
<!-- Pagination links -->
<div class="pagination">
<?php
$totalRecordsQuery = "SELECT COUNT(*) AS total FROM login_history";
$totalRecordsResult = $conn->query($totalRecordsQuery);
$totalRecords = $totalRecordsResult->fetch_assoc()['total'];
$totalPages = ceil($totalRecords / $recordsPerPage);
for ($i = 1; $i <= $totalPages; $i++) {
$class = ($i == $page) ? "active" : "";
echo "<a class='$class' href='?page=$i'>$i</a>";
}
?>
<button onclick="deleteSelectedLogs()">Delete Selected</button>
</div>
</div>
<script>
function deleteSelectedLogs() {
const checkboxes = document.querySelectorAll('.logCheckbox:checked');
const logIds = Array.from(checkboxes).map(checkbox => checkbox.value);
if (logIds.length > 0) {
if (confirm('Are you sure you want to delete the selected logs?')) {
window.location.href = `config/delete_logs.php?logIds=${logIds.join(',')}`;
}
} else {
alert('Please select logs to delete.');
}
}
</script>
</body>
</html>
<?php
$conn->close();
?>