muc-room-affiliations.jsp 12.5 KB
Newer Older
Gaston Dombiak's avatar
Gaston Dombiak committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<%--
  -	$RCSfile$
  -	$Revision$
  -	$Date$
  -
  - Copyright (C) 2004 Jive Software. All rights reserved.
  -
  - This software is the proprietary information of Jive Software.
  - Use is subject to license terms.
--%>

<%@ page import="org.jivesoftware.util.*,
                 java.util.*,
                 org.jivesoftware.messenger.*,
                 org.jivesoftware.admin.*,
                 java.util.Iterator,
                 org.jivesoftware.messenger.muc.*,
                 org.xmpp.packet.IQ,
                 org.dom4j.Element"
    errorPage="error.jsp"
%>

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
24
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
Gaston Dombiak's avatar
Gaston Dombiak committed
25 26 27 28 29 30 31 32 33 34 35 36 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
<jsp:useBean id="admin" class="org.jivesoftware.util.WebManager" />
<% admin.init(request, response, session, application, out ); %>

<%  // 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
    MUCRoom room = admin.getMultiUserChatServer().getChatRoom(roomName);

    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
                response.sendRedirect("muc-room-affiliations.jsp?addsuccess=true&roomName="+roomName);
                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
        response.sendRedirect("muc-room-affiliations.jsp?deletesuccess=true&roomName="+roomName);
        return;
        }
        catch (ConflictException e) {
            errors.put("ConflictException","ConflictException");
        }
    }
%>

<jsp:useBean id="pageinfo" scope="request" class="org.jivesoftware.admin.AdminPageBean" />
<%  // Title of this page and breadcrumbs
109
    String title = LocaleUtils.getLocalizedString("muc.room.affiliations.title");
Gaston Dombiak's avatar
Gaston Dombiak committed
110
    pageinfo.setTitle(title);
111 112
    pageinfo.getBreadcrumbs().add(new AdminPageBean.Breadcrumb(LocaleUtils.getLocalizedString("global.main"), "index.jsp"));
    pageinfo.getBreadcrumbs().add(new AdminPageBean.Breadcrumb(title, "muc-room-affiliations.jsp?roomName="+roomName));
Gaston Dombiak's avatar
Gaston Dombiak committed
113 114 115 116 117 118 119
    pageinfo.setSubPageID("muc-room-affiliations");
    pageinfo.setExtraParams("roomName="+roomName);
%>
<jsp:include page="top.jsp" flush="true" />
<jsp:include page="title.jsp" flush="true" />

<p>
120
<fmt:message key="muc.room.affiliations.info" />
Gaston Dombiak's avatar
Gaston Dombiak committed
121
<b><a href="muc-room-edit-form.jsp?roomName=<%= room.getName() %>"><%= room.getName() %></a></b>.
122
<fmt:message key="muc.room.affiliations.info_detail" />
Gaston Dombiak's avatar
Gaston Dombiak committed
123 124 125 126 127 128 129 130 131 132 133
</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")) { %>

134
        <fmt:message key="muc.room.affiliations.error_removing_user" />
Gaston Dombiak's avatar
Gaston Dombiak committed
135 136 137

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

138
        <fmt:message key="muc.room.affiliations.error_banning_user" />
Gaston Dombiak's avatar
Gaston Dombiak committed
139 140 141

        <%  } else { %>

142
        <fmt:message key="muc.room.affiliations.error_adding_user" />
Gaston Dombiak's avatar
Gaston Dombiak committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158

        <%  } %>
        </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) { %>

159
            <fmt:message key="muc.room.affiliations.user_added" />
Gaston Dombiak's avatar
Gaston Dombiak committed
160 161 162

        <%  } else if (deletesuccess) { %>

163
            <fmt:message key="muc.room.affiliations.user_removed" />
Gaston Dombiak's avatar
Gaston Dombiak committed
164 165 166 167 168 169 170 171 172 173 174 175 176

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

<%  } %>

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

<fieldset>
177
    <legend><fmt:message key="muc.room.affiliations.permission" /></legend>
Gaston Dombiak's avatar
Gaston Dombiak committed
178 179
    <div>
    <p>
180
    <label for="memberJID"><fmt:message key="muc.room.affiliations.add_jid" /></label>
Gaston Dombiak's avatar
Gaston Dombiak committed
181 182
    <input type="text" name="userJID" size="30" maxlength="100" value="<%= (userJID != null ? userJID : "") %>" id="memberJID">
    <select name="affiliation">
183 184 185 186
        <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
187
    </select>
188
    <input type="submit" value="<fmt:message key="global.add" />">
Gaston Dombiak's avatar
Gaston Dombiak committed
189 190 191 192 193 194
    </p>

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

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

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

        <%  if (room.getMembers().isEmpty()) { %>
            <tr>
264
                <td colspan="2" align="center"><i><fmt:message key="muc.room.affiliations.no_users" /></i></td>
Gaston Dombiak's avatar
Gaston Dombiak committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
                <td>&nbsp;</td>
            </tr>
        <%  }
            else {
                for (String user : room.getMembers()) {
                    String nickname = room.getReservedNickname(user);
                    nickname = (nickname == null ? "" : " (" + nickname + ")");
        %>
            <tr>
                <td>&nbsp;</td>
                <td>
                    <%= user %><%=  nickname %>
                </td>
                <td width="1%" align="center">
                    <a href="muc-room-affiliations.jsp?roomName=<%= roomName %>&userJID=<%= user %>&delete=true&affiliation=member"
280 281
                     title="<fmt:message key="muc.room.affiliations.click_delete" />"
                     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 299 300 301 302 303 304 305 306 307
                <td>&nbsp;</td>
            </tr>
        <%  }
            else {
                for (String user : room.getOutcasts()) {
        %>
            <tr>
                <td>&nbsp;</td>
                <td>
                    <%= user %>
                </td>
                <td width="1%" align="center">
                    <a href="muc-room-affiliations.jsp?roomName=<%= roomName %>&userJID=<%= user %>&delete=true&affiliation=outcast"
308 309
                     title="<fmt:message key="muc.room.affiliations.click_delete" />"
                     onclick="return confirm('<fmt:message key="muc.room.affiliations.confirm_removed" />');"
Gaston Dombiak's avatar
Gaston Dombiak committed
310 311 312 313 314 315 316 317 318 319 320 321 322
                     ><img src="images/delete-16x16.gif" width="16" height="16" border="0"></a>
                </td>
            </tr>
        <%  } } %>
    </tbody>
    </table>
    </div>
    </div>
</fieldset>

</form>

<jsp:include page="bottom.jsp" flush="true" />