<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.util.*" %>
<%@ page import="net.sz600.basicdata.*" %>
<%@ page import="net.sz600.tool.SzConvert" %>
<%@ page import="net.sz600.tool.SzDateHelp" %>
<%@ page import="net.sz600.system.*" %>
<%@ page import="net.sz600.formEngine.*" %>
<%@ page import="net.sz600.formEngine2.*" %>
<%@ page import="net.sz600.formCreate.*" %>
<%@ include file="/xml/formEngine2/sessionInfo2.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">
</head>
<%
    //获取提交的参数
    String name = SzConvert.toSpaceStr(request.getParameter("name"));
    String readonly = "";
    String sOPERATOR = SzConvert.toSpaceStr(request.getParameter("OPERATOR"));
		String moduleName = SzConvert.toSpaceStr(request.getParameter("moduleName"));
		String formName = SzConvert.toSpaceStr(request.getParameter("formName"));
    BdAlert bdAlert = new BdAlert();
    String str[] = bdAlert.getInfo(name);
    
		if (sOPERATOR.equals("add")) {
			str[1] = moduleName;
			str[2] = formName;
			str[7] = "0";
			str[8] = "0";
			str[9] = "3";
			str[10] = "0";
			str[11] = "1";
		} else if (sOPERATOR.equals("update")) {
			moduleName = str[1];
			formName = str[2];
		}
		if (str[11].equals("")) {
			str[11] = "0";
		}
   	
		String strPath = "";
		String strPath2 = "";
		String strPathApp = "";
		if (!name.equals("") && !moduleName.equals("") && !formName.equals("")) {
			BdFormControl bdFormControl = new BdFormControl();
			strPath = "share/alert/indexMy.jsp?name=" + name + "&FormID=" + bdFormControl.getFormID(moduleName, formName);
			strPath2 = "share/alert/indexAdmin.jsp?name=" + name + "&FormID=" + bdFormControl.getFormID(moduleName, formName);
			strPathApp = "app/alert/indexMy.jsp?name=" + name + "&FormID=" + bdFormControl.getFormID(moduleName, formName);
		}
   			
%>
<body>

<!-----上面的工具栏------>
<form name="formUpdate" method="post">
  <input type="hidden" name="OPERATOR" value="<%=sOPERATOR%>">
<%@ include file="/xml/formEngine2/title.jsp"%>
<table width="100%">
  <tr>
    <td>
      <%=SzPageHelp.saveButton()%>
      <%=SzPageHelp.backButton()%>
    </td>
  </tr>
</table>

<!-----信息维护------>
<table width="750" border="1" bordercolorlight="#C0C0C0" bordercolordark="#FFFFFF" class="tableClass" cellpadding="3" cellspacing="0">
  <tr>
    <td class="tdClassTitle">名称</td>
    <td colspan="3"><input type="text" name="name" value="<%=str[0]%>" size="10" <%if (sOPERATOR.equals("update")){%> readonly class="txtClass1R"<%}else {%>class="txtClass1"<%} %>> (可用字母、数字、下划线的组合，10个字以内) <font color="red">*</font></td>
  </tr>
  <tr>
    <td class="tdClassTitle">模块名称</td>
    <td><input type="text" name="moduleName" class="txtClass1R" value="<%=str[1]%>"  readonly></td>
    <td class="tdClassTitle">表单名称</td>
    <td><input type="text" name="formName" class="txtClass1R" value="<%=str[2]%>" readonly></td>
  </tr> 
  <tr>
    <td class="tdClassTitle">说明</td>
    <td colspan="3"><input type="text" name="desc" class="txtClass2" value="<%=str[3]%>"></td>
  </tr>
  <tr>
    <td class="tdClassTitle">内容字段</td>
    <td colspan="3"><input type="hidden" name="contentField" value="<%=str[4]%>">
    <%
    BdFormControl bdFormControl = new BdFormControl();    
    Map fieldMap = bdFormControl.getFieldMap();
    BdFormFieldInfo bdFormFieldInfo = null;
    Collection collFormField = null;
    collFormField = (Collection)fieldMap.get(new String(moduleName + "-" + formName));
    Iterator iterFormField = null;    
    String strMainTable = bdFormControl.getMainTableName(moduleName, formName);
    
    if (collFormField != null) {
    	iterFormField = collFormField.iterator();
    }    
		int i =0;
		String temp = "," + str[4] + ",";
		while (iterFormField != null && iterFormField.hasNext()) {
			bdFormFieldInfo = (BdFormFieldInfo) iterFormField.next();			
			if (    bdFormFieldInfo.getZDBJ() == 1 
			 	|| bdFormFieldInfo.getZDBJ() == 3 
			 	|| bdFormFieldInfo.getZDBJ() == 34
		  ) {
				continue;
			}
			if (!strMainTable.equals(bdFormFieldInfo.getTableName())) {
				continue;
			}			
			out.println("<span style='width:200px;'><input type='checkbox' name='contentField2' value='" + bdFormFieldInfo.getZDMC() + "'");
			if (temp.indexOf(bdFormFieldInfo.getZDMC())>0) {
				out.println(" checked ");
			}
			out.println(">");
			out.println(bdFormFieldInfo.getZDMC() + " " + bdFormFieldInfo.getZDSM());
			i ++;
			out.println("</span>");
			if (i % 3 == 0) {
				out.println("<br>");
			}
		}
		%>    
    </td>
  </tr>   
  <tr>
    <td class="tdClassTitle">提醒的人员字段</td>
    <td colspan="3"><input type="hidden" name="userField" value="<%=str[5]%>">
    <%
    if (collFormField != null) {
    	iterFormField = collFormField.iterator();
    }    
		temp = "," + str[5] + ",";
		i = 0;
		while (iterFormField != null && iterFormField.hasNext()) {
			bdFormFieldInfo = (BdFormFieldInfo) iterFormField.next();
			if (bdFormFieldInfo.getZDZT() == 2 ) {								 	
				continue;
			}
			if (   	
				bdFormFieldInfo.getZDBJ() == 31
				|| bdFormFieldInfo.getZDBJ() == 32
				|| bdFormFieldInfo.getZDBJ() == 133
				|| bdFormFieldInfo.getZDBJ() == 4
				|| bdFormFieldInfo.getZDBJ() == 42
				|| bdFormFieldInfo.getZDBJ() == 43
				|| bdFormFieldInfo.getZDBJ() == 44) {				 	
				continue;
			}				
			
			if (!strMainTable.equals(bdFormFieldInfo.getTableName())) {
				continue;
			}
			out.println("<span style='width:200px;'><input type='checkbox' name='userField2' value='" + bdFormFieldInfo.getZDMC() + "'");
			if (temp.indexOf("," + bdFormFieldInfo.getZDMC() + ",")>0) {
				out.println(" checked ");
			}
			out.println(">");
			out.println(bdFormFieldInfo.getZDMC() + " " + bdFormFieldInfo.getZDSM());
			i ++;
			out.println("</span>");
			if (i % 3 == 0) {
				out.println("<br>");
			}
		}
		%>      
    </td>
  </tr>    
  <tr>
    <td class="tdClassTitle">时间字段</td>
    <td colspan="3">
    <%

    if (collFormField != null) {
    	iterFormField = collFormField.iterator();
    }    
		temp = str[6];
		i = 0;
		while (iterFormField != null && iterFormField.hasNext()) {
			bdFormFieldInfo = (BdFormFieldInfo) iterFormField.next();			
			if (    bdFormFieldInfo.getZDBJ() == 1 
				 	|| bdFormFieldInfo.getZDBJ() == 3 
				 	|| bdFormFieldInfo.getZDBJ() == 34
			  ) {
					continue;
			}				
			if (	
				  bdFormFieldInfo.getZDBJ() != 4
					&& bdFormFieldInfo.getZDBJ() != 42
					&& bdFormFieldInfo.getZDBJ() != 43
					&& bdFormFieldInfo.getZDBJ() != 44) {
				continue;
			}
			out.println("<span style='width:200px;'><input type='radio' name='timeField' value='" + bdFormFieldInfo.getZDMC() + "'");
			if (temp.equals(bdFormFieldInfo.getZDMC())) {
				out.println(" checked ");
			}
			out.println(">");
			out.println(bdFormFieldInfo.getZDMC() + " " + bdFormFieldInfo.getZDSM());
			i ++;
			out.println("</span>");
			if (i % 3 == 0) {
				out.println("<br>");
			}
		}
		%>    
    </td>
  </tr>     
  <tr>
    <td class="tdClassTitle">提醒类型</td>
    <td colspan="3">
      <%
      	String s_id2[] = {"0","1","2","3"};
        String s_name2[] = {"保存时提醒","到期提醒","循环提醒","不发提醒消息"};
        out.println(SzPageHelp.radio("alertType", s_id2, s_name2, str[7]));
      %> 
    </td>
  </tr>   
  <tr>
    <td class="tdClassTitle">循环提醒类型</td>
    <td colspan="3">
      <%
      	String s_id3[] = {"0","1","2","3"};
      	String s_name3[] = {"每天","每周","每月","每年"};
        out.println(SzPageHelp.radio("repeatType", s_id3, s_name3, str[8]));
      %> 
    </td>
  </tr>  
  <tr>
    <td class="tdClassTitle">邮件提醒</td>
    <td colspan="3">
      <%
      	String s_id5[] = {"0","1"};
      	String s_name5[] = {"不需要","需要"};
        out.println(SzPageHelp.radio("mailAlert", s_id5, s_name5, str[11]));
      %> 
    </td>
  </tr>   
  <tr>
    <td class="tdClassTitle">微信提醒</td>
    <td colspan="3">
      <%
        out.println(SzPageHelp.radio("weixinAlert", s_id5, s_name5, str[12]));
      %> 
    </td>
  </tr> 
  <tr>
    <td class="tdClassTitle">提前时间</td>
    <td colspan="3"><input type="text" name="before" class="txtClass60" value="<%=str[9]%>">
      <%
      	String s_id4[] = {"0","1","2"};
      	String s_name4[] = {"分钟","小时","天"};
        out.println(SzPageHelp.radio("beforeType", s_id4, s_name4, str[10]));
      %> 
    </td>
  </tr>  
  <tr>
    <td class="tdClassTitle">执行类型</td>
    <td colspan="3">
      <%
        //2014-12增加否决
      	String s_id6[] = {"0","1","2","4"};
        String s_name6[] = {"保存时","审批通过时","办结时","否决时"};
        out.println(SzPageHelp.radio("operatorType", s_id6, s_name6, str[14]));
      %> 
    </td>
  </tr>    
  <tr>
    <td class="tdClassTitle">执行条件</td>
    <td colspan="3"><input type="text" name="condField" class="txtClass2" value="<%=str[13]%>">(SQL条件)</td>
  </tr> 
  <tr>
    <td class="tdClassTitle" nowrap>不符合执行条件</td>
    <td colspan="3">
      <%
        //2014-12增加否决
      	String s_id7[] = {"0","1"};
        String s_name7[] = {"保存提醒记录但不提醒","不保存提醒记录"};
        out.println(SzPageHelp.radio("condResult", s_id7, s_name7, str[15]));
      %> 
    </td>
  </tr>     
  
  <% if (!strPath.equals("")) { %>  
  <tr>
  	<td class="tdClassTitle">手机提醒查询</td>
  	<td colspan="3"><%=strPathApp%></td>
  </tr>  
  <tr>
  	<td class="tdClassTitle">个人提醒查询</td>
  	<td colspan="3"><%=strPath%></td>
  </tr> 
  <tr>
  	<td class="tdClassTitle">管理员提醒查询</td>
  	<td colspan="3"><%=strPath2%></td>
  </tr>           
 	<%} %>
</table>

</form>

<!-----这里包含要提交的内容--->
<form name="formHidden" method="post">
</form>
<script language="javascript" src="../../../share/js/commonTool.js"></script>
<script language="javascript">

  function FormSave(formName, url) {
    if (!notSpace(formName.name, "名称")) {
      return false;
    }  
    if (!isLetterOrNumOrLine(formName.name.value)) {
      alert("名称只能是字母、数字、下划线的组合");
      return false;
    }  
    var contentField2 = ValueOfCheck(formName.contentField2)
    if (contentField2 == "") {
    	alert("请至少选择一个内容字段");
    	return false;
    } else {
    	formName.contentField.value = contentField2;
    }  
    var userField2 = ValueOfCheck(formName.userField2)
    if (userField2 == "") {
    	alert("请至少选择一个人员字段");
    	return false;
    } else {
    	formName.userField.value = userField2;
    }     

    var timeField = ValueOfRadio(formName.timeField)
    if (timeField == "") {
    	alert("请选择一个时间字段");
    	return;
    }   


    formName.action = "control.jsp";
    formName.submit();
  }
  
 
</script>
</body>
