diff --git a/db/migrations/002_add_diagram_text_to_profiles.sql b/db/migrations/002_add_diagram_text_to_profiles.sql new file mode 100644 index 0000000..2b566ce --- /dev/null +++ b/db/migrations/002_add_diagram_text_to_profiles.sql @@ -0,0 +1 @@ +ALTER TABLE `gtm_profiles` ADD `diagram_mermaid_text` TEXT NULL DEFAULT NULL; \ No newline at end of file diff --git a/generate_diagram.php b/generate_diagram.php index 55267ef..1b82f03 100644 --- a/generate_diagram.php +++ b/generate_diagram.php @@ -106,6 +106,7 @@ file_put_contents($log_file, $log_entry, FILE_APPEND); // Clean up the response and extract the Mermaid code $diagram = trim($diagram); +$is_error = false; // Regex to find Mermaid code block, with or without backticks and optional "mermaid" label if (preg_match('/```(?:mermaid)?\s*(graph\s(TD|LR|BT|RL);?[\s\S]*?)```|^(graph\s(TD|LR|BT|RL);?[\s\S]*)/', $diagram, $matches)) { @@ -116,8 +117,19 @@ if (preg_match('/```(?:mermaid)?\s*(graph\s(TD|LR|BT|RL);?[\s\S]*?)```|^(graph\s // If no match, log the bad response and set an error for the user error_log("Invalid AI response format: " . $diagram); $diagram = "graph TD; A[Error: Invalid AI response format.];"; + $is_error = true; } +// --- Auto-save the generated diagram to the database --- +if (!$is_error) { + try { + $pdo = db(); + $stmt = $pdo->prepare("UPDATE gtm_profiles SET diagram_mermaid_text = ? WHERE id = ?"); + $stmt->execute([$diagram, $profile_id]); + } catch (PDOException $e) { + // Log the error, but don't block the user. The diagram was generated, just not saved. + error_log("DB Error saving diagram for profile {$profile_id}: " . $e->getMessage()); + } +} - -echo json_encode(['diagram' => $diagram]); +echo json_encode(['diagram' => $diagram]); \ No newline at end of file diff --git a/generate_roles.php b/generate_roles.php new file mode 100644 index 0000000..47b7721 --- /dev/null +++ b/generate_roles.php @@ -0,0 +1,50 @@ + 'Profile ID is missing.']); + exit; +} + +try { + $pdo = db(); + $stmt = $pdo->prepare("SELECT * FROM gtm_profiles WHERE id = ?"); + $stmt->execute([$profile_id]); + $profile = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!$profile) { + echo json_encode(['error' => 'Profile not found.']); + exit; + } + + // Simulate AI-powered recommendations based on profile data + $recommendations = '
No specific role recommendations for this profile.
'; + } else { + $recommendations .= 'No specific tool recommendations for this profile.
'; + } else { + $recommendations .= 'Sells What:
Growth Goals:
+Get AI-powered suggestions for marketing and sales roles to execute your GTM strategy.
+ + +Discover top industry solutions and integrations to efficiently execute your GTM strategy.
+ + +Generating roles...
Generating tools...
Generating diagram...