35521-vm/contacts.php
2025-11-06 12:19:31 +00:00

64 lines
2.8 KiB
PHP

<?php
require_once 'db/config.php';
require_once 'templates/header.php';
$contacts = [];
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, name, email, phone, company, status, created_at FROM contacts ORDER BY created_at DESC");
$contacts = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
// In a real app, you'd log this error and show a user-friendly message.
// For now, we'll just show a simple error.
echo '<div class="alert alert-danger">Error connecting to the database or fetching data. Please run the migration script.</div>';
}
?>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h2">Contacts</h1>
<a href="#" class="btn btn-primary"><i class="bi bi-plus-circle-fill me-2"></i>Add Contact</a>
</div>
<div class="card">
<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">Phone</th>
<th scope="col">Company</th>
<th scope="col">Status</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($contacts)): ?>
<tr>
<td colspan="6" class="text-center">No contacts found. Add one to get started!</td>
</tr>
<?php else: ?>
<?php foreach ($contacts as $contact): ?>
<tr>
<td><?php echo htmlspecialchars($contact['name']); ?></td>
<td><a href="mailto:<?php echo htmlspecialchars($contact['email']); ?>"><?php echo htmlspecialchars($contact['email']); ?></a></td>
<td><?php echo htmlspecialchars($contact['phone']); ?></td>
<td><?php echo htmlspecialchars($contact['company']); ?></td>
<td><span class="badge bg-secondary"><?php echo htmlspecialchars($contact['status']); ?></span></td>
<td>
<a href="#" class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil-fill"></i></a>
<a href="#" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash-fill"></i></a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php
require_once 'templates/footer.php';
?>