119 lines
4.6 KiB
PHP
119 lines
4.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
@ini_set('display_errors', '1');
|
|
@error_reporting(E_ALL);
|
|
@date_default_timezone_set('UTC');
|
|
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
function ensure_contact_table(): void {
|
|
db()->exec(
|
|
"CREATE TABLE IF NOT EXISTS contact_requests (
|
|
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(120) NOT NULL,
|
|
email VARCHAR(160) NOT NULL,
|
|
message TEXT NOT NULL,
|
|
status VARCHAR(30) NOT NULL DEFAULT 'new',
|
|
ip_address VARCHAR(45) DEFAULT NULL,
|
|
user_agent VARCHAR(255) DEFAULT NULL,
|
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
|
|
);
|
|
}
|
|
|
|
ensure_contact_table();
|
|
|
|
$detail = null;
|
|
if (isset($_GET['id']) && ctype_digit($_GET['id'])) {
|
|
$stmt = db()->prepare('SELECT * FROM contact_requests WHERE id = :id');
|
|
$stmt->execute([':id' => (int) $_GET['id']]);
|
|
$detail = $stmt->fetch();
|
|
}
|
|
|
|
$stmt = db()->prepare('SELECT id, name, email, status, created_at FROM contact_requests ORDER BY created_at DESC LIMIT 50');
|
|
$stmt->execute();
|
|
$rows = $stmt->fetchAll();
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<meta name="robots" content="noindex, nofollow" />
|
|
<title>Contact Requests</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="assets/css/custom.css?v=<?= time(); ?>" rel="stylesheet">
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-light bg-white border-bottom">
|
|
<div class="container">
|
|
<a class="navbar-brand fw-semibold" href="index.php">← Back to portfolio</a>
|
|
<span class="text-muted small">Contact Requests</span>
|
|
</div>
|
|
</nav>
|
|
|
|
<main class="section">
|
|
<div class="container">
|
|
<div class="row g-4">
|
|
<div class="col-lg-7">
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="card-body">
|
|
<h1 class="h4 fw-semibold mb-3">Latest inquiries</h1>
|
|
<?php if (!$rows): ?>
|
|
<p class="text-muted mb-0">No inquiries yet. New submissions will appear here.</p>
|
|
<?php else: ?>
|
|
<div class="table-responsive">
|
|
<table class="table align-middle">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Name</th>
|
|
<th>Email</th>
|
|
<th>Status</th>
|
|
<th>Received</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($rows as $row): ?>
|
|
<tr>
|
|
<td>#<?= htmlspecialchars((string) $row['id']) ?></td>
|
|
<td><a class="link-dark fw-semibold" href="inbox.php?id=<?= htmlspecialchars((string) $row['id']) ?>"><?= htmlspecialchars($row['name']) ?></a></td>
|
|
<td><?= htmlspecialchars($row['email']) ?></td>
|
|
<td><span class="badge badge-soft"><?= htmlspecialchars($row['status']) ?></span></td>
|
|
<td class="text-muted small"><?= htmlspecialchars($row['created_at']) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-5">
|
|
<div class="card border-0 shadow-sm h-100">
|
|
<div class="card-body">
|
|
<h2 class="h5 fw-semibold">Inquiry detail</h2>
|
|
<?php if (!$detail): ?>
|
|
<p class="text-muted">Select a request to see the full message.</p>
|
|
<?php else: ?>
|
|
<div class="border rounded p-3 mb-3">
|
|
<p class="text-muted small mb-1">From</p>
|
|
<p class="fw-semibold mb-0"><?= htmlspecialchars($detail['name']) ?></p>
|
|
<p class="text-muted small mb-0"><?= htmlspecialchars($detail['email']) ?></p>
|
|
</div>
|
|
<div class="border rounded p-3 mb-3">
|
|
<p class="text-muted small mb-1">Message</p>
|
|
<p class="mb-0"><?= nl2br(htmlspecialchars($detail['message'])) ?></p>
|
|
</div>
|
|
<p class="text-muted small mb-0">Received <?= htmlspecialchars($detail['created_at']) ?> · Status <?= htmlspecialchars($detail['status']) ?></p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</body>
|
|
</html>
|