37338-vm/_init_single_instance.php
2026-01-10 19:52:03 +00:00

30 lines
842 B
PHP

<?php
session_start();
require_once 'WorkflowEngine.php';
require_once 'lib/ErrorHandler.php';
require_once 'lib/WorkflowExceptions.php';
if (!isset($_SESSION['user_id'])) {
throw new WorkflowNotAllowedException('Authentication required.');
}
$userId = $_SESSION['user_id'];
$personId = $_GET['personId'] ?? null;
$processDefinitionId = $_GET['processId'] ?? null;
if (!$personId || !$processDefinitionId) {
throw new WorkflowRuleFailedException('Missing parameters for process initialization.');
}
$engine = new WorkflowEngine();
$instance = $engine->getOrCreateInstanceByDefId($personId, $processDefinitionId, $userId);
if ($instance) {
$_SESSION['success_message'] = "Process initialized successfully.";
} else {
$_SESSION['error_message'] = "Failed to initialize process.";
}
header('Location: index.php');
exit();