<%@ page contentType="text/html; charset=UTF-8" %> <%-- - - Copyright (C) 2005-2008 Jive Software, 2017-2025 Ignite Realtime Foundation. All rights reserved. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --%> <%@ page import=" org.jivesoftware.openfire.group.Group, org.jivesoftware.openfire.group.GroupNotFoundException, org.jivesoftware.openfire.user.User, org.jivesoftware.openfire.user.UserNotFoundException"%> <%@ page import="org.jivesoftware.util.ParamUtils"%> <%@ page import="org.jivesoftware.util.StringUtils"%> <%@ page import="org.jivesoftware.util.CookieUtils"%> <%@ page import="org.xmpp.packet.JID"%> <%@ page import="java.net.URLEncoder"%> <%@ page import="java.util.*"%> <%@ page import="java.nio.charset.StandardCharsets" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> <%@ taglib prefix="admin" uri="admin" %> <% webManager.init(pageContext); %> <% // Get parameters String add = StringUtils.escapeHTMLTags(ParamUtils.getParameter(request, "add")); String delete = StringUtils.escapeHTMLTags(ParamUtils.getParameter(request, "delete")); boolean success = ParamUtils.getBooleanParameter(request,"updatesuccess"); String username = StringUtils.escapeHTMLTags(ParamUtils.getParameter(request, "username")); JID jid = webManager.getXMPPServer().createJID(username, null); Cookie csrfCookie = CookieUtils.getCookie(request, "csrf"); String csrfParam = ParamUtils.getParameter(request, "csrf"); if (add != null || delete != null) { if (csrfCookie == null || csrfParam == null || !csrfCookie.getValue().equals(csrfParam)) { add = null; delete = null; } } csrfParam = StringUtils.randomString(15); CookieUtils.setCookie(request, response, "csrf", csrfParam, -1); pageContext.setAttribute("csrf", csrfParam); if(add != null) { try { Group group = webManager.getGroupManager().getGroup(add); group.getMembers().add(jid); response.sendRedirect("user-groups.jsp?username=" + URLEncoder.encode(username, StandardCharsets.UTF_8) + "&updatesuccess=true"); } catch (GroupNotFoundException exp) { return; } } if(delete != null) { try { Group group = webManager.getGroupManager().getGroup(delete); group.getMembers().remove(jid); group.getAdmins().remove(jid); response.sendRedirect("user-groups.jsp?username=" + URLEncoder.encode(username, StandardCharsets.UTF_8) + "&updatesuccess=true"); } catch (GroupNotFoundException exp) { return; } } // Load the user object User user = null; try { user = webManager.getUserManager().getUser(username); } catch (UserNotFoundException unfe) { } Collection userGroups = webManager.getGroupManager().getGroups(user); int start = ParamUtils.getIntParameter(request,"start",0); int range = ParamUtils.getIntParameter(request,"range",15); if (request.getParameter("range") != null) { webManager.setRowsPerPage("group-summary", range); } ArrayList groups = new ArrayList<>(webManager.getGroupManager().getGroups()); // Remove already joined groups groups.removeAll(userGroups); int groupCount = groups.size(); int groupIndex = start + range; String search = null; if (webManager.getGroupManager().isSearchSupported() && request.getParameter("search") != null && !request.getParameter("search").trim().isEmpty()) { search = request.getParameter("search"); search = StringUtils.escapeHTMLTags(search); // Use the search terms to get the list of groups. groups = new ArrayList<>(webManager.getGroupManager().search(search)); // Count already joined groups in the search result int userGroupCount = 0; for(Group group : groups) { if(userGroups.contains(group)) { userGroupCount++; } } groups.removeAll(userGroups); groupCount = groups.size() - userGroupCount; } if(groupIndex >= groupCount) { groupIndex = groupCount; } // paginator vars int numPages = (int)Math.ceil((double)groupCount/(double)range); int curPage = (start/range) + 1; if(success) { %> <% } %> <fmt:message key="user.groups.title" />

<%=username%>.

<% // Print the list of groups if (userGroups.isEmpty()) { %> <% } int x = 0; for (Group group : userGroups) { String groupName = URLEncoder.encode(group.getName(), StandardCharsets.UTF_8); x++; %> <% } %>
 
<%=x%> <%=StringUtils.escapeHTMLTags(group.getName())%> <% if (group.getDescription() != null) { %>
<%=StringUtils.escapeHTMLTags(group.getDescription())%> <% } %>
"><fmt:message key=">

<%=username%>.

<% if (webManager.getGroupManager().isSearchSupported()) { %>
<%=groupCount%>
<% } // Otherwise, searching is not supported. else { %>

<%=groupCount%> <% if (numPages > 1) { %> , <%=(start + 1)%>-<%=(start + range)%> <% } %>

<% } %> <% if (numPages > 1) { %>

[ <% for (int i = 0; i < numPages; i++) { String sep = ((i + 1) < numPages) ? " " : ""; boolean isCurrent = (i + 1) == curPage; %> " class="<%=((isCurrent) ? "jive-current" : "")%>"><%=(i + 1)%><%=sep%> <% } %> ]

<% } %>
<% // Print the list of groups if (groups.isEmpty()) { %> <% } int i = 0; for (Group group : groups.subList(start, groupIndex)) { String groupName = URLEncoder.encode(group.getName(), StandardCharsets.UTF_8); i++; %> <% } %>
 
<%=i%> <%=StringUtils.escapeHTMLTags(group.getName())%> <% if (group.getDescription() != null) { %>
<%=StringUtils.escapeHTMLTags(group.getDescription())%> <% } %>
"> <fmt:message key=">
<% if (numPages > 1) { %>

[ <% for (i = 0; i < numPages; i++) { String sep = ((i + 1) < numPages) ? " " : ""; boolean isCurrent = (i + 1) == curPage; %> " class="<%=((isCurrent) ? "jive-current" : "")%>"><%=(i + 1)%><%=sep%> <% } %> ]

<% } %>