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>
300 lines
17 KiB
PHP
300 lines
17 KiB
PHP
<?php
|
||
require_once __DIR__ . '/includes/bootstrap.php';
|
||
require_once __DIR__ . '/includes/shop.php';
|
||
require_permission('shop.manage');
|
||
|
||
warehouse_sync_catalog();
|
||
|
||
$categories = shop_categories();
|
||
$items = shop_items(false);
|
||
$pendingCount = shop_pending_count();
|
||
|
||
// Lagerhaus-Gegenstaende fuer die Vorschlagsliste (Bild/Verknuepfung) und zum Uebernehmen:
|
||
// alles, was auf Lager ist und noch nicht im Shop steht (ohne Kina).
|
||
$warehouseNames = db()->query('SELECT name FROM warehouse_items ORDER BY name')->fetchAll(PDO::FETCH_COLUMN);
|
||
$linkedIds = array_filter(array_map(static fn (array $i): int => (int) $i['warehouse_item_id'], $items));
|
||
$importable = array_values(array_filter(
|
||
warehouse_stock(),
|
||
static fn (array $row): bool => $row['category'] !== 'currency' && !in_array((int) $row['id'], $linkedIds, true)
|
||
));
|
||
|
||
// Eingaben nach einem Fehler (siehe shop_manage_action.php)
|
||
$old = $_SESSION['shop_item_form'] ?? null;
|
||
unset($_SESSION['shop_item_form']);
|
||
|
||
/** Daten eines Gegenstands fuer den Bearbeiten-Dialog. */
|
||
function shop_item_form_data(array $item): string
|
||
{
|
||
return (string) json_encode([
|
||
'id' => (int) $item['id'],
|
||
'name' => (string) $item['name'],
|
||
'category_id' => $item['category_id'] !== null ? (string) $item['category_id'] : '',
|
||
'description' => (string) ($item['description'] ?? ''),
|
||
'price' => (string) $item['price'],
|
||
'stock_mode' => (string) $item['stock_mode'],
|
||
'stock' => (string) $item['stock'],
|
||
'warehouse_item' => (string) ($item['warehouse_name'] ?? ''),
|
||
'active' => (bool) (int) $item['active'],
|
||
], JSON_UNESCAPED_UNICODE);
|
||
}
|
||
|
||
$pageTitle = 'Lumishop verwalten';
|
||
$containerWide = true;
|
||
include __DIR__ . '/includes/header.php';
|
||
?>
|
||
<div class="panel">
|
||
<div class="warehouse-head">
|
||
<div>
|
||
<h1>Lumishop verwalten</h1>
|
||
<p class="text-muted"><?= count($items) ?> Gegenstände, davon <?= count(array_filter($items, static fn (array $i): bool => (bool) (int) $i['active'])) ?> im Angebot.</p>
|
||
</div>
|
||
<div class="actions">
|
||
<a class="button button-secondary" href="/shop.php">Zum Shop</a>
|
||
<a class="button button-secondary" href="/shop_orders.php">Anträge<?= $pendingCount > 0 ? ' <span class="shop-count">' . $pendingCount . '</span>' : '' ?></a>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="panel">
|
||
<div class="warehouse-head">
|
||
<h2>Gegenstände</h2>
|
||
<div class="actions">
|
||
<button type="button" class="button-success" data-open-modal="shop-item-modal" data-item="">+ Gegenstand anlegen</button>
|
||
<button type="button" class="button-secondary" data-open-modal="shop-import-modal" <?= empty($importable) ? 'disabled title="Alles, was im Lagerhaus liegt, steht schon im Shop"' : '' ?>>Aus dem Lagerhaus übernehmen</button>
|
||
</div>
|
||
</div>
|
||
|
||
<?php if (empty($items)): ?>
|
||
<p class="text-muted">Noch keine Gegenstände. Lege einen an oder übernimm Gegenstände aus dem Lagerhaus – deren Bestand gleicht der Shop dann automatisch ab.</p>
|
||
<?php else: ?>
|
||
<div class="table-scroll">
|
||
<table class="table-actions shop-manage-table">
|
||
<thead>
|
||
<tr>
|
||
<th>Gegenstand</th>
|
||
<th>Kategorie</th>
|
||
<th class="num">Preis</th>
|
||
<th>Bestand</th>
|
||
<th>Aktionen</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($items as $item): ?>
|
||
<?php $stock = shop_stock($item); ?>
|
||
<tr class="<?= (int) $item['active'] ? '' : 'is-inactive' ?>">
|
||
<td>
|
||
<span class="warehouse-item-inline">
|
||
<?= shop_icon_html($item, 32) ?>
|
||
<span>
|
||
<?= e((string) $item['name']) ?>
|
||
<?php if (!(int) $item['active']): ?><span class="badge">nicht im Angebot</span><?php endif; ?>
|
||
</span>
|
||
</span>
|
||
</td>
|
||
<td><?= $item['category_name'] !== null ? e((string) $item['category_name']) : '<span class="text-muted">-</span>' ?></td>
|
||
<td class="num"><?= contribution_coin(16) ?> <?= contribution_format((int) $item['price']) ?></td>
|
||
<td>
|
||
<?php if ($item['stock_mode'] === 'unlimited'): ?>
|
||
Unbegrenzt
|
||
<?php else: ?>
|
||
<?= number_format((int) $stock, 0, ',', '.') ?>
|
||
<?php if ($item['stock_mode'] === 'warehouse'): ?>
|
||
<span class="badge shop-badge-warehouse" title="Bestand kommt aus dem Lagerhaus (<?= e((string) ($item['warehouse_name'] ?? '?')) ?>)">Lagerhaus</span>
|
||
<?php endif; ?>
|
||
<?php endif; ?>
|
||
<?php if ((int) $item['reserved'] > 0): ?>
|
||
<span class="text-muted">· <?= (int) $item['reserved'] ?> beantragt</span>
|
||
<?php endif; ?>
|
||
</td>
|
||
<td>
|
||
<div class="actions">
|
||
<button type="button" class="icon-button" title="Bearbeiten" aria-label="Bearbeiten"
|
||
data-open-modal="shop-item-modal" data-item="<?= e(shop_item_form_data($item)) ?>"><?= icon('edit') ?></button>
|
||
<form class="inline-form" method="post" action="/shop_manage_action.php">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="item_toggle">
|
||
<input type="hidden" name="item_id" value="<?= (int) $item['id'] ?>">
|
||
<button type="submit" class="icon-button" title="<?= (int) $item['active'] ? 'Aus dem Angebot nehmen' : 'Ins Angebot aufnehmen' ?>"
|
||
aria-label="<?= (int) $item['active'] ? 'Aus dem Angebot nehmen' : 'Ins Angebot aufnehmen' ?>"><?= icon((int) $item['active'] ? 'archive' : 'restore') ?></button>
|
||
</form>
|
||
<?php if ($item['stock_mode'] === 'manual'): ?>
|
||
<form class="inline-form" method="post" action="/shop_manage_action.php"
|
||
onsubmit="return confirm(<?= e(json_encode('„' . $item['name'] . '“ mit dem Lagerhaus verknüpfen?' . ((int) $item['stock'] > 0 ? ' Der Shop-Bestand von ' . (int) $item['stock'] . ' Stück wird dort eingelagert.' : '') . ' Danach kommt der Bestand automatisch aus dem Lagerhaus.', JSON_UNESCAPED_UNICODE)) ?>);">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="to_warehouse">
|
||
<input type="hidden" name="item_id" value="<?= (int) $item['id'] ?>">
|
||
<button type="submit" class="icon-button" title="Ins Lagerhaus übertragen und verknüpfen" aria-label="Ins Lagerhaus übertragen"><?= icon('box') ?></button>
|
||
</form>
|
||
<?php endif; ?>
|
||
<form class="inline-form" method="post" action="/shop_manage_action.php"
|
||
onsubmit="return confirm(<?= e(json_encode('„' . $item['name'] . '“ aus dem Shop löschen? Bisherige Anträge bleiben erhalten.', JSON_UNESCAPED_UNICODE)) ?>);">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="item_delete">
|
||
<input type="hidden" name="item_id" value="<?= (int) $item['id'] ?>">
|
||
<button type="submit" class="icon-button icon-button-danger" title="Löschen" aria-label="Löschen"><?= icon('trash') ?></button>
|
||
</form>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<div class="panel">
|
||
<h2>Kategorien</h2>
|
||
<p class="text-muted">Die Reihenfolge bestimmt, wie die Kategorien im Shop sortiert sind (kleinere Zahl zuerst).</p>
|
||
<div class="shop-categories">
|
||
<?php foreach ($categories as $category): ?>
|
||
<div class="shop-category-row">
|
||
<form method="post" action="/shop_manage_action.php" class="shop-category-form">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="category_save">
|
||
<input type="hidden" name="category_id" value="<?= (int) $category['id'] ?>">
|
||
<input type="text" name="name" maxlength="80" required value="<?= e((string) $category['name']) ?>" aria-label="Name">
|
||
<input type="number" name="sort_order" value="<?= (int) $category['sort_order'] ?>" class="shop-sort-input" aria-label="Reihenfolge" title="Reihenfolge">
|
||
<button type="submit" class="button-secondary button-small">Speichern</button>
|
||
</form>
|
||
<form method="post" action="/shop_manage_action.php" class="inline-form"
|
||
onsubmit="return confirm(<?= e(json_encode('Kategorie „' . $category['name'] . '“ löschen? Ihre Gegenstände bleiben ohne Kategorie im Shop.', JSON_UNESCAPED_UNICODE)) ?>);">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="category_delete">
|
||
<input type="hidden" name="category_id" value="<?= (int) $category['id'] ?>">
|
||
<button type="submit" class="icon-button icon-button-danger" title="Kategorie löschen" aria-label="Kategorie löschen"><?= icon('trash') ?></button>
|
||
</form>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
<form method="post" action="/shop_manage_action.php" class="shop-category-form shop-category-new">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="category_save">
|
||
<input type="text" name="name" maxlength="80" required placeholder="Neue Kategorie, z.B. Ausrüstung" aria-label="Neue Kategorie">
|
||
<input type="number" name="sort_order" value="<?= count($categories) * 10 + 10 ?>" class="shop-sort-input" aria-label="Reihenfolge" title="Reihenfolge">
|
||
<button type="submit" class="button-small">+ Anlegen</button>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Gegenstand anlegen / bearbeiten -->
|
||
<div class="modal-overlay" id="shop-item-modal" <?= $old !== null ? '' : 'hidden' ?>
|
||
data-old="<?= $old !== null ? e((string) json_encode($old, JSON_UNESCAPED_UNICODE)) : '' ?>">
|
||
<div class="modal">
|
||
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
|
||
<h2 id="shop-item-title">Gegenstand anlegen</h2>
|
||
<form method="post" action="/shop_manage_action.php" id="shop-item-form">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="item_save">
|
||
<input type="hidden" name="item_id" value="">
|
||
<div>
|
||
<label for="shop-item-name">Name</label>
|
||
<input type="text" id="shop-item-name" name="name" maxlength="150" required list="shop-warehouse-list" autocomplete="off">
|
||
</div>
|
||
<div class="warehouse-row">
|
||
<div>
|
||
<label for="shop-item-category">Kategorie</label>
|
||
<select id="shop-item-category" name="category_id">
|
||
<option value="">– ohne Kategorie –</option>
|
||
<?php foreach ($categories as $category): ?>
|
||
<option value="<?= (int) $category['id'] ?>"><?= e((string) $category['name']) ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
</div>
|
||
<div>
|
||
<label for="shop-item-price">Preis in Lumipunkten</label>
|
||
<input type="number" id="shop-item-price" name="price" min="0" max="<?= SHOP_MAX_PRICE ?>" required>
|
||
</div>
|
||
</div>
|
||
<div>
|
||
<label for="shop-item-description">Beschreibung <span class="text-muted">(optional)</span></label>
|
||
<textarea id="shop-item-description" name="description" maxlength="500" rows="2"></textarea>
|
||
</div>
|
||
<div class="warehouse-row">
|
||
<div>
|
||
<label for="shop-item-mode">Bestand</label>
|
||
<select id="shop-item-mode" name="stock_mode">
|
||
<?php foreach (SHOP_STOCK_MODES as $value => $label): ?>
|
||
<option value="<?= e($value) ?>"><?= e($label) ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
</div>
|
||
<div data-mode-field="manual">
|
||
<label for="shop-item-stock">Stückzahl im Shop</label>
|
||
<input type="number" id="shop-item-stock" name="stock" min="0" max="<?= SHOP_MAX_STOCK ?>" value="0">
|
||
</div>
|
||
</div>
|
||
<div>
|
||
<label for="shop-item-warehouse">Lagerhaus-Gegenstand <span class="text-muted" data-mode-hint>(optional, für das Bild)</span></label>
|
||
<input type="text" id="shop-item-warehouse" name="warehouse_item" maxlength="150" list="shop-warehouse-list" autocomplete="off"
|
||
placeholder="Leer lassen = gleicher Name wie oben, falls es ihn im Lagerhaus gibt">
|
||
<div class="field-hint" data-mode-field="warehouse">Der Bestand im Shop ist der Lagerbestand dieses Gegenstands. Beim Bewilligen wird die Entnahme automatisch im Lagerhaus gebucht.</div>
|
||
</div>
|
||
<label class="checkbox-label">
|
||
<input type="checkbox" name="active" value="1" checked> Im Shop anbieten
|
||
</label>
|
||
<div class="actions">
|
||
<button type="submit" class="button-success">Speichern</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<datalist id="shop-warehouse-list">
|
||
<?php foreach ($warehouseNames as $name): ?>
|
||
<option value="<?= e((string) $name) ?>">
|
||
<?php endforeach; ?>
|
||
</datalist>
|
||
|
||
<!-- Aus dem Lagerhaus uebernehmen -->
|
||
<?php if (!empty($importable)): ?>
|
||
<div class="modal-overlay" id="shop-import-modal" hidden>
|
||
<div class="modal modal-wide">
|
||
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
|
||
<h2>Aus dem Lagerhaus übernehmen</h2>
|
||
<p class="text-muted">Die ausgewählten Gegenstände kommen in den Shop. Ihr Bestand wird laufend aus dem Lagerhaus übernommen, bewilligte Anträge werden dort automatisch als Entnahme gebucht.</p>
|
||
<form method="post" action="/shop_manage_action.php">
|
||
<?= csrf_field() ?>
|
||
<input type="hidden" name="action" value="import_warehouse">
|
||
<div class="warehouse-row">
|
||
<div>
|
||
<label for="shop-import-category">Kategorie für alle</label>
|
||
<select id="shop-import-category" name="category_id">
|
||
<option value="">– ohne Kategorie –</option>
|
||
<?php foreach ($categories as $category): ?>
|
||
<option value="<?= (int) $category['id'] ?>"><?= e((string) $category['name']) ?></option>
|
||
<?php endforeach; ?>
|
||
</select>
|
||
</div>
|
||
<div>
|
||
<label for="shop-import-price">Preis für alle ausgewählten</label>
|
||
<div class="shop-import-price">
|
||
<input type="number" id="shop-import-price" min="0" max="<?= SHOP_MAX_PRICE ?>" placeholder="z.B. 50">
|
||
<button type="button" class="button-secondary button-small" id="shop-import-apply">Übernehmen</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="shop-import-list">
|
||
<label class="shop-import-row shop-import-all">
|
||
<input type="checkbox" id="shop-import-all"> <strong>Alle auswählen</strong>
|
||
</label>
|
||
<?php foreach ($importable as $row): ?>
|
||
<div class="shop-import-row">
|
||
<label>
|
||
<input type="checkbox" name="warehouse_ids[]" value="<?= (int) $row['id'] ?>" class="shop-import-check">
|
||
<?= warehouse_icon_html($row['icon'] ?? null, (string) $row['name'], 28) ?>
|
||
<span><?= e((string) $row['name']) ?></span>
|
||
<span class="text-muted"><?= number_format((int) $row['quantity'], 0, ',', '.') ?> auf Lager</span>
|
||
</label>
|
||
<input type="number" name="prices[<?= (int) $row['id'] ?>]" min="0" max="<?= SHOP_MAX_PRICE ?>" placeholder="Preis" class="shop-import-row-price" aria-label="Preis für <?= e((string) $row['name']) ?>">
|
||
</div>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<div class="actions">
|
||
<button type="submit" class="button-success">Ausgewählte übernehmen</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<script src="<?= e(asset_url('/assets/js/shop.js')) ?>"></script>
|
||
<?php include __DIR__ . '/includes/footer.php'; ?>
|