88 lines
3.4 KiB
PHP
88 lines
3.4 KiB
PHP
<?php
|
|
require_once 'WorkflowEngine.php';
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
http_response_code(401);
|
|
die('Brak autoryzacji');
|
|
}
|
|
|
|
$personId = $_GET['personId'] ?? null;
|
|
$processDefinitionId = $_GET['processId'] ?? null; // Pulpit wysyła processId, który jest ID definicji
|
|
|
|
if (!$personId || !$processDefinitionId) {
|
|
http_response_code(400);
|
|
die('Brakujące parametry');
|
|
}
|
|
|
|
$userId = $_SESSION['user_id'];
|
|
$engine = new WorkflowEngine();
|
|
|
|
// 1. Pobierz lub utwórz instancję
|
|
$instance = $engine->getOrCreateInstanceByDefId($personId, $processDefinitionId, $userId);
|
|
if (!$instance) {
|
|
http_response_code(500);
|
|
die('Nie można pobrać lub utworzyć instancji procesu.');
|
|
}
|
|
$instanceId = $instance['id'];
|
|
|
|
// 2. Pobierz powiązane dane przez silnik
|
|
$events = $engine->getEvents($instanceId);
|
|
$availableTransitions = $engine->getAvailableTransitions($instanceId);
|
|
|
|
// 3. Pobierz nazwy do wyświetlenia
|
|
$pdo = db();
|
|
$stmt_person = $pdo->prepare("SELECT firstName, lastName FROM people WHERE id = ?");
|
|
$stmt_person->execute([$personId]);
|
|
$person = $stmt_person->fetch();
|
|
|
|
$stmt_process = $pdo->prepare("SELECT name FROM process_definitions WHERE id = ?");
|
|
$stmt_process->execute([$processDefinitionId]);
|
|
$process = $stmt_process->fetch();
|
|
?>
|
|
|
|
<h4><?= htmlspecialchars($person['firstName'] . ' ' . $person['lastName']) ?> - <?= htmlspecialchars($process['name']) ?></h4>
|
|
<p>Status: <span class="badge bg-secondary"><?= htmlspecialchars($instance['current_status']) ?></span></p>
|
|
<hr>
|
|
|
|
<h5>Wykonaj akcję</h5>
|
|
<form action="_apply_transition.php" method="post">
|
|
<input type="hidden" name="instanceId" value="<?= $instanceId ?>">
|
|
<div class="mb-3">
|
|
<label for="transitionSelect" class="form-label">Akcja</label>
|
|
<select name="transitionId" id="transitionSelect" class="form-select" required>
|
|
<option value="" disabled selected>-- Wybierz akcję --</option>
|
|
<?php foreach ($availableTransitions as $transition): ?>
|
|
<option value="<?= $transition['id'] ?>"><?= htmlspecialchars($transition['name']) ?></option>
|
|
<?php endforeach; ?>
|
|
<option value="note">Dodaj notatkę</option> <!-- Specjalny przypadek -->
|
|
</select>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="payloadMessage" class="form-label">Notatka / Wiadomość (opcjonalnie)</label>
|
|
<textarea name="payload[message]" id="payloadMessage" class="form-control" rows="3"></textarea>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Zatwierdź</button>
|
|
</form>
|
|
|
|
<hr>
|
|
|
|
<h5>Historia</h5>
|
|
<?php if (empty($events)): ?>
|
|
<p>Brak zdarzeń.</p>
|
|
<?php else: ?>
|
|
<ul class="list-group">
|
|
<?php foreach ($events as $event): ?>
|
|
<li class="list-group-item">
|
|
<strong><?= htmlspecialchars(ucfirst(str_replace('_', ' ', $event['event_type']))) ?></strong>
|
|
<?php if (!empty($event['message'])):
|
|
$payload = json_decode($event['payload_json'], true);
|
|
$message = $payload['message'] ?? $event['message'];
|
|
?>
|
|
<p class="mb-1"><?= htmlspecialchars($message) ?></p>
|
|
<?php endif; ?>
|
|
<small class="text-muted">Przez <?= htmlspecialchars($event['firstName'] . ' ' . $event['lastName']) ?> dnia <?= date('d.m.Y, H:i', strtotime($event['createdAt'])) ?></small>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php endif; ?>
|