35429-vm/team.php
2025-11-02 19:50:28 +00:00

110 lines
5.3 KiB
PHP

<?php
require_once 'includes/header.php';
require_once 'db/config.php';
// Fetch team members
$members = [];
try {
$db = db();
$stmt = $db->query("SELECT id, name, email, role, status, created_at FROM team_members ORDER BY created_at DESC");
$members = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
// In a real app, you'd log this error. For now, we'll just show a message.
echo '<div class="alert alert-danger">Could not connect to the database.</div>';
}
?>
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h1 class="h4 mb-0">Team Members</h1>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addMemberModal">
<i class="bi bi-plus-lg"></i> Add Member
</button>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Role</th>
<th scope="col">Status</th>
<th scope="col">Joined</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($members)): ?>
<tr>
<td colspan="6" class="text-center text-muted">No team members found. Add one to get started!</td>
</tr>
<?php else: ?>
<?php foreach ($members as $member): ?>
<tr>
<td class="fw-medium"><?php echo htmlspecialchars($member['name']); ?></td>
<td><?php echo htmlspecialchars($member['email']); ?></td>
<td><?php echo htmlspecialchars($member['role']); ?></td>
<td>
<?php
$status_class = $member['status'] === 'active' ? 'bg-success-subtle text-success-emphasis' : 'bg-secondary-subtle text-secondary-emphasis';
echo '<span class="badge ' . $status_class . '">' . htmlspecialchars(ucfirst($member['status'])) . '</span>';
?>
</td>
<td><?php echo date('M d, Y', strtotime($member['created_at'])); ?></td>
<td>
<a href="#" class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil"></i></a>
<a href="#" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash"></i></a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Add Member Modal -->
<div class="modal fade" id="addMemberModal" tabindex="-1" aria-labelledby="addMemberModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addMemberModalLabel">Add New Team Member</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="add_member.php" method="POST">
<div class="modal-body">
<div class="mb-3">
<label for="name" class="form-label">Full Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="role" class="form-label">Role</label>
<select class="form-select" id="role" name="role" required>
<option selected disabled value="">Choose...</option>
<option value="Admin">Admin</option>
<option value="Project Manager">Project Manager</option>
<option value="Team Member">Team Member</option>
<option value="Sales/Lead Manager">Sales/Lead Manager</option>
<option value="Finance">Finance</option>
<option value="Support Agent">Support Agent</option>
<option value="Client">Client</option>
</select>
</div>
</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 Member</button>
</div>
</form>
</div>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>