user-message.jsp 7.82 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3
<%--
  -	$Revision$
  -	$Date$
Bill Lynch's avatar
Bill Lynch committed
4
  -
5
  - Copyright (C) 2004-2005 Jive Software. All rights reserved.
Bill Lynch's avatar
Bill Lynch committed
6 7 8
  -
  - This software is published under the terms of the GNU Public License (GPL),
  - a copy of which is included in this distribution.
Matt Tucker's avatar
Matt Tucker committed
9 10 11
--%>

<%@ page import="org.jivesoftware.util.*,
Matt Tucker's avatar
Matt Tucker committed
12
                 java.util.*,
13
                 org.jivesoftware.wildfire.*,
Derek DeMoro's avatar
Derek DeMoro committed
14
                 org.jivesoftware.admin.*,
Matt Tucker's avatar
Matt Tucker committed
15
                 java.util.HashMap,
16
                 org.jivesoftware.wildfire.user.*,
Derek DeMoro's avatar
Derek DeMoro committed
17
                 java.util.Map,
18 19
                 org.xmpp.packet.JID,
                 java.net.URLEncoder"
Bill Lynch's avatar
Bill Lynch committed
20 21
    errorPage="error.jsp"
%>
Matt Tucker's avatar
Matt Tucker committed
22

23
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
24
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
Matt Tucker's avatar
Matt Tucker committed
25
<%  // Get parameters
26
    String username = ParamUtils.getParameter(request,"username");
Matt Tucker's avatar
Matt Tucker committed
27 28 29 30 31 32 33 34 35 36
    boolean send = ParamUtils.getBooleanParameter(request,"send");
    boolean success = ParamUtils.getBooleanParameter(request,"success");
    boolean sendToAll = ParamUtils.getBooleanParameter(request,"sendToAll");
    boolean tabs = ParamUtils.getBooleanParameter(request,"tabs",true);
    String jid = ParamUtils.getParameter(request,"jid");
    String[] jids = ParamUtils.getParameters(request,"jid");
    String sessionID = ParamUtils.getParameter(request,"sessionID");
    String message = ParamUtils.getParameter(request,"message");
%>

Derek DeMoro's avatar
Derek DeMoro committed
37
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager"  />
Derek DeMoro's avatar
Derek DeMoro committed
38
<% webManager.init(pageContext); %>
Matt Tucker's avatar
Matt Tucker committed
39 40 41 42

<%
    // Handle a cancel
    if (request.getParameter("cancel") != null) {
43
        if (username == null) {
Matt Tucker's avatar
Matt Tucker committed
44 45 46 47
            response.sendRedirect("session-summary.jsp");
            return;
        }
        else {
48
            response.sendRedirect("user-properties.jsp?username=" + URLEncoder.encode(username, "UTF-8"));
Matt Tucker's avatar
Matt Tucker committed
49 50 51 52 53 54
            return;
        }
    }

    // Get the user - a user might not be passed in if this is a system-wide message
    User user = null;
55
    if (username != null) {
Derek DeMoro's avatar
Derek DeMoro committed
56
        user = webManager.getUserManager().getUser(username);
Matt Tucker's avatar
Matt Tucker committed
57 58 59
    }

    // Get the session manager
Derek DeMoro's avatar
Derek DeMoro committed
60
    SessionManager sessionManager = webManager.getSessionManager();
Matt Tucker's avatar
Matt Tucker committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

    // Handle the request to send a message:
    Map errors = new HashMap();
    if (send) {
        // Validate the message and jid
        if (jid == null && !sendToAll && user != null) {
            errors.put("jid","jid");
        }
        if (message == null) {
            errors.put("message","message");
        }
        if (errors.size() == 0) {
            // no errors, so continue
            if (user == null) {
                // system-wide message:
                sessionManager.sendServerMessage(null,message);
            }
            else {
                if (sendToAll) {
                    // loop through all sessions based on the user assoc with the JID, send
                    // message to all
                    for (int i=0; i<jids.length; i++) {
Derek DeMoro's avatar
Derek DeMoro committed
83
                        JID address = new JID(jids[i]);
Matt Tucker's avatar
Matt Tucker committed
84 85 86 87 88
                        Session s = sessionManager.getSession(address);
                        sessionManager.sendServerMessage(address, null, message);
                    }
                }
                else {
Derek DeMoro's avatar
Derek DeMoro committed
89
                    sessionManager.sendServerMessage(new JID(jid),null,message);
Matt Tucker's avatar
Matt Tucker committed
90 91
                }
            }
Bill Lynch's avatar
Bill Lynch committed
92
            if (username != null){
93 94
                response.sendRedirect("user-message.jsp?success=true&username=" +
                        URLEncoder.encode(username, "UTF-8") + "&tabs=" + tabs);
Bill Lynch's avatar
Bill Lynch committed
95 96 97
            }
            else {
                response.sendRedirect("user-message.jsp?success=true");
Derek DeMoro's avatar
Derek DeMoro committed
98
            }
Bill Lynch's avatar
Bill Lynch committed
99
            return;
Matt Tucker's avatar
Matt Tucker committed
100 101 102 103 104
        }
    }

    // Get all sessions associated with this user:
    int numSessions = -1;
105 106
    ClientSession sess = null;
    Collection<ClientSession> sessions = null;
Matt Tucker's avatar
Matt Tucker committed
107 108 109 110
    if (user != null) {
        numSessions = sessionManager.getSessionCount(user.getUsername());
        sessions = sessionManager.getSessions(user.getUsername());
        if (numSessions == 1) {
111
            sess = sessions.iterator().next();
Matt Tucker's avatar
Matt Tucker committed
112 113 114
        }
    }
%>
Bill Lynch's avatar
Bill Lynch committed
115

Matt Tucker's avatar
Matt Tucker committed
116

117 118 119 120 121 122 123
<html>
    <head>
        <title><fmt:message key="user.message.title"/></title>
        <meta name="pageID" content="user-message"/>
        <meta name="helpPage" content="send_an_administrative_message_to_users.html"/>
    </head>
    <body>
Matt Tucker's avatar
Matt Tucker committed
124 125 126

<%  if (success) { %>

Bill Lynch's avatar
Bill Lynch committed
127 128 129 130 131
    <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">
132
        <fmt:message key="user.message.send" />
Bill Lynch's avatar
Bill Lynch committed
133 134 135 136
        </td></tr>
    </tbody>
    </table>
    </div><br>
Matt Tucker's avatar
Matt Tucker committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156

<%  } %>

<script language="JavaScript" type="text/javascript">
function updateSelect(el) {
    if (el.checked) {
        for (var e=0; e<el.form.jid.length; e++) {
            el.form.jid[e].selected = true;
        }
    }
    else {
        for (var e=0; e<el.form.jid.length; e++) {
            el.form.jid[e].selected = false;
        }
    }
    el.form.message.focus();
}
</script>

<form action="user-message.jsp" method="post" name="f">
Derek DeMoro's avatar
Derek DeMoro committed
157
<% if(username != null){ %>
158
<input type="hidden" name="username" value="<%= username %>">
Derek DeMoro's avatar
Derek DeMoro committed
159
<% } %>
Matt Tucker's avatar
Matt Tucker committed
160 161 162 163 164 165 166 167 168
<input type="hidden" name="tabs" value="<%= tabs %>">
<input type="hidden" name="send" value="true">
<%  if (sess != null) { %>

    <input type="hidden" name="sessionID" value="<%= sess.getAddress().toString() %>">

<%  } %>

<table cellpadding="3" cellspacing="1" border="0" width="600">
169
<tr class="tableHeader"><td colspan="3" align="left"><fmt:message key="user.message.send_admin_msg" /></td></tr>
Matt Tucker's avatar
Matt Tucker committed
170 171 172
<tr><td colspan=3 class="text">
<%   if (user == null) { %>

173
    <fmt:message key="user.message.info" />
Matt Tucker's avatar
Matt Tucker committed
174 175 176

<%  } else { %>

177
    <fmt:message key="user.message.specified_user_info" />
Matt Tucker's avatar
Matt Tucker committed
178 179 180 181 182

<%  } %>
</td></tr>
<tr>
    <td class="jive-label">
183
        <fmt:message key="user.message.to" />:
Matt Tucker's avatar
Matt Tucker committed
184 185 186 187
    </td>
    <td>
        <%  if (user == null) { %>

188
            <fmt:message key="user.message.all_online_user" />
Matt Tucker's avatar
Matt Tucker committed
189 190 191 192 193 194 195 196 197 198 199 200

        <%  } else { %>

            <%  if (sess != null && numSessions == 1) { %>

                <%= sess.getAddress().toString() %>
                <input type="hidden" name="jid" value="<%= sess.getAddress().toString() %>">

            <%  } else { %>

                <select size="2" name="jid" multiple>

201
                <%   Iterator<ClientSession> iter = sessions.iterator();
Matt Tucker's avatar
Matt Tucker committed
202
                     while (iter.hasNext()) {
203
                        sess = iter.next();
Matt Tucker's avatar
Matt Tucker committed
204 205 206 207 208 209 210 211 212
                %>
                    <option value="<%= sess.getAddress().toString() %>"><%= sess.getAddress().toString() %></option>

                <%  } %>

                </select>

                <input type="checkbox" name="sendToAll" value="true" id="cb01"
                 onfocus="updateSelect(this);" onclick="updateSelect(this);">
213
                <label for="cb01"><fmt:message key="user.message.send_session" /></label>
Matt Tucker's avatar
Matt Tucker committed
214 215 216 217 218 219 220

            <%  } %>

            <%  if (errors.get("jid") != null) { %>

                <br>
                <span class="jive-error-text">
221
                <fmt:message key="user.message.valid_address" />
Matt Tucker's avatar
Matt Tucker committed
222 223 224 225 226 227 228 229 230
                </span>

            <%  } %>

        <%  } %>
    </td>
</tr>
<tr valign="top">
    <td class="jive-label">
231
        <fmt:message key="user.message.message" />:
Matt Tucker's avatar
Matt Tucker committed
232 233 234 235 236
    </td>
    <td>
        <%  if (errors.get("message") != null) { %>

            <span class="jive-error-text">
237
            <fmt:message key="user.message.valid_message" />
Matt Tucker's avatar
Matt Tucker committed
238 239 240 241 242 243 244 245 246 247 248 249
            </span>
            <br>

        <%  } %>
        <textarea name="message" cols="55" rows="5" wrap="virtual"></textarea>
    </td>
</tr>
</table>
</div>

<br>

250 251
<input type="submit" value="<fmt:message key="user.message.send_message" />">
<input type="submit" name="cancel" value="<fmt:message key="global.cancel" />">
Matt Tucker's avatar
Matt Tucker committed
252 253 254 255 256 257 258

</form>

<script language="JavaScript" type="text/javascript">
document.f.message.focus();
</script>

259 260
    </body>
</html>