<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.tool.*" %>
<%@ page import="net.sz600.organize.*" %>
<%@ 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.formEngine2.*" %>
<%@ page import="net.sz600.formEngine.*" %>
<%@ include file="/sessionInfo.jsp"%>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<%=strSkin_SESSION%>/css2007.css" rel="stylesheet" type="text/css">
<script language="javascript">
 function checkMonth(oFormName, sV, sUrl) {
 	oFormName.chkDate.value = sV;
 	oFormName.action = sUrl;
 	oFormName.target = "_self";
 	oFormName.submit();
 }
</script>
<script language="javascript">
  function VisitDetail(key) {
    var type= "";
    var url = "../../newcustomer/visit/detail.jsp?OPERATOR=detail&type=0&KEY=" + key;
    window.showModalDialog(url,window,"status=no;dialogWidth=780px;dialogHeight=550px");  
  }
  function VisitDetail2(key) {
    var type= "";
    var url = "../../newcustomer/info/detail.jsp?OPERATOR=detail&type=0&KEY=" + key;
    window.showModalDialog(url,window,"status=no;dialogWidth=780px;dialogHeight=550px");  
  }  
</script>
</head>
<%
    
    //获取提交的参数
    String sFormID = SzConvert.toZeroStr(request.getParameter("FormID"));
		int iFormID = SzConvert.toInt(sFormID);
	  String flowType = SzConvert.toSpaceStr(request.getParameter("flowType"));
		if (flowType.equals("")) {
			flowType = "-2";
		}	 
		
		String datefield = SzConvert.strWriteData(request.getParameter("datefield"));   //日期字段， 
	  String sSearchName = SzConvert.strWriteData(request.getParameter("txtSearchName")); //查询的人员姓名
	  String sSearchDepart = SzConvert.strWriteData(request.getParameter("txtSearchDepart")); //查询的部门名称
	  //查询时间段
	  String sSearchBegin = SzConvert.strWriteData(request.getParameter("txtSearchBegin")); //开始日期
	  String sSearchEnd = SzConvert.strWriteData(request.getParameter("txtSearchEnd"));     //结束日期
	    
    String sType = SzConvert.toZeroStr(request.getParameter("type"));
    String sPKEY = SzConvert.toZeroStr(request.getParameter("PKEY"));
    String sPage = SzConvert.toZeroStr(request.getParameter("page"));
    String sSearch = SzConvert.strWriteData(request.getParameter("txtSearch"));


    String selectDay = SzConvert.toSpaceStr(request.getParameter("selectDay"));
    

    
    String chkDate = SzConvert.toZeroStr(request.getParameter("chkDate"));
    
    if (chkDate.equals("1")) {
    		sSearchBegin = SzDateHelp.dateToYMD(SzDateHelp.dayBefore(SzDateHelp.stringToDate(sSearchBegin), 7));
    		sSearchEnd = SzDateHelp.dateToYMD(SzDateHelp.dayBefore(SzDateHelp.stringToDate(sSearchEnd), 7));
   	} else if (chkDate.equals("2")) {   	  	
				sSearchBegin = SzDateHelp.dateToYMD(SzDateHelp.dayAfter(SzDateHelp.stringToDate(sSearchBegin), 7));
				sSearchEnd = SzDateHelp.dateToYMD(SzDateHelp.dayAfter(SzDateHelp.stringToDate(sSearchEnd), 7));   	  	
   	} else if (chkDate.equals("0") || sSearchBegin.equals("") || sSearchEnd.equals("")) {
   		//本周
   		sSearchBegin = SzDateHelp.dateToYMD(SzDateHelp.getFirstDateWeek());
   		sSearchEnd = SzDateHelp.dateToYMD(SzDateHelp.getLastDateWeek());
   	}
    
    String sTable_type = "";


		BdValueControl bdValueControl = new BdValueControl();
		bdValueControl.setModuleInfo(iFormID);
		String sNameField = bdValueControl.getNameField();
		String sDepartNameField = bdValueControl.getDepartNameField();
    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;
    } 
    
    String sCond = bdValueControl.getCond(iFormID, iDLID_SESSION, iBMID_SESSION
    		, isBarManager_SESSION, "", isDataCanSee_SESSION
    		, szCOMPANY_SESSION, "", "", flowType, "");
    //2014-11扩展条件：日期区间；姓名；部门
    sCond = bdValueControl.appendCond(sCond, sSearchName, sSearchDepart);

    
    int i = 0;
		int j = 0;
		
	  //2010-2-21
	  BdPopedom bdPopedom = new BdPopedom();        
	  String strDenyField = bdPopedom.getDenyField(iFormID, 0, iDLID_SESSION);
    
%>
<!-----上面的工具栏------>
<%@ include file="/share/title.jsp"%>


<table width="100%">
  <form name="formBar" method="post">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="sCond" value="<%=sCond%>">  
  <input type="hidden" name="chkDate" value="-1">
  <input type="hidden" name="FormID" value="<%=iFormID%>"> 
  <input type="hidden" name="txtSortField" value="<%=sSortField%>"> 
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>">   
  <input type="hidden" name="datefield" value="<%=datefield%>">  
  <tr>
    <td>
			<input type="button" value="本周" class="btnClass" name="prioWeek" OnClick="javascript:checkMonth(formBar, '0', 'index_week.jsp');">
	 		<input type="button" value="上周" class="btnClass" name="prioWeek" OnClick="javascript:checkMonth(formBar, '1', 'index_week.jsp');">
      <input type="button" value="下周" class="btnClass" name="nextWeek" OnClick="javascript:checkMonth(formBar, '2', 'index_week.jsp');">
      指定天<%
      String s_name[] = {"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
      String s_id[] = {"0","1","2","3","4","5","6"};
      
      out.println(SzPageHelp.idSelectArrayFunc(s_name, s_id, "selectDay", selectDay, "txtClass80", "this.form.submit();"));
      %>
      开始<input type="text" name="txtSearchBegin" class="txtClassSearch" value="<%=sSearchBegin%>" readonly>
      结束<input type="text" name="txtSearchEnd" class="txtClassSearch" value="<%=sSearchEnd%>" readonly>
     <%
     	if (!sNameField.equals("") || !sDepartNameField.equals("")) {
     		if (!sNameField.equals("")) {
     			%>按姓名查<input type="text" name="txtSearchName" class="txtClassSearch" value="<%=sSearchName%>" OnDblClick="javascript:OpenWin12('','formBar.txtSearchName','all');"><%     			
     		}
     		if (!sDepartNameField.equals("")) {
     			%>按部门名称查<input type="text" name="txtSearchDepart" class="txtClassSearch" value="<%=sSearchDepart%>"  OnDblClick="javascript:OpenWin22('','formBar.txtSearchDepart','all');"><%     			
     		}
     		%><input class="btnClass" type="button" name="btnSearchNameOk" value="确定" OnClick="javascript:FormSubmit(formBar,'index_week.jsp');"><%
     	}
     %>     		

    </td>
  </tr>
  </form>
</table>

<!-----信息列表----->
<table width="100%" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="1" cellspacing="0">
  <form name="formList" method="post">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="sCond" value="<%=sCond%>">  
  <input type="hidden" name="chkDate" value="-1">
  <input type="hidden" name="FormID" value="<%=iFormID%>"> 
  <input type="hidden" name="txtSortField" value="<%=sSortField%>"> 
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>">   
  <input type="hidden" name="datefield" value="<%=datefield%>">    
  <input type="hidden" name="txtSearchName" value="<%=sSearchName%>">  
  <input type="hidden" name="txtSearchDepart" value="<%=sSearchDepart%>">
  <input type="hidden" name="txtSearchBegin" value="<%=sSearchBegin%>">
  <input type="hidden" name="txtSearchEnd" value="<%=sSearchEnd%>">      
  <tr class="trClassTitle">
    <td width="80">星期</td>
		<%=bdValueControl.printTableTitle(sSortField, iSortOrder)%> 		
		<td width="30">操作</td>
  </tr>
<%
		int iListFieldLen = bdValueControl.getListFieldLen();
		String strDenyField2 = "";
		Collection coll = null;
		Iterator iter = null;
	  String value_str[] = null;
	  int iKeyValue = 0;
	  int iIndexKey = bdValueControl.getIndexKey();

	  if (iIndexKey == -1) {
	    	iIndexKey = 0;
	  }
		Date date = SzDateHelp.stringToDate(sSearchBegin);
		Date nextDate = null;
		int k = 0;
		String strCond = "";
		int iSize = 0;
		for (k = 0; k<7; k++ ) {		
			nextDate = SzDateHelp.dayAfter(date,1);	
			if (!selectDay.equals("")) {
				if (SzConvert.toInt(selectDay) == k) {
				} else {
					date = nextDate;
					continue;
				}
			}
			strCond = bdValueControl.appendCondDate(sCond, datefield, date); 

			coll = bdValueControl.getArrayList(strCond, sSortField, iSortOrder);
			if (coll != null) {
				iter = coll.iterator();
				iSize = coll.size();
			}
			if (iSize > 0) {
			%>
			<tr>
				<td class="trClassTitle_c" align="left" rowspan="<%=iSize + 1 %>"><b><%=SzDateHelp.getWeekName(date) %></b></td>
			</tr>			
			<%
		    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);
			%>
			<tr>
				<%=bdValueControl.printTableValue(value_str, strDenyField, strDenyField2, 0, sType, iKeyValue, "detail", "" + BdFormHelp.s_FROM_WEEK)%>
				<td width="30"><a href="javascript:FormSubmit(formBar,'update.jsp?OPERATOR=detail&KEY=<%=iKeyValue%>&from=<%=BdFormHelp.s_FROM_WEEK %>');">详情</a></td>
			</tr>
<%
		    }
			} else {
			%>
			<tr>
				<td align="left" class="trClassTitle_c"><b><%=SzDateHelp.getWeekName(date) %></b></td>
				<%out.println(SzPageHelp.outIndexTableTd(iListFieldLen)); %>
				<td width="30"></td>				
			</tr>							
			<%					  
			}
			date = SzDateHelp.dayAfter(date,1);			
	} //for (k = 0; k<7; k++ )			
  String temp = "";
%>		

  </form>
</table>

<!-----下面的工具栏------>
<table width="100%">
  <form name="formPage" method="post">
  <input type="hidden" name="type" value="<%=sType%>">
  <input type="hidden" name="txtSearch" value="<%=sSearch%>">
  <input type="hidden" name="sCond" value="<%=sCond%>">  
  <input type="hidden" name="FormID" value="<%=iFormID%>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>"> 
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>">   
  <input type="hidden" name="chkDate" value="-1"> 
  <input type="hidden" name="datefield" value="<%=datefield%>">
  <input type="hidden" name="txtSearchName" value="<%=sSearchName%>">  
  <input type="hidden" name="txtSearchDepart" value="<%=sSearchDepart%>">
  <input type="hidden" name="txtSearchBegin" value="<%=sSearchBegin%>">
  <input type="hidden" name="txtSearchEnd" value="<%=sSearchEnd%>">   
  <tr>
    <td align="right">

    </td>
  </tr>
  </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="sCond" value="<%=sCond%>">  
  <input type="hidden" name="FormID" value="<%=iFormID%>">
  <input type="hidden" name="txtSortField" value="<%=sSortField%>"> 
  <input type="hidden" name="txtSortOrder" value="<%=iSortOrder%>">   
  <input type="hidden" name="chkDate" value="-1">
  <input type="hidden" name="datefield" value="<%=datefield%>">
  <input type="hidden" name="txtSearchName" value="<%=sSearchName%>">  
  <input type="hidden" name="txtSearchDepart" value="<%=sSearchDepart%>">
  <input type="hidden" name="txtSearchBegin" value="<%=sSearchBegin%>">
  <input type="hidden" name="txtSearchEnd" value="<%=sSearchEnd%>">      
</form>
<script language="javascript" src="../../share/js/commonTool.js"></script>
<script language="javascript">
  function OpenWin(objName,type) {
    var url = "../../share/organize/name_single_win.jsp";
    url = url + "?objName=" + objName + "&type=" + type;
    window.showModalDialog(url,window,"status=no;dialogWidth=580px;dialogHeight=350px");
    //window.open(url,"","status=no;Width=580px;Height=350px");
  }
</script>
<%
    //map = null;
%>
<%
    ////如果要使用日历控件，必须输出这个calendarFrame
    out.println(SzPageHelp.calendar2Frame2());
%>
