<%
Dim objInfo
Set objInfo = New Cls_Info

Class Cls_Info

    Public Function LoadFieldInfo(ByVal ChannelId, ByVal RsInfo, ByVal AdminPath)
        If ChannelId = 0 Then
            Exit Function
        Else
            Dim strTemp, iSQL, iRs, FieldList
            FieldList = "Alias,FieldName,FieldType,ListVal,IsNotNull,AttrId,ValidPattern,ValidTipMsg,ValidErrorMsg"
            Set iRs = Easp.db.GR(TablePrefix & "ChannelField:" & FieldList, " ChannelId = "& ChannelId &" ", " Px Asc,id Desc ")
            If (iRs.EOF And iRs.BOF) Then
                Easp.C iRs
                Exit Function
            Else
                strTemp = ""
                Do While Not iRs.EOF
                    If LCase(TypeName(RsInfo)) = "recordset" Then
                        strTemp = strTemp & LoadFieldTypeHtml(iRs, RsInfo(Trim(iRs(1))), ChannelId, AdminPath)
                    Else
                        strTemp = strTemp & LoadFieldTypeHtml(iRs, "", ChannelId, AdminPath)
                    End If
                    iRs.MoveNext
                Loop
                Easp.C iRs
                LoadFieldInfo = strTemp
            End If
        End If
    End Function

    Public Function LoadFieldTypeHtml(ByVal Rs, ByVal FieldVal, ByVal ChannelId, ByVal AdminPath)
        Dim strTemp, iFieldType, AttrId, AttrTemp
        Dim IsNotNullTip, IsNotNullText
        AttrTemp = ""
        iFieldType = CmsFun.ChkNumEric(Rs("FieldType"))
        AttrId = CmsFun.ChkNumEric(Rs("AttrId"))
        If AttrId > 0 Then
            AttrTemp = GetAttrList("AttrName" & Easp.Rand(1111111111, 99999999), "选择" & Rs("Alias"), " ClassId = "& AttrId &" ", Rs("FieldName"), Rs("FieldName"))
        Else
            AttrTemp = ""
        End If
        If (Rs("IsNotNull") > 0 And Not Easp.IsN(Rs("ValidPattern"))) Then
            IsNotNullTip = Rs("ValidTipMsg")
            IsNotNullText = " datatype="""& Rs("ValidPattern") &""" nullmsg="""& Rs("ValidTipMsg") &""" errormsg="""& Rs("ValidErrorMsg") &""""
        Else
            IsNotNullTip = ""
            IsNotNullText = " maxlength=""150"""
        End If
        strTemp = "<tr>" & vbCrLf
        strTemp = strTemp & "  <th>"& Rs("Alias") &"：</th>" & vbCrLf
        strTemp = strTemp & "  <td class=""td2"">"
        Select Case iFieldType
            Case 1
                strTemp = strTemp & "<input type=""text"" name="""& Rs("FieldName") &""" id="""& Rs("FieldName") &""" class=""txtInput w350 left"" autocomplete=""off"""& IsNotNullText &" value="""& FieldVal &""" />"
                strTemp = strTemp & "<span class=""Validform_checktip"">"& IsNotNullTip &"</span>" & AttrTemp
            Case 2
                strTemp = strTemp & getUpLoadHtml(1, Rs("FieldName"), FieldVal, IsNotNullTip, ChannelId, AdminPath)
            Case 3
                strTemp = strTemp & getUpLoadHtml(2, Rs("FieldName"), FieldVal, IsNotNullTip, ChannelId, AdminPath)
            Case 4
                strTemp = strTemp & getUpLoadHtml(3, Rs("FieldName"), FieldVal, IsNotNullTip, ChannelId, AdminPath)
            Case 5
                strTemp = strTemp & getUpLoadHtml(4, Rs("FieldName"), FieldVal, IsNotNullTip, ChannelId, AdminPath)
            Case 6
                strTemp = strTemp & getUpLoadHtml(5, Rs("FieldName"), FieldVal, IsNotNullTip, ChannelId, AdminPath)
            Case 7
                strTemp = strTemp & "<input name="""& Rs("FieldName") &""" id="""& Rs("FieldName") &""" type=""text"" class=""txtInput w150"" autocomplete=""off"" datatype=""date1"" onclick=""WdatePicker();"" readonly=""readonly"" value="""& Easp.DateTime(FieldVal,"yyyy-mm-dd") &""" />"
                strTemp = strTemp & "<span class=""Validform_checktip"">"& IsNotNullTip &"</span>"
            Case 8
                strTemp = strTemp & getListBoxHtml(1, Rs("FieldName"), Rs("ListVal"), FieldVal)
                strTemp = strTemp & "<span class=""Validform_checktip"">"& IsNotNullTip &"</span>"
            Case 9
                strTemp = strTemp & getListBoxHtml(2, Rs("FieldName"), Rs("ListVal"), FieldVal)
                strTemp = strTemp & "<span class=""Validform_checktip"">"& IsNotNullTip &"</span>"
            Case 10
                strTemp = strTemp & getListBoxHtml(3, Rs("FieldName"), Rs("ListVal"), FieldVal)
                strTemp = strTemp & "<span class=""Validform_checktip"">"& IsNotNullTip &"</span>"
            Case 11
                strTemp = strTemp & "<textarea name="""& Rs("FieldName") &""" id="""& Rs("FieldName") &""" class=""big"">"& FieldVal &"</textarea>"
                strTemp = strTemp & "<span class=""Validform_checktip"">"& IsNotNullTip &"</span>"
            Case 12
                strTemp = strTemp & "<textarea name="""& Rs("FieldName") &""" id="""& Rs("FieldName") &""" class=""big"" style=""height:350px;width:99%;"">"& FieldVal &"</textarea>" & vbCrLf
                strTemp = strTemp & "<script>" & vbCrLf
                strTemp = strTemp & "var editor_"& Rs("FieldName") &";" & vbCrLf
                strTemp = strTemp & "$(function() {" & vbCrLf
                strTemp = strTemp & "    editor = LoadCmsEditor('"& AdminPath &"', '"& Rs("FieldName") &"', "& ChannelId &");" & vbCrLf
                strTemp = strTemp & "});" & vbCrLf
                strTemp = strTemp & "</script>"
        End Select
        strTemp = strTemp & "</td>" & vbCrLf
        strTemp = strTemp & "</tr>" & vbCrLf
        LoadFieldTypeHtml = strTemp
    End Function

    Private Function getUpLoadHtml(ByVal UpLoadVal, ByVal FieldName, ByVal FieldVal, ByVal IsNotNull, ByVal ChannelId, ByVal AdminPath)
        Dim strTemp
        strTemp = "<input type=""text"" name="""& FieldName &""" id="""& FieldName &""" data-img=""show"" class=""txtInput w350 left"" autocomplete=""off"""& IsNotNull &" value="""& FieldVal &""" />" & vbCrLf

        strTemp = strTemp & "<a href=""javascript:;"" class=""files"">" & vbCrLf
        strTemp = strTemp & "<input type=""file"" id=""FileUpload"& FieldName &""" name=""FileUpload"& FieldName &""" onchange=""Upload('"& AdminPath &"', 'UpFile', "& ChannelId &", "& UpLoadVal &", '"& FieldName &"');"" />" & vbCrLf
        strTemp = strTemp & "</a> <span class=""uploading"">正在上传，请稍候...</span>" & vbCrLf
        strTemp = strTemp & "<input type=""button"" class=""btnSearch"" value=""从已上传中选择"" onclick=""ShowWin('PicUrl', '从已上传中选择', '"& AdminPath &"Admin_File.Asp?action=sf&ChannelId="& ChannelId &"&ReturnId="& FieldName &"', SetDialog.PublicWidth, SetDialog.PublicHeight, false);"" />" & vbCrLf
        strTemp = strTemp & "<span class=""Validform_checktip""></span>"
        getUpLoadHtml = strTemp
    End Function

    Private Function getListBoxHtml(ByVal T, ByVal strName, ByVal strVal, ByVal Val)
        If Easp.IsN(strVal) Then
            Exit Function
        End If
        Dim strType, strHtml, strArray, i, ArrayName, ArrayVal, ArraySd
        strType = CmsFun.ChkNumEric(T)
        strArray = Split(strVal, ",")
        Select Case strType
            Case 1
                strHtml = ""
                For i = 0 To UBound(strArray)
                    ArrayName = ""
                    ArrayVal = ""
                    ArraySd = ""
                    If InStr(strArray(i), "=") > 0 Then
                        ArrayName = Split(strArray(i), "=")(0)
                        ArrayVal = Split(strArray(i), "=")(1)
                    Else
                        ArrayName = strArray(i)
                        ArrayVal = strArray(i)
                    End If
                    If Not Easp.IsN(Val) Then
                        If InStr("," & Val & ",", "," & ArrayVal & ",") > 0 Then
                            ArraySd = " checked=""checked"""
                        End If
                    End If
                    strHtml = strHtml & "<label><input type=""radio"" name="""& strName &""" value="""& ArrayVal &""""& ArraySd &" />"& ArrayName &"</label>" & vbCrLf
                Next
            Case 2
                strHtml = "<span>"
                For i = 0 To UBound(strArray)
                    ArrayName = ""
                    ArrayVal = ""
                    ArraySd = ""
                    If InStr(strArray(i), "=") > 0 Then
                        ArrayName = Split(strArray(i), "=")(0)
                        ArrayVal = Split(strArray(i), "=")(1)
                    Else
                        ArrayName = strArray(i)
                        ArrayVal = strArray(i)
                    End If
                    If Not Easp.IsN(Val) Then
                        If InStr("," & Val & ",", "," & ArrayVal & ",") > 0 Then
                            ArraySd = " checked=""checked"""
                        End If
                    End If
                    strHtml = strHtml & "<input type=""checkbox"" name="""& strName &""" id=""item_"& i & strName &""" value="""& ArrayVal &""""& ArraySd &" /><label for=""item_"& i & strName &""">"& ArrayName &"</label>" & vbCrLf
                Next
                strHtml = strHtml & "</span>" & vbCrLf
            Case 3
                strHtml = "<select name="""& strName &""" css=""select2"">" & vbCrLf
                For i = 0 To UBound(strArray)
                    ArrayName = ""
                    ArrayVal = ""
                    ArraySd = ""
                    If InStr(strArray(i), "=") > 0 Then
                        ArrayName = Split(strArray(i), "=")(0)
                        ArrayVal = Split(strArray(i), "=")(1)
                    Else
                        ArrayName = strArray(i)
                        ArrayVal = strArray(i)
                    End If
                    If Not Easp.IsN(Val) Then
                        If Trim(Val) = Trim(ArrayVal) Then
                            ArraySd = " selected=""selected"""
                        End If
                    End If
                    strHtml = strHtml & "<option value="""& ArrayVal &""""& ArraySd &">"& ArrayName &"</option>" & vbCrLf
                Next
                strHtml = strHtml & "</select>" & vbCrLf
        End Select
        getListBoxHtml = strHtml
    End Function

    Public Sub GetFieldVal(ByVal ChannelId, ByVal ListInfo)
        Dim oRs, FormFieldName, FieldType
        Set oRs = Easp.db.GR(TablePrefix & "ChannelField:Alias,FieldName,FieldType,IsNotNull", " ChannelId = "& ChannelId &" ", "")
        If Not oRs.EOF Then
            Do While Not oRs.EOF
                FormFieldName = ""
                FieldType = CmsFun.ChkNumEric(oRs("FieldType"))
                Select Case FieldType
                    Case 5
                        FormFieldName = Replace(Easp.Post(""& oRs("FieldName") &":s") & "", " ", "")
                    Case Else
                        FormFieldName = Easp.Post(""& oRs("FieldName") &":s")
                End Select
                If CmsFun.ChkNumEric(oRs("IsNotNull")) = 1 Then
                    If Easp.IsN(FormFieldName) Then
                        CmsAdmin.JscriptMsg ""& oRs("Alias") &"不能为空！", "back", "Error", "null"
                    End If
                End If
                ListInfo(Trim(oRs("FieldName"))) = FormFieldName
                oRs.MoveNext
            Loop
        End If
        Easp.db.C oRs
    End Sub

    '========================== 添加批量上传图片

    Public Sub SwfUpLoadAdd(ByVal ChannelId, ByVal DataId)
        Dim Val, ArrayImages, ImagesList, ii, ArrayTemp
        Val = Trim(Easp.Post("UpImagesListVal:s"))
        If Not Easp.IsN(Val) Then
            ArrayImages = Split(Val, "㊣")
            For ii = 0 To UBound(ArrayImages)
                ArrayTemp = Split(ArrayImages(ii), "#$@")
                If Not Easp.IsN(ArrayTemp(0)) Then
                    Easp.Use "list"
                    Set ImagesList = Easp.List.New
                    ImagesList("ChannelId") = ChannelId
                    ImagesList("DataId") = DataId
                    ImagesList("Img") = Trim(ArrayTemp(0))
                    ImagesList("Imgs") = Trim(ArrayTemp(1))
                    ImagesList("Info") = Trim(ArrayTemp(2))
                    ImagesList("Px") = Trim(ArrayTemp(3))
                    ImagesList("FileType") = LCase(Replace(Easp.Fso.ExtOf(Trim(ArrayTemp(0))) & "", ".", ""))
                    ImagesList("AddTime") = Now()
                    Easp.db.AR TablePrefix & "UpLoad", ImagesList.Hash
                    Easp.C ImagesList
                End If
            Next
        End If
    End Sub

    '========================== 批量上传图片列表

    Public Function GetPicList(ByVal ChannelId, ByVal DataId, ByVal DataImageUrl)
        Dim strHtml, iRs, FieldList
        FieldList = "ChannelId,DataId,Img,Imgs,Info,Px"
        If (CmsFun.ChkNumEric(ChannelId) = 0 Or CmsFun.ChkNumEric(DataId) = 0) Then
            Exit Function
        End If
        strHtml = ""
        Set iRs = Easp.db.GR(TablePrefix & "UpLoad:" & FieldList, " ChannelId = "& ChannelId &" And DataId = "& DataId &" ", " Px Asc,Id Asc ")
        If Not Easp.IsN(iRs) Then
            Do While Not iRs.EOF
                strHtml = strHtml & "<li>" & vbCrLf
                strHtml = strHtml & "<input type=""hidden"" name=""BatchImg"" value=""" & iRs("Img") & """ />"
                strHtml = strHtml & "<input type=""hidden"" name=""BatchImgs"" value=""" & iRs("Imgs") & """ />"
                strHtml = strHtml & "<input type=""hidden"" name=""BatchInfo"" value=""" & iRs("Info") & """ />"
                strHtml = strHtml & "<input type=""hidden"" name=""BatchPx"" value=""" & CmsFun.ChkNumEric(iRs("Px")) & """ />"
                strHtml = strHtml & "<div onclick=""focus_img(this);"" class=""img_box"
                If Not Easp.IsN(DataImageUrl) Then
                    If Trim(iRs("Img")) = Trim(DataImageUrl) Then
                        strHtml = strHtml & " current"
                    End If
                End If
                strHtml = strHtml & """>"
                strHtml = strHtml & "<img bigsrc=""" & iRs("Img") & """ src=""" & iRs("Imgs") & """ class=""imgpreview"" />"
                strHtml = strHtml & "<span class=""remark""><i>"& Easp.IIf(Not Easp.IsN(iRs("Info")), iRs("Info"), "暂无描述...") &"</i></span>"
                strHtml = strHtml & "</div>"
                strHtml = strHtml & "<a onclick=""show_remark(this);"" href=""javascript:;"">描述</a><a onclick=""del_img(this);"" href=""javascript:;"">删除</a>"
                strHtml = strHtml & "</li>" & vbCrLf
                iRs.MoveNext
            Loop
        End If
        Easp.C iRs
        GetPicList = strHtml
    End Function

    '========================== 删除批量上传图片

    Public Sub UpPicDel(ByVal ChannelId, ByVal DataId)
        Dim TempWhere
        If DataId = 0 Then
            TempWhere = "DataId = 0"
        Else
            TempWhere = "DataId = "& DataId &" Or DataId = 0"
        End If
        Easp.db.DR TablePrefix & "UpLoad", " ChannelId = "& ChannelId &" And ("& TempWhere &") "
    End Sub

    Public Function GetAttrList(ByVal ListName, ByVal TitleName, ByVal TempWhere, ByVal JsId, ByVal Val)
        Dim strTemp, oRs, arrList, i, IfSelect
        strTemp = "<select name="""& ListName &""" id="""& ListName &""" class=""select2"" onChange=""InnerVal('"& JsId &"',this.value);"">" & vbCrLf
        strTemp = strTemp & "<option value=""0"">"& TitleName &"</option>" & vbCrLf
        Set oRs = Easp.db.GR(TablePrefix & "Attr:Id,AttrName", TempWhere, " Px Asc,id Desc ")
        If Not Easp.IsN(oRs) Then
            arrList = oRs.GetRows()
        End If
        Easp.C oRs
        If IsArray(arrList) Then
            For i = 0 To UBound(arrList, 2)
                IfSelect = ""
                IfSelect = Easp.IIf(Trim(arrList(1, i)) = Trim(Val), " selected=""selected""", "")
                strTemp = strTemp & "<option value="""& arrList(1, i) &""""& IfSelect &">"& arrList(1, i) &"</option>" & vbCrLf
            Next
        End If
        strTemp = strTemp & "</select>" & vbCrLf
        GetAttrList = strTemp
    End Function

    Public Function GetTopicList(ByVal ChannelId, ByVal Val)
        Dim strTemp, oRs, arrList, i, IfSelect
        strTemp = "<select name=""TopicId"" id=""TopicId"" class=""select2"" datatype=""*"">" & vbCrLf
        strTemp = strTemp & "<option value=""0"">选择专题</option>" & vbCrLf

        Set oRs = Easp.db.GR(TablePrefix & "Topic:Id,Title", " ChannelId = "& ChannelId &" ", " Px Asc,id Desc ")
        If Not Easp.IsN(oRs) Then
            arrList = oRs.GetRows()
        End If
        Easp.C oRs
        If IsArray(arrList) Then
            For i = 0 To UBound(arrList, 2)
                IfSelect = ""
                IfSelect = Easp.IIf(Trim(arrList(0, i)) = Trim(Val), " selected=""selected""", "")
                strTemp = strTemp & "<option value="""& arrList(0, i) &""""& IfSelect &">"& arrList(1, i) &"</option>" & vbCrLf
            Next
        End If
        strTemp = strTemp & "</select>" & vbCrLf
        GetTopicList = strTemp
    End Function

    Public Sub UpdateTag(ByVal ChannelId, ByVal TabName, ByVal Str)
        If Not Easp.IsN(Str) Then
            Str = Trim(Str)
            Str = Easp.RegReplace(Str, "(\s+)", ",")
            Dim taglist, i, tag, oRs, CountNum
            taglist = Split(Str, ",")
            If UBound(taglist) < 0 Then
                Exit Sub
            End If
            For i = 0 To UBound(taglist)
                tag = Easp.Safe(Trim(taglist(i)), "s")
                Set oRs = Easp.db.GR(TablePrefix & "Tags:Id:1", " ChannelId = "& ChannelId &" And Name = '"& tag &"' ", "")
                If Easp.IsN(oRs) Then
                    Easp.db.AR TablePrefix & "Tags", Array("ChannelId:" & ChannelId, "Name:" & tag, "Tag:" & CmsFun.GetTag(tag), "Counts:" & 1)
                Else
                    CountNum = CmsFun.ChkNumEric(Easp.db.RT(TabName, " ','+Tag+',' Like '%," & tag & ",%' ", "Count(Id)"))
                    Easp.db.UR TablePrefix & "Tags", " ChannelId = "& ChannelId &" And Name = '"& tag &"' ", Array("Counts:" & CountNum)
                End If
                Easp.C oRs
            Next
        End If
    End Sub

End Class
%>