<%@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.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;

    String planId = request.getParameter("planId");
    String newName = request.getParameter("newName");
    String comment = request.getParameter("comment");
    String isArchived = request.getParameter("isArchived");

    long id = Long.parseLong(planId);

    Plan plan = null;
    if (isArchived != null && isArchived.equals("true")) {
		// the adminSession has to be set because otherwise the method
		// "Plan.saveAs()" won't work
    	plan = wfSession.getArchivedPlan(id);
    	plan.setWFSession(wfSession);
    }
    else {
	    plan = WFObjectFactory.getPlan(id, wfSession);
    }

    if ((newName == "") || (newName == null))
    {
        newName = plan.getName();
    }

    Plan newPlan = plan.saveAs(newName);
    String returnMsg = "New process definition with id " + newPlan.getId() + " successfully created.";

%>
<html>
<head><title>Interstage Business Process Manager | Create Process Definition Version</title>
<jsp:include page="StyleSheet.jsp" flush="true"/>
<script>

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

</script>


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


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



%>
