LuminaWebsite/shop.php
Maaxxs 6f8040c397 Menu counts for open reports and moderation, item tooltips in warehouse and Lumishop
- Reports: the menu item shows how many reports are still open (not archived), for everyone with
  reports.view. The reports live in the bot, so the count sits in settings.reports_nav_cache and is
  fetched at most every 2 minutes with a short timeout (reports_nav_open()); the reports page
  refreshes it right away, also after archiving. reports_api_request() takes a timeout.
- Moderation: the menu count now matches the "Freigabe" tab - waiting items plus reported items that
  are still visible (moderation_open_counts(), internal calendar entries only for
  calendar.leadership), with a title like "2 warten auf Freigabe, 1 gemeldet".
- Warehouse and Lumishop cards get an info bubble on mouse hover or keyboard focus (not on touch):
  large image, category, stock, Lumishop price and the last movement in the warehouse; price,
  availability, amount in open requests and whether the own Lumipunkte suffice in the shop. Weapons
  and armour with the same name in the gear catalogue also show grade, level and base stats.
  Content is rendered as a <template> per card (includes/item_tooltip.php), shown and placed by
  assets/js/item-tooltip.js; the old native title on warehouse cards is gone.
- Patch notes and README updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 01:48:08 +02:00

224 lines
12 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/shop.php';
require_once __DIR__ . '/includes/item_tooltip.php';
require_permission('shop.view');
$canManage = user_has_permission('shop.manage');
$userId = (int) current_user()['id'];
$balance = contribution_user_balance($userId);
$reservedPoints = shop_reserved_points($userId);
$spendable = max(0, $balance - $reservedPoints);
$items = shop_items(true);
// Kategorien fuer den Kasten links: Name und Anzahl der Gegenstaende (0 = ohne Kategorie)
$categories = [];
$categoryCounts = [];
foreach ($items as $item) {
$categoryId = (int) ($item['category_id'] ?? 0);
if ($categoryId > 0) {
$categories[$categoryId] = (string) $item['category_name'];
}
$categoryCounts[$categoryId] = ($categoryCounts[$categoryId] ?? 0) + 1;
}
$hasUncategorized = !empty($categoryCounts[0]);
// Waffen und Ruestungen aus dem Gear-Katalog (gleicher Name) bekommen in der Info-Blase ihre Werte
$gearByName = item_tip_gear(array_merge(array_column($items, 'name'), array_filter(array_column($items, 'warehouse_name'))));
/**
* Info-Blase eines Angebots (includes/item_tooltip.php): Preis, Verfuegbarkeit, schon beantragt und ob die
* eigenen Lumipunkte reichen.
*/
function shop_item_tip(array $item, int $spendable, ?array $gear): string
{
$price = (int) $item['price'];
$available = $item['available'];
$lines = [
['Preis', $price > 0 ? contribution_coin(14) . ' ' . e(contribution_format($price)) . ' pro Stück' : 'kostenlos'],
['Verfügbar', e($available === null ? 'unbegrenzt' : ($available > 0 ? number_format($available, 0, ',', '.') : 'ausverkauft'))],
];
if ((int) ($item['reserved'] ?? 0) > 0) {
$lines[] = ['In offenen Anträgen', e(number_format((int) $item['reserved'], 0, ',', '.'))];
}
if ($price > 0) {
$affordable = intdiv($spendable, $price);
$lines[] = $affordable > 0
? ['Deine Lumipunkte reichen für', '<span class="is-ok">' . e(number_format($affordable, 0, ',', '.')) . ' Stück</span>']
: ['Dir fehlen noch', '<span class="is-short">' . contribution_coin(14) . ' ' . e(contribution_format($price - $spendable)) . '</span>'];
}
return item_tip_template([
'name' => (string) $item['name'],
'icon_html' => shop_icon_html($item, 56),
'subtitle' => $item['category_name'] !== null ? (string) $item['category_name'] : 'Lumishop',
'gear' => $gear,
'text' => (string) ($item['description'] ?? ''),
'lines' => $lines,
]);
}
$showCategoryList = count($categories) + ($hasUncategorized ? 1 : 0) > 1;
// Eigene Antraege
$perPage = 10;
$totalOrders = shop_order_count([], $userId);
$pageCount = max(1, (int) ceil($totalOrders / $perPage));
$page = min($pageCount, max(1, (int) ($_GET['page'] ?? 1)));
$myOrders = shop_orders([], $userId, $perPage, ($page - 1) * $perPage);
$pendingCount = $canManage ? shop_pending_count() : 0;
// Eingaben nach einem Fehler (siehe shop_action.php)
$old = $_SESSION['shop_form'] ?? [];
unset($_SESSION['shop_form']);
$pageTitle = 'Lumishop';
$containerWide = true;
include __DIR__ . '/includes/header.php';
?>
<div class="panel contribution-hero shop-hero">
<img class="contribution-hero-coin" src="/assets/images/lumipunkt.svg" alt="" width="72" height="72">
<div class="contribution-hero-text">
<h1>Lumishop</h1>
<p class="text-muted">Tausche deine Lumipunkte gegen Gegenstände aus dem Legionslager. Nach der Bewilligung bekommst du den Gegenstand im Spiel überreicht.</p>
</div>
<div class="contribution-hero-balance" title="Punktestand abzüglich offener Anträge">
<span class="text-muted">Verfügbar</span>
<strong><?= contribution_coin(26) ?> <?= contribution_format($spendable) ?></strong>
<?php if ($reservedPoints > 0): ?>
<span class="text-muted shop-reserved"><?= contribution_format($reservedPoints) ?> in offenen Anträgen vorgemerkt</span>
<?php endif; ?>
</div>
<?php if ($canManage): ?>
<div class="shop-hero-actions">
<a class="button" href="/shop_orders.php">Anträge<?php if ($pendingCount > 0): ?> <span class="shop-count"><?= $pendingCount ?></span><?php endif; ?></a>
<a class="button button-secondary" href="/shop_manage.php">Shop verwalten</a>
</div>
<?php endif; ?>
</div>
<div class="shop-layout<?= $showCategoryList ? '' : ' shop-layout-single' ?>">
<?php if ($showCategoryList): ?>
<aside class="panel shop-categories" aria-label="Kategorien">
<h2><?= icon('list') ?> Kategorien</h2>
<div class="shop-category-list" id="shop-category" role="group">
<button type="button" class="shop-category active" data-value="" aria-pressed="true">
<span>Alle</span><span class="shop-category-count"><?= count($items) ?></span>
</button>
<?php foreach ($categories as $id => $name): ?>
<button type="button" class="shop-category" data-value="<?= (int) $id ?>" aria-pressed="false">
<span><?= e($name) ?></span><span class="shop-category-count"><?= (int) ($categoryCounts[$id] ?? 0) ?></span>
</button>
<?php endforeach; ?>
<?php if ($hasUncategorized): ?>
<button type="button" class="shop-category" data-value="0" aria-pressed="false">
<span>Ohne Kategorie</span><span class="shop-category-count"><?= (int) $categoryCounts[0] ?></span>
</button>
<?php endif; ?>
</div>
</aside>
<?php endif; ?>
<div class="panel shop-main">
<div class="shop-searchbar">
<label class="search-field">
<?= icon('search') ?>
<input type="search" id="shop-search" placeholder="Gegenstand suchen …" autocomplete="off" aria-label="Lumishop durchsuchen">
</label>
<span class="list-search-count text-muted" id="shop-count"><?= count($items) ?> <?= count($items) === 1 ? 'Gegenstand' : 'Gegenstände' ?></span>
</div>
<?php if (empty($items)): ?>
<p class="text-muted">Im Lumishop gibt es gerade nichts.<?= $canManage ? ' Unter „Shop verwalten“ legst du Gegenstände an oder übernimmst sie aus dem Lagerhaus.' : '' ?></p>
<?php else: ?>
<div class="shop-grid" id="shop-items">
<?php foreach ($items as $item): ?>
<?php
$available = $item['available'];
$price = (int) $item['price'];
$soldOut = $available !== null && $available < 1;
$affordable = $price === 0 ? SHOP_MAX_ORDER_QUANTITY : intdiv($spendable, $price);
// Mehr als verfuegbar darf beantragt werden (die Bewilligung kann kuerzen) - nur die
// Punkte muessen reichen.
$max = min(SHOP_MAX_ORDER_QUANTITY, $affordable);
$reason = $max < 1 ? 'Nicht genug Lumipunkte' : '';
?>
<div class="shop-card" data-item-tip data-name="<?= e(mb_strtolower((string) $item['name'])) ?>" data-category="<?= (int) ($item['category_id'] ?? 0) ?>">
<?= shop_item_tip($item, $spendable, $gearByName[mb_strtolower((string) $item['name'])]
?? $gearByName[mb_strtolower((string) ($item['warehouse_name'] ?? ''))] ?? null) ?>
<span class="shop-card-image"><?= shop_icon_html($item, 72) ?></span>
<span class="shop-card-name"><?= e((string) $item['name']) ?></span>
<?php if ($item['category_name'] !== null): ?>
<span class="warehouse-card-category"><?= e((string) $item['category_name']) ?></span>
<?php endif; ?>
<?php if (!empty($item['description'])): ?>
<span class="shop-card-description"><?= nl2br(e((string) $item['description'])) ?></span>
<?php endif; ?>
<span class="shop-card-price"><?= contribution_coin(18) ?> <?= contribution_format($price) ?></span>
<span class="shop-card-stock<?= $soldOut ? ' is-empty' : '' ?>"><?= e(shop_format_availability($available)) ?></span>
<button type="button" class="button-small shop-buy" <?= $reason !== '' ? 'disabled title="' . e($reason) . '"' : '' ?>
data-item-id="<?= (int) $item['id'] ?>" data-item-name="<?= e((string) $item['name']) ?>"
data-price="<?= $price ?>" data-max="<?= max(0, $max) ?>">
<?= $reason !== '' ? e($reason) : 'Beantragen' ?>
</button>
</div>
<?php endforeach; ?>
</div>
<p class="text-muted warehouse-no-match" id="shop-no-match" hidden>Kein Gegenstand passt zur Suche.</p>
<?php endif; ?>
</div>
</div>
<div class="panel" id="antraege">
<h2>Meine Anträge</h2>
<?php if (empty($myOrders)): ?>
<p class="text-muted">Du hast noch nichts beantragt.</p>
<?php else: ?>
<div class="shop-orders shop-orders-tiles">
<?php foreach ($myOrders as $order): ?>
<?php include __DIR__ . '/includes/shop_order_row.php'; ?>
<?php endforeach; ?>
</div>
<div class="warehouse-pages">
<span class="text-muted">
Anträge <?= ($page - 1) * $perPage + 1 ?>–<?= min($page * $perPage, $totalOrders) ?>
von <?= number_format($totalOrders, 0, ',', '.') ?>
</span>
<?php render_pagination('/shop.php?', $page, $pageCount, '#antraege'); ?>
</div>
<?php endif; ?>
</div>
<!-- Beantragen -->
<div class="modal-overlay" id="shop-buy-modal" <?= !empty($old) ? '' : 'hidden' ?>>
<div class="modal">
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
<h2>Beantragen</h2>
<form method="post" action="/shop_action.php">
<?= csrf_field() ?>
<input type="hidden" name="action" value="order">
<input type="hidden" name="item_id" id="shop-buy-item" value="<?= e((string) ($old['item_id'] ?? '')) ?>">
<p class="shop-buy-title"><strong id="shop-buy-name"><?= e((string) ($old['item_name'] ?? '')) ?></strong></p>
<div class="warehouse-row">
<div>
<label for="shop-buy-quantity">Anzahl</label>
<input type="number" id="shop-buy-quantity" name="quantity" min="1" required value="<?= e((string) ($old['quantity'] ?? '1')) ?>">
</div>
<div>
<label>Kosten</label>
<div class="shop-buy-total"><?= contribution_coin(20) ?> <span id="shop-buy-total">0</span></div>
</div>
</div>
<div>
<label for="shop-buy-note">Bemerkung <span class="text-muted">(optional, z.B. Name deines Charakters)</span></label>
<input type="text" id="shop-buy-note" name="note" maxlength="255" value="<?= e((string) ($old['note'] ?? '')) ?>">
</div>
<p class="text-muted shop-buy-hint">Du kannst auch mehr beantragen, als gerade verfügbar ist – dann wird eventuell nur ein Teil bewilligt. Die Lumipunkte werden erst bei der Bewilligung abgezogen, und nur für die bewilligte Anzahl. Bis dahin kannst du den Antrag zurückziehen.</p>
<div class="actions">
<button type="submit" class="button-success">Antrag stellen</button>
</div>
</form>
</div>
</div>
<script src="<?= e(asset_url('/assets/js/shop.js')) ?>"></script>
<script src="<?= e(asset_url('/assets/js/item-tooltip.js')) ?>"></script>
<?php include __DIR__ . '/includes/footer.php'; ?>