diff --git a/assets/css/style.css b/assets/css/style.css index 6b21956..a20b011 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -5812,3 +5812,6 @@ html.has-scroll-progress::-webkit-scrollbar { display: none; } .shop-category { width: auto; flex-shrink: 0; border-left: 0; border: 1px solid var(--border); border-radius: 999px; padding: 0.4rem 0.8rem; } .shop-category.active { border-color: var(--gold); } } + +/* Mitglieder-Suchliste (includes/member_picker.php) in Formular-Zeilen */ +.member-picker { flex: 1 1 220px; min-width: 0; } diff --git a/assets/js/warehouse.js b/assets/js/warehouse.js index 0c08a15..fab827e 100644 --- a/assets/js/warehouse.js +++ b/assets/js/warehouse.js @@ -58,9 +58,10 @@ } // Konto oder Name: wer ein Konto waehlt, braucht keinen Namen mehr. + // (Die Mitgliederauswahl ist eine Suchliste - ihr verstecktes Feld meldet Aenderungen per "change".) document.querySelectorAll('.warehouse-counterpart').forEach(function (box) { - var select = box.querySelector('select'); - var name = box.querySelector('input'); + var select = box.querySelector('input[name="counterpart_user"]'); + var name = box.querySelector('input[name="counterpart_name"]'); if (!select || !name) return; var sync = function () { name.disabled = select.value !== ''; diff --git a/includes/bootstrap.php b/includes/bootstrap.php index 62eb913..49362ba 100644 --- a/includes/bootstrap.php +++ b/includes/bootstrap.php @@ -28,6 +28,7 @@ if (session_status() !== PHP_SESSION_ACTIVE) { require_once __DIR__ . '/db.php'; require_once __DIR__ . '/functions.php'; require_once __DIR__ . '/map_links.php'; +require_once __DIR__ . '/member_picker.php'; require_once __DIR__ . '/auth.php'; require_once __DIR__ . '/permissions.php'; require_once __DIR__ . '/schema.php'; diff --git a/includes/member_picker.php b/includes/member_picker.php new file mode 100644 index 0000000..211c32b --- /dev/null +++ b/includes/member_picker.php @@ -0,0 +1,62 @@ +> + */ +function member_picker_rows(): array +{ + return db()->query( + "SELECT u.id, u.discord_id, COALESCE(NULLIF(u.display_name, ''), u.username) AS name, u.avatar_filename, u.class_name, + (SELECT COALESCE(NULLIF(r.display_name, ''), r.name) FROM user_roles ur JOIN roles r ON r.id = ur.role_id + WHERE ur.user_id = u.id ORDER BY COALESCE(r.roster_order, 999), r.name LIMIT 1) AS top_role + FROM users u WHERE u.status = 'active' ORDER BY name" + )->fetchAll(); +} + +/** + * Ein Eintrag fuer die Liste. $idField: welche Spalte als Wert gesendet wird (id oder discord_id). + * + * @return array{id: string, name: string, category: string, icon: ?string, qty: null} + */ +function member_picker_item(array $row, string $idField = 'id'): array +{ + return [ + 'id' => (string) ($row[$idField] ?? ''), + 'name' => (string) ($row['name'] ?? ''), + 'category' => trim((($row['top_role'] ?? '') ?: 'Mitglied') . (!empty($row['class_name']) ? ' · ' . $row['class_name'] : '')), + 'icon' => !empty($row['avatar_filename']) ? '/assets/uploads/avatars/' . rawurlencode((string) $row['avatar_filename']) : null, + 'qty' => null, + ]; +} + +/** + * HTML fuer das Auswahlfeld. + * + * @param array>|null $items aus member_picker_item(); null = Liste mit dieser ID + * steht schon auf der Seite (mehrere Felder teilen sich eine Liste) + * @param array{selected?: string, placeholder?: string, required?: bool, input_id?: string, empty?: string} $options + */ +function member_picker(string $name, string $listId, ?array $items, array $options = []): string +{ + $required = !empty($options['required']); + $inputId = $options['input_id'] ?? $listId . '-search'; + return '
' + . '' + . '' + . '
' + . ($items === null ? '' : ''); +} diff --git a/premades.php b/premades.php index cc2b57f..540f712 100644 --- a/premades.php +++ b/premades.php @@ -30,7 +30,7 @@ $namesByDiscordId = []; $linkedUsersByDiscordId = []; if (!empty($allDiscordIds)) { $placeholders = implode(',', array_fill(0, count($allDiscordIds), '?')); - $stmt = db()->prepare("SELECT id, discord_id, discord_username, display_name, avatar_filename FROM users WHERE discord_id IN ($placeholders)"); + $stmt = db()->prepare("SELECT id, discord_id, discord_username, display_name, avatar_filename, class_name FROM users WHERE discord_id IN ($placeholders)"); $stmt->execute($allDiscordIds); foreach ($stmt->fetchAll() as $row) { $name = $row['display_name'] !== '' ? $row['display_name'] : $row['discord_username']; @@ -253,13 +253,25 @@ include __DIR__ . '/includes/header.php'; - + (string) $discordId, + 'name' => premade_name_for($discordId, $namesByDiscordId, $candidate['name'] ?? null), + 'avatar_filename' => $linked['avatar_filename'] ?? null, + 'class_name' => $candidate['class'] ?? ($linked['class_name'] ?? null), + 'top_role' => 'Premade-Mitglied', + ], 'discord_id'); + }, array_values($accepted)); + ?> + true, + 'input_id' => 'premade-owner-search-' . $premadeId, + 'placeholder' => 'Neue Leitung wählen …', + ]) ?> @@ -323,6 +335,7 @@ include __DIR__ . '/includes/header.php'; + diff --git a/raid_attendance.php b/raid_attendance.php index 274227e..8492f43 100644 --- a/raid_attendance.php +++ b/raid_attendance.php @@ -57,11 +57,8 @@ foreach ($attendance as $discordId => $entry) { } // Zum Nachtragen: Website-Konten mit Discord-Verknuepfung, die noch nicht in der Liste stehen. -$addable = db()->query( - "SELECT discord_id, COALESCE(NULLIF(display_name, ''), username) AS name FROM users - WHERE status = 'active' AND discord_id IS NOT NULL ORDER BY name" -)->fetchAll(); -$addable = array_values(array_filter($addable, static fn (array $u): bool => !isset($rows[(string) $u['discord_id']]))); +$addable = array_values(array_filter(member_picker_rows(), static fn (array $u): bool => + !empty($u['discord_id']) && !isset($rows[(string) $u['discord_id']]))); $title = $raid ? (string) ($raid['title'] ?? 'Raid') : 'Raid'; $timestamp = $raid ? (int) ($raid['timestamp'] ?? 0) : 0; @@ -155,12 +152,10 @@ include __DIR__ . '/includes/header.php';
- + member_picker_item($u, 'discord_id'), $addable), [ + 'input_id' => 'attendance-add', + 'placeholder' => 'Mitglied nachtragen (als anwesend) …', + ]) ?>
@@ -183,4 +178,5 @@ document.querySelectorAll('[data-bulk]').forEach(function (button) { }); }); + diff --git a/warehouse.php b/warehouse.php index f090ccc..760a92e 100644 --- a/warehouse.php +++ b/warehouse.php @@ -70,10 +70,8 @@ $historyItems = db()->query( 'SELECT i.id, i.name, i.category, i.icon FROM warehouse_items i WHERE EXISTS (SELECT 1 FROM warehouse_movements m WHERE m.item_id = i.id) ORDER BY i.name' )->fetchAll(); -$members = $canManage ? db()->query( - "SELECT id, COALESCE(NULLIF(display_name, ''), username) AS name FROM users - WHERE status = 'active' ORDER BY name" -)->fetchAll() : []; +// Konten fuer "Ueberreicht von" / "An" (Suchliste mit Avatar, includes/member_picker.php) +$memberItems = $canManage ? array_map('member_picker_item', member_picker_rows()) : []; // Eingaben nach einem Fehler wieder ins Formular (siehe warehouse_action.php). $old = $_SESSION['warehouse_form'] ?? []; @@ -97,20 +95,21 @@ function warehouse_counterpart(array $movement): string return (string) ($movement['counterpart_name'] ?? ''); } -/** Auswahl "Konto oder Name" fuer beide Formulare. */ -function warehouse_render_counterpart(string $prefix, array $members, array $old, bool $required): void +/** + * Auswahl "Konto oder Name" fuer beide Formulare. Die Mitgliederliste ($items) wird nur beim + * ersten Aufruf ausgegeben, der zweite nutzt sie mit (null). + */ +function warehouse_render_counterpart(string $prefix, ?array $items, array $old, bool $required): void { - $selectedUser = (string) ($old['counterpart_user'] ?? ''); ?>
- + (string) ($old['counterpart_user'] ?? ''), + 'input_id' => $prefix . '-user', + 'placeholder' => 'Mitglied suchen …', + ]) ?>
@@ -363,7 +362,7 @@ include __DIR__ . '/includes/header.php';
- +
@@ -407,7 +406,7 @@ include __DIR__ . '/includes/header.php';
- +