|
|
@@ -53,55 +53,36 @@ $activities = $pdo->query("
|
|
|
ORDER BY ag.sortOrder, a.sortOrder, a.activityID
|
|
|
")->fetchAll();
|
|
|
|
|
|
-$editing = null;
|
|
|
-if (isset($_GET['edit'])) {
|
|
|
- $stmt = $pdo->prepare("SELECT * FROM activities WHERE activityID=?");
|
|
|
- $stmt->execute([(int)$_GET['edit']]);
|
|
|
- $editing = $stmt->fetch();
|
|
|
-}
|
|
|
-
|
|
|
admin_head('Activities', 'activities.php');
|
|
|
show_alerts();
|
|
|
?>
|
|
|
<h1>Activities</h1>
|
|
|
|
|
|
<div class="card">
|
|
|
- <h2><?= $editing ? 'Edit Activity' : 'Add New Activity' ?></h2>
|
|
|
+ <h2>Add New Activity</h2>
|
|
|
<form method="POST">
|
|
|
- <input type="hidden" name="action" value="<?= $editing ? 'edit' : 'add' ?>">
|
|
|
- <?php if ($editing): ?>
|
|
|
- <input type="hidden" name="activityID" value="<?= $editing['activityID'] ?>">
|
|
|
- <?php endif; ?>
|
|
|
+ <input type="hidden" name="action" value="add">
|
|
|
<div class="form-row">
|
|
|
<div>
|
|
|
<label>Activity Name</label>
|
|
|
- <input type="text" name="activityName"
|
|
|
- value="<?= htmlspecialchars($editing['activityName'] ?? '') ?>"
|
|
|
- placeholder="e.g. Kayaking" required>
|
|
|
+ <input type="text" name="activityName" placeholder="e.g. Kayaking" required>
|
|
|
</div>
|
|
|
<div>
|
|
|
<label>Group</label>
|
|
|
<select name="groupID" required>
|
|
|
<option value="">– select –</option>
|
|
|
<?php foreach ($groups as $g): ?>
|
|
|
- <option value="<?= $g['groupID'] ?>"
|
|
|
- <?= ($editing && $editing['groupID'] == $g['groupID']) ? 'selected' : '' ?>>
|
|
|
- <?= htmlspecialchars($g['groupName']) ?>
|
|
|
- </option>
|
|
|
+ <option value="<?= $g['groupID'] ?>"><?= htmlspecialchars($g['groupName']) ?></option>
|
|
|
<?php endforeach; ?>
|
|
|
</select>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div>
|
|
|
<label>Sort Order</label>
|
|
|
- <input type="number" name="sortOrder"
|
|
|
- value="<?= (int)($editing['sortOrder'] ?? 0) ?>" min="0" style="max-width:120px;">
|
|
|
+ <input type="number" name="sortOrder" value="0" min="0" style="max-width:120px;">
|
|
|
</div>
|
|
|
<div style="display:flex;gap:.5rem;margin-top:.25rem;">
|
|
|
- <button type="submit" class="btn btn-primary"><?= $editing ? '💾 Save' : '➕ Add' ?></button>
|
|
|
- <?php if ($editing): ?>
|
|
|
- <a href="activities.php" class="btn btn-secondary">Cancel</a>
|
|
|
- <?php endif; ?>
|
|
|
+ <button type="submit" class="btn btn-primary">➕ Add</button>
|
|
|
</div>
|
|
|
</form>
|
|
|
</div>
|
|
|
@@ -109,22 +90,67 @@ show_alerts();
|
|
|
<table class="tbl">
|
|
|
<thead><tr><th>#</th><th>Name</th><th>Group</th><th>Sort</th><th></th></tr></thead>
|
|
|
<tbody>
|
|
|
- <?php foreach ($activities as $a): ?>
|
|
|
- <tr>
|
|
|
- <td style="color:var(--muted)"><?= $a['activityID'] ?></td>
|
|
|
+ <?php foreach ($activities as $a):
|
|
|
+ $id = $a['activityID'];
|
|
|
+ ?>
|
|
|
+ <tr id="view-<?= $id ?>">
|
|
|
+ <td style="color:var(--muted)"><?= $id ?></td>
|
|
|
<td><?= htmlspecialchars($a['activityName']) ?></td>
|
|
|
<td><span class="badge badge-group"><?= htmlspecialchars($a['groupName']) ?></span></td>
|
|
|
<td><?= $a['sortOrder'] ?></td>
|
|
|
<td style="display:flex;gap:.4rem;justify-content:flex-end;">
|
|
|
- <a href="?edit=<?= $a['activityID'] ?>" class="btn btn-sm btn-teal">Edit</a>
|
|
|
+ <button type="button" onclick="startEdit(<?= $id ?>)" class="btn btn-sm btn-teal">Edit</button>
|
|
|
<form method="POST" onsubmit="return confirm('Delete this activity?')">
|
|
|
<input type="hidden" name="action" value="delete">
|
|
|
- <input type="hidden" name="activityID" value="<?= $a['activityID'] ?>">
|
|
|
+ <input type="hidden" name="activityID" value="<?= $id ?>">
|
|
|
<button class="btn btn-sm btn-danger">Delete</button>
|
|
|
</form>
|
|
|
</td>
|
|
|
</tr>
|
|
|
+ <tr id="edit-<?= $id ?>" style="display:none;background:rgba(79,209,197,.04);">
|
|
|
+ <td colspan="5">
|
|
|
+ <form method="POST" style="display:flex;gap:.75rem;align-items:flex-end;flex-wrap:wrap;padding:.25rem 0;">
|
|
|
+ <input type="hidden" name="action" value="edit">
|
|
|
+ <input type="hidden" name="activityID" value="<?= $id ?>">
|
|
|
+ <div>
|
|
|
+ <label>Activity Name</label>
|
|
|
+ <input type="text" name="activityName" value="<?= htmlspecialchars($a['activityName']) ?>" required style="margin-bottom:0;min-width:180px;">
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label>Group</label>
|
|
|
+ <select name="groupID" required style="margin-bottom:0;min-width:140px;">
|
|
|
+ <?php foreach ($groups as $g): ?>
|
|
|
+ <option value="<?= $g['groupID'] ?>" <?= $a['groupID'] == $g['groupID'] ? 'selected' : '' ?>>
|
|
|
+ <?= htmlspecialchars($g['groupName']) ?>
|
|
|
+ </option>
|
|
|
+ <?php endforeach; ?>
|
|
|
+ </select>
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <label>Sort Order</label>
|
|
|
+ <input type="number" name="sortOrder" value="<?= (int)$a['sortOrder'] ?>" min="0" style="margin-bottom:0;max-width:90px;">
|
|
|
+ </div>
|
|
|
+ <div style="display:flex;gap:.4rem;padding-bottom:1px;">
|
|
|
+ <button type="submit" class="btn btn-sm btn-primary">💾 Save</button>
|
|
|
+ <button type="button" onclick="cancelEdit(<?= $id ?>)" class="btn btn-sm btn-secondary">Cancel</button>
|
|
|
+ </div>
|
|
|
+ </form>
|
|
|
+ </td>
|
|
|
+ </tr>
|
|
|
<?php endforeach; ?>
|
|
|
</tbody>
|
|
|
</table>
|
|
|
+
|
|
|
+<script>
|
|
|
+function startEdit(id) {
|
|
|
+ document.getElementById('view-' + id).style.display = 'none';
|
|
|
+ document.getElementById('edit-' + id).style.display = '';
|
|
|
+ document.querySelector('#edit-' + id + ' input[name="activityName"]').focus();
|
|
|
+}
|
|
|
+function cancelEdit(id) {
|
|
|
+ document.getElementById('edit-' + id).style.display = 'none';
|
|
|
+ document.getElementById('view-' + id).style.display = '';
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
<?php admin_foot(); ?>
|