LuminaWebsite/sidebar_action.php
Maaxxs c547e00a81 Gear planner autosave, extra dividers in the customizable menu
- Gear planner: slot changes save automatically (selects right away, numbers/text shortly after
  typing) with a status instead of the save button; totals and slot tile update without a reload,
  a different item reloads once for its fields; slot labels no longer uppercase (Füße, not FÜSSE)
- Menu editor: "+ Trennlinie" adds extra dividers (up to 10), removable with ×

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 11:06:49 +02:00

42 lines
1.5 KiB
PHP

<?php
/**
* Eigene Reihenfolge der Menuepunkte speichern (Seitenleiste -> "Menü anpassen",
* assets/js/sidebar-editor.js). Antwortet als JSON.
*/
require_once __DIR__ . '/includes/bootstrap.php';
require_login();
header('Content-Type: application/json; charset=UTF-8');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
echo json_encode(['ok' => false]);
exit;
}
verify_csrf();
$userId = (int) current_user()['id'];
if (!empty($_POST['reset'])) {
db()->prepare('UPDATE users SET sidebar_order = NULL WHERE id = ?')->execute([$userId]);
echo json_encode(['ok' => true]);
exit;
}
/** Nur bekannte Menuepunkte, jeder hoechstens einmal. */
$clean = static function ($keys, array $allowed): array {
$keys = array_values(array_unique(array_filter((array) $keys, 'is_string')));
return array_values(array_filter($keys, static fn (string $key): bool => in_array($key, $allowed, true)));
};
// Zusaetzliche Trennlinien heissen gap-1, gap-2, ... (hoechstens SIDEBAR_MAX_EXTRA_GAPS)
$extraGaps = array_slice(array_values(array_filter(
(array) ($_POST['main'] ?? []),
static fn ($key): bool => is_string($key) && preg_match('/^gap-\d{1,3}$/', $key) === 1
)), 0, SIDEBAR_MAX_EXTRA_GAPS);
$order = [
'main' => $clean($_POST['main'] ?? [], array_merge(SIDEBAR_NAV_MAIN, $extraGaps)),
'admin' => $clean($_POST['admin'] ?? [], SIDEBAR_NAV_ADMIN),
];
db()->prepare('UPDATE users SET sidebar_order = ? WHERE id = ?')
->execute([json_encode($order, JSON_UNESCAPED_SLASHES), $userId]);
echo json_encode(['ok' => true]);