OpenNIT

Quelltext des aktuellen Standes

Fassung 1.1.1

inbox.php

8 KB
<?php
$this->layout('layouts/main', [
    'page_title'    => $page_title ?? 'Anträge & Genehmigungen',
    'current_route' => 'workflows',
    'full_width'    => true,
    'extra_css'     => ['/assets/css/workflows.css'],
]);
$inbox     = $inbox ?? [];
$canManage = $can_manage ?? false;
$active    = 'inbox';
include __DIR__ . '/_nav.php';
?>
<div class="page-body">
    <?php include __DIR__ . '/_subnav.php'; ?>
    <?php if (empty($inbox)): ?>
        <div class="empty-state">
            <i class="fas fa-clipboard-check"></i>
            <p><?= $this->te('Aktuell wartet kein Antrag auf Ihre Entscheidung.') ?></p>
        </div>
    <?php else:
        $resolverLabels = ['fixed_user'=>'als fester Genehmiger','capability'=>'über eine Berechtigung','department'=>'über Ihre Abteilung','manager_of'=>'als Vorgesetzte/r','external_email'=>'als externe/r Genehmiger/in'];
    ?>
    <?php /* Endet vor der Tabelle – deren Zeilen tragen eigene Formulare;
             die Markierungen hängen über das form-Attribut daran. */ ?>
    <form method="post" action="/antraege/sammelaktion" id="bulkForm">
        <input type="hidden" name="_csrf" value="<?= $this->csrf() ?>">
        <div class="card card-outline card-primary">
        <div class="filter-card-body">
            <span class="text-muted" style="font-size:.85rem;"><i class="fas fa-layer-group"></i> <?= $this->te('Sammelaktion für markierte Genehmigungen:') ?></span>
            <button class="btn btn-sm btn-success" type="submit" name="decision" value="approve"
                onclick="return document.querySelectorAll('.wf-bulk-cb:checked').length>0 || (alert('Bitte mindestens eine Genehmigung markieren.'),false);">
                <i class="fas fa-check"></i> <?= $this->te('Markierte genehmigen') ?></button>
            <button class="btn btn-sm btn-danger" type="submit" name="decision" value="reject"
                onclick="var r=prompt('Begründung für die Ablehnung der markierten Anträge:');if(r===null)return false;if(!r.trim()){alert('Begründung erforderlich.');return false;}document.getElementById('bulkReason').value=r;return document.querySelectorAll('.wf-bulk-cb:checked').length>0||(alert('Bitte mindestens eine Genehmigung markieren.'),false);">
                <i class="fas fa-times"></i> <?= $this->te('Markierte ablehnen') ?></button>
            <input type="hidden" name="reason" id="bulkReason" value="">
        </div>
        </div>
    </form>
    <div class="table-wrapper">
        <table class="data-table wf-inbox-table">
            <thead>
                <tr>
                    <th scope="col" style="width:32px;"><input type="checkbox" onclick="document.querySelectorAll('.wf-bulk-cb').forEach(c=>c.checked=this.checked);"></th>
                    <th scope="col"><?= $this->te('Antrag') ?></th>
                    <th scope="col"><?= $this->te('Vorlage') ?></th>
                    <th scope="col"><?= $this->te('Station') ?></th>
                    <th scope="col"><?= $this->te('Typ') ?></th>
                    <th scope="col"><?= $this->te('Frist') ?></th>
                    <th scope="col"></th>
                </tr>
            </thead>
            <tbody>
            <?php foreach ($inbox as $row): ?>
                <?php
                $isTask = ($row['step_type'] ?? '') === 'task';
                $chain = !empty($row['resolver_json']) ? (json_decode($row['resolver_json'], true) ?: []) : [];
                $why = !empty($chain[0]['type']) ? ($resolverLabels[$chain[0]['type']] ?? '') : '';
                ?>
                <tr>
                    <td class="wf-cb-cell"><?php if (!$isTask): ?><input class="wf-bulk-cb" type="checkbox" form="bulkForm" name="step_state_ids[]" value="<?= (int)$row['step_state_id'] ?>"><?php endif; ?></td>
                    <td data-label="Antrag"><a class="table-link" href="/antraege/<?= (int)$row['request_id'] ?>"><?= $this->e($row['title']) ?></a><?php if (!empty($row['via_deputy'])): ?> <span class="badge" title="In Vertretung für <?= $this->e($row['deputy_for']) ?>"><?= $this->te('Vertretung') ?></span><?php endif; ?></td>
                    <td data-label="Vorlage"><i class="fas <?= $this->e($row['icon'] ?: 'fa-project-diagram') ?>"></i> <?= $this->e($row['workflow_name']) ?></td>
                    <td data-label="Station"><?= $this->e($row['step_name']) ?><?php if ($why): ?><br><span class="text-muted" style="font-size:.76rem;" title="<?= $this->te('Warum sehe ich das?') ?>"><i class="fas fa-info-circle"></i> zugewiesen <?= $this->e($why) ?></span><?php endif; ?></td>
                    <td data-label="Typ">
                        <?php if ($isTask): ?>
                            <span class="badge"><?= $this->te('Aufgabe') ?></span>
                            <?php
                            // Checklisten-Fortschritt ("2/3") direkt im Posteingang
                            if (($row['fulfillment_type'] ?? '') === 'checklist') {
                                $clCfg   = !empty($row['fulfillment_config_json']) ? (json_decode($row['fulfillment_config_json'], true) ?: []) : [];
                                $clItems = count((array)($clCfg['items'] ?? []));
                                if ($clItems > 0) {
                                    $clDone = count(!empty($row['checklist_state_json']) ? (json_decode($row['checklist_state_json'], true) ?: []) : []);
                                    echo '<span class="status-pill" title="Teilaufgaben erledigt">☑ ' . $clDone . '/' . $clItems . '</span>';
                                }
                            }
                            ?>
                        <?php else: ?>
                            <span class="badge"><?= $this->te('Genehmigung') ?></span>
                        <?php endif; ?>
                    </td>
                    <td data-label="Frist">
                        <?php if (!empty($row['deadline_at'])): ?>
                            <?php $overdue = strtotime($row['deadline_at']) < time(); ?>
                            <span class="status-pill <?= $overdue ? 'status-pill--danger' : '' ?>"><?= $this->date($row['deadline_at'], 'd.m.Y H:i') ?></span>
                        <?php else: ?>
                            <span class="text-muted">–</span>
                        <?php endif; ?>
                    </td>
                    <td class="wf-inline-actions">
                        <?php if (!$isTask): ?>
                            <!-- Direkt entscheiden, ohne den Antrag zu öffnen -->
                            <form method="post" action="/antraege/<?= (int)$row['request_id'] ?>/decide" style="display:inline;margin:0;">
                                <input type="hidden" name="_csrf" value="<?= $this->csrf() ?>">
                                <input type="hidden" name="step_state_id" value="<?= (int)$row['step_state_id'] ?>">
                                <input type="hidden" name="_return" value="inbox">
                                <input type="hidden" name="decision" value="approve">
                                <button class="btn btn-sm btn-success" type="submit" title="<?= $this->te('Direkt genehmigen') ?>"><i class="fas fa-check"></i></button>
                            </form>
                            <form method="post" action="/antraege/<?= (int)$row['request_id'] ?>/decide" style="display:inline;margin:0;"
                                  onsubmit="var r=prompt('Begründung für die Ablehnung:');if(r===null||!r.trim())return false;this.querySelector('[name=reason]').value=r;return true;">
                                <input type="hidden" name="_csrf" value="<?= $this->csrf() ?>">
                                <input type="hidden" name="step_state_id" value="<?= (int)$row['step_state_id'] ?>">
                                <input type="hidden" name="_return" value="inbox">
                                <input type="hidden" name="decision" value="reject">
                                <input type="hidden" name="reason" value="">
                                <button class="btn btn-sm btn-danger" type="submit" title="<?= $this->te('Direkt ablehnen (mit Begründung)') ?>"><i class="fas fa-times"></i></button>
                            </form>
                        <?php endif; ?>
                        <a class="btn btn-sm" href="/antraege/<?= (int)$row['request_id'] ?>"><?= $this->te('Öffnen') ?></a>
                    </td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php endif; ?>
</div>