112 lines
4.2 KiB
PHP
112 lines
4.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
// Simple handling of form submissions
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
if (isset($_POST['action']) && $_POST['action'] === 'add') {
|
|
$keywords = $_POST['keywords'] ?? '';
|
|
$answer = $_POST['answer'] ?? '';
|
|
if ($keywords && $answer) {
|
|
$stmt = db()->prepare("INSERT INTO faqs (keywords, answer) VALUES (?, ?)");
|
|
$stmt->execute([$keywords, $answer]);
|
|
}
|
|
} elseif (isset($_POST['action']) && $_POST['action'] === 'delete') {
|
|
$id = $_POST['id'] ?? 0;
|
|
if ($id) {
|
|
$stmt = db()->prepare("DELETE FROM faqs WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
}
|
|
}
|
|
header("Location: admin.php");
|
|
exit;
|
|
}
|
|
|
|
$faqs = db()->query("SELECT * FROM faqs ORDER BY created_at DESC")->fetchAll();
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Admin - FAQ Manager</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
<style>
|
|
.btn-delete {
|
|
background: #dc3545;
|
|
color: white;
|
|
border: none;
|
|
padding: 0.25rem 0.5rem;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
}
|
|
.btn-add {
|
|
background: #212529;
|
|
color: white;
|
|
border: none;
|
|
padding: 0.5rem 1rem;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
margin-top: 1rem;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="bg-animations">
|
|
<div class="blob blob-1"></div>
|
|
<div class="blob blob-2"></div>
|
|
<div class="blob blob-3"></div>
|
|
</div>
|
|
<div class="admin-container">
|
|
<div style="display: flex; justify-content: space-between; align-items: center;">
|
|
<h1>FAQ Manager</h1>
|
|
<a href="index.php" class="admin-link">Back to Chat</a>
|
|
</div>
|
|
|
|
<div class="admin-card" style="background: rgba(255, 255, 255, 0.6); padding: 2rem; border-radius: 20px; border: 1px solid rgba(255, 255, 255, 0.5); margin-bottom: 2.5rem; box-shadow: 0 10px 30px rgba(0,0,0,0.05);">
|
|
<h3 style="margin-top: 0; margin-bottom: 1.5rem; font-weight: 700;">Add New FAQ</h3>
|
|
<form method="POST">
|
|
<input type="hidden" name="action" value="add">
|
|
<div class="form-group">
|
|
<label for="keywords">Keywords (comma separated)</label>
|
|
<input type="text" name="keywords" id="keywords" class="form-control" placeholder="e.g. price, cost, dollar" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="answer">Answer</label>
|
|
<textarea name="answer" id="answer" class="form-control" rows="3" placeholder="Enter the answer..." required></textarea>
|
|
</div>
|
|
<button type="submit" class="btn-add" style="background: #212529; color: white; border: none; padding: 0.8rem 1.5rem; border-radius: 12px; cursor: pointer; font-weight: 600; width: 100%; transition: all 0.3s ease;">Save FAQ</button>
|
|
</form>
|
|
</div>
|
|
|
|
<h3>Existing FAQs</h3>
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Keywords</th>
|
|
<th>Answer</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($faqs as $faq): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($faq['keywords']) ?></td>
|
|
<td><?= htmlspecialchars($faq['answer']) ?></td>
|
|
<td>
|
|
<form method="POST" style="display:inline;" onsubmit="return confirm('Delete this FAQ?');">
|
|
<input type="hidden" name="action" value="delete">
|
|
<input type="hidden" name="id" value="<?= $faq['id'] ?>">
|
|
<button type="submit" class="btn-delete">Delete</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|