Asked for: alliances ("Consilium Elyseum") with their own view, a member-list tab with the allied legions and their
members, an own raid area, a calendar that shows them only alliance entries, and live map sessions the legion can
share with them - watching only, or drawing only with an extra permission. There is one Discord role "Consilium
Elyseum" for all allies, so which legion each ally belongs to is stored on the website.
- Permissions consilium.view / consilium.draw / consilium.manage. An account with consilium.view but without
dashboard.view is a guest of the Consilium (consilium_only(), sql_is_consilium_only()) and sees only the alliance
area; raids, calendar and map stay restricted even with extra rights like raids.view or map.view.
- includes/consilium.php; consilium.php is the allies' start page instead of the dashboard (next raids and entries,
legions, running shared map sessions); admin/consilium.php: setup hints, allied legions, member assignment.
users.consilium_legion_id, table consilium_legions (schema 69); allies pick their legion under Mein Profil.
- Members: new tab "Consilium Elyseum" (legions with their members), the only tab allies see. Legion-only lists
(dues, Lumipunkte, member pickers, raid and activity points) leave allies out.
- Raids: two areas, legion and Consilium, told apart by the Discord channel ("Consilium-Raids" under Verwaltung ->
Discord-Bot, settings.consilium_raid_channel; the bot API returns channel_id). Allies only see and sign up for
Consilium raids, which give no Lumipunkte; raids created in the Consilium area are posted to its channel.
- Calendar: audience "Consilium Elyseum". Allies see only those entries and the Consilium raids (also in their iCal
subscription), their own entries are always Consilium entries; the public calendar shows no Consilium raids; the
legion sees them marked with 🤝.
- Map: whoever may edit a public tactic shares its running live session with the Consilium (consilium_share, logged).
The share lives in the bot's live relay and only for that session: it ends with "Freigabe beenden" or 60 s after
the last legion member left; making the tactic private or deleting it ends it as well. Allies see only running
shared sessions under Karte (and on their start page), join and watch; with consilium.draw they add strokes,
areas, points and text - no figures, nothing moved, erased or undone, no tactics, steps, copies or history.
Enforced in tactics_api.php (guest branch: shared tactics only, only live_token and shape_create) and in the relay
(guest tickets, event whitelist, guests are disconnected when the share ends). Needs the bot update (api.py,
database/db.py, live_tactics.py).
- Navigation, privacy page, patch note, README.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
174 lines
8.1 KiB
PHP
174 lines
8.1 KiB
PHP
<?php
|
||
require_once __DIR__ . '/includes/bootstrap.php';
|
||
require_once __DIR__ . '/includes/raids_api.php';
|
||
require_once __DIR__ . '/includes/raid_attendance.php';
|
||
require_login();
|
||
// Die Leitung (raids.manage) und alle mit raids.create - wer anlegt, wird Raid-Lead
|
||
if (!user_has_permission('raids.manage') && !user_has_permission('raids.create')) {
|
||
http_response_code(403);
|
||
json_response(false, 'Dir fehlt die Berechtigung, Raids zu erstellen.');
|
||
}
|
||
|
||
$input = read_json_body();
|
||
verify_csrf_token($input['csrf_token'] ?? '');
|
||
|
||
// Bereich: Raid der Legion oder des Consilium Elyseum (eigener Kanal, keine Lumipunkte) - nur, wo man ihn sehen darf
|
||
$area = (string) ($input['bereich'] ?? 'legion');
|
||
if (!in_array($area, ['legion', 'consilium'], true) || !raid_area_visible($area)) {
|
||
json_response(false, 'In diesem Bereich kannst du keine Raids anlegen.');
|
||
}
|
||
|
||
$title = trim((string) ($input['title'] ?? ''));
|
||
$dateRaw = trim((string) ($input['date_raw'] ?? ''));
|
||
$requirements = trim((string) ($input['requirements'] ?? ''));
|
||
$groupNames = trim((string) ($input['group_names'] ?? ''));
|
||
[$gearscore, $gearscoreError] = raid_normalize_gearscore((string) ($input['gearscore'] ?? ''));
|
||
|
||
if ($title === '' || $dateRaw === '' || $requirements === '' || $groupNames === '') {
|
||
json_response(false, 'Bitte Titel, Datum, Anforderungen und mindestens eine Gruppe angeben.');
|
||
}
|
||
$groupList = array_values(array_filter(array_map('trim', explode(',', $groupNames)), static fn (string $name): bool => $name !== ''));
|
||
$groupCount = count($groupList);
|
||
$slotsError = raid_slots_error($input['max_slots'] ?? '', $groupCount);
|
||
if ($slotsError !== null) {
|
||
json_response(false, $slotsError);
|
||
}
|
||
$maxSlots = (int) trim((string) $input['max_slots']);
|
||
if ($gearscoreError !== null) {
|
||
json_response(false, $gearscoreError);
|
||
}
|
||
|
||
// Lumipunkte legt nur fest, wer raids.points hat. Sonst: Raids der Leitung fest +1 pro Teilnahme,
|
||
// Raids eines Mitglieds als Raid-Lead keine (die Leitung kann sie nachtraeglich einstellen).
|
||
[$pointsPresent, $pointsAbsent] = raid_points_defaults_for_creator();
|
||
if ($area === 'consilium') {
|
||
[$pointsPresent, $pointsAbsent] = [0, 0]; // Consilium-Raids bringen keine Lumipunkte
|
||
} elseif (user_has_permission('raids.points')) {
|
||
$pointsPresent = raid_points_input($input['points_present'] ?? RAID_POINTS_DEFAULT_PRESENT);
|
||
$pointsAbsent = raid_points_input($input['points_absent'] ?? RAID_POINTS_DEFAULT_ABSENT);
|
||
$pointsError = $pointsPresent === null || $pointsAbsent === null
|
||
? 'Lumipunkte: bitte ganze Zahlen von 0 bis ' . RAID_POINTS_MAX . ' angeben.'
|
||
: raid_points_error($pointsPresent, $pointsAbsent);
|
||
if ($pointsError !== null) {
|
||
json_response(false, $pointsError);
|
||
}
|
||
}
|
||
|
||
// Feste Premades, die direkt einer Gruppe zugeordnet werden (Gruppe => Premade-ID).
|
||
$premadeChoices = [];
|
||
foreach ((array) ($input['premades'] ?? []) as $choice) {
|
||
$group = (int) ($choice['group'] ?? 0);
|
||
$premadeId = (int) ($choice['premade_id'] ?? 0);
|
||
if ($premadeId <= 0) {
|
||
continue;
|
||
}
|
||
if ($group < 1 || $group > $groupCount || isset($premadeChoices[$group])) {
|
||
json_response(false, 'Die Zuordnung der Premades zu den Gruppen ist ungültig.');
|
||
}
|
||
if (in_array($premadeId, $premadeChoices, true)) {
|
||
json_response(false, 'Eine Premade kann nur einer Gruppe zugeordnet werden.');
|
||
}
|
||
$premadeChoices[$group] = $premadeId;
|
||
}
|
||
$premadesById = [];
|
||
if (!empty($premadeChoices)) {
|
||
try {
|
||
foreach (fetch_premades() as $premade) {
|
||
$premadesById[(int) ($premade['id'] ?? 0)] = $premade;
|
||
}
|
||
} catch (Throwable $e) {
|
||
json_response(false, 'Die Premades konnten nicht geladen werden: ' . $e->getMessage());
|
||
}
|
||
foreach ($premadeChoices as $group => $premadeId) {
|
||
if (!isset($premadesById[$premadeId])) {
|
||
json_response(false, 'Diese Premade gibt es nicht (mehr) - bitte die Seite neu laden.');
|
||
}
|
||
// Die Gruppe heisst wie die Premade (beim Einladen benennt der Bot sie ohnehin so um).
|
||
$groupList[$group - 1] = trim((string) preg_replace('/\s+/u', ' ', str_replace(',', ' ', (string) ($premadesById[$premadeId]['name'] ?? ''))))
|
||
?: 'Gruppe ' . $group;
|
||
}
|
||
$groupNames = implode(', ', $groupList);
|
||
if (mb_strlen($groupNames, 'UTF-8') > RAID_FIELD_LIMITS['group_names'][1]) {
|
||
// Zu lang fuer die API - Platzhalter schicken, die Einladung setzt den richtigen Namen.
|
||
foreach ($premadeChoices as $group => $premadeId) {
|
||
$groupList[$group - 1] = 'Gruppe ' . $group;
|
||
}
|
||
$groupNames = implode(', ', $groupList);
|
||
}
|
||
}
|
||
|
||
$fieldError = raid_fields_error(['title' => $title, 'requirements' => $requirements, 'gearscore' => $gearscore, 'group_names' => $groupNames]);
|
||
if ($fieldError !== null) {
|
||
json_response(false, $fieldError);
|
||
}
|
||
|
||
$creator = current_user();
|
||
try {
|
||
$result = create_raid([
|
||
'title' => $title,
|
||
'date_raw' => $dateRaw,
|
||
'requirements' => $requirements,
|
||
'group_names' => $groupNames,
|
||
'gearscore' => $gearscore,
|
||
'max_slots' => $maxSlots,
|
||
// Zeigt die Discord-Nachricht an: wer anlegt, ist Raid-Lead - und was es an Lumipunkten gibt (Consilium: nichts)
|
||
'lead_id' => (int) ($creator['discord_id'] ?? 0),
|
||
'lead_name' => (string) (($creator['display_name'] ?? '') !== '' ? $creator['display_name'] : $creator['username']),
|
||
'points_text' => $area === 'consilium' ? '' : raid_points_summary($pointsPresent, $pointsAbsent),
|
||
], $area);
|
||
} catch (Throwable $e) {
|
||
json_response(false, 'Erstellen fehlgeschlagen: ' . $e->getMessage());
|
||
}
|
||
|
||
$newRaidId = (int) ($result['raid_id'] ?? 0);
|
||
// Der eigene Raid ist fuer den, der ihn erstellt hat, nicht "neu" (Seitenleiste, Markierung nach dem Neuladen)
|
||
try {
|
||
raids_mark_seen((int) current_user()['id']);
|
||
} catch (PDOException $e) {
|
||
// Dann steht er eben einmal als neu da.
|
||
}
|
||
// Lumipunkte beim Archivieren und den Raid-Lead kennt die Raid-API nicht - die merkt sich die Website.
|
||
// Auch 0/0 wird gespeichert, damit ein bewusst punktloser Raid nicht den festen Punkt bekommt.
|
||
if ($newRaidId > 0) {
|
||
try {
|
||
raid_settings_save_points($newRaidId, $pointsPresent, $pointsAbsent);
|
||
raid_settings_save_lead($newRaidId, (int) current_user()['id']);
|
||
} catch (PDOException $e) {
|
||
// Raid steht - ohne Eintrag gilt beim Anzeigen der feste Punkt, und er hat keinen Raid-Lead.
|
||
}
|
||
}
|
||
admin_log('⚔️ Raid erstellt', [
|
||
'Raid' => $title,
|
||
'Termin' => $dateRaw,
|
||
'Raid-Lead' => admin_log_user((int) current_user()['id']),
|
||
'Plätze' => $maxSlots,
|
||
'Gruppen' => $groupNames,
|
||
'Gearscore' => $gearscore,
|
||
'Bereich' => $area === 'consilium' ? 'Consilium Elyseum' : '',
|
||
'Lumipunkte' => $area === 'consilium' ? '' : '+' . $pointsPresent . ' anwesend / -' . $pointsAbsent . ' abwesend',
|
||
], 'success');
|
||
|
||
// Premades direkt einladen - Fehler dabei machen den Raid nicht ungueltig.
|
||
$premadeMessages = [];
|
||
foreach ($newRaidId > 0 ? $premadeChoices : [] as $group => $premadeId) {
|
||
$premade = $premadesById[$premadeId];
|
||
$premadeName = (string) ($premade['name'] ?? ('#' . $premadeId));
|
||
try {
|
||
$count = invite_premade($newRaidId, $premadeId, $group);
|
||
admin_log('🤝 Premade zum Raid eingeladen', [
|
||
'Raid' => $title,
|
||
'Premade' => $premadeName,
|
||
'Zielgruppe' => 'Gruppe ' . $group . ' – umbenannt und gesperrt',
|
||
'Eingeladen' => $count . ' Mitglied(er) per DM',
|
||
'Mitglieder' => implode(', ', array_map(
|
||
static fn (array $m): string => (string) ($m['name'] ?? admin_log_discord_name((string) ($m['user_id'] ?? ''))),
|
||
array_filter((array) ($premade['members'] ?? []), static fn ($m): bool => ($m['status'] ?? '') === 'accepted')
|
||
)),
|
||
]);
|
||
$premadeMessages[] = '„' . $premadeName . '“: ' . $count . ' Mitglied(er) per DM eingeladen.';
|
||
} catch (Throwable $e) {
|
||
$premadeMessages[] = '„' . $premadeName . '“ konnte nicht eingeladen werden (' . $e->getMessage() . ') - bitte im Bearbeiten-Modus erneut versuchen.';
|
||
}
|
||
}
|
||
|
||
json_response(true, trim('Raid wurde erstellt. ' . implode(' ', $premadeMessages)), ['raid_id' => $result['raid_id'] ?? null]);
|