diff --git a/add_process.php b/add_process.php index 0d35d08..76cff90 100644 --- a/add_process.php +++ b/add_process.php @@ -17,6 +17,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $sql = "INSERT INTO processes (name, description) VALUES (?, ?)"; $stmt = $pdo->prepare($sql); $stmt->execute([$name, $description]); + + $process_id = $pdo->lastInsertId(); + + // Insert process steps if available + if (isset($_POST['steps']) && is_array($_POST['steps'])) { + $step_order = 0; + $stmt_steps = $pdo->prepare("INSERT INTO process_steps (process_id, title, description, step_order) VALUES (?, ?, ?, ?)"); + foreach ($_POST['steps'] as $step) { + if (isset($step['title']) && isset($step['description'])) { + $stmt_steps->execute([$process_id, $step['title'], $step['description'], $step_order]); + $step_order++; + } + } + } } catch (PDOException $e) { // In a real app, log this error. For now, we'll just die. error_log("DB Error: " . $e->getMessage()); diff --git a/api/generate_process_suggestion.php b/api/generate_process_suggestion.php index 0c2f684..9a0891e 100644 --- a/api/generate_process_suggestion.php +++ b/api/generate_process_suggestion.php @@ -5,7 +5,7 @@ require_once __DIR__ . '/../ai/LocalAIApi.php'; $keyword = $_GET['keyword'] ?? 'new process'; -$prompt = "Generate a creative and concise name and a short description for a process related to '" . htmlspecialchars($keyword) . "'. Respond in JSON format with 'name' and 'description' keys. Example: {"name": "Automated Workflow Orchestrator", "description": "Manages and streamlines complex business workflows."}"; +$prompt = "Generate a creative and concise name, a short description, and a list of detailed steps for a business process related to '" . htmlspecialchars($keyword) . "'. Each step should have a 'title' and a 'description'. Respond in JSON format with 'name', 'description', and 'steps' keys. Example: {"name": "Employee Onboarding Process", "description": "A systematic process to integrate new hires into the company.", "steps": [{"title": "Send welcome email", "description": "Automatically send a welcome email with company resources."}, {"title": "Setup IT access", "description": "Provision access to internal systems and tools."}]}"; $params = [ 'input' => [ @@ -19,7 +19,7 @@ $response = LocalAIApi::createResponse($params); if (!empty($response['success'])) { $decoded = LocalAIApi::decodeJsonFromResponse($response); - if ($decoded && isset($decoded['name']) && isset($decoded['description'])) { + if ($decoded && isset($decoded['name']) && isset($decoded['description']) && isset($decoded['steps'])) { echo json_encode(['success' => true, 'data' => $decoded]); } else { // Fallback if AI didn't return valid JSON or missing keys diff --git a/db/migrations/20230102_create_process_steps_table.sql b/db/migrations/20230102_create_process_steps_table.sql new file mode 100644 index 0000000..67d9513 --- /dev/null +++ b/db/migrations/20230102_create_process_steps_table.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS process_steps ( + id INT AUTO_INCREMENT PRIMARY KEY, + process_id INT NOT NULL, + title VARCHAR(255) NOT NULL, + description TEXT, + step_order INT NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (process_id) REFERENCES processes(id) ON DELETE CASCADE +); \ No newline at end of file diff --git a/edit_process.php b/edit_process.php index d5c7bbd..4769cd4 100644 --- a/edit_process.php +++ b/edit_process.php @@ -13,7 +13,12 @@ if (isset($_GET['id'])) { $stmt->execute(); $process = $stmt->fetch(PDO::FETCH_ASSOC); - if (!$process) { + if ($process) { + $stmt_steps = $pdo->prepare("SELECT id, title, description, step_order FROM process_steps WHERE process_id = :process_id ORDER BY step_order ASC"); + $stmt_steps->bindParam(':process_id', $id, PDO::PARAM_INT); + $stmt_steps->execute(); + $process['steps'] = $stmt_steps->fetchAll(PDO::FETCH_ASSOC); + } else { $error = "Process not found."; } } catch (PDOException $e) { @@ -68,6 +73,33 @@ $project_name = htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'ProcessFlow Optimi + +
+
Process Steps
+
+ + $step): ?> +
+ +
+ + +
+
+ + +
+ +
+ + +
+ + Cancel @@ -85,6 +117,57 @@ $project_name = htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'ProcessFlow Optimi \ No newline at end of file diff --git a/index.php b/index.php index e979ddd..0b26c50 100644 --- a/index.php +++ b/index.php @@ -161,6 +161,10 @@ $project_image_url = htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); +