37338-vm/_apply_transition.php
2026-01-10 07:48:27 +00:00

43 lines
1.3 KiB
PHP

<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: process_dashboard.php');
exit;
}
require_once 'WorkflowEngine.php';
if (!isset($_POST['instanceId']) || !isset($_POST['transitionId'])) {
$_SESSION['flash_message'] = ['type' => 'danger', 'message' => 'Błąd: Brak wymaganych parametrów.'];
header('Location: process_dashboard.php');
exit;
}
$instanceId = (int)$_POST['instanceId'];
$transitionId = $_POST['transitionId'];
$userId = $_SESSION['user_id'] ?? null;
$payload = $_POST['payload'] ?? null;
if (!$userId) {
$_SESSION['flash_message'] = ['type' => 'danger', 'message' => 'Błąd: Sesja wygasła.'];
header('Location: login.php');
exit;
}
try {
$engine = new WorkflowEngine();
$success = $engine->applyTransition($instanceId, $transitionId, $payload, $userId);
if ($success) {
$_SESSION['flash_message'] = ['type' => 'success', 'message' => 'Akcja została wykonana pomyślnie.'];
} else {
$_SESSION['flash_message'] = ['type' => 'danger', 'message' => 'Błąd: Nie udało się wykonać akcji.'];
}
} catch (Exception $e) {
error_log("Error applying transition: " . $e->getMessage());
$_SESSION['flash_message'] = ['type' => 'danger', 'message' => 'Wystąpił krytyczny błąd: ' . $e->getMessage()];
}
header('Location: process_dashboard.php');
exit;