<!--#include file="../../Inc/Cls_Main.Asp"-->
<!--#include file="../inc/Cls_Admin.Asp"-->
<!--#include file="../inc/Cls_MapPath.Asp"-->
<!--#include file="../inc/Cls_ChannelField.Asp"-->
<!--#include file="../inc/Cls_InType.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 ChannelId
ChannelId = Easp.Get("ChannelId:n:0")
If ChannelId = 0 Then
    CmsAdmin.JscriptMsg "频道参数错误！", "back", "Error", "null"
End If
' 读取频道信息
Dim ArrayChannel, ChannelName, BriefName, TabName
ArrayChannel = GetCaCheChannelInfo("Channel", ChannelId, ChannelField)
If Easp.IsN(ArrayChannel) Then
    CmsAdmin.JscriptMsg "不存在的频道！", "back", "Error", "null"
Else
    ChannelName = ArrayChannel(0)
    BriefName = ArrayChannel(1)
    TabName = ArrayChannel(2)
End If
'=============================================================================
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/channel.field.check.js"></script>
<form name="myform" id="myform" method="post" action="?action=savemain&ChannelId=<%=ChannelId%>">
  <div class="navigation"><a href="Admin.Field.List.Asp?ChannelId=<%=ChannelId%>" class="back">字段管理</a> 控制面板 &gt; 系统频道管理 &gt; <%=BriefName%>频道字段管理 &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"><input type="text" name="Alias" id="Alias" class="txtInput w200" autocomplete="off" datatype="*2-50" nullmsg="字段别名必须填写" errormsg="至少4个字符,最多50个字符!" />
              <span class="Validform_checktip">*,如：新闻标题</span></td>
          </tr>
          <tr>
            <th>字段名称：</th>
            <td class="td2"><input type="text" name="FieldName" id="FieldName" class="txtInput w200" autocomplete="off" value="<%=FieldPrefix%>" datatype="zd" nullmsg="字段名称必须填写" errormsg="至少2个字符,最多20个字符!" />
              <span class="Validform_checktip">*,必须已：MY_开头,只能是英文+字母</span></td>
          </tr>
          <tr>
            <th>是否必填：</th>
            <td class="td2"><span id="cblItem">
              <input id="IsNotNull001" type="radio" name="IsNotNull" value="1" datatype="n0-1" />
              <label for="IsNotNull001">是</label>
              <input id="IsNotNull002" type="radio" name="IsNotNull" value="0" checked="checked" />
              <label for="IsNotNull002">否</label>
              </span><span class="Validform_checktip"></span></td>
          </tr>
          <tr class="IsNotNull" style="display:none;">
            <th>验证正则表达式：</th>
            <td class="td2"><input type="text" name="ValidPattern" id="ValidPattern" class="txtInput w350" autocomplete="off" datatype="*0-30" errormsg="最多30个字符!" />
              <span class="Validform_checktip">不填写则不验证</span></td>
          </tr>
          <tr class="IsNotNull" style="display:none;">
            <th>验证提示信息：</th>
            <td class="td2"><input type="text" name="ValidTipMsg" id="ValidTipMsg" class="txtInput w350" autocomplete="off" datatype="*0-50" errormsg="最多50个字符!" />
              <span class="Validform_checktip"></span></td>
          </tr>
          <tr class="IsNotNull" style="display:none;">
            <th>验证失败信息：</th>
            <td class="td2"><input type="text" name="ValidErrorMsg" id="ValidErrorMsg" class="txtInput w350" autocomplete="off" datatype="*0-50" errormsg="最多50个字符!" />
              <span class="Validform_checktip"></span></td>
          </tr>
          <tr>
            <th>字段类型：</th>
            <td class="td2"><%=objChannelField.LoadFieldType(0, 0)%><span class="Validform_checktip"></span></td>
          </tr>
          <tr id="FieldType0">
            <th>关联属性分类：</th>
            <td class="td2"><%=GetAttrType("选择属性分类","AttrId",0,"")%><span class="Validform_checktip"></span></td>
          </tr>
          <tr id="FieldType1" style="display:none;">
            <th>下拉|多选|单选项：</th>
            <td class="td2"><textarea name="ListVal" id="ListVal" class="w350" datatype="*4-200" nullmsg="注:复选框、单选按钮、选择（列表菜单）的格式为：选项1=值1,选项2=值2,每个选项之间用半角英文逗号分割" errormsg="至少4个字符,最多200个字符!"></textarea>
              <span class="Validform_checktip">注:复选框、单选按钮、选择（列表菜单）的格式为：选项1=值1,选项2=值2,每个选项之间用半角英文逗号分割</span></td>
          </tr>
          <tr id="FieldType2">
            <th>前台字段值为空时显示：</th>
            <td class="td2"><input type="text" name="FieldNull" id="FieldNull" class="txtInput w350" autocomplete="off" datatype="*0-100" errormsg="最多100个字符!" />
              <span class="Validform_checktip"></span></td>
          </tr>
          <tr id="FieldType3">
            <th>前台字段值不为空时显示：</th>
            <td class="td2"><input type="text" name="FieldNotNull" id="FieldNotNull" class="txtInput w350" autocomplete="off" datatype="*0-100" errormsg="最多100个字符!" />
              <span class="Validform_checktip"></span></td>
          </tr>
          <tr>
            <th> 显示顺序： </th>
            <td class="td2"><input type="text" class="txtInput w100" name="Px" id="Px" autocomplete="off" value="100" datatype="px" nullmsg="排序必须填写" errormsg="只能是数字越小越排前,不可为：0,最多5位数" />
              <span class="Validform_checktip">*</span></td>
          </tr>
          <tr>
            <th></th>
            <td><input type="submit" class="btnSubmit" value="提交保存" />
              &nbsp;
              <input name="重置" type="reset" class="btnSubmit" value="重 置" /></td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</form>
<%
End Sub

Sub SaveMain()
    ChkSysAdminLevel "sys_channel", "add"
    '=====================================================================
    Dim Alias, FieldName, IsNotNull, FieldType, ListVal
    Dim ValidPattern, ValidTipMsg, ValidErrorMsg
    Dim FieldNull, FieldNotNull, Px, AttrId
    Alias = Trim(Easp.Post("Alias:s"))
    FieldName = Trim(Easp.Post("FieldName:s"))
    IsNotNull = Easp.Post("IsNotNull:n:0")
    ValidPattern = Trim(Easp.Post("ValidPattern"))
    ValidTipMsg = Trim(Easp.Post("ValidTipMsg"))
    ValidErrorMsg = Trim(Easp.Post("ValidErrorMsg"))
    FieldType = Easp.Post("FieldType:n:0")
    ListVal = Trim(Easp.Post("ListVal:s"))
    FieldNull = Trim(Easp.Post("FieldNull:s"))
    FieldNotNull = Trim(Easp.Post("FieldNotNull:s"))
    Px = Easp.Post("Px:n:0")
    AttrId = Easp.Post("AttrId:n:0")
    '=====================================================================
    If Easp.IsN(Alias) Then
        CmsAdmin.JscriptMsg "字段别名必须填写！", "back", "Error", "null"
    End If
    If Easp.IsN(FieldName) Then
        CmsAdmin.JscriptMsg "字段名称必须填写！", "back", "Error", "null"
    End If
    If CmsMain.IsFieldsText(TabName, FieldName) Then
        CmsAdmin.JscriptMsg "字段名称："& FieldName &",已经存在！", "back", "Error", "null"
    End If
    If FieldType = 0 Then
        CmsAdmin.JscriptMsg "字段名称必须填写！", "back", "Error", "null"
    Else
        If (FieldType = 4 Or FieldType = 5 Or FieldType = 6) Then
            If Easp.IsN(ListVal) Then
                CmsAdmin.JscriptMsg "分割值必须填写！", "back", "Error", "null"
            End If
        End If
    End If
    If Px = 0 Then
        CmsAdmin.JscriptMsg "显示顺序必须填写！", "back", "Error", "null"
    End If
    '=====================================================================
    Dim List, ResultVal
    Easp.Use "list"
    Set List = Easp.List.New
    List("ChannelId") = ChannelId
    List("Alias") = Alias
    List("FieldName") = FieldName
    List("IsNotNull") = IsNotNull
    List("ValidPattern") = ValidPattern
    List("ValidTipMsg") = ValidTipMsg
    List("ValidErrorMsg") = ValidErrorMsg
    List("FieldType") = FieldType
    List("ListVal") = ListVal
    List("FieldNull") = FieldNull
    List("FieldNotNull") = FieldNotNull
    List("Px") = Px
    List("AttrId") = AttrId
    List("IsSys") = 0
    List("AddTime") = Now()
    ResultVal = Easp.db.AR(TablePrefix & "ChannelField:id", List.Hash)
    Easp.C List
    If ResultVal <> 0 Then
        ' 创建字段
        objChannelField.CreateField ChannelId, TabName, FieldName, FieldType
        Set objChannelField = Nothing
        CmsAdmin.JscriptMsg "添加字段成功！", "Admin.Field.List.Asp?ChannelId="& ChannelId &"", "Success", "null"
    End If
    '=====================================================================
End Sub
%>
