<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Collection" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.database.SzPageInfo" %>
<%@ page import="net.sz600.system.SzProperties" %>
<%@ page import="net.sz600.system.SzLevelNumber" %>
<%@ page import="net.sz600.system.SzPageHelp" %>
<%@ page import="net.sz600.weboffice.*" %>
<%@ page import="net.sz600.flow.*" %>
<%

    String sLCID = "0";
    String sLCMC = SzConvert.strWriteData(request.getParameter("LCMC"));

    if (sOPERATOR.equals("add") && sLCID.equals("0")) {
    	//取出默认流程。根据表单取出当前表单的默认流程
    	LcFlowInfo lcFlowInfo = lcFlowControl.getDefaultFlow(iFormID, iDLID_SESSION, iBMID_SESSION);
    	if (lcFlowInfo != null) {
    		sLCID = Integer.toString(lcFlowInfo.getLCID());
    		sLCMC = lcFlowInfo.getLCMC();
    	}
    }      
    if (sLCID.equals("-1")) {
    	sLCID = "0";
    }

    String sTable_type = "";
    //读取数据
    LcStep lcStep = new LcStep();
    LcStepInfo lcStepInfo = null;
    String sCond = "1=1";
    boolean canAdd_SESSION = false;
    boolean canPrint_SESSION = false;
    boolean canDelete_SESSION = false;
    boolean canUpdate_SESSION = false;
    //管理资料，只有管理员和有权限的人才能添加。有权限的人员可以查看、修改、删除
    if (isBarManager_SESSION) {
        canAdd_SESSION = true;
        canPrint_SESSION = true;
        canDelete_SESSION = true;
        canUpdate_SESSION = true;
    }
    String sFlowID_draft = "" + iFlowID;
    if (!sLCID.equals("0")) {
    	sFlowID_draft = sLCID;
    } else {
        //列出流程名称
        LcFlow lcFlow = new LcFlow();
	sLCMC = lcFlow.getMainByKey(iFlowID);
    }

    
    if (!sFlowID_draft.equals("0")) {
        sCond += " and BZLC=" + sFlowID_draft;
    } else {
    	sCond += " and 1<>1";
    }
    //sCond += " order by BZXH ASC";
    String strCond = "";
    Iterator iter = null;
    
    iter = lcStep.getArrayList(sCond).iterator();
	
    int i = 0;
    SzData szData = null;
    
    //////流程相关
    //根据流程获取当前办理节点

    //取得流程权限信息
    //LcFlowPopedomInfo lcFlowPopedomInfo = lcFlowControl.getFlowPopedomInfo(iFormID, iInfoID);    
    
    //int iFlowID = lcFlowPopedomInfo.getFlowID();
    int iCurrentStep = lcFlowPopedomInfo.getStepID();
    int iCurrentOrder = lcFlowControl.getCurrentOrder(iCurrentStep);
    boolean hasFinish = lcFlowPopedomInfo.isHasFinish();
    boolean isDraft = true;    

    if (!sOPERATOR.equals("add") && !sOPERATOR.equals("update")) {
    	isDraft = false;
    }  
    int iNextStep = 0;
    //未保存流程或者重新选择流程的时候不能修改

    boolean canModifyFlow = lcFlowPopedomInfo.isCanModifyFlow(iFlowID, Integer.parseInt(sType));
    String firstSign = "";
    String strOpinion_temp = lcFlowControl.getOpinion(iFormID, iCurrentStep, iDLID_SESSION);
    if (strOpinion_temp.equals("")) {
	strOpinion_temp = "同意";
    }

    int iBZXH = 0;
    int iBZID = 0;
    int iBZXH_Parent = 0;

%>

<!-- 拟稿状态，不管添加还是修改都可以选择流程 -->  



<% if (sOPERATOR.equals("transact")) { %>
  <tr class="trClassTitle_c">
    <td>
请填写办理意见
<%
  OfficeHelp officeHelp = new OfficeHelp();
  out.println(officeHelp.selectSignature(iDLID_SESSION, 150, "RYBLTP_FLOW"));
  firstSign = officeHelp.getFirstSign();
%>
    </td>
  </tr>
  <tr>
    <td>
	<textarea name="RYBLYJ_FLOW" class="areaClass" style="width:280px;" ><%=strOpinion_temp%></textarea>
    </td>
  </tr>

  <tr>
    <td>
	<img id="imgSignature" style="display:none" height="100"> 
    </td>
  </tr>
<% } else { %>
<input type="hidden" name="RYBLYJ_FLOW">
<input type="hidden" name="RYBLTP_FLOW">
<% } %>

  <tr class="trClassTitle_c">
    <td>
      流程名称：<%=sLCMC%>
    </td>
  </tr>
<!-------------- 选择下一步骤办理人员------------->
<% 
  if (!hasFinish) { 
    //未办理的
    //2011-09-16增加判断,减少表头的影响
    strCond = sCond + " AND BZZT IN (0) order by BZXH ASC"; 
    Collection coll = lcStep.getArrayList(strCond);
    iter = null;
    if (coll != null) {
	  iter = coll.iterator();
    }
    iNextStep = 0;  

    //if (iter != null && iter.hasNext()) {
    while (iter != null && iter.hasNext()) {
        lcStepInfo = (LcStepInfo)iter.next();

        if (iNextStep == 0) {
        	iNextStep = lcStepInfo.getBZID();
        }
        //判断是否有下一步骤
	if (!sOPERATOR.startsWith("detail") && !lcFlowControl.stepCanTransact(iNextStep, iDLID_SESSION, isDraft)) {
            iNextStep = 0;
	    continue;
	} else if (!sOPERATOR.startsWith("detail") && iNextStep == lcStepInfo.getBZID()) { 
	  iBZXH = lcStepInfo.getBZXH();
	  iBZID = lcStepInfo.getBZID();
	  //下一个办理步骤
	  out.println("<tr class='trClassTitleYellow'><td>");
	  out.println("下一步骤:");
	  out.println(lcStepInfo.getBZXH());
	  out.println(lcStepInfo.getBZMC());
	  out.println(lcStepInfo.getBZBLSM());
	  out.println(lcFlowControl.getPersonInfo(lcStepInfo.getBZID()));
	
	  out.println("&nbsp;</td></tr>");

	  out.println("<tr class='trClassTitleYellow'><td>");
	  out.println(lcFlowControl.printTransactPersonInfo(lcStepInfo.getBZID(), iDLID_SESSION, isDraft, lcStepInfo.getBZYSTJ(), lcStepInfo.getBZYSBM(), true));

   	  out.println("&nbsp;</td></tr>");
	} 

       iBZXH_Parent = lcStepInfo.getBZXH(); //上一步骤的顺序
       break;

    } //if (iter != null && iter.hasNext()) {
  } //if (!hasFinish) {      
%>

<!-- 拟稿状态，不管添加还是修改都可以选择流程 -->  
<% if (iNextStep > 0) { %>
  <tr class="trClassTitle_c">
    <td>
      流程详细步骤：
    </td>
  </tr>
<% } %>
<!-- 显示已经办理完成的人员姓名、办理时间、状态、办理意见 -->
<!-- 只要选择了流程，就可以看到已办的或者待办的 -->
<%
    iBZXH_Parent = 0;
    i = 0;
    strCond = sCond + " AND ( BZXH=1 OR BZZT IN (1,2,5,4) ) order by BZXH ASC";
    iter = lcStep.getArrayList(strCond).iterator();
    while (iter != null && iter.hasNext()) {
        lcStepInfo = (LcStepInfo)iter.next();
        i++; 
%>    
  <tr id="trFlow">
  <td>
  <%=lcStepInfo.getBZXH()%>
  <b><%=lcStepInfo.getBZMC()%></b>
  <%=lcStepInfo.getBZKSSJ()%>&nbsp;
  <%=lcFlowControl.getStepStateName(lcStepInfo.getBZZT())%>&nbsp;
  <%=lcStepInfo.getBZBLSM()%>&nbsp;
  </td>
  </tr>

  <%=lcFlowControl.getTransactedPersonInfo2(lcStepInfo.getBZID()) %>

  <tr>
    <td height="8" align="left" background="../images/line.gif"></td>
  </tr> 
<!--------------------------------------------------------------->
<%
        iBZXH_Parent = lcStepInfo.getBZXH(); //上一步骤的顺序

    }
%>





<!-------------- 显示已经办理完成的人员姓名、办理时间、状态、办理意见结束 ------------->
<% 
  if (!hasFinish) { 
    //未办理的
    //2011-09-16增加判断,减少表头的影响
    strCond = sCond + " AND BZZT IN (0) order by BZXH ASC"; 
    Collection coll = lcStep.getArrayList(strCond);
    iter = null;
    if (coll != null) {
	  iter = coll.iterator();
    }
    iNextStep = 0;  

    while (iter != null && iter.hasNext()) {
        lcStepInfo = (LcStepInfo)iter.next();

        if (iNextStep == 0) {
        	iNextStep = lcStepInfo.getBZID();
        }
        //判断是否有下一步骤
	if (!sOPERATOR.startsWith("detail") && !lcFlowControl.stepCanTransact(iNextStep, iDLID_SESSION, isDraft)) {
            iNextStep = 0;
	    continue;
	}
        i++;  

 	if (!sOPERATOR.startsWith("detail") && iNextStep == lcStepInfo.getBZID()) { 
			iBZXH = lcStepInfo.getBZXH();
			iBZID = lcStepInfo.getBZID();
	  //下一个办理步骤
	  out.println("<tr><td>");
	  out.println(lcStepInfo.getBZXH());
	  out.println(lcStepInfo.getBZMC());
	  out.println(lcStepInfo.getBZBLSM());
	  out.println(lcFlowControl.getPersonInfo(lcStepInfo.getBZID()));
	  //out.println("(下一步骤)");	
	  out.println("&nbsp;</td></tr>");

	  //out.println("<tr class='trClassTitleYellow'><td>");
	  //out.println(lcFlowControl.printTransactPersonInfo(lcStepInfo.getBZID(), iDLID_SESSION, isDraft, lcStepInfo.getBZYSTJ(), lcStepInfo.getBZYSBM()));
   	  //out.println("&nbsp;</td></tr>");
	} else {
	  //未开始的步骤
	  out.println("<tr><td>");
	  out.println(lcStepInfo.getBZXH());
	  out.println(lcStepInfo.getBZMC());
	  out.println(lcStepInfo.getBZBLSM());
	  out.println(lcFlowControl.getPersonInfo(lcStepInfo.getBZID()));
	  out.println("&nbsp;</td></tr>");
	}


       iBZXH_Parent = lcStepInfo.getBZXH(); //上一步骤的顺序
%>
    <tr>
      <td height="8" align="left" background="../images/line.gif"></td>
    </tr> 
<%

    } //while (iter != null && iter.hasNext()) {
  } //if (!hasFinish) {      
%>  
  <tr id="trFlow" class="trClassTitle_c">
    <td>
      <b>流程总状态: </b> <%=lcFlowControl.getFlowStateName(iFormID, iInfoID) %>
    </td>
  </tr>
  <input type="hidden" name="BZXH_FLOW" value="<%=iBZXH%>">
  <input type="hidden" name="BZID_FLOW" value="<%=iBZID%>">
  <input type="hidden" name="LCID_FLOW" value="<%=sLCID%>">
  <input type="hidden" name="BZRYID_FLOW" value="0">  
  <input type="hidden" name="firstSign" value="<%=firstSign%>">
<script language="javascript">
  	
  function LoadSignature() {
	//选择印章
	var vId = formUpdate.RYBLTP_FLOW.value;
	displaySignature(vId);
  }

  function displaySignature(vId) {
	if (formUpdate.imgSignature == null) {
		return false;
	}
	if (vId == "" || vId == "0") {
		formUpdate.imgSignature.style.display="none";
	} else {
	    	formUpdate.imgSignature.src= "../../share/weboffice/signature/selectSignature.jsp?id=" + vId;
		formUpdate.imgSignature.style.display="";
		formUpdate.RYBLTP_FLOW.value = vId;
	}
  }
  

  var firstSign = formUpdate.firstSign.value;
  displaySignature(firstSign);

</script>

