86 lines
3.9 KiB
PHP
86 lines
3.9 KiB
PHP
<?php
|
|
require_once '../db/config.php';
|
|
|
|
// Fetch all users from the database
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query("SELECT * FROM users ORDER BY created_at DESC");
|
|
$users = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
$users = [];
|
|
$db_error = "Error fetching users: " . $e->getMessage();
|
|
}
|
|
|
|
// Include header
|
|
include 'partials/header.php';
|
|
?>
|
|
|
|
<div id="page-content-wrapper">
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-transparent py-4 px-4">
|
|
<div class="d-flex align-items-center">
|
|
<i class="bi bi-list fs-4 me-3" id="menu-toggle"></i>
|
|
<h2 class="fs-2 m-0">Manajemen Pengguna</h2>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container-fluid px-4">
|
|
|
|
<?php if (isset($_GET['status'])) : ?>
|
|
<div class="alert alert-<?php echo $_GET['status'] == 'success' ? 'success' : 'danger'; ?> alert-dismissible fade show" role="alert">
|
|
<?php echo htmlspecialchars($_GET['message']); ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (isset($db_error)) : ?>
|
|
<div class="alert alert-danger"> <?php echo $db_error; ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="row my-5">
|
|
<div class="col">
|
|
<a href="user_add.php" class="btn btn-primary mb-3"><i class="bi bi-plus-lg"></i> Tambah Pengguna</a>
|
|
<div class="card shadow-sm">
|
|
<div class="card-body">
|
|
<h3 class="fs-4 mb-3">Daftar Pengguna</h3>
|
|
<div class="table-responsive">
|
|
<table class="table table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col">#</th>
|
|
<th scope="col">Nama</th>
|
|
<th scope="col">Email</th>
|
|
<th scope="col">Peran</th>
|
|
<th scope="col">Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($users)) : ?>
|
|
<tr>
|
|
<td colspan="5" class="text-center">Belum ada pengguna.</td>
|
|
</tr>
|
|
<?php else : ?>
|
|
<?php foreach ($users as $key => $user) : ?>
|
|
<tr>
|
|
<th scope="row"><?php echo $key + 1; ?></th>
|
|
<td><?php echo htmlspecialchars($user['name']); ?></td>
|
|
<td><?php echo htmlspecialchars($user['email']); ?></td>
|
|
<td><?php echo htmlspecialchars($user['role']); ?></td>
|
|
<td>
|
|
<a href="user_edit.php?id=<?php echo $user['id']; ?>" class="btn btn-sm btn-primary">Edit</a>
|
|
<a href="user_delete.php?id=<?php echo $user['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Anda yakin ingin menghapus pengguna ini?');">Hapus</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'partials/footer.php'; ?>
|