64 lines
2.3 KiB
PHP
64 lines
2.3 KiB
PHP
<?php
|
|
require_once 'auth.php';
|
|
require_once '../db/config.php';
|
|
|
|
// Fetch unique customers (by email)
|
|
$stmt = db()->query("
|
|
SELECT
|
|
name,
|
|
email,
|
|
phone,
|
|
COUNT(id) as request_count
|
|
FROM service_requests
|
|
GROUP BY email
|
|
ORDER BY name ASC
|
|
");
|
|
$customers = $stmt->fetchAll();
|
|
|
|
require_once '../header.php';
|
|
?>
|
|
|
|
<div class="container my-5">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1>Customer History</h1>
|
|
<a href="index.php" class="btn btn-outline-secondary">Back to Dashboard</a>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<?php if (count($customers) > 0): ?>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Customer Name</th>
|
|
<th>Email</th>
|
|
<th>Phone</th>
|
|
<th>Service Requests</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($customers as $customer): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($customer['name']); ?></td>
|
|
<td><?php echo htmlspecialchars($customer['email']); ?></td>
|
|
<td><?php echo htmlspecialchars($customer['phone']); ?></td>
|
|
<td><span class="badge bg-primary"><?php echo $customer['request_count']; ?></span></td>
|
|
<td>
|
|
<a href="customer_history.php?email=<?php echo urlencode($customer['email']); ?>" class="btn btn-sm btn-info">View History</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php else: ?>
|
|
<p class="text-center">No customers found.</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once '../footer.php'; ?>
|