Asked for: "das consilium elyseum wurde umbenannt zu DACH Elyos. pass das bitte an auf der website". - CONSILIUM_NAME is 'DACH Elyos', and every visible text follows it: sidebar, the alliance page, member tab, raid area, calendar audience and badge, iCal note, map live sessions and share buttons, admin pages (Verwaltung -> DACH Elyos, Discord-Bot, Berechtigungsgruppen), flash messages, log entries, permission descriptions (synced to the database by schema_sync_core_permissions()) and the privacy page. - The name takes no article, so the sentences around it changed too: "von DACH Elyos", "in DACH Elyos", "für DACH Elyos" instead of "des Consiliums", "im Consilium", "für das Consilium". The bot channel label is now "Raid-Kanal DACH Elyos". - Internal names stay "consilium": permission keys, tables, settings, files and URLs (?bereich=consilium, ?tab=consilium), so nothing in the database or in existing links changes. includes/consilium.php says so. - README: section renamed to "DACH Elyos" (anchor #dach-elyos). - No patch note (alliance topics stay out of them). The bot's two "Consilium" error texts in live_tactics.py never reach the page - the map only reads the status code - so the bot needs no update. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
223 lines
9.2 KiB
PHP
223 lines
9.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* DACH Elyos (bis 28.09.2026 "Consilium Elyseum") - das Buendnis mit anderen Legionen. Auf der Website steht der Name
|
|
* aus CONSILIUM_NAME; intern heisst alles weiter "consilium" (Rechte, Tabellen, Einstellungen, Dateien, Adressen).
|
|
* Der Name hat keinen Artikel: "von DACH Elyos", "in DACH Elyos", "fuer DACH Elyos".
|
|
*
|
|
* Das Buendnis hat einen eigenen Discord-Server (consilium_guild_id(),
|
|
* Verwaltung -> Discord-Bot) mit den Rollen Force Commander, Legion Lead, Legion Officer und Legionaer. Die damit
|
|
* verknuepften Gruppen (roles.discord_guild_id = dieser Server) geben consilium.view und je nach Rang mehr
|
|
* (consilium.draw, consilium.raids ...). Wer dort eine Rolle hat, gehoert zum Consilium - Verbuendete wie Mitglieder
|
|
* unserer Legion; wer nicht auf dem Server ist, sieht vom Consilium nichts. Verbuendete haben kein dashboard.view: Sie
|
|
* sehen nur ihre eigene Ansicht (consilium.php) und zaehlen nirgends zur Legion (sql_is_legion_member()).
|
|
* Anmelden koennen sie sich ueber den Server des Consiliums (includes/discord_auth.php); freigeschaltet werden sie wie
|
|
* alle von den Admins.
|
|
*
|
|
* Zu welcher verbuendeten Legion jemand gehoert, steht auf der Website - auf dem Server gibt es keine Rolle je Legion:
|
|
* Die Leitung legt die Legionen an (admin/consilium.php, consilium.manage) und ordnet die Mitglieder zu, jedes Mitglied
|
|
* kann seine Legion auch selbst im Profil waehlen (users.consilium_legion_id). Unsere eigenen Leute stehen dort unter
|
|
* CONSILIUM_HOME_LEGION.
|
|
*/
|
|
|
|
const CONSILIUM_NAME = 'DACH Elyos';
|
|
const CONSILIUM_HOME_LEGION = 'Lumina Ascendens';
|
|
const CONSILIUM_LEGION_NAME_MAX = 80;
|
|
|
|
/** Discord-Server des Consilium Elyseum (Server-ID) - '' = keiner eingetragen. */
|
|
function consilium_guild_id(): string
|
|
{
|
|
$id = trim(setting_get('consilium_guild_id'));
|
|
return preg_match('/^[0-9]{5,20}$/', $id) === 1 ? $id : '';
|
|
}
|
|
|
|
/**
|
|
* SQL-Bedingung: Das Konto (Tabelle users als $alias) hat eine Gruppe, die an einer Rolle des Servers des Consiliums
|
|
* haengt - es ist also dort Mitglied (Stand des letzten Abgleichs).
|
|
*/
|
|
function sql_has_consilium_role(string $alias = 'u'): string
|
|
{
|
|
$guild = consilium_guild_id();
|
|
if ($guild === '') {
|
|
return '0';
|
|
}
|
|
return "EXISTS (SELECT 1 FROM user_roles cur JOIN roles cr ON cr.id = cur.role_id
|
|
WHERE cur.user_id = $alias.id AND cr.discord_guild_id = " . db()->quote($guild) . ')';
|
|
}
|
|
|
|
/**
|
|
* Raenge im Consilium: je Konto die Gruppen, die an Rollen des Servers des Consiliums haengen (Force Commander,
|
|
* Legion Lead ...), in der Reihenfolge der Tags.
|
|
*
|
|
* @param int[] $userIds
|
|
* @return array<int, string[]>
|
|
*/
|
|
function consilium_member_ranks(array $userIds): array
|
|
{
|
|
$guild = consilium_guild_id();
|
|
if ($guild === '' || !$userIds) {
|
|
return [];
|
|
}
|
|
$placeholders = implode(',', array_fill(0, count($userIds), '?'));
|
|
$stmt = db()->prepare(
|
|
"SELECT ur.user_id, COALESCE(NULLIF(r.display_name, ''), r.name) AS label
|
|
FROM user_roles ur JOIN roles r ON r.id = ur.role_id
|
|
WHERE r.discord_guild_id = ? AND ur.user_id IN ($placeholders)
|
|
ORDER BY " . ROLE_TAG_ORDER_SQL
|
|
);
|
|
$stmt->execute(array_merge([$guild], array_map('intval', $userIds)));
|
|
$ranks = [];
|
|
foreach ($stmt->fetchAll() as $row) {
|
|
$ranks[(int) $row['user_id']][] = (string) $row['label'];
|
|
}
|
|
return $ranks;
|
|
}
|
|
|
|
/**
|
|
* Die verbuendeten Legionen in ihrer Reihenfolge, mit der Zahl ihrer (aktiven) Mitglieder.
|
|
*
|
|
* @return array<int, array{id: int, name: string, sort_order: int, member_count: int}>
|
|
*/
|
|
function consilium_legions(): array
|
|
{
|
|
try {
|
|
$rows = db()->query(
|
|
"SELECT l.id, l.name, l.sort_order,
|
|
(SELECT COUNT(*) FROM users u WHERE u.consilium_legion_id = l.id AND u.status = 'active'
|
|
AND " . sql_is_consilium_only('u') . ") AS member_count
|
|
FROM consilium_legions l ORDER BY l.sort_order, l.name"
|
|
)->fetchAll();
|
|
} catch (PDOException $e) {
|
|
return []; // Tabelle kommt erst mit dem naechsten Schema-Abgleich
|
|
}
|
|
return array_map(static fn (array $row): array => [
|
|
'id' => (int) $row['id'],
|
|
'name' => (string) $row['name'],
|
|
'sort_order' => (int) $row['sort_order'],
|
|
'member_count' => (int) $row['member_count'],
|
|
], $rows);
|
|
}
|
|
|
|
/**
|
|
* Mitglieder des Consiliums, nach Name: alle mit einer Rolle auf dem Server des Consiliums - Verbuendete und unsere
|
|
* eigenen Leute (is_legion = 1) - und Verbuendete, deren Gruppe von Hand vergeben ist. Fuer die Mitgliederliste nur
|
|
* aktive, fuer die Verwaltung ($withPending, nur Verbuendete) auch solche, die noch auf die Freischaltung warten.
|
|
*
|
|
* @return array<int, array<string, mixed>>
|
|
*/
|
|
function consilium_members(bool $withPending = false): array
|
|
{
|
|
try {
|
|
return db()->query(
|
|
"SELECT u.id, u.username, u.display_name, u.discord_id, u.discord_username, u.avatar_filename, u.class_name,
|
|
u.classes, u.status, u.consilium_legion_id,
|
|
COALESCE(u.last_seen_at, u.last_login) AS last_active,
|
|
COALESCE(u.discord_joined_at, u.created_at) AS joined_at,
|
|
" . sql_is_legion_member('u') . " AS is_legion
|
|
FROM users u
|
|
WHERE u.status " . ($withPending ? "IN ('active', 'pending')" : "= 'active'") . '
|
|
AND (' . sql_is_consilium_only('u') . ($withPending ? '' : ' OR ' . sql_has_consilium_role('u')) . ")
|
|
ORDER BY COALESCE(NULLIF(u.display_name, ''), u.username)"
|
|
)->fetchAll();
|
|
} catch (PDOException $e) {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Ist das Consilium eingerichtet? Erst dann sieht die Legion es in Menue und Mitgliederliste - vorher waere es nur
|
|
* ein leerer Reiter. Eingerichtet heisst: Sein Discord-Server ist eingetragen, es gibt eine verbuendete Legion oder eine
|
|
* Gruppe des Consiliums (consilium.view ohne dashboard.view - die Administrator-Gruppe bekommt neue Rechte automatisch
|
|
* und zaehlt nicht).
|
|
*/
|
|
function consilium_enabled(): bool
|
|
{
|
|
static $enabled = null;
|
|
if ($enabled === null) {
|
|
try {
|
|
$enabled = consilium_guild_id() !== ''
|
|
|| (bool) db()->query('SELECT 1 FROM consilium_legions LIMIT 1')->fetchColumn()
|
|
|| (bool) db()->query(
|
|
"SELECT 1 FROM role_permissions rp JOIN permissions p ON p.id = rp.permission_id
|
|
WHERE p.`key` = 'consilium.view'
|
|
AND NOT EXISTS (SELECT 1 FROM role_permissions rp2 JOIN permissions p2 ON p2.id = rp2.permission_id
|
|
WHERE rp2.role_id = rp.role_id AND p2.`key` = 'dashboard.view')
|
|
LIMIT 1"
|
|
)->fetchColumn();
|
|
} catch (PDOException $e) {
|
|
$enabled = false;
|
|
}
|
|
}
|
|
return $enabled;
|
|
}
|
|
|
|
/**
|
|
* Die naechsten Consilium-Termine aus dem Kalender (freigegeben, ab jetzt) fuer die Startseite.
|
|
*
|
|
* @return array<int, array<string, mixed>>
|
|
*/
|
|
function consilium_upcoming_entries(int $limit = 5): array
|
|
{
|
|
try {
|
|
$stmt = db()->prepare(
|
|
"SELECT e.id, e.title, e.starts_at,
|
|
(SELECT COUNT(*) FROM calendar_participants p JOIN users pu ON pu.id = p.user_id
|
|
WHERE p.entry_id = e.id AND pu.status = 'active') AS people
|
|
FROM calendar_entries e JOIN users u ON u.id = e.user_id
|
|
WHERE e.audience = 'consilium' AND e.status = 'visible' AND u.status = 'active' AND e.starts_at >= ?
|
|
ORDER BY e.starts_at LIMIT " . max(1, $limit)
|
|
);
|
|
$stmt->execute([date('Y-m-d H:i:s', strtotime('-2 hours'))]);
|
|
return $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
/** Gibt es diese Legion? */
|
|
function consilium_legion_exists(int $legionId): bool
|
|
{
|
|
$stmt = db()->prepare('SELECT 1 FROM consilium_legions WHERE id = ?');
|
|
$stmt->execute([$legionId]);
|
|
return (bool) $stmt->fetchColumn();
|
|
}
|
|
|
|
/** Name einer Legion oder null. */
|
|
function consilium_legion_name(?int $legionId): ?string
|
|
{
|
|
if ($legionId === null) {
|
|
return null;
|
|
}
|
|
$stmt = db()->prepare('SELECT name FROM consilium_legions WHERE id = ?');
|
|
$stmt->execute([$legionId]);
|
|
$name = $stmt->fetchColumn();
|
|
return $name === false ? null : (string) $name;
|
|
}
|
|
|
|
/** Gehoert das Konto nur zum Consilium (nicht zur Legion)? Fuer andere Konten als das angemeldete. */
|
|
function consilium_is_member_account(int $userId): bool
|
|
{
|
|
$stmt = db()->prepare('SELECT 1 FROM users u WHERE u.id = ? AND ' . sql_is_consilium_only('u'));
|
|
$stmt->execute([$userId]);
|
|
return (bool) $stmt->fetchColumn();
|
|
}
|
|
|
|
/** Legion eines Kontos (users.consilium_legion_id) oder null. */
|
|
function consilium_member_legion_id(int $userId): ?int
|
|
{
|
|
try {
|
|
$stmt = db()->prepare('SELECT consilium_legion_id FROM users WHERE id = ?');
|
|
$stmt->execute([$userId]);
|
|
$legionId = $stmt->fetchColumn();
|
|
} catch (PDOException $e) {
|
|
return null;
|
|
}
|
|
return $legionId === false || $legionId === null ? null : (int) $legionId;
|
|
}
|
|
|
|
/** Ein Mitglied einer verbuendeten Legion zuordnen (null = keiner). */
|
|
function consilium_set_member_legion(int $userId, ?int $legionId): void
|
|
{
|
|
db()->prepare('UPDATE users SET consilium_legion_id = ? WHERE id = ?')->execute([$legionId, $userId]);
|
|
}
|