Siel meldet über bot_api.php?action=consilium_legions, wer welche Legionsrolle hat. Die Website ordnet diese Mitglieder ohne Login der passenden Legion zu (neue Legionen werden angelegt, Lumina Ascendens übergangen). Im Profil und in der Verwaltung ist die Legion dann gesperrt, bis die Rolle wegfällt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
4.2 KiB
PHP
94 lines
4.2 KiB
PHP
<?php
|
||
/** Formulare von Verwaltung -> Consilium Elyseum (admin/consilium.php). */
|
||
require_once __DIR__ . '/../includes/bootstrap.php';
|
||
require_once __DIR__ . '/../includes/consilium.php';
|
||
require_permission('consilium.manage');
|
||
|
||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||
redirect('/admin/consilium.php');
|
||
}
|
||
verify_csrf();
|
||
|
||
$pdo = db();
|
||
$action = (string) ($_POST['action'] ?? '');
|
||
$id = (int) ($_POST['id'] ?? 0);
|
||
$name = trim((string) ($_POST['name'] ?? ''));
|
||
$back = '/admin/consilium.php';
|
||
|
||
switch ($action) {
|
||
case 'legion_add':
|
||
case 'legion_rename':
|
||
if ($name === '' || mb_strlen($name) > CONSILIUM_LEGION_NAME_MAX) {
|
||
set_flash('error', 'Bitte einen Namen mit höchstens ' . CONSILIUM_LEGION_NAME_MAX . ' Zeichen angeben.');
|
||
redirect($back);
|
||
}
|
||
if ($action === 'legion_add') {
|
||
$order = (int) $pdo->query('SELECT COALESCE(MAX(sort_order), 0) + 10 FROM consilium_legions')->fetchColumn();
|
||
$pdo->prepare('INSERT INTO consilium_legions (name, sort_order) VALUES (?, ?)')->execute([$name, $order]);
|
||
admin_log('🤝 ' . CONSILIUM_NAME . ': Legion hinzugefügt', ['Legion' => $name], 'success');
|
||
set_flash('success', '„' . $name . '“ gehört jetzt zu ' . CONSILIUM_NAME . '.');
|
||
redirect($back);
|
||
}
|
||
$old = consilium_legion_name($id);
|
||
if ($old === null) {
|
||
set_flash('error', 'Diese Legion gibt es nicht (mehr).');
|
||
redirect($back);
|
||
}
|
||
if ($old !== $name) {
|
||
$pdo->prepare('UPDATE consilium_legions SET name = ? WHERE id = ?')->execute([$name, $id]);
|
||
admin_log('🤝 ' . CONSILIUM_NAME . ': Legion umbenannt', ['Vorher' => $old, 'Neu' => $name]);
|
||
}
|
||
set_flash('success', 'Gespeichert.');
|
||
redirect($back);
|
||
|
||
case 'legion_delete':
|
||
$old = consilium_legion_name($id);
|
||
if ($old !== null) {
|
||
$pdo->beginTransaction();
|
||
$pdo->prepare('UPDATE users SET consilium_legion_id = NULL WHERE consilium_legion_id = ?')->execute([$id]);
|
||
$pdo->prepare('DELETE FROM consilium_legions WHERE id = ?')->execute([$id]);
|
||
$pdo->commit();
|
||
admin_log('🤝 ' . CONSILIUM_NAME . ': Legion gelöscht', ['Legion' => $old, 'Hinweis' => 'Ihre Mitglieder bleiben in ' . CONSILIUM_NAME . ', nur ohne Legion.'], 'danger');
|
||
set_flash('success', '„' . $old . '“ ist gelöscht.');
|
||
}
|
||
redirect($back);
|
||
|
||
case 'legion_move':
|
||
$rows = $pdo->query('SELECT id FROM consilium_legions ORDER BY sort_order, name')->fetchAll(PDO::FETCH_COLUMN);
|
||
$ids = array_map('intval', $rows);
|
||
$index = array_search($id, $ids, true);
|
||
$target = $index === false ? false : $index + (($_POST['direction'] ?? '') === 'up' ? -1 : 1);
|
||
if ($index !== false && isset($ids[$target])) {
|
||
[$ids[$index], $ids[$target]] = [$ids[$target], $ids[$index]];
|
||
$update = $pdo->prepare('UPDATE consilium_legions SET sort_order = ? WHERE id = ?');
|
||
foreach ($ids as $position => $legionId) {
|
||
$update->execute([($position + 1) * 10, $legionId]);
|
||
}
|
||
}
|
||
redirect($back);
|
||
|
||
case 'member_legion':
|
||
$userId = (int) ($_POST['user_id'] ?? 0);
|
||
$legionId = (int) ($_POST['legion_id'] ?? 0);
|
||
if (!consilium_is_member_account($userId)) {
|
||
set_flash('error', 'Dieses Konto gehört nicht zu ' . CONSILIUM_NAME . '.');
|
||
redirect($back);
|
||
}
|
||
if ($legionId > 0 && !consilium_legion_exists($legionId)) {
|
||
set_flash('error', 'Diese Legion gibt es nicht (mehr).');
|
||
redirect($back);
|
||
}
|
||
if (consilium_legion_by_role($userId)) {
|
||
set_flash('error', 'Die Legion dieses Mitglieds kommt von seiner Legionsrolle auf Discord – dort ändern.');
|
||
redirect($back);
|
||
}
|
||
consilium_set_member_legion($userId, $legionId > 0 ? $legionId : null);
|
||
admin_log('🤝 ' . CONSILIUM_NAME . ': Mitglied zugeordnet', [
|
||
'Mitglied' => admin_log_user($userId),
|
||
'Legion' => $legionId > 0 ? (string) consilium_legion_name($legionId) : 'keine',
|
||
]);
|
||
set_flash('success', 'Zugeordnet.');
|
||
redirect($back);
|
||
}
|
||
|
||
redirect($back);
|