<%@ page contentType="text/html;charset=GBK" %>
<%@ 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.*" %>
<%@ include file="/sessionInfo.jsp"%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
</head>
<body onLoad="javascript:ReSize();">
<%

    LcFlowControl lcFlowControl = new LcFlowControl();
    //获取提交的参数
    //type就是流程ID
    //PKEY就是流程前一步骤ID
    //detail, add, update, transact
    String sOPERATOR = SzConvert.toZeroStr(request.getParameter("OPERATOR"));    
    String sType = SzConvert.toZeroStr(request.getParameter("type"));
    //System.out.println("operator==" + sOPERATOR);
    
    int iFormID = Integer.parseInt(SzConvert.toZeroStr(request.getParameter("FormID")));
    int iInfoID = Integer.parseInt(SzConvert.toZeroStr(request.getParameter("InfoID")));
    
    String sType2 = SzConvert.toZeroStr(request.getParameter("type2"));
    String sPKEY2 = SzConvert.toZeroStr(request.getParameter("PKEY2"));
    String sPFORM2 = SzConvert.toZeroStr(request.getParameter("PFORM2"));
    
    String sLCID = SzConvert.toZeroStr(request.getParameter("LCID"));
   
    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";
    }
    int sPKEY = 0;
    String sPage = SzConvert.toZeroStr(request.getParameter("page"));
    String sSearch = SzConvert.strWriteData(request.getParameter("txtSearch"));
    String sSearchName = SzConvert.strWriteData(request.getParameter("txtSearchName"));

    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;
    }
    if (!sLCID.equals("0")) {
    	sType = sLCID;
    }
    
    if (!sType.equals("0")) {
        sCond += " and BZLC=" + sType;
    } 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 hasSend = lcFlowPopedomInfo.isHasSend();
    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 = "同意";
    }

    //System.out.println("iFlowID==" + iFlowID);
    //System.out.println("sType=="   + sType);    
    //System.out.println("canModifyFlow=="   + canModifyFlow);     
    //System.out.println("==hasSend==" + hasSend);
    //System.out.println("==iCurrentStep==" + iCurrentStep);
 
    //System.out.println("iCurrentStep==" + iCurrentStep);
    //System.out.println("iCurrentOrder==" + iCurrentOrder);
    int iBZXH = 0;
    int iBZID = 0;

%>
<!-----上面的工具栏------>
<form name="formList" method="post">
<table width="100%">
  <tr>
    <td>
    	<%
    	if (sOPERATOR.equals("detailWin")) {
    		out.println( SzPageHelp.closeButton() );
    	}
      %>         
    </td>
  </tr>
</table>
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="page" value="<%=sPage%>">
  <input type="hidden" name="LCID" value="<%=sLCID%>">
<!-- 拟稿状态，不管添加还是修改都可以选择流程 -->  
<% if (isDraft) { %>  
<table width="100%">
  <tr>
    <td>
      <%//=SzPageHelp.idSelectTreeSubmit("SZLC_FL","FLID","FLMC","","LCFL",Integer.parseInt(LCFL), "txtClass1")%>      
      请选择流程：<input type="text" class="txtClass2" readonly name="LCMC" value="<%=sLCMC%>">
      <input type="button" name="btnSelect" class="btnClassShort" value="选择" OnClick="javascript:OpenFlowSingleWinSubmit('<%=iFormID %>', 'SZLC_LCMB', 'formList.LCID','formList.LCMC', 'formList');">                   
    </td>
  </tr>
</table>
<% } %>  
<% if (sOPERATOR.equals("transact")) { %>
<table width="98%">
  <tr>
    <td colspan="2">
请填写办理意见或
<%
  OfficeHelp officeHelp = new OfficeHelp();
  out.println(officeHelp.selectSignature(iDLID_SESSION));
  firstSign = officeHelp.getFirstSign();
%>
    </td>
  </tr>
  <tr>
    <td width="50%">
<textarea name="RYBLYJ" class="areaClass2" style="width:320"><%=strOpinion_temp%></textarea>
    </td>
    <td width="50%" align="left" valign="top">
<img id="imgSignature" style="display:none" height="100"> 
    </td>
  </tr>
</table>
<% } else { %>
<input type="hidden" name="RYBLYJ">
<input type="hidden" name="selectSignature">
<% } %>
<!-- 显示已经办理完成的人员姓名、办理时间、状态、办理意见 -->
<table id="tableFlow" align="center" width="650" border="0" cellpadding="0" cellspacing="0">
<!-- 只要选择了流程，就可以看到已办的或者待办的 -->
<%
    sPKEY = 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++; 
        if (i==1) {
%>
<tr id="trFlow">
<td>
  <table align="center" width="750" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <tr class="trClassTitle_c">
    <td align="center" width="30">序号</td>
    <td align="center" width="80">步骤/人员</td>    
    <td align="center" width="120">接收时间/办理时间</td>
    <td align="center" width="80">状态</td>
    <td align="center">办理意见</td>    
  </tr>
  </table>
</td>
</tr>
<%        	
        }
%>    
<tr id="trFlow">
<td>
  <table align="center" width="750" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <tr class="trClassTitle2" style="cursor:hand;">
    <a href="javascript:ModifyStepWin('detail','<%=sType%>','<%=lcStepInfo.getBZID()%>');">
    <td width="30"><%=lcStepInfo.getBZXH()%></td>
    <td width="80" title="办理名称"><b><%=lcStepInfo.getBZMC()%></b>&nbsp;</td>       
    <td width="120" title="接收时间"><%=lcStepInfo.getBZKSSJ()%>&nbsp;</td>
    <td width="80" title="步骤状态"><%=lcFlowControl.getStepStateName(lcStepInfo.getBZZT())%>&nbsp;</td>    
    <td title="办理说明"><%=lcStepInfo.getBZBLSM()%>&nbsp;</td> 
    </a> 
  </tr>
  <%=lcFlowControl.getTransactedPersonInfo(lcStepInfo.getBZID()) %>
  </table>
</td>
</tr>
<!--------------------------------------------------------------->
<%
        sPKEY = lcStepInfo.getBZXH(); //上一步骤的顺序

    }
%>

</table>

<!-------------- 显示已经办理完成的人员姓名、办理时间、状态、办理意见结束 ------------->
<!-----流程分类、流程列表的选择，以及显示流程的剩余办理步骤----->

<% if (!hasFinish) { %>

<table id="tableFlow" align="center" width="750" border="0" cellpadding="0" cellspacing="0">
<tr id="trFlow">
<td>
  <table align="center" width="750" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <%
	//未办理的
	//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 (coll.size() >0 || (canModifyFlow && !sOPERATOR.startsWith("detail"))) {
  %>
  <tr class="trClassTitle_c">
    <td align="center" width="30">序号</td>
    <td align="center" width="80">办理名称</td>
    <td align="center" width="120">办理期限/跳转时间</td>
    <td align="center" width="30" title="是否会签">会签</td>
    <td align="center" width="30" title="是否可以修改表单">表单</td>
    <td align="center" width="30" title="是否可以修改流程">流程</td>
    <td align="center" width="30" title="是否可以退回">退回</td>
    <td align="center" width="30" title="是否可以办结">办结</td>
    <td align="center" width="30" title="是否可以否决">否决</td>
    <td align="center" width="30" title="是否可以跳签">跳签</td>
    <td align="center">办理说明</td>    
  </tr>
  <% } %>
  <% if (1!=1) { %>
  <tr>
    <td width="30">0</td>
    <td width="80">拟稿</td>
    <td width="120">&nbsp;</td>
    <td align="center" width="30" title="是否会签">&nbsp;</td>
    <td align="center" width="30" title="是否可以修改表单">&nbsp;</td>
    <td align="center" width="30" title="是否可以修改流程">&nbsp;</td>
    <td align="center" width="30" title="是否可以退回">&nbsp;</td>
    <td align="center" width="30" title="是否可以办结">&nbsp;</td>
    <td align="center" width="30" title="是否可以否决">&nbsp;</td>
    <td align="center" width="30" title="是否可以跳签">&nbsp;</td>
    <td>&nbsp;</td>    
  </tr>
  <tr>
    <td valign="top">&nbsp;</td>
    <td colspan="20">
      <table border="0" width="100%">
        <!-- 拟稿人节点 -->
        <tr>
          <td width="25%"><input type="checkbox" checked disabled>起草人</td>
          <td width="25%">&nbsp;</td>
          <td width="25%">&nbsp;</td>
          <td width="25%">&nbsp;</td>
        </tr>
      </table>
    </td>
  </tr>
  <% } %>
  </table>
</td>
</tr>

<!---------------显示未办理的------------------------------------------------>
<%
    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++;  
      
%>
<tr id="trFlow">
<td>
  <table align="center" width="750" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <tr class="trClassTitle3">
    <td colspan="20" class="tdClassLine2" align="center">
  <a href="javascript:ModifyStepWin('detail','<%=sType%>','<%=lcStepInfo.getBZID()%>');">
  查看步骤
  </a>          
  <% if ( (hasSend && i == 1) || sOPERATOR.equals("detail") ) { %> 
  <% } else {%>    
      <% if (iCurrentOrder < lcStepInfo.getBZXH() && canModifyFlow && !sOPERATOR.equals("detailWin") ) { %>
      <a href="javascript:ModifyStepWin('add','<%=sType%>', '<%=sPKEY%>');">增加步骤</a>
      <a href="javascript:ModifyStepWin('update','<%=sType%>','<%=lcStepInfo.getBZID()%>');">修改步骤</a>
      <a href="javascript:ModifyStepWin('delete','<%=sType%>','<%=lcStepInfo.getBZID()%>');">删除步骤</a>
      <% } %>
  <% } %>&nbsp;  
    </td>
  </tr>

  <tr>
    <td width="30"><%=lcStepInfo.getBZXH()%></td>
    <td width="80" title="办理名称"><%=lcStepInfo.getBZMC()%>&nbsp;</td>
    <td width="120" title="期限/跳转时间">
      <%
      	if (lcStepInfo.getBZBLQX().equals("0") || lcStepInfo.getBZBLQX().equals("")) {
      		out.println("无 / ");
      	} else {
      		out.println(lcStepInfo.getBZBLQX() + "小时 / ");
      	}
      
      	if (lcStepInfo.getBZTXRY().equals("0") || lcStepInfo.getBZTXRY().equals("")) {
      		out.println("无");
      	} else {
      		out.println(lcStepInfo.getBZTXRY() + "小时");
      	}      
      %>&nbsp;    
    </td>
    <td align="center" width="30" title="是否会签"><%=SzPageHelp.checkboxDisabled(lcStepInfo.getBZSX())%></td>
    <td align="center" width="30" title="是否可以修改表单"><%=SzPageHelp.checkboxDisabled(lcStepInfo.getBZQXBD())%></td>
    <td align="center" width="30" title="是否可以修改流程"><%=SzPageHelp.checkboxDisabled(lcStepInfo.getBZQXLC())%></td>
    <td align="center" width="30" title="是否可以退回"><%=SzPageHelp.checkboxDisabled(lcStepInfo.getBZQXTH())%></td>
    <td align="center" width="30" title="是否可以办结"><%=SzPageHelp.checkboxDisabled(lcStepInfo.getBZQXBJ())%></td>
    <td align="center" width="30" title="是否可以否决"><%=SzPageHelp.checkboxDisabled(lcStepInfo.getBZQXFJ())%></td>
    <td align="center" width="30" title="是否可以跳签"><%=SzPageHelp.checkboxDisabled(lcStepInfo.getBZQXTQ())%></td>
    <td title="办理说明"><%=lcStepInfo.getBZBLSM()%>&nbsp;</td>  
  </tr>
  <tr>
    <td valign="top">&nbsp;</td>
    <td colspan="20">
      <!-----显示人员设置的人员，包括部门、职务等其他-------->
      <%=lcFlowControl.getPersonInfo(lcStepInfo.getBZID()) %>&nbsp;
    </td>
  </tr>
  <% if (!sOPERATOR.startsWith("detail") && iNextStep == lcStepInfo.getBZID()) { 
			iBZXH = lcStepInfo.getBZXH();
			iBZID = lcStepInfo.getBZID();
  %>  
  <tr>
    <td valign="top" align="center" width="30">
    <!-- 增加全选功能 2011-09-16  --><input type="checkbox" name="ChkBZRYID" title="全选或全部反选" OnClick="javascript:CheckAll(formList, ChkBZRYID, 'BZRYID');">
    </td>
    <td colspan="20">
      <!-----显示人员，将部门等其他转换成姓名-------->
      <%=lcFlowControl.printTransactPersonInfo(lcStepInfo.getBZID(), iDLID_SESSION, isDraft, lcStepInfo.getBZYSTJ(), lcStepInfo.getBZYSBM()) %>&nbsp;
      &nbsp;
    </td>
  </tr>  
  <% } %>
  </table>
</td>
</tr>

<!--------------------------------------------------------------->
<%
        sPKEY = lcStepInfo.getBZXH(); //上一步骤的顺序
    }
%>

<tr id="trFlow">
<td>
  <table align="center" width="750" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <tr class="trClassTitle3">
    <td colspan="20" class="tdClassLine2" align="center">
    <% if ( (hasSend && i == 1) || sOPERATOR.startsWith("detail")) { %>
      &nbsp;
    <% } else if (canModifyFlow) { %> 
      <a href="javascript:ModifyStepWin('add','<%=sType%>', '<%=sPKEY%>');">增加步骤</a>
    <% } %>      
    </td>
  </tr>
  </table>
</td>
</tr>

</table>
<% } %>
<table id="tableFlow" align="center" width="750" border="0" cellpadding="0" cellspacing="0">
<tr id="trFlow">
<td>
  <table align="center" width="750" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <tr class="trClassTitle3">
    <td colspan="20" class="tdClassLine2" align="left">
		&nbsp;<b>流程总状态: </b> <%=lcFlowControl.getFlowStateName(iFormID, iInfoID) %>
    </td>
  </tr>
  </table>
</td>
</tr>
</table>
      <input type="hidden" name="BZXH" value="<%=iBZXH%>">
      <input type="hidden" name="BZID" value="<%=iBZID%>">      
</form>
<!-----下面的工具栏------>
<table width="100%">
  <form name="formPage" method="post">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="PKEY" value="<%=sPKEY%>">
  </form>
</table>

<!-----这里包含要提交的内容--->
<form name="formHidden" method="post">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="firstSign" value="<%=firstSign%>">
</form>
</body>
</html>
<script language="javascript" src="../../share/js/commonTool.js"></script>
<script language="javascript">
  function ModifyStepWin(vOPERATOR, vType, vKey) {
    var vUrl = "../../flow/step/update.jsp";
    var vPKEY = "0";
    if (vOPERATOR == "delete") {     
      vUrl = "../../flow/step/control.jsp";
    } else if (vOPERATOR == "add") {
      vPKEY = vKey;
      vKey = "0";     
      vUrl = "../../flow/step/update.jsp";
    } else if (vOPERATOR == "update") {    
      vUrl = "../../flow/step/update.jsp";    
    }
    var vUrl = vUrl
            + "?OPERATOR=" + vOPERATOR + "&type=" + vType 
            + "&KEY=" + vKey + "&PKEY=" + vPKEY + "&win=win" + "&type2=<%=sType2%>&PKEY2=<%=sPKEY2%>&PFORM2=<%=sPFORM2%>"
    window.showModalDialog(vUrl,window,"status=no;dialogWidth=680px;dialogHeight=780px");
    //window.open(vUrl,"","");
  }
  
  function OpenFlowSingleWinSubmit(vFormID, vTableName, objId, objName, vFormName) {
    var type= "";
    var url = "../../flow/flow/id_single_win.jsp";
    url = url + "?objId=" + objId + "&objName=" + objName 
        + "&tableName=" + vTableName + "&formName=" + vFormName
        + "&FormID=" + vFormID;
    window.showModalDialog(url,window,"status=no;dialogWidth=580px;dialogHeight=350px");
  }  
  
  function ReSize() {
    //自动调节窗口的大小
  	var vHeight = document.body.scrollHeight + 30;
  	window.resizeTo(750, vHeight);
  }
  	//var vHeight = document.body.scrollHeight + 30;
  	//window.resizeTo(650, vHeight);
  	
  function LoadSignature() {
	//选择印章
	var vId = formList.selectSignature.value;
	displaySignature(vId);
  }

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

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

</script>

