36557-vm/admin_dashboard.php
Flatlogic Bot 08fcb2dae0 0.2
2025-12-01 21:25:15 +00:00

154 lines
8.6 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'Super Admin') {
header('Location: login.php');
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/dashboard.css?v=<?php echo time(); ?>">
</head>
<body>
<div class="sidebar">
<a href="index.php" class="logo"><i class="bi bi-buildings"></i> Admin Panel</a>
<ul class="nav flex-column">
<li class="nav-item"><a class="nav-link active" href="admin_dashboard.php"><i class="bi bi-people-fill"></i> User Management</a></li>
<li class="nav-item"><a class="nav-link" href="edit_content.php"><i class="bi bi-pencil-square"></i> Edit Content</a></li>
<li class="nav-item"><a class="nav-link" href="index.php" target="_blank"><i class="bi bi-box-arrow-up-right"></i> View Site</a></li>
<li class="nav-item" style="margin-top: auto;"><hr></li>
<li class="nav-item"><a class="nav-link" href="logout.php"><i class="bi bi-box-arrow-left"></i> Logout</a></li>
</ul>
</div>
<div class="main-content">
<header class="header">
<h1 class="h3 mb-0">User Management</h1>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addUserModal"><i class="bi bi-plus-circle-fill me-2"></i> Add User</button>
</header>
<main class="container-fluid p-4">
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped table-hover align-middle">
<thead class="table-light">
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Company</th>
<th>Role</th>
<th>Agent Tier</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
require_once 'db/config.php';
$db = db();
$stmt = $db->query('SELECT id, name, email, phone, company, role, agent_tier FROM users ORDER BY id DESC');
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<tr>";
echo "<td>" . htmlspecialchars($row['id']) . "</td>";
echo "<td>" . htmlspecialchars($row['name']) . "</td>";
echo "<td>" . htmlspecialchars($row['email']) . "</td>";
echo "<td>" . htmlspecialchars($row['phone']) . "</td>";
echo "<td>" . htmlspecialchars($row['company']) . "</td>";
echo "<td><span class=\"badge bg-secondary\">" . htmlspecialchars($row['role']) . "</span></td>";
echo "<td><span class=\"badge bg-info\">" . htmlspecialchars($row['agent_tier']) . "</span></td>";
echo '<td>
<a href="edit_user.php?id=' . $row['id'] . '" class="btn btn-sm btn-outline-primary"><i class="bi bi-pencil-fill"></i></a>
<a href="delete_user.php?id=' . $row['id'] . '" class="btn btn-sm btn-outline-danger" onclick="return confirm(\'Are you sure you want to delete this user?\');"><i class="bi bi-trash-fill"></i></a>
</td>';
echo "</tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</main>
</div>
<!-- Add User Modal -->
<div class="modal fade" id="addUserModal" tabindex="-1" aria-labelledby="addUserModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addUserModalLabel">Add New User</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="add_user.php" method="POST">
<div class="row">
<div class="col-md-6 mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="col-md-6 mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="phone" class="form-label">Phone</label>
<input type="text" class="form-control" id="phone" name="phone">
</div>
<div class="col-md-6 mb-3">
<label for="company" class="form-label">Company</label>
<input type="text" class="form-control" id="company" name="company">
</div>
</div>
<div class="mb-3">
<label for="notes" class="form-label">Notes</label>
<textarea class="form-control" id="notes" name="notes" rows="3"></textarea>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="role" class="form-label">Role</label>
<select class="form-select" id="role" name="role">
<option value="Agent">Agent</option>
<option value="Finance">Finance</option>
<option value="Support">Support</option>
<option value="Admin">Admin</option>
<option value="Super Admin">Super Admin</option>
</select>
</div>
<div class="col-md-6 mb-3">
<label for="agent_tier" class="form-label">Agent Tier</label>
<select class="form-select" id="agent_tier" name="agent_tier">
<option value="Normal">Normal</option>
<option value="Silver">Silver</option>
<option value="Gold">Gold</option>
<option value="Diamond">Diamond</option>
</select>
</div>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Add User</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>