<?php
require 'config.php';

$stmt = $pdo->query("SELECT * FROM users ORDER BY created_at DESC");
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html>
<head>
<title>Hotspot Dashboard</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-4">
<h2>Hotspot Users</h2>
<a href="user_add.php" class="btn btn-success mb-2">Add User</a>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>ID</th>
<th>Mobile/Email</th>
<th>MAC</th>
<th>OTP</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach($users as $u): ?>
<tr>
<td><?= $u['id'] ?></td>
<td><?= $u['mobile'] ?></td>
<td><?= $u['mac'] ?></td>
<td><?= $u['otp'] ?></td>
<td><?= $u['created_at'] ?></td>
<td>
<a href="user_edit.php?id=<?= $u['id'] ?>" class="btn btn-sm btn-primary">Edit</a>
<a href="user_delete.php?id=<?= $u['id'] ?>" class="btn btn-sm btn-danger">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<a href="logs.php" class="btn btn-info">View Login Logs</a>
</div>
</body>
</html>
