<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"%>
<%@page errorPage="AdminException.jsp"
%><%@page import="com.fujitsu.iflow.model.workflow.WFAdminSession"
%><%@page import="com.fujitsu.iflow.model.wfcore.WFAdminSessionImpl"
%><%@page import="com.fujitsu.iflow.model.wfcore.WFSessionImpl"
%><%@page import="com.fujitsu.iflow.model.workflow.ProcessInstance"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectList"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"
%><%@page import="com.fujitsu.iflow.model.workflow.UserInfo"

%><%@page import="com.fujitsu.iflow.server.dataobjects.ProcessInstanceStatesEnum"
%><%@page import="com.fujitsu.iflow.server.dataobjects.FilterEnum"
%><%@page import="com.fujitsu.iflow.model.workflow.Filter"
%><%@page import="com.fujitsu.iflow.model.util.QuickForm"
%><%@page import="java.util.Date"
%><%@page import="java.util.Enumeration"
%><%@page import="java.util.StringTokenizer"
%><%@page import="com.fujitsu.iflow.model.util.URLEncoder"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMAdmin"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMSession"
%><%@page import="com.fujitsu.iflow.model.bpmcore.BPMAdminImpl"
%><%
    request.setCharacterEncoding("UTF-8");request.getParameterNames(); //Need dummy call for WL9.1
    BPMSession bps = (BPMSession) session.getAttribute("BPMSession");
    if (bps == null) {
        %><jsp:include page="PasswordPanel.jsp" flush="true"/><%
        return;
    }

    BPMAdmin bpas = bps.getAdmin();
    WFAdminSessionImpl wfSession = ((BPMAdminImpl)bpas)._wfas;

    Long uaid = null;
    String uaname = null;
    String returnMsg = "";

    String[] bcolor = {"evenrow","oddrow"};
    int nextColor = 0;
    String rowColor = bcolor[nextColor];
    session.setAttribute("TabIndex","2");

    String sel = request.getParameter("selected");
    String clientID = request.getParameter("uaid");
    if(sel != null)
    {
        int selValue = new Integer(sel).intValue();
        session.setAttribute("selected", sel);
        switch(selValue){
            case 0: returnMsg = deleteUserSession(clientID, wfSession);
                    break;
            case 1: returnMsg = deleteMultipleUserSessions(clientID, wfSession);
                    break;
            default: returnMsg = doNothing();

        }
    }

    int selIdValue=1;
    long id = -1;



%>
<html>
<head>
<title>Interstage Business Process Manager | Delete User Session</title>
<jsp:include page="StyleSheet.jsp" flush="true"/>
<script language="javascript" src="styles/clockscripts.js"></script>
<script>


</script>
<script>


function gotoLoginSessions()
{
    document.location.href='LoginSessions.jsp';
}


</script>


</head>

<body class="adminBodyClass">

<jsp:include page="AdminHeader.jsp" flush="true"/>
<center>
       <TABLE  border="0" cellpadding="2" cellspacing="1" class="tableClass" width="75%" align="center">
            <tr><td>&nbsp;</td></tr>
            <tr><td align="center">
            <img src="images/icons/info_excep.gif" border="0"><br/></td></tr>
            <tr><td>&nbsp;</td></tr>
        <tr align="center" class="headrow">
            <td bgcolor="#EEEEEE" style="filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FFFFFF', endColorStr='#6699CC', gradientType='1')"><font color="#000000" size="2"><%= returnMsg %></font></td>
            </tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
            <tr><td>&nbsp;</td></tr>
            <tr><td align ="center">
            <input type="button" onClick="gotoLoginSessions()" value="Login Sessions" name="check" class="core-button">
            </td></tr>

          </table>
</center>
</body>
</html>

<%!

    public
    String
    deleteUserSession(
        String clientID, WFAdminSessionImpl wfSession)
        throws Exception
    {
        try {
        wfSession.logoutUser((new Long(clientID)).longValue());
        }
        finally {
        }

        return "Session with client id " + clientID + " deleted";
    }

    public
    String
    deleteMultipleUserSessions(
        String clientID, WFAdminSessionImpl wfSession)
        throws Exception
    {

        StringTokenizer st = new StringTokenizer(clientID, ",");
        String clientIdsDeleted = "";
        String clientIdsFailed = "";
        long id = -1;
        String message = "";

        while (st.hasMoreTokens()){
            try{
                id = Long.parseLong(st.nextToken());
            wfSession.logoutUser((new Long(id)).longValue());
                clientIdsDeleted = clientIdsDeleted + id + ", ";
            }
            catch (Exception ex) {
                clientIdsFailed = clientIdsFailed + id + ", ";
            }
        }

    if (!((clientIdsDeleted.equals("")) || (clientIdsDeleted.equals(null))))
    {
        message = "Client ID's " + clientIdsDeleted.substring(0,clientIdsDeleted.length() -2) + " have been successfully disconnected. ";
    }

    if (!(clientIdsFailed.equals("") || clientIdsFailed.equals(null)))
    {
        message = message + "Disconnecting client ID's " + clientIdsFailed.substring(0,clientIdsFailed.length()-2) + " failed .";
    }

        return message;

    }


    public WFAdminSessionImpl getiFlowSession(Object modelObject)
    {
            return (WFAdminSessionImpl)(modelObject);
    }

    public String doNothing() throws Exception
    {
        return "this does nothing";
    }

%>
