128 lines
5.0 KiB
PHP
128 lines
5.0 KiB
PHP
<?php
|
|
require_once 'auth.php';
|
|
require_once 'db/config.php';
|
|
|
|
if (!is_logged_in()) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
if (!hasPermission('manage_roles')) {
|
|
// Redirect to a generic "access denied" page or the home page
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
$pdo = db();
|
|
|
|
// Handle form submission for new role
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_role'])) {
|
|
$role_name = $_POST['role_name'] ?? '';
|
|
|
|
if (!empty($role_name)) {
|
|
try {
|
|
$stmt = $pdo->prepare("INSERT INTO roles (name) VALUES (?)");
|
|
$stmt->execute([$role_name]);
|
|
header("Location: " . $_SERVER['PHP_SELF']);
|
|
exit;
|
|
} catch (PDOException $e) {
|
|
error_log("Error adding role: " . $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Fetch roles
|
|
$stmt = $pdo->query("SELECT * FROM roles ORDER BY name");
|
|
$roles = $stmt->fetchAll();
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Role Management</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
<header class="header d-flex justify-content-between align-items-center">
|
|
<div class="logo">FinMox<span class="dot">.</span></div>
|
|
<nav class="d-flex align-items-center">
|
|
<a href="index.php" class="btn btn-outline-primary me-2">Home</a>
|
|
<a href="dashboard.php" class="btn btn-outline-primary me-2">Dashboard</a>
|
|
<a href="workflows.php" class="btn btn-outline-primary me-3">Workflows</a>
|
|
<div class="dropdown">
|
|
<button class="btn btn-outline-secondary dropdown-toggle" type="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<?php echo htmlspecialchars($_SESSION['username']); ?>
|
|
</button>
|
|
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
|
|
<?php if (hasPermission('manage_roles')): ?>
|
|
<li><a class="dropdown-item" href="roles.php">Manage Roles</a></li>
|
|
<li><hr class="dropdown-divider"></li>
|
|
<?php endif; ?>
|
|
<li><a class="dropdown-item" href="logout.php">Logout</a></li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
</header>
|
|
|
|
<main class="container-fluid">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2>Role Management</h2>
|
|
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addRoleModal">Add Role</button>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Role Name</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($roles as $role): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($role['name']); ?></td>
|
|
<td>
|
|
<a href="edit_role.php?role_id=<?php echo $role['id']; ?>" class="btn btn-sm btn-outline-primary">Edit</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<!-- Add Role Modal -->
|
|
<div class="modal fade" id="addRoleModal" tabindex="-1" aria-labelledby="addRoleModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="addRoleModalLabel">Add New Role</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form method="POST">
|
|
<input type="hidden" name="add_role" value="1">
|
|
<div class="mb-3">
|
|
<label for="role_name" class="form-label">Role Name</label>
|
|
<input type="text" class="form-control" id="role_name" name="role_name" required>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
|
<button type="submit" class="btn btn-primary">Save Role</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|