<!--#include file="../../Inc/Cls_Main.Asp"-->
<!--#include file="../inc/Cls_Admin.Asp"-->
<!--#include file="../inc/Cls_MapPath.Asp"-->
<!--#include file="../inc/Cls_FreeField.Asp"-->
<!--#include file="../Admin_Check.Asp"-->
<%
Dim CmsAdmin, ToUrl
ToUrl = CmsFun.LoadToUrl()
'=============================================================================
Set CmsAdmin = New Cls_Admin
CmsAdmin.SetAdminTitle = CmsSiteName
CmsAdmin.SetBodyCssName = "mainbody"
CmsAdmin.SetAdminPath = CmsAdminMapPath
CmsAdmin.LoadHead()
'=============================================================================
Dim Action, ChannelId
ChannelId = Easp.Get("ChannelId:n:0")
If ChannelId = 0 Then
    CmsAdmin.JscriptMsg "参数错误！", "back", "Error", "null"
End If
'=============================================================================
Action = Easp.Get("action")
Select Case Action
    Case "pageload"
        Call PageLoad()
    Case "px"
        Call Px()
    Case "delall"
        Call DelAll()
    Case Else
        Call PageLoad()
End Select
CmsAdmin.LoadFooter()
Set CmsAdmin = Nothing

Sub PageLoad()
    ChkSysAdminLevel "sys_free", "show"
    '=====================================================================
%>
<div class="navigation"><a href="Admin.Form.List.Asp" class="back">自定义表单管理</a> 控制面板 &gt; 自定义字段管理</div>
<div class="tools_box">
  <div class="tools_bar">
    <ul>
      <li><a href="Admin.Field.Add.Asp?ChannelId=<%=ChannelId%>" class="tools_btn"><span><b class="add">添加字段</b></span></a></li>
      <li><a href="javascript:GetSubmit('myform','?action=px&ChannelId=<%=ChannelId%>')" class="tools_btn"><span><b class="send">保存排序</b></span></a></li>
      <li><a href="javascript:void(0);" onclick="checkAll(this);" class="tools_btn"><span><b class="all">全选</b></span></a></li>
      <li><a href="javascript:void(0);" onclick="return ExePostBack('确定要批量删除吗？','myform','?action=delall&ChannelId=<%=ChannelId%>');" class="tools_btn"><span><b class="delete">批量删除</b></span></a></li>
      <li><a href="Admin.Field.List.Asp" class="tools_btn"><span><b class="refresh">刷新列表</b></span></a></li>
    </ul>
  </div>
</div>
<form id="myform" action="?action=px&ChannelId=<%=ChannelId%>" method="post">
  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="msgtable">
    <tr>
      <th width="5%">选择</th>
      <th width="30%" align="left">字段别名</th>
      <th width="20%" align="left">字段名称</th>
      <th width="15%">字段类型</th>
      <th width="10%">是否系统</th>
      <th width="10%">排序</th>
      <th width="10%">操作</th>
    </tr>
    <%
    Dim ShowPage, oRs, PageNum, ArrayList, i, oSQL
    ShowPage = ""
    PageNum = 20
    '============================ page
    Easp.db.PageSize = PageNum
    Easp.db.SetPager "default", "<span class=""disableds"">总记录数:{recordcount},每页:{pagesize},页次:{pageindex}/{pagecount}</span> {first}{prev}{list}{next}{last}{jump}", Array("first:首　页", "last:尾　页", "prev:上一页", "next:下一页", "list:*")
    Set oRs = Easp.db.GPR("0", Array(TablePrefix & "FreeField:Id,ChannelId,Alias,FieldName,FieldType,IsSys,Px", " ChannelId = "& ChannelId &" ", " Px Asc,id Desc ", " id "))
    If Easp.IsN(oRs) Then
        Easp.C(oRs)
    Else
        ShowPage = Easp.db.GetPager("default")
        ArrayList = oRs.GetRows(PageNum)
    End If
    Easp.C oRs
    If IsArray(ArrayList) Then
        For i = 0 To UBound(ArrayList, 2)
    %>
    <tr align="center">
      <td><input type="checkbox" name="chkId" value="<%=ArrayList(0,i)%>" /></td>
      <td align="left"><%=ArrayList(2,i)%></td>
      <td align="left"><%=ArrayList(3,i)%></td>
      <td><%=objFreeField.GetFieldType(ArrayList(4,i))%></td>
      <td><%=Easp.IIF(CmsFun.ChkNumEric(ArrayList(5,i)) = 1,"是",CmsFun.ShowColor("否","blue"))%></td>
      <td><input type="hidden" name="hidId" value="<%=ArrayList(0,i)%>" />
        <input type="text" class="txtInput2 w50" name="Px" value="<%=ArrayList(6,i)%>" maxlength="5" onfocus="ChkNumEric(this)" autocomplete="off" /></td>
      <td><a href="Admin.Field.Edit.Asp?ChannelId=<%=ChannelId%>&id=<%=ArrayList(0,i)%>">编辑</a></td>
    </tr>
    <%
        Next
    End If
    %>
  </table>
  <div class="line15"> </div>
  <div class="page_box">
    <div class="flickr right"><%=ShowPage%></div>
  </div>
</form>
<%
End Sub

Sub Px()
    ChkSysAdminLevel "sys_free", "edit"
    '=====================================================================
    Dim hidId, Px, i, spHidId, spPx
    hidId = Replace(Easp.Post("hidId:s"), ", ", ",")
    Px = Replace(Easp.Post("Px:s"), ", ", ",")
    If Easp.IsN(hidId) Then
        CmsAdmin.JscriptMsg "对不起，请选中您要操作的记录！", "back", "Error", "null"
    End If
    spHidId = Split(hidId, ",")
    spPx = Split(Px, ",")
    For i = 0 To UBound(spHidId)
        Easp.db.UR TablePrefix & "FreeField", " ChannelId = "& ChannelId &" And Id = "& spHidId(i) &" ", Array("px:" & spPx(i))
    Next
    CmsAdmin.JscriptMsg "批量排序成功！", ToUrl, "Success", "null"
End Sub

Sub DelAll()
    ChkSysAdminLevel "sys_free", "del"
    '=====================================================================
    Dim chkId, ResultVal, spChkId, i, ResultMsg, ArrayField, TabName
    chkId = Easp.Post("chkId:s")
    If Easp.IsN(chkId) Then
        CmsAdmin.JscriptMsg "对不起，请选中您要操作的记录！", "back", "Error", "null"
    Else
        spChkId = Split(chkId, ",")
        For i = 0 To UBound(spChkId)
            ArrayField = ""
            ArrayField = Easp.db.RT(TablePrefix & "FreeField", " ChannelId = "& ChannelId &" And IsSys = 0 And Id = "& spChkId(i) &" ", "FieldName,ChannelId")
            If Easp.Has(ArrayField) Then
                If CmsFun.ChkNumEric(ArrayField(1)) > 0 Then
                    TabName = Easp.db.RT(TablePrefix & "FreeForm", " Id = "& spChkId(i) &" ", "FormTableName")
                    If CmsMain.IsFieldsText(TabName, ArrayField(0)) Then
                        ResultMsg = CmsMain.DelColumn(TabName, ArrayField(0))
                    End If
                End If
            End If
        Next
        ResultVal = Easp.db.DR(TablePrefix & "FreeField", " IsSys = 0 And Id in("& chkId &")")
        If ResultVal <> 0 Then
            CmsAdmin.JscriptMsg "批量删除成功！", ToUrl, "Success", "null"
        End If
    End If
End Sub
%>
