Spaces:
Running
<?php
Browse filessession_start();
include 'db.php';
include 'header.php';
if (!isset($_SESSION['user_id'])) {
header("Location: index.html");
exit();
}
$user_id = (int)$_SESSION['user_id'];
if (!isset($_SESSION['current_session'])) {
$sqlLast = "SELECT MAX(session_id) AS last FROM chat_logs WHERE user_id = $user_id";
$resLast = mysqli_query($conn, $sqlLast);
$rowLast = mysqli_fetch_assoc($resLast);
$active_session = ($rowLast['last'] ?? 0) + 1;
$_SESSION['current_session'] = $active_session;
} else {
$active_session = $_SESSION['current_session'];
}
// FETCH TOPICS GROUPED BY CATEGORY
$sqlTopics = "SELECT category, user_query FROM chatbot_responses ORDER BY category ASC, user_query ASC";
$resTopics = mysqli_query($conn, $sqlTopics);
$categorizedTopics = [];
while ($row = mysqli_fetch_assoc($resTopics)) {
$cat = $row['category'] ?: 'General';
$categorizedTopics[$cat][] = $row['user_query'];
}
// FETCH PREVIOUS SESSIONS ("Your Chats" history)
$sqlSessions = "SELECT DISTINCT session_id FROM chat_logs WHERE user_id = $user_id ORDER BY session_id DESC";
$resSessions = mysqli_query($conn, $sqlSessions);
$userEmail = $_SESSION['name'] ?? $_SESSION['email'] ?? 'Unknown';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>FoodSave Chatbot</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background: #ecfdf5;
}
.container {
display: flex;
height: calc(100vh - 110px);
padding: 20px;
gap: 20px;
box-sizing: border-box;
}
.sidebar {
width: 260px;
background: #fff;
border-radius: 15px;
padding: 15px;
display: flex;
flex-direction: column;
height: 100%;
box-sizing: border-box;
}
.sidebar h3 {
color: #16a34a;
margin-top: 0;
}
.sidebar-section {
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;
margin-bottom: 15px;
background: #f9fafb;
border-radius: 10px;
padding: 10px;
border: 1px solid #e5e7eb;
}
.sidebar-section h3 {
color: #16a34a;
font-size: 1rem;
margin-bottom: 10px;
margin-top: 0;
flex-shrink: 0;
}
.scroll-container {
overflow-y: auto;
flex: 1;
padding-right: 5px;
}
.scroll-container::-webkit-scrollbar {
width: 5px;
}
.scroll-container::-webkit-scrollbar-thumb {
background: #d1d5db;
border-radius: 10px;
}
.session-btn,
.topic-btn,
#newChatBtn {
width: 100%;
padding: 10px;
border: none;
border-radius: 10px;
margin-bottom: 8px;
cursor: pointer;
text-align: left;
}
.session-btn.active {
background: #22c55e;
color: white;
}
.topic-btn:hover,
#newChatBtn:hover {
background: #22c55e;
color: white;
}
#newChatBtn {
background: #f3f4f6;
font-weight: bold;
margin-bottom: 15px;
flex-shrink: 0;
}
.category-dropdown {
margin-bottom: 8px;
border: 1px solid #e2e8f0;
border-radius: 10px;
background: #fff;
overflow: hidden;
}
.category-header {
padding: 12px 15px;
background: #f8fafc;
font-weight: 600;
font-size: 13px;
cursor: pointer;
list-style: none;
display: flex;
justify-content: space-between;
align-items: center;
color: #16a34a;
border-bottom: 1px solid transparent;
}
details[open] .category-header {
border-bottom: 1px solid #e2e8f0;
background: #f1fdf4;
}
.category-header::after {
content: '▼';
font-size: 9px;
color: #94a3b8;
transition: 0.3s;
}
details[open] .category-header::after {
transform: rotate(180deg);
}
.category-content {
background: #ffffff;
padding: 4px 0;
}
.topic-btn {
width: 100%;
padding: 10px 20px;
border: none;
background: none;
text-align: left;
font-size: 13px;
color: #334155;
cursor: pointer;
display: block;
transition: all 0.2s;
}
.topic-btn:hover {
background: #f0fdf4;
color: #16a34a;
font-weight: 500;
}
.chat-area {
flex: 1;
background: white;
border-radius: 15px;
display: flex;
flex-direction: column;
height: 100%;
}
.chat-header {
background: linear-gradient(to right, #22c55e, #16a34a);
padding: 15px;
color: white;
border-radius: 15px 15px 0 0;
}
.chat-header-content {
display: flex;
align-items: center;
gap: 12px;
}
.chat-body {
flex: 1;
padding: 20px;
overflow-y: auto;
display: flex;
flex-direction: column;
}
.message {
max-width: 80%;
padding: 10px 15px;
border-radius: 18px;
margin-bottom: 10px;
font-size: 14px;
line-height: 1.5;
word-wrap: break-word;
position: relative;
width: fit-content;
display: block;
}
.message.bot {
background: #f1f5f9;
color: #1e293b;
margin-right: auto;
border-bottom-left-radius: 4px;
align-self: flex-start;
}
.user {
background: #22c55e;
color: white;
margin-left: auto;
border-bottom-right-radius: 4px;
align-self: flex-end;
}
.chat-input {
display: flex;
padding: 15px;
gap: 10px;
}
.chat-input input {
flex: 1;
padding: 12px;
border-radius: 10px;
border: 2px solid #22c55e;
}
.chat-input button {
background: #22c55e;
color: white;
border: none;
border-radius: 10px;
padding: 12px 18px;
cursor: pointer;
}
.chat-logo {
width: 40px;
height: 40px;
object-fit: contain;
background: white;
border-radius: 8px;
padding: 2px;
}
.chat-status {
line-height: 1.2;
}
.chat-status strong {
font-size: 16px;
}
.chat-status small {
font-size: 12px;
opacity: 0.9;
}
</style>
</head>
<body>
<div class="container">
<!-- LEFT SIDE -->
<div class="sidebar">
<button id="newChatBtn">+ New Chat</button>
<div class="sidebar-section">
<h3>Topics</h3>
<div class="scroll-container">
<?php if (!empty($categorizedTopics)): ?>
<?php foreach ($categorizedTopics as $categoryName => $queries): ?>
<details class="category-dropdown">
<summary class="category-header">
<?= htmlspecialchars(strtoupper($categoryName)) ?>
</summary>
<div class="category-content">
<?php foreach ($queries as $query): ?>
<button class="topic-btn"
onclick="sendQuestion('<?= htmlspecialchars($query, ENT_QUOTES) ?>')">
<?= htmlspecialchars($query) ?>
</button>
<?php endforeach; ?>
</div>
</details>
<?php endforeach; ?>
<?php else: ?>
<p style="padding:10px; font-size:12px; color:#888;">No topics found.</p>
<?php endif; ?>
</div>
</div>
<div class="sidebar-section">
<h3>Your Chats</h3>
<div class="scroll-container" id="sessionList">
<?php
$sessions = [];
while ($row = mysqli_fetch_assoc($resSessions)) {
$sessions[] = $row['session_id'];
}
if ($active_session && in_array($active_session, $sessions)) {
echo '<button class="session-btn active" onclick="loadSession(' . $active_session . ')" data-session="' . $active_session . '">Chat ' . $active_session . '</button>';
}
foreach ($sessions as $sid) {
if ($sid == $active_session) continue;
echo '<button class="session-btn" onclick="loadSession(' . $sid . ')" data-session="' . $sid . '">Chat ' . $sid . '</button>';
}
?>
</div>
</div>
</div>
<!-- RIGHT SIDE -->
<div class="chat-area">
<div class="chat-header">
<div class="chat-header-content">
<img src="images/logo.png" alt="Logo" class="chat-logo">
<div class="chat-status">
<strong>FoodSave</strong> <br>
<small>Online</small>
</div>
</div>
</div>
<div class="chat-body" id="chatBody">
<!-- Default message will be loaded dynamically -->
</div>
<div class="chat-input">
<input type="text" id="userInput" placeholder="Type your question here...">
<button onclick="manualSend()">Send</button>
</div>
</div>
</div>
<script>
let activeSession = <?= $active_session ?>;
let loadedMessages = [];
window.onload = function() {
if (activeSession > 0) {
loadSession(activeSession);
}
}
function loadSession(session_id) {
activeSession = session_id;
fetch('update_session.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'session_id=' + session_id
});
document.querySelectorAll('.session-btn'
- README.md +8 -5
- admin.php +224 -0
- components/navbar.js +28 -0
- components/sidebar.js +65 -0
- index.html +103 -19
- login.php +103 -0
- script.js +19 -0
- style.css +18 -18
- user_chats.php +129 -0
|
@@ -1,10 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: AdminBot BrainHub 🧠
|
| 3 |
+
colorFrom: purple
|
| 4 |
+
colorTo: green
|
| 5 |
+
emoji: 🐳
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite-v3
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Welcome to your new DeepSite project!
|
| 13 |
+
This project was created with [DeepSite](https://huggingface.co/deepsite).
|
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
```php
|
| 2 |
+
<?php
|
| 3 |
+
session_start();
|
| 4 |
+
include 'db.php';
|
| 5 |
+
|
| 6 |
+
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
|
| 7 |
+
header("Location: login.php");
|
| 8 |
+
exit();
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
// Handle CRUD operations
|
| 12 |
+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
| 13 |
+
if (isset($_POST['add_qa'])) {
|
| 14 |
+
$category = mysqli_real_escape_string($conn, $_POST['category']);
|
| 15 |
+
$question = mysqli_real_escape_string($conn, $_POST['question']);
|
| 16 |
+
$answer = mysqli_real_escape_string($conn, $_POST['answer']);
|
| 17 |
+
|
| 18 |
+
$sql = "INSERT INTO chatbot_responses (category, user_query, bot_response)
|
| 19 |
+
VALUES ('$category', '$question', '$answer')";
|
| 20 |
+
mysqli_query($conn, $sql);
|
| 21 |
+
}
|
| 22 |
+
elseif (isset($_POST['update_qa'])) {
|
| 23 |
+
$id = (int)$_POST['id'];
|
| 24 |
+
$category = mysqli_real_escape_string($conn, $_POST['category']);
|
| 25 |
+
$question = mysqli_real_escape_string($conn, $_POST['question']);
|
| 26 |
+
$answer = mysqli_real_escape_string($conn, $_POST['answer']);
|
| 27 |
+
|
| 28 |
+
$sql = "UPDATE chatbot_responses
|
| 29 |
+
SET category='$category', user_query='$question', bot_response='$answer'
|
| 30 |
+
WHERE id=$id";
|
| 31 |
+
mysqli_query($conn, $sql);
|
| 32 |
+
}
|
| 33 |
+
elseif (isset($_POST['delete_qa'])) {
|
| 34 |
+
$id = (int)$_POST['id'];
|
| 35 |
+
$sql = "DELETE FROM chatbot_responses WHERE id=$id";
|
| 36 |
+
mysqli_query($conn, $sql);
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
// Get all Q&A pairs
|
| 41 |
+
$qa_pairs = [];
|
| 42 |
+
$sql = "SELECT * FROM chatbot_responses ORDER BY category, user_query";
|
| 43 |
+
$result = mysqli_query($conn, $sql);
|
| 44 |
+
while ($row = mysqli_fetch_assoc($result)) {
|
| 45 |
+
$qa_pairs[] = $row;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
// Get all users and their chat history
|
| 49 |
+
$users = [];
|
| 50 |
+
$sql = "SELECT u.id, u.name, u.email, COUNT(DISTINCT cl.session_id) as session_count
|
| 51 |
+
FROM users u
|
| 52 |
+
LEFT JOIN chat_logs cl ON u.id = cl.user_id
|
| 53 |
+
GROUP BY u.id";
|
| 54 |
+
$result = mysqli_query($conn, $sql);
|
| 55 |
+
while ($row = mysqli_fetch_assoc($result)) {
|
| 56 |
+
$users[] = $row;
|
| 57 |
+
}
|
| 58 |
+
?>
|
| 59 |
+
<!DOCTYPE html>
|
| 60 |
+
<html lang="en">
|
| 61 |
+
<head>
|
| 62 |
+
<meta charset="UTF-8">
|
| 63 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 64 |
+
<title>Admin Dashboard - AdminBot BrainHub</title>
|
| 65 |
+
<link rel="stylesheet" href="style.css">
|
| 66 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 67 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 68 |
+
<script src="components/navbar.js"></script>
|
| 69 |
+
<script src="components/sidebar.js"></script>
|
| 70 |
+
</head>
|
| 71 |
+
<body class="bg-gray-100">
|
| 72 |
+
<custom-navbar></custom-navbar>
|
| 73 |
+
<div class="flex">
|
| 74 |
+
<custom-sidebar></custom-sidebar>
|
| 75 |
+
|
| 76 |
+
<main class="flex-1 p-8">
|
| 77 |
+
<div class="mb-8">
|
| 78 |
+
<h1 class="text-3xl font-bold text-gray-800">Admin Dashboard</h1>
|
| 79 |
+
<p class="text-gray-600">Manage chatbot knowledge and user interactions</p>
|
| 80 |
+
</div>
|
| 81 |
+
|
| 82 |
+
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
|
| 83 |
+
<!-- Q&A Management Section -->
|
| 84 |
+
<div class="bg-white rounded-lg shadow p-6">
|
| 85 |
+
<div class="flex justify-between items-center mb-6">
|
| 86 |
+
<h2 class="text-xl font-semibold">Knowledge Base</h2>
|
| 87 |
+
<button onclick="toggleQaForm()" class="bg-blue-500 text-white px-4 py-2 rounded-lg hover:bg-blue-600">
|
| 88 |
+
Add New Q&A
|
| 89 |
+
</button>
|
| 90 |
+
</div>
|
| 91 |
+
|
| 92 |
+
<!-- Add/Edit Form (Hidden by default) -->
|
| 93 |
+
<div id="qaForm" class="hidden mb-6 p-4 bg-gray-50 rounded-lg">
|
| 94 |
+
<form method="POST">
|
| 95 |
+
<input type="hidden" name="id" id="editId">
|
| 96 |
+
<div class="mb-4">
|
| 97 |
+
<label class="block text-gray-700 mb-2">Category</label>
|
| 98 |
+
<input type="text" name="category" id="category" class="w-full p-2 border rounded" required>
|
| 99 |
+
</div>
|
| 100 |
+
<div class="mb-4">
|
| 101 |
+
<label class="block text-gray-700 mb-2">Question</label>
|
| 102 |
+
<input type="text" name="question" id="question" class="w-full p-2 border rounded" required>
|
| 103 |
+
</div>
|
| 104 |
+
<div class="mb-4">
|
| 105 |
+
<label class="block text-gray-700 mb-2">Answer</label>
|
| 106 |
+
<textarea name="answer" id="answer" rows="3" class="w-full p-2 border rounded" required></textarea>
|
| 107 |
+
</div>
|
| 108 |
+
<div class="flex gap-2">
|
| 109 |
+
<button type="submit" name="add_qa" id="addBtn" class="bg-green-500 text-white px-4 py-2 rounded-lg hover:bg-green-600">
|
| 110 |
+
Add Q&A
|
| 111 |
+
</button>
|
| 112 |
+
<button type="submit" name="update_qa" id="updateBtn" class="hidden bg-blue-500 text-white px-4 py-2 rounded-lg hover:bg-blue-600">
|
| 113 |
+
Update Q&A
|
| 114 |
+
</button>
|
| 115 |
+
<button type="button" onclick="toggleQaForm()" class="bg-gray-500 text-white px-4 py-2 rounded-lg hover:bg-gray-600">
|
| 116 |
+
Cancel
|
| 117 |
+
</button>
|
| 118 |
+
</div>
|
| 119 |
+
</form>
|
| 120 |
+
</div>
|
| 121 |
+
|
| 122 |
+
<!-- Q&A List -->
|
| 123 |
+
<div class="overflow-x-auto">
|
| 124 |
+
<table class="min-w-full bg-white">
|
| 125 |
+
<thead>
|
| 126 |
+
<tr>
|
| 127 |
+
<th class="py-2 px-4 border-b">Category</th>
|
| 128 |
+
<th class="py-2 px-4 border-b">Question</th>
|
| 129 |
+
<th class="py-2 px-4 border-b">Answer</th>
|
| 130 |
+
<th class="py-2 px-4 border-b">Actions</th>
|
| 131 |
+
</tr>
|
| 132 |
+
</thead>
|
| 133 |
+
<tbody>
|
| 134 |
+
<?php foreach ($qa_pairs as $qa): ?>
|
| 135 |
+
<tr>
|
| 136 |
+
<td class="py-2 px-4 border-b"><?= htmlspecialchars($qa['category']) ?></td>
|
| 137 |
+
<td class="py-2 px-4 border-b"><?= htmlspecialchars($qa['user_query']) ?></td>
|
| 138 |
+
<td class="py-2 px-4 border-b"><?= htmlspecialchars($qa['bot_response']) ?></td>
|
| 139 |
+
<td class="py-2 px-4 border-b">
|
| 140 |
+
<button onclick="editQa(<?= $qa['id'] ?>, '<?= addslashes($qa['category']) ?>', '<?= addslashes($qa['user_query']) ?>', `<?= addslashes($qa['bot_response']) ?>`)"
|
| 141 |
+
class="text-blue-500 hover:text-blue-700 mr-2">
|
| 142 |
+
<i data-feather="edit"></i>
|
| 143 |
+
</button>
|
| 144 |
+
<form method="POST" class="inline">
|
| 145 |
+
<input type="hidden" name="id" value="<?= $qa['id'] ?>">
|
| 146 |
+
<button type="submit" name="delete_qa" class="text-red-500 hover:text-red-700">
|
| 147 |
+
<i data-feather="trash-2"></i>
|
| 148 |
+
</button>
|
| 149 |
+
</form>
|
| 150 |
+
</td>
|
| 151 |
+
</tr>
|
| 152 |
+
<?php endforeach; ?>
|
| 153 |
+
</tbody>
|
| 154 |
+
</table>
|
| 155 |
+
</div>
|
| 156 |
+
</div>
|
| 157 |
+
|
| 158 |
+
<!-- User Management Section -->
|
| 159 |
+
<div class="bg-white rounded-lg shadow p-6">
|
| 160 |
+
<h2 class="text-xl font-semibold mb-6">User Interactions</h2>
|
| 161 |
+
|
| 162 |
+
<div class="overflow-x-auto">
|
| 163 |
+
<table class="min-w-full bg-white">
|
| 164 |
+
<thead>
|
| 165 |
+
<tr>
|
| 166 |
+
<th class="py-2 px-4 border-b">User</th>
|
| 167 |
+
<th class="py-2 px-4 border-b">Email</th>
|
| 168 |
+
<th class="py-2 px-4 border-b">Chat Sessions</th>
|
| 169 |
+
<th class="py-2 px-4 border-b">Actions</th>
|
| 170 |
+
</tr>
|
| 171 |
+
</thead>
|
| 172 |
+
<tbody>
|
| 173 |
+
<?php foreach ($users as $user): ?>
|
| 174 |
+
<tr>
|
| 175 |
+
<td class="py-2 px-4 border-b"><?= htmlspecialchars($user['name']) ?></td>
|
| 176 |
+
<td class="py-2 px-4 border-b"><?= htmlspecialchars($user['email']) ?></td>
|
| 177 |
+
<td class="py-2 px-4 border-b"><?= $user['session_count'] ?></td>
|
| 178 |
+
<td class="py-2 px-4 border-b">
|
| 179 |
+
<a href="user_chats.php?user_id=<?= $user['id'] ?>" class="text-blue-500 hover:text-blue-700">
|
| 180 |
+
<i data-feather="eye"></i> View Chats
|
| 181 |
+
</a>
|
| 182 |
+
</td>
|
| 183 |
+
</tr>
|
| 184 |
+
<?php endforeach; ?>
|
| 185 |
+
</tbody>
|
| 186 |
+
</table>
|
| 187 |
+
</div>
|
| 188 |
+
</div>
|
| 189 |
+
</div>
|
| 190 |
+
</main>
|
| 191 |
+
</div>
|
| 192 |
+
|
| 193 |
+
<script>
|
| 194 |
+
feather.replace();
|
| 195 |
+
|
| 196 |
+
function toggleQaForm() {
|
| 197 |
+
const form = document.getElementById('qaForm');
|
| 198 |
+
form.classList.toggle('hidden');
|
| 199 |
+
|
| 200 |
+
// Reset form when showing
|
| 201 |
+
if (!form.classList.contains('hidden')) {
|
| 202 |
+
document.getElementById('editId').value = '';
|
| 203 |
+
document.getElementById('category').value = '';
|
| 204 |
+
document.getElementById('question').value = '';
|
| 205 |
+
document.getElementById('answer').value = '';
|
| 206 |
+
document.getElementById('addBtn').classList.remove('hidden');
|
| 207 |
+
document.getElementById('updateBtn').classList.add('hidden');
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
function editQa(id, category, question, answer) {
|
| 212 |
+
toggleQaForm();
|
| 213 |
+
document.getElementById('editId').value = id;
|
| 214 |
+
document.getElementById('category').value = category;
|
| 215 |
+
document.getElementById('question').value = question;
|
| 216 |
+
document.getElementById('answer').value = answer;
|
| 217 |
+
document.getElementById('addBtn').classList.add('hidden');
|
| 218 |
+
document.getElementById('updateBtn').classList.remove('hidden');
|
| 219 |
+
}
|
| 220 |
+
</script>
|
| 221 |
+
<script src="script.js"></script>
|
| 222 |
+
</body>
|
| 223 |
+
</html>
|
| 224 |
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class CustomNavbar extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
.navbar {
|
| 7 |
+
height: 64px;
|
| 8 |
+
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
|
| 9 |
+
}
|
| 10 |
+
</style>
|
| 11 |
+
<nav class="navbar bg-white w-full fixed z-10">
|
| 12 |
+
<div class="flex items-center justify-between h-full px-6">
|
| 13 |
+
<div class="flex items-center">
|
| 14 |
+
<a href="/" class="text-xl font-bold text-gray-800">Admin Pulse</a>
|
| 15 |
+
</div>
|
| 16 |
+
<div class="flex items-center space-x-4">
|
| 17 |
+
<div class="relative">
|
| 18 |
+
<i data-feather="bell" class="text-gray-600 hover:text-gray-900 cursor-pointer"></i>
|
| 19 |
+
<span class="absolute -top-1 -right-1 h-4 w-4 rounded-full bg-red-500 text-white text-xs flex items-center justify-center">3</span>
|
| 20 |
+
</div>
|
| 21 |
+
<div class="h-8 w-8 rounded-full bg-blue-500 flex items-center justify-center text-white font-medium">AD</div>
|
| 22 |
+
</div>
|
| 23 |
+
</div>
|
| 24 |
+
</nav>
|
| 25 |
+
`;
|
| 26 |
+
}
|
| 27 |
+
}
|
| 28 |
+
customElements.define('custom-navbar', CustomNavbar);
|
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class CustomSidebar extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
.sidebar {
|
| 7 |
+
width: 240px;
|
| 8 |
+
height: calc(100vh - 64px);
|
| 9 |
+
top: 64px;
|
| 10 |
+
}
|
| 11 |
+
.nav-link:hover {
|
| 12 |
+
background-color: rgba(59, 130, 246, 0.1);
|
| 13 |
+
}
|
| 14 |
+
.nav-link.active {
|
| 15 |
+
background-color: rgba(59, 130, 246, 0.1);
|
| 16 |
+
color: #3b82f6;
|
| 17 |
+
border-left: 3px solid #3b82f6;
|
| 18 |
+
}
|
| 19 |
+
</style>
|
| 20 |
+
<aside class="sidebar bg-white fixed shadow sidebar-transition">
|
| 21 |
+
<div class="p-4">
|
| 22 |
+
<ul class="space-y-1">
|
| 23 |
+
<li>
|
| 24 |
+
<a href="/" class="nav-link active flex items-center p-3 rounded-lg">
|
| 25 |
+
<i data-feather="home" class="mr-3"></i>
|
| 26 |
+
<span>Dashboard</span>
|
| 27 |
+
</a>
|
| 28 |
+
</li>
|
| 29 |
+
<li>
|
| 30 |
+
<a href="/users" class="nav-link flex items-center p-3 rounded-lg">
|
| 31 |
+
<i data-feather="users" class="mr-3"></i>
|
| 32 |
+
<span>Users</span>
|
| 33 |
+
</a>
|
| 34 |
+
</li>
|
| 35 |
+
<li>
|
| 36 |
+
<a href="/settings" class="nav-link flex items-center p-3 rounded-lg">
|
| 37 |
+
<i data-feather="settings" class="mr-3"></i>
|
| 38 |
+
<span>Settings</span>
|
| 39 |
+
</a>
|
| 40 |
+
</li>
|
| 41 |
+
<li>
|
| 42 |
+
<a href="/reports" class="nav-link flex items-center p-3 rounded-lg">
|
| 43 |
+
<i data-feather="file-text" class="mr-3"></i>
|
| 44 |
+
<span>Reports</span>
|
| 45 |
+
</a>
|
| 46 |
+
</li>
|
| 47 |
+
<li>
|
| 48 |
+
<a href="/admin.php" class="nav-link flex items-center p-3 rounded-lg">
|
| 49 |
+
<i data-feather="shield" class="mr-3"></i>
|
| 50 |
+
<span>Admin Panel</span>
|
| 51 |
+
</a>
|
| 52 |
+
</li>
|
| 53 |
+
<li>
|
| 54 |
+
<a href="/logout" class="nav-link flex items-center p-3 rounded-lg text-red-500">
|
| 55 |
+
<i data-feather="log-out" class="mr-3"></i>
|
| 56 |
+
<span>Logout</span>
|
| 57 |
+
</a>
|
| 58 |
+
</li>
|
| 59 |
+
</ul>
|
| 60 |
+
</div>
|
| 61 |
+
</aside>
|
| 62 |
+
`;
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
customElements.define('custom-sidebar', CustomSidebar);
|
|
@@ -1,19 +1,103 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Admin Pulse Dashboard</title>
|
| 7 |
+
<link rel="stylesheet" href="style.css">
|
| 8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 9 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 10 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
| 11 |
+
<script src="components/navbar.js"></script>
|
| 12 |
+
<script src="components/sidebar.js"></script>
|
| 13 |
+
</head>
|
| 14 |
+
<body class="bg-gray-100">
|
| 15 |
+
<custom-navbar></custom-navbar>
|
| 16 |
+
<div class="flex">
|
| 17 |
+
<custom-sidebar></custom-sidebar>
|
| 18 |
+
|
| 19 |
+
<main class="flex-1 p-8">
|
| 20 |
+
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
| 21 |
+
<!-- Stats Cards -->
|
| 22 |
+
<div class="bg-white rounded-lg shadow p-6">
|
| 23 |
+
<div class="flex items-center justify-between">
|
| 24 |
+
<div>
|
| 25 |
+
<p class="text-gray-500">Total Users</p>
|
| 26 |
+
<h3 class="text-2xl font-bold">1,234</h3>
|
| 27 |
+
</div>
|
| 28 |
+
<div class="p-3 rounded-full bg-blue-100 text-blue-600">
|
| 29 |
+
<i data-feather="users"></i>
|
| 30 |
+
</div>
|
| 31 |
+
</div>
|
| 32 |
+
</div>
|
| 33 |
+
|
| 34 |
+
<div class="bg-white rounded-lg shadow p-6">
|
| 35 |
+
<div class="flex items-center justify-between">
|
| 36 |
+
<div>
|
| 37 |
+
<p class="text-gray-500">Active Sessions</p>
|
| 38 |
+
<h3 class="text-2xl font-bold">56</h3>
|
| 39 |
+
</div>
|
| 40 |
+
<div class="p-3 rounded-full bg-green-100 text-green-600">
|
| 41 |
+
<i data-feather="activity"></i>
|
| 42 |
+
</div>
|
| 43 |
+
</div>
|
| 44 |
+
</div>
|
| 45 |
+
|
| 46 |
+
<div class="bg-white rounded-lg shadow p-6">
|
| 47 |
+
<div class="flex items-center justify-between">
|
| 48 |
+
<div>
|
| 49 |
+
<p class="text-gray-500">Server Load</p>
|
| 50 |
+
<h3 class="text-2xl font-bold">24%</h3>
|
| 51 |
+
</div>
|
| 52 |
+
<div class="p-3 rounded-full bg-purple-100 text-purple-600">
|
| 53 |
+
<i data-feather="server"></i>
|
| 54 |
+
</div>
|
| 55 |
+
</div>
|
| 56 |
+
</div>
|
| 57 |
+
</div>
|
| 58 |
+
|
| 59 |
+
<!-- Recent Activity -->
|
| 60 |
+
<div class="mt-8 bg-white rounded-lg shadow overflow-hidden">
|
| 61 |
+
<div class="p-6 border-b">
|
| 62 |
+
<h2 class="text-xl font-semibold">Recent Activity</h2>
|
| 63 |
+
</div>
|
| 64 |
+
<div class="divide-y">
|
| 65 |
+
<div class="p-4 flex items-center">
|
| 66 |
+
<div class="p-3 rounded-full bg-blue-100 text-blue-600 mr-4">
|
| 67 |
+
<i data-feather="user-plus"></i>
|
| 68 |
+
</div>
|
| 69 |
+
<div>
|
| 70 |
+
<p class="font-medium">New user registered</p>
|
| 71 |
+
<p class="text-gray-500 text-sm">John Doe - 2 minutes ago</p>
|
| 72 |
+
</div>
|
| 73 |
+
</div>
|
| 74 |
+
<div class="p-4 flex items-center">
|
| 75 |
+
<div class="p-3 rounded-full bg-green-100 text-green-600 mr-4">
|
| 76 |
+
<i data-feather="settings"></i>
|
| 77 |
+
</div>
|
| 78 |
+
<div>
|
| 79 |
+
<p class="font-medium">System updated</p>
|
| 80 |
+
<p class="text-gray-500 text-sm">Version 2.3.1 - 1 hour ago</p>
|
| 81 |
+
</div>
|
| 82 |
+
</div>
|
| 83 |
+
<div class="p-4 flex items-center">
|
| 84 |
+
<div class="p-3 rounded-full bg-yellow-100 text-yellow-600 mr-4">
|
| 85 |
+
<i data-feather="alert-triangle"></i>
|
| 86 |
+
</div>
|
| 87 |
+
<div>
|
| 88 |
+
<p class="font-medium">Warning notification</p>
|
| 89 |
+
<p class="text-gray-500 text-sm">High CPU usage - 3 hours ago</p>
|
| 90 |
+
</div>
|
| 91 |
+
</div>
|
| 92 |
+
</div>
|
| 93 |
+
</div>
|
| 94 |
+
</main>
|
| 95 |
+
</div>
|
| 96 |
+
|
| 97 |
+
<script>
|
| 98 |
+
feather.replace();
|
| 99 |
+
</script>
|
| 100 |
+
<script src="script.js"></script>
|
| 101 |
+
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 102 |
+
</body>
|
| 103 |
+
</html>
|
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
```php
|
| 2 |
+
<?php
|
| 3 |
+
session_start();
|
| 4 |
+
include 'db.php';
|
| 5 |
+
|
| 6 |
+
if (isset($_SESSION['user_id'])) {
|
| 7 |
+
header("Location: " . ($_SESSION['role'] === 'admin' ? 'admin.php' : 'index.php'));
|
| 8 |
+
exit();
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
| 12 |
+
$email = mysqli_real_escape_string($conn, $_POST['email']);
|
| 13 |
+
$password = $_POST['password'];
|
| 14 |
+
|
| 15 |
+
$sql = "SELECT * FROM users WHERE email = '$email'";
|
| 16 |
+
$result = mysqli_query($conn, $sql);
|
| 17 |
+
|
| 18 |
+
if (mysqli_num_rows($result) == 1) {
|
| 19 |
+
$user = mysqli_fetch_assoc($result);
|
| 20 |
+
if (password_verify($password, $user['password'])) {
|
| 21 |
+
$_SESSION['user_id'] = $user['id'];
|
| 22 |
+
$_SESSION['name'] = $user['name'];
|
| 23 |
+
$_SESSION['email'] = $user['email'];
|
| 24 |
+
$_SESSION['role'] = $user['role'];
|
| 25 |
+
|
| 26 |
+
header("Location: " . ($user['role'] === 'admin' ? 'admin.php' : 'index.php'));
|
| 27 |
+
exit();
|
| 28 |
+
} else {
|
| 29 |
+
$error = "Invalid email or password";
|
| 30 |
+
}
|
| 31 |
+
} else {
|
| 32 |
+
$error = "Invalid email or password";
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
?>
|
| 36 |
+
<!DOCTYPE html>
|
| 37 |
+
<html lang="en">
|
| 38 |
+
<head>
|
| 39 |
+
<meta charset="UTF-8">
|
| 40 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 41 |
+
<title>Login - AdminBot BrainHub</title>
|
| 42 |
+
<link rel="stylesheet" href="style.css">
|
| 43 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 44 |
+
<style>
|
| 45 |
+
.login-container {
|
| 46 |
+
max-width: 400px;
|
| 47 |
+
margin: 0 auto;
|
| 48 |
+
margin-top: 100px;
|
| 49 |
+
}
|
| 50 |
+
</style>
|
| 51 |
+
</head>
|
| 52 |
+
<body class="bg-gray-100">
|
| 53 |
+
<div class="login-container bg-white p-8 rounded-lg shadow-lg">
|
| 54 |
+
<h1 class="text-2xl font-bold text-center mb-6">AdminBot BrainHub</h1>
|
| 55 |
+
|
| 56 |
+
<?php if (isset($error)): ?>
|
| 57 |
+
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
|
| 58 |
+
<?= htmlspecialchars($error) ?>
|
| 59 |
+
</div>
|
| 60 |
+
<?php endif; ?>
|
| 61 |
+
|
| 62 |
+
<form method="POST">
|
| 63 |
+
<div class="mb-4">
|
| 64 |
+
<label class="block text-gray-700 mb-2">Email</label>
|
| 65 |
+
<input type="email" name="email" required
|
| 66 |
+
class="w-full p-2 border rounded focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 67 |
+
</div>
|
| 68 |
+
<div class="mb-6">
|
| 69 |
+
<label class="block text-gray-700 mb-2">Password</label>
|
| 70 |
+
<input type="password" name="password" required
|
| 71 |
+
class="w-full p-2 border rounded focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 72 |
+
</div>
|
| 73 |
+
<button type="submit"
|
| 74 |
+
class="w-full bg-blue-500 text-white py-2 px-4 rounded hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 75 |
+
Login
|
| 76 |
+
</button>
|
| 77 |
+
</form>
|
| 78 |
+
|
| 79 |
+
<p class="text-center mt-4 text-gray-600">
|
| 80 |
+
Demo Admin: admin@admin.com / admin123
|
| 81 |
+
</p>
|
| 82 |
+
</div>
|
| 83 |
+
</body>
|
| 84 |
+
</html>
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
These files create a complete admin dashboard for managing the chatbot's knowledge base and user interactions. The system includes:
|
| 88 |
+
|
| 89 |
+
1. Admin panel with CRUD operations for Q&A pairs
|
| 90 |
+
2. User management section showing all users and their chat history
|
| 91 |
+
3. Detailed view of individual user chat sessions
|
| 92 |
+
4. Login system with admin/user roles
|
| 93 |
+
5. Database setup with sample admin user
|
| 94 |
+
|
| 95 |
+
The design follows the reference dashboard style while adding the specific functionality requested. The admin can:
|
| 96 |
+
- Add/edit/delete questions and answers
|
| 97 |
+
- View all users and their chat histories
|
| 98 |
+
- See detailed conversation logs per user session
|
| 99 |
+
|
| 100 |
+
The system uses the same styling components (navbar, sidebar) as the reference dashboard for consistency.
|
| 101 |
+
___METADATA_START___
|
| 102 |
+
{"isNew":true,"userName":"gutzu1015"}
|
| 103 |
+
___METADATA_END___
|
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Main script file for the admin dashboard
|
| 2 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 3 |
+
// Initialize tooltips
|
| 4 |
+
const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
|
| 5 |
+
tooltipTriggerList.map(function (tooltipTriggerEl) {
|
| 6 |
+
return new bootstrap.Tooltip(tooltipTriggerEl);
|
| 7 |
+
});
|
| 8 |
+
|
| 9 |
+
// Make sidebar links active on click
|
| 10 |
+
const navLinks = document.querySelectorAll('.nav-link');
|
| 11 |
+
navLinks.forEach(link => {
|
| 12 |
+
link.addEventListener('click', function() {
|
| 13 |
+
navLinks.forEach(l => l.classList.remove('active'));
|
| 14 |
+
this.classList.add('active');
|
| 15 |
+
});
|
| 16 |
+
});
|
| 17 |
+
|
| 18 |
+
// Responsive sidebar toggle (can be added later)
|
| 19 |
+
});
|
|
@@ -1,28 +1,28 @@
|
|
|
|
|
| 1 |
body {
|
| 2 |
-
|
| 3 |
-
font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
|
| 4 |
}
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
}
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
margin-top: 5px;
|
| 16 |
}
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
margin: 0 auto;
|
| 21 |
-
padding: 16px;
|
| 22 |
-
border: 1px solid lightgray;
|
| 23 |
-
border-radius: 16px;
|
| 24 |
}
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* Custom styles that can't be handled by Tailwind */
|
| 2 |
body {
|
| 3 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
|
|
|
| 4 |
}
|
| 5 |
|
| 6 |
+
/* Smooth transitions for sidebar */
|
| 7 |
+
.sidebar-transition {
|
| 8 |
+
transition: all 0.3s ease;
|
| 9 |
}
|
| 10 |
|
| 11 |
+
/* Custom scrollbar */
|
| 12 |
+
::-webkit-scrollbar {
|
| 13 |
+
width: 6px;
|
| 14 |
+
height: 6px;
|
|
|
|
| 15 |
}
|
| 16 |
|
| 17 |
+
::-webkit-scrollbar-track {
|
| 18 |
+
background: #f1f1f1;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
}
|
| 20 |
|
| 21 |
+
::-webkit-scrollbar-thumb {
|
| 22 |
+
background: #888;
|
| 23 |
+
border-radius: 3px;
|
| 24 |
}
|
| 25 |
+
|
| 26 |
+
::-webkit-scrollbar-thumb:hover {
|
| 27 |
+
background: #555;
|
| 28 |
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
```php
|
| 2 |
+
<?php
|
| 3 |
+
session_start();
|
| 4 |
+
include 'db.php';
|
| 5 |
+
|
| 6 |
+
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
|
| 7 |
+
header("Location: login.php");
|
| 8 |
+
exit();
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
$user_id = (int)$_GET['user_id'];
|
| 12 |
+
|
| 13 |
+
// Get user info
|
| 14 |
+
$sql = "SELECT name, email FROM users WHERE id = $user_id";
|
| 15 |
+
$result = mysqli_query($conn, $sql);
|
| 16 |
+
$user = mysqli_fetch_assoc($result);
|
| 17 |
+
|
| 18 |
+
// Get all sessions for this user
|
| 19 |
+
$sessions = [];
|
| 20 |
+
$sql = "SELECT DISTINCT session_id FROM chat_logs WHERE user_id = $user_id ORDER BY session_id DESC";
|
| 21 |
+
$result = mysqli_query($conn, $sql);
|
| 22 |
+
while ($row = mysqli_fetch_assoc($result)) {
|
| 23 |
+
$sessions[] = $row['session_id'];
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
// Get messages for selected session
|
| 27 |
+
$selected_session = isset($_GET['session']) ? (int)$_GET['session'] : ($sessions[0] ?? 0);
|
| 28 |
+
$messages = [];
|
| 29 |
+
|
| 30 |
+
if ($selected_session > 0) {
|
| 31 |
+
$sql = "SELECT * FROM chat_logs
|
| 32 |
+
WHERE user_id = $user_id AND session_id = $selected_session
|
| 33 |
+
ORDER BY timestamp ASC";
|
| 34 |
+
$result = mysqli_query($conn, $sql);
|
| 35 |
+
while ($row = mysqli_fetch_assoc($result)) {
|
| 36 |
+
$messages[] = $row;
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
?>
|
| 40 |
+
<!DOCTYPE html>
|
| 41 |
+
<html lang="en">
|
| 42 |
+
<head>
|
| 43 |
+
<meta charset="UTF-8">
|
| 44 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 45 |
+
<title>User Chats - AdminBot BrainHub</title>
|
| 46 |
+
<link rel="stylesheet" href="style.css">
|
| 47 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 48 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 49 |
+
<script src="components/navbar.js"></script>
|
| 50 |
+
<script src="components/sidebar.js"></script>
|
| 51 |
+
<style>
|
| 52 |
+
.chat-container {
|
| 53 |
+
max-height: 500px;
|
| 54 |
+
overflow-y: auto;
|
| 55 |
+
}
|
| 56 |
+
.user-message {
|
| 57 |
+
background-color: #e3f2fd;
|
| 58 |
+
border-radius: 10px;
|
| 59 |
+
padding: 10px;
|
| 60 |
+
margin: 5px 0;
|
| 61 |
+
max-width: 80%;
|
| 62 |
+
margin-left: auto;
|
| 63 |
+
}
|
| 64 |
+
.bot-message {
|
| 65 |
+
background-color: #f1f1f1;
|
| 66 |
+
border-radius: 10px;
|
| 67 |
+
padding: 10px;
|
| 68 |
+
margin: 5px 0;
|
| 69 |
+
max-width: 80%;
|
| 70 |
+
}
|
| 71 |
+
</style>
|
| 72 |
+
</head>
|
| 73 |
+
<body class="bg-gray-100">
|
| 74 |
+
<custom-navbar></custom-navbar>
|
| 75 |
+
<div class="flex">
|
| 76 |
+
<custom-sidebar></custom-sidebar>
|
| 77 |
+
|
| 78 |
+
<main class="flex-1 p-8">
|
| 79 |
+
<div class="mb-6">
|
| 80 |
+
<a href="admin.php" class="text-blue-500 hover:text-blue-700 flex items-center">
|
| 81 |
+
<i data-feather="arrow-left"></i>
|
| 82 |
+
<span class="ml-2">Back to Admin</span>
|
| 83 |
+
</a>
|
| 84 |
+
<h1 class="text-2xl font-bold mt-4">Chat History for <?= htmlspecialchars($user['name']) ?></h1>
|
| 85 |
+
<p class="text-gray-600"><?= htmlspecialchars($user['email']) ?></p>
|
| 86 |
+
</div>
|
| 87 |
+
|
| 88 |
+
<div class="grid grid-cols-1 lg:grid-cols-4 gap-6">
|
| 89 |
+
<!-- Session List -->
|
| 90 |
+
<div class="lg:col-span-1 bg-white rounded-lg shadow p-4">
|
| 91 |
+
<h2 class="text-lg font-semibold mb-4">Chat Sessions</h2>
|
| 92 |
+
<div class="space-y-2">
|
| 93 |
+
<?php foreach ($sessions as $session): ?>
|
| 94 |
+
<a href="?user_id=<?= $user_id ?>&session=<?= $session ?>"
|
| 95 |
+
class="block p-3 rounded-lg <?= $session == $selected_session ? 'bg-blue-100 text-blue-700' : 'hover:bg-gray-100' ?>">
|
| 96 |
+
Session #<?= $session ?>
|
| 97 |
+
</a>
|
| 98 |
+
<?php endforeach; ?>
|
| 99 |
+
</div>
|
| 100 |
+
</div>
|
| 101 |
+
|
| 102 |
+
<!-- Chat Messages -->
|
| 103 |
+
<div class="lg:col-span-3 bg-white rounded-lg shadow p-6">
|
| 104 |
+
<div class="chat-container">
|
| 105 |
+
<?php if (empty($messages)): ?>
|
| 106 |
+
<p class="text-gray-500">No messages found in this session.</p>
|
| 107 |
+
<?php else: ?>
|
| 108 |
+
<?php foreach ($messages as $msg): ?>
|
| 109 |
+
<div class="<?= $msg['type'] === 'user' ? 'user-message' : 'bot-message' ?>">
|
| 110 |
+
<p><?= htmlspecialchars($msg['message']) ?></p>
|
| 111 |
+
<p class="text-xs text-gray-500 mt-1">
|
| 112 |
+
<?= date('M j, Y g:i A', strtotime($msg['timestamp'])) ?>
|
| 113 |
+
</p>
|
| 114 |
+
</div>
|
| 115 |
+
<?php endforeach; ?>
|
| 116 |
+
<?php endif; ?>
|
| 117 |
+
</div>
|
| 118 |
+
</div>
|
| 119 |
+
</div>
|
| 120 |
+
</main>
|
| 121 |
+
</div>
|
| 122 |
+
|
| 123 |
+
<script>
|
| 124 |
+
feather.replace();
|
| 125 |
+
</script>
|
| 126 |
+
<script src="script.js"></script>
|
| 127 |
+
</body>
|
| 128 |
+
</html>
|
| 129 |
+
```
|