muc-room-affiliations.jsp 12.6 KB
Newer Older
Gaston Dombiak's avatar
Gaston Dombiak committed
1 2 3 4
<%--
  -	$Revision$
  -	$Date$
  -
5
  - Copyright (C) 2004-2005 Jive Software. All rights reserved.
Gaston Dombiak's avatar
Gaston Dombiak committed
6 7 8 9 10 11 12
  -
  - This software is the proprietary information of Jive Software.
  - Use is subject to license terms.
--%>

<%@ page import="org.jivesoftware.util.*,
                 java.util.*,
13
                 org.jivesoftware.wildfire.muc.*,
Gaston Dombiak's avatar
Gaston Dombiak committed
14
                 org.xmpp.packet.IQ,
Gaston Dombiak's avatar
Gaston Dombiak committed
15 16
                 org.dom4j.Element,
                 java.net.URLEncoder"
Gaston Dombiak's avatar
Gaston Dombiak committed
17 18 19 20
    errorPage="error.jsp"
%>

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
21
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
22 23
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" />
<% webManager.init(request, response, session, application, out ); %>
Gaston Dombiak's avatar
Gaston Dombiak committed
24 25 26 27 28 29 30 31 32 33 34 35

<%  // Get parameters
    String roomName = ParamUtils.getParameter(request,"roomName");
    String affiliation = ParamUtils.getParameter(request,"affiliation");
    String userJID = ParamUtils.getParameter(request,"userJID");

    boolean add = request.getParameter("add") != null;
    boolean addsuccess = request.getParameter("addsuccess") != null;
    boolean deletesuccess = request.getParameter("deletesuccess") != null;
    boolean delete = ParamUtils.getBooleanParameter(request,"delete");

    // Load the room object
36
    MUCRoom room = webManager.getMultiUserChatServer().getChatRoom(roomName);
Gaston Dombiak's avatar
Gaston Dombiak committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

    if (room == null) {
        // The requested room name does not exist so return to the list of the existing rooms
        response.sendRedirect("muc-room-summary.jsp");
        return;
    }

    Map errors = new HashMap();
    // Handle an add
    if (add) {
        // do validation
        if (userJID == null || userJID.indexOf('@') == -1) {
            errors.put("userJID","userJID");
        }

        if (errors.size() == 0) {
            try {
                IQ iq = new IQ(IQ.Type.set);
                if ("owner".equals(affiliation) || "admin".equals(affiliation)) {
                    Element frag = iq.setChildElement("query", "http://jabber.org/protocol/muc#owner");
                    Element item = frag.addElement("item");
                    item.addAttribute("affiliation", affiliation);
                    item.addAttribute("jid", userJID);
                    // Send the IQ packet that will modify the room's configuration
                    room.getIQOwnerHandler().handleIQ(iq, room.getRole());
                }
                else if ("member".equals(affiliation) || "outcast".equals(affiliation)) {
                    Element frag = iq.setChildElement("query", "http://jabber.org/protocol/muc#admin");
                    Element item = frag.addElement("item");
                    item.addAttribute("affiliation", affiliation);
                    item.addAttribute("jid", userJID);
                    // Send the IQ packet that will modify the room's configuration
                    room.getIQAdminHandler().handleIQ(iq, room.getRole());
                }
                // done, return
Gaston Dombiak's avatar
Gaston Dombiak committed
72
                response.sendRedirect("muc-room-affiliations.jsp?addsuccess=true&roomName="+URLEncoder.encode(roomName, "UTF-8"));
Gaston Dombiak's avatar
Gaston Dombiak committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
                return;
            }
            catch (ConflictException e) {
                errors.put("ConflictException","ConflictException");
            }
            catch (NotAllowedException e) {
                errors.put("NotAllowedException","NotAllowedException");
            }
        }
    }

    if (delete) {
        // Remove the user from the allowed list
        IQ iq = new IQ(IQ.Type.set);
        Element frag = iq.setChildElement("query", "http://jabber.org/protocol/muc#admin");
        Element item = frag.addElement("item");
        item.addAttribute("affiliation", "none");
        item.addAttribute("jid", userJID);
        try {
        // Send the IQ packet that will modify the room's configuration
        room.getIQOwnerHandler().handleIQ(iq, room.getRole());
        // done, return
Gaston Dombiak's avatar
Gaston Dombiak committed
95
        response.sendRedirect("muc-room-affiliations.jsp?deletesuccess=true&roomName="+URLEncoder.encode(roomName, "UTF-8"));
Gaston Dombiak's avatar
Gaston Dombiak committed
96 97 98 99 100 101 102 103
        return;
        }
        catch (ConflictException e) {
            errors.put("ConflictException","ConflictException");
        }
    }
%>

104 105 106 107 108 109 110 111
<html>
    <head>
        <title><fmt:message key="muc.room.affiliations.title"/></title>
        <meta name="subPageID" content="muc-room-affiliations"/>
        <meta name="extraParams" content="<%= "roomName="+URLEncoder.encode(roomName, "UTF-8") %>"/>
        <meta name="helpPage" content="edit_group_chat_room_user_permissions.html"/>
    </head>
    <body>
Gaston Dombiak's avatar
Gaston Dombiak committed
112 113

<p>
114
<fmt:message key="muc.room.affiliations.info" />
Gaston Dombiak's avatar
Gaston Dombiak committed
115
<b><a href="muc-room-edit-form.jsp?roomName=<%= URLEncoder.encode(room.getName(), "UTF-8") %>"><%= room.getName() %></a></b>.
116
<fmt:message key="muc.room.affiliations.info_detail" />
Gaston Dombiak's avatar
Gaston Dombiak committed
117 118 119 120 121 122 123 124 125 126 127
</p>

<%  if (errors.size() > 0) { %>

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr><td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0"></td>
        <td class="jive-icon-label">
        <%  if (errors.containsKey("ConflictException")) { %>

128
        <fmt:message key="muc.room.affiliations.error_removing_user" />
Gaston Dombiak's avatar
Gaston Dombiak committed
129 130 131

        <%  } else if (errors.containsKey("NotAllowedException")) { %>

132
        <fmt:message key="muc.room.affiliations.error_banning_user" />
Gaston Dombiak's avatar
Gaston Dombiak committed
133 134 135

        <%  } else { %>

136
        <fmt:message key="muc.room.affiliations.error_adding_user" />
Gaston Dombiak's avatar
Gaston Dombiak committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152

        <%  } %>
        </td></tr>
    </tbody>
    </table>
    </div><br>

<%  } else if (addsuccess || deletesuccess) { %>

    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr><td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0"></td>
        <td class="jive-icon-label">
        <%  if (addsuccess) { %>

153
            <fmt:message key="muc.room.affiliations.user_added" />
Gaston Dombiak's avatar
Gaston Dombiak committed
154 155 156

        <%  } else if (deletesuccess) { %>

157
            <fmt:message key="muc.room.affiliations.user_removed" />
Gaston Dombiak's avatar
Gaston Dombiak committed
158 159 160 161 162 163 164 165 166 167 168 169 170

        <%  } %>
        </td></tr>
    </tbody>
    </table>
    </div><br>

<%  } %>

<form action="muc-room-affiliations.jsp?add" method="post">
<input type="hidden" name="roomName" value="<%= roomName %>">

<fieldset>
171
    <legend><fmt:message key="muc.room.affiliations.permission" /></legend>
Gaston Dombiak's avatar
Gaston Dombiak committed
172 173
    <div>
    <p>
174
    <label for="memberJID"><fmt:message key="muc.room.affiliations.add_jid" /></label>
Gaston Dombiak's avatar
Gaston Dombiak committed
175 176
    <input type="text" name="userJID" size="30" maxlength="100" value="<%= (userJID != null ? userJID : "") %>" id="memberJID">
    <select name="affiliation">
177 178 179 180
        <option value="owner"><fmt:message key="muc.room.affiliations.owner" /></option>
        <option value="admin"><fmt:message key="muc.room.affiliations.admin" /></option>
        <option value="member"><fmt:message key="muc.room.affiliations.member" /></option>
        <option value="outcast"><fmt:message key="muc.room.affiliations.outcast" /></option>
Gaston Dombiak's avatar
Gaston Dombiak committed
181
    </select>
182
    <input type="submit" value="<fmt:message key="global.add" />">
Gaston Dombiak's avatar
Gaston Dombiak committed
183 184 185 186 187 188
    </p>

    <div class="jive-table" style="width:400px;">
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <thead>
        <tr>
189
            <th colspan="2"><fmt:message key="muc.room.affiliations.user" /></th>
190
            <th width="1%"><fmt:message key="global.delete" /></th>
Gaston Dombiak's avatar
Gaston Dombiak committed
191 192 193 194 195
        </tr>
    </thead>
    <tbody>
    <%-- Add owners section --%>
            <tr>
196
                <td colspan="2"><b><fmt:message key="muc.room.affiliations.room_owner" /></b></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
197 198 199 200 201
                <td>&nbsp;</td>
            </tr>

        <%  if (room.getOwners().isEmpty()) { %>
            <tr>
202
                <td colspan="2" align="center"><i><fmt:message key="muc.room.affiliations.no_users" /></i></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
203 204 205 206
                <td>&nbsp;</td>
            </tr>
        <%  }
            else {
Matt Tucker's avatar
Matt Tucker committed
207 208 209
                ArrayList<String> owners = new ArrayList<String>(room.getOwners());
                Collections.sort(owners);
                for (String user : owners) {
Gaston Dombiak's avatar
Gaston Dombiak committed
210 211 212 213 214 215 216
        %>
            <tr>
                <td>&nbsp;</td>
                <td>
                    <%= user %>
                </td>
                <td width="1%" align="center">
Gaston Dombiak's avatar
Gaston Dombiak committed
217
                    <a href="muc-room-affiliations.jsp?roomName=<%= URLEncoder.encode(roomName, "UTF-8") %>&userJID=<%= user %>&delete=true&affiliation=owner"
218
                     title="<fmt:message key="global.click_delete" />"
219
                     onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');"
Gaston Dombiak's avatar
Gaston Dombiak committed
220 221 222 223 224 225
                     ><img src="images/delete-16x16.gif" width="16" height="16" border="0"></a>
                </td>
            </tr>
        <%  } } %>
    <%-- Add admins section --%>
            <tr>
226
                <td colspan="2"><b><fmt:message key="muc.room.affiliations.room_admin" /></b></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
227 228 229 230 231
                <td>&nbsp;</td>
            </tr>

        <%  if (room.getAdmins().isEmpty()) { %>
            <tr>
232
                <td colspan="2" align="center"><i><fmt:message key="muc.room.affiliations.no_users" /></i></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
233 234 235 236
                <td>&nbsp;</td>
            </tr>
        <%  }
            else {
Matt Tucker's avatar
Matt Tucker committed
237 238 239
                ArrayList<String> admins = new ArrayList<String>(room.getAdmins());
                Collections.sort(admins);
                for (String user : admins) {
Gaston Dombiak's avatar
Gaston Dombiak committed
240 241 242 243 244 245 246
        %>
            <tr>
                <td>&nbsp;</td>
                <td>
                    <%= user %>
                </td>
                <td width="1%" align="center">
Gaston Dombiak's avatar
Gaston Dombiak committed
247
                    <a href="muc-room-affiliations.jsp?roomName=<%= URLEncoder.encode(roomName, "UTF-8") %>&userJID=<%= user %>&delete=true&affiliation=admin"
248
                     title="<fmt:message key="global.click_delete" />"
249
                     onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');"
Gaston Dombiak's avatar
Gaston Dombiak committed
250 251 252 253 254 255
                     ><img src="images/delete-16x16.gif" width="16" height="16" border="0"></a>
                </td>
            </tr>
        <%  } } %>
    <%-- Add members section --%>
            <tr>
256
                <td colspan="2"><b><fmt:message key="muc.room.affiliations.room_member" /></b></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
257 258 259 260 261
                <td>&nbsp;</td>
            </tr>

        <%  if (room.getMembers().isEmpty()) { %>
            <tr>
262
                <td colspan="2" align="center"><i><fmt:message key="muc.room.affiliations.no_users" /></i></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
263 264 265 266
                <td>&nbsp;</td>
            </tr>
        <%  }
            else {
Matt Tucker's avatar
Matt Tucker committed
267 268 269
                ArrayList<String> members = new ArrayList<String>(room.getMembers());
                Collections.sort(members);
                for (String user : members) {
Gaston Dombiak's avatar
Gaston Dombiak committed
270 271 272 273 274 275 276 277 278
                    String nickname = room.getReservedNickname(user);
                    nickname = (nickname == null ? "" : " (" + nickname + ")");
        %>
            <tr>
                <td>&nbsp;</td>
                <td>
                    <%= user %><%=  nickname %>
                </td>
                <td width="1%" align="center">
Gaston Dombiak's avatar
Gaston Dombiak committed
279
                    <a href="muc-room-affiliations.jsp?roomName=<%= URLEncoder.encode(roomName, "UTF-8") %>&userJID=<%= user %>&delete=true&affiliation=member"
280
                     title="<fmt:message key="global.click_delete" />"
281
                     onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');"
Gaston Dombiak's avatar
Gaston Dombiak committed
282 283 284 285 286 287
                     ><img src="images/delete-16x16.gif" width="16" height="16" border="0"></a>
                </td>
            </tr>
        <%  } } %>
    <%-- Add outcasts section --%>
            <tr>
288
                <td colspan="2"><b><fmt:message key="muc.room.affiliations.room_outcast" /></b></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
289 290 291 292 293
                <td>&nbsp;</td>
            </tr>

        <%  if (room.getOutcasts().isEmpty()) { %>
            <tr>
294
                <td colspan="2" align="center"><i><fmt:message key="muc.room.affiliations.no_users" /></i></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
295 296 297 298
                <td>&nbsp;</td>
            </tr>
        <%  }
            else {
Matt Tucker's avatar
Matt Tucker committed
299 300 301
                ArrayList<String> outcasts = new ArrayList<String>(room.getOutcasts());
                Collections.sort(outcasts);
                for (String user : outcasts) {
Gaston Dombiak's avatar
Gaston Dombiak committed
302 303 304 305 306 307 308
        %>
            <tr>
                <td>&nbsp;</td>
                <td>
                    <%= user %>
                </td>
                <td width="1%" align="center">
Gaston Dombiak's avatar
Gaston Dombiak committed
309
                    <a href="muc-room-affiliations.jsp?roomName=<%= URLEncoder.encode(roomName, "UTF-8") %>&userJID=<%= user %>&delete=true&affiliation=outcast"
310
                     title="<fmt:message key="global.click_delete" />"
311
                     onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');"
Gaston Dombiak's avatar
Gaston Dombiak committed
312 313 314 315 316 317 318 319 320 321 322 323
                     ><img src="images/delete-16x16.gif" width="16" height="16" border="0"></a>
                </td>
            </tr>
        <%  } } %>
    </tbody>
    </table>
    </div>
    </div>
</fieldset>

</form>

324 325
    </body>
</html>