50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$processId = $_POST['process_id'] ?? null;
|
|
$name = $_POST['name'];
|
|
$definition_json = $_POST['definition_json'];
|
|
|
|
if (empty($name)) {
|
|
die('Process name is required.');
|
|
}
|
|
|
|
// Validate JSON
|
|
if (!empty($definition_json)) {
|
|
json_decode($definition_json);
|
|
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
die('Invalid JSON format in definition.');
|
|
}
|
|
}
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
if (empty($processId)) {
|
|
// Create new process
|
|
$sql = 'INSERT INTO process_definitions (name, definition_json) VALUES (?, ?)';
|
|
$params = [$name, $definition_json];
|
|
$message = 'Process created successfully.';
|
|
} else {
|
|
// Update existing process
|
|
$sql = 'UPDATE process_definitions SET name = ?, definition_json = ? WHERE id = ?';
|
|
$params = [$name, $definition_json, $processId];
|
|
$message = 'Process updated successfully.';
|
|
}
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
|
|
session_start();
|
|
$_SESSION['success_message'] = $message;
|
|
|
|
} catch (PDOException $e) {
|
|
error_log('Save process definition failed: ' . $e->getMessage());
|
|
die('Save process definition failed. Please check the logs.');
|
|
}
|
|
|
|
header('Location: process_definitions.php');
|
|
exit();
|
|
}
|