From dc740fb94de3affc457b58c86bcdf53698f4a038 Mon Sep 17 00:00:00 2001 From: Niek Rabelink Date: Fri, 11 Sep 2026 15:39:36 +0200 Subject: [PATCH] feat(widgets): allow users to customize widget titles from settings gear dropdown --- api/planner.php | 21 ++++++- planner.php | 145 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 151 insertions(+), 15 deletions(-) diff --git a/api/planner.php b/api/planner.php index 938a708..d5abaac 100644 --- a/api/planner.php +++ b/api/planner.php @@ -42,8 +42,27 @@ try { exit; } + // Valideer en sanitize layout items inclusief optionele custom widget titel + $cleanedLayout = []; + foreach ($layout as $item) { + if (!is_array($item) || empty($item['id'])) continue; + $cleaned = [ + 'id' => substr(trim((string)$item['id']), 0, 64), + 'enabled' => !empty($item['enabled']), + 'col_span' => in_array((int)($item['col_span'] ?? 6), [4, 5, 6, 7, 8, 12]) ? (int)$item['col_span'] : 6, + 'order' => (int)($item['order'] ?? 1), + ]; + if (!empty($item['custom_title'])) { + $customTitle = trim(strip_tags((string)$item['custom_title'])); + if ($customTitle !== '') { + $cleaned['custom_title'] = substr($customTitle, 0, 50); + } + } + $cleanedLayout[] = $cleaned; + } + $stmt = $db->prepare("UPDATE users SET fociz_widget_layout = ? WHERE id = ?"); - $stmt->execute([json_encode($layout), $user['id']]); + $stmt->execute([json_encode($cleanedLayout, JSON_UNESCAPED_UNICODE), $user['id']]); echo json_encode(['success' => true, 'message' => 'Widget indeling succesvol opgeslagen']); exit; diff --git a/planner.php b/planner.php index f9b50d5..a3d677d 100644 --- a/planner.php +++ b/planner.php @@ -289,18 +289,34 @@ $savedLayoutJson = $currentUser['fociz_widget_layout'] ?? ''; if (!empty($savedLayoutJson)) { $decoded = json_decode($savedLayoutJson, true); if (is_array($decoded)) { + $savedOrder = 1; + $seen = []; foreach ($decoded as $item) { $wId = $item['id'] ?? ''; if (isset($userWidgetLayout[$wId])) { $userWidgetLayout[$wId]['enabled'] = !empty($item['enabled']); if (!empty($item['col_span'])) $userWidgetLayout[$wId]['col_span'] = (int)$item['col_span']; - if (isset($item['order'])) $userWidgetLayout[$wId]['order'] = (int)$item['order']; + $userWidgetLayout[$wId]['order'] = isset($item['order']) ? (int)$item['order'] : $savedOrder; + if (!empty($item['custom_title'])) { + $userWidgetLayout[$wId]['custom_title'] = trim($item['custom_title']); + $userWidgetLayout[$wId]['title'] = trim($item['custom_title']); + } + $seen[$wId] = true; + $savedOrder++; } } + foreach ($userWidgetLayout as $wId => &$wData) { + if (!isset($seen[$wId])) { + $wData['order'] = $savedOrder++; + } + } + unset($wData); } } uasort($userWidgetLayout, function($a, $b) { - return ($a['order'] ?? 0) <=> ($b['order'] ?? 0); + $diff = ($a['order'] ?? 0) <=> ($b['order'] ?? 0); + if ($diff !== 0) return $diff; + return strcmp($a['id'] ?? '', $b['id'] ?? ''); }); // Bereken dagstatistieken @@ -545,19 +561,45 @@ for ($h = $startHour; $h <= $endHour; $h++) {
- +
- +
- -