<%@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.WFObjectFactory"
%><%@page import="com.fujitsu.iflow.model.workflow.Plan"
%><%@page import="com.fujitsu.iflow.model.workflow.ProcessInstantiator"
%><%@page import="com.fujitsu.iflow.model.workflow.WorkItem"
%><%@page import="com.fujitsu.iflow.model.wfcore.WFAdminSessionImpl"
%><%@page import="java.util.Enumeration"
%><%@page import="java.util.Date"
%><%@page import="java.lang.Long"
%><%@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 startDate = request.getParameter("startDate");
    String endDate = request.getParameter("endDate");
    Date date1 = new Date(Long.parseLong(startDate));
    Date date2 = new Date(Long.parseLong(endDate));
    String returnMsg = "";


    long[] archivedProcesses = wfSession.archiveClosedProcesses(date1,date2);

    if (archivedProcesses.length != 0)
    {
        String processIds = "";
        for (int i=0; i < archivedProcesses.length; i++) {
            processIds = processIds + archivedProcesses[i] + " ,";
        }
    returnMsg = "Process Instances with ID's " + processIds.substring(0,processIds.length() - 1) + " have been successfully archived.";
    }

    else
    {
        returnMsg = "No process Instances available to be archived";
    }

    String[] bcolor = {"evenrow","oddrow"};
    int nextColor = 0;

    session.setAttribute("TabIndex","1");
%>
<html>
<script>


function gotoProcessList()
{
    document.location.href='SortedProcessList.jsp';
}


</script>

<head><title>Interstage Business Process Manager | Archive</title></head>
<jsp:include page="StyleSheet.jsp" flush="true"/>
<script language="javascript" src="styles/clockscripts.js"></script>
</head>
<body class="adminBodyClass">
<center>

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

       <TABLE  border="0" cellpadding="2" cellspacing="1" class="tableClass" width="75%" align="center">
            <tr><td>&nbsp;</td></tr>
            <tr><td align="center">
            <img src="images/icons/info_excep.gif" border="0"><br/></td></tr>
            <tr><td>&nbsp;</td></tr>
        <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"><%= returnMsg %></font></td>
            </tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
            <tr><td>&nbsp;</td></tr>
            <tr><td align ="center">
            <input type="button" onClick="gotoProcessList()" value="Process Instance List" name="check" class="core-button">
            </td></tr>
          </TABLE>
</center>
</body>
</html>


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



%>
