From 288e0c05f6bd377a549fc27bdf0c79ba495beacc Mon Sep 17 00:00:00 2001 From: morgane Date: Wed, 17 Jun 2026 13:30:48 +0000 Subject: [PATCH] Actualiser api/index.php --- api/index.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/api/index.php b/api/index.php index e17b52b..911627f 100644 --- a/api/index.php +++ b/api/index.php @@ -939,6 +939,9 @@ try { case 'locations_remove': locationsRemove($db); break; + case 'locations_update': + locationsUpdate($db); + break; case 'recipes_list': recipesList($db); break; @@ -12041,6 +12044,30 @@ function locationsRemove(PDO $db): void { echo json_encode(['success' => true]); } +function locationsUpdate(PDO $db): void { + $input = json_decode(file_get_contents('php://input'), true) ?? []; + $key = trim($input['key'] ?? ''); + $label = trim($input['label'] ?? ''); + $icon = trim($input['icon'] ?? ''); + + if ($key === '' || $label === '') { + echo json_encode(['success' => false, 'error' => 'key and label required']); + return; + } + + $stmt = $db->prepare("SELECT id FROM locations WHERE key = ?"); + $stmt->execute([$key]); + if (!$stmt->fetch()) { + echo json_encode(['success' => false, 'error' => 'location not found']); + return; + } + + $stmt = $db->prepare("UPDATE locations SET label = ?, icon = ? WHERE key = ?"); + $stmt->execute([$label, $icon ?: '📦', $key]); + + echo json_encode(['success' => true]); +} + // ===== SHARED APP DATA FUNCTIONS ===== function appSettingsGet(PDO $db): void {