Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
627c05e261 | ||
|
|
86776affbc | ||
|
|
3317cb7a89 | ||
|
|
6a8221f33b | ||
|
|
78612e6972 | ||
|
|
7dc21c2972 | ||
|
|
d8e46675be | ||
|
|
046470377a |
91
api/chat.php
Normal file
91
api/chat.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
require_once __DIR__ . '/../ai/LocalAIApi.php';
|
||||
require_once __DIR__ . '/../db/config.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$questions = [
|
||||
"I wake up feeling tired, even after a full night’s sleep.",
|
||||
"By midday, I already feel mentally drained and out of energy.",
|
||||
"I feel emotionally numb, detached, or ‘on autopilot’ most of the time.",
|
||||
"Things that used to excite me now feel pointless or like a chore.",
|
||||
"I feel irritated or cynical about people I work or study with.",
|
||||
"I struggle to focus and constantly procrastinate, even on important tasks.",
|
||||
"I feel guilty for not doing ‘enough’, no matter how much I actually do.",
|
||||
"I often think about quitting everything for a while or disappearing from social media and work.",
|
||||
"I use caffeine, sugar, nicotine, alcohol, or scrolling to ‘numb out’ instead of resting.",
|
||||
"I feel like my life is just surviving, not really living"
|
||||
];
|
||||
|
||||
if (!isset($_SESSION['question_index'])) {
|
||||
$_SESSION['question_index'] = 0;
|
||||
$_SESSION['answers'] = [];
|
||||
}
|
||||
|
||||
$response = [];
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$answer = $data['answer'] ?? null;
|
||||
|
||||
if ($answer !== null && $_SESSION['question_index'] < count($questions)) {
|
||||
$_SESSION['answers'][$_SESSION['question_index']] = $answer;
|
||||
$_SESSION['question_index']++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($_SESSION['question_index'] < count($questions)) {
|
||||
$response['question'] = $questions[$_SESSION['question_index']];
|
||||
} else {
|
||||
// Survey is complete, analyze the answers
|
||||
$formatted_answers = [];
|
||||
foreach ($_SESSION['answers'] as $index => $answer) {
|
||||
$formatted_answers[] = "Q: " . $questions[$index] . "\nA: " . $answer;
|
||||
}
|
||||
$prompt = <<<EOT
|
||||
Analyze the user's survey answers and return ONLY a raw JSON object with the specified structure. Do not include any other text or formatting.
|
||||
|
||||
User's Answers:
|
||||
EOT;
|
||||
$prompt .= "\n" . implode("\n", $formatted_answers);
|
||||
|
||||
error_log('Attempting to call AI API for burnout analysis.');
|
||||
$ai_response = LocalAIApi::createResponse([
|
||||
'input' => [
|
||||
['role' => 'system', 'content' => 'You are a burnout analysis expert.'],
|
||||
['role' => 'user', 'content' => $prompt],
|
||||
],
|
||||
]);
|
||||
|
||||
error_log('AI API Response: ' . print_r($ai_response, true));
|
||||
|
||||
if (!empty($ai_response['success'])) {
|
||||
$decoded_response = LocalAIApi::decodeJsonFromResponse($ai_response);
|
||||
$_SESSION['results'] = $decoded_response;
|
||||
|
||||
if (isset($_SESSION['user_id'])) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare('INSERT INTO survey_results (user_id, results_json) VALUES (:user_id, :results_json)');
|
||||
$stmt->execute([
|
||||
':user_id' => $_SESSION['user_id'],
|
||||
':results_json' => json_encode($decoded_response)
|
||||
]);
|
||||
} catch (PDOException $e) {
|
||||
// Optionally handle or log the database error
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Handle AI API error, maybe provide default results
|
||||
$_SESSION['results'] = [
|
||||
'scores' => ['Exhaustion' => 0, 'Cynicism' => 0, 'Inefficacy' => 0],
|
||||
'recommendations' => ['Could not analyze results at this time. Please try again later.']
|
||||
];
|
||||
}
|
||||
|
||||
$response['redirect'] = 'results.php';
|
||||
}
|
||||
|
||||
echo json_encode($response);
|
||||
57
assets/css/custom.css
Normal file
57
assets/css/custom.css
Normal file
@ -0,0 +1,57 @@
|
||||
body {
|
||||
background-color: #F8F9FA;
|
||||
font-family: 'Inter', sans-serif;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.card {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-image: linear-gradient(to right, #007BFF, #0056b3);
|
||||
border: none;
|
||||
}
|
||||
|
||||
.chat-message {
|
||||
margin-bottom: 15px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.chat-message .message-bubble {
|
||||
padding: 10px 15px;
|
||||
border-radius: 20px;
|
||||
max-width: 80%;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.user-message .message-bubble {
|
||||
background-color: #007BFF;
|
||||
color: white;
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
.bot-message .message-bubble {
|
||||
background-color: #E9ECEF;
|
||||
color: #333;
|
||||
align-self: flex-start;
|
||||
}
|
||||
|
||||
.message-time {
|
||||
font-size: 0.75rem;
|
||||
color: #6C757D;
|
||||
align-self: flex-end;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.user-message .message-time {
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
.bot-message .message-time {
|
||||
align-self: flex-start;
|
||||
}
|
||||
89
assets/js/main.js
Normal file
89
assets/js/main.js
Normal file
@ -0,0 +1,89 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const chatWindow = document.getElementById('chat-window');
|
||||
const chatInput = document.getElementById('chat-input');
|
||||
const sendBtn = document.getElementById('send-btn');
|
||||
const progressContainer = document.getElementById('progress-container');
|
||||
const inputContainer = document.getElementById('input-container');
|
||||
|
||||
function addMessage(message, sender) {
|
||||
const messageElement = document.createElement('div');
|
||||
const bubble = document.createElement('div');
|
||||
const time = document.createElement('div');
|
||||
|
||||
messageElement.classList.add('chat-message', `${sender}-message`);
|
||||
bubble.classList.add('message-bubble');
|
||||
time.classList.add('message-time');
|
||||
|
||||
bubble.innerText = message;
|
||||
time.innerText = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
|
||||
messageElement.appendChild(bubble);
|
||||
messageElement.appendChild(time);
|
||||
chatWindow.appendChild(messageElement);
|
||||
chatWindow.scrollTop = chatWindow.scrollHeight;
|
||||
}
|
||||
|
||||
async function getNextQuestion(answer = null) {
|
||||
const response = await fetch('api/chat.php', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ answer: answer })
|
||||
});
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async function handleUserInput() {
|
||||
const userInput = chatInput.value.trim();
|
||||
if (userInput === '') return;
|
||||
|
||||
const rating = parseInt(userInput, 10);
|
||||
if (isNaN(rating) || rating < 1 || rating > 5) {
|
||||
addMessage('Please enter a number between 1 and 5.', 'bot');
|
||||
return;
|
||||
}
|
||||
|
||||
addMessage(userInput, 'user');
|
||||
chatInput.value = '';
|
||||
chatInput.disabled = true;
|
||||
sendBtn.disabled = true;
|
||||
|
||||
const data = await getNextQuestion(rating);
|
||||
|
||||
if (data.redirect) {
|
||||
inputContainer.style.display = 'none';
|
||||
progressContainer.style.display = 'block';
|
||||
// Wait a bit for the user to see the progress bar
|
||||
setTimeout(() => {
|
||||
window.location.href = data.redirect;
|
||||
}, 2000);
|
||||
} else if (data.question) {
|
||||
addMessage(data.question, 'bot');
|
||||
chatInput.disabled = false;
|
||||
sendBtn.disabled = false;
|
||||
chatInput.focus();
|
||||
} else if (data.message) {
|
||||
addMessage(data.message, 'bot');
|
||||
chatInput.style.display = 'none';
|
||||
sendBtn.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
sendBtn.addEventListener('click', handleUserInput);
|
||||
chatInput.addEventListener('keypress', function (e) {
|
||||
if (e.key === 'Enter') {
|
||||
handleUserInput();
|
||||
}
|
||||
});
|
||||
|
||||
async function startConversation() {
|
||||
const data = await getNextQuestion();
|
||||
if (data.question) {
|
||||
addMessage("Welcome to the Burnout Survey. I'll ask you a series of questions. Please rate each one on a scale of 1 (Never) to 5 (Always).", 'bot');
|
||||
addMessage(data.question, 'bot');
|
||||
}
|
||||
}
|
||||
|
||||
startConversation();
|
||||
});
|
||||
BIN
assets/pasted-20251118-103639-363b1604.png
Normal file
BIN
assets/pasted-20251118-103639-363b1604.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 269 KiB |
BIN
assets/pasted-20251118-104242-29c69e9a.png
Normal file
BIN
assets/pasted-20251118-104242-29c69e9a.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 197 KiB |
BIN
assets/pasted-20251118-104529-37f09ec1.png
Normal file
BIN
assets/pasted-20251118-104529-37f09ec1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 190 KiB |
BIN
assets/pasted-20251118-104955-bf6113a1.png
Normal file
BIN
assets/pasted-20251118-104955-bf6113a1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 362 KiB |
15
db/migrations/001_create_users_and_results_tables.sql
Normal file
15
db/migrations/001_create_users_and_results_tables.sql
Normal file
@ -0,0 +1,15 @@
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(255) NOT NULL UNIQUE,
|
||||
email VARCHAR(255) NOT NULL UNIQUE,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS survey_results (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
results_json TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
);
|
||||
180
index.php
180
index.php
@ -1,150 +1,48 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
@ini_set('display_errors', '1');
|
||||
@error_reporting(E_ALL);
|
||||
@date_default_timezone_set('UTC');
|
||||
|
||||
$phpVersion = PHP_VERSION;
|
||||
$now = date('Y-m-d H:i:s');
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>New Style</title>
|
||||
<?php
|
||||
// Read project preview data from environment
|
||||
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
|
||||
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
|
||||
?>
|
||||
<?php if ($projectDescription): ?>
|
||||
<!-- Meta description -->
|
||||
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
|
||||
<!-- Open Graph meta tags -->
|
||||
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<!-- Twitter meta tags -->
|
||||
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
|
||||
<?php endif; ?>
|
||||
<?php if ($projectImageUrl): ?>
|
||||
<!-- Open Graph image -->
|
||||
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<!-- Twitter image -->
|
||||
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
|
||||
<?php endif; ?>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg-color-start: #6a11cb;
|
||||
--bg-color-end: #2575fc;
|
||||
--text-color: #ffffff;
|
||||
--card-bg-color: rgba(255, 255, 255, 0.01);
|
||||
--card-border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: 'Inter', sans-serif;
|
||||
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
|
||||
color: var(--text-color);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
body::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
|
||||
animation: bg-pan 20s linear infinite;
|
||||
z-index: -1;
|
||||
}
|
||||
@keyframes bg-pan {
|
||||
0% { background-position: 0% 0%; }
|
||||
100% { background-position: 100% 100%; }
|
||||
}
|
||||
main {
|
||||
padding: 2rem;
|
||||
}
|
||||
.card {
|
||||
background: var(--card-bg-color);
|
||||
border: 1px solid var(--card-border-color);
|
||||
border-radius: 16px;
|
||||
padding: 2rem;
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.loader {
|
||||
margin: 1.25rem auto 1.25rem;
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 3px solid rgba(255, 255, 255, 0.25);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
@keyframes spin {
|
||||
from { transform: rotate(0deg); }
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.hint {
|
||||
opacity: 0.9;
|
||||
}
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px; height: 1px;
|
||||
padding: 0; margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap; border: 0;
|
||||
}
|
||||
h1 {
|
||||
font-size: 3rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 1rem;
|
||||
letter-spacing: -1px;
|
||||
}
|
||||
p {
|
||||
margin: 0.5rem 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
code {
|
||||
background: rgba(0,0,0,0.2);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
}
|
||||
footer {
|
||||
position: absolute;
|
||||
bottom: 1rem;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Burnout Survey</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<div class="card">
|
||||
<h1>Analyzing your requirements and generating your website…</h1>
|
||||
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
|
||||
<span class="sr-only">Loading…</span>
|
||||
</div>
|
||||
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
|
||||
<p class="hint">This page will update automatically as the plan is implemented.</p>
|
||||
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
|
||||
<div class="container mt-4">
|
||||
|
||||
<main class="container my-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-8">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header bg-primary text-white">
|
||||
<h4 class="mb-0">AI Assistant</h4>
|
||||
</div>
|
||||
<div class="card-body" id="chat-window" style="height: 400px; overflow-y: auto;">
|
||||
<!-- Chat messages will be appended here -->
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<div id="progress-container" class="progress" style="display: none;">
|
||||
<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 100%">Analyzing...</div>
|
||||
</div>
|
||||
<div class="input-group" id="input-container">
|
||||
<input type="text" id="chat-input" class="form-control" placeholder="Rate from 1 (Strongly Disagree) to 5 (Strongly Agree)">
|
||||
<button id="send-btn" class="btn btn-primary">
|
||||
<i class="bi bi-send"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Page updated: <?= htmlspecialchars($now) ?> (UTC)
|
||||
</footer>
|
||||
</main>
|
||||
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
66
login.php
Normal file
66
login.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
require_once 'partials/header.php';
|
||||
require_once 'db/config.php';
|
||||
|
||||
$errors = [];
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$email = $_POST['email'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
if (empty($email)) {
|
||||
$errors[] = 'Email is required';
|
||||
}
|
||||
if (empty($password)) {
|
||||
$errors[] = 'Password is required';
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = :email');
|
||||
$stmt->execute([':email' => $email]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
} else {
|
||||
$errors[] = 'Invalid email or password';
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = 'Database error: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">Login</div>
|
||||
<div class="card-body">
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p><?php echo $error; ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once 'partials/footer.php'; ?>
|
||||
6
logout.php
Normal file
6
logout.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_unset();
|
||||
session_destroy();
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
5
partials/footer.php
Normal file
5
partials/footer.php
Normal file
@ -0,0 +1,5 @@
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
43
partials/header.php
Normal file
43
partials/header.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Burnout Survey</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="index.php">Burnout Survey</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<?php if (isset($_SESSION['user_id'])): ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="profile.php">Profile</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="logout.php">Logout</a>
|
||||
</li>
|
||||
<?php else: ?>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="login.php">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="register.php">Register</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container mt-4">
|
||||
110
profile.php
Normal file
110
profile.php
Normal file
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
require_once 'partials/header.php';
|
||||
require_once 'db/config.php';
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$user_id = $_SESSION['user_id'];
|
||||
$results = [];
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare('SELECT * FROM survey_results WHERE user_id = :user_id ORDER BY created_at DESC');
|
||||
$stmt->execute([':user_id' => $user_id]);
|
||||
$results = $stmt->fetchAll();
|
||||
} catch (PDOException $e) {
|
||||
// handle error
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<h2>Your Past Results</h2>
|
||||
|
||||
<?php if (empty($results)): ?>
|
||||
<p>You have no past survey results.</p>
|
||||
<?php else: ?>
|
||||
<div class="accordion" id="resultsAccordion">
|
||||
<?php foreach ($results as $index => $result): ?>
|
||||
<?php $data = json_decode($result['results_json'], true); ?>
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="heading<?php echo $index; ?>">
|
||||
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse<?php echo $index; ?>" aria-expanded="false" aria-controls="collapse<?php echo $index; ?>">
|
||||
Survey from <?php echo date('F j, Y, g:i a', strtotime($result['created_at'])); ?>
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapse<?php echo $index; ?>" class="accordion-collapse collapse" aria-labelledby="heading<?php echo $index; ?>" data-bs-parent="#resultsAccordion">
|
||||
<div class="accordion-body">
|
||||
<h5>Overall Summary</h5>
|
||||
<p><?php echo htmlspecialchars($data['summary'] ?? ''); ?></p>
|
||||
|
||||
<h5>Score Breakdown</h5>
|
||||
<canvas id="chart-<?php echo $index; ?>" width="400" height="400"></canvas>
|
||||
|
||||
<h5>Recommendations</h5>
|
||||
<div class="accordion" id="recommendationsAccordion-<?php echo $index; ?>">
|
||||
<?php foreach ($data['recommendations'] as $rec_index => $rec): ?>
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="rec-heading-<?php echo $index; ?>-<?php echo $rec_index; ?>">
|
||||
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#rec-collapse-<?php echo $index; ?>-<?php echo $rec_index; ?>" aria-expanded="false" aria-controls="rec-collapse-<?php echo $index; ?>-<?php echo $rec_index; ?>">
|
||||
<?php echo htmlspecialchars($rec['title']); ?>
|
||||
</button>
|
||||
</h2>
|
||||
<div id="rec-collapse-<?php echo $index; ?>-<?php echo $rec_index; ?>" class="accordion-collapse collapse" aria-labelledby="rec-heading-<?php echo $index; ?>-<?php echo $rec_index; ?>" data-bs-parent="#recommendationsAccordion-<?php echo $index; ?>">
|
||||
<div class="accordion-body">
|
||||
<?php echo htmlspecialchars($rec['description']); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<h5>Next Steps</h5>
|
||||
<ul>
|
||||
<?php foreach ($data['next_steps'] as $step): ?>
|
||||
<li><?php echo htmlspecialchars($step); ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
new Chart(document.getElementById('chart-<?php echo $index; ?>'), {
|
||||
type: 'radar',
|
||||
data: {
|
||||
labels: ['Exhaustion', 'Cynicism', 'Inefficacy'],
|
||||
datasets: [{
|
||||
label: 'Burnout Score',
|
||||
data: [
|
||||
<?php echo $data['scores']['Exhaustion'] ?? 0; ?>,
|
||||
<?php echo $data['scores']['Cynicism'] ?? 0; ?>,
|
||||
<?php echo $data['scores']['Inefficacy'] ?? 0; ?>
|
||||
],
|
||||
fill: true,
|
||||
backgroundColor: 'rgba(255, 99, 132, 0.2)',
|
||||
borderColor: 'rgb(255, 99, 132)',
|
||||
pointBackgroundColor: 'rgb(255, 99, 132)',
|
||||
pointBorderColor: '#fff',
|
||||
pointHoverBackgroundColor: '#fff',
|
||||
pointHoverBorderColor: 'rgb(255, 99, 132)'
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
elements: {
|
||||
line: {
|
||||
borderWidth: 3
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php require_once 'partials/footer.php'; ?>
|
||||
75
register.php
Normal file
75
register.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
require_once 'partials/header.php';
|
||||
require_once 'db/config.php';
|
||||
|
||||
$errors = [];
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$username = $_POST['username'] ?? '';
|
||||
$email = $_POST['email'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
if (empty($username)) {
|
||||
$errors[] = 'Username is required';
|
||||
}
|
||||
if (empty($email)) {
|
||||
$errors[] = 'Email is required';
|
||||
}
|
||||
if (empty($password)) {
|
||||
$errors[] = 'Password is required';
|
||||
}
|
||||
|
||||
if (empty($errors)) {
|
||||
try {
|
||||
$pdo = db();
|
||||
$stmt = $pdo->prepare('SELECT id FROM users WHERE username = :username OR email = :email');
|
||||
$stmt->execute([':username' => $username, ':email' => $email]);
|
||||
if ($stmt->fetch()) {
|
||||
$errors[] = 'Username or email already exists';
|
||||
} else {
|
||||
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$stmt = $pdo->prepare('INSERT INTO users (username, email, password) VALUES (:username, :email, :password)');
|
||||
$stmt->execute([':username' => $username, ':email' => $email, ':password' => $hashed_password]);
|
||||
$_SESSION['user_id'] = $pdo->lastInsertId();
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$errors[] = 'Database error: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">Register</div>
|
||||
<div class="card-body">
|
||||
<?php if (!empty($errors)): ?>
|
||||
<div class="alert alert-danger">
|
||||
<?php foreach ($errors as $error): ?>
|
||||
<p><?php echo $error; ?></p>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Username</label>
|
||||
<input type="text" class="form-control" id="username" name="username" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email address</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Password</label>
|
||||
<input type="password" class="form-control" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Register</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once 'partials/footer.php'; ?>
|
||||
187
results.php
Normal file
187
results.php
Normal file
@ -0,0 +1,187 @@
|
||||
<?php
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
if (!isset($_SESSION['results'])) {
|
||||
// Redirect to the main page if no results are available
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$results = $_SESSION['results'];
|
||||
|
||||
// Attempt to decode if the results are a JSON string
|
||||
if (is_string($results)) {
|
||||
$decoded_results = json_decode($results, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
$results = $decoded_results;
|
||||
} else {
|
||||
// Handle the case where the string is not valid JSON
|
||||
$results = []; // Reset to a safe value
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$scores = $results['scores'] ?? [];
|
||||
$analysis = $results['analysis'] ?? [];
|
||||
$recommendations = $results['recommendations'] ?? [];
|
||||
$nextSteps = $results['nextSteps'] ?? [];
|
||||
|
||||
// Clear the session data after displaying the results
|
||||
unset($_SESSION['answers']);
|
||||
unset($_SESSION['question_index']);
|
||||
unset($_SESSION['results']);
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Your Burnout Analysis</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container mt-4">
|
||||
<div class="card">
|
||||
<div class="card-header text-center">
|
||||
<h1>Your Burnout Analysis</h1>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (empty($scores) || empty($analysis) || empty($recommendations) || empty($nextSteps)): ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<h4 class="alert-heading">Analysis Failed</h4>
|
||||
<p>We're sorry, but there was an error generating your burnout analysis. The data we received was incomplete or corrupted.</p>
|
||||
<hr>
|
||||
<p class="mb-0">Please try the survey again. If the problem persists, please contact support.</p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<?php if (!empty($analysis['overallSummary'])):
|
||||
?>
|
||||
<div class="alert alert-light" role="alert">
|
||||
<h4 class="alert-heading">Overall Summary</h4>
|
||||
<p><?php echo htmlspecialchars($analysis['overallSummary']); ?></p>
|
||||
</div>
|
||||
<?php
|
||||
endif; ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<h2>Your Scores</h2>
|
||||
<canvas id="burnoutChart"></canvas>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<h2>Analysis</h2>
|
||||
<?php if (!empty($analysis['exhaustionSummary'])):
|
||||
?>
|
||||
<h5>Exhaustion</h5>
|
||||
<p><?php echo htmlspecialchars($analysis['exhaustionSummary']); ?></p>
|
||||
<?php
|
||||
endif; ?>
|
||||
<?php if (!empty($analysis['cynicismSummary'])):
|
||||
?>
|
||||
<h5>Cynicism</h5>
|
||||
<p><?php echo htmlspecialchars($analysis['cynicismSummary']); ?></p>
|
||||
<?php
|
||||
endif; ?>
|
||||
<?php if (!empty($analysis['inefficacySummary'])):
|
||||
?>
|
||||
<h5>Inefficacy</h5>
|
||||
<p><?php echo htmlspecialchars($analysis['inefficacySummary']); ?></p>
|
||||
<?php
|
||||
endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class="my-4">
|
||||
|
||||
<h2>Recommendations</h2>
|
||||
<?php if (!empty($recommendations)):
|
||||
?>
|
||||
<div class="accordion" id="recommendationsAccordion">
|
||||
<?php foreach ($recommendations as $index => $rec):
|
||||
?>
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header" id="heading<?php echo $index; ?>">
|
||||
<button class="accordion-button <?php echo $index > 0 ? 'collapsed' : ''; ?>" type="button" data-bs-toggle="collapse" data-bs-target="#collapse<?php echo $index; ?>" aria-expanded="<?php echo $index === 0 ? 'true' : 'false'; ?>" aria-controls="collapse<?php echo $index; ?>">
|
||||
<?php echo htmlspecialchars($rec['title']); ?>
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapse<?php echo $index; ?>" class="accordion-collapse collapse <?php echo $index === 0 ? 'show' : ''; ?>" aria-labelledby="heading<?php echo $index; ?>" data-bs-parent="#recommendationsAccordion">
|
||||
<div class="accordion-body">
|
||||
<?php echo htmlspecialchars($rec['description']); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
endforeach; ?>
|
||||
</div>
|
||||
<?php else:
|
||||
?>
|
||||
<p>No specific recommendations available at this time.</p>
|
||||
<?php
|
||||
endif; ?>
|
||||
|
||||
<hr class="my-4">
|
||||
|
||||
<h2>Next Steps</h2>
|
||||
<?php if (!empty($nextSteps)):
|
||||
?>
|
||||
<ul>
|
||||
<?php foreach ($nextSteps as $step):
|
||||
?>
|
||||
<li><?php echo htmlspecialchars($step); ?></li>
|
||||
<?php
|
||||
endforeach; ?>
|
||||
</ul>
|
||||
<?php else:
|
||||
?>
|
||||
<p>No specific next steps available at this time.</p>
|
||||
<?php
|
||||
endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
<a href="index.php" class="btn btn-primary">Take the Survey Again</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const scores = <?php echo json_encode($scores); ?>;
|
||||
const canvas = document.getElementById('burnoutChart');
|
||||
if (canvas) {
|
||||
const ctx = canvas.getContext('2d');
|
||||
const burnoutChart = new Chart(ctx, {
|
||||
type: 'radar',
|
||||
data: {
|
||||
labels: Object.keys(scores),
|
||||
datasets: [{
|
||||
label: 'Burnout Dimensions',
|
||||
data: Object.values(scores),
|
||||
backgroundColor: 'rgba(0, 123, 255, 0.2)',
|
||||
borderColor: 'rgba(0, 123, 255, 1)',
|
||||
borderWidth: 1
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
r: {
|
||||
angleLines: {
|
||||
display: false
|
||||
},
|
||||
suggestedMin: 0,
|
||||
suggestedMax: 5
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user