|
|
@@ -12,14 +12,21 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
$iid = (int)($_POST['itemID'] ?? 0);
|
|
|
|
|
|
if ($action === 'add' && $aid > 0 && $iid > 0) {
|
|
|
+ $qty = max(1, (int)($_POST['quantity'] ?? 1));
|
|
|
try {
|
|
|
- $pdo->prepare("INSERT IGNORE INTO activity_item_map (activityID,itemID) VALUES (?,?)")
|
|
|
- ->execute([$aid, $iid]);
|
|
|
+ $pdo->prepare("INSERT IGNORE INTO activity_item_map (activityID,itemID,quantity) VALUES (?,?,?)")
|
|
|
+ ->execute([$aid, $iid, $qty]);
|
|
|
flash('success', 'Mapping added.');
|
|
|
} catch (Exception $e) {
|
|
|
flash('error', 'Could not add mapping.');
|
|
|
}
|
|
|
}
|
|
|
+ if ($action === 'update' && $aid > 0 && $iid > 0) {
|
|
|
+ $qty = max(1, (int)($_POST['quantity'] ?? 1));
|
|
|
+ $pdo->prepare("UPDATE activity_item_map SET quantity=? WHERE activityID=? AND itemID=?")
|
|
|
+ ->execute([$qty, $aid, $iid]);
|
|
|
+ flash('success', 'Quantity updated.');
|
|
|
+ }
|
|
|
if ($action === 'remove' && $aid > 0 && $iid > 0) {
|
|
|
$pdo->prepare("DELETE FROM activity_item_map WHERE activityID=? AND itemID=?")
|
|
|
->execute([$aid, $iid]);
|
|
|
@@ -56,7 +63,7 @@ $mappedItemIds = [];
|
|
|
$mappedItems = [];
|
|
|
if ($selectedAid) {
|
|
|
$stmt = $pdo->prepare("
|
|
|
- SELECT i.itemID, i.itemName, ig.groupName
|
|
|
+ SELECT i.itemID, i.itemName, ig.groupName, aim.quantity
|
|
|
FROM activity_item_map aim
|
|
|
JOIN items i ON i.itemID = aim.itemID
|
|
|
JOIN item_groups ig ON ig.groupID = i.groupID
|
|
|
@@ -125,6 +132,10 @@ show_alerts();
|
|
|
<?php endforeach; ?>
|
|
|
</select>
|
|
|
</div>
|
|
|
+ <div style="width:90px;">
|
|
|
+ <label>Qty</label>
|
|
|
+ <input type="number" name="quantity" value="1" min="1" style="margin-bottom:0;width:100%;">
|
|
|
+ </div>
|
|
|
<button type="submit" class="btn btn-primary">➕ Add</button>
|
|
|
</form>
|
|
|
|
|
|
@@ -133,13 +144,22 @@ show_alerts();
|
|
|
<p style="color:var(--muted);font-size:.85rem">No items mapped yet.</p>
|
|
|
<?php else: ?>
|
|
|
<table class="tbl">
|
|
|
- <thead><tr><th>#</th><th>Item</th><th>Group</th><th></th></tr></thead>
|
|
|
+ <thead><tr><th>#</th><th>Item</th><th>Group</th><th>Qty</th><th></th></tr></thead>
|
|
|
<tbody>
|
|
|
<?php foreach ($mappedItems as $it): ?>
|
|
|
<tr>
|
|
|
<td style="color:var(--muted)"><?= $it['itemID'] ?></td>
|
|
|
<td><?= htmlspecialchars($it['itemName']) ?></td>
|
|
|
<td><span class="badge badge-group"><?= htmlspecialchars($it['groupName']) ?></span></td>
|
|
|
+ <td>
|
|
|
+ <form method="POST" style="display:flex;gap:.3rem;align-items:center;">
|
|
|
+ <input type="hidden" name="action" value="update">
|
|
|
+ <input type="hidden" name="activityID" value="<?= $selectedAid ?>">
|
|
|
+ <input type="hidden" name="itemID" value="<?= $it['itemID'] ?>">
|
|
|
+ <input type="number" name="quantity" value="<?= (int)$it['quantity'] ?>" min="1" style="margin:0;width:70px;">
|
|
|
+ <button class="btn btn-sm btn-primary">💾</button>
|
|
|
+ </form>
|
|
|
+ </td>
|
|
|
<td style="text-align:right">
|
|
|
<form method="POST" onsubmit="return confirm('Remove this mapping?')">
|
|
|
<input type="hidden" name="action" value="remove">
|