<%@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.Plan"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectList"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"
%><%@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="com.fujitsu.iflow.model.util.QuickForm"
%><%@page import="java.util.Date"
%><%@page import="java.util.Enumeration"
%><%@page import="java.text.SimpleDateFormat"
%><%@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;

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

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

<style type="text/css">@import url(calendar/calendar-win2k-1.css);</style>
<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>

<script>

function filter()
{
    var partURL ="FilteredProcessList.jsp?";
    var test = "false";
    var connector ="";

    var state = "";
    for (var i=0; i < document.filterForm.processState.length; i++)
    {
       if (document.filterForm.processState[i].checked)
       {
          connector = "&";
          test="true"
          state = state + document.filterForm.processState[i].value + ",";
       }
    }

    if (!state == "")
    {
        partURL = partURL + "processState=" + state.substring(0,state.length -1);
    }




    var priority = "";
    for (var i=0; i < document.filterForm.processPriority.length; i++)
    {
       if (document.filterForm.processPriority[i].checked)
       {

          priority = priority + document.filterForm.processPriority[i].value + ",";
       }
    }

    if (!(priority == "") )
    {
        partURL = partURL + connector + "processPriority=" + priority.substring(0,priority.length -1);
            connector = "&";
    }



    var procIdLength = document.filterForm.processIDOp.length;
    var procIdOpVal = "";
    var valN = "";
    var regExp = /,/g;
    for (i=0;i<procIdLength;i++)
    {
        if (document.filterForm.processIDOp.options[i].selected == true)
        {
            procIdOpVal = document.filterForm.processIDOp.options[i].text;
            }
    }

    if (!(document.filterForm.processID.value == "") )
    {
    	if( !(procIdOpVal == "In"))
    	{
    	   if(isNaN(document.filterForm.processID.value))
    	   {    	   
    		alert("Please enter a valid Process Instance ID.");
		document.filterForm.processID.focus();
	        document.filterForm.processID.select();
	        return false;
	   } 
	 }
	 else
	 {
	 	valN = document.filterForm.processID.value;
	 	valN = valN.replace(regExp,"");
	 	if(isNaN(valN))
		{    	   
			alert("Please enter a valid Process Instance ID.");
			document.filterForm.processID.focus();
		        document.filterForm.processID.select();
		        return false;
	   	} 
	 }
            partURL = partURL + connector + "processID=" + document.filterForm.processID.value + "&processIDOp=" + procIdOpVal;
            connector = "&";        
    }




    var procNameLength = document.filterForm.processNameOp.length;
    var procNameOpVal = "";
    for (i=0;i<procNameLength;i++)
    {
        if (document.filterForm.processNameOp.options[i].selected == true)
        {
            procNameOpVal = document.filterForm.processNameOp.options[i].text;
            }
    }

    if (!(document.filterForm.processName.value == "") )
    {
    	var rm = document.filterForm.processName.value;
        if(rm.indexOf("%") != -1)
        {
        	rm = rm.replace("%","%25");
    	}
        partURL = partURL + connector + "processName=" + rm + "&processNameOp=" + procNameOpVal;
            connector = "&";
    }



    var procInitLength = document.filterForm.processInitOp.length;
    var procInitOpVal = "";
    for (i=0;i<procInitLength;i++)
    {
        if (document.filterForm.processInitOp.options[i].selected == true)
        {
            procInitOpVal = document.filterForm.processInitOp.options[i].text;
            }
    }

    if (!(document.filterForm.processInit.value == "") )
    {
       	var rm = document.filterForm.processInit.value;
       	if(rm.indexOf("%") != -1)
        {
            	rm = rm.replace("%","%25");
    	}
        partURL = partURL + connector + "processInitiator=" + rm + "&processInitiatorOp=" + procInitOpVal;
            connector = "&";
    }


    var procTitleLength = document.filterForm.processTitleOp.length;
    var procTitleOpVal = "";
    for (i=0;i<procTitleLength;i++)
    {
        if (document.filterForm.processTitleOp.options[i].selected == true)
        {
            procTitleOpVal = document.filterForm.processTitleOp.options[i].text;
            }
    }

    if (!(document.filterForm.processTitle.value == "") )
    {
      	var rm = document.filterForm.processTitle.value;
       	if(rm.indexOf("%") != -1)
        {
            	rm = rm.replace("%","%25");
    	}
        partURL = partURL + connector + "processTitle=" + rm + "&processTitleOp=" + procTitleOpVal;
            connector = "&";
    }


    var procOwnerLength = document.filterForm.processOwnerOp.length;
    var procOwnerOpVal = "";
    for (i=0;i<procOwnerLength;i++)
    {
        if (document.filterForm.processOwnerOp.options[i].selected == true)
        {
            procOwnerOpVal = document.filterForm.processOwnerOp.options[i].text;
            }
    }

    if (!(document.filterForm.processOwner.value == "") )
    {
      	var rm = document.filterForm.processOwner.value;
       	if(rm.indexOf("%") != -1)
        {
               	rm = rm.replace("%","%25");
    	}
        partURL = partURL + connector + "processOwner=" + rm + "&processOwnerOp=" + procOwnerOpVal;
            connector = "&";
    }


    var planIdLength = document.filterForm.planIdOp.length;
    var planIdOpVal = "";
    valN = "";
    regExp = /,/g;
    for (i=0;i<planIdLength;i++)
    {
        if (document.filterForm.planIdOp.options[i].selected == true)
        {
            planIdOpVal = document.filterForm.planIdOp.options[i].text;
            }
    }

    if (!(document.filterForm.planId.value == "") )
    {
	if( !(planIdOpVal == "In"))
      	{
       	   if(isNaN(document.filterForm.planId.value))
	   {
	      		alert("Please enter a valid Process Definition ID.");
	       		document.filterForm.planId.focus();
	       	        document.filterForm.planId.select();
	       	        return false;
       	   }
    	 }
    	 else
    	 {
    	 	valN = document.filterForm.planId.value;
    	 	valN = valN.replace(regExp,"");
    	 	if(isNaN(valN))
		   {
		      		alert("Please enter a valid Process Definition ID.");
		       		document.filterForm.planId.focus();
		       	        document.filterForm.planId.select();
		       	        return false;
	       	   }
	 }
    	   
            partURL = partURL + connector + "planID=" + document.filterForm.planId.value + "&planIDOp=" + planIdOpVal;
            connector = "&";
    }



    var planNameLength = document.filterForm.planNameOp.length;
    var planNameOpVal = "";
    for (i=0;i<planNameLength;i++)
    {
        if (document.filterForm.planNameOp.options[i].selected == true)
        {
            connector = "&";
            planNameOpVal = document.filterForm.planNameOp.options[i].text;
            }
    }

    if (!(document.filterForm.planName.value == "") )
    {
    	var rm = document.filterForm.planName.value;
    	if(rm.indexOf("%") != -1)
    	{
    		rm = rm.replace("%","%25");
    	}
        partURL = partURL + connector + "planName=" + rm + "&planNameOp=" + planNameOpVal;
            connector = "&";
    }



    var planIdentifierLength = document.filterForm.planIdentifierOp.length;
    var planIdentifierOpVal = "";
    for (i=0;i<planIdentifierLength;i++)
    {
        if (document.filterForm.planIdentifierOp.options[i].selected == true)
        {
            planIdentifierOpVal = document.filterForm.planIdentifierOp.options[i].text;
            }
    }

    if (!(document.filterForm.planIdentifier.value == "") )
    {
        var rm = document.filterForm.planIdentifier.value;
        if(rm.indexOf("%") != -1)
        {
            rm = rm.replace("%","%25");
    	}
        partURL = partURL + connector + "planIdentifier=" + rm + "&planIdentifierOp=" + planIdentifierOpVal;
        connector = "&";
    }

    if (!document.filterForm.hiddenStartDate.value == "")
    {
        partURL = partURL + connector + "startDate=" + document.filterForm.hiddenStartDate.value;
        connector = "&";
    }

    if (!document.filterForm.hiddenEndDate.value == "")
    {
        partURL = partURL + connector + "endDate=" + document.filterForm.hiddenEndDate.value;
    }


    location.href=partURL;

}

function dateChanged(hidden, viewed)
{
    if (viewed.value == "")
    {
        hidden.value = "";
    }
    else
    {
        validateDate(hidden, viewed);
    }
}

</script>
</head>

<body class="adminBodyClass">
<center>

<jsp:include page="AdminHeader.jsp" flush="true"/>
<br>
<form name="filterForm" method="get" action="PlanSummary.jsp">
<br>
<table bgcolor="#CCCCCC" border="0" cellpadding="4" cellspacing="1" class="tableClass" width="600" align="center">
<tr align="center" class="headrow">
    <td colspan="3" bgcolor="#EEEEEE" style="filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FFFFFF', endColorStr='#6699CC', gradientType='1')"><font color="#000000" size="2">Search Filter Criteria</font></td>
</tr>
<tr bgcolor="#FFFFFF">
    <td align="right"><b>Process Instance State</b></td>
    <td>
    <INPUT TYPE=CHECKBOX NAME= processState VALUE="Running">Running
    <INPUT TYPE=CHECKBOX NAME= processState VALUE="Closed">Closed
    <INPUT TYPE=CHECKBOX NAME= processState VALUE="Suspended">Suspended
    <INPUT TYPE=CHECKBOX NAME= processState VALUE="Aborted">Aborted
    <INPUT TYPE=CHECKBOX NAME= processState VALUE="Created">Created
    <INPUT TYPE=CHECKBOX NAME= processState VALUE="Error">Error
    </td>
</tr>

<tr bgcolor="#EEEEEE">
    <td align="right"><b>Process Instance Priority</b></td>
    <td>
    <INPUT TYPE=CHECKBOX NAME= processPriority VALUE="High">High
    <INPUT TYPE=CHECKBOX NAME= processPriority VALUE="Medium">Medium
    <INPUT TYPE=CHECKBOX NAME= processPriority VALUE="Low">Low
    </td>
</tr>

<tr bgcolor="#FFFFFF">
    <td align="right"><b>Process Instance Id</b></td>
    <td>
    <select name=processIDOp>
    <option selected>EqualTo</option>
    <option>GreaterThan</option>
    <option>In</option>
    <option>LessThan</option>
    <option>GreaterThanOrEqualTo</option>
    <option>LessThanOrEqualTo</option>
    <option>NotEqualTo</option>
    </select>
    <input type="text" name="processID" value=""></td>
</tr>

<tr bgcolor="#EEEEEE">
    <td align="right"><b>Process Instance Name</b></td>
    <td>
    <select name=processNameOp>
    <option selected>EqualTo</option>
    <option>GreaterThan</option>
    <option>In</option>
    <option>LessThan</option>
    <option>GreaterThanOrEqualTo</option>
    <option>LessThanOrEqualTo</option>
    <option>NotEqualTo</option>
    <option>Like</option>
    <option>NotLike</option>
    </select>
    <input type="text" name="processName" value=""></td>
</tr>

<tr bgcolor="#FFFFFF">
    <td align="right"><b>Process Instance Initiator</b></td>
    <td>
    <select name=processInitOp>
    <option selected>EqualTo</option>
    <option>GreaterThan</option>
    <option>In</option>
    <option>LessThan</option>
    <option>GreaterThanOrEqualTo</option>
    <option>LessThanOrEqualTo</option>
    <option>NotEqualTo</option>
    <option>Like</option>
    <option>NotLike</option>
    </select>
    <input type="text" name="processInit" value=""></td>
</tr>

<tr bgcolor="#EEEEEE">
    <td align="right"><b>Process Instance Title</b></td>
    <td>
    <select name=processTitleOp>
    <option selected>EqualTo</option>
    <option>GreaterThan</option>
    <option>In</option>
    <option>LessThan</option>
    <option>GreaterThanOrEqualTo</option>
    <option>LessThanOrEqualTo</option>
    <option>NotEqualTo</option>
    <option>Like</option>
    <option>NotLike</option>
    </select>
    <input type="text" name="processTitle" value=""></td>
</tr>

<tr bgcolor="#FFFFFF">
    <td align="right"><b>Process Instance Owner</b></td>
    <td>
    <select name=processOwnerOp>
    <option selected>EqualTo</option>
    <option>GreaterThan</option>
    <option>In</option>
    <option>LessThan</option>
    <option>GreaterThanOrEqualTo</option>
    <option>LessThanOrEqualTo</option>
    <option>NotEqualTo</option>
    <option>Like</option>
    <option>NotLike</option>
    </select>
    <input type="text" name="processOwner" value=""></td>
</tr>


<tr bgcolor="#EEEEEE">
    <td align="right"><b>Process Definition Id</b></td>
    <td>
    <select name=planIdOp>
    <option selected>EqualTo</option>
    <option>GreaterThan</option>
    <option>In</option>
    <option>LessThan</option>
    <option>GreaterThanOrEqualTo</option>
    <option>LessThanOrEqualTo</option>
    <option>NotEqualTo</option>
    </select>
    <input type="text" name="planId" value=""></td>
</tr>

<tr bgcolor="#FFFFFF">
    <td align="right"><b>Process Definition Name</b></td>
    <td>
    <select name=planNameOp>
    <option selected>EqualTo</option>
    <option>GreaterThan</option>
    <option>In</option>
    <option>LessThan</option>
    <option>GreaterThanOrEqualTo</option>
    <option>LessThanOrEqualTo</option>
    <option>NotEqualTo</option>
    <option>Like</option>
    <option>NotLike</option>
    </select>
    <input type="text" name="planName" value=""></td>
</tr>

<tr bgcolor="#EEEEEE">
    <td align="right"><b>Process Definition Identifier</b></td>
    <td>

    <select name=planIdentifierOp >
    <option selected>EqualTo</option>
    <option>GreaterThan</option>
    <option>In</option>
    <option>LessThan</option>
    <option>GreaterThanOrEqualTo</option>
    <option>LessThanOrEqualTo</option>
    <option>NotEqualTo</option>
    <option>Like</option>
    <option>NotLike</option>
    </select>
    <input type="text" name="planIdentifier" value=""></td>
</tr>

<tr bgcolor="#FFFFFF">
    <td align="right"><b>Date</b></td>
    <td>
    From &nbsp;
    <input type="hidden" name="hiddenStartDate" value="" size="14"/>
    <input type="text" name="displayStartDate" value="" size ="20" onChange="dateChanged(filterForm.hiddenStartDate,filterForm.displayStartDate);"/>
    <input type="image" name="calIconStartDate" src="calendar/cal.gif" width="16" height="15"/>
    <script type="text/javascript">
        Calendar.setup({inputField  : "displayStartDate", button      : "calIconStartDate", align   : "BR"});
        showTimeZone();
    </script>
    <br>
    To &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="hidden" name="hiddenEndDate" value="" size="14"/>
    <input type="text" name="displayEndDate" value="" size ="20" onChange="dateChanged(filterForm.hiddenEndDate,filterForm.displayEndDate);"/>
    <input type="image" name="calIconEndDate" src="calendar/cal.gif" width="16" height="15"/>
    <script type="text/javascript">
        Calendar.setup({inputField  : "displayEndDate", button      : "calIconEndDate", align   : "BR"});
        showTimeZone();
    </script>
    </td>

</tr>
    <tr>
        <td colspan="3" align ="center" bgcolor="#EEEEEE">
        <input type="button" onClick="filter()" value="Filter" name="button" class="core-button">
      </td>
    </tr>
</table>



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

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


%>
