<%@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="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.BPMSessionImpl"
%><%@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 suaid = null;
    String uaname = null;

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

    session.removeAttribute("uaid");

    UserInfo[] userSessions = getUserSessions(wfSession);

    int selIdValue=1;
    long id = -1;

    WFSessionImpl wfRegSession = ((BPMSessionImpl)bps)._wfs;
    long regSessionId = wfRegSession.getClientId();

    long adminSessionId = wfSession.getClientId();

    String selAllSessions = request.getParameter("selAll");
    if(selAllSessions != null && selAllSessions.equalsIgnoreCase("true"))
	selAllSessions = "CHECKED";
    else
	selAllSessions ="";

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


function deleteSession(val, id)
{
    delClientID.uaid.value= id
    delClientID.selected.value= val
    delClientID.submit()

}


 function getSelected(opt) {
     var selected = new Array();
     var index = 0;
     if (!(opt ==null))
     {
 	    for (var intLoop = 0; intLoop < opt.length; intLoop++) {
 	       if ((opt[intLoop].selected) ||
 		   (opt[intLoop].checked)) {
 		  index = selected.length;
 		  selected[index] = new Object;
 		  selected[index].value = opt[intLoop].value;
 		  selected[index].index = intLoop;
 	       }
 	    }
 	    return selected;
     }
     else 
     {
     	return "CanNotDisconnect";
     }
  }


function outputSelected(val) {
    var opt = delClientID.selIds
    var sel = getSelected(opt);
    var strSel = "";
    if (sel == "CanNotDisconnect")
    {
    	alert("Can not disconnect exiting session.");
    	return;
    }
    else{
    
	    for (var item in sel)
	       strSel += sel[item].value + ",";
	    var test = strSel.substring(0,strSel.length-1);
	    if(test == "")
	    {
            if((delClientID.selIds.selected) ||  (delClientID.selIds.checked))
            {
                var out = delClientID.selIds.value
                deleteSession(0,out)
            }
            else
                alert("Select session's for disconnecting multiple sessions.");
	    }
	    else
	    {
		delClientID.uaid.value= test;
		delClientID.selected.value= val;
		delClientID.submit();
	    }
    }
 }

function selectAllSessions() {
	document.location.href='LoginSessions.jsp?selAll='+document.delClientID.selAll.checked;
}

</script>
</head>

<body class="adminBodyClass">
<center>

<jsp:include page="AdminHeader.jsp" flush="true"/>
<br><br>
<table bgcolor="#CCCCCC" border="0" cellpadding="4" cellspacing="1" class="tableClass" width="90%" align="center">
<tr align="center" class="headrow">
    <td colspan="4" bgcolor="#EEEEEE" style="filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FFFFFF', endColorStr='#6699CC', gradientType='1')"><font color="#000000" size="2">Login Sessions</font></td>
</tr>
<form name="delClientID" method="post" action="DeleteSession.jsp">
	               <input type="hidden" name="selected" value="Disconnect">
	  		<input type="hidden" name="uaid" value="-1">
                  <tr align="center" class="headrow">
                    <th width="7%"><INPUT TYPE=CHECKBOX NAME= selAll VALUE="" onclick="selectAllSessions()" <%= selAllSessions%>>Select</th>
                    <td> Client ID </td>
                    <td> User ID </td>
                    <td width="10%"> Action </td>
                  </tr>
                  <%
    for (int i = 0; i < userSessions.length; i++)
    {
	boolean adminSession = false;
    	boolean regularSession = false;
	uaid = new Long(userSessions[i].getClientID());
	uaname = userSessions[i].getName();
	if ((new Long(regSessionId).equals(uaid)))
      {
		uaname = uaname + " (this session) ";
		regularSession = true;
      }
	if ((new Long(adminSessionId).equals(uaid)))
      {
		uaname = uaname + " (this admin session) ";
		adminSession = true;
      }

        rowColor = bcolor[nextColor];
        nextColor = (nextColor + 1)%2;

%>
                  <tr class="<%=rowColor%>">
                  <%
	                if (!(regularSession || adminSession))
	                {
		  %>
		     <td align="center"><INPUT TYPE=CHECKBOX NAME= selIds VALUE="<%= uaid %>" <%= selAllSessions%> ></td>
		  <%
                  	}
                  	else
                  	{
		  %>
		  <td></td>
		  <%
                  	}

		  %>


                    <td><%= uaid %></td>
                    <td> <%= uaname %> </td>
                    <td>
                    <%
                    if (!(regularSession || adminSession))
                    {
		    %>
<!-- Image Button
<table border="0" cellspacing="0" cellpadding="0">
	  <tr background="images/buttons/com_button_bg.gif">
		<td width="15"><img src="images/buttons/but_delete.gif" width="29" height="24"></td>
		<td background="images/buttons/com_button_bg.gif" nowrap><a href="javascript:'deleteSession('0','<%= uaid %>', this.form);'"><div align="center" class="buttonlink">&nbsp;Disconnect</span></div></a></td>
		<td width="9"><div align="right"><img src="images/buttons/com_button_right.gif" width="9" height="24"></div></td>
	  </tr>
	</table> -->
		    <input type="button" onClick="deleteSession('0','<%= uaid %>')" value="Disconnect" name="check" class="core-button">
		    <%
		    }
		    %>
		    </td>

                  </tr>
                  <%
   }
%>
              
            </form>
  </table><br>
		<TABLE border="0" cellpadding="0" cellspacing="0" class="tableClass" width="90%" align="center">
		<tr>
		<td>
		<input type="button" onClick="outputSelected('1')" value="Disconnect" name="check" class="core-button"></td>
        
		</tr>
		
        </TABLE>
</center>
        
        </body>

</html>

<%!

    public
    UserInfo[]
    getUserSessions(
        WFAdminSessionImpl wfSession)
        throws Exception
    {
    	UserInfo[] ui = null;
        try {
		ui = wfSession.getAllUserAgentInfo();
        }
        finally {
        }

        return ui;
    }

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


%>
