diff --git a/api/chat.php b/api/chat.php index 0d86e33..91d4724 100644 --- a/api/chat.php +++ b/api/chat.php @@ -1,6 +1,9 @@ $answer) { + $formatted_answers[] = "Q: " . $questions[$index] . "\nA: " . $answer; + } + $prompt = "You are a burnout analysis expert. A user has completed a burnout survey. The user answered on a scale of 1-5 where 1 is 'Never' and 5 is 'Always'. Analyze the following survey answers and provide a detailed analysis. Return the response as a JSON object with the following structure: +{ + \"scores\": { + \"Exhaustion\": , + \"Cynicism\": , + \"Inefficacy\": + }, + \"analysis\": { + \"overallSummary\": \"\", + \"exhaustionSummary\": \"\", + \"cynicismSummary\": \"\", + \"inefficacySummary\": \"\" + }, + \"recommendations\": [ + { + \"title\": \"\", + \"description\": \"\" + }, + ... (provide 3 to 5 detailed recommendations) + ], + \"nextSteps\": [ + \"\", + \"\" + ] +} + +Answers: +" . implode("\n\n", $formatted_answers); + + $ai_response = LocalAIApi::createResponse([ + 'input' => [ + ['role' => 'system', 'content' => 'You are a burnout analysis expert.'], + ['role' => 'user', 'content' => $prompt], + ], + ]); + + 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); diff --git a/assets/js/main.js b/assets/js/main.js index ff65470..1c93a44 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -49,7 +49,9 @@ document.addEventListener('DOMContentLoaded', function () { const data = await getNextQuestion(rating); - if (data.question) { + if (data.redirect) { + window.location.href = data.redirect; + } else if (data.question) { addMessage(data.question, 'bot'); } else if (data.message) { addMessage(data.message, 'bot'); @@ -71,10 +73,10 @@ document.addEventListener('DOMContentLoaded', function () { 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 (Strongly Disagree) to 5 (Strongly Agree).", 'bot'); + 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(); -}); \ No newline at end of file +}); diff --git a/assets/pasted-20251118-103639-363b1604.png b/assets/pasted-20251118-103639-363b1604.png new file mode 100644 index 0000000..6809e3a Binary files /dev/null and b/assets/pasted-20251118-103639-363b1604.png differ diff --git a/db/migrations/001_create_users_and_results_tables.sql b/db/migrations/001_create_users_and_results_tables.sql new file mode 100644 index 0000000..28e3987 --- /dev/null +++ b/db/migrations/001_create_users_and_results_tables.sql @@ -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 +); diff --git a/index.php b/index.php index f6101e5..91dbbce 100644 --- a/index.php +++ b/index.php @@ -1,51 +1,26 @@ - - - - - - Burnout Adviser - - - - - - - - - - - - - + -
-
-
-
-
-

AI Assistant

-
-
- -
- +
- - - - + \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..848d651 --- /dev/null +++ b/login.php @@ -0,0 +1,66 @@ +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(); + } + } +} +?> + +
+
+
+
Login
+
+ +
+ +

+ +
+ +
+
+ + +
+
+ + +
+ +
+
+
+
+
+ + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..95db42c --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ + + + + + diff --git a/partials/header.php b/partials/header.php new file mode 100644 index 0000000..165de8b --- /dev/null +++ b/partials/header.php @@ -0,0 +1,41 @@ + + + + + + + Burnout Survey + + + + + +
diff --git a/profile.php b/profile.php new file mode 100644 index 0000000..a2cdcdc --- /dev/null +++ b/profile.php @@ -0,0 +1,110 @@ +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 +} + +?> + +

Your Past Results

+ + +

You have no past survey results.

+ +
+ $result): ?> + +
+

+ +

+
+
+
Overall Summary
+

+ +
Score Breakdown
+ + +
Recommendations
+
+ $rec): ?> +
+

+ +

+
+
+ +
+
+
+ +
+ +
Next Steps
+
    + +
  • + +
+
+
+
+ + + +
+ + + diff --git a/register.php b/register.php new file mode 100644 index 0000000..cbafdf5 --- /dev/null +++ b/register.php @@ -0,0 +1,75 @@ +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(); + } + } +} +?> + +
+
+
+
Register
+
+ +
+ +

+ +
+ +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+
+ + diff --git a/results.php b/results.php new file mode 100644 index 0000000..b2155cf --- /dev/null +++ b/results.php @@ -0,0 +1,127 @@ + +
+
+

Your Burnout Analysis

+
+
+ + + + +
+
+

Your Scores

+ +
+
+

Analysis

+ +
Exhaustion
+

+ + +
Cynicism
+

+ + +
Inefficacy
+

+ +
+
+ +
+ +

Recommendations

+ +
+ $rec): ?> +
+

+ +

+
+
+ +
+
+
+ +
+ +

No specific recommendations available at this time.

+ + +
+ +

Next Steps

+ +
    + +
  • + +
+ +

No specific next steps available at this time.

+ + +
+ +
+ + +