- "Menü anpassen" at the bottom of the sidebar starts an edit mode: drag items (and the divider) with mouse or touch, save, reset to default or cancel; admin items stay in the admin section - Order stored per member (users.sidebar_order) and applied via CSS order, no reflow on load - Wiki chapter tiles get the same dark hover with gold border as the subpage tiles Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
37 lines
1.2 KiB
PHP
37 lines
1.2 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)));
|
|
};
|
|
$order = [
|
|
'main' => $clean($_POST['main'] ?? [], SIDEBAR_NAV_MAIN),
|
|
'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]);
|