<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Collection" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.database.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.tool.SzDateHelp" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.flow.*" %>
<%@ page import="net.sz600.online.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ page import="net.sz600.formEngine.*" %>
<%@ page import="net.sz600.weboffice.*" %>
<%@ include file="/sessionInfoWeixin.jsp"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="format-detection" content="telephone=no" />
<%@ include file="/share/oa_app_title.jsp"%>
 <link href="<%=strLevel_SESSION%>app/images/soarwell_css.css" rel="stylesheet" type="text/css" />
 <script type="text/javascript" src="<%=strLevel_SESSION%>share/js/commonTool.js"></script>
<script language="javascript"> 
  function OpenPressWin(vFormID, vInfoID, vType) {
    var type = "all";
    var url = "../../flow/press/win_app.jsp?FormID=" + vFormID + "&InfoID=" + vInfoID + "&type=" + vType;
    //window.showModalDialog(url,window,"status=no;dialogWidth=650px;dialogHeight=300px");
    window.open(url,"","left=100,top=100,scrollbars=yes,resizable=yes,status=yes,width=400px,height=350px");
  }   
</script>  
</head>
<%
    int iFormID = SzConvert.toInt(request.getParameter("FormID"));
    //取得表单的信息
    String moduleName = "";
    String formName = "";
		//根据表单取得moduleName, formName
		LcForm lcForm = new LcForm();
		LcFormInfo lcFormInfo = null;    
    if (iFormID == 0) {
    	moduleName = SzConvert.toSpaceStr(request.getParameter("moduleName"));
    	formName = SzConvert.toSpaceStr(request.getParameter("formName")); 
    	//
    	iFormID = lcForm.getKeyByCond(moduleName, formName); 
    } else {
    	lcFormInfo = (LcFormInfo)lcForm.getInfoByKey(iFormID);    
    	if (lcFormInfo != null) {
    		moduleName = lcFormInfo.getBDLJ();
    		formName = lcFormInfo.getBDBY1();  
    	}
    }
    //System.out.println("moduleName=" + moduleName);
    //System.out.println("formName=" + formName);
    if (moduleName.equals("") || formName.equals("")) {
    	out.println("还没有设置相关表单信息！");
    	return;
    }

    //找出关联的信息
    BdRelateForm bdRelateForm = new BdRelateForm();
    ArrayList listRelate = bdRelateForm.getRelateList(moduleName, formName);
    Iterator iterRelate = null;
    BdRelateFormInfo bdRelateFormInfo = null;

	BdValueControl bdValueControl = new BdValueControl(moduleName, formName);
    //int iIndexLogin = bdValueControl.getIndexLogin();
    //System.out.println(iIndexLogin);
  	String assistant = bdValueControl.getAssistant();  

  	String sTableAnnex = bdValueControl.getTableAnnex();
  	String sKeyField = bdValueControl.getKeyField();
	boolean hasFlow = bdValueControl.getHasFlow();
	String allograph = bdValueControl.getAllograph(); //是否有代录人
	String printTemp = bdValueControl.getPrintTemp();
	String sWeboffice = bdValueControl.getWebOffice();
	int iFlowID = 0;

	String strSelectName = bdValueControl.getSelectName(); //是否有关联选择
	//是否有关联选择:支持逗号或分号
	BdListSelect bdListSelect = new BdListSelect();
	String strSelectCond = bdListSelect.genSelectCond(strSelectName, request, "selectName");

    /////////////////////////////////////////流程相关
    LcFlowControl lcFlowControl = new LcFlowControl();
    //根据信息ID，获取流程总体办理状态FlowState
    String sState = "";
    //sState = lcFlowControl.getFlowStateName(iFormID, iInfoID); 
    //判断是否能删除、修改
    boolean hasSend = false; //是否已经发送出去
    //hasSend = lcFlowControl.hasSend(iFormID, iInfoID);
    //获取提交的参数
    String flowType = SzConvert.toSpaceStr(request.getParameter("flowType"));
		if (flowType.equals("")) {
			flowType = "-2";
		}	    
    //获取提交的参数
    String sType = SzConvert.toZeroStr(request.getParameter("type"));
    String sPKEY = SzConvert.toZeroStr(request.getParameter("PKEY"));
    String sPage = SzConvert.toZeroStr(request.getParameter("page"));
    String sSearch = SzConvert.toHTMLString(SzConvert.strWriteDataHTML(request.getParameter("txtSearch"))) ;
    String sSearch2 = SzConvert.strWriteData(request.getParameter("txtSearch"));    
    String sSearchName = SzConvert.strWriteData(request.getParameter("txtSearchName"));
		//2015-01
		String sModulePopedom = bdValueControl.getModulePopedom();
    

    String sTable_type = "";
    //读取数据
    String sSearchCond = SzConvert.strWriteDataHTML(request.getParameter("searchCond"));


    String sCond = bdValueControl.getCond(iFormID, iDLID_SESSION, iBMID_SESSION
    		, isBarManager_SESSION, sSearchCond, isDataCanSee_SESSION
    		, szCOMPANY_SESSION, "", "", flowType, strSelectCond);
    

    String sSortField = SzConvert.toSpaceStr(request.getParameter("txtSortField")); 
    int iSortOrder    = Integer.parseInt(SzConvert.toZeroStr(request.getParameter("txtSortOrder"))); 
    if (sSortField.equals("")) { 
      sSortField = bdValueControl.getKeyField();
      iSortOrder = SzProperties.I_SortOrder_DESC;
    } 

    int iCurrentPage = 1;
    
    try {
        iCurrentPage =  Integer.parseInt(sPage);
    }catch(Exception e) {
    }

    int iPageSize = SzProperties.I_PageSize_APP;  	
    Collection coll = bdValueControl.getArrayList(sCond, sSortField, iSortOrder, iCurrentPage, iPageSize,sSearch2); 
    BdFormControl bdFormControl = new BdFormControl(); 
    Iterator iter = null;
    if (coll != null) {
    	iter = coll.iterator();
    } else {
    	out.println(bdFormControl.getFormCheckInfo(iFormID));
    	return;
    }
    SzPageInfo pageInfo = bdValueControl.getPageInfo();
    int iPageCount = pageInfo.getPageCount();
    int iRecordCount = pageInfo.getRecordCount();
    iCurrentPage = pageInfo.getCurrentPage();
    int i = 0;
    SzData szData = null;     
    

    
    //2010-2-21
    BdPopedom bdPopedom = new BdPopedom();        
    String strDenyField = bdPopedom.getDenyField(iFormID, 0, iDLID_SESSION);
    
    boolean bPress = false;
	if ((";" + assistant + ";").indexOf(";6;") >=0) {
		bPress = true;
	}    
  	boolean bSkip = false;
	if ((";" + assistant + ";").indexOf(";7;") >=0) {
		bSkip = true;
	}
	boolean bRead = false;
	if ((";" + assistant + ";").indexOf(";13;") >=0 && !hasFlow) {
		bRead = true;
	}	
		
    SzAnnex szAnnex = new SzAnnex(sTableAnnex);
    SzReadForm szReadForm = new SzReadForm(iFormID); 

    String sSelectButton = bdListSelect.selectButton(strSelectName,request, "selectName", "txtClass1", true);    
%>
<%@ include file="title.jsp"%>
<table width="100%">
  <form name="formBar" method="post">
  <input type="hidden" name="page" value="<%=sPage%>">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>"> 
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>"> 
  <input type="hidden" name="searchCond" value="<%=sSearchCond%>">
  <input type="hidden" name="sCond" value="<%=sCond%>">
  <input type="hidden" name="FormID" value="<%=iFormID%>"> 

  <tr>
    <td>
      <%=bdFormControl.addButton(moduleName, formName, isBarManager_SESSION)%>
      <%=bdFormControl.deleteButton(moduleName, formName, isBarManager_SESSION)%>
      <%=bdListSelect.selectButton(strSelectName,request, "selectName", "txtClass1") %>   
      <%
      if (hasFlow) {
      	String s_id[] = {"-2","-1","0","1","2"};
      	String s_name[] = {"全部","草稿","办理中","否决","办结"};
      	out.println(SzPageHelp.radioSubmit("flowType", s_id, s_name, flowType));
      }
      %>     	                
    </td>
  </tr>
  </form>
</table>
<table width="100%" border="0" cellspacing="3" cellpadding="3" style="border:#D7D7D9 1px solid;">
  <form name="formList" method="post">
  <input type="hidden" name="page" value="<%=iCurrentPage%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="FormID" value="<%=iFormID%>">
  <%=sSelectButton%>
<%
    String value_str[] = null;
    int iKeyValue = 0;
    int iIndexKey = bdValueControl.getIndexKey();

    if (iIndexKey == -1) {
    	iIndexKey = 0;
    }
    int iListFieldLen = 0;
	
		if (hasFlow) {
    	iListFieldLen = 3 + bdValueControl.getListFieldLen() ;
    	if (flowType.equals("0")) {
    		iListFieldLen = iListFieldLen + 2;
				if (bPress) {
					iListFieldLen ++;
				}				
    	} else if (flowType.equals("2")) {
    		iListFieldLen += 2;
    	}
    } else {
    	iListFieldLen = 2 + bdValueControl.getListFieldLen() ;
    }
    if (allograph.equals("1")) {
    	iListFieldLen ++;
    }
    boolean sameLogin = false;
    boolean sameDepart = false;
    //2011-06-08 部门负责人可修改部门内人员的数据
    boolean departManager = false;	//判断本人是否该数据的部门负责人。

    //2015-01细化
    String managerDepartID = "0";
    if (sModulePopedom.equals("6") || sModulePopedom.equals("7")) {
    	managerDepartID = SzUserHelp.getInstance().getManageDepartID(iDLID_SESSION);
    } else if (sModulePopedom.equals("8") || sModulePopedom.equals("9")) {
    	managerDepartID = SzUserHelp.getInstance().getManagerDepartIDTree(iDLID_SESSION);
    }   
		//=======================================
    
    //归档状态
    LcPigonhole pigonhole = new LcPigonhole();
    boolean hasPigonhole = false;
    int iState = 0;   
    
    String sRelateInfo = "";
    String loginName2 = "";
    
    boolean canUpdate = false;
    
    String strDenyField2 = "";
    boolean readonly = false;
    String s_transact[] = null;
    String sPressCount = "";
 	int iNextStepID = 0; //判断是否最后一个
    LcAssistant lcAssistant = new LcAssistant();
    LcStep lcStep = new LcStep();
    
    bdValueControl.getTableTitleApp();
  
    while (iter != null && iter.hasNext()) {
    	value_str = (String[])iter.next();
    	iKeyValue = SzConvert.toInt(value_str[iIndexKey]);
    	if (value_str == null) {
    		continue;
    	}
    	strDenyField2 = bdPopedom.getDenyField(iFormID, iKeyValue, iDLID_SESSION);
        hasSend = lcFlowControl.hasSend(iFormID, iKeyValue); 
        iState = lcFlowControl.getFlowState(iFormID, iKeyValue);        
        iFlowID = lcFlowControl.getFlowID(iFormID, iKeyValue);
        i++;
        
        sameLogin = bdValueControl.sameLogin(iDLID_SESSION, value_str);        
        sameDepart = bdValueControl.sameDepart(iBMID_SESSION, value_str); 
  	
        loginName2 = bdValueControl.getLoginName2(value_str);
        //2011-06-08 部门负责人可修改部门内人员的数据
        //canUpdate = bdFormControl.canUpdate(moduleName, formName, isBarManager_SESSION, hasSend, sType, iKeyValue, sameLogin, sameDepart);
        departManager = bdValueControl.departManager(managerDepartID, value_str);
        canUpdate = bdFormControl.canUpdate(moduleName, formName, isBarManager_SESSION, hasSend, sType, iKeyValue, sameLogin, sameDepart, departManager);
        //=================================================	
        if ( !sRelateInfo.equals("") && canUpdate) {
        	canUpdate = bdRelateForm.canUpdate(iFormID, iKeyValue); 
        }
        
        if ((hasFlow && hasSend) || !canUpdate) {        
        	readonly = true;
        } else {
        	readonly = false;
        }
        sRelateInfo = bdRelateForm.relateButton(iFormID, listRelate, iKeyValue, readonly, true);
        
        if (i>1) {
  		  out.println("	<tr>");
  		  out.println("	<td height=\"5\" align=\"left\" background=\"../images/line.gif\"></td>");
  		  out.println("	</tr>\n"); 
        }
   	    if (hasFlow && iFlowID >0) { 
   	   		s_transact = lcFlowControl.getCurrentTransactingInfo(iFormID, iKeyValue, "<br>", true);		
   	   		iNextStepID = lcFlowControl.getSkipStepID(SzConvert.toInt(s_transact[3]),s_transact[2]);
   	   	}          
%> 
  <tr>
    <td><span class="product_name"><%=i%>
      <% if (!readonly) {%> 
      <input type="checkbox" name="chkId" id="chkId" value="<%=iKeyValue%>">	  
      <% } %>  
      </span>
      <%
      if (!sTableAnnex.equals("")) {
      	out.println(SzPageHelp.annexImage(strSkin_SESSION, szAnnex.hasAnnex(iKeyValue)));
      }
      if (bRead) {
      	out.println(SzPageHelp.newImage(strSkin_SESSION, szReadForm.hasReaded(iKeyValue, iDLID_SESSION)));
      }
      %>
      <a href="javascript:FormSubmit(formPage,'detail.jsp?OPERATOR=detail&type=<%=sType%>&KEY=<%=iKeyValue%>');">详情</a>
      <% 
      if (canUpdate) {
      	out.println(bdFormControl.updateButton(canUpdate, sType, iKeyValue));
      	//out.println("<br>");
      }
      /*
      BdModifyButton bdModifyButton = new BdModifyButton();
      boolean flagModifyButton = canUpdate;
      if (hasFlow && sameLogin) {
        flagModifyButton = true;
      }
      out.println(bdModifyButton.modifyButton(moduleName, formName, iKeyValue, flagModifyButton ));
      */
      %>
      <% 
      	if (iState == 0) {
      		 if (bPress) {
    	%>
      	<a href="#" OnClick="javascript:OpenPressWin(<%=iFormID%>,<%=iKeyValue%>,'0');">催办</a>
      	<%
      		}
      		//有下一个节点才可以 
      		if (bSkip && iNextStepID>0) { 
      	%>
      	<a href="#" OnClick="javascript:OpenPressWin(<%=iFormID%>,<%=iKeyValue%>,'1');">跳转</a>
		<% 
      		}
		} 
	  %>      
    </td>    
  </tr>
	<% 
	   if (hasFlow && iFlowID >0) { 
		 //s_transact = lcFlowControl.getCurrentTransactingInfo(iFormID, iKeyValue, "<br>", true);		
		 sPressCount = Integer.toString(lcAssistant.getPressCount(iFormID, iKeyValue, SzConvert.toInt(s_transact[3])))
				  	 + "次/总"
					 + Integer.toString(lcAssistant.getPressCount(iFormID, iKeyValue, 0))
					 + "次";
		 if (s_transact[0] != null && !s_transact[0].equals("")) {
		   out.println("<tr><td><span class=\"product_content\"><b>[当前办理人员]</b>" + s_transact[0] + "</span></td></tr>");
		 }
		 if (s_transact[1] != null && !s_transact[1].equals("&nbsp;") && !s_transact[1].equals("")) {
		   out.println("<tr><td><span class=\"product_content\"><b>[剩余办理时间]</b>" + s_transact[1] + "</span></td></tr>");
		 }		 
		 if (bPress) {
		   out.println("<tr><td><span class=\"product_content\"><b>[被催办次数]</b>" + sPressCount + "</span></td></tr>");
		 }
		 out.println("<tr><td><span class=\"product_content\"><b>[办理状态]</b>" + lcFlowControl.getFlowStateName(iFormID, iKeyValue) + "</span></td></tr>"); 
	   } 
	   out.println(bdValueControl.printTableValueApp(value_str, strDenyField, strDenyField2, 0, sType, iKeyValue,"detail", BdFormHelp.s_FROM_INDEX));
    } //while
    out.println(bdValueControl.printTableBlankApp(i, iPageSize));
%>  
  </form>
</table>
<table width="100%" border="0" cellspacing="3" cellpadding="3">
  <form name="formPage" method="post">  
  <input type="hidden" name="flowType" value="<%=flowType%>">  
  <input type="hidden" name="page" value="<%=iCurrentPage%>">
  <input type="hidden" name="FormID" value="<%=iFormID%>">
  <%=sSelectButton%>
  <%@ include file="/app/share/page_include.jsp" %>
  </form>
</table>
<BR><BR>
