muc-room-affiliations.jsp 15.1 KB
Newer Older
Gaston Dombiak's avatar
Gaston Dombiak committed
1 2 3 4
<%--
  -	$Revision$
  -	$Date$
  -
5
  - Copyright (C) 2004-2008 Jive Software. All rights reserved.
Gaston Dombiak's avatar
Gaston Dombiak committed
6
  -
7 8 9
  - This software is published under the terms of the GNU Public License (GPL),
  - a copy of which is included in this distribution, or a commercial license
  - agreement with Jive.
Gaston Dombiak's avatar
Gaston Dombiak committed
10 11
--%>

12 13 14 15 16 17
<%@ page import="org.dom4j.Element,
                 org.jivesoftware.openfire.muc.ConflictException,
                 org.jivesoftware.openfire.muc.MUCRoom,
                 org.jivesoftware.openfire.muc.NotAllowedException,
                 org.jivesoftware.util.ParamUtils,
                 org.xmpp.packet.IQ"
Gaston Dombiak's avatar
Gaston Dombiak committed
18 19
    errorPage="error.jsp"
%>
20 21 22 23 24 25
<%@ page import="org.xmpp.packet.JID" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Collections" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
26
<%@ page import="org.jivesoftware.openfire.muc.CannotBeInvitedException" %>
Gaston Dombiak's avatar
Gaston Dombiak committed
27 28

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

<%  // Get parameters
34
    JID roomJID = new JID(ParamUtils.getParameter(request,"roomJID"));
Gaston Dombiak's avatar
Gaston Dombiak committed
35 36
    String affiliation = ParamUtils.getParameter(request,"affiliation");
    String userJID = ParamUtils.getParameter(request,"userJID");
37
    String roomName = roomJID.getNode();
Gaston Dombiak's avatar
Gaston Dombiak committed
38 39 40 41 42 43 44

    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
45
    MUCRoom room = webManager.getMultiUserChatManager().getMultiUserChatService(roomJID).getChatRoom(roomName);
Gaston Dombiak's avatar
Gaston Dombiak committed
46 47 48

    if (room == null) {
        // The requested room name does not exist so return to the list of the existing rooms
49
        response.sendRedirect("muc-room-summary.jsp?roomJID="+URLEncoder.encode(roomJID.toBareJID(), "UTF-8"));
Gaston Dombiak's avatar
Gaston Dombiak committed
50 51 52
        return;
    }

53
    Map<String,String> errors = new HashMap<String,String>();
Gaston Dombiak's avatar
Gaston Dombiak committed
54 55 56
    // Handle an add
    if (add) {
        // do validation
57
        if (userJID == null) {
Gaston Dombiak's avatar
Gaston Dombiak committed
58 59
            errors.put("userJID","userJID");
        }
60 61 62
        else if (userJID.indexOf('@') == -1) {
            userJID = webManager.getXMPPServer().createJID(userJID, null).toBareJID();
        }
Gaston Dombiak's avatar
Gaston Dombiak committed
63 64 65

        if (errors.size() == 0) {
            try {
66 67 68 69
                // Escape username
                String username = JID.escapeNode(userJID.substring(0, userJID.indexOf('@')));
                String rest = userJID.substring(userJID.indexOf('@'), userJID.length());
                userJID = username + rest;
Gaston Dombiak's avatar
Gaston Dombiak committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
                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());
                }
87 88
                // Log the event
                webManager.logEvent("set MUC affilation to "+affiliation+" for "+userJID+" in "+roomName, null);
Gaston Dombiak's avatar
Gaston Dombiak committed
89
                // done, return
90
                response.sendRedirect("muc-room-affiliations.jsp?addsuccess=true&roomJID="+URLEncoder.encode(roomJID.toBareJID(), "UTF-8"));
Gaston Dombiak's avatar
Gaston Dombiak committed
91 92 93 94 95 96 97 98
                return;
            }
            catch (ConflictException e) {
                errors.put("ConflictException","ConflictException");
            }
            catch (NotAllowedException e) {
                errors.put("NotAllowedException","NotAllowedException");
            }
99 100 101
            catch (CannotBeInvitedException e) {
                errors.put("CannotBeInvitedException", "CannotBeInvitedExcpetion");
            }
Gaston Dombiak's avatar
Gaston Dombiak committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115
        }
    }

    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
116
        response.sendRedirect("muc-room-affiliations.jsp?deletesuccess=true&roomJID="+URLEncoder.encode(roomJID.toBareJID(), "UTF-8"));
Gaston Dombiak's avatar
Gaston Dombiak committed
117 118 119 120 121
        return;
        }
        catch (ConflictException e) {
            errors.put("ConflictException","ConflictException");
        }
122 123 124
        catch (CannotBeInvitedException e) {
                errors.put("CannotBeInvitedException", "CannotBeInvitedExcpetion");
        }
Gaston Dombiak's avatar
Gaston Dombiak committed
125 126 127
    }
%>

128 129 130 131
<html>
    <head>
        <title><fmt:message key="muc.room.affiliations.title"/></title>
        <meta name="subPageID" content="muc-room-affiliations"/>
132
        <meta name="extraParams" content="<%= "roomJID="+URLEncoder.encode(roomJID.toBareJID(), "UTF-8") %>"/>
133 134 135
        <meta name="helpPage" content="edit_group_chat_room_user_permissions.html"/>
    </head>
    <body>
Gaston Dombiak's avatar
Gaston Dombiak committed
136 137

<p>
138
<fmt:message key="muc.room.affiliations.info" />
139
<b><a href="muc-room-edit-form.jsp?roomJID=<%= URLEncoder.encode(room.getJID().toBareJID(), "UTF-8") %>"><%= room.getJID().toBareJID() %></a></b>.
140
<fmt:message key="muc.room.affiliations.info_detail" />
Gaston Dombiak's avatar
Gaston Dombiak committed
141 142 143 144 145 146 147
</p>

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

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
148
        <tr><td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0" alt=""></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
149 150 151
        <td class="jive-icon-label">
        <%  if (errors.containsKey("ConflictException")) { %>

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

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

156
        <fmt:message key="muc.room.affiliations.error_banning_user" />
Gaston Dombiak's avatar
Gaston Dombiak committed
157 158 159

        <%  } else { %>

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

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

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

    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
173
        <tr><td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0" alt=""></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
174 175 176
        <td class="jive-icon-label">
        <%  if (addsuccess) { %>

177
            <fmt:message key="muc.room.affiliations.user_added" />
Gaston Dombiak's avatar
Gaston Dombiak committed
178 179 180

        <%  } else if (deletesuccess) { %>

181
            <fmt:message key="muc.room.affiliations.user_removed" />
Gaston Dombiak's avatar
Gaston Dombiak committed
182 183 184 185 186 187 188 189 190 191

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

<%  } %>

<form action="muc-room-affiliations.jsp?add" method="post">
192
<input type="hidden" name="roomJID" value="<%= roomJID.toBareJID() %>">
Gaston Dombiak's avatar
Gaston Dombiak committed
193 194

<fieldset>
195
    <legend><fmt:message key="muc.room.affiliations.permission" /></legend>
Gaston Dombiak's avatar
Gaston Dombiak committed
196 197
    <div>
    <p>
198
    <label for="memberJID"><fmt:message key="muc.room.affiliations.add_jid" /></label>
Gaston Dombiak's avatar
Gaston Dombiak committed
199 200
    <input type="text" name="userJID" size="30" maxlength="100" value="<%= (userJID != null ? userJID : "") %>" id="memberJID">
    <select name="affiliation">
201 202 203 204
        <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
205
    </select>
206
    <input type="submit" value="<fmt:message key="global.add" />">
Gaston Dombiak's avatar
Gaston Dombiak committed
207 208 209 210 211 212
    </p>

    <div class="jive-table" style="width:400px;">
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <thead>
        <tr>
213
            <th colspan="2"><fmt:message key="muc.room.affiliations.user" /></th>
214
            <th width="1%"><fmt:message key="global.delete" /></th>
Gaston Dombiak's avatar
Gaston Dombiak committed
215 216 217 218 219
        </tr>
    </thead>
    <tbody>
    <%-- Add owners section --%>
            <tr>
220
                <td colspan="2"><b><fmt:message key="muc.room.affiliations.room_owner" /></b></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
221 222 223 224 225
                <td>&nbsp;</td>
            </tr>

        <%  if (room.getOwners().isEmpty()) { %>
            <tr>
226
                <td colspan="2" align="center"><i><fmt:message key="muc.room.affiliations.no_users" /></i></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
227 228 229 230
                <td>&nbsp;</td>
            </tr>
        <%  }
            else {
Matt Tucker's avatar
Matt Tucker committed
231 232 233
                ArrayList<String> owners = new ArrayList<String>(room.getOwners());
                Collections.sort(owners);
                for (String user : owners) {
234 235 236 237
                    String username = JID.unescapeNode(user.substring(0, user.indexOf('@')));
                    String rest = user.substring(user.indexOf('@'), user.length());
                    String userDisplay = username + rest;

Gaston Dombiak's avatar
Gaston Dombiak committed
238 239 240 241
        %>
            <tr>
                <td>&nbsp;</td>
                <td>
242
                    <%= userDisplay %>
Gaston Dombiak's avatar
Gaston Dombiak committed
243 244
                </td>
                <td width="1%" align="center">
245
                    <a href="muc-room-affiliations.jsp?roomJID=<%= URLEncoder.encode(roomJID.toBareJID(), "UTF-8") %>&userJID=<%= user %>&delete=true&affiliation=owner"
246
                     title="<fmt:message key="global.click_delete" />"
247
                     onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');"
248
                     ><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a>
Gaston Dombiak's avatar
Gaston Dombiak committed
249 250 251 252 253
                </td>
            </tr>
        <%  } } %>
    <%-- Add admins section --%>
            <tr>
254
                <td colspan="2"><b><fmt:message key="muc.room.affiliations.room_admin" /></b></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
255 256 257 258 259
                <td>&nbsp;</td>
            </tr>

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

        <%  if (room.getMembers().isEmpty()) { %>
            <tr>
293
                <td colspan="2" align="center"><i><fmt:message key="muc.room.affiliations.no_users" /></i></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
294 295 296 297
                <td>&nbsp;</td>
            </tr>
        <%  }
            else {
Matt Tucker's avatar
Matt Tucker committed
298 299 300
                ArrayList<String> members = new ArrayList<String>(room.getMembers());
                Collections.sort(members);
                for (String user : members) {
301 302 303 304
                    String username = JID.unescapeNode(user.substring(0, user.indexOf('@')));
                    String rest = user.substring(user.indexOf('@'), user.length());
                    String userDisplay = username + rest;

Gaston Dombiak's avatar
Gaston Dombiak committed
305 306 307 308 309 310
                    String nickname = room.getReservedNickname(user);
                    nickname = (nickname == null ? "" : " (" + nickname + ")");
        %>
            <tr>
                <td>&nbsp;</td>
                <td>
311
                    <%= userDisplay %><%=  nickname %>
Gaston Dombiak's avatar
Gaston Dombiak committed
312 313
                </td>
                <td width="1%" align="center">
314
                    <a href="muc-room-affiliations.jsp?roomJID=<%= URLEncoder.encode(roomJID.toBareJID(), "UTF-8") %>&userJID=<%= user %>&delete=true&affiliation=member"
315
                     title="<fmt:message key="global.click_delete" />"
316
                     onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');"
317
                     ><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a>
Gaston Dombiak's avatar
Gaston Dombiak committed
318 319 320 321 322
                </td>
            </tr>
        <%  } } %>
    <%-- Add outcasts section --%>
            <tr>
323
                <td colspan="2"><b><fmt:message key="muc.room.affiliations.room_outcast" /></b></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
324 325 326 327 328
                <td>&nbsp;</td>
            </tr>

        <%  if (room.getOutcasts().isEmpty()) { %>
            <tr>
329
                <td colspan="2" align="center"><i><fmt:message key="muc.room.affiliations.no_users" /></i></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
330 331 332 333
                <td>&nbsp;</td>
            </tr>
        <%  }
            else {
Matt Tucker's avatar
Matt Tucker committed
334 335 336
                ArrayList<String> outcasts = new ArrayList<String>(room.getOutcasts());
                Collections.sort(outcasts);
                for (String user : outcasts) {
337 338 339
                    String username = JID.unescapeNode(user.substring(0, user.indexOf('@')));
                    String rest = user.substring(user.indexOf('@'), user.length());
                    String userDisplay = username + rest;
Gaston Dombiak's avatar
Gaston Dombiak committed
340 341 342 343
        %>
            <tr>
                <td>&nbsp;</td>
                <td>
344
                    <%= userDisplay %>
Gaston Dombiak's avatar
Gaston Dombiak committed
345 346
                </td>
                <td width="1%" align="center">
347
                    <a href="muc-room-affiliations.jsp?roomJID=<%= URLEncoder.encode(roomJID.toBareJID(), "UTF-8") %>&userJID=<%= user %>&delete=true&affiliation=outcast"
348
                     title="<fmt:message key="global.click_delete" />"
349
                     onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');"
350
                     ><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt=""></a>
Gaston Dombiak's avatar
Gaston Dombiak committed
351 352 353 354 355 356 357 358 359 360 361
                </td>
            </tr>
        <%  } } %>
    </tbody>
    </table>
    </div>
    </div>
</fieldset>

</form>

362 363
    </body>
</html>