user-roster.jsp 12.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<%--
  -	$Revision$
  -	$Date$
  -
  - Copyright (C) 2007 Jive Software. All rights reserved.
  -
  - This software is published under the terms of the GNU Public License (GPL),
  - a copy of which is included in this distribution.
--%>

<%@ page import="org.jivesoftware.util.ParamUtils,
                 org.jivesoftware.openfire.user.UserNotFoundException"
    errorPage="error.jsp"
%>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="org.jivesoftware.openfire.roster.Roster" %>
<%@ page import="org.jivesoftware.openfire.roster.RosterItem" %>
<%@ page import="org.jivesoftware.util.LocaleUtils" %>
<%@ page import="java.util.*" %>
20
<%@ page import="org.jivesoftware.openfire.group.Group" %>
21
<%@ page import="org.xmpp.packet.JID" %>
22 23 24 25 26 27 28 29 30 31 32 33 34

<%!
    final int DEFAULT_RANGE = 15;
    final int[] RANGE_PRESETS = {15, 25, 50, 75, 100};
%>

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" />

<%
    class RosterItemComparator implements Comparator<RosterItem> {
        public int compare(RosterItem itemA, RosterItem itemB) {
35
            return itemA.getJid().toBareJID().compareTo(itemB.getJid().toBareJID());
36 37 38 39 40 41
        }
    }
%>
<%  // Get parameters
    int start = ParamUtils.getIntParameter(request,"start",0);
    int range = ParamUtils.getIntParameter(request,"range",webManager.getRowsPerPage("user-roster", DEFAULT_RANGE));
42
    int filter = ParamUtils.getIntParameter(request,"filter",webManager.getPageProperty("user-roster", "filter", 0));
43 44 45 46 47

    if (request.getParameter("range") != null) {
        webManager.setRowsPerPage("user-roster", range);
    }

48 49 50 51
    if (request.getParameter("filter") != null) {
        webManager.setPageProperty("user-roster", "filter", filter);
    }

52 53 54 55 56 57 58 59
    // Get parameters //
    String username = ParamUtils.getParameter(request, "username");

    // Load the roster object
    Roster roster = null;
    int rosterCount = 0;
    try {
        roster = webManager.getRosterManager().getRoster(username);
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
        if (filter == 2) {
            for (RosterItem item : roster.getRosterItems()) {
                if (item.isOnlyShared()) {
                    rosterCount++;
                }
            }
        }
        else if (filter == 1) {
            for (RosterItem item : roster.getRosterItems()) {
                if (!item.isOnlyShared()) {
                    rosterCount++; 
                }
            }
        }
        else {
            rosterCount = roster.getRosterItems().size();
        }
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
    }
    catch (UserNotFoundException unfe) {
        // ignore
    }

    // paginator vars
    int numPages = (int)Math.ceil((double)rosterCount/(double)range);
    int curPage = (start/range) + 1;
%>

<html>
    <head>
        <title><fmt:message key="user.roster.title"/></title>
        <meta name="subPageID" content="user-roster"/>
        <meta name="extraParams" content="<%= "username="+URLEncoder.encode(username, "UTF-8") %>"/>
    </head>
    <body>

95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    <%  if (request.getParameter("addsuccess") != null) { %>

        <div class="jive-success">
        <table cellpadding="0" cellspacing="0" border="0">
        <tbody>
            <tr><td class="jive-icon"><img src="images/success-16x16.gif" alt="" width="16" height="16" border="0"></td>
            <td class="jive-icon-label">
            <fmt:message key="user.roster.added" />
            </td></tr>
        </tbody>
        </table>
        </div><br>

    <%  } %>

    <%  if (request.getParameter("editsuccess") != null) { %>

        <div class="jive-success">
        <table cellpadding="0" cellspacing="0" border="0">
        <tbody>
            <tr><td class="jive-icon"><img src="images/success-16x16.gif" alt="" width="16" height="16" border="0"></td>
            <td class="jive-icon-label">
            <fmt:message key="user.roster.edited" />
            </td></tr>
        </tbody>
        </table>
        </div><br>

    <%  } %>

125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    <%  if (request.getParameter("deletesuccess") != null) { %>

        <div class="jive-success">
        <table cellpadding="0" cellspacing="0" border="0">
        <tbody>
            <tr><td class="jive-icon"><img src="images/success-16x16.gif" alt="" width="16" height="16" border="0"></td>
            <td class="jive-icon-label">
            <fmt:message key="user.roster.deleted" />
            </td></tr>
        </tbody>
        </table>
        </div><br>

    <%  } %>

<p>
<fmt:message key="user.roster.info">
142
    <fmt:param value="<%= "<b>"+JID.unescapeNode(username)+"</b>" %>" />
143 144 145
</fmt:message>
</p>

146
<p style="margin-bottom: 2px">
147 148 149 150 151 152 153 154 155 156 157 158 159
<fmt:message key="user.roster.total_items" />:
<b><%= LocaleUtils.getLocalizedNumber(rosterCount) %></b> --

<%  if (numPages > 1) { %>

    <fmt:message key="global.showing" />
    <%= LocaleUtils.getLocalizedNumber(start+1) %>-<%= LocaleUtils.getLocalizedNumber(start+range > rosterCount ? rosterCount:start+range) %>,

<%  } %>
<fmt:message key="user.roster.sorted" />

<%  if (numPages > 1) { %>

160 161
    --

162 163 164 165 166 167 168 169 170 171 172 173
    <fmt:message key="global.pages" />:
    [
    <%  int num = 15 + curPage;
        int s = curPage-1;
        if (s > 5) {
            s -= 5;
        }
        if (s < 5) {
            s = 0;
        }
        if (s > 2) {
    %>
174
        <a href="user-roster.jsp?username=<%= URLEncoder.encode(username, "UTF-8") %>&start=0&range=<%= range %>&filter=<%= filter %>">1</a> ...
175 176 177

    <%
        }
178 179 180 181
        int i;
        for (i = s; i < numPages && i < num; i++) {
            String sep = ((i + 1) < numPages) ? " " : "";
            boolean isCurrent = (i + 1) == curPage;
182
    %>
183 184 185
        <a href="user-roster.jsp?username=<%= URLEncoder.encode(username, "UTF-8") %>&start=<%= (i*range) %>&range=<%= range %>&filter=<%= filter %>"
        class="<%= ((isCurrent) ? "jive-current" : "") %>"
        ><%= (i+1) %></a><%= sep %>
186 187 188 189 190

    <%  } %>

    <%  if (i < numPages) { %>

191
        ... <a href="user-roster.jsp?username=<%= URLEncoder.encode(username, "UTF-8") %>&start=<%= ((numPages-1)*range) %>&range=<%= range %>&filter=<%= filter %>"><%= numPages %></a>
192 193 194 195 196 197

    <%  } %>

    ]

<%  } %>
198
</p>
199

200 201
<div style="float:right; vertical-align: bottom; padding: 0; margin-bottom: 0; background-color: #ffffff; border: 0.0px solid #005500; vertical-align: middle">
    <a style="color: #007700; font-weight: bold; vertical-align: middle; text-decoration: none" href="user-roster-add.jsp?username=<%= URLEncoder.encode(username, "UTF-8") %>"><fmt:message key="user.roster.add"/><img style="position: relative; left: 3px; top: 3px" src="images/add-16x16.gif" alt="" width="16" height="16" border="0"></a>
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
</div>

<p style="margin-bottom: 2px">
    <fmt:message key="user.roster.items_per_page" />:
    <select size="1" onchange="location.href='user-roster.jsp?username=<%= URLEncoder.encode(username, "UTF-8") %>&start=0&range=' + this.options[this.selectedIndex].value;">

        <% for (int aRANGE_PRESETS : RANGE_PRESETS) { %>

        <option value="<%= aRANGE_PRESETS %>"
                <%= (aRANGE_PRESETS == range ? "selected" : "") %>><%= aRANGE_PRESETS %>
        </option>

        <% } %>

    </select>

    --

    <fmt:message key="user.roster.filter" />:
<select size="1" onchange="location.href='user-roster.jsp?username=<%= URLEncoder.encode(username, "UTF-8") %>&start=0&range=<%= range %>&filter=' + this.options[this.selectedIndex].value;">

    <option value="0"<%= filter == 0 ? " SELECTED" : "" %>><fmt:message key="user.roster.filter.all" /></option>
    <option value="1"<%= filter == 1 ? " SELECTED" : "" %>><fmt:message key="user.roster.filter.noshared" /></option>
    <option value="2"<%= filter == 2 ? " SELECTED" : "" %>><fmt:message key="user.roster.filter.onlyshared" /></option>

</select>
</p>

<div class="jive-table" style="clear: both">
231 232 233 234 235 236 237 238
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
    <tr>
        <th>&nbsp;</th>
        <th nowrap><fmt:message key="user.roster.jid" /></th>
        <th nowrap><fmt:message key="user.roster.nickname" /></th>
        <th nowrap><fmt:message key="user.roster.groups" /></th>
        <th nowrap><fmt:message key="user.roster.subscription" /></th>
239
        <th nowrap><fmt:message key="user.roster.edit" /></th>
240 241 242 243 244 245 246 247
        <th nowrap><fmt:message key="global.delete" /></th>
    </tr>
</thead>
<tbody>
    <%
        if (roster == null) {
    %>
    <tr>
248
        <td colspan="7" align="center">
249 250 251 252
            <fmt:message key="error.requested_user_not_found" />
        </td>
    </tr>
    <%
253
        } else if (rosterCount < 1) {
254 255
    %>
    <tr>
256
        <td colspan="7" align="center">
257 258 259 260 261 262 263 264 265
            <i><fmt:message key="user.roster.none_found" /></i>
        </td>
    </tr>
    <%
        } else {
            List<RosterItem> rosterItems = new ArrayList<RosterItem>(roster.getRosterItems());
            Collections.sort(rosterItems, new RosterItemComparator());
            int i = 0;
            for (RosterItem rosterItem : rosterItems) {
266 267 268 269 270 271
                if (filter == 2 && !rosterItem.isOnlyShared()) {
                    continue;
                }
                if (filter == 1 && rosterItem.isOnlyShared()) {
                    continue;
                }
272 273 274 275 276 277 278 279 280 281 282 283 284 285
                i++;
                if (i < start) {
                    continue;
                }
                if (i > start+range) {
                    break;
                }
    %>
    <tr class="jive-<%= (((i%2)==0) ? "even" : "odd") %>">

        <td width="1%">
            <%= i %>
        </td>
        <td>
286 287 288
            <a href="user-roster-view.jsp?username=<%= URLEncoder.encode(username, "UTF-8") %>&jid=<%= URLEncoder.encode(rosterItem.getJid().toString(), "UTF-8") %>"
             title="<fmt:message key="user.roster.click_view" />"
             ><%= rosterItem.getJid() %></a>
289 290 291 292 293 294 295
        </td>
        <td>
            <%= (rosterItem.getNickname() != null ? rosterItem.getNickname() : "<i>None</i>") %>
        </td>
        <td>
            <%
                List<String> groups = rosterItem.getGroups();
296 297
                int count = 0;
                if (!groups.isEmpty()) {
298 299 300 301 302 303 304 305
                    for (String group : groups) {
                        if (count != 0) {
                            out.print(", ");
                        }
                        out.print(group);
                        count++;
                    }
                }
306
                Collection<Group> sharedGroups = rosterItem.getSharedGroups();
307 308 309 310 311 312 313 314 315 316
                if (filter != 1) {
                    if (!sharedGroups.isEmpty()) {
                        for (Group group : sharedGroups) {
                            if (count != 0) {
                                out.print(", ");
                            }
                            out.print("<a style='text-decoration: underline' href='group-edit.jsp?group="+URLEncoder.encode(group.getName(), "UTF-8")+"'>");
                            out.print(group.getName());
                            out.print("</a>");
                            count++;
317 318 319 320 321 322 323 324
                        }
                    }
                }
                if (count == 0) {
            %>
                <i>None</i>
            <%
                }
325 326 327 328 329
            %>
        </td>
        <td>
            <%= rosterItem.getSubStatus().getName() %>
        </td>
330 331 332 333 334
        <td width="1%" align="center">
            <a href="user-roster-edit.jsp?username=<%= URLEncoder.encode(username, "UTF-8") %>&jid=<%= URLEncoder.encode(rosterItem.getJid().toString(), "UTF-8") %>"
             title="<fmt:message key="global.click_edit" />"
             ><img src="images/edit-16x16.gif" width="16" height="16" border="0" alt="<fmt:message key="global.click_edit" />"></a>
        </td>
335
        <td width="1%" align="center" style="border-right:1px #ccc solid;">
336
            <% if (sharedGroups.isEmpty()) { %>
337 338 339
            <a href="user-roster-delete.jsp?username=<%= URLEncoder.encode(username, "UTF-8") %>&jid=<%= URLEncoder.encode(rosterItem.getJid().toString(), "UTF-8") %>"
             title="<fmt:message key="global.click_delete" />"
             ><img src="images/delete-16x16.gif" width="16" height="16" border="0" alt="<fmt:message key="global.click_delete" />"></a>
340
            <% } else { %>
341
             <img onclick='alert("<fmt:message key="user.roster.cant_delete" />")' src="images/lock.gif" width="16" height="16" border="0" alt="">
342
            <% } %>
343 344 345 346 347 348 349 350 351 352 353 354 355 356
        </td>
    </tr>
    <%
            }
        }
    %>
</tbody>
</table>
</div>

<br><br>
    
</body>
</html>