Until now the tags of a member were sorted by rank group first and then by the internal name, so "Legionär" came before PvE while "Veteranus" came last. Verwaltung -> Berechtigungsgruppen now has "Reihenfolge der Tags": move groups by drag & drop (mouse: whole row, finger: grip) or with the arrows, then save. - New column roles.tag_order (schema version 56, also in sql/schema.sql), saved by admin/role_order_action.php (roles.manage) with before/after in the audit log. - ROLE_TAG_ORDER_SQL and role_tags_sorted() in includes/permissions.php sort the tags in the member list and its group filter, on the profile page, in the dashboard and in the user admin. Groups without a position (before the first save, or created later) follow in the old order. - The rank of a member (sections of the member list) still depends only on roster_order. - Live updates of the member list react to a new order; README and patch notes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
162 lines
8.3 KiB
PHP
162 lines
8.3 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../includes/bootstrap.php';
|
|
require_once __DIR__ . '/../includes/events_api.php';
|
|
require_permission('roles.manage');
|
|
|
|
$roles = db()->query(
|
|
'SELECT r.id, r.name, r.display_name, r.description, r.is_system, r.roster_order, r.discord_role_id, r.tag_bg, r.tag_bg2, r.tag_color, r.tag_icon,
|
|
COUNT(DISTINCT ur.user_id) AS user_count,
|
|
COUNT(DISTINCT rp.permission_id) AS permission_count
|
|
FROM roles r
|
|
LEFT JOIN user_roles ur ON ur.role_id = r.id
|
|
LEFT JOIN role_permissions rp ON rp.role_id = r.id
|
|
GROUP BY r.id
|
|
ORDER BY r.name'
|
|
)->fetchAll();
|
|
|
|
// Reihenfolge der Tags: alle Gruppen so, wie ihre Tags gerade sortiert sind
|
|
$tagOrderRoles = db()->query(
|
|
'SELECT r.id, r.name, r.display_name, r.tag_bg, r.tag_bg2, r.tag_color, r.tag_icon FROM roles r ORDER BY ' . ROLE_TAG_ORDER_SQL
|
|
)->fetchAll();
|
|
|
|
// Namen der Discord-Rollen fuer die Anzeige - ohne Bot-API bleibt es bei der Rollen-ID.
|
|
$guildRoles = [];
|
|
try {
|
|
foreach (fetch_guild_roles() as $guildRole) {
|
|
$guildRoles[(string) ($guildRole['role_id'] ?? '')] = (string) ($guildRole['name'] ?? '');
|
|
}
|
|
} catch (Throwable $e) {
|
|
$guildRoles = [];
|
|
}
|
|
|
|
// Discord-Rollen, die als Klassenrolle zaehlen (Klassen im Profil, includes/discord_auth.php)
|
|
$classRoles = discord_class_roles($guildRoles);
|
|
|
|
$pageTitle = 'Berechtigungsgruppen';
|
|
// Die Tabelle hat viele Spalten - volle Breite statt der schmalen Inhaltsspalte.
|
|
$containerWide = true;
|
|
include __DIR__ . '/../includes/header.php';
|
|
?>
|
|
<div class="panel">
|
|
<h1>Berechtigungsgruppen</h1>
|
|
<p class="text-muted">
|
|
Rollen fassen mehrere Berechtigungen zusammen. Jeder Benutzer kann eine oder mehrere Gruppen
|
|
haben, die Rechte addieren sich. Gruppen mit Discord-Rolle werden automatisch vergeben und
|
|
entzogen - wer mehrere dieser Rollen hat, bekommt alle zugehörigen Gruppen. Einzelnen Personen
|
|
lassen sich Berechtigungen auch direkt geben, ohne eigene Gruppe: in der Benutzerverwaltung beim
|
|
Bearbeiten unter „Einzelne Berechtigungen“ (mit <code>users.permissions</code>).
|
|
</p>
|
|
|
|
<p><a class="button" href="/admin/role_form.php">Neue Gruppe anlegen</a></p>
|
|
|
|
<div class="table-scroll">
|
|
<table class="table-actions">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Anzeigename</th>
|
|
<th>Beschreibung</th>
|
|
<th>Discord-Rolle</th>
|
|
<th>Mitgliederliste</th>
|
|
<th>Mitglieder</th>
|
|
<th>Berechtigungen</th>
|
|
<th>Aktionen</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($roles as $r): ?>
|
|
<tr>
|
|
<td><?= e($r['name']) ?> <?php if ($r['is_system']): ?><span class="badge">System</span><?php endif; ?></td>
|
|
<td><?= role_tag_html($r['display_name'] !== '' ? $r['display_name'] : $r['name'], role_tag_css($r['tag_bg'], $r['tag_color'], $r['tag_bg2']), '', role_icon_url($r['tag_icon'])) ?></td>
|
|
<td><?= e($r['description']) ?></td>
|
|
<td>
|
|
<?php if ($r['discord_role_id'] !== null): ?>
|
|
<?php $roleName = $guildRoles[(string) $r['discord_role_id']] ?? ''; ?>
|
|
<span class="discord-inline"><?= discord_logo(14) ?> <?= $roleName !== '' ? '@' . e($roleName) : e((string) $r['discord_role_id']) ?></span>
|
|
<?php else: ?>
|
|
<span class="text-muted">—</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td>
|
|
<?php if ($r['roster_order'] !== null): ?>
|
|
<span class="badge badge-active">Gruppe #<?= (int) $r['roster_order'] ?></span>
|
|
<?php else: ?>
|
|
<span class="text-muted">—</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td><?= (int) $r['user_count'] ?></td>
|
|
<td><?= (int) $r['permission_count'] ?></td>
|
|
<td>
|
|
<div class="actions">
|
|
<a class="icon-button" href="/admin/role_form.php?id=<?= (int) $r['id'] ?>" title="Bearbeiten" aria-label="Bearbeiten"><?= icon('edit') ?></a>
|
|
<?php if (!$r['is_system']): ?>
|
|
<form class="inline-form" method="post" action="/admin/role_delete.php" data-confirm="Diese Berechtigungsgruppe wirklich löschen?" data-confirm-title="Gruppe löschen" data-confirm-danger data-confirm-ok="Löschen">
|
|
<?= csrf_field() ?>
|
|
<input type="hidden" name="id" value="<?= (int) $r['id'] ?>">
|
|
<button type="submit" class="icon-button icon-button-danger" title="Löschen" aria-label="Löschen"><?= icon('trash') ?></button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if (count($tagOrderRoles) > 1): ?>
|
|
<div class="panel" id="tag-order">
|
|
<h2>Reihenfolge der Tags</h2>
|
|
<p class="text-muted">
|
|
In dieser Reihenfolge stehen die Gruppen eines Mitglieds als Tags: in der Mitgliederliste, auf den
|
|
Profilseiten, im Dashboard und in der Benutzerverwaltung. Zum Verschieben ein Tag am Griff (⠿) ziehen
|
|
oder die Pfeile nutzen, dann speichern. Neu angelegte Gruppen stehen hinten, bis ihr sie einordnet.
|
|
</p>
|
|
<form method="post" action="/admin/role_order_action.php" data-tag-order>
|
|
<?= csrf_field() ?>
|
|
<ol class="tag-order-list">
|
|
<?php foreach ($tagOrderRoles as $i => $r): ?>
|
|
<?php $label = $r['display_name'] !== '' ? $r['display_name'] : $r['name']; ?>
|
|
<li class="tag-order-item">
|
|
<input type="hidden" name="order[]" value="<?= (int) $r['id'] ?>">
|
|
<span class="tag-order-handle" title="Ziehen zum Verschieben" aria-hidden="true">⠿</span>
|
|
<?= role_tag_html($label, role_tag_css($r['tag_bg'], $r['tag_color'], $r['tag_bg2']), '', role_icon_url($r['tag_icon'])) ?>
|
|
<?php // Interner Name nur, wenn der Anzeigename ihn nicht schon enthaelt (z.B. "Sedes Luminis" = Leitung) ?>
|
|
<?php if (mb_stripos($label, $r['name']) === false): ?><span class="tag-order-name text-muted"><?= e($r['name']) ?></span><?php endif; ?>
|
|
<span class="tag-order-move">
|
|
<button type="button" class="icon-button tag-order-up" data-move="up" title="Nach oben" aria-label="<?= e($label) ?> nach oben"<?= $i === 0 ? ' disabled' : '' ?>><?= icon('chevron-down') ?></button>
|
|
<button type="button" class="icon-button" data-move="down" title="Nach unten" aria-label="<?= e($label) ?> nach unten"<?= $i === count($tagOrderRoles) - 1 ? ' disabled' : '' ?>><?= icon('chevron-down') ?></button>
|
|
</span>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ol>
|
|
<div class="actions">
|
|
<button type="submit">Reihenfolge speichern</button>
|
|
<span class="text-muted" data-tag-order-status hidden>Noch nicht gespeichert</span>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<script src="<?= e(asset_url('/assets/js/tag-order.js')) ?>"></script>
|
|
<?php endif; ?>
|
|
|
|
<div class="panel">
|
|
<h2>Klassenrollen auf Discord</h2>
|
|
<p class="text-muted">
|
|
Diese Discord-Rollen zählen als Klasse: Wer sie hat, bekommt die Klasse beim nächsten Discord-Abgleich
|
|
automatisch ins Profil - auch mehrere. Erkannt wird am Rollennamen (deutsche und englische Klassennamen).
|
|
Wer mehrere Klassen spielt, wählt im Profil seine Main-Klasse.
|
|
</p>
|
|
<?php if (!$guildRoles): ?>
|
|
<p class="text-muted">Die Rollen des Discord-Servers sind gerade nicht abrufbar (Bot nicht erreichbar).</p>
|
|
<?php elseif (!$classRoles): ?>
|
|
<p class="text-muted">Keine Discord-Rolle heißt wie eine Klasse - so kann die Website keine Klassen erkennen.</p>
|
|
<?php else: ?>
|
|
<div class="member-profile-classes">
|
|
<?php foreach ($classRoles as $roleName => $class): ?>
|
|
<span class="member-profile-class is-main"><?= class_badge_html($class, 18) ?> <?= e($roleName) ?><?= $roleName !== $class ? ' → ' . e($class) : '' ?></span>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php include __DIR__ . '/../includes/footer.php'; ?>
|