69 lines
2.4 KiB
PHP
69 lines
2.4 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
require_once 'header.php';
|
|
|
|
// Check if user is logged in and is an admin
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'admin') {
|
|
echo '<div class="container">
|
|
<div class="alert alert-danger mt-5" role="alert">
|
|
You are not authorized to view this page. Please <a href="login.php">login</a> as an admin.
|
|
</div>
|
|
</div>';
|
|
require_once 'footer.php';
|
|
exit;
|
|
}
|
|
|
|
// Fetch users from the database
|
|
$pdo = db();
|
|
$stmt = $pdo->query('SELECT id, name, email, role, created_at FROM users ORDER BY created_at DESC');
|
|
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
include 'sidebar.php';
|
|
?>
|
|
|
|
<div class="main-content">
|
|
<header class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2>User Management</h2>
|
|
<div class="d-flex align-items-center">
|
|
<span class="me-3">Welcome, <?php echo htmlspecialchars($_SESSION['username']); ?>!</span>
|
|
<a href="logout.php" class="btn btn-outline-primary">Logout</a>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-sm">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Name</th>
|
|
<th>Email</th>
|
|
<th>Role</th>
|
|
<th>Registered At</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($users)): ?>
|
|
<tr>
|
|
<td colspan="5" class="text-center">No users found.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($users as $user): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($user['id']); ?></td>
|
|
<td><?php echo htmlspecialchars($user['name']); ?></td>
|
|
<td><?php echo htmlspecialchars($user['email']); ?></td>
|
|
<td><?php echo htmlspecialchars($user['role']); ?></td>
|
|
<td><?php echo htmlspecialchars(date('Y-m-d H:i', strtotime($user['created_at']))); ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
require_once 'footer.php';
|
|
?>
|