164 lines
6.2 KiB
PHP
164 lines
6.2 KiB
PHP
<?php
|
|
require_once 'auth.php';
|
|
if (!is_logged_in()) {
|
|
header('Location: login.php');
|
|
exit();
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<!-- SEO & Meta Tags -->
|
|
<title>AI Chat - FinMox</title>
|
|
<meta name="description" content="FinMox Flow - a multi-tenant SaaS platform for HR and Operations teams. Built with Flatlogic Generator.">
|
|
<meta name="keywords" content="finmox, hr, operations, saas, candidate tracking, onboarding, automations, ai copilot, flatlogic">
|
|
|
|
<!-- Social Media Meta Tags -->
|
|
<meta property="og:title" content="FinMox Flow">
|
|
<meta property="og:description" content="A multi-tenant SaaS platform for HR and Operations teams.">
|
|
<meta property="og:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '', ENT_QUOTES, 'UTF-8'); ?>">
|
|
<meta name="twitter:card" content="summary_large_image">
|
|
<meta name="twitter:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? '', ENT_QUOTES, 'UTF-8'); ?>">
|
|
|
|
<!-- Stylesheets -->
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
<style>
|
|
#chat-container {
|
|
max-width: 800px;
|
|
margin: 2rem auto;
|
|
border: 1px solid #ddd;
|
|
border-radius: 8px;
|
|
padding: 1rem;
|
|
height: 70vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
#chat-messages {
|
|
flex-grow: 1;
|
|
overflow-y: auto;
|
|
padding: 1rem;
|
|
border-bottom: 1px solid #ddd;
|
|
}
|
|
.message {
|
|
margin-bottom: 1rem;
|
|
}
|
|
.message .sender {
|
|
font-weight: bold;
|
|
}
|
|
.message .content {
|
|
padding: 0.5rem 1rem;
|
|
border-radius: 8px;
|
|
display: inline-block;
|
|
}
|
|
.user-message .content {
|
|
background-color: #e9f5ff;
|
|
}
|
|
.ai-message .content {
|
|
background-color: #f8f9fa;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<header class="header d-flex justify-content-between align-items-center">
|
|
<div class="logo">FinMox<span class="dot">.</span></div>
|
|
<nav class="d-flex align-items-center">
|
|
<a href="index.php" class="btn btn-outline-primary me-2">Home</a>
|
|
<a href="chat.php" class="btn btn-outline-primary me-2">Chat</a>
|
|
<a href="dashboard.php" class="btn btn-outline-primary me-2">Dashboard</a>
|
|
<a href="workflows.php" class="btn btn-outline-primary me-3">Workflows</a>
|
|
<div class="dropdown">
|
|
<button class="btn btn-outline-secondary dropdown-toggle" type="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<?php echo htmlspecialchars($_SESSION['username']); ?>
|
|
</button>
|
|
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
|
|
<?php if (hasPermission('manage_roles')): ?>
|
|
<li><a class="dropdown-item" href="roles.php">Manage Roles</a></li>
|
|
<li><hr class="dropdown-divider"></li>
|
|
<?php endif; ?>
|
|
<li><a class="dropdown-item" href="logout.php">Logout</a></li>
|
|
</ul>
|
|
</div>
|
|
</nav>
|
|
</header>
|
|
|
|
<main class="main-content">
|
|
<div id="chat-container">
|
|
<div id="chat-messages"></div>
|
|
<div class="input-group mt-3">
|
|
<input type="text" id="user-input" class="form-control" placeholder="Ask the AI Assistant...">
|
|
<button id="send-btn" class="btn btn-primary">Send</button>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
const chatMessages = document.getElementById('chat-messages');
|
|
const userInput = document.getElementById('user-input');
|
|
const sendBtn = document.getElementById('send-btn');
|
|
|
|
function addMessage(sender, content) {
|
|
const messageDiv = document.createElement('div');
|
|
messageDiv.classList.add('message', sender + '-message');
|
|
|
|
const senderDiv = document.createElement('div');
|
|
senderDiv.classList.add('sender');
|
|
senderDiv.textContent = sender === 'user' ? 'You' : 'AI Assistant';
|
|
|
|
const contentDiv = document.createElement('div');
|
|
contentDiv.classList.add('content');
|
|
contentDiv.textContent = content;
|
|
|
|
messageDiv.appendChild(senderDiv);
|
|
messageDiv.appendChild(contentDiv);
|
|
chatMessages.appendChild(messageDiv);
|
|
chatMessages.scrollTop = chatMessages.scrollHeight;
|
|
}
|
|
|
|
async function sendMessage() {
|
|
const message = userInput.value.trim();
|
|
if (!message) return;
|
|
|
|
addMessage('user', message);
|
|
userInput.value = '';
|
|
sendBtn.disabled = true;
|
|
|
|
try {
|
|
const response = await fetch('api/chat.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ message })
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error('Network response was not ok');
|
|
}
|
|
|
|
const data = await response.json();
|
|
const aiReply = data.reply || data.error || 'No reply from AI.';
|
|
addMessage('ai', aiReply);
|
|
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
addMessage('ai', 'Sorry, something went wrong. Please check the console.');
|
|
} finally {
|
|
sendBtn.disabled = false;
|
|
}
|
|
}
|
|
|
|
sendBtn.addEventListener('click', sendMessage);
|
|
userInput.addEventListener('keypress', (e) => {
|
|
if (e.key === 'Enter') {
|
|
sendMessage();
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|