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

115 lines
5.2 KiB
PHP

<?php
require_once 'WorkflowEngine.php';
require_once 'lib/i18n.php';
session_start();
$engine = new WorkflowEngine();
$pdo = db();
$stmt_groups = $pdo->prepare("SELECT * FROM bni_groups ORDER BY name");
$stmt_groups->execute();
$groups = $stmt_groups->fetchAll(\PDO::FETCH_ASSOC);
$stmt_defs = $pdo->prepare("SELECT * FROM process_definitions WHERE is_active = 1 AND is_latest = 1 AND subject_scope = 'bni_group' 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 Grup BNI</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>Grupa BNI</th>
<?php foreach ($definitions as $def): ?>
<th class="text-center"><?= htmlspecialchars($def['name']) ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php if (empty($groups)): ?>
<tr><td colspan="<?= count($definitions) + 1 ?>" class="text-center">Brak grup.</td></tr>
<?php endif; ?>
<?php foreach ($groups as $group): ?>
<tr>
<td>
<strong><?= htmlspecialchars($group['name']) ?></strong>
</td>
<?php foreach ($definitions as $def): ?>
<?php
$instance = $engine->getActiveInstanceForSubject($def['code'], 'bni_group', $group['id']);
$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('bni_group', <?= $group['id'] ?>, '<?= htmlspecialchars($def['code']) ?>')">
<?= htmlspecialchars($cellText) ?>
</button>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</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'; ?>