35251-vm/customers.php
Flatlogic Bot c1d245a403 1
2025-10-26 16:30:02 +00:00

128 lines
5.6 KiB
PHP

<?php
require_once 'db/config.php';
try {
$pdo = db();
$stmt = $pdo->query('SELECT id, name, email, plan, status FROM customers ORDER BY id');
$customers = $stmt->fetchAll();
} catch (PDOException $e) {
// For development, you might want to log this error or display a generic message
// For production, log the error and show a user-friendly message.
error_log('Database error: ' . $e->getMessage());
$customers = []; // Ensure $customers is an empty array on error
// Optionally, set an error message to display to the user
$errorMessage = 'Could not retrieve customer data. Please try again later.';
}
function getStatusBadgeClass($status) {
switch (strtolower($status)) {
case 'active':
return 'bg-success';
case 'suspended':
return 'bg-warning text-dark';
case 'deactivated':
return 'bg-danger';
default:
return 'bg-secondary';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Customers - CableCRM</title>
<meta name="description" content="Customer Management for CableCRM">
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<div class="sidebar">
<h4 class="p-2 mb-4">CableCRM</h4>
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link" href="index.php"><i class="bi bi-grid-1x2-fill"></i> Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="customers.php"><i class="bi bi-people-fill"></i> Customers</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="bi bi-receipt"></i> Invoices</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="bi bi-box-seam"></i> Plans</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><i class="bi bi-bar-chart-fill"></i> Reports</a>
</li>
</ul>
</div>
<div class="main-content">
<div class="container-fluid">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>Customers</h1>
<button class="btn btn-primary"><i class="bi bi-plus-circle-fill me-2"></i>Add Customer</button>
</div>
<?php if (isset($errorMessage)): ?>
<div class="alert alert-danger" role="alert">
<?php echo htmlspecialchars($errorMessage); ?>
</div>
<?php endif; ?>
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Plan</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($customers) && !isset($errorMessage)): ?>
<tr>
<td colspan="6" class="text-center">No customers found.</td>
</tr>
<?php else: ?>
<?php foreach ($customers as $customer): ?>
<tr>
<td>CUST-<?php echo str_pad($customer['id'], 3, '0', STR_PAD_LEFT); ?></td>
<td><?php echo htmlspecialchars($customer['name']); ?></td>
<td><?php echo htmlspecialchars($customer['email']); ?></td>
<td><?php echo htmlspecialchars($customer['plan']); ?></td>
<td><span class="badge <?php echo getStatusBadgeClass($customer['status']); ?>"><?php echo htmlspecialchars(ucfirst($customer['status'])); ?></span></td>
<td>
<button class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil-fill"></i></button>
<button class="btn btn-sm btn-outline-danger"><i class="bi bi-trash-fill"></i></button>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap 5 JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<!-- Custom JS -->
<script src="assets/js/main.js"></script>
</body>
</html>