<%@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="com.fujitsu.iflow.model.util.QuickForm"
%><%@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 isArchived = request.getParameter("isArchived");

    long id = Long.parseLong(planId);

    Plan plan = null;

    if (isArchived != null && isArchived.equals("true")) {
        plan = wfSession.getArchivedPlan(id);
    }
    else {
        plan = WFObjectFactory.getPlan(id, wfSession);
    }

    String planName = plan.getName();

%>
<html>
<head><title>Interstage Business Process Manager | Copy Plan</title>
<jsp:include page="StyleSheet.jsp" flush="true"/>
<script language="javascript" src="styles/clockscripts.js"></script>
<SCRIPT TYPE="text/javascript">


function trimAll(sString)
{
    while (sString.substring(0,1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ') {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

function createNewVersion(id)
{
    var templateName = document.copyPlan.newName.value;

    <%
        String isArchivedSuffix = "";
        if (isArchived != null && isArchived.equals("true")) {
            isArchivedSuffix += "&isArchived=true";
        }
    %>

    var isArchivedSuffix = "<%=isArchivedSuffix%>";


    templateName = trimAll(templateName);

    if (templateName.length == 0) {
        alert("Please enter a valid process definition name.");
        document.copyPlan.newName.value="";
        document.copyPlan.newName.focus();
        document.copyPlan.newName.select();
        return false;
    }

    if (templateName.length > 30) {
        alert("Process definition  name cannot be more than 30 characters.");
        document.copyPlan.newName.focus();
        document.copyPlan.newName.select();
        return false;
    }
    return true;

}

</script>
</head>


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

<br/><br/>
<TABLE cols ="2" border="0" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC" class="tableClass" width="450" align= "center">
    <form name="copyPlan" method="post" action="CreateNewVersion.jsp" onSubmit="return createNewVersion(<%= planId %>)">
    
    <input type="hidden" name="planId" value="<%= planId %>">
    <input type="hidden" name="isArchived" value="<%= isArchived %>">
    
    <center>
    <tr>
        <td colspan="2" class="headrow">Create new version of Process definition  (<%= planId %>) </td>
    </tr>
    <tr>
            <td bgcolor="#FFFFFF" align="center"><br/> Process Definition name : </td>
            <td bgcolor="#FFFFFF" ><input type="text" size =15 name= "newName" value="<% QuickForm.writeHtml(out, planName); %>" ></td>
    </tr>

    <tr>
        <td colspan ="2" valign="middle" align="center" bgcolor="#EEEEEE">
        <input type="submit" value="Copy" class="submitClass">
        </td>
    </tr>
    </center>
    </form>
</table>
</body>
</html>


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



%>
