<!--#include file="../../Inc/Cls_Main.Asp"-->
<!--#include file="../inc/Cls_Admin.Asp"-->
<%
Dim Action
Action = Easp.Get("action:s")
Select Case Action
    Case "loadmenu"
        Call GetMenu()
    Case "checktitle"
        Call CheckTitle()
        '===================== bbs
    Case "bbsusername"
        Call CheckUserName()
    Case "bbsusernickname"
        Call CheckUserNickName()
    Case "bbsuseremail"
        Call CheckUserEmail()
        '==========================
    Case "loadplugins"
        Call GetPlugins()
    Case "clearcache"
        Call ClearCache()
    Case "updatetype"
        Call UpdateType()
    Case "zjjcms"
        Call GetZjjCmsInfo()
End Select

Sub CheckTitle()
    Dim ChannelId, TabName
    ChannelId = Easp.Get("ChannelId:n:0")
    If ChannelId = 0 Then
        CmsFun.ShowJsonMsg 0, ""
    End If
    ' 读取频道信息
    Dim ArrayChannel
    ArrayChannel = GetCaCheChannelInfo("Channel", ChannelId, ChannelField)
    If Easp.IsN(ArrayChannel) Then
        CmsFun.ShowJsonMsg 0, ""
    Else
        TabName = ArrayChannel(2)
    End If
    Dim oRs, Title, Id
    Title = Easp.UnEscape(Trim(Easp.Get("Title:s")))
    Id = Easp.Get("Id:n:0")
    If Not Easp.IsN(Title) Then
        Set oRs = Easp.db.GR(TabName & ":Id:1", " Title = '"& Title &"' " & Easp.IIf(Id > 0, " And Id <> "& Id & " ", "") & " ", "")
        If Easp.IsN(oRs) Then
            CmsFun.ShowJsonMsg 0, ""
        Else
            CmsFun.ShowJsonMsg 1, ""
        End If
        Easp.C oRs
    Else
        CmsFun.ShowJsonMsg 0, ""
    End If
End Sub

Sub CheckUserName()
    Dim param, Id
    param = Trim(Easp.Post("param:s"))
    Id = Easp.Get("id:n:0")
    CheckBBSInfo "uName", param, Id, "帐号"
End Sub

Sub CheckUserNickName()
    Dim param, Id
    param = Trim(Easp.Post("param:s"))
    Id = Easp.Get("id:n:0")
    CheckBBSInfo "NickName", param, Id, "昵称"
End Sub

Sub CheckUserEmail()
    Dim param, Id
    param = Trim(Easp.Post("param:s"))
    Id = Easp.Get("id:n:0")
    CheckBBSInfo "Eamil", param, Id, "邮箱"
End Sub

Sub CheckBBSInfo(ByVal FieldName, ByVal Val, ByVal IdVal, ByVal Tip)
    Dim oRs
    Set oRs = Easp.db.GR(TablePrefix & "BBS_User:" & FieldName & ":1", " "& FieldName &" = '"& Val &"'"& Easp.IIf(IdVal > 0, " And Id <> "& IdVal &" ", "") &" ", "")
    If Easp.IsN(oRs) Then
        Easp.WE "{""info"": """& Tip &"验证通过"",""status"": ""y""}"
    Else
        Easp.WE "{""info"": """& Tip &"验证失败,"& Tip &"已存在."",""status"": ""n""}"
    End If
    Easp.C oRs
End Sub


Sub GetMenu()
    Dim ResultJson, oRs, i, arrList, TempJson
    Set oRs = Easp.db.GR(TablePrefix & "Channel:Id,ChannelName,BriefName,ModelId,IsShow", "", " Px Asc,id Desc ")
    If Not Easp.IsN(oRs) Then
        arrList = oRs.GetRows()
    Else
        Easp.WE "[]"
    End If
    Easp.C oRs
    If IsArray(arrList) Then
        Easp.Use "json"
        Set ResultJson = Easp.Json.New(1)
        For i = 0 To UBound(arrList, 2)
            ResultJson(Null) = Easp.Json.New(0)
            ResultJson(Null)("isexpand") = "false"
            ResultJson(Null)("text") = arrList(1, i) &"("& Easp.IIf(arrList(4, i) = 0, CmsFun.ShowColor("不显示", "red"), "显示") &")"
            ResultJson(Null)("children") = Easp.Json.New(1)
            ResultJson(Null)("children")(Null) = Easp.Json.New(0)
            ResultJson(Null)("children")(Null)("url") = "info/Admin.Index.asp?ChannelId="& arrList(0, i)
            ResultJson(Null)("children")(Null)("text") = arrList(2, i) &"管理"
            ResultJson(Null)("children")(Null) = Easp.Json.New(0)
            ResultJson(Null)("children")(Null)("url") = "type/Admin.Index.asp?ChannelId="& arrList(0, i)
            ResultJson(Null)("children")(Null)("text") = arrList(2, i) &"分类"
            ResultJson(Null)("children")(Null) = Easp.Json.New(0)
            ResultJson(Null)("children")(Null)("url") = "topic/Admin.Index.asp?ChannelId="& arrList(0, i)
            ResultJson(Null)("children")(Null)("text") = "专题管理"
            ResultJson(Null)("children")(Null) = Easp.Json.New(0)
            ResultJson(Null)("children")(Null)("url") = "comment/Admin.Index.asp?ChannelId="& arrList(0, i)
            ResultJson(Null)("children")(Null)("text") = "评论管理"
            ResultJson(Null)("children")(Null) = Easp.Json.New(0)
            ResultJson(Null)("children")(Null)("url") = "Admin_File.asp?ChannelId="& arrList(0, i)
            ResultJson(Null)("children")(Null)("text") = "上传文件管理"
        Next
        TempJson = ResultJson.jsString
        Set ResultJson = Nothing
        Easp.WE TempJson
    End If
End Sub

Sub GetPlugins()
    Dim OtherFile, TempJson
    OtherFile = "otherlist.xml"
    If Easp.Fso.IsFile(OtherFile) Then
        Dim ResultJson, objXml, Root, x, Childrens, y
        Easp.Use "Xml"
        Easp.Use "Json"
        Set objXml = Easp.Xml.New
        '加载文档
        objXml.Open OtherFile
        '获取集合对象
        Set Root = objXml.Select("//list")
        'json
        Set ResultJson = Easp.Json.New(1)
        For x = 0 To Root.Length -1
            ResultJson(Null) = Easp.Json.New(0)
            ResultJson(Null)("text") = Root(x).Select("text").Text
            ResultJson(Null)("url") = Root(x).Select("url").Text
            ResultJson(Null)("isexpand") = Root(x).Select("isexpand").Text
            Set Childrens = Root(x).Select("children")
            If Childrens.Length>0 Then
                ResultJson(Null)("children") = Easp.Json.New(1)
                For y = 0 To Childrens.Length -1
                    ResultJson(Null)("children")(Null) = Easp.Json.New(0)
                    ResultJson(Null)("children")(Null)("text") = Childrens(y).Select("text").Text
                    ResultJson(Null)("children")(Null)("url") = Childrens(y).Select("url").Text
                Next
            End If
        Next
        TempJson = ResultJson.jsString
        Set ResultJson = Nothing
        Set objXml = Nothing
        Easp.WE TempJson
    Else
        TempJson = "[]"
    End If
    Easp.WE TempJson
End Sub

Sub UpdateType()
    Dim oRs, DataNum
    Set oRs = Easp.db.GR(TablePrefix & "Type:Id,ChannelId,ChildIdAll", "", "")
    If Easp.IsN(oRs) Then
        CmsFun.ShowJsonMsg 0, ""
    Else
        Do While Not oRs.EOF
            ' 读取频道信息
            Dim ArrayChannel, TabName
            ArrayChannel = GetCaCheChannelInfo("Channel", oRs("ChannelId"), ChannelField)
            If Easp.IsN(ArrayChannel) Then
                CmsFun.ShowJsonMsg 0, ""
            Else
                TabName = ArrayChannel(2)
            End If
            DataNum = CmsFun.ChkNumEric(Easp.db.RT(TabName, " ClassId in("& oRs("ChildIdAll") &") ", "Count(0)"))
            Easp.db.UR TablePrefix & "Type", " Id = "& oRs("Id") &" ", Array("DataNum:" & DataNum)
            oRs.MoveNext
        Loop
    End If
    Easp.C oRs
    CmsFun.ShowJsonMsg 1, ""
End Sub

Sub ClearCache()
    Easp.Use "Cache"
    Easp.Use "Fso"
    Easp.Cache.ClearAll()
    If Easp.Fso.IsFolder(SiteCaChePath) Then
        Easp.Fso.DelFile SiteCaChePath & "*"
    End If
    CmsFun.ShowJsonMsg 1, ""
End Sub

Sub GetZjjCmsInfo()
    Dim Result, UpdateUrl
    UpdateUrl = "http://www.zjjxp.com/updatecms/asp/qy/index.html"
    Easp.http.CharSet = Easp.CharSet
    Result = Easp.http.Get(UpdateUrl)
    Easp.W Result
End Sub
%>