<%
Dim objFreeField
Set objFreeField = New Cls_FreeField

Class Cls_FreeField

    Public Function GetFieldInfo(ByVal ChannelId, ByVal objRs)
        If ChannelId = 0 Then
            Exit Function
        Else
            Dim strTemp, iSQL, iRs
            Set iRs = Easp.db.GR(TablePrefix & "FreeField", " 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(objRs)) = "recordset" Then
                        strTemp = strTemp & GetFieldTypeHtml(iRs, ChannelId, objRs(Trim(iRs("FieldName"))))
                    Else
                        strTemp = strTemp & GetFieldTypeHtml(iRs, ChannelId, "")
                    End If
                    iRs.MoveNext
                Loop
                Easp.C iRs
                GetFieldInfo = strTemp
            End If
        End If
    End Function

    Public Function GetFieldTypeHtml(ByVal Rs, ByVal ChannelId, ByVal FieldVal)
        Dim strTemp, iFieldType
        iFieldType = CmsFun.ChkNumEric(Rs("FieldType"))
        strTemp = ""
        strTemp = strTemp & "<tr>" & vbCrLf
        strTemp = strTemp & "<th> "& Rs("Alias") &"： </th>" & vbCrLf
        strTemp = strTemp & "<td>"& Rs("FieldVal") &"</td>" & vbCrLf
        strTemp = strTemp & "</tr>" & vbCrLf
        GetFieldTypeHtml = strTemp & vbCrLf
    End Function

    Public Function LoadFieldInfo(ByVal ChannelId)
        If ChannelId = 0 Then
            Exit Function
        Else
            Dim strTemp, iSQL, iRs
            Set iRs = Easp.db.GR(TablePrefix & "FreeField", " 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
                    strTemp = strTemp & LoadFieldTypeHtml(iRs, ChannelId)
                    iRs.MoveNext
                Loop
                Easp.C iRs
                LoadFieldInfo = strTemp
            End If
        End If
    End Function

    Public Function LoadFieldTypeHtml(ByVal Rs, ByVal ChannelId)
        Dim strTemp, iFieldType
        iFieldType = CmsFun.ChkNumEric(Rs("FieldType"))
        strTemp = Rs("Alias") & "："
        Select Case iFieldType
            Case 1
                strTemp = strTemp & "<input type=""text"" name="""& Rs("FieldName") &""" id="""& Rs("FieldName") &""" autocomplete=""off"" />"
            Case 2
                strTemp = strTemp & "<input name="""& Rs("FieldName") &""" id="""& Rs("FieldName") &""" type=""text"" autocomplete=""off"" onclick=""WdatePicker();"" readonly=""readonly""  />"
            Case 3
                strTemp = strTemp & getListBoxHtml(1, Rs("FieldName"), Rs("ListVal"))
            Case 4
                strTemp = strTemp & getListBoxHtml(2, Rs("FieldName"), Rs("ListVal"))
            Case 5

                strTemp = strTemp & getListBoxHtml(3, Rs("FieldName"), Rs("ListVal"))
            Case 6
                strTemp = strTemp & "<textarea name="""& Rs("FieldName") &""" id="""& Rs("FieldName") &"""></textarea>"
        End Select
        LoadFieldTypeHtml = strTemp & vbCrLf
    End Function

    Public Function getListBoxHtml(ByVal T, ByVal strName, ByVal strVal)
        If Easp.IsN(strVal) Then
            Exit Function
        End If
        Dim strType, strHtml, strArray, i, ArrayName, ArrayVal
        strType = CmsFun.ChkNumEric(T)
        strArray = Split(strVal, ",")
        Select Case strType
            Case 1
                strHtml = ""
                For i = 0 To UBound(strArray)
                    ArrayName = ""
                    ArrayVal = ""
                    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
                    strHtml = strHtml & "<label><input type=""radio"" name="""& strName &""" value="""& ArrayVal &""" />"& ArrayName &"</label>" & vbCrLf
                Next
            Case 2
                strHtml = "<span>"
                For i = 0 To UBound(strArray)
                    ArrayName = ""
                    ArrayVal = ""
                    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
                    strHtml = strHtml & "<input type=""checkbox"" name="""& strName &""" id=""item_"& i & strName &""" value="""& ArrayVal &""" /><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 = ""
                    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
                    strHtml = strHtml & "<option value="""& ArrayVal &""">"& ArrayName &"</option>" & vbCrLf
                Next
                strHtml = strHtml & "</select>" & vbCrLf
        End Select
        getListBoxHtml = strHtml
    End Function

    Public Function LoadFieldType(ByVal Val, ByVal IsDisabled)
        Dim StrTemp, ii, arrTemp, arrTempSp
        arrTemp = "选择类型|单行文本|日期控件|单选项|多选项|下拉框|多行文本"
        StrTemp = "<select name=""FieldType"" id=""FieldType"" class=""select2"" onChange=""ShowType(this.value);"""& Easp.IIf(IsDisabled = 1, " disabled=""disabled""", "") &">" & vbCrLf
        arrTempSp = Split(arrTemp, "|")
        For ii = 0 To UBound(arrTempSp)
            StrTemp = StrTemp & "<option value="""& ii &""""& Easp.IIf(Trim(Val) = Trim(ii), " selected=""selected""", "") &">"& arrTempSp(ii) &"</option>" & vbCrLf
        Next
        StrTemp = StrTemp & "</select>" & vbCrLf
        LoadFieldType = StrTemp
    End Function

    Public Function GetFieldType(ByVal Val)
        Dim StrTemp, ii, arrTemp, arrTempSp
        arrTemp = "选择类型|单行文本|日期控件|单选项|多选项|下拉框|多行文本"
        arrTempSp = Split(arrTemp, "|")
        For ii = 0 To UBound(arrTempSp)
            If Val = ii Then
                StrTemp = arrTempSp(ii)
            End If
        Next
        GetFieldType = StrTemp
    End Function

    Public Function CreateField(ByVal ChannelId, ByVal TableName, ByVal FieldName, ByVal FieldType)
        If (CmsFun.ChkNumEric(ChannelId) = 0 Or Easp.IsN(TableName) Or Easp.IsN(FieldName) Or CmsFun.ChkNumEric(FieldType) = 0) Then
            Exit Function
        Else
            Dim StrFieldType
            StrFieldType = CmsFun.ChkNumEric(FieldType)
            Select Case StrFieldType
                Case 1, 2
                    CmsMain.AddColumn TableName, FieldName, " nvarchar(255) Null"
                Case Else
                    CmsMain.AddColumn TableName, FieldName, " text Null"
            End Select
        End If
    End Function

End Class
%>