<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"
%><%@page errorPage="Exception.jsp"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMSession"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMAdmin"
%><%@page import="com.fujitsu.iflow.model.util.ComplexConditionHelper"
%><%@page import="com.fujitsu.iflow.model.util.QuickForm"
%><%@page import="com.fujitsu.iflow.model.util.URLEncoder"
%><%@page import="com.fujitsu.iflow.model.workflow.Arrow"
%><%@page import="com.fujitsu.iflow.model.workflow.BranchSpec"
%><%@page import="com.fujitsu.iflow.model.workflow.ConditionSpec"
%><%@page import="com.fujitsu.iflow.model.workflow.DataItemRef"
%><%@page import="com.fujitsu.iflow.model.workflow.Filter"
%><%@page import="com.fujitsu.iflow.model.workflow.FormRef"
%><%@page import="com.fujitsu.iflow.model.workflow.JavaAction"
%><%@page import="com.fujitsu.iflow.model.workflow.JavaActionSet"
%><%@page import="com.fujitsu.iflow.model.workflow.Node"
%><%@page import="com.fujitsu.iflow.model.workflow.Plan"
%><%@page import="com.fujitsu.iflow.model.workflow.TimerAction"
%><%@page import="com.fujitsu.iflow.model.workflow.TimerDef"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectList"
%><%@page import="java.awt.Point"
%><%@page import="java.io.Writer"
%><%@page import="java.util.Arrays"
%>
<%
    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;
    }

    String planId = (String)request.getParameter("planId");
    if (planId == null) {
        throw new Exception("PDGraphic.jsp requires the process definition id to be specified in a 'planId' parameter.  No such parameter was found on this invocation.");
    }
    Plan plan = null;
    String headRow = "<a href=\"ProcessDefinition.jsp?planID=" + planId +"\"><font color=\"#FFFFFF\">Process Definition " + planId;
    String isArchived = request.getParameter("isArchived");
    if(isArchived != null && isArchived.equals("true")){
         BPMAdmin bpas = bps.getAdmin();
         plan = bpas.getArchivedPlan(Long.parseLong(planId));
         headRow = "<font color=\"#FFFFFF\">Archived Process Definition" + planId + " : " + plan.getName();
    }
    else {
        plan = bps.getPlan(Long.parseLong(planId));
        headRow = headRow + " : " + plan.getName();
    }
    int xmax = 290;
    int ymax = 290;
    Node[] allNodes = plan.getNodes();
    int last = allNodes.length;
    for (int i=0; i<last; i++) {

        Node aNode = allNodes[i];
        Point p = aNode.getPosition();
        if (p.x+60>xmax) xmax = p.x+60;
        if (p.y+45>ymax) ymax = p.y+45;

    }
//set URL
    StringBuffer reqURL = request.getRequestURL();
    reqURL.append("?");
    if (request.getQueryString() != null) {
        reqURL.append(request.getQueryString());
    }
    session.setAttribute("TabIndex","2");
%>
<HTML>
<HEAD>
<title>Interstage Business Process Manager | Process Definition Graphic</TITLE>
<script language="javascript" src="styles/clockscripts.js"></script>
<jsp:include page="StyleSheet.jsp" flush="true"/>
</HEAD>
<body class="bodyClass" onLoad="goforit();">
    <jsp:include page="Header.jsp" flush="true"/>
<br/>
<%if(isArchived == null || isArchived.equals("false")){ 
  String tmpPlanId = ""+plan.getId();
  String tmpEditMode = ""+plan.isInEditMode();
%>
     <jsp:include page="TemplateMenu.jsp">
          <jsp:param name="planId" value="<%= String.valueOf(tmpPlanId) %>" />
          <jsp:param name="editMode" value="<%= String.valueOf(tmpEditMode) %>" />
           <jsp:param name="referralURL" value="<%=reqURL.toString() %>" />

    </jsp:include>
<%}%>

<table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
  <tr>
    <td><table width="100%" border="0" align="center" cellpadding="4" cellspacing="0" bgcolor="#FFFFFF">
        <tr>
          <td class="headrow"><%=headRow%></font></a></td>
        </tr>
        <tr>
          <td align="center"><br><object data="ProcDefGraph.jsp?planId=<%=planId%>&amp;isArchived=<%=isArchived%>" type="image/svg+xml" width="<%=xmax+100%>"

            height="<%=ymax+100%>">
               <table width="100%" cellpadding="10" border="0" cellspacing="0"><tr><td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
               <img src="images/icons/error.gif" border="0" align="left" hspace="8">This is where the graphic is supposed to appear.
               If you see this sentence, it means the object tag was not correctly processed by your browser.
               Usually this means that you need to install an SVG viewer into your browser.<br/>
               <br/>
               You can get an SVG viewer from Adobe at <a href="http://www.adobe.com/svg/main.html">http://www.adobe.com/svg/main.html</a>.<br/><br/>
               The installation is quick and easy.Or you can access the <a href="ProcDefGraph.jsp?planId=<%=planId%>&amp;isArchived=<%=isArchived%>">graphic file</a> directly and save it to disk for viewing outside the browser. <font color="#cccccc">(recommended for experts only)</font>
            </font></td>
        </tr></table></object>
    </td></tr></table>
</td></tr></table>
</body>
</html>
