37338-vm/organization_processes.php
2026-03-02 19:32:17 +00:00

107 lines
4.7 KiB
PHP

<?php
require_once 'WorkflowEngine.php';
require_once 'lib/i18n.php';
session_start();
$engine = new WorkflowEngine();
$pdo = db();
$stmt_defs = $pdo->prepare("SELECT * FROM process_definitions WHERE is_active = 1 AND is_latest = 1 AND subject_scope = 'organization' ORDER BY sort_order, name");
$stmt_defs->execute();
$definitions = $stmt_defs->fetchAll(\PDO::FETCH_ASSOC);
?>
<?php include '_header.php'; ?>
<?php include '_navbar.php'; ?>
<div class="container-fluid">
<div class="row">
<?php include '_sidebar.php'; ?>
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4 main-content">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Procesy Organizacji</h1>
</div>
<div class="table-responsive mt-3">
<table class="table table-striped table-hover table-bordered align-middle matrix-table">
<thead class="table-light">
<tr>
<th>Organizacja</th>
<?php foreach ($definitions as $def): ?>
<th class="text-center"><?= htmlspecialchars($def['name']) ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<tr>
<td>
<strong>Główna Organizacja</strong>
</td>
<?php foreach ($definitions as $def): ?>
<?php
// We use subject_id = 1 for the whole organization
$instance = $engine->getActiveInstanceForSubject($def['code'], 'organization', 1);
$cellColor = '';
$cellText = 'Brak';
if ($instance) {
$cellText = $instance['current_status'];
if (in_array($instance['current_status'], ['completed','positive'])) {
$cellColor = 'background-color: #d1e7dd;';
} else if ($instance['current_status'] == 'in_progress') {
$cellColor = 'background-color: #fff3cd;';
}
}
?>
<td class="text-center p-2" style="<?= $cellColor ?>">
<button type="button" class="btn btn-sm btn-outline-secondary w-100"
onclick="openInstanceModal('organization', 1, '<?= htmlspecialchars($def['code']) ?>')">
<?= htmlspecialchars($cellText) ?>
</button>
</td>
<?php endforeach; ?>
</tr>
</tbody>
</table>
</div>
</main>
</div>
</div>
<script>
function openInstanceModal(subjectType, subjectId, processCode) {
const modal = new bootstrap.Modal(document.getElementById('instanceModal'));
const modalBody = document.getElementById('instanceModalBody');
const modalTitle = document.getElementById('instanceModalLabel');
modalBody.innerHTML = '<div class="text-center"><div class="spinner-border" role="status"><span class="visually-hidden">Loading...</span></div></div>';
modalTitle.textContent = 'Ładowanie...';
modal.show();
fetch(`_get_instance_details.php?subject_type=${subjectType}&subject_id=${subjectId}&process_code=${processCode}`)
.then(response => {
if (!response.ok) throw new Error('Network response was not ok');
return response.text();
})
.then(html => {
modalBody.innerHTML = html;
const tempDiv = document.createElement('div');
tempDiv.innerHTML = html;
const titleEl = tempDiv.querySelector('#instance-modal-title');
if (titleEl) {
modalTitle.textContent = titleEl.textContent;
} else {
modalTitle.textContent = 'Szczegóły procesu';
}
bindModalEvents();
})
.catch(error => {
console.error('Error fetching details:', error);
modalBody.innerHTML = '<div class="alert alert-danger">Błąd podczas pobierania szczegółów.</div>';
});
}
</script>
<?php include '_footer.php'; ?>