<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"
%><%@page errorPage="AdminException.jsp"
%><%@page import="com.fujitsu.iflow.model.workflow.WFAdminSession"
%><%@page import="com.fujitsu.iflow.model.wfcore.WFAdminSessionImpl"
%><%@page import="com.fujitsu.iflow.model.workflow.ProcessInstance"
%><%@page import="com.fujitsu.iflow.model.workflow.Plan"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectList"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"
%><%@page import="com.fujitsu.iflow.server.dataobjects.ProcessInstanceStatesEnum"
%><%@page import="com.fujitsu.iflow.server.dataobjects.ProcessDefinitionStatesEnum"
%><%@page import="com.fujitsu.iflow.server.dataobjects.FilterEnum"
%><%@page import="com.fujitsu.iflow.model.workflow.Filter"
%><%@page import="java.util.Date"
%><%@page import="java.util.Properties"
%><%@page import="java.util.Enumeration"
%><%@page import="java.text.SimpleDateFormat"
%><%@page import="java.io.Writer"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMAdmin"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMSession"
%><%@page import="com.fujitsu.iflow.model.bpmcore.BPMAdminImpl"
%><%
    request.setCharacterEncoding("UTF-8");request.getParameterNames(); //Need dummy call for WL9.1
    BPMSession bps = (BPMSession) session.getAttribute("BPMSession");
    if (bps == null) {
        %><jsp:include page="PasswordPanel.jsp" flush="true"/><%
        return;
    }

    BPMAdmin bpas = bps.getAdmin();
    WFAdminSessionImpl wfSession = ((BPMAdminImpl)bpas)._wfas;

    String returnMsg = null;
    boolean browseDMS = false;

    String url ="";

    String planId = request.getParameter("planId");
    if (planId == null) {
        planId = (String) session.getAttribute("planId");
    }
    long id = Long.parseLong(planId);

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

    String path = request.getParameter("path");
    String fileName = request.getParameter("fileName");

    String pwd = (String)session.getAttribute("password");

    String sel = request.getParameter("selected");
    if(sel != null)
    {
        int selValue = new Integer(sel).intValue();
        session.setAttribute("selected", sel);
        switch(selValue){
            case 1: returnMsg = deletePlan(wfSession, id);
                    break;
            case 2: returnMsg = modifyOwner(wfSession, id, owner);
                    break;
            case 3: returnMsg = publishPlan(wfSession, id);
                    break;
            case 4: returnMsg = obsoletePlan(wfSession, id);
                    break;
            case 5: returnMsg = archivePlan(wfSession, id);
                    break;
            case 6: browseDMS = true;
                    break;
        }
    }

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

%>

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

<body class="adminBodyClass">
<script>

function setPlanId(val, id, actionForm)
{
    actionForm.planId.value= id
    actionForm.selected.value= val
    actionForm.submit()
}


function gotoPlanList()
{
    document.location.href='SortedPlanList.jsp';
}


</script>
<center>

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

<%

if(browseDMS == true) {
url =  "ExportXPDL.jsp?planId=" + planId + "&type=xml";
response.sendRedirect(response.encodeRedirectURL(url));
}
%>

       <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="gotoPlanList()" value="Process Definition List" name="check" class="core-button">
            </td></tr>
          </TABLE>
 </center>
 </body>
</html>

<%!
    public String deletePlan(WFAdminSessionImpl wfSession, long id) throws Exception
    {
        wfSession.deletePlan(id);
        return "Process Definition with ID " + id + " has been successfully deleted";
    }

    public String modifyOwner(WFAdminSessionImpl wfSession, long id, String owner) throws Exception
    {
        Plan plan = WFObjectFactory.getPlan(id, wfSession);
        try
        {
        	plan.startEdit();
        	plan.setOwner(owner);
        	plan.commitEdit();
        	return "Owner for Process Definition with ID " + id + " has been successfully modified to " + owner;
    	}
    	catch(Exception e)
    	{
    		plan.cancelEdit();
    		return "Modify Owner for Process Definition with ID " + id + " failed. Please enter a valid User Name.";
    	}
    }

    public String archivePlan(WFAdminSessionImpl wfSession, long id) throws Exception
    {
        wfSession.archivePlan(id);
        return "Process Definition with ID " + id + " has been successfully archived";
    }

    public String publishPlan(WFAdminSessionImpl wfSession, long id) throws Exception
    {
        wfSession.publishPlan(id);
        return "Process Definition with ID " + id + " has been successfully published";
    }

    public String obsoletePlan(WFAdminSessionImpl wfSession, long id) throws Exception
    {
        wfSession.obsoletePlan(id);
        return "Process Definition with ID " + id + " is now obsolete ";
    }

    public String copyPlan(WFAdminSessionImpl wfSession, long id) throws Exception
    {
        Plan plan = WFObjectFactory.getPlan(id, wfSession);
        long newID = wfSession.createPlanVersion(plan.getName(), "", plan.getVersion());
        return "New Process Definition for " + plan.getName() + " with ID " + newID + " created";
    }

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



%>
