35429-vm/clients.php
2025-11-02 20:12:50 +00:00

95 lines
4.1 KiB
PHP

<?php
require_once 'db/config.php';
require_once 'includes/header.php';
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, name, website, status, created_at FROM clients ORDER BY name ASC");
$clients = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo '<div class="alert alert-danger">Error fetching clients: ' . $e->getMessage() . '</div>';
$clients = [];
}
?>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-3">
<h1 class="h2">Clients</h1>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addClientModal">
Add Client
</button>
</div>
<div class="card">
<div class="card-body">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>Name</th>
<th>Website</th>
<th>Status</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($clients)): ?>
<tr>
<td colspan="5" class="text-center">No clients found.</td>
</tr>
<?php else: ?>
<?php foreach ($clients as $client): ?>
<tr>
<td><?php echo htmlspecialchars($client['name']); ?></td>
<td><a href="<?php echo htmlspecialchars($client['website']); ?>" target="_blank"><?php echo htmlspecialchars($client['website']); ?></a></td>
<td><span class="badge bg-<?php echo strtolower($client['status']) == 'active' ? 'success' : 'secondary'; ?>"><?php echo htmlspecialchars($client['status']); ?></span></td>
<td><?php echo htmlspecialchars($client['created_at']); ?></td>
<td>
<!-- Actions like edit/delete can be added here -->
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Add Client Modal -->
<div class="modal fade" id="addClientModal" tabindex="-1" aria-labelledby="addClientModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addClientModalLabel">Add New Client</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="add_client.php" method="POST">
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="website" class="form-label">Website</label>
<input type="url" class="form-control" id="website" name="website">
</div>
<div class="mb-3">
<label for="status" class="form-label">Status</label>
<select class="form-select" id="status" name="status">
<option value="Active" selected>Active</option>
<option value="Inactive">Inactive</option>
</select>
</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 Client</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>