LuminaWebsite/member.php
2026-09-21 20:45:37 +02:00

127 lines
6.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/member_profile.php';
require_once __DIR__ . '/includes/wiki.php'; // wiki_render() fuer den Beschreibungstext
require_permission('members.view');
$id = (int) ($_GET['id'] ?? 0);
$stmt = db()->prepare(
"SELECT id, username, display_name, class_name, profile_bio, discord_id, discord_username, avatar_filename, status,
COALESCE(discord_joined_at, created_at) AS joined_at, discord_joined_at IS NOT NULL AS joined_discord
FROM users WHERE id = ?"
);
$stmt->execute([$id]);
$member = $stmt->fetch();
if (!$member || $member['status'] !== 'active') {
set_flash('error', 'Dieses Mitglied gibt es nicht (mehr).');
redirect('/members.php');
}
$groupStmt = db()->prepare(
"SELECT COALESCE(NULLIF(r.display_name, ''), r.name) AS name FROM roles r
JOIN user_roles ur ON ur.role_id = r.id WHERE ur.user_id = ? ORDER BY COALESCE(r.roster_order, 999), r.name"
);
$groupStmt->execute([$id]);
$groups = array_column($groupStmt->fetchAll(), 'name');
$characters = profile_characters_by_user($id)[$id] ?? [];
$galleryStmt = db()->prepare('SELECT * FROM member_gallery WHERE user_id = ? ORDER BY sort_order, id');
$galleryStmt->execute([$id]);
$gallery = $galleryStmt->fetchAll();
$name = $member['display_name'] !== '' ? $member['display_name'] : $member['username'];
$canEdit = profile_can_edit($id);
$isOwn = (int) current_user()['id'] === $id;
$pageTitle = $name;
include __DIR__ . '/includes/header.php';
?>
<div class="panel member-profile-head">
<?= avatar_html($member, 96) ?>
<div class="member-profile-info">
<h1><?= e($name) ?> <?= class_badge_html($member['class_name'] ?? null, 32) ?></h1>
<div class="member-profile-meta text-muted">
<?php if (!empty($member['discord_username'])): ?>
<span class="discord-inline"><?= discord_logo(14) ?> <?= e($member['discord_username']) ?></span>
<?php endif; ?>
<span title="<?= $member['joined_discord'] ? 'Beitritt zum Discord-Server der Legion' : 'Konto auf der Website angelegt' ?>">Dabei seit <?= e(date('d.m.Y', strtotime($member['joined_at']))) ?></span>
<?php if (!empty($characters)): ?><span><?= count($characters) ?> <?= count($characters) === 1 ? 'Charakter' : 'Charaktere' ?></span><?php endif; ?>
</div>
<?php if (!empty($groups)): ?>
<div class="member-roles">
<?php foreach ($groups as $group): ?><span class="member-role"><?= e($group) ?></span><?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<div class="member-profile-actions">
<?php if ($canEdit): ?>
<a class="button button-small" href="/member_edit.php?id=<?= $id ?>"><?= icon('edit') ?> <?= $isOwn ? 'Profilseite bearbeiten' : 'Bearbeiten (Leitung)' ?></a>
<?php endif; ?>
<a class="button button-secondary button-small" href="/members.php">Alle Mitglieder</a>
</div>
</div>
<?php if (trim((string) $member['profile_bio']) !== ''): ?>
<div class="panel">
<h2>Über mich</h2>
<div class="wiki-content"><?= wiki_render((string) $member['profile_bio']) ?></div>
</div>
<?php elseif ($isOwn): ?>
<div class="panel member-profile-empty">
<p>Deine Profilseite ist noch leer. Erzähl etwas über dich, zeig deine Charaktere und Screenshots!</p>
<a class="button" href="/member_edit.php?id=<?= $id ?>">Profilseite gestalten</a>
</div>
<?php endif; ?>
<?php if (!empty($characters)): ?>
<div class="panel">
<h2>Charaktere</h2>
<div class="character-grid">
<?php foreach ($characters as $character): ?>
<?php $portrait = profile_image_url($character['portrait_filename']); $image = profile_image_url($character['image_filename']); ?>
<article class="character-card<?= $character['is_main'] ? ' is-main' : '' ?>">
<div class="character-portrait">
<?php if ($portrait): ?>
<a href="<?= e($portrait) ?>" data-lightbox="characters" data-caption="<?= e($character['name'] . ' – Portrait') ?>"><img src="<?= e($portrait) ?>" alt="Portrait von <?= e($character['name']) ?>" loading="lazy"></a>
<?php else: ?>
<span class="character-portrait-empty"><?= class_badge_html($character['class_name'], 56) ?: e(mb_substr($character['name'], 0, 1)) ?></span>
<?php endif; ?>
</div>
<div class="character-info">
<h3><?= e($character['name']) ?> <?= class_badge_html($character['class_name'], 22) ?></h3>
<div class="text-muted">
<?= e($character['class_name'] ?? 'Klasse unbekannt') ?><?= $character['level'] ? ' · Stufe ' . (int) $character['level'] : '' ?>
</div>
<?php if ($character['is_main']): ?><span class="badge badge-pending">Hauptcharakter</span><?php endif; ?>
<?php if (!empty($character['note'])): ?><p><?= e($character['note']) ?></p><?php endif; ?>
</div>
<?php if ($image): ?>
<a class="character-image" href="<?= e($image) ?>" data-lightbox="characters" data-caption="<?= e($character['name']) ?>">
<img src="<?= e($image) ?>" alt="Bild von <?= e($character['name']) ?>" loading="lazy">
</a>
<?php endif; ?>
</article>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<?php if (!empty($gallery)): ?>
<div class="panel">
<h2>Galerie</h2>
<div class="gallery-grid">
<?php foreach ($gallery as $picture): ?>
<?php $url = profile_image_url($picture['filename']); ?>
<figure class="gallery-item">
<a href="<?= e($url) ?>" data-lightbox="gallery" data-caption="<?= e((string) $picture['caption']) ?>">
<img src="<?= e($url) ?>" alt="<?= e($picture['caption'] ?: 'Bild von ' . $name) ?>" loading="lazy">
</a>
<?php if (!empty($picture['caption'])): ?><figcaption><?= e($picture['caption']) ?></figcaption><?php endif; ?>
</figure>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<script src="<?= e(asset_url('/assets/js/lightbox.js')) ?>" defer></script>
<?php include __DIR__ . '/includes/footer.php'; ?>