Members request items from the shop. Their points and the stock are earmarked but not taken until someone with shop.manage approves. Approving books a negative "Lumishop" entry in the Lumipunkte history and takes the stock. For warehouse-backed items it also books a withdrawal to the member in the warehouse. Approved orders are then marked as handed over in the game, or can be reversed, which restores points, stock and the warehouse withdrawal. The management page handles categories and items (price, description, stock). Stock is either the shop's own count, unlimited, or live from a linked warehouse item. Items in stock can be imported from the warehouse, and an item's own stock can be moved into the warehouse to link it there. Warehouse cards show when an item is sold in the shop. Shop bookings can't be deleted from the Lumipunkte page, only reversed in the shop, so orders and points stay in sync. The new permissions go to the Administrator group only, so the shop stays hidden until it is assigned. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
165 lines
8.2 KiB
PHP
165 lines
8.2 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);
|
||
$categories = [];
|
||
foreach ($items as $item) {
|
||
if ($item['category_id'] !== null) {
|
||
$categories[(int) $item['category_id']] = (string) $item['category_name'];
|
||
}
|
||
}
|
||
$hasUncategorized = (bool) array_filter($items, static fn (array $i): bool => $i['category_id'] === null);
|
||
|
||
// 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="panel">
|
||
<div class="warehouse-filters">
|
||
<input type="search" id="shop-search" placeholder="Gegenstand suchen …" autocomplete="off">
|
||
<?php if (count($categories) + ($hasUncategorized ? 1 : 0) > 1): ?>
|
||
<select id="shop-category">
|
||
<option value="">Alle Kategorien</option>
|
||
<?php foreach ($categories as $id => $name): ?>
|
||
<option value="<?= (int) $id ?>"><?= e($name) ?></option>
|
||
<?php endforeach; ?>
|
||
<?php if ($hasUncategorized): ?>
|
||
<option value="0">Ohne Kategorie</option>
|
||
<?php endif; ?>
|
||
</select>
|
||
<?php endif; ?>
|
||
</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);
|
||
$max = min(SHOP_MAX_ORDER_QUANTITY, $affordable, $available ?? SHOP_MAX_ORDER_QUANTITY);
|
||
$reason = $soldOut ? 'Ausverkauft' : ($max < 1 ? 'Nicht genug Lumipunkte' : '');
|
||
?>
|
||
<div class="shop-card<?= $soldOut ? ' sold-out' : '' ?>" 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 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">Die Lumipunkte werden erst abgezogen, wenn dein Antrag bewilligt ist. Bis dahin kannst du ihn 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'; ?>
|