<%@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.workflow.DataItemRef"
%><%@page import="com.fujitsu.iflow.model.workflow.Filter"
%><%@page import="com.fujitsu.iflow.model.workflow.JavaAction"
%><%@page import="com.fujitsu.iflow.model.workflow.JavaActionSet"
%><%@page import="com.fujitsu.iflow.model.workflow.Arrow"
%><%@page import="com.fujitsu.iflow.model.workflow.Node"
%><%@page import="com.fujitsu.iflow.model.workflow.FormRef"
%><%@page import="com.fujitsu.iflow.model.workflow.ProcessInstance"
%><%@page import="com.fujitsu.iflow.model.workflow.Arrow"
%><%@page import="com.fujitsu.iflow.model.workflow.ConditionSpec"
%><%@page import="com.fujitsu.iflow.model.workflow.BranchSpec"
%><%@page import="com.fujitsu.iflow.model.workflow.TimerDef"
%><%@page import="com.fujitsu.iflow.model.workflow.TimerAction"
%><%@page import="com.fujitsu.iflow.model.workflow.Plan"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"
%><%@page import="com.fujitsu.iflow.model.workflow.WFSession"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectList"
%><%@page import="com.fujitsu.iflow.model.util.QuickForm"
%><%@page import="com.fujitsu.iflow.model.util.ComplexConditionHelper"
%><%@page import="java.util.Arrays"
%><%@page import="java.io.Writer"
%><%@page import="java.awt.Point"
%><%@page import="com.fujitsu.iflow.model.util.URLEncoder"
%><%@page import="com.fujitsu.iflow.svg.SVGRender"
%><%@page import="com.fujitsu.iflow.model.util.QuickForm"
%><%request.setCharacterEncoding("UTF-8");request.getParameterNames(); //Need dummy call for WL9.1
%>
<%
    request.setCharacterEncoding("UTF-8");request.getParameterNames(); //Need dummy call for WL9.1
    WFSession wfSession = (WFSession)session.getAttribute("ModelsessionID");
    if (wfSession == null) {
        %><jsp:include page="PasswordPanel.jsp" flush="true"/><%
        return;
    }

    String piId = (String)request.getParameter("piId");
    if (piId == null) {
        throw new Exception("PIGraphic.jsp requires the process instance id to be specified in a 'piId' parameter.  No such parameter was found on this invocation.");
    }

    long piIdLong;
    try {
         piIdLong = Long.parseLong(piId);
    }
    catch (Exception e4) {
        throw new Exception("The piID variable had a problem being parsed as a long value: "+e4.toString());
    }

    ProcessInstance pi = null;

    String headRow = "";
    String planName = "";
    String isArchived = request.getParameter("isArchived");
    if(isArchived != null && isArchived.equals("true")){
        BPMSession bps = (BPMSession) session.getAttribute("BPMSession");
        BPMAdmin bpas = bps.getAdmin();
        pi = bpas.getArchivedProcess(piIdLong);
        headRow = "<font class=\"arialfonts\" color=\"#FFFFFF\">Archived Process Instance: ";
        planName = pi.getName();
    }
    else {
        pi = WFObjectFactory.getProcessInstance(piIdLong, wfSession);
        headRow = "<a href=ProcessInstance.jsp?piId=" + piId + "><font class=\"arialfonts\" color=\"#FFFFFF\">Process Instance " + piId +" : ";
        planName = pi.getName();
    }

    //ProcessInstance pi = WFObjectFactory.getProcessInstance(piIdLong, wfSession);
    Plan plan = pi.getPlan();
    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());
    }
%>
<HTML>
<HEAD>
<title>Interstage Business Process Manager | Process Instance 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="ProcessHeader.jsp" flush="true"/>
<br/> 
<%if(isArchived == null || isArchived.equals("false")){ 
  String tmpPiId = String.valueOf(pi.getId());
%>   
    <table cellpadding=2 cellspacing=1 class="tableclass" align="center" width="90%">
      <tr>
        <td align="left">
          <jsp:include page="GraphViewMenu.jsp">
            <jsp:param name="piId" value="<%=tmpPiId%>" />
              <jsp:param name="referralURL" value="<%=reqURL.toString() %>" />
                <jsp:param name="graphType" value="BPMN" />
          </jsp:include>
        </td>
      </tr>
    </table>   
<% } %>
<br/>
<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"><p><%=headRow%><%QuickForm.writeHtml(out, planName); %></font></a></p>
            </td></tr><tr><td>
            <table width="100%" cellpadding="10" border="0" cellspacing"0"><tr>
                <td align="center"><br><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
                  <object data="ProcInstGraphBPMN.jsp?piId=<%=piId%>&isArchived=<%=isArchived%>" type="image/svg+xml" width="<%=xmax+100%>" height="<%=ymax+100%>">
                  
              <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
              message, 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="ProcInstGraphNew.jsp?piId=<%=piId%>&isArchived=<%=isArchived%>">graphic
              file</a> directly and save it to disk for viewing outside the browser.
              (recommended for experts only)
                  </object></font></td>
              </tr></table></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
