<%@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.workflow.ProcessInstance"
%><%@page import="com.fujitsu.iflow.model.workflow.Plan"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectList"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"
%><%@page import="com.fujitsu.iflow.server.dataobjects.ProcessInstanceStatesEnum"
%><%@page import="com.fujitsu.iflow.server.dataobjects.ProcessDefinitionStatesEnum"
%><%@page import="com.fujitsu.iflow.server.dataobjects.FilterEnum"
%><%@page import="com.fujitsu.iflow.model.workflow.Filter"
%><%@page import="java.util.Date"
%><%@page import="java.util.Enumeration"
%><%@page import="java.util.StringTokenizer"
%><%@page import="java.io.Writer"
%><%@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;

    String returnMsg = "";

    long id = -1;
    Plan plan = null;
    String name = "";
    String planName = "";
    String desc = "";
    String version = "";
    int processState;
    String piState = "";
    String piOwners[] = null;
    String processOwners = "";
    String piURL = "";
    String piCreationDate ="";
    String piClosedDate ="";

    String userId = request.getParameter("currentOwner");
    String processId = request.getParameter("processId");

    if (processId == null) {
    processId = (String) session.getAttribute("processId");
    }

    id = Long.parseLong(processId);

    try {

        ProcessInstance pi = WFObjectFactory.getProcessInstance(id, wfSession);
        name = pi.getName();
        desc = pi.getDescription();
        planName = pi.getPlanName();
        desc = (desc == null || desc.length() <=0)?"":desc;
        piCreationDate = "" + pi.getCreationTime();
        piClosedDate = "" + pi.getClosedTime();

        processState = pi.getState();
        switch(processState)
        {
            case 0: piState =  "Open";
                break;
            case 1: piState = "NotRunning";
                break;
            case 2: piState = "NotStarted";
                break;
            case 3: piState = "Created";
                break;
            case 4: piState = "Initialized";
                break;
            case 5: piState = "Dormant";
                break;
            case 6: piState = "Locked";
                break;
            case 7: piState = "Running";
                break;
            case 8: piState =  "Closed";
                break;
            case 9: piState =  "Completed";
                break;
            case 10: piState =  "Error";
                break;
            case 11: piState =  "Aborted";
                break;
            case 12: piState =  "Suspended";
                break;
        }


        piOwners = pi.getOwners();
        String owners = "";
        processOwners = "";
        for(int j=0; j<piOwners.length; j++)
        {
        owners = owners + piOwners[j] + ",";
        }
        processOwners = owners.substring(0,owners.length() - 1);
    }
    catch (Exception ex)
    {
        returnMsg = "Could not retrieve process instance with id " + id + ".";
    }

    piURL = "ProcessInstance.jsp?piId="+id;

    session.setAttribute("TabIndex","3");





%>


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

<body class="adminBodyClass">
<script>

function setProcessId(val, id, adForm)
{
    processSumForm.processId.value= id
    processSumForm.selected.value= val
    processSumForm.submit()
}

function saveAsXML(val, id, adForm)
{
    location.href="ProcessAsXML.jsp?processId=" + id
}

function setProcessOwner(val, id, userId, owner, adForm)
{
    processSumForm.processId.value= id;
    processSumForm.userId.value= userId;
    processSumForm.owner.value= owner;
    processSumForm.selected.value= val;
    processSumForm.submit();
}

</script>

<center>

<jsp:include page="AdminHeader.jsp" flush="true"/>


    <table cellpadding=2 cellspacing=1 class="tableclass" align="center" width="90%">
        <tr>&nbsp;</tr><tr><td align="left">
        </td>
        <td align="right">
        <table border="0" cellpadding="0" cellspacing="3"><tr><td>
			<table border="0" cellspacing="0" cellpadding="0">
			  <tr background="images/buttons/com_button_bg.gif">
				<td width="15"><a href="ShowHistory.jsp?id=<%=processId%>"><img src="images/buttons/but_history.gif" border="0"></a></td>
				<td background="images/buttons/com_button_bg.gif" nowrap><a href="ShowHistory.jsp?id=<%=processId%>">
				<div align="center" class="buttonlink">History</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>
		</td>
		<td>
	        <table border="0" cellspacing="0" cellpadding="0">
			  <tr background="images/buttons/com_button_bg.gif">
				<td width="15"><a href="PIGraphic.jsp?piId=<%= processId %>"><img src="images/buttons/but_graphical_view.gif" border="0"></a></td>
				<td background="images/buttons/com_button_bg.gif" nowrap><a href="PIGraphic.jsp?piId=<%= processId %>"><div align="center" class="buttonlink">Snapshot</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>
		 </td>
		</tr></table>	</td></tr>
    </table>
    <table width="90%" border="0" cellpadding="0" cellspacing="0"><tr>
        <form name="processSumForm" method="get" action="ProcessOwnerAction.jsp">
          <input type="hidden" name="processId" value="-1">
          <input type="hidden" name="selected" value="-1">
          <input type="hidden" name="userId" value="<%= userId %>">
    	<td>
    <TABLE  bgcolor="#CCCCCC" border="0" cellpadding="2" cellspacing="1" class="tableClass" width="100%" 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">Process Instance Summary</font></td>
            </tr>
            <tr><td colspan="1" class="headrow"> ID</td><td bgcolor="#FFFFFF" colspan="3"><%= id %></td></tr>
            <tr><td colspan="1" class="headrow"> Name</td><td bgcolor="#FFFFFF" colspan="3"><a href="<%=piURL%>"><%= name %></td></td></tr>
            <tr>
            <td colspan="1" rowspan= "1" class="headrow"> Description</td>
            <td bgcolor="#FFFFFF" colspan="3"><%= desc %></td>
            </tr>
            <tr><td colspan="1" class="headrow"> State</td>
            <td bgcolor="#FFFFFF" colspan="3"><%= piState %></td></tr>
            <tr><td colspan="1" class="headrow"> Owner(s)</td>
            <td colspan="3" bgcolor="#FFFFFF"><input type=text value =<%= processOwners %> name=owner size=30>
            <input type="button" onClick="setProcessOwner('5','<%= id %>','<%= userId %>',this.form.owner.value, this.form)" value="Modify Owner" name="check" class="core-button">

                    <tr><td colspan="1" class="headrow"> Started On</td><td bgcolor="#FFFFFF" colspan="3">
                    <script> showDate('<%=piCreationDate%>'); </script></td>
                    <%
                    if (piState.equals("Closed"))
                    {
            %>
                    <tr><td colspan="1" class="headrow"> Date Closed </td><td bgcolor="#FFFFFF" colspan="3">
                    <script> showDate('<%=piClosedDate%>'); </script></td>
            </tr>
            <%
            }
            %>
            <tr><td colspan="1" class="headrow" width="20%"> Process Definition Name</td><td colspan="3" bgcolor="#FFFFFF"><%= planName %></td></tr>

    </TABLE>


    <TABLE border="0" cellpadding="4" cellspacing="1" class="tableClass" width="100%" align="center">

            <tr>
            <td>
            <input type="button" onClick="setProcessId('1',<%= id %>, this.form)" value="Delete" name="check" class="core-button">
            <input type="button" onClick="setProcessId('6',<%= id %>, this.form)" value="Archive" name="check" class="core-button">
            <input type="button" onClick="saveAsXML('7',<%= id %>, this.form)" value="Save As XML" name="check" class="core-button">
            </td>
            </tr>
            </TABLE>
            </tr>
        </table>
        </form>
        <!-- Added Larer for changing the layout -->
          </td>
      </table>

</center>
</html>

<%!
    public WFAdminSessionImpl getiFlowSession(Object modelObject)
    {
            return (WFAdminSessionImpl)(modelObject);
    }

%>
