<!--#include file="../../fy.Function.asp"-->
<!doctype html>
<html>
<head>
<meta charset="gb2312">
<title>自定义表单管理</title>
<link rel="stylesheet" type="text/css" href="../../css/base.css">
<link rel="stylesheet" type="text/css" href="../../css/content.css">
<script type="text/javascript" src="../../../fy_inc/js/time/WdatePicker.js"></script>
<script type="text/javascript" src="../../../fy_inc/js/jquery.js"></script>
<script type='text/javascript' src='../../../fy_inc/js/lhg/lhgdialog.min.js'></script>
<script type='text/javascript' src='../../js/main.js'></script>
</head>
<body>
<div class="content"> 
	<div class="breadnav">当前位置：<a href="#">后台首页</a> >> 自定义表单管理</div>
    <div class="opers">
    	<a href="?" class="btn<%If request("A")="" Then echo " btn_primary" %>">管理首页</a>
    	<a href="?A=Add" class="btn<%If request("A")="Add" Then echo " btn_primary" %>">添加自定义表单</a>
    </div>
   <% 

Response.Expires = 0
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
Dim Action,ModeID,Rs,UploadSize,UploadPath,UnlockTime,FormCode,StartTime,EndTime,UserGroupList,SubmitNum,Moneys,ModeStatus,IsMail
	ModeID = ChkNumeric(Request("ModeID"))
	If Not fycms.fycms_QXYZ(0,"form_fy","") Then   Call fycms.Alert("对不起，你没有操作权限！","") 
	Action = Request.QueryString("A")
	 if ModeID=0 or ModeID="" Then ModeID=1
	Select Case Action
		   Case "AddSave","ESave"
		   		Call AddSave()
			Case "Add","E"
				Call AddEdit()
			Case Else
				Call Main()
	End Select
	
	
	IF Action = "Del" Then
			fycms.ACTEXE("Delete From ModeForm_fy Where ModeID=" & ModeID)		
			Call fycms.ActErr("删除表单成功","Sys_fy/Form/Index.asp","")
 	End IF
	
	
	Sub AddSave()
		 Dim ModeName,ModeTable,sql,ChannelRS,ChannelRSSql,ModeNote
		 Dim UpfilesDir,RecyleIF
		 ModeName = fycms.S("ModeName")
		 ModeTable = fycms.S("ModeTable")
		 ModeNote = fycms.S("ModeNote")
		 UploadPath = fycms.S("UploadPath")
		 UploadSize = ChkNumeric(fycms.S("UploadSize"))
		 UnlockTime = ChkNumeric(fycms.S("UnlockTime"))
		 IsMail = ChkNumeric(fycms.S("IsMail"))
 		 StartTime = fycms.S("StartTime")
		 EndTime = fycms.S("EndTime")
		 UserGroupList = fycms.S("UserGroupList")
		 SubmitNum = ChkNumeric(fycms.S("SubmitNum"))
		 ModeStatus = ChkNumeric(fycms.S("ModeStatus"))
		 Moneys = fycms.S("Moneys")
		 If Not IsNumeric(Moneys) Then Moneys=0
		 If  UserGroupList =""  Then UserGroupList=0
		 ModeNote = fycms.S("ModeNote")
		 FormCode = ChkNumeric(fycms.S("FormCode"))

		 IF fycms.S("ModeName") = "" Then
		 	Call fycms.Alert("表单名称为空!",""):Exit Sub
		 End if
		 IF Not IsDate(StartTime) Then StartTime=Now
		 IF Not IsDate(EndTime) Then EndTime=Now+10
		 if Action="AddSave" Then
			 IF fycms.S("ModeTable") = "" Then
				Call fycms.Alert("数据表为空!",""):Exit Sub
			 End If
			If fycms.defaultField(ModeName,"")=True Then  Call fycms.Alert("数据库中已存在该字段\n或该字段是系统关键字!", "")
			 If Not fycms.ACTEXE("SELECT ModeName FROM ModeForm_fy Where ModeName='" & ModeName & "' order by ModeID desc").eof Then
				Call fycms.Alert("系统已存在该表单名称!",""):Exit Sub
			 End if	
			 If Not fycms.ACTEXE("SELECT ModeTable FROM ModeForm_fy Where ModeTable='" & ModeTable & "' order by ModeID desc").eof Then
				Call fycms.Alert("系统已存在该数据表!",""):Exit Sub
			 End if	
			 Set ChannelRS = Server.CreateObject("adodb.recordset")
			  ChannelRSSql = "select * from ModeForm_fy"
			  ChannelRS.Open ChannelRSSql, Conn, 1, 3
			  ChannelRS.AddNew
		 	  ChannelRS("ModeTable") = ModeTable
			  ChannelRS("ModeName") = ModeName
			  ChannelRS("ModeNote") = ModeNote
			  ChannelRS("UploadPath") = UploadPath
			  ChannelRS("UploadSize") = UploadSize
			  ChannelRS("UnlockTime") = UnlockTime
			  ChannelRS("StartTime") = StartTime
			  ChannelRS("EndTime") = EndTime
			  ChannelRS("UserGroupList") = UserGroupList
			  ChannelRS("SubmitNum") = SubmitNum
			  ChannelRS("Moneys") = Moneys
			  ChannelRS("ModeNote") = ModeNote
			  ChannelRS("FormCode") = FormCode
			  ChannelRS("ModeStatus") = ModeStatus
			  ChannelRS("IsMail") = IsMail
			  ChannelRS.Update
			  ChannelRS.Close:Set ChannelRS = Nothing			
				 Dim sqlformat:If  DataBaseType="access" Then sqlformat=" CONSTRAINT PrimaryKey PRIMARY KEY"
 				 Sql="CREATE TABLE "&ModeTable&" ([ID] int IDENTITY (1, 1) NOT NULL "&sqlformat&" ,"&_
				"addtime datetime,"&_
				"ModeID SmallInt Default 0,"&_
				"UModeID SmallInt Default 0,"&_
				"UserIP varchar(50),"&_
				"UserID int Default 0 "&_
				")"
				
			'SmallInt 整型,varchar(200)'文本,tinyint 字节, int Default 0 长整型
			fycms.ACTEXE(sql)
			'die sql
			Call fycms.ActErr("添加成功","Sys_fy/Form/Index.asp","")
 		 Else
		 	If Not fycms.ACTEXE("SELECT ModeName FROM ModeForm_fy Where ModeID <>" & ModeID & " AND  ModeName='" & ModeName & "' order by ModeID desc").eof Then
				Call fycms.Alert("系统已存在该表单名称-!",""):Exit Sub
			 End if	
			 Set ChannelRS = Server.CreateObject("adodb.recordset")
			  ChannelRSSql = "select * from ModeForm_fy Where ModeID=" &ModeID
			  ChannelRS.Open ChannelRSSql, Conn, 1, 3
			  if ChannelRS.eof then Call fycms.Alert("错误!",""):Exit Sub
		 End if 
			  ChannelRS("ModeName") = ModeName
			  ChannelRS("ModeNote") = ModeNote
			  ChannelRS("UploadPath") = UploadPath
			  ChannelRS("UploadSize") = UploadSize
			  ChannelRS("UnlockTime") = UnlockTime
			  ChannelRS("StartTime") = StartTime
			  ChannelRS("EndTime") = EndTime
			  ChannelRS("UserGroupList") = UserGroupList
			  ChannelRS("SubmitNum") = SubmitNum
			  ChannelRS("Moneys") = Moneys
			  ChannelRS("ModeNote") = ModeNote
			  ChannelRS("FormCode") = FormCode
			  ChannelRS("ModeStatus") = ModeStatus
			  ChannelRS("IsMail") = IsMail
			  
		  ChannelRS.Update
		  ChannelRS.Close:Set ChannelRS = Nothing	
		  Call fycms.ActErr("修改成功","Sys_fy/Form/Index.asp","")
 	End Sub
	Sub Main()
	%>	
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <thead>
      <tr>
      <th>表单编号</th>
	  <th>表单名称</th>
	  <th>是否开始</th>
	  <th>参与人数</th>
	  <th>状态</th>
	  <th>管理操作</th>
	  </tr>
    </thead>
     <% 
	  Set Rs =fycms.ACTEXE("SELECT * FROM ModeForm_fy order by ModeID desc")
	 If Rs.EOF  Then
	 	echo	"<tr><td colspan=""7"" align=""center"">没有记录</td></tr>"
	 Else
		Do While Not Rs.EOF	
			 %>
  <tr>
    <td><%= Rs("ModeID") %></td>
    <td><%= Rs("ModeName") %></td>
    <td>
	<%If now >Rs("StartTime") Then 
		echo "<font color=green title=结束日期是"& Rs("EndTime")&">已经开始</a>"
	Else
		echo "<font color=red title=开始日期是"& Rs("StartTime")&">还没有开始</font>"
	End if%>
	</td>
	<td><%=fycms.actexe("select Count(id) from "&rs("ModeTable")&" where modeid="&Rs("ModeID")&"")(0) %></td>
	<td><% IF Rs("ModeStatus") = 0 Then echo "<font color=green>正常</font>" else  echo "<font color=red>禁用</font>" %></td>
	<td >
	<a  target="_blank" href="../../../plus/Form/fy.f.asp?A=list&ModeID=<%= Rs("ModeID") %>"><font color=green>访问</font></a>┆
	<a href="list.asp?ModeID=<%= Rs("ModeID") %>"><font color=red>查看反馈</font></a>
	<a href="javascript:" onClick="WinOpenDialog('<%=fycms.actsys&fycms.adminurl%>/Sys_fy/Form/Type.asp?A=Html&ModeID=<%= Rs("ModeID") %>',650,500)">HTML调用</a> ┆
	<a href="javascript:" onClick="WinOpenDialog('<%=fycms.actsys&fycms.adminurl%>/Sys_fy/Form/Type.asp?ModeID=<%= Rs("ModeID") %>',650,180)">JS调用</a> ┆
	<a href="list.Form.asp?A=L&ModeID=<%=Rs("ModeID")  %>">字段列表</a> 
	┆ <a href="?A=E&ModeID=<%=Rs("ModeID")  %>" >修改</a> ┆ 
	<a href="?A=Del&ModeID=<%=Rs("ModeID")  %>"  onClick="{if(confirm('确定删除该表单吗?')){return true;}return false;}">删除</a></td>
  </tr>
  <% 
		
		Rs.movenext
		Loop
	End if	 %>
    </table>
 
 
<% 	
 
	End Sub
	Sub AddEdit()
	Dim FileFolder,ModeTable,ModeName,FormCode,ModeNote,A,Template
	if Action="Add" Then
	A="AddSave"
	StartTime=date()
	EndTime=date()+10
	UploadPath="UpFiles/form"
	UploadSize=100
	Moneys=0
	ModeStatus=0
	SubmitNum=1
	IsMail=1
	Else
	Set Rs=server.CreateObject("adodb.recordset") 
	Rs.OPen "Select * from ModeForm_fy Where ModeID = "&ModeID&" order by ModeID desc",Conn,1,1
	ModeTable = Rs("ModeTable")
	ModeName = Rs("ModeName")
	ModeNote=Rs("ModeNote")
	ModeStatus=Rs("ModeStatus")
	 UploadPath = Rs("UploadPath")
	 UploadSize = Rs("UploadSize")
	 UnlockTime = Rs("UnlockTime")
	 StartTime = Rs("StartTime")
	 EndTime = Rs("EndTime")
	 UserGroupList = Rs("UserGroupList")
	 SubmitNum = Rs("SubmitNum")
	 Moneys = Rs("Moneys")
	 ModeNote = Rs("ModeNote")
	 FormCode = Rs("FormCode")
	 IsMail= Rs("IsMail")
	A="ESave"
	end if
  %>

<form id="form1" name="form1" method="post" action="?A=<%= A %>&ModeID=<%= Request.QueryString("ModeID") %>">
    <div class="divtable"> 
        <dl>
            <dt>表单状态：</dt>
            <dd>
                <input <% IF ModeStatus = 0 Then echo "Checked" %> id="ModeStatus1" type="radio" name="ModeStatus" value="0" />
     <label for="ModeStatus1"> 正常 </label>
       <input <% IF ModeStatus = 1 Then echo "Checked" %>  id="ModeStatus2" type="radio" name="ModeStatus" value="1" /><label for="ModeStatus2">关闭</label>    
            </dd>
         </dl>
        
        <dl>
            <dt>表单名称：</dt>
            <dd>
               <input name="ModeName"   class="Ainput"  type="text" id="ModeName" value="<%=ModeName %>" />
             </dd>
         </dl>
        <dl>
            <dt>数据表名称：</dt>
            <dd>
               <input   class="Ainput"  <% if A="ESave" then echo "disabled" %> name="ModeTable" type="text" id="ModeTable" value="<%= ModeTable %>" />
             </dd>
         </dl>
        <dl>
            <dt>上传附件存放目录：</dt>
            <dd>
               <input  class="Ainput"   name="UploadPath" type="text" id="UploadPath" value="<%= UploadPath %>" />
             </dd>
         </dl>
        <dl>
            <dt>允许上传的文件大小：</dt>
            <dd>
                只能上传小于或等于 <input   class="Ainput"  name="UploadSize" size=5 type="text" id="UploadSize" value="<%= UploadSize %>" />
       KB的文件（0KB表示不限制）
             </dd>
         </dl>
        <dl>
            <dt>将提交结果发送到站长信箱</dt>
            <dd>
               <input     <% IF IsMail = 0 Then echo "Checked" %> id="IsMail1" type="radio" name="IsMail" value="0">
        <label for="IsMail1">启用</label>
      <input    <% IF IsMail = 1 Then echo "Checked" %> id="IsMail2"  type="radio" name="IsMail" value="1"> 
     <label for="IsMail2">不启用</label> <font color="green">站长信箱在 基本设置 -> 站长信箱.   邮件SMTP在基本设置里 SMTP服务器地址</font>
             </dd>
         </dl>
        <dl>
            <dt>启用时间限制：</dt>
            <dd>
               <input    onClick=time(1)    <% IF UnlockTime = 0 Then echo "Checked" %> id="UnlockTime1" type="radio" name="UnlockTime" value="0">
        <label for="UnlockTime1">启用</label>
      <input    onClick=time(2)   <% IF UnlockTime = 1 Then echo "Checked" %> id="UnlockTime2"  type="radio" name="UnlockTime" value="1"> 
     <label for="UnlockTime2">不启用</label>
             </dd>
         </dl>
        <dl  id="times1"	<%If UnlockTime<>0 Then echo "style=""DISPLAY: none"""%>>
            <dt>开始时间：</dt>
            <dd>
               <input  class="Ainput"  size=30 name="StartTime" type="text" id="StartTime" value="<%= StartTime %>"  onClick="WdatePicker();" />
             </dd>
         </dl>
        <dl id="times2" <%If UnlockTime<>0 Then echo "style=""DISPLAY: none"""%>>
            <dt>结束时间：</dt>
            <dd>
               <input  class="Ainput"   size=30  name="EndTime" type="text" id="EndTime" value="<%= EndTime %>"  onClick="WdatePicker();"/>
             </dd>
         </dl>
        <dl>
            <dt>指定用户组提交：</dt>
            <dd>
               <%= fycms.GetGroup_CheckBox("UserGroupList",UserGroupList,5) %>不限制提交，请不要选择
             </dd>
         </dl>
        <dl>
            <dt>每个用户只允许提交一次：</dt>
            <dd>
                <input  <% IF SubmitNum = 0 Then echo "Checked" %> id="SubmitNum1" type="radio" name="SubmitNum" value="0">
        <label for="SubmitNum1">是</label>
      <input  <% IF SubmitNum = 1 Then echo "Checked" %> id="SubmitNum2"  type="radio" name="SubmitNum" value="1"> 
     <label for="SubmitNum2">否</label>
             </dd>
         </dl>
        <dl>
            <dt>金币设置：</dt>
            <dd>
               <input  class="Ainput"  name="Moneys" type="text" id="Moneys" value="<%= Moneys %>" />
        <font color=red>如需要扣除5个金币请设置为-5,如果增加5个金币请设置5，不设置请为0</font>
             </dd>
         </dl>
        <dl>
            <dt>表单描述：</dt>
            <dd>
               <input  class="Ainput"  name="ModeNote" type="text" id="ModeNote" value="<%= ModeNote %>" size="50" maxlength="250" />
        简单的描述.不能超过250个字符
             </dd>
         </dl>
        <dl>
            <dt>显示验证码：</dt>
            <dd>
                <input  <% IF FormCode = 0 Then echo "Checked" %> id="FormCode1" type="radio" name="FormCode" value="0">
        <label for="FormCode1">显示</label>
      <input  <% IF FormCode = 1 Then echo "Checked" %> id="FormCode2"  type="radio" name="FormCode" value="1"> 
     <label for="FormCode2">不显示</label>
             </dd>
         </dl>
 
            <dl>
            <dt class="vhid">提交：</dt>
            <dd>
                <a class="btn btn_primary" href="javascript:void(0);" onclick="CheckForm()">提交</a>
            
				 <input type="reset" name="Submit2" class="btn" value="重置" />
            </dd>
         </dl>
        
    </div>
    </form>
 
<script language="javascript">time(<%=""""&UnlockTime&""""%>);</script>

<% end sub  %>
<script language="JavaScript" type="text/javascript">
		
function time(n){
	if (n == 2){
		times1.style.display='none';
		times2.style.display='none';
	}
	else{
		times1.style.display='';
		times2.style.display='';
	}
} 



function CheckForm()
{ var form=document.form1;
	
	 if (form.ModeName.value=='')
		{ alert("请输入表单名称!");   
		  form.ModeName.focus();    
		   return false;
		} 
	 if (form.ModeTable.value=='')
		{ alert("请输入数据表名称!");   
		  form.ModeTable.focus();    
		   return false;
		} 	   	
	    form.submit();
        return true;
	}
</script>




</div>


</body>
</html>
