<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"
%><%@page errorPage="Exception.jsp"
%><%@page import="com.fujitsu.iflow.common.UdaNameSanitizer"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMSession"
%><%@page import="com.fujitsu.iflow.model.util.QuickForm"
%><%@page import="com.fujitsu.iflow.model.util.QuickFormOperation"
%><%@page import="com.fujitsu.iflow.model.workflow.DataItem"
%><%@page import="com.fujitsu.iflow.model.workflow.FormRef"
%><%@page import="com.fujitsu.iflow.model.workflow.NodeInstance"
%><%@page import="com.fujitsu.iflow.model.workflow.Plan"
%><%@page import="com.fujitsu.iflow.model.workflow.ProcessInstance"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"
%><%@page import="com.fujitsu.iflow.model.workflow.WorkItem"
%><%@page import="java.io.File"
%><%@page import="java.io.Writer"
%><%@page import="java.io.PrintWriter"
%><%@page import="java.lang.Long"
%><%@page import="com.fujitsu.iflow.model.util.URLEncoder"
%><%@page import="java.net.URL"
%><%@page import="java.text.ParseException"
%><%@page import="java.text.DateFormat"
%><%@page import="java.util.Date"
%><%@page import="java.util.Hashtable"
%><%@page import="java.util.Locale"
%><%
    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;
    }

    // change this variable if you save this file to a new name.
    String nameOfThisPage = "TemplateCopy.jsp";

    String pdIdStr = request.getParameter("pdId");
    if (pdIdStr == null) {
        throw new Exception(nameOfThisPage + " needs a pdId parameter to tell it which process definition to work on.");
    }

    long piId = 0;
    try {
        piId = Long.parseLong(pdIdStr);
    }
    catch (Exception e) {
        throw new Exception(nameOfThisPage + " pdId parameter must be an integer value instead of ("+pdIdStr+")");
    }

    Plan plan = bps.getPlan(piId);

    String command = request.getParameter("Command");
    if (command == null) {
        throw new Exception(nameOfThisPage + " needs a Command parameter to tell it which command to work on.");
    }

    String pageTitle = "Interstage Business Process Manager";

    if (command.equalsIgnoreCase("COPY")) {

        pageTitle = pageTitle + " | Copy Process Definition";
    }

%>
<html>
<head><title><%QuickForm.writeHtml(out,pageTitle);%></title>
<jsp:include page="StyleSheet.jsp" flush="true"/>
<script language="javascript" src="styles/clockscripts.js"></script>

<script language="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 formValidation()
{
    var templateName = document.copyPlan.newName.value;
    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;
    }
}

</script>

</head>
<body class="bodyClass" onLoad="goforit();">
<jsp:include page="Header.jsp" flush="true"/>
<%
if(command.equals("Copy")){
%>
<br/><br/>
<br/><br/>
<form method="post" name="copyPlan" action="TemplateCommands.jsp" onSubmit="return formValidation()">
<TABLE border="0" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC" class="tableClass" width="500" align="center">
  <tr>

      <td class="headrow">Copy Process Definition: <%=plan.getName()%> </td>
    </tr>
    <tr>
            <td bgcolor="#FFFFFF" align="center"><br/>
      Process Definition Name:
      <input type="text" name="newName" size="50">
      <br/><br/>
      </td>
    </tr>
    <tr>
        <td valign="middle" align="center" bgcolor="#EEEEEE">
        <input type="hidden" name="pdId" value = "<%=pdIdStr%>" > <input type="hidden" name="mode" value="CopyWithName">
      <input type="submit" value="Copy" class="submitClass">
        </td>
    </tr>
</table>
</form>
<%
//Add more views for other commands
}else{
        throw new Exception(command + " not supported");
}

%>
</body>
</html>
