-
+
${persona.name}
${persona.age}, ${persona.occupation}
-
Traits:
-
${persona.traits}
-
Concerns:
-
${persona.concerns}
-
Style:
-
${persona.style}
+
Traits:
${persona.traits}
+
Concerns:
${persona.concerns}
+
Style:
${persona.style}
`).join('');
}
-});
\ No newline at end of file
+
+ function openChat(persona, gradientIndex) {
+ chatPersonaName.textContent = persona.name;
+ const cardGradientClass = `persona-gradient-${gradientIndex}`;
+ chatCard.querySelector('.card-header').className = `card-header d-flex justify-content-between align-items-center p-3 rounded-top-5 ${cardGradientClass}`;
+ chatPersonaIcon.className = "bi bi-person-circle fs-3 me-3";
+
+ chatLog.innerHTML = '';
+ const welcomeMessage = `Hello! I'm ${persona.name}. Ask me anything about the business idea.`;
+ addMessageToChatLog(welcomeMessage, 'persona');
+ chatHistory = [{ sender: 'persona', message: welcomeMessage }];
+
+ chatContainer.classList.remove('d-none');
+ analysisSection.classList.add('d-none');
+ analysisContainer.classList.add('d-none');
+ generateAnalysisBtn.disabled = true;
+
+ chatContainer.scrollIntoView({ behavior: 'smooth', block: 'start' });
+ }
+
+ function addMessageToChatLog(message, sender, isError = false) {
+ const messageElement = document.createElement('div');
+ messageElement.className = `chat-message ${sender === 'user' ? 'user' : 'persona'}`;
+
+ const bubble = document.createElement('div');
+ bubble.className = 'message-bubble';
+ if (isError) bubble.classList.add('bg-danger', 'text-white');
+ bubble.textContent = message;
+
+ const time = document.createElement('div');
+ time.className = 'message-time';
+ time.textContent = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
+
+ messageElement.appendChild(bubble);
+ messageElement.appendChild(time);
+ chatLog.appendChild(messageElement);
+ chatLog.scrollTop = chatLog.scrollHeight;
+
+ // Check to enable analysis button (user messages count towards total)
+ if (sender === 'user' && chatHistory.filter(m => m.sender === 'user').length >= 2) {
+ analysisSection.classList.remove('d-none');
+ generateAnalysisBtn.disabled = false;
+ }
+ }
+
+ function showTypingIndicator() {
+ sendMessageBtn.disabled = true;
+ let indicator = chatLog.querySelector('.typing-indicator');
+ if (!indicator) {
+ indicator = document.createElement('div');
+ indicator.className = 'chat-message persona typing-indicator';
+ indicator.innerHTML = `
+
+ `;
+ chatLog.appendChild(indicator);
+ }
+ chatLog.scrollTop = chatLog.scrollHeight;
+ }
+
+ function hideTypingIndicator() {
+ sendMessageBtn.disabled = false;
+ const indicator = chatLog.querySelector('.typing-indicator');
+ if (indicator) {
+ indicator.remove();
+ }
+ }
+});
diff --git a/db/config.php b/db/config.php
index f12ebaf..ddb52b1 100644
--- a/db/config.php
+++ b/db/config.php
@@ -1,17 +1,55 @@
PDO::ERRMODE_EXCEPTION,
- PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
- ]);
+ $dsn = 'pgsql:host=' . DB_HOST . ';port=' . DB_PORT . ';dbname=' . DB_NAME;
+ try {
+ $pdo = new PDO($dsn, DB_USER, DB_PASS, [
+ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
+ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
+ ]);
+ } catch (PDOException $e) {
+ // In a real app, you'd log this error and show a generic message.
+ // For now, we'll just die and show the error.
+ die("Database connection failed: " . $e->getMessage());
+ }
}
return $pdo;
}
+
+// A simple function to run migrations.
+// In a real application, you would use a more robust migration tool.
+function run_migrations() {
+ $pdo = db();
+ $migration_dir = __DIR__ . '/migrations';
+ $files = glob($migration_dir . '/*.sql');
+ foreach ($files as $file) {
+ try {
+ $sql = file_get_contents($file);
+ $pdo->exec($sql);
+ } catch (Exception $e) {
+ // Log error or handle it
+ error_log("Failed to run migration: $file. Error: " . $e->getMessage());
+ }
+ }
+}
+
+// Automatically run migrations when this file is included.
+// This is for simplicity in this development environment.
+if (DB_HOST !== 'YOUR_SUPABASE_HOST') { // Don't run if not configured
+ run_migrations();
+}
\ No newline at end of file
diff --git a/db/migrations/001_initial_schema.sql b/db/migrations/001_initial_schema.sql
new file mode 100644
index 0000000..5f3530c
--- /dev/null
+++ b/db/migrations/001_initial_schema.sql
@@ -0,0 +1,45 @@
+-- 001_initial_schema.sql
+-- This script creates the initial database schema for Screen Test.
+
+-- Create sessions table to store the core user inputs.
+CREATE TABLE IF NOT EXISTS sessions (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ target_audience TEXT NOT NULL,
+ business_idea TEXT NOT NULL,
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+-- Create personas table to store the generated AI personas for each session.
+CREATE TABLE IF NOT EXISTS personas (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ session_id INT NOT NULL,
+ name VARCHAR(255) NOT NULL,
+ age INT,
+ occupation VARCHAR(255),
+ traits TEXT,
+ concerns TEXT,
+ style TEXT,
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ FOREIGN KEY (session_id) REFERENCES sessions(id) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+-- Create chat_messages table to store the conversation history.
+CREATE TABLE IF NOT EXISTS chat_messages (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ session_id INT NOT NULL,
+ persona_id INT NOT NULL,
+ sender ENUM('user', 'persona', 'system') NOT NULL,
+ message TEXT NOT NULL,
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ FOREIGN KEY (session_id) REFERENCES sessions(id) ON DELETE CASCADE,
+ FOREIGN KEY (persona_id) REFERENCES personas(id) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+-- Create analyses table to store the generated conversation analysis.
+CREATE TABLE IF NOT EXISTS analyses (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ session_id INT NOT NULL,
+ content TEXT NOT NULL,
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ FOREIGN KEY (session_id) REFERENCES sessions(id) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
diff --git a/index.php b/index.php
index 51ee228..b6aca68 100644
--- a/index.php
+++ b/index.php
@@ -67,6 +67,50 @@
+
+
+