<!--#include file="../../Inc/Cls_Main.Asp"-->
<!--#include file="../inc/Cls_Admin.Asp"-->
<!--#include file="../inc/Cls_MapPath.Asp"-->
<!--#include file="../Admin_Check.Asp"-->
<%
Dim CmsAdmin
'=============================================================================
Set CmsAdmin = New Cls_Admin
CmsAdmin.SetAdminTitle = CmsSiteName
CmsAdmin.SetBodyCssName = "mainbody"
CmsAdmin.SetAdminPath = CmsAdminMapPath
CmsAdmin.LoadHead()
'=============================================================================
Dim Action
'=============================================================================
Action = Easp.Get("action")
Select Case Action
    Case "savemain"
        Call SaveMain()
    Case Else
        Call PageLoad()
End Select
CmsAdmin.LoadFooter()
Set CmsAdmin = Nothing

Sub PageLoad()
%>
<script src="<%=CmsAdminMapPath%>js/check/free.form.check.js"></script>
<form name="myform" id="myform" method="post" action="?action=savemain">
  <div class="navigation"><a href="Admin.Form.List.Asp" class="back">自定义表单管理</a> 控制面板 &gt; 自定义表单管理 &gt; 添加表单</div>
  <div id="contentTab">
    <div class="content-tab">
      <ul class="tab_nav">
        <li><a onclick="tabs(this);" class="selected" href="javascript:void(0);">添加表单</a></li>
      </ul>
    </div>
    <div class="tab_con" style="display: block;">
      <table class="form_table">
        <col width="200px">
          </col>
        
        <tbody>
          <tr>
            <th> 表单状态： </th>
            <td class="td2"><span>
              <input type="radio" name="IsStatus" id="IsStatus1" value="1" checked="checked" datatype="*" nullmsg="请选择表单状态！" />
              <label for="IsStatus1">正常</label>
              <input type="radio" name="IsStatus" id="IsStatus0" value="0" />
              <label for="IsStatus0">停用</label>
              </span> <span class="Validform_checktip">*</span></td>
          </tr>
          <tr>
            <th> 表单名称： </th>
            <td class="td2"><input type="text" class="txtInput w250" name="FormName" id="FormName" autocomplete="off" datatype="*2-20" nullmsg="表单名称必须填写" errormsg="至少2个字符,最多20个字符!" />
              <span class="Validform_checktip">*</span></td>
          </tr>
          <tr>
            <th> 数据表： </th>
            <td class="td2"><input type="text" class="txtInput w150" name="FormTableName" id="FormTableName" autocomplete="off" datatype="en1" nullmsg="数据表必须填写" errormsg="只能是字母+数字,至少3个字符,最多10个字符!" />
              <span class="Validform_checktip">*</span></td>
          </tr>
          <tr>
            <th> 时间限制： </th>
            <td class="td2"><span>
              <input type="radio" name="IsUnlockTime" id="IsUnlockTime1" value="1" checked="checked" datatype="*" nullmsg="请选择时间限制！" />
              <label for="IsUnlockTime1">启用</label>
              <input type="radio" name="IsUnlockTime" id="IsUnlockTime0" value="0" />
              <label for="IsUnlockTime0">不启用</label>
              </span> <span class="Validform_checktip">*</span></td>
          </tr>
          <tr>
            <th> 开始时间： </th>
            <td class="td2"><input type="text" class="txtInput w100" name="StartTime" id="StartTime" autocomplete="off" value="<%=Easp.DateTime(Now(),"yyyy-mm-dd")%>" datatype="date1" onclick="WdatePicker();" />
              <span class="Validform_checktip">*</span></td>
          </tr>
          <tr>
            <th> 结束时间： </th>
            <td class="td2"><input type="text" class="txtInput w100" name="EndTime" id="EndTime" autocomplete="off" value="<%=Easp.DateTime(DateAdd("m", 1, Now()),"yyyy-mm-dd")%>" datatype="date1" onclick="WdatePicker();" />
              <span class="Validform_checktip">*</span></td>
          </tr>
          <tr>
            <th> 表单提交成功提示： </th>
            <td class="td2"><input type="text" class="txtInput w250" name="SuccessMsg" id="SuccessMsg" autocomplete="off" datatype="*2-100" nullmsg="表单提交成功提示必须填写" errormsg="至少2个字符,最多100个字符!" />
              <span class="Validform_checktip">*</span></td>
          </tr>
          <tr>
            <th> 表单提交失败提示： </th>
            <td class="td2"><input type="text" class="txtInput w250" name="ErrorMsg" id="ErrorMsg" autocomplete="off" datatype="*2-100" nullmsg="表单提交失败提示必须填写" errormsg="至少2个字符,最多100个字符!" />
              <span class="Validform_checktip">*</span></td>
          </tr>
          <tr>
            <th> 显示验证码： </th>
            <td class="td2"><span>
              <input type="radio" name="IsCode" id="IsCode1" value="1" checked="checked" datatype="*" nullmsg="请选择显示验证码！" />
              <label for="IsCode1">是</label>
              <input type="radio" name="IsCode" id="IsCode0" value="0" />
              <label for="IsCode0">否</label>
              </span> <span class="Validform_checktip">*</span></td>
          </tr>
          <tr>
            <th></th>
            <td><input type="submit" class="btnSubmit" value="提交保存" />
              <input name="重置" type="reset" class="btnSubmit" value="重 置" /></td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</form>
<%
End Sub

Sub SaveMain()
    ChkSysAdminLevel "sys_free", "add"
    '=====================================================================
    Dim FormName, FormTableName, IsStatus, IsUnlockTime
    Dim StartTime, EndTime, SuccessMsg, ErrorMsg, IsCode, TabName
    FormName = Trim(Easp.Post("FormName:s"))
    FormTableName = Trim(Easp.Post("FormTableName:s"))
    IsStatus = Easp.Post("IsStatus:n:0")
    IsUnlockTime = Easp.Post("IsUnlockTime:n:0")
    StartTime = Easp.Post("StartTime:d")
    EndTime = Easp.Post("EndTime:d")
    SuccessMsg = Trim(Easp.Post("SuccessMsg:s"))
    ErrorMsg = Trim(Easp.Post("ErrorMsg:s"))
    IsCode = Easp.Post("IsCode:n:0")
    '=====================================================================
    If Easp.IsN(FormName) Then
        CmsAdmin.JscriptMsg "表单名称不能为空！", "back", "Error", "null"
    End If
    If Easp.IsN(FormTableName) Then
        CmsAdmin.JscriptMsg "数据表不能为空！", "back", "Error", "null"
    End If
    If IsUnlockTime = 1 Then
        If (Easp.IsN(StartTime) Or Easp.IsN(EndTime)) Then
            CmsAdmin.JscriptMsg "开始时间与结束时间不能为空！", "back", "Error", "null"
        End If
    End If
    TabName = TablePrefix & "From_" & FormTableName
    If CmsMain.CheckTable(TabName) Then
        CmsAdmin.JscriptMsg "所填写的表:"& FormTableName &"，已经存在！", "back", "Error", "null"
    End If
    If Easp.IsN(SuccessMsg) Then
        CmsAdmin.JscriptMsg "表单提交成功提示必须填写！", "back", "Error", "null"
    End If
    If Easp.IsN(ErrorMsg) Then
        CmsAdmin.JscriptMsg "表单提交失败提示必须填写！", "back", "Error", "null"
    End If
    '=====================================================================
    Dim List, ResultVal
    Easp.Use "list"
    Set List = Easp.List.New
    List("FormName") = FormName
    List("FormTableName") = TabName
    List("IsStatus") = IsStatus
    List("IsUnlockTime") = IsUnlockTime
    List("StartTime") = StartTime
    List("EndTime") = EndTime
    List("SuccessMsg") = SuccessMsg
    List("ErrorMsg") = ErrorMsg
    List("IsCode") = IsCode
    List("AddTime") = Now()
    '=====================================================================
    ResultVal = Easp.db.AR(TablePrefix & "FreeForm:id", List.Hash)
    '=====================================================================
    Easp.C List
    If ResultVal <> 0 Then
        If Not CmsMain.CheckTable(TabName) Then
            CmsMain.CreateTable TabName
            CreateList ResultVal, TabName, "提交用户", "UserName", "提交用户必须填写"
            CmsMain.AddColumn TabName, "Ip", "nvarchar(50) Null"
            CmsMain.AddColumn TabName, "AddTime", "DATETIME DEFAULT " & GetSqlTime
        End If
        '=================================================================
        CmsAdmin.JscriptMsg "添加自定义表单成功！", "Admin.Form.List.Asp", "Success", "null"
    End If
    '=====================================================================
End Sub


Sub CreateList(ByVal Id, ByVal TabName, ByVal Alias, ByVal FieldName, ByVal FieldNull)
    Dim objList
    Easp.Use "list"
    Set objList = Easp.List.New
    objList("ChannelId") = Id
    objList("Alias") = Alias
    objList("FieldName") = "MY_" & FieldName
    objList("IsNotNull") = 1
    objList("FieldType") = 1
    objList("ListVal") = ""
    objList("FieldNull") = FieldNull
    objList("Px") = 1
    objList("IsSys") = 1
    objList("AddTime") = Now()
    Easp.db.AR TablePrefix & "FreeField", objList.Hash
    Easp.C objList
    CmsMain.AddColumn TabName, "MY_" & FieldName, "nvarchar(255) Null"
End Sub
%>
