104 lines
4.4 KiB
PHP
104 lines
4.4 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true || $_SESSION['role'] !== 'Admin') {
|
|
header('location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$users = [];
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query("SELECT id, username, role FROM users ORDER BY id DESC");
|
|
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
// For a real app, you'd want to log this error
|
|
die("Could not connect to the database or fetch users.");
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>View Employees - Employee Attendance System</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
</head>
|
|
<body>
|
|
|
|
<div class="sidebar">
|
|
<h4 class="mb-4 fw-bold">Attendance System</h4>
|
|
<ul class="nav flex-column">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="index.php"><i class="bi bi-grid-fill me-2"></i> Dashboard</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="add_employee.php"><i class="bi bi-person-plus-fill me-2"></i> Add Employee</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link active" href="view_employees.php"><i class="bi bi-people-fill me-2"></i> View Employees</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="#"><i class="bi bi-calendar-check-fill me-2"></i> Attendance</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="#"><i class="bi bi-file-earmark-bar-graph-fill me-2"></i> Reports</a>
|
|
</li>
|
|
<li class="nav-item mt-auto">
|
|
<a class="nav-link" href="logout.php"><i class="bi bi-box-arrow-left me-2"></i> Logout</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="main-content">
|
|
<div class="container-fluid">
|
|
<h1 class="mt-4">View Employees</h1>
|
|
<p class="lead">A list of all users in the system.</p>
|
|
|
|
<div class="card shadow-sm">
|
|
<div class="card-body">
|
|
<table class="table table-hover">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th scope="col">ID</th>
|
|
<th scope="col">Username</th>
|
|
<th scope="col">Role</th>
|
|
<th scope="col">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($users)): ?>
|
|
<tr>
|
|
<td colspan="4" class="text-center">No users found.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($users as $user): ?>
|
|
<tr>
|
|
<th scope="row"><?php echo htmlspecialchars($user['id']); ?></th>
|
|
<td><?php echo htmlspecialchars($user['username']); ?></td>
|
|
<td><?php echo htmlspecialchars($user['role']); ?></td>
|
|
<td>
|
|
<a href="edit_employee.php?id=<?php echo $user['id']; ?>" class="btn btn-sm btn-outline-primary"><i class="bi bi-pencil-square"></i></a>
|
|
<a href="delete_employee.php?id=<?php echo $user['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this employee?');"><i class="bi bi-trash"></i></a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|