<!--#include file="../../../inc/cms_admin.asp" -->
<%
dim customID,custom,customname,LID,customType,customClass,customOptions,customValues,customOrder,customOnOff,customdesc,customplace
dim sql,table,col,colval,idval,id,wherestr,dbtable

dim act : act=getForm("act","get")
dim stype : stype=getForm("stype","get")
dim postion : postion=getForm("postion","get")
table=getForm("table","both")
col=getForm("col","both")
colval=getForm("colval","both")
idval=getForm("idval","both")
CustomID=getForm("CustomID","both")

Select case act		
	case "getcity"		:	getcity
	case "setCustom"	:	dbconn("update  [dbpre]Content_Custom set CustomOnOff="&colval&"  where  CustomID="&CustomID&"")
	case "edit"			:	editCustom
	case "add"			: 	addtCustom
	case "del"			:	delcustom
	case "saveid"	:	saveid	
End Select

Sub saveid
	dim colid		:	colid=getForm("colid","both")
	dim colname		:	colname=getForm("colname","both")
	dim colval		:	colval=getForm("colval","both")
	dim sql1 		:	sql1="update [dbpre]Content_Custom Set "&colname&"='"&colval&"' Where CustomID="&colid
	dim sql2 		:	sql2="update [dbpre]Content_Custom Set "&colname&"="&colval&" Where CustomID="&colid	
	dbconn(sql1)	:	if err then dbconn(sql2)
End Sub

sub delcustom
	customType=dbselect("[dbpre]Content_Custom","customType","Custom='"&idval&"'")
	if customType="gbook" or customType="brand" or customType="about" then
		 dbconn("ALTER TABLE [dbpre]"&customType&" drop column "&idval&"")
	else
		 dbconn("ALTER TABLE [dbpre]Content drop column "&idval&"")
	end if
	dbconn("delete from [dbpre]Content_Custom  where Custom = '"&idval&"'")
end sub

Sub addtCustom
	CustomName=getForm("CustomName","post")
	Custom="k"&getForm("Custom","post")
	 if iscolin("[dbpre]content",Custom) then back "参数已经存在,请修改!"
	 if dbcount("[dbpre]content_custom","Custom='"&Custom&"'")>0 then back "参数已经存在,请修改!"	
	CustomClass=getForm("CustomClass","post")
	customOptions=ReplaceStr(getForm("customOptions","post"),"，",",")
	customValues=ReplaceStr(getForm("customValues","post"),"，",",")
	customType=getForm("customType","post")	
	if customType="" then  back "参数类型未选"
	CustomOnOff=getcheck(getForm("CustomOnOff","post"))
	CustomOrder=getForm("CustomOrder","post")	
	Customdesc=getForm("Customdesc","post")
	customplace=getForm("customplace","post")	
	LID=zset.lid	
	 '0 文本,1 数字,2 备注, 3 编辑器,4 单选，5 多选，6 图片，7 文件，10 时间
	if ifstrin("brand,about,gbook",customType)  then
		dbtable="[dbpre]"&customType
	else
		dbtable="[dbpre]Content"
	end if
Select Case CInt(CustomClass)
	Case 1
	dbconn("ALTER TABLE "&dbtable&" ADD "&Custom&" int null")
	dbconn("update "&dbtable&" set "&Custom&"="&isnum(customValues)&"")
	Case 2,3
	dbconn("ALTER TABLE "&dbtable&" ADD "&Custom&" ntext null")
	case 10
	dbconn("ALTER TABLE "&dbtable&" ADD "&Custom&" datetime null")
	Case Else
	dbconn("ALTER TABLE  "&dbtable&"  ADD "&Custom&" nvarchar(255) null")
End Select

	sql="insert into [dbpre]Content_Custom(custom,CustomName,CustomClass,customOptions,customValues,customType,CustomOnOff,Customdesc,LID,CustomOrder,customplace) values ('"&Custom&"','"&CustomName&"','"&CustomClass&"','"&customOptions&"','"&customValues&"','"&customType&"',"&CustomOnOff&",'"&Customdesc&"',"&LID&","&CustomOrder&",'"&customplace&"')"
	 dbconn(sql)
	 if Err then back "添加失败，请修改参数内容重试"
	layertrue("添加成功")
End Sub

Sub editCustom	
	CustomName=getForm("CustomName","post")
	CustomClass=getForm("CustomClass","post")
	customOptions=ReplaceStr(getForm("customOptions","post"),"，",",")
	customValues=ReplaceStr(getForm("customValues","post"),"，",",")
	customType=getForm("customType","post")	
	if customType="" then  back "参数类型未选"
	CustomOnOff=getcheck(getForm("CustomOnOff","post"))
	CustomOrder=getForm("CustomOrder","post")	
	Customdesc=getForm("Customdesc","post")	
	customplace=getForm("customplace","post")	
	LID=zset.lid	
	dbconn("update  [dbpre]Content_Custom set  CustomName='"&CustomName&"', CustomClass="&CustomClass&",customOptions='"&customOptions&"',customValues='"&customValues&"',customType='"&customType&"',Customdesc='"&Customdesc&"',customplace='"&customplace&"',CustomOnOff="&CustomOnOff&",LID="&LID&",CustomOrder="&CustomOrder&" where  CustomID="&CustomID&"")	
	layertrue("保存成功")		
End Sub

Sub getCustom
dim rs,id
	if not isnul(CustomID) then	
		sql ="select * from [dbpre]Content_Custom where CustomID="&CustomID
		set rs = conn.exec(sql,"r1")		
	else
		alertgo "没有这条记录","-1"
	end if 	
	if rs.eof then 
			alertgo "没有这条记录","-1"
		else
			CustomID=rs("CustomID")
			Custom=rs("Custom")
			CustomName=rs("CustomName")
			CustomClass=rs("CustomClass")		
			CustomOnOff=rs("CustomOnOff")
			CustomOrder=rs("CustomOrder")
			customType=rs("customType")
			Customdesc=rs("Customdesc")
			customplace=rs("customplace")
			customOptions=rs("customOptions")
			customValues=rs("customValues")
		end if
	rs.close : set rs=nothing
End Sub

Sub getMobel(this)
	dim rs,sel,sql,i,splitValue
	if ifstrin("about,brand",this)  then
	sql="select model_type,model_name,Model_list_TP,Model_Content_TP,Model_list_FD,Model_Content_FD,Model_list_Name,Model_Content_Name,Model_table  from [dbpre]model where Model_OnOff=1 and model_type='"&this&"'"
	elseif not isnul(this) then
	sql="select model_type,model_name,Model_list_TP,Model_Content_TP,Model_list_FD,Model_Content_FD,Model_list_Name,Model_Content_Name,Model_table  from [dbpre]model where Model_OnOff=1 and Model_table='content'"
	else
	sql="select model_type,model_name,Model_list_TP,Model_Content_TP,Model_list_FD,Model_Content_FD,Model_list_Name,Model_Content_Name,Model_table  from [dbpre]model where Model_OnOff=1 and not(Model_list_TP='-' or model_type='gbook')"
	end if
	set rs=conn.Exec(sql,"r1")
		Do While Not rs.Eof	
			if ifstrin(this,",") then 
				sel=""
				splitValue=split(this,",")
				for i=0 to ubound(splitValue)
					IF CSTR(rs(0))=repkong(splitValue(i)) Then sel = "checked" 
				next
			else
				IF CSTR(this)=CSTR(rs(0)) Then sel = "checked" else sel="" end if
			end if			
			dim rscount:rscount=0		
				echo "  <div class='checkbox checkbox-success checkbox-inline'><input type='checkbox' value='"& rs(0) &"' "&sel&" name='customType' id='"& rs(0) &"'><label for="& rs(0) &"> "&rs(1)&" </label></div>" & vbcr				
			rs.MoveNext
		Loop
		Closers rs
end Sub

function getCustomClass(num)		
		select case(num)
			case 0,1,10
			getCustomClass=""
			case 2,3
			getCustomClass="<option value='2'>文本域</option>"&vbcrlf& _
            				"<option value='3'>编辑器</option>"&vbcrlf
			case 4,5,6				
			getCustomClass="<option value='4'>单选</option>"&vbcrlf& _		
							"<option value='5'>多选</option>"&vbcrlf& _		
							"<option value='6'>下拉</option>"&vbcrlf
			case 7
			getCustomClass="<option value='7'>文件上传</option>"&vbcrlf& _	
							"<option value='8'>图片上传</option>"&vbcrlf& _	
							"<option value='9'>视频上传</option>"&vbcrlf	
			case else
			getCustomClass="<option value='0' >文本</option>"&vbcrlf& _	
							"<option value='1'>数字</option>"&vbcrlf& _		
							"<option value='2'>文本域</option>"&vbcrlf& _
							"<option value='3'>编辑器</option>"&vbcrlf& _
							"<option value='4'>单选</option>"&vbcrlf& _	
							"<option value='5'>多选</option>"&vbcrlf& _
							"<option value='6'>下拉</option>"&vbcrlf& _
							"<option value='7'>文件上传</option>"&vbcrlf& _		
							"<option value='8'>图片上传</option>"&vbcrlf& _	
							"<option value='9'>视频上传</option>"&vbcrlf& _	
							"<option value='10'>日期时间</option>"&vbcrlf			
			end select	
End function

function getCustomname(num)
	select case num
		case 0 :	getCustomname="文本"
		case 1 :	getCustomname="数字"
		case 2 :	getCustomname="文本域"
		case 3 :	getCustomname="编辑器"
		case 4 :	getCustomname="单选"
		case 5 :	getCustomname="多选"
		case 6 :	getCustomname="下拉"
		case 7 :	getCustomname="文件上传"
		case 8 :	getCustomname="图片上传"
		case 9 :	getCustomname="视频上传"
		case 10 :	getCustomname="日期时间"
	end select
End function
%>