<?php
$pageTitle = 'User Management';
require_once __DIR__ . '/../../app/includes/header.php';
require_admin();
$users = db()->query('SELECT * FROM users ORDER BY id')->fetchAll();
?>
<div class="page-head"><div><h1>User Management</h1><p>Create users, assign roles, and control account status.</p></div><a class="btn btn-primary" href="<?= APP_BASE ?>/users/create.php"><i class="bi bi-plus-lg me-1"></i>Create User</a></div>
<div class="card app-card"><div class="table-responsive"><table class="table align-middle mb-0">
<thead><tr><th>Name</th><th>Email</th><th>Role</th><th>Status</th><th>Must Change Password</th><th>Created</th><th>Action</th></tr></thead><tbody>
<?php foreach ($users as $u): ?><tr>
    <td><?= e($u['name']) ?></td><td><?= e($u['email']) ?></td><td><?= e($u['role']) ?></td>
    <td><span class="badge text-bg-<?= $u['status']==='active'?'success':'secondary' ?>"><?= e($u['status']) ?></span></td>
    <td><?= (int)$u['must_change_password'] ? 'Yes' : 'No' ?></td><td><?= e(date('Y-m-d', strtotime($u['created_at']))) ?></td>
    <td><a class="btn btn-sm btn-outline-primary" href="<?= APP_BASE ?>/users/edit.php?id=<?= (int)$u['id'] ?>">Edit</a></td>
</tr><?php endforeach; ?>
</tbody></table></div></div>
<?php require_once __DIR__ . '/../../app/includes/footer.php'; ?>
