OpenNIT

Quelltext des aktuellen Standes

Fassung 1.1.1

index.php

7 KB
<?php $this->layout('layouts/admin', [
    'page_title'         => 'Berechtigungsverwaltung',
    'current_admin_page' => 'permissions',
    'breadcrumbs'        => [['label' => 'Berechtigungen']],
    'page_actions'       => '<a href="/admin/permissions/matrix" class="btn btn-default"><i class="fas fa-table"></i> '
                          . $this->te('Matrix') . '</a>',
]); ?>

<?php
    $mitZuweisung = 0;
    foreach ($users as $u) {
        if ((int)($u['role_count'] ?? 0) > 0) { $mitZuweisung++; }
    }
?>

<div class="kpi-row">
    <div class="kpi-col">
        <div class="small-box bg-info">
            <div class="inner">
                <h3><?= count($users) ?></h3>
                <p><?= $this->te('Benutzer') ?></p>
            </div>
            <div class="icon"><i class="fas fa-users"></i></div>
        </div>
    </div>
    <div class="kpi-col">
        <div class="small-box bg-success">
            <div class="inner">
                <h3><?= $mitZuweisung ?></h3>
                <p><?= $this->te('mit Zuweisung') ?></p>
            </div>
            <div class="icon"><i class="fas fa-user-check"></i></div>
        </div>
    </div>
    <div class="kpi-col">
        <div class="small-box bg-primary">
            <div class="inner">
                <h3><?= count($topics) ?></h3>
                <p><?= $this->te('Themengebiete') ?></p>
            </div>
            <div class="icon"><i class="fas fa-sitemap"></i></div>
        </div>
    </div>
    <div class="kpi-col">
        <div class="small-box bg-warning">
            <div class="inner">
                <h3><?= count($roles) ?></h3>
                <p><?= $this->te('Rollen') ?></p>
            </div>
            <div class="icon"><i class="fas fa-user-shield"></i></div>
        </div>
    </div>
</div>

<div class="card">
    <div class="card-header">
        <h3 class="card-title"><?= $this->te('Rolle für ein Themengebiet vergeben') ?></h3>
    </div>
    <div class="card-body">
        <form method="POST" action="/admin/permissions/grant" class="filter-card-body">
            <input type="hidden" name="_csrf" value="<?= $this->csrf() ?>">
            <input type="hidden" name="return_to" value="/admin/permissions">
            <div class="form-group">
                <label for="pg-user"><?= $this->te('Benutzer') ?> <span class="text-danger">*</span></label>
                <select name="user_id" id="pg-user" class="form-control form-control-sm" required>
                    <option value=""><?= $this->te('Bitte wählen') ?></option>
                    <?php foreach ($users as $u): ?>
                        <option value="<?= (int)$u['id'] ?>"<?= empty($u['is_active']) ? ' disabled' : '' ?>>
                            <?= $this->e($u['display_name'] ?: $u['email']) ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="form-group">
                <label for="pg-topic"><?= $this->te('Themengebiet') ?> <span class="text-danger">*</span></label>
                <select name="topic_id" id="pg-topic" class="form-control form-control-sm" required>
                    <option value=""><?= $this->te('Bitte wählen') ?></option>
                    <?php foreach ($topics as $t): ?>
                        <option value="<?= (int)$t['id'] ?>">
                            <?= str_repeat('— ', max(0, (int)($t['depth'] ?? 0))) ?><?= $this->e($t['name']) ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="form-group">
                <label for="pg-role"><?= $this->te('Rolle') ?> <span class="text-danger">*</span></label>
                <select name="role_id" id="pg-role" class="form-control form-control-sm" required>
                    <option value=""><?= $this->te('Bitte wählen') ?></option>
                    <?php foreach ($roles as $r): ?>
                        <option value="<?= (int)$r['id'] ?>"><?= $this->e($r['name']) ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="form-group">
                <label>&nbsp;</label>
                <button type="submit" class="btn btn-primary btn-sm">
                    <i class="fas fa-plus"></i> <?= $this->te('Zuweisen') ?>
                </button>
            </div>
        </form>
        <small class="form-hint">
            <?= $this->te('Vergeben lässt sich nur eine Rolle, deren Rechte Sie selbst besitzen.') ?>
        </small>
    </div>
</div>

<?php if (!empty($users)): ?>
<div class="table-wrapper">
    <table class="data-table">
        <thead>
            <tr>
                <th scope="col"><?= $this->te('Benutzer') ?></th>
                <th scope="col"><?= $this->te('E-Mail') ?></th>
                <th scope="col"><?= $this->te('Status') ?></th>
                <th scope="col"><?= $this->te('Rollen') ?></th>
                <th scope="col"><?= $this->te('Themengebiete') ?></th>
                <th scope="col"></th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($users as $u): ?>
            <tr>
                <td>
                    <a href="/admin/permissions/user/<?= (int)$u['id'] ?>" class="table-link">
                        <?= $this->e($u['display_name'] ?: $u['email']) ?>
                    </a>
                </td>
                <td><?= $this->e($u['email']) ?></td>
                <td>
                    <?php if (!empty($u['is_active'])): ?>
                        <span class="status-pill status-pill--success">
                            <span class="status-dot status-dot--success"></span> <?= $this->te('aktiv') ?>
                        </span>
                    <?php else: ?>
                        <span class="status-pill status-pill--neutral"><?= $this->te('deaktiviert') ?></span>
                    <?php endif; ?>
                </td>
                <td><span class="badge badge-info"><?= (int)($u['role_count'] ?? 0) ?></span></td>
                <td><span class="badge badge-secondary"><?= (int)($u['topic_count'] ?? 0) ?></span></td>
                <td style="text-align:right;white-space:nowrap;">
                    <a href="/admin/permissions/user/<?= (int)$u['id'] ?>" class="btn btn-default btn-sm"
                       title="<?= $this->te('Berechtigungen anzeigen') ?>">
                        <i class="fas fa-key"></i>
                    </a>
                </td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>
<?php else: ?>
<div class="empty-state">
    <i class="fas fa-users"></i>
    <p><?= $this->te('Keine Benutzer vorhanden.') ?></p>
</div>
<?php endif; ?>

<?php if (!empty($topics)): ?>
<div class="detail-card" style="margin-top:1.25rem;">
    <div class="detail-card-header">
        <span class="detail-card-title"><?= $this->te('Themengebiete') ?></span>
    </div>
    <div class="detail-card-body">
        <p class="form-hint" style="margin-top:0;">
            <?= $this->te('Ein Themengebiet zeigt, wer dort welche Rolle hat.') ?>
        </p>
        <?php foreach ($topics as $t): ?>
            <a href="/admin/permissions/topic/<?= (int)$t['id'] ?>" class="badge badge-secondary"
               style="margin:0 .25rem .35rem 0;display:inline-block;text-decoration:none;">
                <?= $this->e($t['name']) ?>
            </a>
        <?php endforeach; ?>
    </div>
</div>
<?php endif; ?>