false, 'message' => 'You do not have permission to perform this action.']); exit; } try { // Find the default tab (first one by sort order or ID) to assign orphans to $stmt = $pdo->query("SELECT id FROM tabs ORDER BY sort_order ASC, id ASC LIMIT 1"); $default_tab_id = $stmt->fetchColumn(); if (!$default_tab_id) { throw new Exception("No default tab found to assign bookmarks to."); } $update_stmt = $pdo->prepare("UPDATE bookmarks SET tab_id = ? WHERE tab_id IS NULL OR tab_id = '' OR tab_id = 0"); $update_stmt->execute([$default_tab_id]); $count = $update_stmt->rowCount(); if ($count > 0) { $message = "Successfully assigned {$count} orphaned bookmarks to the default tab (ID: {$default_tab_id})."; } else { $message = "No orphaned bookmarks were found."; } echo json_encode(['success' => true, 'message' => $message, 'updated_count' => $count]); } catch (Exception $e) { http_response_code(500); echo json_encode(['success' => false, 'message' => 'Database error: ' . $e->getMessage()]); }