| Linux premium274.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64 Path : /home/whagcoha/ledger.mwagalwaservices.com/ |
| Current File : /home/whagcoha/ledger.mwagalwaservices.com/user_stat.php |
<?php
if ((!isset($_SESSION['gen256'])) ) {
echo "<script>
window.open('login.php','_self');
</script>";
}
?>
<?php
// ---------------- Top 5 Active Users ----------------
$topUsersQuery = "
SELECT u.id, u.fname, u.oname, u.email, COUNT(l.id) AS total_logins
FROM users u
JOIN user_logs l ON u.id = l.user_id AND l.success = 1
GROUP BY u.id
ORDER BY total_logins DESC
LIMIT 5";
$topUsers = $conn->query($topUsersQuery);
// ---------------- Latest 10 Logins ----------------
$latestLoginsQuery = "
SELECT u.fname, u.oname, u.email, l.login_time, l.ip_address
FROM user_logs l
JOIN users u ON u.id = l.user_id
ORDER BY l.login_time DESC
LIMIT 10";
$latestLogins = $conn->query($latestLoginsQuery);
// ---------------- Logins per Day for Chart ----------------
$loginsChartQuery = "
SELECT DATE(login_time) as login_date, COUNT(id) as total
FROM user_logs
WHERE success = 1
GROUP BY DATE(login_time)
ORDER BY login_date ASC
LIMIT 15";
$chartResult = $conn->query($loginsChartQuery);
$chartLabels = [];
$chartValues = [];
while ($row = $chartResult->fetch_assoc()) {
$chartLabels[] = $row['login_date'];
$chartValues[] = $row['total'];
}
?>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2>User Statistics Dashboard</h2>
<a href="index.php?p=adminreg" class="btn btn-primary">➕ Add User</a>
</div>
<!-- Top 5 Active Users -->
<div class="card mb-4">
<div class="card-header bg-primary text-white">Top 5 Active Users</div>
<div class="card-body">
<table class="table table-striped">
<thead>
<tr><th>Name</th><th>Email</th><th>Total Logins</th></tr>
</thead>
<tbody>
<?php while($row = $topUsers->fetch_assoc()): ?>
<tr>
<td><?php echo $row['fname']." ".$row['oname']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><span class="badge bg-success"><?php echo $row['total_logins']; ?></span></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
<!-- Latest 10 Logins -->
<div class="card mb-4">
<div class="card-header bg-secondary text-white">Latest 10 Logins</div>
<div class="card-body">
<table class="table table-hover">
<thead>
<tr><th>Name</th><th>Email</th><th>IP</th><th>Login Time</th></tr>
</thead>
<tbody>
<?php while($row = $latestLogins->fetch_assoc()): ?>
<tr>
<td><?php echo $row['fname']." ".$row['oname']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['ip_address']; ?></td>
<td><?php echo $row['login_time']; ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</div>
<!-- Logins Per Day Graph -->
<div class="card mb-4">
<div class="card-header bg-info text-white">Logins Per Day</div>
<div class="card-body">
<canvas id="loginsChart"></canvas>
</div>
</div>
</div>
<script>
const ctx = document.getElementById('loginsChart').getContext('2d');
const loginsChart = new Chart(ctx, {
type: 'line',
data: {
labels: <?php echo json_encode($chartLabels); ?>,
datasets: [{
label: 'Logins',
data: <?php echo json_encode($chartValues); ?>,
backgroundColor: 'rgba(54,162,235,0.2)',
borderColor: 'rgba(54,162,235,1)',
borderWidth: 2,
fill: true,
tension: 0.3
}]
},
options: {
responsive: true,
plugins: {
legend: { display: false }
},
scales: {
y: { beginAtZero: true }
}
}
});
</script>