<%@ page contentType="text/html;charset=GBK" %>

<%
/**
 *	$RCSfile: groupMembers.jsp,v $
 *	$Revision: 1.1.1.1 $
 *	$Date: 2002/09/09 13:50:16 $
 */
%>

<%@ page import="java.util.*,
                 java.net.URLEncoder,
                 com.jivesoftware.forum.*,
                 com.jivesoftware.forum.util.*"%>

<%@ include file="global.jsp" %>


<%	// get parameters
	int groupID = ParamUtils.getIntParameter(request,"group",-1);
	boolean add = ParamUtils.getBooleanParameter(request,"add");
    boolean remove = ParamUtils.getBooleanParameter(request,"remove");
    long memberID = ParamUtils.getLongParameter(request,"member",-1L);
    String userList = ParamUtils.getParameter(request,"userList");

	// Get user and group managers
	UserManager userManager = forumFactory.getUserManager();
	GroupManager groupManager = forumFactory.getGroupManager();

    // Load the group
    Group group = groupManager.getGroup(groupID);

    if (add && userList != null) {
        StringTokenizer tokenizer = new StringTokenizer(userList,",");
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken().trim();
            // try to load the user by ID first
            User user = null;
            try {
                user = userManager.getUser(Long.parseLong(token));
            }
            catch (Exception ignored1) {
                // loading by user ID failed, so try by username
                try {
                    user = userManager.getUser(token);
                }
                catch (Exception ignored2) {}
            }
            // if user is not null, add the user to the group
            if (user != null) {
                group.addMember(user);
            }
        }
        // done, so redirect
        response.sendRedirect("groupMembers.jsp?group="+groupID);
        return;
    }

    if (remove) {
        User member = userManager.getUser(memberID);
        group.removeMember(member);
        // done, so redirect
        response.sendRedirect("groupMembers.jsp?group="+groupID);
        return;
    }

    // Total number of members in this group
	int memberCount = group.getMemberCount();

    // Iterator of members
	Iterator members = group.members();
%>

<%  // special onload command to load the sidebar
    onload = " onload=\"parent.frames['sidebar'].location.href='sidebar.jsp?sidebar=users';\"";
%>
<%@ include file="header.jsp" %>

<p>

<%  // Title of this page and breadcrumbs
    String title = "用户组管理";
    String[][] breadcrumbs = {
        {"主页面", "main.jsp"},
        {"用户组概览", "groups.jsp"},
        {title, "groupMembers.jsp?group="+groupID}
    };
%>
<%@ include file="title.jsp" %>

<font size="-1">
使用以下的表单向此用户组添加用户。
</font>

<p>

<font size="-1"><b>此用户组成员</b></font><p>
<ul>
<table bgcolor="<%= tblBorderColor %>" cellpadding="0" cellspacing="0" border="0" width="">
<tr><td>
<table bgcolor="<%= tblBorderColor %>" cellpadding="3" cellspacing="1" border="0" width="100%">
<tr bgcolor="#eeeeee">
    <td align="center"><font size="-2" face="verdana"><b>用户名</b></font></td>
    <td align="center"><font size="-2" face="verdana"><b>姓名</b></font></td>
    <td align="center"><font size="-2" face="verdana"><b>从组中删除</b></font></td>
</tr>
<%  while (members.hasNext()) {
        User member = (User)members.next();
        String name = member.getName();
%>
<tr bgcolor="#ffffff">
    <td><font size="-1"><%= member.getUsername() %></font></td>
    <td><font size="-1">&nbsp;<%= (name!=null)?name:"&nbsp;" %>&nbsp;</font></td>
    <td align="center"><a href="groupMembers.jsp?group=<%= groupID %>&remove=true&member=<%= member.getID() %>"><img src="images/button_delete.gif" width="17" height="17" alt="Click to remove this member from the group" border="0"></a></td>
</tr>
<%  } %>
</table>
</td></tr>
</table>
</ul>
<p>


<font size="-1"><b>向此用户组添加成员</b></font><p>
<form action="groupMembers.jsp">
<input type="hidden" name="group" value="<%= groupID %>">
<input type="hidden" name="add" value="true">
<ul>
    <table cellpadding="2" cellspacing="0" border="0">
    <tr>
    	<td><font size="-1">
            输入用户ID或者用户名列表，以逗号分隔(例如:john, user23, 58)。
            </font>
            <br>
            <textarea name="userList" cols="30" rows="6"></textarea>
        </td>
    </tr>
    <tr>
    	<td><br><input type="submit" value="加入到用户组"></td>
    </tr>
    </table>
</ul>
</form>
<p>


</body>
</html>




