35122-vm/admin.php
Flatlogic Bot db34ad1091 002
2025-10-22 19:18:04 +00:00

73 lines
4.4 KiB
PHP

<?php
session_start();
// If the user is not logged in, redirect to the login page.
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
require_once 'db/config.php';
$page_title = 'Admin Dashboard';
require_once __DIR__ . '/header.php';
$pdo = db();
$stmt = $pdo->query('SELECT id, name, email, message, status, created_at FROM service_requests ORDER BY created_at DESC');
$requests = $stmt->fetchAll();
?>
<div class="flex justify-between items-center mb-6">
<h1 class="text-3xl font-bold text-gray-800">Admin Dashboard</h1>
<a href="logout.php" class="px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-md shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">Logout</a>
</div>
<div class="bg-white rounded-lg shadow-md">
<div class="px-6 py-4 border-b">
<h2 class="text-xl font-semibold text-gray-800">Incoming Service Requests</h2>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Email</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Message</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Received At</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
<?php if (empty($requests)): ?>
<tr>
<td colspan="7" class="px-6 py-4 text-center text-gray-500">No service requests yet.</td>
</tr>
<?php else: ?>
<?php foreach ($requests as $request): ?>
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900"><?php echo htmlspecialchars($request['id']); ?></td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"><?php echo htmlspecialchars($request['name']); ?></td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"><a href="mailto:<?php echo htmlspecialchars($request['email']); ?>" class="text-indigo-600 hover:text-indigo-900"><?php echo htmlspecialchars($request['email']); ?></a></td>
<td class="px-6 py-4 text-sm text-gray-500"><div class="w-48 truncate"><?php echo nl2br(htmlspecialchars($request['message'])); ?></div></td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500"><?php echo htmlspecialchars(date('M d, Y H:i', strtotime($request['created_at']))); ?></td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800">
<?php echo htmlspecialchars(ucfirst($request['status'])); ?>
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium space-x-2">
<button class="px-3 py-1 text-xs text-white bg-green-600 rounded-md hover:bg-green-700 focus:outline-none">Approve</button>
<button class="px-3 py-1 text-xs text-white bg-red-600 rounded-md hover:bg-red-700 focus:outline-none">Deny</button>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
<?php require_once __DIR__ . '/footer.php'; ?>