-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.php
More file actions
225 lines (201 loc) · 8.33 KB
/
users.php
File metadata and controls
225 lines (201 loc) · 8.33 KB
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
<?php
session_start();
include 'db.php';
// Check if the user is logged in
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
header("Location: splash.php");
exit;
}
// Set the inactive threshold (e.g., 30 days)
$inactiveThreshold = date('Y-m-d H:i:s', strtotime('-30 days'));
try {
// Fetch basic user data
$sql = "SELECT id, firstName, lastName, age, gender, adrHouseNo, adrZone, adrStreet, birthday, status FROM user_accounts";
$stmt = $conn->prepare($sql);
$stmt->execute();
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Count total registered users
$registeredResidentsQuery = "SELECT COUNT(*) AS count FROM user_accounts";
$registeredResidentsResult = $conn->query($registeredResidentsQuery)->fetch(PDO::FETCH_ASSOC);
$registeredResidentsCount = $registeredResidentsResult['count'];
// Count active users (users who have been active within the last 30 days)
$activeUsersQuery = "SELECT COUNT(*) AS count FROM user_accounts
WHERE last_active >= :threshold";
$stmt = $conn->prepare($activeUsersQuery);
$stmt->bindParam(':threshold', $inactiveThreshold);
$stmt->execute();
$activeUsersResult = $stmt->fetch(PDO::FETCH_ASSOC);
$activeUsersCount = $activeUsersResult['count'];
// Calculate inactive users
$inactiveUsersCount = $registeredResidentsCount - $activeUsersCount;
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Users</title>
<link rel="stylesheet" href="css/users.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css">
<link rel="icon" type="image/png" href="assets/Southside.png">
</head>
<body>
<?php
$pageTitle = "Resident Users";
include 'header.php';
include 'sidebar.php';
?>
<div class="main-content">
<div class="container mt-4 px-4">
<!-- User Statistics Boxes -->
<div class="row justify-content-center mb-5" style="max-width: 100vw; margin: 0 auto;">
<div class="col-md-4 px-4">
<div class="stat-box total-resident text-center py-3">
<h4>Registered Residents</h4>
<div class="stat-number"><?php echo $registeredResidentsCount; ?></div>
</div>
</div>
<div class="col-md-4 px-4">
<div class="stat-box active-user text-center py-3">
<h4>Active Users</h4>
<div class="stat-number"><?php echo $activeUsersCount; ?></div>
</div>
</div>
<div class="col-md-4 px-4">
<div class="stat-box inactive-user text-center py-3">
<h4>Inactive Users</h4>
<div class="stat-number"><?php echo $inactiveUsersCount; ?></div>
</div>
</div>
</div>
<!-- User Table -->
<div class="table-responsive">
<table class="table table-bordered mb-0">
<thead>
<tr>
<th data-sort="string">Last Name</th>
<th data-sort="string">First Name</th>
<th data-sort="string">Address</th>
<th data-sort="status">Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?php echo htmlspecialchars($user['lastName']); ?></td>
<td><?php echo htmlspecialchars($user['firstName']); ?></td>
<td>
<?php
echo htmlspecialchars($user['adrHouseNo']) . " " .
htmlspecialchars($user['adrStreet']) . " " .
htmlspecialchars($user['adrZone']);
?>
</td>
<td>
<?php
$statusBadgeClass = '';
$status = strtolower($user['status']);
switch($status) {
case 'verified':
$statusBadgeClass = 'badge bg-success';
break;
case 'rejected':
$statusBadgeClass = 'badge bg-danger';
break;
default:
$statusBadgeClass = 'badge bg-warning';
break;
}
?>
<span class="<?php echo $statusBadgeClass; ?>">
<?php echo ucfirst($status ?? 'pending'); ?>
</span>
</td>
<td>
<div class="d-flex justify-content-center gap-2">
<a href="view_user.php?id=<?php echo $user['id']; ?>" class="action-button">View</a>
<button class="action-button button-delete" onclick="confirmDelete(<?php echo $user['id']; ?>)">Delete</button>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<div id="deleteConfirmationModal" class="custom-modal">
<div class="custom-modal-content">
<div class="custom-modal-header">
<h5 class="modal-title">Confirm Deletion</h5>
<i class="fas fa-times close-modal"></i>
</div>
<div class="custom-modal-body">
Are you sure you want to delete this user? This action cannot be undone.
</div>
<div class="custom-modal-footer">
<button class="btn btn-secondary close-modal">Cancel</button>
<button class="btn btn-danger" onclick="deleteConfirmed()">Delete</button>
</div>
</div>
</div>
<script>
let userIdToDelete;
function confirmDelete(userId) {
userIdToDelete = userId;
document.getElementById('deleteConfirmationModal').style.display = 'block';
document.body.style.overflow = 'hidden'; // Prevent background scrolling
}
function deleteConfirmed() {
window.location.href = 'deleteUser.php?id=' + userIdToDelete;
}
// Close modal when clicking the X button or Cancel button
document.querySelectorAll('.close-modal').forEach(button => {
button.onclick = function() {
document.getElementById('deleteConfirmationModal').style.display = 'none';
document.body.style.overflow = 'auto'; // Restore scrolling
}
});
// Close modal when clicking outside
window.onclick = function(event) {
const modal = document.getElementById('deleteConfirmationModal');
if (event.target == modal) {
modal.style.display = 'none';
document.body.style.overflow = 'auto'; // Restore scrolling
}
}
// Table sorting functionality
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('th').forEach((header, index) => {
header.style.cursor = 'pointer';
header.addEventListener('click', () => {
sortTable(index);
});
});
});
function sortTable(columnIndex) {
const table = document.querySelector('table tbody');
const rows = Array.from(table.rows);
const isAscending = table.getAttribute('data-sort-asc') === 'true' ? false : true;
table.setAttribute('data-sort-asc', isAscending);
rows.sort((a, b) => {
const cellA = a.cells[columnIndex].textContent.trim();
const cellB = b.cells[columnIndex].textContent.trim();
if (columnIndex === 3) { // Age column (numeric sort)
return isAscending ? cellA - cellB : cellB - cellA;
} else {
return isAscending
? cellA.localeCompare(cellB)
: cellB.localeCompare(cellA);
}
});
rows.forEach(row => table.appendChild(row));
}
</script>
</body>
</html>