<!--#include file="../../../inc/cms_admin.asp" -->
<%
dim GID,LID,G_name,G_tel,G_email,G_title,G_Content,G_order,G_IP,G_Time,G_OnOff,R_name,R_content,R_Time,R_OnOff
dim sql,table,col,colval,idval,id,colname,colid,gbookParas

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")
colid=getForm("colid","post")
colname=getForm("colname","post")
colval=getForm("colval","both")
idval=getForm("idval","both")
GID=getForm("GID","both")
G_order=getForm("G_order","both")
R_content=getForm("R_content","both")
Select case act	
	case "setgbook"		:	dbconn("update  [dbpre]gbook set "&col&"="&colval&"  where  GID="&GID&"")	: if err then dbconn("update  [dbpre]gbook set "&col&"=1  where  GID="&GID&"")
	case "edit"			:	editgbook
	case "del"			:	dbconn("delete from [dbpre]gbook  where GID in ("&idval&")")
	case "delall"		:	dbconn("delete from [dbpre]gbook  where G_OnOff<>1")	:	aspgo("gbook_list.asp")
	case "saveid" 		: 	saveid
	case "savecustom" 	: 	savecustom	
	case "offgbook"		: 	offgbook
	case "addtCustom"	: 	addtCustom	
End Select

sub offgbook
	gbookParas=loadfile(sitepath&"gbook/gbook_config.asp")
	gbookParas=AddParas(colname,"num",gbookParas,colval)
	savefile sitepath&"gbook/gbook_config.asp",gbookParas
end sub

sub savecustom
	if isnul(colid) then
		gbookParas=loadfile(sitepath&"gbook/gbook_config.asp")
		gbookParas=AddParas(colname,"str",gbookParas,colval)
		savefile sitepath&"gbook/gbook_config.asp",gbookParas
	else		
		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 if
end sub

sub saveid
	dim sql1		:	sql1="update [dbpre]gbook Set "&colname&"='"&colval&"' Where GID="&colid
	dim sql2		:	sql2="update [dbpre]gbook Set "&colname&"="&colval&" Where GID="&colid	
	dbconn(sql1)	:	if err then  dbconn(sql2)	
end sub

Sub editgbook		
		LID=zset.lid	
		G_name=getForm("G_name","post")
		G_tel=getForm("G_tel","post")
		G_email=getForm("G_email","post")
		G_title=getForm("G_title","post")
		G_Content=getForm("G_Content","post")
		G_IP=getForm("G_IP","post")
		G_Time=getForm("G_Time","post")
		G_OnOff=getcheck(getForm("G_OnOff","post"))
		R_name=getForm("R_name","post")
		R_content=getForm("R_content","post")
		R_Time=getForm("R_Time","post")
		if isnul(R_Time) then R_Time=sqltime
		R_OnOff=getcheck(getForm("R_OnOff","post"))	
		dim rs,customStr
	set rs=dbsqlr1("select custom,customClass from [dbpre]content_custom where customType ='gbook'")	
	Do While not rs.Eof 	
		if rs(1)=1 then 
		customStr=customStr&","&rs(0)&"="&isnum(getForm(rs(0),"post"))& ""
		elseif rs(1)=3 then 
		customStr=customStr&","&rs(0)&"='"&encode(request.form(rs(0)))& "'"
		else
		customStr=customStr&","&rs(0)&"='"&getForm(rs(0),"post")&"'"
		end if
	rs.MoveNext
	Loop
	closers rs
	 dbconn("update  [dbpre]gbook set LID="&LID&",G_name='"&G_name&"',G_tel='"&G_tel&"',G_email='"&G_email&"',G_title='"&G_title&"',G_Content='"&G_Content&"',G_IP='"&G_IP&"',G_Time='"&G_Time&"',G_OnOff="&G_OnOff&",R_name='"&R_name&"',R_content='"&R_content&"',R_Time='"&R_Time&"',R_OnOff="&R_OnOff&""&customStr&" where  GID="&GID&"")	
	layertrue("保存成功")		
End Sub

Sub addtCustom
	dim customID,custom,customname,LID,customType,customClass,customOptions,customValues,customOrder,customOnOff,customdesc,customplace
	CustomName=getForm("CustomName","post")
	Custom="z"&getForm("Custom","post")		:	if dbcount("[dbpre]content_custom","Custom='"&Custom&"'")>0 then back "参数已经存在,请修改!"	
	CustomClass=getForm("CustomClass","post")
	customOptions=ReplaceStr(getForm("customOptions","post"),"，",",")
	customValues=ReplaceStr(getForm("customValues","post"),"，",",")
	CustomOnOff=getcheck(getForm("CustomOnOff","post"))
	CustomOrder=getForm("CustomOrder","post")	
	Customdesc=getForm("Customdesc","post")
	customplace=getForm("customplace","post")	
	customType="gbook"
  Select Case CInt(CustomClass)
	Case 1
	dbconn("ALTER TABLE [dbpre]gbook ADD "&Custom&" int null")
	dbconn("update [dbpre]gbook set "&Custom&"="&isnum(customValues)&"")
	Case 2,3
	dbconn("ALTER TABLE [dbpre]gbook ADD "&Custom&" ntext null")
	case 10
	dbconn("ALTER TABLE [dbpre]gbook ADD "&Custom&" datetime null")
	Case Else
	dbconn("ALTER TABLE  [dbpre]gbook  ADD "&Custom&" nvarchar(255) null")
  End Select
	sql="insert into [dbpre]Content_Custom(custom,CustomName,CustomClass,customOptions,customValues,customType,CustomOnOff,Customdesc,CustomOrder,customplace) values ('"&Custom&"','"&CustomName&"','"&CustomClass&"','"&customOptions&"','"&customValues&"','"&customType&"',"&CustomOnOff&",'"&Customdesc&"',"&CustomOrder&",'"&customplace&"')"
	 dbconn(sql)
	 if Err then back "添加失败，请修改参数内容重试"
	layermsggo "添加成功",sitepath&adminpath&"cms_content/gbook/gbook_custom.asp"
End Sub

function selectgbook(title,str)
	dim gbookstr
	gbookstr=""&vbcrlf
		if isnul(str) then gbookstr=gbookstr&"<option value='' selected>可空</option>"&vbcrlf	else gbookstr=gbookstr&"<option value=''>可空</option>"
		if str="*" then gbookstr=gbookstr&"<option value='*' selected>不能为空</option>"&vbcrlf	else gbookstr=gbookstr&"<option value='*'>不能为空</option>"&vbcrlf
		if str="m" then gbookstr=gbookstr&"<option value='m' selected>手机</option>"&vbcrlf		else gbookstr=gbookstr&"<option value='m'>手机</option>"&vbcrlf	
		if str="e" then gbookstr=gbookstr&"<option value='e' selected>邮箱</option>"&vbcrlf		else gbookstr=gbookstr&"<option value='e'>邮箱</option>"&vbcrlf		
		if str="p" then gbookstr=gbookstr&"<option value='p' selected>邮编</option>"&vbcrlf		else gbookstr=gbookstr&"<option value='p'>邮编</option>"&vbcrlf
		gbookstr=gbookstr&"</select>"&vbcrlf
	selectgbook= gbookstr
End function

Sub getgbook
dim rs,id
	if not isnul(GID) then	
		sql ="select * from [dbpre]gbook where GID="&GID
		set rs = conn.exec(sql,"r1")		
	else
		alertgo "没有这条记录","-1"
	end if 
	
	if rs.eof then 
			alertgo "没有这条记录","-1"
		else
		LID=rs("LID")
		G_name=rs("G_name")
		G_tel=rs("G_tel")
		G_email=rs("G_email")
		G_title=rs("G_title")
		G_Content=rs("G_Content")
		G_IP=rs("G_IP")
		G_Time=rs("G_Time")
		G_OnOff=rs("G_OnOff")
		R_name=rs("R_name")
		R_content=rs("R_content")
		R_Time=rs("R_Time")
		R_OnOff=rs("R_OnOff")
		end if
	rs.close : set rs=nothing
End Sub

function getCustom(GID)	
		Dim rs,CustomFields,rs1,i,CustomNames,splitValue,checkstr,selectstr,valstr,topstr,endstr,filetype
		CustomFields=""		
		Set rs=dbsqlr1("select CustomName,Custom,customValues,customOptions,customClass,customplace from [dbpre]Content_custom where Customtype ='gbook' order by CustomOrder asc,CustomID desc")		
		Do While not rs.Eof 			
			if GID=0 then 	
				valstr=rs(2)
			 else 
				valstr=dbselect("[dbpre]gbook",""&rs(1)&"","GID="&GID&"")
			end if
				select case rs(4)
				case 0,1	
				getCustom= getCustom&"<div class='form-group'>"&vbcrlf& _	
                     "<label class='col-sm-2 control-label'>"&rs(0)&"</label>"&vbcrlf& _	
                     "<div class='col-sm-8'><input name='"&rs(1)&"' id='"&rs(1)&"' type='text' class='form-control' placeholder='"&rs(5)&"' value='"&valstr&"'>"&vbcrlf& _	
                     "</div> </div>"&vbcrlf
				case 2
				getCustom= getCustom&"<div class='form-group'>"&vbcrlf& _	
					"<label class='col-sm-2 control-label'>"&rs(0)&"</label>"&vbcrlf& _	
					"<div class='col-sm-8'> <textarea class='textarea form-control'   name='"&rs(1)&"' id='"&rs(1)&"'  placeholder='"&rs(5)&"'>"&valstr&"</textarea>"&vbcrlf& _	
					"</div></div>"&vbcrlf
				case 3
				getCustom= getCustom&"<div class='form-group'>"&vbcrlf& _	
					"<label class='col-sm-2 control-label'>"&rs(0)&"</label>"&vbcrlf& _	
					"<div class='col-sm-8'> <textarea class='textarea textarea-editor'   name='"&rs(1)&"' id='"&rs(1)&"'>"&decode(valstr)&"</textarea>"&vbcrlf& _	
					"</div></div> <script>var $cmsEditor = new UE.getEditor('"&rs(1)&"');</script>"&vbcrlf
				case 4,5,6
					if ifstrin(rs(3),",") then
					getCustom= getCustom&"<div class='form-group'><label class='col-sm-2 control-label'>"&rs(0)&"</label>"&vbcrlf	
					if rs(4)=6 then getCustom= getCustom&"<div class='col-sm-7'><select name='"&rs(1)&"' id='"&rs(1)&"' class='form-control'>" else getCustom= getCustom&"<div class='col-sm-8'>"
					splitValue=split(rs(3),",")
						for i=0 to ubound(splitValue)
						if ifstrin(valstr,splitValue(i)) then
						  checkstr="checked"
						  selectstr="selected"
						  else 
						  checkstr=""
						  selectstr=""
						end if
						if rs(4)=4	then getCustom= getCustom& "<div class='radio radio-inline'><input type=""radio"" id='"&rs(1)&i&"' name='"&rs(1)&"' "&checkstr&" value='"&splitValue(i)&"'/><label for='"&rs(1)&i&"'>"&splitValue(i)&"</label></div>"&vbcrlf
						if rs(4)=5	then getCustom= getCustom& "<div class='checkbox radio-inline'><input type=""checkbox"" id='"&rs(1)&i&"' name='"&rs(1)&"' "&checkstr&" value='"&splitValue(i)&"'/><label for='"&rs(1)&i&"'>"&splitValue(i)&"</label></div>"&vbcrlf
						if rs(4)=6	then getCustom= getCustom& " <option value='"&splitValue(i)&"' "&selectstr&">"&splitValue(i)&"</option>"
						next
					if rs(4)=6 then getCustom= getCustom&" </select>"
					getCustom=  getCustom&"</div></div>"&vbcrlf
					end if
				case 7,8,9
				if rs(4)=7 then	filetype="file"
				if rs(4)=8 then	filetype="pic"
				if rs(4)=9 then	filetype="video"
				getCustom= getCustom&"<div class='form-group'>"&vbcrlf& _	
                     "<label class='col-sm-2 control-label'>"&rs(0)&"</label>"&vbcrlf& _	
					  "<div class='col-sm-7'><input id='"&rs(1)&"' name='"&rs(1)&"' class='form-control' value='"&valstr&"'/></div>"&vbcrlf& _	
                     "<div class='col-sm-2'> <iframe frameborder='0' height='30' width='150' scrolling='no' name='"&rs(1)&"'  src='"&sitepath&adminpath&"inc/swfupload/upload1.asp?filetype="&filetype&"&stype=about&parentid="&rs(1)&"'></iframe>"&vbcrlf& _
                     "</div> </div>"&vbcrlf
				
				end select
			rs.MoveNext
		Loop
		getCustom=topstr&getCustom&endstr
End function
%>