<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"%>
<%@page errorPage="Exception.jsp"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMSession"
%><%@page import="com.fujitsu.iflow.model.bpmcore.BPMSessionImpl"
%><%@page import="com.fujitsu.iflow.model.util.QuickForm"
%><%@page import="com.fujitsu.iflow.model.util.URLEncoder"
%><%@page import="com.fujitsu.iflow.model.workflow.DataItemRef"
%><%@page import="com.fujitsu.iflow.model.workflow.Plan"
%><%@page import="com.fujitsu.iflow.model.workflow.Filter"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectList"
%><%@page import="com.fujitsu.iflow.model.workflow.WorkItem"
%><%@page import="com.fujitsu.iflow.server.dataobjects.FilterEnum"
%><%@page import="com.fujitsu.iflow.server.dataobjects.WorkItemStatesEnum"
%><%@page import="java.io.Writer"
%><%@page import="java.text.DateFormat"
%><%@page import="java.text.SimpleDateFormat"
%><%@page import="java.util.Collections"
%><%@page import="java.util.Date"
%><%@page import="java.util.Enumeration"
%><%@page import="java.util.Hashtable"
%><%@page import="java.util.Iterator"
%><%@page import="java.util.Vector"
%><%
    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;
    }
%>
<html>
<head>
<title>Interstage Business Process Manager | Advanced Work List Search Details</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 filterChanged()
{
    var iSelected = document.main.pdf.selectedIndex;
    var filterValue = document.main.pdf.options[iSelected].text;
    if (filterValue == "My Active Activities") {
        document.main.filterId.value = 11; //Filter.MyActiveWorkItems;
    }
    else if (filterValue == "My Accepted Activities") {
        document.main.filterId.value = 10; //Filter.MyAcceptedWorkItems;
    }
    else if (filterValue == "My Activities") {
        document.main.filterId.value = 7; //Filter.MyWorkItems;
    }
    else if (filterValue == "My Declined Activities") {
        document.main.filterId.value = 12; //Filter.MyDeclinedWorkItems;
    }
    else if (filterValue == "All Inactive Activities") {
        document.main.filterId.value = 14; //Filter.AllInactiveWorkItems;
    }
    else if (filterValue == "All Activities") {
        document.main.filterId.value = 6; //Filter.AllWorkItems;
    }
}

function addUda(){
    var uname = document.main.uname;
    var iSelected = document.main.uname.selectedIndex;
    if (iSelected < 0 || iSelected >= uname.options.length-1) {
        alert("Select UDA Name to Add");
        uname.focus();
        return;
    }
    var uop = document.main.uop;
    var uval = document.main.uval;
    var ulist = document.main.ulist;
    var ulistLength = ulist.options.length;

    var condition = uname.options[iSelected].text + " " +
                    uop.options[uop.selectedIndex].text + " " +
                    uval.value;

    for(var i = 0; i < ulistLength; i++) {
        if (condition == document.main.ulist.options[i].text) {
            return;
        }
    }

    ulist.options[ulistLength] = new Option(ulist.options[ulistLength-1].text);
    ulist.options[ulistLength-1] = new Option(condition);
}

function removeUda(){
    var iSelected = document.main.ulist.selectedIndex;
    if (iSelected < 0) return;
    var toRemove = document.main.ulist.options[iSelected].text;

    if (iSelected >= 0 && iSelected != document.main.ulist.options.length-1) {
        document.main.ulist.options[iSelected] = null;

    }
}

function addDisplayUda(){
    var iSelected = document.main.avlUdas.selectedIndex;
    if (iSelected >= 0 && iSelected != document.main.avlUdas.options.length-1) {
        var udaToAdd = document.main.avlUdas.options[iSelected].text;
        var selUdas = document.main.selUdas;
        var selUdasLen = selUdas.options.length;

        for(var i = 0; i < selUdasLen; i++) {
            if (udaToAdd == document.main.selUdas.options[i].text) {
                return;
            }
        }

        selUdas.options[selUdasLen] = new Option(selUdas.options[selUdasLen-1].text);
        selUdas.options[selUdasLen-1] = new Option(udaToAdd);
        populateSort();
    }
}

function removeDisplayUda(){
    var iSelected = document.main.selUdas.selectedIndex;
    if (iSelected < 0) return;
    var toRemove = document.main.selUdas.options[iSelected].text;

    if (iSelected >= 0 && iSelected != document.main.selUdas.options.length-1) {
        document.main.selUdas.options[iSelected] = null;
        populateSort();
    }
}

function addDisplayField(){
    var iSelected = document.main.avlFields.selectedIndex;
    if (iSelected >= 0 && iSelected != document.main.avlFields.options.length-1) {
        var fieldToAdd = document.main.avlFields.options[iSelected].text;
        var selFields = document.main.selFields;
        var selFieldsLen = selFields.options.length;

        for(var i = 0; i < selFieldsLen; i++) {
            if (fieldToAdd == document.main.selFields.options[i].text) {
                return;
            }
        }

        selFields.options[selFieldsLen] = new Option(selFields.options[selFieldsLen-1].text);
        selFields.options[selFieldsLen-1] = new Option(fieldToAdd);
        populateSort();
    }

}

function removeDisplayField(){
    var iSelected = document.main.selFields.selectedIndex;
    if (iSelected < 0) return;
    var toRemove = document.main.selFields.options[iSelected].text;

    if (iSelected >= 0 && iSelected != document.main.selFields.options.length-1) {
        document.main.selFields.options[iSelected] = null;
        populateSort();
    }
}

function doSubmit() {

    if (document.main.selFields.options.length <= 1) {
        alert("Please specify fields to display");
        document.main.avlFields.focus();
        return;
    }
    document.main.filterUdas.value = "";
    for(var i = 0; i < document.main.ulist.options.length-1; i++) {
        if (document.main.filterUdas.value == "" || document.main.filterUdas.value == null) {
            document.main.filterUdas.value = document.main.ulist.options[i].text;
        }
        else {
            document.main.filterUdas.value += ";" + document.main.ulist.options[i].text;
        }
    }
    document.main.dspFields.value = "";
    for(var i = 0; i < document.main.selFields.options.length-1; i++) {
        if (document.main.dspFields.value == "" || document.main.dspFields.value == null) {
            document.main.dspFields.value = document.main.selFields.options[i].text;
        }
        else {
            document.main.dspFields.value += "," + document.main.selFields.options[i].text;
        }
    }
    document.main.dspUda.value = "";
    for(var i = 0; i < document.main.selUdas.options.length-1; i++) {
        if (document.main.dspUda.value == "" || document.main.dspUda.value == null) {
            document.main.dspUda.value = document.main.selUdas.options[i].text;
        }
        else {
            document.main.dspUda.value += "," + document.main.selUdas.options[i].text;
        }
    }
    var iSelected = document.main.sort.selectedIndex;
    if (iSelected >= 0) {
        document.main.sortField.value = document.main.sort.options[iSelected].text;
    }
    document.main.submit();
}

function populateSort(){
    var selUdas = document.main.selUdas;
    var selFields = document.main.selFields;
    var sort = document.main.sort;
    var iSelected = sort.selectedIndex;
    var selected;
    if (iSelected >= 0) {
        selected = sort.options[iSelected].text;
    }
    else {
        selected = null;
    }
    for (i = 1; i < sort.options.length; i++) {
        sort.options[i] = null;
    }
    for (i = 0; i < selFields.options.length-1; i++) {
        var opt = new Option(selFields.options[i].text);
        sort.options[i+1] = opt;
    }
    var len = sort.options.length;
    for (k = 0; k < selUdas.options.length-1; k++) {
        var opt = new Option(selUdas.options[k].text);
        sort.options[len+k] = opt;
    }
    if (selected != null) {
        for (p = 0; p < sort.options.length; p++) {
            if (selected == sort.options[p].text) {
                sort.options[p].selected = true;
            }
        }
    }
}

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

function bodyLoaded()
{
    // Filter UDAs
    var ulist = document.main.ulist;
    var ulistLen = ulist.options.length;
    if (document.main.filterUdas.value != null && document.main.filterUdas.value != "") {
        //populate from hidden field (case of back button)
        var filterUdasArray = document.main.filterUdas.value.split(";");
        for (i=0; i < filterUdasArray.length; i++) {
            ulist.options[ulistLen] = new Option(ulist.options[ulistLen-1].text);
            ulist.options[ulistLen-1] = new Option(filterUdasArray[i]);
            ulistLen++;
        }
    }

    if (ulist.options.length == 1) {
        //populate from param (case of no back button, coming from 'Details' of saved search)
        if (document.main.filterUdasParam.value != null && document.main.filterUdasParam.value != "") {
            var filterUdasParamArray = document.main.filterUdasParam.value.split(";");
            for (i=0; i < filterUdasParamArray.length; i++) {
                ulist.options[ulistLen] = new Option(ulist.options[ulistLen-1].text);
                ulist.options[ulistLen-1] = new Option(filterUdasParamArray[i]);
                ulistLen++;
            }
        }
    }


    // Display fields
    var selFields = document.main.selFields;
    var selFieldsLen = selFields.options.length;
    var sort = document.main.sort;

    if (document.main.dspFields.value != null && document.main.dspFields.value != "") {
        //populate from hidden field (case of back button)
        var dspFieldsArray = document.main.dspFields.value.split(",");
        for (i=0; i < dspFieldsArray.length; i++) {
            selFields.options[selFieldsLen] = new Option(selFields.options[selFieldsLen-1].text);
            selFields.options[selFieldsLen-1] = new Option(dspFieldsArray[i]);
            selFieldsLen++;
            sort.options[sort.length] = new Option(dspFieldsArray[i]);
        }
    }
    if (selFields.options.length == 1) {
        //populate from param (case of no back button, coming from 'Details' of saved search)
        if (document.main.dspFieldsParam.value != null && document.main.dspFieldsParam.value != "") {
            var dspFieldsParamArray = document.main.dspFieldsParam.value.split(",");
            for (i=0; i < dspFieldsParamArray.length; i++) {
                selFields.options[selFieldsLen] = new Option(selFields.options[selFieldsLen-1].text);
                selFields.options[selFieldsLen-1] = new Option(dspFieldsParamArray[i]);
                selFieldsLen++;
                sort.options[sort.length] = new Option(dspFieldsParamArray[i]);
            }
        }
    }
    if (selFields.options.length == 1) {
        //populate defaults (case of brand new search)
        var blank = selFields[0].text;

        selFields.options[0] = new Option("Id");
        sort.options[sort.length] = new Option("Id");

        selFields.options[1] = new Option("Activity Name");
        sort.options[sort.length] = new Option("Activity Name");

        selFields.options[2] = new Option("Process Instance Name");
        sort.options[sort.length] = new Option("Process Instance Name");

        selFields.options[3] = new Option("Created");
        sort.options[sort.length] = new Option("Created");

        selFields.options[4] = new Option("Status");
        sort.options[sort.length] = new Option("Status");

        selFields.options[5] = new Option("Due Date");
        sort.options[sort.length] = new Option("Due Date");

        selFields.options[6] = new Option("Assignee");
        sort.options[sort.length] = new Option("Assignee");

        selFields.options[7] = new Option(blank);
    }

    // Display UDAs
    var selUdas = document.main.selUdas;
    var selUdasLen = selUdas.options.length;

    if (document.main.dspUda.value != null && document.main.dspUda.value != "") {
        //populate from hidden field (case of back button)
        var dspUdaArray = document.main.dspUda.value.split(",");
        for (i=0; i < dspUdaArray.length; i++) {
            selUdas.options[selUdasLen] = new Option(selUdas.options[selUdasLen-1].text);
            selUdas.options[selUdasLen-1] = new Option(dspUdaArray[i]);
            selUdasLen++;
            sort.options[sort.length] = new Option(dspUdaArray[i]);
        }
    }
    if (selUdas.options.length == 1) {
        //populate from param (case of no back button, coming from 'Details' of saved search)
        if (document.main.dspUdaParam.value != null && document.main.dspUdaParam.value != "") {
            var dspUdaParamArray = document.main.dspUdaParam.value.split(",");
            for (i=0; i < dspUdaParamArray.length; i++) {
                selUdas.options[selUdasLen] = new Option(selUdas.options[selUdasLen-1].text);
                selUdas.options[selUdasLen-1] = new Option(dspUdaParamArray[i]);
                selUdasLen++;
                sort.options[sort.length] = new Option(dspUdaParamArray[i]);
            }
        }
    }
    for (i=0; i < sort.length; i++) {
        if (document.main.sortField.value == sort.options[i].text) {
            sort.options[i].selected=true;
        }
    }
}

</script>
</head>

<body class="bodyClass" onload="bodyLoaded()">
<center>

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

<%
    int filterId = Filter.MyActiveWorkItems;
    int pageSize = 20;
    String sortField = "Id";
    String asc = "true";
    String filterName = "";
    String planName = "";
    String piName = "";
    String piopStr = "";
    String wiName = "";
    String wiopStr = "";
    String assigneeName = "";
    String asnopStr = "";
    String pageSizeStr = "";
    String udaFilters[] = null;
    Plan[] plans = null;
    DataItemRef dataItemRef = null;
    String hFrmCrt = "";
    String hToCrt = "";
    String hFrmDue = "";
    String hToDue = "";
    Vector sortList = new Vector();

    String dspFieldsParam = "";
    String dspUdaParam = "";
    String filterUdasParam = "";

    String[] filters = {
        "My Active Activities",
        "My Accepted Activities",
        "My Activities",
        "My Declined Activities",
        "All Inactive Activities",
        "All Activities"
    };
    String[] opts = {
        "Equal To",
        "Greater Than",
        "In",
        "Less Than",
        "Greater Than Or Equal To",
        "Less Than Or Equal To",
        "Not Equal To",
        "Like",
        "Not Like"
    };
    String[] pageSizeOpts = {
        "10",
        "20",
        "30",
        "50",
        "100"
    };
    boolean trace=false;

    String pageTitle = null;
    String srchnm = request.getParameter("srchnm");
    if (srchnm == null) {
        srchnm = "--new--";
        pageTitle = "New Advanced Work List Search";
    }
    else {
        pageTitle = "Advanced Work List Search - " + srchnm;
    }

    String filterIdStr = request.getParameter("filterId");
    debug(trace, out, "\n filterIdStr="+filterIdStr);

    planName = request.getParameter("pd");
    debug(trace, out, "\n planName="+planName);
    if (planName == null) {
        planName = "";
        debug(trace, out, "\n planName ="+planName+"'");
    }

    piName = request.getParameter("pin");
    if (piName == null) {
        piName = "";
    }
    piopStr = request.getParameter("piop");
    if (piopStr == null) {
        piopStr = "";
    }

    wiName = request.getParameter("win");
    if (wiName == null) {
        wiName = "";
    }
    wiopStr = request.getParameter("wiop");
    if (wiopStr == null) {
        wiopStr = "";
    }

    assigneeName = request.getParameter("asn");
    if (assigneeName == null) {
        assigneeName = "";
    }
    asnopStr = request.getParameter("asnop");
    if (asnopStr == null) {
        asnopStr = "";
    }

    pageSizeStr = request.getParameter("pg");
    if (pageSizeStr == null) {
        pageSizeStr = "";
    }
    debug(trace, out, "\n pageSizeStr="+pageSizeStr);

    hFrmCrt = request.getParameter("hFrmCrt");
    if (hFrmCrt == null) {
        hFrmCrt = "";
    }
    hToCrt = request.getParameter("hToCrt");
    if (hToCrt == null) {
        hToCrt = "";
    }
    hFrmDue = request.getParameter("hFrmDue");
    if (hFrmDue == null) {
        hFrmDue = "";
    }
    hToDue = request.getParameter("hToDue");
    if (hToDue == null) {
        hToDue = "";
    }
    sortField = request.getParameter("sort");
    if (sortField == null) {
        sortField = "Id";
    }
    asc = request.getParameter("asc");
    if (asc == null) {
        asc = "true";
    }
    dspFieldsParam = request.getParameter("dspFields");
    if (dspFieldsParam == null) {
        dspFieldsParam = "";
    }
    dspUdaParam = request.getParameter("dspUda");
    if (dspUdaParam == null) {
        dspUdaParam = "";
    }
    filterUdasParam = request.getParameter("filterUdas");
    if (filterUdasParam == null) {
        filterUdasParam = "";
    }

%>

<form id="main" name="main" method="get" action="WorkList.jsp">
  <input type="hidden" name="srchnm" value="<%=srchnm%>"/>
  <input type="hidden" name="filterUdas" value=""/>
  <input type="hidden" name="dspUda" value=""/>
  <input type="hidden" name="dspFields" value=""/>
  <input type="hidden" name="dspUdaParam" value="<%=dspUdaParam%>"/>
  <input type="hidden" name="dspFieldsParam" value="<%=dspFieldsParam%>"/>
  <input type="hidden" name="filterUdasParam" value="<%=filterUdasParam%>"/>
  <input type="hidden" name="pgNum" value="1"/>
  <input type="hidden" name="sortField" value="<%=sortField%>"/>

  <!-- Main table -->
  <table bgcolor="#CCCCCC" width="90%" border="0" cellpadding="2" cellspacing="1" align="center" class="tableclass">
    <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"><%=pageTitle%></font>
      </td>
    </tr>
    <tr class="oddrow">
      <td> <!-- Encloses 2nd level tables -->
        <br/>
        <!-- Filters table -->
        <table bgcolor="#CCCCCC" width="90%" border="0" cellpadding="2" cellspacing="1" align="center" class="tableclass">
          <tr class="headrow">
            <td colspan="2">
              <b>Filters</b>
            </td>
          </tr>
          <tr class="oddrow">
            <td align="right"><b>Predefined Filter</b></td>
            <td>
              <select name="pdf" onchange="filterChanged()">
<%
                String str = null;
                if(filterIdStr != null) {
                  filterId = new Integer(filterIdStr).intValue();
                }
                for (int i=0; i < filters.length; i++) {
                    if (getFilterTitleFromId(filterId).equals(filters[i])) {
                        str = "<option selected>" + filters[i] + "</option>";
                    }
                    else {
                        str = "<option>" + filters[i] + "</option>";
                    }
%>
                <%=str%>
<%
                }
%>
              </select>
              <input type="hidden" name="filterId" value="<%=filterId%>"/>
            </td>
          </tr>
          <tr class="evenrow">
            <td align="right"><b>Process Definition Name</b></td>
            <td>
              <select name="pd">
                <option>-- Select --</option>
<%
    plans = getPlans(bps);
    if (plans != null && plans.length > 0) {
        for (int i=0; i < plans.length; i++) {
            Plan p = plans[i];
            if (planName.equals(p.getName())) {
%>
                <option selected><%=p.getName()%></option>
<%
            }else{
%>
                <option><%=p.getName()%></option>
<%
            }
        }
    }
%>

              </select>
            </td>
          </tr>
          <tr class="oddrow">
            <td align="right"><b>Process Instance Name</b></td>
            <td>
              <select name="piop">
<%
                for (int i=0; i < opts.length; i++) {
                    if (piopStr.equalsIgnoreCase(opts[i])) {
%>
                      <option selected><%=opts[i]%></option>
<%
                    }else{
%>
                      <option><%=opts[i]%></option>
<%
                    }
                }
%>
              </select>
              <input type="text" name="pin" size="50" value="<%=piName%>"/>
            </td>
          </tr>
          <tr class="evenrow">
            <td align="right"><b>Workitem Name</b></td>
            <td>
              <select name="wiop">
<%
                for (int i=0; i < opts.length; i++) {
                    if (wiopStr.equalsIgnoreCase(opts[i])) {
%>
                      <option selected><%=opts[i]%></option>
<%
                    }else{
%>
                      <option><%=opts[i]%></option>
<%
                    }
                }
%>
              </select>
              <input type="text" name="win" size="50" value="<%=wiName%>"/>
            </td>
          </tr>
          <tr class="oddrow">
            <td align="right"><b>Workitem Created Date</b></td>
            <td align="center">
              From &nbsp;
              <input type="hidden" name="hFrmCrt" size="14" value="<%=hFrmCrt%>"/>
              <input type="text" name="dFrmCrt" size="20" onChange="dateChanged(main.hFrmCrt,main.dFrmCrt);"/>
              <input type="image" name="cFrmCrt" src="calendar/cal.gif" width="16" height="15"/>
              <script type="text/javascript">
                  main.dFrmCrt.value = formatDate(main.hFrmCrt.value);
                  Calendar.setup({inputField  : "dFrmCrt", button      : "cFrmCrt", align   : "UR"});
                  showTimeZone();
              </script>
              <br>
              To &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <input type="hidden" name="hToCrt" size="14" value="<%=hToCrt%>"/>
              <input type="text" name="dToCrt" size="20" onChange="dateChanged(main.hToCrt,main.dToCrt);"/>
              <input type="image" name="cToCrt" src="calendar/cal.gif" width="16" height="15"/>
              <script type="text/javascript">
                  main.dToCrt.value = formatDate(main.hToCrt.value);
                  Calendar.setup({inputField  : "dToCrt", button      : "cToCrt", align   : "UR"});
                  showTimeZone();
              </script>
            </td>
          </tr>
          <tr class="evenrow">
            <td align="right"><b>Due Date</b></td>
            <td align="center">
              From &nbsp;
              <input type="hidden" name="hFrmDue" size="14" value="<%=hFrmDue%>"/>
              <input type="text" name="dFrmDue" size="20" onChange="dateChanged(main.hFrmDue,main.dFrmDue);"/>
              <input type="image" name="cFrmDue" src="calendar/cal.gif" width="16" height="15"/>
              <script type="text/javascript">
                  main.dFrmDue.value = formatDate(main.hFrmDue.value);
                  Calendar.setup({inputField  : "dFrmDue", button      : "cFrmDue", align   : "UR"});
                  showTimeZone();
              </script>
              <br>
              To &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <input type="hidden" name="hToDue" value="" size="14" value="<%=hToDue%>"/>
              <input type="text" name="dToDue" size="20" onChange="dateChanged(main.hToDue,main.dToDue);"/>
              <input type="image" name="cToDue" src="calendar/cal.gif" width="16" height="15"/>
              <script type="text/javascript">
                  main.dToDue.value = formatDate(main.hToDue.value);
                  Calendar.setup({inputField  : "dToDue", button      : "cToDue", align   : "UR"});
                  showTimeZone();
              </script>
            </td>
          </tr>
          <tr class="oddrow">
            <td align="right"><b>Assignee</b></td>
            <td>
              <select name="asnop">
<%
                for (int i=0; i < opts.length; i++) {
                    if (asnopStr.equalsIgnoreCase(opts[i])) {
%>
                      <option selected><%=opts[i]%></option>
<%
                    }else{
%>
                      <option><%=opts[i]%></option>
<%
                    }
                }
%>
              </select>
              <input type="text" name="asn" size="50" value="<%=assigneeName%>"/>
            </td>
          </tr>
        </table>
        <!-- ******************** End Filters table ******************** -->
        <!-- ******************** UDA Filters Table ******************** -->
        <p><br/></p>
        <table bgcolor="#CCCCCC" width="90%" border="0" cellpadding="2" cellspacing="1" align="center" class="tableclass">
          <tr class="headrow">
            <td colspan="4">
              <b>Work List User Defined Attribute Filters</b>
            </td>
          </tr>
          <tr class="oddrow">
            <td align="center"><b>Name (Type)</b></td>
            <td align="center"><b>Operator</b></td>
            <td align="center"><b>Filter value</b></td>
            <td/>
          </tr>
          <tr class="oddrow">
            <td align="center">
              <select name="uname">
<%
        Vector udaVector = new Vector();
        if (plans != null && plans.length > 0) {
            Hashtable udalist = new Hashtable();
            String udaname = null;
            for (int i=0; i < plans.length; i++) {
                Plan plan = plans[i];
                DataItemRef[] dataItemRefs = plan.getDataItemRefs();
                if (dataItemRefs != null && dataItemRefs.length > 0) {
                    for (int k=0; k < dataItemRefs.length; k++) {
                        dataItemRef = dataItemRefs[k];
                        debug(trace, out, "plan="+plan.getName()+",uda="+dataItemRef.getName());
                        if (dataItemRef.isWorkListUDA()) {
                            udaname = dataItemRef.getName()+" ("+dataItemRef.getType()+")";
                            udalist.put(udaname, udaname);
                        }
                    }
                }
            }
            udaVector = new Vector(udalist.keySet());
        }
        Collections.sort(udaVector);
        Iterator udaIter = udaVector.iterator();
        while (udaIter.hasNext()) {
            String element =  (String)udaIter.next();
%>
                <option><%=element%></option>
<%
        }
%>
                <option>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                </option>
              </select>
            </td>
            <td align="center">
              <select name="uop">
                <option><%=WFObjectList.SQLOP_EQUALTO%></option>
                <option><%=WFObjectList.SQLOP_GREATERTHAN%></option>
                <option>In</option>
                <option><%=WFObjectList.SQLOP_LESSTHAN%></option>
                <option><%=WFObjectList.SQLOP_GREATERTHANOREQUALTO%></option>
                <option><%=WFObjectList.SQLOP_LESSTHANOREQUALTO%></option>
                <option><%=WFObjectList.SQLOP_NOTEQUALTO%></option>
                <option>Like</option>
                <option>Not Like</option>
              </select>
            </td>
            <td align="center">
              <input type="text" name="uval" size="35"/>
            </td>
            <td align="center">
              <input value="Add" type="button" class="core-button" onclick="addUda()"/>
            </td>
          </tr>
          <tr class="oddrow">
            <td colspan="3" align="center">
              <select name="ulist" size="5">
                <option>
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  &nbsp;&nbsp;&nbsp;&nbsp;
                </option>
              </select>
            </td>
            <td align="center" valign="center">
              <input value="Remove" type="button" class="core-button" onclick="removeUda()"/>
            </td>
          </tr>
        </table>
        <!-- End UDA Filters table -->
        <p><br/></p>
        <!-- Fields table -->
        <table bgcolor="#CCCCCC" width="90%" border="0" cellpadding="0" cellspacing="1" align="center" class="tableclass">
          <tr class="headrow">
            <td>
              <b>&nbsp;Choose Fields To Display</b>
            </td>
          </tr>
          <tr>
            <td>
              <table border="0" cellspacing="0" width="100%">
                <tr class="oddrow">
                  <td align="center"><b>&nbsp;Available Fields</b></td>
                  <td/>
                  <td align="center"><b>Selected Fields</b></td>
                </tr>
                <tr class="oddrow">
                  <td align="center">
                    <select name="avlFields" size="5">
                      <option>Id</option>
                      <option>Activity Name</option>
                      <option>Process Instance Name</option>
                      <option>Created</option>
                      <option>Status</option>
                      <option>Due Date</option>
                      <option>Assignee</option>
                      <option>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                      </option>
                    </select>
                  </td>
                  <td align="center">
                    <table border="0">
                      <tr>
                        <td align="center">
                          <input type="button" value="&nbsp;>&nbsp;" class="core-button" onclick="addDisplayField()"/>
                        </td>
                      </tr>
                      <tr>
                        <td align="center">
                          <input type="button" value="&nbsp;<&nbsp;" class="core-button" onclick="removeDisplayField()"/>
                        </td>
                      </tr>
                    </table>
                  </td>
                  <td align="center">
                    <select name="selFields" size="5">
                      <option>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                      </option>
                    </select>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
        <!-- End Fields table -->
        <p><br/></p>
        <!-- Worklist UDA table -->
        <table bgcolor="#CCCCCC" width="90%" border="0" cellpadding="0" cellspacing="1" align="center" class="tableclass">
          <tr class="headrow">
            <td>
              <b>&nbsp;Choose Work List User Defined Attributes To Display</b>
            </td>
          </tr>
          <tr>
            <td>
              <table border="0" cellspacing="0" width="100%">
                <tr class="oddrow">
                  <td align="center"><b>&nbsp;Available Work List UDAs</b></td>
                  <td/>
                  <td align="center"><b>Selected Work List UDAs</b></td>
                </tr>
                <tr class="oddrow">
                  <td align="center">
                    <select name="avlUdas" size="5">
<%
        udaIter = udaVector.iterator();
        while (udaIter.hasNext()) {
            String element =  (String)udaIter.next();
%>
                   <option><%=element%></option>
<%
        }
%>
                      <option>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                      </option>
                    </select>
                  </td>
                  <td align="center">
                    <table border="0">
                      <tr>
                        <td align="center">
                          <input type="button" value="&nbsp;>&nbsp;" class="core-button" onclick="addDisplayUda()"/>
                        </td>
                      </tr>
                      <tr>
                        <td align="center">
                          <input type="button" value="&nbsp;<&nbsp;" class="core-button" onclick="removeDisplayUda()"/>
                        </td>
                      </tr>
                    </table>
                  </td>
                  <td align="center">
                    <select name="selUdas" size="5">
                      <option>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                      </option>
                    </select>
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
        <!-- End Worklist UDA table -->
        <p><br/></p>
        <!-- Sort table -->
        <table bgcolor="#CCCCCC" width="90%" border="0" cellpadding="2" cellspacing="1" align="center" class="tableclass">
          <tr class="headrow">
            <td colspan="2">
              <b>Sort</b>
            </td>
          </tr>
          <tr class="oddrow">
            <td align="right" width="100"><b>Sort Order</b></td>
            <td>
              <select name="sort">
                <option>-- Select --</option>
              </select>
<%
              String ascChecked = "";
              String descChecked = "";
              if(asc.equals("true")) {
                  ascChecked = "checked";
              }
              else {
                  descChecked = "checked";
              }
%>
              <input type="radio" name="asc" value="true" <%=ascChecked%>>Ascending
              <input type="radio" name="asc" value="false" <%=descChecked%>>Descending
            </td>
          </tr>
        </table>
        <!-- End Sort table -->
        <p><br/></p>
        <!-- Page Size table -->
        <table bgcolor="#CCCCCC" width="90%" border="0" cellpadding="2" cellspacing="1" align="center" class="tableclass">
          <tr class="headrow">
            <td colspan="2">
              <b>Page Size</b>
            </td>
          </tr>
          <tr class="oddrow">
            <td align="right" width="100"><b>Page Size</b></td>
            <td>
              <select name="pg">
<%
                for (int i=0; i < pageSizeOpts.length; i++) {
                    if (pageSizeStr.equalsIgnoreCase(pageSizeOpts[i])) {
%>
                      <option selected><%=pageSizeOpts[i]%></option>
<%
                    }else{
%>
                      <option><%=pageSizeOpts[i]%></option>
<%
                    }
                }
%>
              </select>
            </td>
          </tr>
        </table>
        <!-- End Page Size table -->
        <br/>
      </td>
    </tr>
  </table>
  <!-- End Main table -->
  <!-- Search Button table -->
  <table border="0" cellpadding="2" cellspacing="1" align="center" class="tableclass">
    <tr class="row">
      <td>
        <input type="button" value="Search" class="core-button" onclick="doSubmit()"/>
      </td>
    </tr>
  </table>
  <!-- End Button table -->


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

<%!
    public
    Plan[]
    getPlans(BPMSession bps)
        throws Exception
    {
        WFObjectList wfObjectList=null;
        try {
            wfObjectList = WFObjectFactory.getWFObjectList(((BPMSessionImpl)bps)._wfs);
            wfObjectList.openList(Filter.AllPlans);
            Object[] objList = wfObjectList.getAllObjects();
            Plan[] plans = null;
            if (objList != null && objList.length > 0) {
                plans = new Plan[objList.length];
                for (int i=0; i < objList.length; i++) {
                    plans[i] = (Plan)objList[i];
                }
            }
            return plans;
        }
        catch (Exception e)
        {
          throw new Exception("WorklistSearchDtl.jsp: getPlans failed because\n" + e.toString());
        }
        finally
        {
            if (wfObjectList != null)
                wfObjectList.closeList();
        }
    }

    public void debug (boolean trace, Writer out, String msg) throws Exception
    {
        if (trace) {
            System.out.println(msg);
        }
    }

    public
    String
    getFilterTitleFromId(
        int filterId)
    {
        String filterTitle = "My Active Activities";
        switch(filterId){
            case Filter.MyActiveWorkItems:
                filterTitle = "My Active Activities";
                break;
            case Filter.MyAcceptedWorkItems:
                filterTitle = "My Accepted Activities";
                break;
            case Filter.MyWorkItems:
                filterTitle = "My Activities";
                break;
            case Filter.MyDeclinedWorkItems:
                filterTitle = "My Declined Activities";
                break;
            case Filter.MyCompletedWorkItems:
                filterTitle = "My Completed Activities";
                break;
            case Filter.AllInactiveWorkItems:
                filterTitle = "All Inactive Activities";
                break;
            case Filter.AllWorkItems:
                filterTitle = "All Activities";
                break;
        }
        return filterTitle;
    }

%>