<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"%>
<%@page errorPage="AdminException.jsp"
%><%@page import="com.fujitsu.iflow.model.workflow.WFSession"
%><%@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.WFObjectList"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"
%><%@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.Vector"
%><%@page import="java.util.Hashtable"
%><%@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;

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

    String piSortedURL= "SortedProcessList.jsp";

    int _pageSize = 20;
    int selIdValue = 1;
    long id = -1;
    long processId = -1;

    String pageOption = request.getParameter("wPageId");

    if (!(pageOption != null && pageOption.length() >= 1))
    {
        pageOption = "1";
    }

    int wPageValue = Integer.parseInt(pageOption);
    if (wPageValue < 1)
        wPageValue = 1;


    // Retrieve all relevant parameters that are passed to this page
    String planID = request.getParameter("planID");
    String planIDOp = request.getParameter("planIDOp");
    String planName = request.getParameter("planName");
    String planNameOp = request.getParameter("planNameOp");
    String planIdentifier = request.getParameter("planIdentifier");
    String planIdentifierOp = request.getParameter("planIdentifierOp");
    String processID = request.getParameter("processID");
    String processIDOp = request.getParameter("processIDOp");
    String processInitiator = request.getParameter("processInitiator");
    String processInitiatorOp = request.getParameter("processInitiatorOp");
    String processName = request.getParameter("processName");
    String processNameOp = request.getParameter("processNameOp");
    String processTitle = request.getParameter("processTitle");
    String processTitleOp = request.getParameter("processTitleOp");
    String processOwner = request.getParameter("processOwner");
    String processOwnerOp = request.getParameter("processOwnerOp");

    String startDate = request.getParameter("startDate");
    String endDate = request.getParameter("endDate");


    String processState = request.getParameter("processState");


    String processPriority = request.getParameter("processPriority");

    // Build the array of SQL Operator used in i-Flow
    int sqlOpCount = 9; // note that this value may change
    String[] sqlOpArray = new String[sqlOpCount];
    sqlOpArray[0] = WFObjectList.SQLOP_EQUALTO;
    sqlOpArray[1] = WFObjectList.SQLOP_GREATERTHAN;
    sqlOpArray[2] = WFObjectList.SQLOP_GREATERTHANOREQUALTO;
    sqlOpArray[3] = WFObjectList.SQLOP_IN;
    sqlOpArray[4] = WFObjectList.SQLOP_LESSTHAN;
    sqlOpArray[5] = WFObjectList.SQLOP_LESSTHANOREQUALTO;
    sqlOpArray[6] = WFObjectList.SQLOP_LIKE;
    sqlOpArray[7] = WFObjectList.SQLOP_NOTEQUALTO;
    sqlOpArray[8] = WFObjectList.SQLOP_NOTLIKE;


    // Build a Hashtable object to hold the parameters for WFObjectList.addFilter() call.
    // Key is the integer value of listField, hash value is an array of 2 elements comprised by sqlOperator and value.
    /*
        int - listField - one of the WFObjectList.LISTFIELD_* constants, representing the field to be used to filter the list.
    String - sqlOperator - one of the WFObjectList.SQLOP_* constants, representing a SQL operation.
    String - value - a string representation of the value that will be used in conjunction with the listField's column name and SQL operator.
    */

    Vector filterParamsVect = new Vector();

    if (planID != null && planIDOp != null)
    {
       String[] planIDArr = new String[3];
       planIDArr[0] = getSQLOperator(planIDOp,sqlOpArray);
       // if the operator is SQLOP_IN, then enclosed the  operand, 3rd parameter to WFObjectList.addFilter, in ()
       if (planIDArr[0].equals(WFObjectList.SQLOP_IN))
       {
          planIDArr[1] = encloseStrInParenthesis(planID);
       }
       else
       {
          planIDArr[1] = planID;
       }
       planIDArr[2] = Integer.toString(WFObjectList.LISTFIELD_PLAN_ID);
       filterParamsVect.addElement(planIDArr);

    }
    if (planName != null && planNameOp != null)
    {
       String[] planNameArr = new String[3];
       planNameArr[0] = getSQLOperator(planNameOp,sqlOpArray);
       if (planNameArr[0].equals(WFObjectList.SQLOP_IN))
       {
         // planName = addSingleQuotes(planName);
          planNameArr[1] = encloseStrInParenthesis(addSingleQuotes(planName));
       }
       else
       {
          planNameArr[1] = planName;
       }
       planNameArr[2] = Integer.toString(WFObjectList.LISTFIELD_PLAN_NAME);
       filterParamsVect.addElement(planNameArr);
    }

    if (planIdentifier != null && planIdentifierOp != null)
    {
       String[] planIdentifierArr = new String[3];
       planIdentifierArr[0] = getSQLOperator(planIdentifierOp,sqlOpArray);
       if (planIdentifierArr[0].equals(WFObjectList.SQLOP_IN))
       {
        //  planIdentifier = addSingleQuotes(planIdentifier);
          planIdentifierArr[1] = encloseStrInParenthesis(addSingleQuotes(planIdentifier));
       }
       else
       {
          planIdentifierArr[1] = planIdentifier;
       }
       planIdentifierArr[2] = Integer.toString(WFObjectList.LISTFIELD_PLAN_IDENTIFIER);
       filterParamsVect.addElement(planIdentifierArr);
    }
    if (processID != null && processIDOp != null)
    {
       String[] processIDArr = new String[3];
       processIDArr[0] = getSQLOperator(processIDOp,sqlOpArray);
       if (processIDArr[0].equals(WFObjectList.SQLOP_IN))
       {
          processIDArr[1] = encloseStrInParenthesis(processID);
       }
       else
       {
          processIDArr[1] = processID;
       }
       processIDArr[2] = Integer.toString(WFObjectList.LISTFIELD_PROCESSINSTANCE_ID);
       filterParamsVect.addElement(processIDArr);
    }

    if (processInitiator != null && processInitiatorOp != null)
    {
       String[] processInitiatorArr = new String[3];
       processInitiatorArr[0] = getSQLOperator(processInitiatorOp,sqlOpArray);
       if (processInitiatorArr[0].equals(WFObjectList.SQLOP_IN))
       {
          //processInitiator = addSingleQuotes(processInitiator);
          processInitiatorArr[1] = encloseStrInParenthesis(addSingleQuotes(processInitiator));
       }
       else
       {
          processInitiatorArr[1] = processInitiator;
       }
       processInitiatorArr[2] = Integer.toString(WFObjectList.LISTFIELD_PROCESSINSTANCE_INITIATOR);
       filterParamsVect.addElement(processInitiatorArr);
    }

    if (processName != null && processNameOp != null)
    {
       String[] processNameArr = new String[3];
       processNameArr[0] = getSQLOperator(processNameOp,sqlOpArray);
       if (processNameArr[0].equals(WFObjectList.SQLOP_IN))
       {
          processNameArr[1] = encloseStrInParenthesis(addSingleQuotes(processName));
       }
       else
       {
          processNameArr[1] = processName;
       }
       processNameArr[2] = Integer.toString(WFObjectList.LISTFIELD_PROCESSINSTANCE_NAME);
       filterParamsVect.addElement(processNameArr);
    }

    if (processTitle != null && processTitleOp != null)
    {
       String[] processTitleArr = new String[3];
       processTitleArr[0] = getSQLOperator(processTitleOp,sqlOpArray);
       if (processTitleArr[0].equals(WFObjectList.SQLOP_IN))
       {
          processTitleArr[1] = encloseStrInParenthesis(addSingleQuotes(processTitle));
       }
       else
       {
          processTitleArr[1] = processTitle;
       }
       processTitleArr[2] = Integer.toString(WFObjectList.LISTFIELD_PROCESSINSTANCE_TITLE);
       filterParamsVect.addElement(processTitleArr);
    }
    if (processOwner != null && processOwnerOp != null)
    {
       String[] processOwnerArr = new String[3];
       processOwnerArr[0] = getSQLOperator(processOwnerOp,sqlOpArray);
       if (processOwnerArr[0].equals(WFObjectList.SQLOP_IN))
       {
          processOwnerArr[1] = encloseStrInParenthesis(addSingleQuotes(processOwner));
       }
       else
       {
          processOwnerArr[1] = processOwner;
       }
       processOwnerArr[2] = Integer.toString(WFObjectList.LISTFIELD_PROCESSINSTANCE_OWNER);
       filterParamsVect.addElement(processOwnerArr);
    }
    if (startDate != null)
    {
       String[] startDateArr = new String[3];
       startDateArr[0] = WFObjectList.SQLOP_GREATERTHANOREQUALTO;
       startDateArr[1] = startDate;
       startDateArr[2] = Integer.toString(WFObjectList.LISTFIELD_PROCESSINSTANCE_CREATEDTIME);
       filterParamsVect.addElement(startDateArr);
    }
    if (endDate != null)
    {
       String[] endDateArr = new String[3];
       endDateArr[0] = WFObjectList.SQLOP_LESSTHANOREQUALTO;
       endDateArr[1] = endDate;
       endDateArr[2] = Integer.toString(WFObjectList.LISTFIELD_PROCESSINSTANCE_CREATEDTIME);
       filterParamsVect.addElement(endDateArr);
    }
    if (processState != null)
    {
       String[] processStateArr = new String[3];
       processStateArr[0] = WFObjectList.SQLOP_IN; // the only acceptable operator for this field
       processStateArr[1] = getProcessState(processState);
       processStateArr[2] = Integer.toString(WFObjectList.LISTFIELD_PROCESSINSTANCE_STATE);
       filterParamsVect.addElement(processStateArr);
    }
    if (processPriority != null)
    {
       String[] processPriorityArr = new String[3];
       processPriorityArr[0] = WFObjectList.SQLOP_IN; // the only acceptable operator for this field
       processPriorityArr[1] = getProcessPriority(processPriority);
       processPriorityArr[2] = Integer.toString(WFObjectList.LISTFIELD_PROCESSINSTANCE_PRIORITY);
       filterParamsVect.addElement(processPriorityArr);
    }


    ProcessInstance[] procInsts = getFilteredProcesses(Filter.AllProcesses, wPageValue, _pageSize, wfSession,filterParamsVect);

    if (procInsts == null) {
        procInsts = new ProcessInstance[0];
    }

%>
<html>
<head>
<title>Interstage Business Process Manager | Filtered Process Instance List</title>
<jsp:include page="StyleSheet.jsp" flush="true"/>
<script language="javascript" src="styles/clockscripts.js"></script>
<script>
function setNextSelection()
{
    document.adProcessForm.wPageId.value = parseInt(document.adProcessForm.wPageId.value) + parseInt(1);
    adProcessForm.submit();
}

function setPreviousSelection()
{
    document.adProcessForm.wPageId.value = parseInt(document.adProcessForm.wPageId.value) + parseInt(-1);
    adProcessForm.submit();
}

function setProcessId(val, id, adProcessForm)
{
    adProcessForm.processId.value= id;
    adProcessForm.selected.value= val;
    adProcessForm.submit();
}

function gotoProcessId()
{
    location.href="ProcessSummary.jsp?processId=" + document.adProcessForm.processInstanceId.value;
}

function archiveQuery()
{
    document.location.href='ArchiveProcesses.jsp';
}

function archivedProcesses()
{
    location.href="ArchivedProcesses.jsp";
}

function filter()
{
    location.href="FilterProcesses.jsp";
}

 function getSelected(opt) {
    var selected = new Array();
    var index = 0;
    if(document.adProcessForm.pnum.value == 1)
    {
      if (opt.checked)
      {
          index = selected.length;
      selected[index] = new Object;
      selected[index].value = opt.value;
      selected[index].index = 0;
      }
    }
    else
    {
      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;
 }

function outputSelected(val) {
    var opt = document.adProcessForm.selIds;
    var sel = getSelected(opt);
    var strSel = "";
    for (var item in sel)
       strSel += sel[item].value + ",";
    var test = strSel.substring(0,strSel.length-1);
    if(test == "")
    {
        var selected;
        if (val == 7) {
            selected = 'deleting';
        }
        else
        {
            selected = 'archiving';
        }
        alert("Select process instance id's for " + selected + " multiple process instances.");
    }
    else
    {
    document.location.href = 'ProcessSummary.jsp?processId=' + test + '&selected='  + val;
    }
 }

 function migrateProcesses() {
    var opt = document.adProcessForm.selIds;
    var sel = getSelected(opt);
    var strSel = "";
    for (var item in sel)
       strSel += sel[item].value + ",";
    var test = strSel.substring(0,strSel.length-1);
    if(test == "")
    {
        alert("Select process instance id's for migrating multiple process instances.");
    }
    else
    {
    document.location.href = 'MigrateProcesses.jsp?processIds=' + test;
    }
 }


</script>
</head>

<body class="adminBodyClass">
<center>

<jsp:include page="AdminHeader.jsp" flush="true"/>
 <form name="adProcessForm" method="get" action="FilteredProcessList.jsp">
  <input type="hidden" name="wPageId" value="<%= wPageValue%>">
  <!--input type="hidden" name="selId" value="<%= selIdValue %>"-->

<% if (planID != null)
{
%>
  <input type="hidden" name="planID" value="<%= planID %>">
<%
}
%>


<% if (planIDOp != null)
{
%>
  <input type="hidden" name="planIDOp" value="<%= planIDOp %>">
<%
}
%>

<% if (planName != null)
{
%>
  <input type="hidden" name="planName" value="<%= planName %>">
<%
}
%>

<% if (planNameOp != null)
{
%>
  <input type="hidden" name="planNameOp" value="<%= planNameOp %>">
<%
}
%>

<% if (planIdentifier != null)
{
%>
  <input type="hidden" name="planIdentifier" value="<%= planIdentifier %>">
<%
}
%>

<% if (planIdentifierOp != null)
{
%>
  <input type="hidden" name="planIdentifierOp" value="<%= planIdentifierOp %>">
<%
}
%>

<% if (processID != null)
{
%>
  <input type="hidden" name="processID" value="<%= processID %>">
<%
}
%>

<% if (processIDOp != null)
{
%>
  <input type="hidden" name="processIDOp" value="<%= processIDOp %>">
<%
}
%>

<% if (processInitiator != null)
{
%>
  <input type="hidden" name="processInitiator" value="<%= processInitiator %>">
<%
}
%>

<% if (processInitiatorOp != null)
{
%>
  <input type="hidden" name="processInitiatorOp" value="<%= processInitiatorOp %>">
<%
}
%>

<% if (processName != null)
{
%>
  <input type="hidden" name="processName" value="<%= processName %>">
<%
}
%>

<% if (processNameOp != null)
{
%>
  <input type="hidden" name="processNameOp" value="<%= processNameOp %>">
<%
}
%>

<% if (processTitle != null)
{
%>
  <input type="hidden" name="processTitle" value="<%= processTitle %>">
<%
}
%>

<% if (processTitleOp != null)
{
%>
  <input type="hidden" name="processTitleOp" value="<%= processTitleOp %>">
<%
}
%>

<% if (processOwner != null)
{
%>
  <input type="hidden" name="processOwner" value="<%= processOwner %>">
<%
}
%>

<% if (processOwnerOp != null)
{
%>
  <input type="hidden" name="processOwnerOp" value="<%= processOwnerOp %>">
<%
}
%>

<% if (startDate != null)
{
%>
  <input type="hidden" name="startDate" value="<%= startDate %>">
<%
}
%>

<% if (endDate != null)
{
%>
  <input type="hidden" name="endDate" value="<%= endDate %>">
<%
}
%>

<% if (processState != null)
{
%>
  <input type="hidden" name="processState" value="<%= processState %>">
<%
}
%>

<% if (processPriority != null)
{
%>
  <input type="hidden" name="processPriority" value="<%= processPriority %>">
<%
}
%>




<table width="95%" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td align="right">
<table border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td>
        <table border="0" cellspacing="0" cellpadding="0" align="right" >
                <tr background="images/buttons/com_button_bg.gif">
                    <td width="15"><a href="ArchivedProcesses.jsp"><img src="images/buttons/but_package.gif" border="0"></a></td>
                    <td background="images/buttons/com_button_bg.gif" nowrap><a href="ArchivedProcesses.jsp"><div align="center" class="buttonlink"> Archived Process Instances</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>&nbsp;</td>
    
    <td>&nbsp;</td>
    <td>
    <table border="0" cellspacing="0" cellpadding="0">
      <tr background="images/buttons/com_button_bg.gif">
        <td width="15"><a href="FilterProcesses.jsp"><img src="images/buttons/but_search.gif" height="24" border="0"></a></td>
        <td background="images/buttons/com_button_bg.gif" nowrap><a href="FilterProcesses.jsp"><div align="center" class="buttonlink">&nbsp;Search</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><br>
<table width="95%" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td>
<font face="arial" size="2">Process Instance Id:</font><input type= "text" name ="processInstanceId" value = "" size = 8><input type = "button" onClick="gotoProcessId()" value = "Go To" class="submitClass">
</td>
<td align="right">

<%
    String btnEnabled = "";
       String selOption = "disabled";
       if (wPageValue > 1 && _pageSize != 0)
       {
           selOption = "onClick="+"\"setPreviousSelection()"+"\"";
           }
       else {
           btnEnabled = "disabled";
       }
       if(btnEnabled.equalsIgnoreCase("disabled") && selOption.equalsIgnoreCase("disabled"))
       {
   %>
       <input value="Prev Page" <%= btnEnabled %> type="button" class="submitClass">
   <%
   }
   else
   {
   %>
       <input value="Prev Page" <%= btnEnabled %> type="button" <%= selOption %> class="submitClass">
   <%
   }
%>

                <%
    selOption = "setNextSelection()";
    if (procInsts.length < _pageSize || _pageSize == 0)
        btnEnabled = "disabled";
    else
        btnEnabled="";
%>
    <input value="Next Page" <%= btnEnabled %> type="button" onClick="<%= selOption %>" class="submitClass">




</td></tr>
</table>

<table bgcolor="#CCCCCC" border="0" cellpadding="4" cellspacing="1" class="tableClass" width="95%" align="center">
<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">All Filtered Process instances</font></td>
</tr>
</table>

<TABLE bgcolor="#CCCCCC" border="0" cellpadding="4" cellspacing="1" class="tableClass" width="95%" align="center">
                  <tr align="center" class="headrow">
                    <th>Select</th>
                    <td><a href="<%=piSortedURL%>?sort=processId"><font color="#FFFFFF"> Id </font></a></td>
                    <th><a href="<%=piSortedURL%>?sort=processName"><font color="#FFFFFF">  Process Instance Name </font></a></th>
                    <th><a href="<%=piSortedURL%>?sort=planName"><font color="#FFFFFF"> Process Definition Name </font></a></th>
                    <th>Date Started </th>
                    <th><a href="<%=piSortedURL%>?sort=processStatus"><font color="#FFFFFF"> State </font></a></th>
                    <th> Owner(s) </th>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                  </tr>
<input type="hidden" name=pnum value="<%= procInsts.length %>">
                  <%
    for (int i = 0; i < procInsts.length; i++)
    {
        ProcessInstance pi = procInsts[i];
        long piId = pi.getId();
        String piName = pi.getName();
        String thisPlanName = pi.getPlanName();
        String piState = null;
        int thisProcessState = pi.getState();
        switch(thisProcessState)
        {
            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;
        }
            //piState = ProcessInstanceStatesEnum.from_int(pi.getState()).toString();
        String[] piOwners = pi.getOwners();
        String piURL = "ProcessInstance.jsp?piId="+pi.getId();
        String pdURL = "ProcessDefinition.jsp?planId="+pi.getPlanId();
        String summaryURL = "ProcessSummary.jsp?processId="+piId;
        String piDate = ""+pi.getCreationTime();
        rowColor = bcolor[nextColor];
        nextColor = (nextColor + 1)%2;
        String summary ="Summary";
        String Copy = "Copy";
%>
                  <tr class="<%=rowColor%>">
                    <td><INPUT TYPE=CHECKBOX NAME= selIds VALUE="<%= piId %>"></td>
                    <td><%= piId %></td>
                    <td><a href="<%=piURL%>"> <%= piName %> </a></td>
                    <td><a href="<%=pdURL%>"> <%= thisPlanName %> </a></td>
                    <td nowrap><script> showDate('<%=piDate%>'); </script></td>
                    <td><%= piState %></td>
                    <td>
                      <% for(int j=0; j<piOwners.length; j++){%>

                      <%= piOwners[j] %>
                      <% if(j!=piOwners.length-1) out.print(","); %>

                      <%}%>
                    </td>
                    <td>
						<table border="0" cellspacing="0" cellpadding="0">
						  <tr><td align="center"><a href="<%=summaryURL%>" title="Go here to modify this process instance"><img src="images/buttons/details_small_icon.gif" width="20" height="17" border="0"></a></td></tr>
						  <tr><td><a href="<%=summaryURL%>" title="Go here to modify this process instance"><div class="smalllinks">SUMMARY</div></a></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="ShowHistory.jsp?id=<%=piId%>"><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=<%=piId%>">
							<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=<%=piId%>"><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=<%=piId%>"><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>
<br>
<table border="0" cellpadding="0" cellspacing="0" width="95%" align="center">
    <tr>
        <td>

<TABLE border="0" cellpadding=0 cellspacing=0>
        <tr>
            <td>
<table border="0" cellspacing="0" cellpadding="0">
  <tr background="images/buttons/com_button_bg.gif">
    <td width="15"><a href="javascript:onClick=outputSelected('7')"><img src="images/buttons/but_delete.gif" border="0"></a></td>
    <td background="images/buttons/com_button_bg.gif" nowrap><a href="javascript:onClick=outputSelected('7')"><div align="center" class="buttonlink"> Delete</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>&nbsp;</td><td>

<table border="0" cellspacing="0" cellpadding="0">
  <tr background="images/buttons/com_button_bg.gif">
    <td width="15"><a href="javascript:onClick=outputSelected('8')"><img src="images/buttons/but_package.gif" border="0"></a></td>
    <td background="images/buttons/com_button_bg.gif" nowrap><a href="javascript:onClick=outputSelected('8')"><div align="center" class="buttonlink"> Archive</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>&nbsp;</td>
<td>
        <table border="0" cellspacing="0" cellpadding="0" align="right" >
                <tr background="images/buttons/com_button_bg.gif">
                    <td width="15"><a href="ArchiveProcesses.jsp"><img src="images/buttons/but_package.gif" border="0"></a></td>
                    <td background="images/buttons/com_button_bg.gif" nowrap><a href="ArchiveProcesses.jsp"><div align="center" class="buttonlink">Archive by Date</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>&nbsp;</td>
<td>

<table border="0" cellspacing="0" cellpadding="0">
  <tr background="images/buttons/com_button_bg.gif">
    <td width="15"><a href="javascript:onClick=migrateProcesses()"><img src="images/buttons/but_migrate.gif" border="0"></a></td>
    <td background="images/buttons/com_button_bg.gif" nowrap><a href="javascript:onClick=migrateProcesses()"><div align="center" class="buttonlink"> Migrate</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>

    </form>
    </center>
    </body>
</html>

<%!
    public ProcessInstance[]
    getFilteredProcesses(
        int filterOption,
        int batchNumber,
        int batchSize,
        WFSession wfSession,
        Vector filterParamsVect)
        throws Exception
    {
        WFObjectList wfObjectList = null;
        ProcessInstance[] piList = null;

        try {
            wfObjectList = WFObjectFactory.getWFObjectList(wfSession);

            int size = filterParamsVect.size();
            for (int i = 0; i < size; i++)
            {
                String[] paramsValues = (String[])filterParamsVect.elementAt(i);
                int fieldId = Integer.parseInt(paramsValues[2]);
                 if (paramsValues[0].equals("IN"))
                 {
                    wfObjectList.addFilter(fieldId,paramsValues[0],paramsValues[1]);
                 }
                 else{
                    wfObjectList.addFilter(fieldId,paramsValues[0],"\'" + paramsValues[1] + "\'");
                 }
            }

            Object[] objList = null;
            wfObjectList.openBatchedList(filterOption);

            objList = wfObjectList.getNextBatch(batchSize);
            if (batchNumber > 1)
            {
                for (int i=1; i < batchNumber; i++)
                {
                    objList = wfObjectList.getNextBatch(batchSize);
                }
            }

            if (objList != null && objList.length > 0)
            {
                piList = new ProcessInstance[objList.length];
                for (int i=0; i < objList.length; i++)
                {
                    piList[i] = (ProcessInstance)objList[i];
                }
            }

        }
        catch (Exception e)
        {
          throw new Exception("FilteredProcessList.jsp: getFilteredProcesses failed because\n" + e.toString());
        }
        finally
        {
            if (wfObjectList != null)
                wfObjectList.closeList();
        }

        return piList;
    }

    private
    String
    getSQLOperator(
        String sqlOperator,
        String[] sqlOpArray)
        throws Exception
    {
        try
        {
            if (sqlOperator.equals("EqualTo"))
            {
                return sqlOpArray[0];
            }
            else if (sqlOperator.equals("GreaterThan"))
            {
                return sqlOpArray[1];
            }
            else if (sqlOperator.equals("GreaterThanOrEqualTo"))
            {
                return sqlOpArray[2];
            }
            else if (sqlOperator.equals("In"))
            {
                return sqlOpArray[3];
            }
            else if (sqlOperator.equals("LessThan"))
            {
                return sqlOpArray[4];
            }
            else if (sqlOperator.equals("LessThanOrEqualTo"))
            {
                return sqlOpArray[5];
            }
            else if (sqlOperator.equals("Like"))
            {
                return sqlOpArray[6];
            }
            else if (sqlOperator.equals("NotEqualTo"))
            {
                return sqlOpArray[7];
            }
            else if (sqlOperator.equals("NotLike"))
            {
                return sqlOpArray[8];
            }
            else
            {
                // no matching opertors.
                throw new Exception("FilteredProcessList.jsp: getSQLOperator failed to locate a matching SQL Operator!");
            }
        }
        catch (Exception e)
        {
            throw new Exception("FilteredProcessList.jsp: getSQLOperator failed because\n" + e.toString());
        }
    }

    private
    String
    encloseStrInParenthesis(
        String inString)
        throws Exception
    {
        return "(" + inString + ")";
    }


    private Vector stringParserByDelimiter(String inString, String delimiter)
    {
       int containsDelimFlag = -1;
       Vector tokenNames = new Vector();
       String curTokenName = "";

       while (inString.indexOf(delimiter) != containsDelimFlag)
       {
            int delimIndex = inString.indexOf(delimiter);
            curTokenName = inString.substring(0,delimIndex);
            inString = inString.substring(delimIndex+1,inString.length());
            tokenNames.addElement(curTokenName);
            if (inString == "" || inString == null)
            {
                break;
            }
        }
        tokenNames.addElement(inString);
        return tokenNames;
    }



    private
    String
    addSingleQuotes(
        String inString)
        throws Exception
    {
        String delimiter = ",";
        Vector strVec = stringParserByDelimiter(inString,delimiter);
        String quotedStr = "";
        String curStrElement = "";

        if (strVec != null && strVec.size() > 0)
        {
            for (int i=0; i < strVec.size(); i++)
            {
                curStrElement = (String) strVec.elementAt(i);
                if ((i+1) == strVec.size())
                {
                    // last element, so no need to append an ending comma ",".
                    quotedStr += "'" +  curStrElement + "'";
                }
                else
                {
                    quotedStr += "'" +  curStrElement + "'" + ",";
                }
            }

            return quotedStr;
        }
        else
        {
            throw new Exception("FilteredProcessList.jsp: addSingleQuotes failed due to null value.");
        }
    }



    private
    String
    getProcessState(
        String processState)
        throws Exception
    {
        String procState = "";
        StringTokenizer st = new StringTokenizer(processState,",");
        String processStates ="";
        while (st.hasMoreTokens())
        {
            procState = st.nextToken();
            try
            {
                if (procState.equals("Running"))
                {
                    processStates= processStates + 7 + ",";
                }
                else if (procState.equals("Closed"))
                {
                    processStates= processStates + 8 + ",";
                }
                else if (procState.equals("Error"))
                {
                    processStates= processStates + 10 + ",";
                }
                else if (procState.equals("Suspended"))
                {
                    processStates= processStates + 12 + ",";
                }
                else if (procState.equals("Created"))
                {
                    processStates= processStates + 3 + ",";
                }
                else if (procState.equals("Aborted"))
                {
                    processStates= processStates + 11 + ",";
                }

            }
            catch (Exception e)
            {
                throw new Exception("FilteredProcessList.jsp: getProcessState failed because\n" + e.toString());
            }
        }
        return encloseStrInParenthesis(processStates.substring(0,processStates.length()-1));
    }

    private
    String
    getProcessPriority(
        String processPriority)
        throws Exception
    {
        String procPr = "";
        StringTokenizer st = new StringTokenizer(processPriority,",");
        String procPriority ="";
        while (st.hasMoreTokens())
        {
            procPr = st.nextToken();
            try
            {
                if (procPr.equals("High"))
                {
                    procPriority= procPriority + 16 + ",";
                }
                else if (procPr.equals("Medium"))
                {
                    procPriority= procPriority + 8 + ",";
                }
                else if (procPr.equals("Low"))
                {
                    procPriority= procPriority + 0 + ",";
                }

            }
            catch (Exception e)
            {
                throw new Exception("FilteredProcessList.jsp: getProcessPriority failed because\n" + e.toString());
            }
        }
        return encloseStrInParenthesis(procPriority.substring(0,procPriority.length()-1));
    }

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


%>
