- Category list below each other with counts, active category highlighted in gold, sticky while scrolling; on phones a swipeable row - Search field in the same round style as elsewhere, with a "x of y" count Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
187 lines
9.6 KiB
PHP
187 lines
9.6 KiB
PHP
<?php
|
||
require_once __DIR__ . '/includes/bootstrap.php';
|
||
require_once __DIR__ . '/includes/shop.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]);
|
||
$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-name="<?= e(mb_strtolower((string) $item['name'])) ?>" data-category="<?= (int) ($item['category_id'] ?? 0) ?>">
|
||
<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">
|
||
<?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>
|
||
<?php include __DIR__ . '/includes/footer.php'; ?>
|