LuminaWebsite/member_edit.php

392 lines
25 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/professions.php';
require_once __DIR__ . '/includes/armory.php';
require_permission('members.view');
$id = (int) ($_GET['id'] ?? current_user()['id']);
if (!profile_can_edit($id)) {
set_flash('error', 'Du darfst nur deine eigene Profilseite bearbeiten.');
redirect('/member.php?id=' . $id);
}
$stmt = db()->prepare("SELECT id, username, display_name, profile_bio, profile_background, gallery_comments_enabled, status FROM users WHERE id = ?");
$stmt->execute([$id]);
$member = $stmt->fetch();
if (!$member) {
redirect('/members.php');
}
$name = $member['display_name'] !== '' ? $member['display_name'] : $member['username'];
$isOwn = (int) current_user()['id'] === $id;
$characters = profile_characters_by_user($id)[$id] ?? [];
$characterProfessions = professions_for_characters(array_column($characters, 'id'));
foreach ($characters as &$character) {
$character['professions'] = $characterProfessions[(int) $character['id']] ?? [];
}
unset($character);
$wantedProfessions = professions_wanted();
$galleryStmt = db()->prepare('SELECT * FROM member_gallery WHERE user_id = ? AND is_background = 0 ORDER BY sort_order, id');
$galleryStmt->execute([$id]);
$gallery = $galleryStmt->fetchAll();
/** Felder eines Charakters (fuer "neu" und "bearbeiten" gleich). */
function character_fields(array $c, string $prefix): void
{
?>
<div class="character-form-grid">
<div>
<label for="<?= $prefix ?>-name">Name</label>
<input type="text" id="<?= $prefix ?>-name" name="name" maxlength="60" required value="<?= e((string) ($c['name'] ?? '')) ?>" placeholder="z.B. Damaskar">
</div>
<div>
<label for="<?= $prefix ?>-class">Klasse</label>
<select id="<?= $prefix ?>-class" name="class_name">
<option value="">– wählen –</option>
<?php foreach (AION_CLASSES as $class): ?>
<option value="<?= e($class) ?>"<?= ($c['class_name'] ?? '') === $class ? ' selected' : '' ?>><?= e($class) ?></option>
<?php endforeach; ?>
</select>
</div>
<div>
<label for="<?= $prefix ?>-level">Stufe (optional)</label>
<input type="number" id="<?= $prefix ?>-level" name="level" min="1" max="<?= PROFILE_MAX_LEVEL ?>" value="<?= e((string) ($c['level'] ?? '')) ?>">
</div>
<div>
<label for="<?= $prefix ?>-legion">Legion im Spiel</label>
<select id="<?= $prefix ?>-legion" name="legion">
<option value="">– noch nicht zugeordnet –</option>
<?php foreach (LEGION_UNITS as $key => $label): ?>
<option value="<?= e($key) ?>"<?= ($c['legion'] ?? '') === $key ? ' selected' : '' ?>><?= e($label) ?></option>
<?php endforeach; ?>
</select>
</div>
<label class="character-main-toggle">
<input type="checkbox" name="is_main" value="1"<?= !empty($c['is_main']) ? ' checked' : '' ?>> Hauptcharakter
</label>
</div>
<?php
$aionData = armory_data($c);
$aionServer = (int) ($c['aion_server_id'] ?? 0) ?: ARMORY_DEFAULT_SERVER;
?>
<fieldset class="armory-link" data-armory-link>
<legend>Charakter im Spiel <span class="text-muted">(optional)</span></legend>
<input type="hidden" name="aion_char_id" value="<?= e((string) ($c['aion_char_id'] ?? '')) ?>" data-armory-id>
<input type="hidden" name="aion_server_id" value="<?= !empty($c['aion_char_id']) ? (int) $c['aion_server_id'] : '' ?>" data-armory-server-id>
<div class="armory-link-current"<?= empty($c['aion_char_id']) ? ' hidden' : '' ?> data-armory-current>
<span>Verknüpft mit <strong data-armory-current-name><?= e((string) ($aionData['name'] ?? $c['name'] ?? '')) ?></strong>
<span class="text-muted" data-armory-current-server><?= !empty($c['aion_char_id']) ? '· ' . e(armory_server_name((int) $c['aion_server_id'])) : '' ?></span></span>
<button type="button" class="armory-text-button" data-armory-unlink>Verknüpfung lösen</button>
</div>
<div class="armory-link-search">
<select aria-label="Server" data-armory-server>
<?php foreach (ARMORY_SERVERS as $serverId => $serverName): ?>
<option value="<?= $serverId ?>"<?= $serverId === $aionServer ? ' selected' : '' ?>><?= e($serverName) ?></option>
<?php endforeach; ?>
</select>
<input type="search" maxlength="30" placeholder="Name im Spiel" aria-label="Name im Spiel" data-armory-name>
<button type="button" class="button-secondary" data-armory-search>Suchen</button>
</div>
<ul class="armory-link-results" hidden data-armory-results></ul>
<div class="field-hint">
Verknüpfst du den Charakter, zeigt deine Profilseite seine Ausrüstung, Kampfkraft und Werte live aus dem Spiel
(nur für eingeloggte Mitglieder). Name, Klasse und Stufe werden dann aus dem Spiel übernommen. Speichern nicht vergessen.
</div>
</fieldset>
<div>
<label for="<?= $prefix ?>-note">Kurzbeschreibung (optional)</label>
<input type="text" id="<?= $prefix ?>-note" name="note" maxlength="255" value="<?= e((string) ($c['note'] ?? '')) ?>" placeholder="z.B. Main für Raids, Twink zum Farmen">
</div>
<?php $gathering = gathering_parse($c['gathering'] ?? null); ?>
<fieldset class="character-professions">
<legend>Berufe <span class="text-muted">(optional)</span></legend>
<div class="profession-rows">
<?php foreach (PROFESSIONS as $key => $profession): ?>
<?php $entry = $c['professions'][$key] ?? null; ?>
<div class="profession-row<?= $entry ? ' is-set' : '' ?>">
<span class="profession-row-name" title="<?= e($profession['en'] . ' – stellt her: ' . $profession['makes']) ?>">
<span aria-hidden="true"><?= $profession['icon'] ?></span> <?= e($profession['label']) ?>
</span>
<select name="profession_stage[<?= $key ?>]" aria-label="<?= e($profession['label']) ?>: Stufe" data-profession-stage>
<option value="0">– nicht –</option>
<?php foreach (PROFESSION_STAGES as $stage => $stageLabel): ?>
<option value="<?= $stage ?>"<?= $entry && $entry['stage'] === $stage ? ' selected' : '' ?>><?= e($stageLabel) ?></option>
<?php endforeach; ?>
</select>
<input type="number" name="profession_level[<?= $key ?>]" min="1" max="<?= PROFESSION_LEVEL_MAX ?>" value="<?= $entry && $entry['level'] !== null ? (int) $entry['level'] : '' ?>"
placeholder="Level" aria-label="<?= e($profession['label']) ?>: Level (optional)">
<label class="profession-main-toggle" title="Der Beruf, auf den sich dieser Charakter konzentriert">
<input type="checkbox" name="main_profession[]" value="<?= $key ?>"<?= $entry && $entry['main'] ? ' checked' : '' ?> data-profession-main> Hauptberuf
</label>
</div>
<?php endforeach; ?>
</div>
<div class="field-hint">
Stufe und Level stehen im Spiel beim Beruf (Anfänger bis Level 50, danach Fortgeschritten, später Meister).
Der Hauptberuf ist der, auf den sich dieser Charakter konzentriert – nach ihm richtet sich die Übersicht <a href="/professions.php">Berufe</a>.
</div>
<div class="profession-gathering">
<span class="profession-gathering-label">Sammeln – spezialisiert auf:</span>
<?php foreach (GATHERING_MATERIALS as $key => $material): ?>
<label class="profession-gathering-option">
<input type="checkbox" name="gathering[]" value="<?= $key ?>"<?= in_array($key, $gathering, true) ? ' checked' : '' ?>>
<span aria-hidden="true"><?= $material['icon'] ?></span> <?= e($material['label']) ?>
</label>
<?php endforeach; ?>
</div>
</fieldset>
<div class="character-form-grid">
<div>
<label for="<?= $prefix ?>-portrait">Portrait</label>
<?php if (!empty($c['portrait_filename'])): ?>
<div class="character-current-image">
<img src="<?= e(profile_image_url($c['portrait_filename'])) ?>" alt="">
<label><input type="checkbox" name="remove_portrait" value="1"> entfernen</label>
</div>
<?php endif; ?>
<input type="file" id="<?= $prefix ?>-portrait" name="portrait" accept="image/png,image/jpeg,image/gif,image/webp" data-max-size="600">
<div class="field-hint">Am besten ein quadratischer Ausschnitt des Gesichts.</div>
</div>
<div>
<label for="<?= $prefix ?>-image">Bild</label>
<?php if (!empty($c['image_filename'])): ?>
<div class="character-current-image">
<img src="<?= e(profile_image_url($c['image_filename'])) ?>" alt="">
<label><input type="checkbox" name="remove_image" value="1"> entfernen</label>
</div>
<?php endif; ?>
<input type="file" id="<?= $prefix ?>-image" name="image" accept="image/png,image/jpeg,image/gif,image/webp" data-max-size="1600">
<div class="field-hint">Z.B. ein Screenshot des ganzen Charakters in seiner Rüstung.</div>
</div>
</div>
<?php
}
$pageTitle = 'Profilseite bearbeiten';
include __DIR__ . '/includes/header.php';
?>
<div class="panel">
<div class="raid-header">
<h1><?= $isOwn ? 'Meine Profilseite' : 'Profilseite von ' . e($name) ?></h1>
<a class="button button-secondary" href="/member.php?id=<?= $id ?>">Ansehen</a>
</div>
<p class="text-muted">Alles hier sehen die anderen Mitglieder der Legion auf deiner Profilseite.</p>
</div>
<form class="panel" method="post" action="/member_action.php">
<?= csrf_field() ?>
<input type="hidden" name="action" value="bio_save">
<input type="hidden" name="user_id" value="<?= $id ?>">
<h2>Über mich</h2>
<textarea name="profile_bio" rows="8" maxlength="<?= PROFILE_MAX_BIO ?>" placeholder="Erzähl etwas über dich: Wie lange spielst du schon Aion? Was machst du am liebsten im Spiel? Wann bist du meistens online?"><?= e((string) $member['profile_bio']) ?></textarea>
<div class="field-hint">Formatierung: <code>**fett**</code>, <code>*kursiv*</code>, <code>- Liste</code>, <code>## Überschrift</code>, <code>[Link](https://…)</code>.</div>
<div class="actions"><button type="submit">Speichern</button></div>
</form>
<div class="panel" id="charaktere">
<h2>Charaktere</h2>
<p class="text-muted">Bei jedem Charakter kannst du auch seine Berufe eintragen – so sieht die Legion, wer was herstellen kann.</p>
<?= professions_wanted_html($wantedProfessions) ?>
<?php foreach ($characters as $character): ?>
<details class="character-edit">
<summary>
<?= class_badge_html($character['class_name'], 22) ?>
<strong><?= e($character['name']) ?></strong>
<span class="text-muted"><?= e($character['class_name'] ?? '') ?><?= $character['level'] ? ' · Stufe ' . (int) $character['level'] : '' ?></span>
<?php if ($character['is_main']): ?><span class="badge badge-pending">Hauptcharakter</span><?php endif; ?>
<?php foreach ($character['professions'] as $key => $entry): ?><?= profession_badge_html($key, $entry, true) ?><?php endforeach; ?>
<span class="character-edit-hint">bearbeiten ▾</span>
</summary>
<form method="post" action="/member_action.php" enctype="multipart/form-data">
<?= csrf_field() ?>
<input type="hidden" name="action" value="character_save">
<input type="hidden" name="user_id" value="<?= $id ?>">
<input type="hidden" name="character_id" value="<?= (int) $character['id'] ?>">
<?php character_fields($character, 'c' . (int) $character['id']); ?>
<div class="actions">
<button type="submit">Speichern</button>
<button type="submit" name="action" value="character_delete" class="button-danger"
data-confirm="<?= e($character['name'] . ' wirklich löschen?') ?>" data-confirm-title="Charakter löschen" data-confirm-danger data-confirm-ok="Löschen">Löschen</button>
</div>
</form>
</details>
<?php endforeach; ?>
<?php if (count($characters) < PROFILE_MAX_CHARACTERS): ?>
<details class="character-edit character-new"<?= empty($characters) ? ' open' : '' ?>>
<summary><strong>+ Charakter hinzufügen</strong></summary>
<form method="post" action="/member_action.php" enctype="multipart/form-data">
<?= csrf_field() ?>
<input type="hidden" name="action" value="character_save">
<input type="hidden" name="user_id" value="<?= $id ?>">
<input type="hidden" name="character_id" value="0">
<?php character_fields(['is_main' => empty($characters)], 'new'); ?>
<div class="actions"><button type="submit">Charakter anlegen</button></div>
</form>
</details>
<?php else: ?>
<p class="text-muted">Mehr als <?= PROFILE_MAX_CHARACTERS ?> Charaktere gehen nicht.</p>
<?php endif; ?>
</div>
<div class="panel" id="galerie">
<h2>Galerie</h2>
<form class="settings-toggle" method="post" action="/member_action.php">
<?= csrf_field() ?>
<input type="hidden" name="action" value="gallery_comments_toggle">
<input type="hidden" name="user_id" value="<?= $id ?>">
<label>
<input type="checkbox" name="enabled" value="1" <?= !empty($member['gallery_comments_enabled']) ? 'checked' : '' ?> onchange="this.form.submit()">
Andere Mitglieder dürfen meine Bilder kommentieren und mit Emojis reagieren
</label>
<noscript><button type="submit" class="button-secondary button-small">Speichern</button></noscript>
</form>
<?php if (count($gallery) < PROFILE_MAX_GALLERY): ?>
<form method="post" action="/member_action.php" enctype="multipart/form-data" class="gallery-upload">
<?= csrf_field() ?>
<input type="hidden" name="action" value="gallery_upload">
<input type="hidden" name="user_id" value="<?= $id ?>">
<input type="file" name="images[]" accept="image/png,image/jpeg,image/gif,image/webp" multiple required data-max-size="1920" data-paste>
<input type="text" name="caption" maxlength="150" placeholder="Bildunterschrift (optional)">
<button type="submit">Hochladen</button>
</form>
<div class="field-hint">Screenshots, Erinnerungen an Raids, lustige Momente … bis zu <?= PROFILE_MAX_GALLERY ?> Bilder, je höchstens 8 MB. Mehrere auf einmal auswählen geht auch.</div>
<?php else: ?>
<p class="text-muted">Die Galerie ist voll (<?= PROFILE_MAX_GALLERY ?> Bilder). Lösch ein altes Bild, um ein neues hochzuladen.</p>
<?php endif; ?>
<?php // Bilder fuer die oeffentliche Startseite (index.php) waehlt die Leitung in der Galerie aus (Recht site.homepage) ?>
<?php if ($isOwn): ?>
<p class="field-hint">
Die Legionsleitung kann einzelne Bilder für die öffentliche Startseite auswählen - dort erscheinen sie ohne deinen
Namen und ohne Bildunterschrift und sind hier mit „Startseite“ markiert. Möchtest du das für ein Bild nicht, sag der Leitung Bescheid.
</p>
<?php elseif (user_has_permission('site.homepage')): ?>
<p class="field-hint">Bilder für die Startseite wählst du in der <a href="/gallery.php?mitglied=<?= $id ?>">Galerie</a> aus.</p>
<?php endif; ?>
<?php if (!empty($gallery)): ?>
<div class="gallery-grid gallery-edit-grid">
<?php foreach ($gallery as $picture): ?>
<figure class="gallery-item<?= ($picture['status'] ?? 'visible') === 'pending' ? ' is-pending' : '' ?>">
<?php if (($picture['status'] ?? 'visible') === 'pending'): ?>
<span class="pending-badge" title="<?= e((string) $picture['moderation_note']) ?>">Wartet auf Freigabe</span>
<?php endif; ?>
<?php if (!empty($picture['show_on_home'])): ?>
<span class="gallery-home-badge" title="Die Legionsleitung zeigt dieses Bild auf der öffentlichen Startseite (ohne Namen)"><?= icon('home') ?> Startseite</span>
<?php endif; ?>
<img src="<?= e(profile_image_url($picture['filename'])) ?>" alt="" loading="lazy">
<form method="post" action="/member_action.php" class="gallery-item-form">
<?= csrf_field() ?>
<input type="hidden" name="user_id" value="<?= $id ?>">
<input type="hidden" name="picture_id" value="<?= (int) $picture['id'] ?>">
<input type="text" name="caption" maxlength="150" value="<?= e((string) $picture['caption']) ?>" placeholder="Bildunterschrift">
<div class="gallery-item-actions">
<button type="submit" name="action" value="gallery_update" class="button-small button-secondary">Speichern</button>
<button type="submit" name="action" value="gallery_delete" class="icon-button icon-button-danger" title="Löschen"
data-confirm="Dieses Bild löschen?" data-confirm-title="Bild löschen" data-confirm-danger data-confirm-ok="Löschen"><?= icon('trash') ?></button>
</div>
</form>
</figure>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<script src="<?= e(asset_url('/assets/js/image-resize.js')) ?>"></script>
<script src="<?= e(asset_url('/assets/js/armory.js')) ?>" defer></script>
<?php
$currentBackground = (string) ($member['profile_background'] ?? '');
$backgroundPictures = array_values(array_filter($gallery, static fn (array $p): bool => ($p['status'] ?? 'visible') === 'visible'));
// Eigenes Bild, das nur als Hintergrund hochgeladen wurde (nicht in der Galerie)
$ownBackground = profile_background_image($id);
?>
<div class="panel" id="hintergrund">
<h2>Hintergrund der Profilseite</h2>
<p class="text-muted">Gib deiner Profilseite deine persönliche Note: eine der Landschaften, ein Bild aus deiner Galerie oder ein eigenes Bild nur für den Hintergrund.</p>
<form method="post" action="/member_action.php" class="background-picker">
<?= csrf_field() ?>
<input type="hidden" name="action" value="background_save">
<input type="hidden" name="user_id" value="<?= $id ?>">
<div class="background-grid">
<label class="background-option background-default<?= $currentBackground === '' ? ' is-selected' : '' ?>">
<input type="radio" name="background" value="" <?= $currentBackground === '' ? 'checked' : '' ?>>
<span class="background-thumb"><img src="/assets/images/Landscapes/web/thumbs/landscape9-thumb.jpg" alt="" loading="lazy"></span>
<span class="background-name">Standard</span>
</label>
<?php foreach (PROFILE_BACKGROUND_PRESETS as $index => $preset): ?>
<?php $value = 'preset:' . $preset; ?>
<label class="background-option<?= $currentBackground === $value ? ' is-selected' : '' ?>">
<input type="radio" name="background" value="<?= e($value) ?>" <?= $currentBackground === $value ? 'checked' : '' ?>>
<span class="background-thumb"><img src="/assets/images/Landscapes/web/thumbs/<?= e($preset) ?>-thumb.jpg" alt="" loading="lazy"></span>
<span class="background-name">Landschaft <?= $index + 1 ?></span>
</label>
<?php endforeach; ?>
<?php if ($ownBackground): ?>
<?php $value = 'gallery:' . (int) $ownBackground['id']; $ownPending = $ownBackground['status'] === 'pending'; ?>
<label class="background-option background-own<?= $currentBackground === $value ? ' is-selected' : '' ?>">
<input type="radio" name="background" value="<?= e($value) ?>" <?= $currentBackground === $value ? 'checked' : '' ?>>
<span class="background-thumb">
<img src="<?= e(profile_image_url($ownBackground['filename'])) ?>" alt="" loading="lazy">
<?php if ($ownPending): ?><span class="background-pending" title="<?= e((string) $ownBackground['moderation_note']) ?>">Wartet auf Freigabe</span><?php endif; ?>
</span>
<span class="background-name">Eigenes Hintergrundbild</span>
</label>
<?php endif; ?>
<?php foreach ($backgroundPictures as $picture): ?>
<?php $value = 'gallery:' . (int) $picture['id']; ?>
<label class="background-option<?= $currentBackground === $value ? ' is-selected' : '' ?>">
<input type="radio" name="background" value="<?= e($value) ?>" <?= $currentBackground === $value ? 'checked' : '' ?>>
<span class="background-thumb"><img src="<?= e(profile_image_url($picture['filename'])) ?>" alt="" loading="lazy"></span>
<span class="background-name"><?= e($picture['caption'] ?: 'Eigenes Bild') ?></span>
</label>
<?php endforeach; ?>
</div>
<div class="actions"><button type="submit">Hintergrund speichern</button></div>
</form>
<div class="background-upload">
<h3><?= $ownBackground ? 'Anderes eigenes Hintergrundbild' : 'Eigenes Bild als Hintergrund' ?></h3>
<form method="post" action="/member_action.php" enctype="multipart/form-data" class="background-upload-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="background_upload">
<input type="hidden" name="user_id" value="<?= $id ?>">
<input type="file" name="background_image" accept="image/png,image/jpeg,image/gif,image/webp" required data-max-size="2560" data-paste>
<button type="submit">Hochladen &amp; als Hintergrund setzen</button>
</form>
<div class="field-hint">
Kommt nicht in deine Galerie. Am besten ein Querformat-Bild (z.B. ein Screenshot), höchstens 8 MB.
<?= $ownBackground ? 'Ersetzt dein bisheriges eigenes Hintergrundbild.' : '' ?>
</div>
<?php if ($ownBackground): ?>
<form method="post" action="/member_action.php" class="inline-form" data-confirm="Eigenes Hintergrundbild löschen?" data-confirm-title="Hintergrundbild löschen" data-confirm-danger data-confirm-ok="Löschen">
<?= csrf_field() ?>
<input type="hidden" name="action" value="background_delete">
<input type="hidden" name="user_id" value="<?= $id ?>">
<button type="submit" class="button-secondary button-small"><?= icon('trash') ?> Eigenes Hintergrundbild löschen</button>
</form>
<?php endif; ?>
</div>
</div>
<script>
// Berufe: nur ein Hauptberuf je Charakter; Hauptberuf ohne Stufe wird Anfaenger, "uebe ich nicht aus" nimmt den Haken weg
document.addEventListener('change', function (event) {
var target = event.target;
var row = target.closest('.profession-row');
if (!row) return;
var main = row.querySelector('[data-profession-main]');
var stage = row.querySelector('[data-profession-stage]');
if (target === main && main.checked) {
target.form.querySelectorAll('[data-profession-main]').forEach(function (box) { if (box !== main) box.checked = false; });
if (stage.value === '0') stage.value = '1';
}
if (target === stage && stage.value === '0') main.checked = false;
row.classList.toggle('is-set', stage.value !== '0');
});
// Auswahl sofort sichtbar markieren
document.querySelectorAll('.background-picker input[type="radio"]').forEach(function (radio) {
radio.addEventListener('change', function () {
document.querySelectorAll('.background-option').forEach(function (o) { o.classList.remove('is-selected'); });
radio.closest('.background-option').classList.add('is-selected');
});
});
</script>
<?php include __DIR__ . '/includes/footer.php'; ?>