<%@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.workflow.Plan"
%><%@page import="com.fujitsu.iflow.model.workflow.ProcessInstance"
%><%@page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"
%><%@page import="com.fujitsu.iflow.model.util.URLEncoder"
%><%
    request.setCharacterEncoding("UTF-8");request.getParameterNames(); //Need dummy call for WL9.1
    BPMSession bps = (BPMSession) session.getAttribute("BPMSession");
    if (bps == null) {
        throw new Exception("Somehow got to the ProcessMenu.jsp without a valid session.  Any page including the ProcessMenu.jsp must first assure there is a valid session");
    }

    String piId = (String)request.getParameter("piId");
    String graphType = (String)request.getParameter("graphType");
    if(graphType == null)
       graphType = "Snapshot";

    if (piId == null) {
        throw new Exception("ProcessInstance.jsp requires the process instance id to be specified ina '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 = bps.getProcessInstance(piIdLong);
    Plan plan = pi.getPlan();

    String selectedPlanID = (String)request.getParameter("planId");
    String editMode = (String) request.getParameter("editMode");
    String referralURL = (String) request.getParameter("referralURL");
    if (referralURL==null) {
        throw new Exception("GraphViewMenu.jsp requires 'referralURL' parameter.  No such parameter was found on this invocation.");
    }

    boolean isEditMode = false;
    if(editMode!=null && editMode.equalsIgnoreCase("true")) isEditMode = true;

    String historyURL = "ShowHistory.jsp?id="+piIdLong;
    String processViewURL = "ProcessInstance.jsp?piId="+piIdLong;
    String editorURL = "ProcessEditor.jsp?AppletCommand=EditProcess&amp;ProcessID="+piIdLong+"&amp;referralURL="+URLEncoder.encode(referralURL, "UTF-8");
    String appletViewURL = "ProcessEditor.jsp?AppletCommand=DisplayProcess&amp;ProcessID="+piIdLong+"&amp;referralURL="+URLEncoder.encode(referralURL, "UTF-8");
%>

<table cellpadding=2 cellspacing=1 class="tableclass" align="center" width="100%">
  <tr>
    <td align="right">
      <div align="right">

<table border="0" cellpadding="0" cellspacing="3"><tr><td>

        <table border="0" cellspacing="0" cellpadding="0">
      <tr background="images/buttons/com_button_bg.gif">
        <td width="15"><img src="images/buttons/but_table_view.gif"></td>
        <td background="images/buttons/com_button_bg.gif" nowrap><a href="<%= processViewURL %>">
        <div align="center" class="buttonlink">Process Instance</div></a></td>
        <td width="9"><div align="right"><img src="images/buttons/com_button_right.gif" width="9" height="24"></div></td>
      </tr>
    </table>
    </td><td>
        <table border="0" cellspacing="0" cellpadding="0">
      <tr background="images/buttons/com_button_bg.gif">
        <td width="15"><img src="images/buttons/but_history.gif" border="0"></td>
        <td background="images/buttons/com_button_bg.gif" nowrap><a href="<%=historyURL%>"><div align="center" class="buttonlink"> History</div></a></td>
        <td width="9"><div align="right"><img src="images/buttons/com_button_right.gif" width="9" height="24"></div></td>
      </tr>
    </table>
    </td>
<%
    if(graphType.equals("Snapshot") == true)
    {
       String graphicalViewBPMNURL = "PIGraphicBPMN.jsp?piId="+piIdLong;
%>
       <td>
        <table border="0" cellspacing="0" cellpadding="0">
         <tr background="images/buttons/com_button_bg.gif">
          <td width="15"><img src="images/buttons/but_graphical_view.gif"></td>
          <td background="images/buttons/com_button_bg.gif" nowrap><a href="<%= graphicalViewBPMNURL %>"><div align="center"              class="buttonlink">BPMN</div></a></td>
          <td width="9"><div align="right"><img src="images/buttons/com_button_right.gif" width="9" height="24"></div></td>
         </tr>
        </table>
       </td>
<%
    }
    else
    {
       String graphicalViewURL = "PIGraphic.jsp?piId="+piIdLong;
%>
       <td>
        <table border="0" cellspacing="0" cellpadding="0">
          <tr background="images/buttons/com_button_bg.gif">
           <td width="15"><img src="images/buttons/but_graphical_view.gif"></td>
           <td background="images/buttons/com_button_bg.gif" nowrap><a href="<%= graphicalViewURL %>"><div align="center"                  class="buttonlink">Snapshot</div></a></td>
           <td width="9"><div align="right"><img src="images/buttons/com_button_right.gif" width="9" height="24"></div></td>
          </tr>
        </table>
       </td>
<%
    }
%>
    <td>
        <table border="0" cellspacing="0" cellpadding="0">
      <tr background="images/buttons/com_button_bg.gif">
        <td width="15"><img src="images/buttons/but_applet_edit.gif"></td>
        <td background="images/buttons/com_button_bg.gif" nowrap><a href="<%=editorURL%>"><div align="center" class="buttonlink">Graphical Edit</div></a></td>
        <td width="9"><div align="right"><img src="images/buttons/com_button_right.gif" width="9" height="24"></div></td>
      </tr>
    </table>
    </td>
    <td>
        <table border="0" cellspacing="0" cellpadding="0">
      <tr background="images/buttons/com_button_bg.gif">
        <td width="15"><img src="images/buttons/but_view.gif"></td>
        <td background="images/buttons/com_button_bg.gif" nowrap><a href="<%=appletViewURL%>"><div align="center" class="buttonlink">Graphical View</div></a></td>
        <td width="9"><div align="right"><img src="images/buttons/com_button_right.gif" width="9" height="24"></div></td>
      </tr>
    </table>
     </td></tr></table></div>
    </td>
  </tr>
</table>
