user-roster.jsp 12.9 KB
Newer Older
1 2 3 4
<%--
  -	$Revision$
  -	$Date$
  -
5
  - Copyright (C) 2005-2008 Jive Software. All rights reserved.
6
  -
7 8 9 10 11 12 13 14 15 16 17
  - Licensed under the Apache License, Version 2.0 (the "License");
  - you may not use this file except in compliance with the License.
  - You may obtain a copy of the License at
  -
  -     http://www.apache.org/licenses/LICENSE-2.0
  -
  - Unless required by applicable law or agreed to in writing, software
  - distributed under the License is distributed on an "AS IS" BASIS,
  - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  - See the License for the specific language governing permissions and
  - limitations under the License.
18 19 20 21 22 23 24 25 26 27
--%>

<%@ 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" %>
28
<%@ page import="org.jivesoftware.util.StringUtils" %>
29
<%@ page import="java.util.*" %>
30
<%@ page import="org.jivesoftware.openfire.group.Group" %>
31
<%@ page import="org.xmpp.packet.JID" %>
32 33 34 35 36 37 38 39 40 41 42 43 44

<%!
    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) {
45
            return itemA.getJid().toBareJID().compareTo(itemB.getJid().toBareJID());
46 47 48 49 50 51
        }
    }
%>
<%  // Get parameters
    int start = ParamUtils.getIntParameter(request,"start",0);
    int range = ParamUtils.getIntParameter(request,"range",webManager.getRowsPerPage("user-roster", DEFAULT_RANGE));
52
    int filter = ParamUtils.getIntParameter(request,"filter",webManager.getPageProperty("user-roster", "filter", 0));
53 54 55 56 57

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

58 59 60 61
    if (request.getParameter("filter") != null) {
        webManager.setPageProperty("user-roster", "filter", filter);
    }

62 63 64 65 66 67 68 69
    // Get parameters //
    String username = ParamUtils.getParameter(request, "username");

    // Load the roster object
    Roster roster = null;
    int rosterCount = 0;
    try {
        roster = webManager.getRosterManager().getRoster(username);
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
        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();
        }
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
    }
    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>

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    <%  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>

    <%  } %>

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
    <%  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">
Sven Tantau's avatar
Sven Tantau committed
152
    <fmt:param value="<%= "<b>"+StringUtils.escapeForXML(JID.unescapeNode(username))+"</b>" %>" />
153 154 155
</fmt:message>
</p>

156
<p style="margin-bottom: 2px">
157 158 159 160 161 162 163 164 165 166 167 168 169
<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) { %>

170 171
    --

172 173 174 175 176 177 178 179 180 181 182 183
    <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) {
    %>
184
        <a href="user-roster.jsp?username=<%= URLEncoder.encode(username, "UTF-8") %>&start=0&range=<%= range %>&filter=<%= filter %>">1</a> ...
185 186 187

    <%
        }
188 189 190 191
        int i;
        for (i = s; i < numPages && i < num; i++) {
            String sep = ((i + 1) < numPages) ? " " : "";
            boolean isCurrent = (i + 1) == curPage;
192
    %>
193 194 195
        <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 %>
196 197 198 199 200

    <%  } %>

    <%  if (i < numPages) { %>

201
        ... <a href="user-roster.jsp?username=<%= URLEncoder.encode(username, "UTF-8") %>&start=<%= ((numPages-1)*range) %>&range=<%= range %>&filter=<%= filter %>"><%= numPages %></a>
202 203 204 205 206 207

    <%  } %>

    ]

<%  } %>
208
</p>
209

210 211
<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>
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
</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">
241 242 243 244 245 246 247 248
<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>
249
        <th nowrap><fmt:message key="user.roster.edit" /></th>
250 251 252 253 254 255 256 257
        <th nowrap><fmt:message key="global.delete" /></th>
    </tr>
</thead>
<tbody>
    <%
        if (roster == null) {
    %>
    <tr>
258
        <td colspan="7" align="center">
259 260 261 262
            <fmt:message key="error.requested_user_not_found" />
        </td>
    </tr>
    <%
263
        } else if (rosterCount < 1) {
264 265
    %>
    <tr>
266
        <td colspan="7" align="center">
267 268 269 270 271 272 273 274 275
            <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) {
276 277 278 279 280 281
                if (filter == 2 && !rosterItem.isOnlyShared()) {
                    continue;
                }
                if (filter == 1 && rosterItem.isOnlyShared()) {
                    continue;
                }
282 283 284 285 286 287 288 289 290 291 292 293 294 295
                i++;
                if (i < start) {
                    continue;
                }
                if (i > start+range) {
                    break;
                }
    %>
    <tr class="jive-<%= (((i%2)==0) ? "even" : "odd") %>">

        <td width="1%">
            <%= i %>
        </td>
        <td>
296 297 298
            <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>
299 300
        </td>
        <td>
Sven Tantau's avatar
Sven Tantau committed
301
            <%= (rosterItem.getNickname() != null ? StringUtils.escapeHTMLTags(rosterItem.getNickname()) : "<i>None</i>") %>
302 303 304 305
        </td>
        <td>
            <%
                List<String> groups = rosterItem.getGroups();
306 307
                int count = 0;
                if (!groups.isEmpty()) {
308 309 310 311
                    for (String group : groups) {
                        if (count != 0) {
                            out.print(", ");
                        }
312
                        out.print(StringUtils.escapeHTMLTags(group));
313 314 315
                        count++;
                    }
                }
316
                Collection<Group> sharedGroups = rosterItem.getSharedGroups();
317 318 319 320 321 322 323
                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")+"'>");
324
                            out.print(StringUtils.escapeHTMLTags(group.getName()));
325 326
                            out.print("</a>");
                            count++;
327 328 329 330 331 332 333 334
                        }
                    }
                }
                if (count == 0) {
            %>
                <i>None</i>
            <%
                }
335 336 337 338 339
            %>
        </td>
        <td>
            <%= rosterItem.getSubStatus().getName() %>
        </td>
340 341 342 343 344
        <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>
345
        <td width="1%" align="center" style="border-right:1px #ccc solid;">
346
            <% if (sharedGroups.isEmpty()) { %>
347 348 349
            <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>
350
            <% } else { %>
351
             <img onclick='alert("<fmt:message key="user.roster.cant_delete" />")' src="images/lock.gif" width="16" height="16" border="0" alt="">
352
            <% } %>
353 354 355 356 357 358 359 360 361 362 363 364 365
        </td>
    </tr>
    <%
            }
        }
    %>
</tbody>
</table>
</div>

<br><br>
    
</body>
Sven Tantau's avatar
Sven Tantau committed
366
</html>