LuminaWebsite/warehouse.php
Maaxxs 5f25e20900 Kina in the warehouse, Lumipunkte, new logo, versioned assets
Warehouse: Kina (the game currency) can be paid in and out, shown in its own
box with the in-game coin icon (Icon_Currency_Coin_GoldNonbinding from the
game client via aion2.app, since the wiki has none). It is a catalog item in
the new "Währung" category, kept out of the item cards and totals, and
allows up to a trillion per entry; warehouse_movements.quantity becomes
BIGINT for that. A leftover "Kinah" entry is merged into "Kina".

Beitragspunkte are renamed to Lumipunkte in every visible text, the coin is
now lumipunkt.svg, and the schema sync also updates the descriptions of
existing core permissions so the new name reaches the role editor.

The sidebar, login page and mobile top bar show the new Lumina Ascendens
logo, cropped and with its dark background made transparent.

Scripts and the stylesheet are included with a ?v=<mtime> query
(asset_url()), so browsers pick up new versions after an upload instead of
running stale JavaScript - the cause of raid points not being saved.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 10:25:28 +02:00

344 lines
18 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/warehouse.php';
require_permission('warehouse.view');
$canManage = user_has_permission('warehouse.manage');
warehouse_sync_catalog();
$stock = warehouse_stock();
// Kina steht als eigener Kasten oben, nicht zwischen den Gegenstaenden.
$kinaStmt = db()->prepare("SELECT id, icon FROM warehouse_items WHERE name = ? AND category = 'currency'");
$kinaStmt->execute([WAREHOUSE_KINA]);
$kinaItem = $kinaStmt->fetch() ?: null;
$kinaBalance = $kinaItem ? warehouse_item_stock((int) $kinaItem['id']) : 0;
$itemStock = array_values(array_filter($stock, static fn (array $row): bool => $row['category'] !== 'currency'));
$stockTotal = array_sum(array_map(static fn (array $row): int => (int) $row['quantity'], $itemStock));
// Verlauf, optional nur fuer einen Gegenstand (Klick auf den Namen im Bestand).
$filterItemId = isset($_GET['item']) ? (int) $_GET['item'] : null;
$filterItem = null;
if ($filterItemId !== null) {
$stmt = db()->prepare('SELECT id, name FROM warehouse_items WHERE id = ?');
$stmt->execute([$filterItemId]);
$filterItem = $stmt->fetch() ?: null;
if (!$filterItem) {
$filterItemId = null;
}
}
$perPage = 25;
$totalMovements = warehouse_movement_count($filterItemId);
$pageCount = max(1, (int) ceil($totalMovements / $perPage));
$page = min($pageCount, max(1, (int) ($_GET['page'] ?? 1)));
$movements = warehouse_movements($filterItemId, $perPage, ($page - 1) * $perPage);
// Fuer die Formulare: alle Gegenstaende (Vorschlagsliste) und die Konten der Website.
$allItems = $canManage ? db()->query('SELECT name FROM warehouse_items ORDER BY name')->fetchAll(PDO::FETCH_COLUMN) : [];
$members = $canManage ? db()->query(
"SELECT id, COALESCE(NULLIF(display_name, ''), username) AS name FROM users
WHERE status = 'active' ORDER BY name"
)->fetchAll() : [];
// Eingaben nach einem Fehler wieder ins Formular (siehe warehouse_action.php).
$old = $_SESSION['warehouse_form'] ?? [];
unset($_SESSION['warehouse_form']);
$openForm = (string) ($old['form'] ?? '');
$categoriesInStock = [];
foreach ($itemStock as $row) {
$categoriesInStock[$row['category']] = warehouse_category_label((string) $row['category']);
}
asort($categoriesInStock);
/** Von wem / an wen: Konto oder frei eingetragener Name. */
function warehouse_counterpart(array $movement): string
{
if (!empty($movement['counterpart_user'])) {
return (string) $movement['counterpart_user'];
}
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
{
$selectedUser = (string) ($old['counterpart_user'] ?? '');
?>
<div class="warehouse-counterpart">
<div>
<label for="<?= e($prefix) ?>-user">Mitglied der Website</label>
<select id="<?= e($prefix) ?>-user" name="counterpart_user">
<option value="">– kein Konto / Name eintragen –</option>
<?php foreach ($members as $member): ?>
<option value="<?= (int) $member['id'] ?>" <?= $selectedUser === (string) $member['id'] ? 'selected' : '' ?>><?= e((string) $member['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div>
<label for="<?= e($prefix) ?>-name">oder Name</label>
<input type="text" id="<?= e($prefix) ?>-name" name="counterpart_name" maxlength="100"
value="<?= e((string) ($old['counterpart_name'] ?? '')) ?>" placeholder="z.B. Spielername ohne Website-Konto">
</div>
</div>
<div class="field-hint"><?= $required ? 'Ein Konto auswählen oder einen Namen eintragen.' : 'Optional - leer lassen, wenn es an niemand Bestimmten ging.' ?></div>
<?php
}
$pageTitle = 'Lagerhaus';
$containerWide = true;
include __DIR__ . '/includes/header.php';
?>
<div class="panel">
<div class="warehouse-head">
<div>
<h1>Lagerhaus</h1>
<p class="text-muted">
<?= count($itemStock) ?> verschiedene Gegenstände, <?= number_format($stockTotal, 0, ',', '.') ?> Stück insgesamt.
</p>
</div>
<?php if ($kinaItem): ?>
<div class="warehouse-kina">
<?= warehouse_icon_html($kinaItem['icon'] ?? null, WAREHOUSE_KINA, 44) ?>
<div>
<span class="text-muted">Kina im Lager</span>
<strong><?= number_format($kinaBalance, 0, ',', '.') ?></strong>
</div>
<?php if ($canManage): ?>
<div class="warehouse-kina-actions">
<button type="button" class="button-secondary button-small" data-open-modal="warehouse-in-modal" data-item-name="<?= e(WAREHOUSE_KINA) ?>">+ Einzahlen</button>
<button type="button" class="button-secondary button-small" data-open-modal="warehouse-out-modal" data-item-id="<?= (int) $kinaItem['id'] ?>" <?= $kinaBalance > 0 ? '' : 'disabled' ?>>− Auszahlen</button>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ($canManage): ?>
<div class="actions">
<button type="button" class="button-success" data-open-modal="warehouse-in-modal">+ Einlagern</button>
<button type="button" class="button-secondary" data-open-modal="warehouse-out-modal" <?= empty($stock) ? 'disabled' : '' ?>>− Entnehmen</button>
</div>
<?php endif; ?>
</div>
<div class="warehouse-filters">
<input type="search" id="warehouse-search" placeholder="Gegenstand suchen …" autocomplete="off">
<select id="warehouse-category">
<option value="">Alle Kategorien</option>
<?php foreach ($categoriesInStock as $key => $label): ?>
<option value="<?= e((string) $key) ?>"><?= e($label) ?></option>
<?php endforeach; ?>
</select>
</div>
<?php if (empty($itemStock)): ?>
<p class="text-muted">Keine Gegenstände im Lager.<?= $canManage ? ' Mit „Einlagern“ trägst du den ersten Gegenstand ein.' : '' ?></p>
<?php else: ?>
<div class="warehouse-grid" id="warehouse-stock">
<?php foreach ($itemStock as $row): ?>
<div class="warehouse-card" data-name="<?= e(mb_strtolower((string) $row['name'])) ?>" data-category="<?= e((string) $row['category']) ?>">
<a class="warehouse-card-link" href="/warehouse.php?item=<?= (int) $row['id'] ?>#verlauf"
title="<?= e((string) $row['name']) ?> - zuletzt bewegt <?= e(warehouse_format_time($row['last_movement'])) ?>. Klicken für den Verlauf.">
<span class="warehouse-card-image">
<?= warehouse_icon_html($row['icon'] ?? null, (string) $row['name'], 72) ?>
<span class="warehouse-card-qty"><?= number_format((int) $row['quantity'], 0, ',', '.') ?></span>
</span>
<span class="warehouse-card-name"><?= e((string) $row['name']) ?></span>
<span class="warehouse-card-category"><?= e(warehouse_category_label((string) $row['category'])) ?></span>
</a>
<?php if ($canManage): ?>
<div class="warehouse-card-actions">
<button type="button" class="icon-button" title="Entnehmen" aria-label="Entnehmen"
data-open-modal="warehouse-out-modal" data-item-id="<?= (int) $row['id'] ?>">−</button>
<button type="button" class="icon-button" title="Mehr einlagern" aria-label="Mehr einlagern"
data-open-modal="warehouse-in-modal" data-item-name="<?= e((string) $row['name']) ?>">+</button>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<p class="text-muted warehouse-no-match" id="warehouse-no-match" hidden>Kein Gegenstand passt zur Suche.</p>
<?php endif; ?>
</div>
<div class="panel" id="verlauf">
<div class="warehouse-head">
<h2>Verlauf<?= $filterItem ? ': ' . e((string) $filterItem['name']) : '' ?></h2>
<?php if ($filterItem): ?>
<a href="/warehouse.php#verlauf">Alle Gegenstände anzeigen</a>
<?php endif; ?>
</div>
<?php if (empty($movements)): ?>
<p class="text-muted">Noch keine Einträge.</p>
<?php else: ?>
<div class="table-scroll">
<table class="table-actions">
<thead>
<tr>
<th>Zeitpunkt</th>
<th>Art</th>
<th>Gegenstand</th>
<th class="num">Menge</th>
<th>Von / An</th>
<th>Bemerkung</th>
<th>Eingetragen von</th>
<th><?= $canManage ? 'Aktionen' : '' ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($movements as $movement): ?>
<?php $isIn = $movement['direction'] === 'in'; ?>
<tr>
<td><?= e(warehouse_format_time($movement['occurred_at'])) ?></td>
<td><span class="badge <?= $isIn ? 'badge-active' : 'badge-disabled' ?>"><?= $isIn ? 'Eingelagert' : 'Entnommen' ?></span></td>
<td>
<a class="warehouse-item-inline" href="/warehouse.php?item=<?= (int) $movement['item_id'] ?>#verlauf">
<?= warehouse_icon_html($movement['icon'] ?? null, (string) $movement['item_name'], 32) ?>
<span><?= e((string) $movement['item_name']) ?></span>
</a>
</td>
<td class="num"><?= $isIn ? '+' : '−' ?><?= number_format((int) $movement['quantity'], 0, ',', '.') ?></td>
<td>
<?php $who = warehouse_counterpart($movement); ?>
<?php if ($who !== ''): ?>
<span class="text-muted"><?= $isIn ? 'von' : 'an' ?></span> <?= e($who) ?>
<?php else: ?>
<span class="text-muted">-</span>
<?php endif; ?>
</td>
<td><?= e((string) ($movement['note'] ?? '')) ?></td>
<td><?= e((string) ($movement['author'] ?? '-')) ?></td>
<td>
<?php if ($canManage): ?>
<form class="inline-form" method="post" action="/warehouse_action.php"
onsubmit="return confirm('Diesen Eintrag löschen? Der Bestand wird entsprechend angepasst.');">
<?= csrf_field() ?>
<input type="hidden" name="action" value="delete">
<input type="hidden" name="movement_id" value="<?= (int) $movement['id'] ?>">
<button type="submit" class="icon-button icon-button-danger" title="Eintrag löschen" aria-label="Eintrag löschen"><?= icon('trash') ?></button>
</form>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<div class="warehouse-pages">
<span class="text-muted">
Einträge <?= ($page - 1) * $perPage + 1 ?>–<?= min($page * $perPage, $totalMovements) ?>
von <?= number_format($totalMovements, 0, ',', '.') ?>
</span>
<?php render_pagination('/warehouse.php?' . ($filterItemId !== null ? 'item=' . $filterItemId . '&' : ''), $page, $pageCount, '#verlauf'); ?>
</div>
<?php endif; ?>
</div>
<?php if ($canManage): ?>
<?php $oldIn = $openForm === 'in' ? $old : []; $oldOut = $openForm === 'out' ? $old : []; ?>
<!-- Einlagern -->
<div class="modal-overlay" id="warehouse-in-modal" <?= $openForm === 'in' ? '' : 'hidden' ?>>
<div class="modal">
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
<h2>Einlagern</h2>
<form method="post" action="/warehouse_action.php">
<?= csrf_field() ?>
<input type="hidden" name="action" value="deposit">
<div>
<label for="in-item">Gegenstand</label>
<input type="text" id="in-item" name="item" list="warehouse-item-list" required autocomplete="off"
value="<?= e((string) ($oldIn['item'] ?? '')) ?>" placeholder="Namen eintippen, Vorschläge erscheinen">
<datalist id="warehouse-item-list">
<?php foreach ($allItems as $name): ?>
<option value="<?= e((string) $name) ?>">
<?php endforeach; ?>
</datalist>
</div>
<?php if (!empty($oldIn['unknown_item'])): ?>
<div class="warehouse-new-item">
<label>
<input type="checkbox" name="create_item" value="1" checked>
„<?= e((string) $oldIn['item']) ?>“ als neuen Gegenstand anlegen
</label>
<select name="create_category">
<?php foreach (WAREHOUSE_CUSTOM_CATEGORIES as $key): ?>
<option value="<?= e($key) ?>" <?= ($oldIn['create_category'] ?? 'material') === $key ? 'selected' : '' ?>><?= e(warehouse_category_label($key)) ?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
<div class="warehouse-row">
<div>
<label for="in-quantity">Anzahl</label>
<input type="number" id="in-quantity" name="quantity" min="1" max="<?= WAREHOUSE_MAX_CURRENCY ?>" required
value="<?= e((string) ($oldIn['quantity'] ?? '1')) ?>">
</div>
<div>
<label for="in-time">Überreicht am</label>
<input type="datetime-local" id="in-time" name="occurred_at" required
value="<?= e((string) ($oldIn['occurred_at'] ?? warehouse_now_input())) ?>">
</div>
</div>
<label>Überreicht von</label>
<?php warehouse_render_counterpart('in', $members, $oldIn, true); ?>
<div>
<label for="in-note">Bemerkung <span class="text-muted">(optional)</span></label>
<input type="text" id="in-note" name="note" maxlength="255" value="<?= e((string) ($oldIn['note'] ?? '')) ?>">
</div>
<div class="actions">
<button type="submit" class="button-success">Einlagern</button>
</div>
</form>
</div>
</div>
<!-- Entnehmen -->
<div class="modal-overlay" id="warehouse-out-modal" <?= $openForm === 'out' ? '' : 'hidden' ?>>
<div class="modal">
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
<h2>Entnehmen</h2>
<form method="post" action="/warehouse_action.php">
<?= csrf_field() ?>
<input type="hidden" name="action" value="withdraw">
<div>
<label for="out-item">Gegenstand</label>
<select id="out-item" name="item_id" required>
<option value="">– aus dem Bestand wählen –</option>
<?php foreach ($stock as $row): ?>
<option value="<?= (int) $row['id'] ?>" data-max="<?= (int) $row['quantity'] ?>"
<?= (string) ($oldOut['item_id'] ?? '') === (string) $row['id'] ? 'selected' : '' ?>>
<?= e((string) $row['name']) ?> (<?= number_format((int) $row['quantity'], 0, ',', '.') ?> auf Lager)
</option>
<?php endforeach; ?>
</select>
</div>
<div class="warehouse-row">
<div>
<label for="out-quantity">Anzahl</label>
<input type="number" id="out-quantity" name="quantity" min="1" required
value="<?= e((string) ($oldOut['quantity'] ?? '1')) ?>">
</div>
<div>
<label for="out-time">Entnommen am</label>
<input type="datetime-local" id="out-time" name="occurred_at" required
value="<?= e((string) ($oldOut['occurred_at'] ?? warehouse_now_input())) ?>">
</div>
</div>
<label>Überreicht an <span class="text-muted">(optional)</span></label>
<?php warehouse_render_counterpart('out', $members, $oldOut, false); ?>
<div>
<label for="out-note">Bemerkung <span class="text-muted">(optional)</span></label>
<input type="text" id="out-note" name="note" maxlength="255" value="<?= e((string) ($oldOut['note'] ?? '')) ?>">
</div>
<div class="actions">
<button type="submit">Entnehmen</button>
</div>
</form>
</div>
</div>
<?php endif; ?>
<script src="<?= e(asset_url('/assets/js/warehouse.js')) ?>"></script>
<?php include __DIR__ . '/includes/footer.php'; ?>