false, 'ERROR' => 'missing_businessid', 'MESSAGE' => 'BusinessID is required.']); } try { $updateCount = 0; // Clear all station assignments for items in this business queryTimed("UPDATE Items SET StationID = NULL WHERE BusinessID = ?", [$businessID]); // Apply new assignments foreach ($assignments as $assignment) { if (isset($assignment['ItemID'], $assignment['StationID'])) { queryTimed("UPDATE Items SET StationID = ? WHERE ID = ?", [ (int) $assignment['StationID'], (int) $assignment['ItemID'], ]); $updateCount++; } } jsonResponse([ 'OK' => true, 'ERROR' => '', 'MESSAGE' => 'Station assignments updated', 'UPDATED_COUNT' => $updateCount, ]); } catch (Exception $e) { jsonResponse([ 'OK' => false, 'ERROR' => 'server_error', 'MESSAGE' => 'Error updating stations', 'DETAIL' => $e->getMessage(), ]); }