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

    String graphicalViewURL = "PIGraphic.jsp?piId="+piIdLong;
    String graphicalViewBPMNURL = "PIGraphicBPMN.jsp?piId="+piIdLong;

    String locationButtonGraphEdit = "";
    String locationBackgroundButton = "";
    String locationRightButton = "";
    String locationButtonGraphView = "";

    if (isArchived != null && isArchived.equals("true")) {
        bpas = bps.getAdmin();
        pi = bpas.getArchivedProcess(piIdLong);
        graphicalViewURL += "&isArchived="+isArchived;
        graphicalViewBPMNURL += "&isArchived="+isArchived;
        locationButtonGraphEdit = "images/buttons/but_applet_edit_disabled.gif";
        locationBackgroundButton = "images/buttons/com_button_bg_disabled.gif";
        locationRightButton = "images/buttons/com_button_right_disabled.gif";
        locationButtonGraphView = "images/buttons/but_view_disabled.gif";
    }
    else {
        pi = bps.getProcessInstance(piIdLong);
        locationButtonGraphEdit = "images/buttons/but_applet_edit.gif";
        locationBackgroundButton = "images/buttons/com_button_bg.gif";
        locationRightButton = "images/buttons/com_button_right.gif";
        locationButtonGraphView = "images/buttons/but_view.gif";
    }
    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("ProcessMenu REQUIRES a referral URL request parameter");
    }

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

    String b1URL = "ShowHistory.jsp?id="+piIdLong;
    String b1GIF = "but_history.gif";
    String b1Name = " History";
    if (referralURL.startsWith("ShowHistory")) {
        b1URL = "ProcessInstance.jsp?piId="+piIdLong;
        b1GIF = "but_table_view.gif";
        b1Name = "Process Instance";
    }
    if (isArchived != null && isArchived.equals("true")) {
        b1URL += "&isArchived="+isArchived;
    }

    String editorURL = "ProcessEditor.jsp?AppletCommand=EditProcess&ProcessID="+piIdLong+"&referralURL="+URLEncoder.encode(referralURL,"UTF-8");
    String appletViewURL = "ProcessEditor.jsp?AppletCommand=DisplayProcess&ProcessID="+piIdLong+"&referralURL="+URLEncoder.encode(referralURL,"UTF-8");

    // in case we want to support viewing of an archived process instance we
    // have to add "isArchived=true" to the appletViewURL string. In any case this
    // token has to be placed before the encoder-url information.

    String reference = "<a href=\"" + editorURL +"\">";
    String viewReference = "<a href=\"" + appletViewURL +"\">";
    if (isArchived != null && isArchived.equals("true")) {
        reference = "";
        viewReference = "";
    }

%>

<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"><a href="<%=b1URL%>"><img src="images/buttons/<%=b1GIF%>" border="0"></a></td>
        <td background="images/buttons/com_button_bg.gif" nowrap><a href="<%=b1URL%>">
        <div align="center" class="buttonlink"><%=b1Name%></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"><a href="<%= graphicalViewURL %>"><img src="images/buttons/but_graphical_view.gif" border="0"></a></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"><a href="<%= graphicalViewBPMNURL %>"><img src="images/buttons/but_graphical_view.gif" border="0"></a></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>
    <td>
        <table border="0" cellspacing="0" cellpadding="0">
      <tr background="images/buttons/com_button_bg.gif">
        <td width="15"><%=reference%><img src="<%=locationButtonGraphEdit%>" border="0"></a></td>
        <td background="<%=locationBackgroundButton%>" nowrap>
             <%=reference%><div align="center" class="buttonlink">Graphical Edit</div></a></td>
        <td width="9"><div align="right"><img src="<%=locationRightButton%>" 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"><%=viewReference%><img src="<%=locationButtonGraphView%>" border="0"></a></td>
        <td background="<%=locationBackgroundButton%>" nowrap><%=viewReference%><div align="center" class="buttonlink">Graphical View</div></a></td>
        <td width="9"><div align="right"><img src="<%=locationRightButton%>" width="9" height="24"></div></td>
      </tr>
    </table>
        </td></tr></table></div>
    </td>
  </tr>
</table>
