<!--#include file="../../../inc/cms_admin.asp" -->
<%
dim SID, TID,T_SID,T_LID, T_PID, T_Order, T_Type,   T_AddTime, T_name,  T_OnOff, T_TID, T_Visits,T_editTime
dim sql,T_EnName,usertype,table,col,colval,idval,id,sortid

dim act : act=getForm("act","get")
dim stype : stype=getForm("stype","get")
dim postion : postion=getForm("postion","get")
T_Order=getForm("T_Order","both")
table=getForm("table","both")
col=getForm("col","both")
colval=getForm("colval","both")
idval=getForm("idval","both")
TID=getForm("TID","both")
id=isnum(getForm("id","both"))
Select case act	
	case "settag"	:	dbconn("update [dbpre]tag set T_OnOff="&colval&"  where  TID="&TID&"")
	case "del"		:	dbconn("delete from [dbpre]tag  where TID in ("&idval&")")	
	case "edit" 	:	edittag
	case "add"		:	addtag
	case "del"		: 	deltag
	case "saveid"	:	saveid
	case "tag_list"	:	tag_list
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]tag Set "&colname&"='"&colval&"' Where TID="&colid
	dim sql2 		:	sql2="update [dbpre]tag Set "&colname&"="&colval&" Where TID="&colid	
	dbconn(sql1)	:	if err then dbconn(sql2)
End Sub

Sub gettag
dim rs,id	
	if not isnul(TID) then	
		sql ="select * from [dbpre]tag where TID="&TID
		set rs = conn.exec(sql,"r1")		
	else
		back "没有这条记录"
	end if 
	if rs.eof then 
			back "没有这条记录"
		else
			TID=rs("TID")			
			T_LID=rs("T_LID")
			T_Order=rs("T_Order")
			T_Name=rs("T_name")
			T_enName=rs("T_enname")
			T_type=rs("T_type")
			T_AddTime=rs("T_AddTime")	
			T_editTime=rs("T_editTime")	
			T_OnOff=rs("T_OnOff")			
			T_Visits=rs("T_Visits")
		end if
	rs.close : set rs=nothing
End Sub

Sub addtag	
	TID=getForm("TID", "get")	
	T_Order=getForm("T_Order", "post")	
	T_Name=getForm("T_Name", "post")
	T_enName=getForm("T_enName", "post")
	T_type=getForm("T_type", "post")
	T_AddTime=getForm("T_AddTime", "post")	
	T_Visits=getForm("T_Visits", "post")
	T_LID=cint(zset.lid)	
	T_OnOff=getcheck(getForm("T_OnOff", "post"))
	if isnul(T_Name) then back "分类名称不能为空"
	if dbcount("[dbpre]tag","T_Name='"&T_Name&"'")>0 then  back "名称已存在"
 sql="insert into [dbpre]tag(T_LID, T_Order, T_type, T_AddTime, T_name, T_enname,T_OnOff, T_Visits)values("&T_LID&","& T_Order&",'"& T_type&"','"& now()&"','"& T_name&"','"& T_enname&"',1,"&T_Visits&")"
	dbconn(sql)	
	layernext("添加成功")
End Sub	
Sub edittag	
	TID=getForm("TID", "get")	
	T_Order=isnum(getForm("T_Order", "post"))	
	T_name=getForm("T_Name", "post")
	T_enname=getForm("T_enName", "post")
	T_type=getForm("T_type", "post")
	T_AddTime=getForm("T_AddTime", "post")	
	if isnul(T_Name) then back "分类名称不能为空"	
	sql= "update [dbpre]tag set T_Order="&T_Order&", T_Name='"&T_Name&"',T_enName='"&T_enName&"', T_type='"&T_type&"', T_AddTime ='"&T_AddTime&"',T_editTime ='"&sqltime&"'  where TID="&TID
	dbconn(sql)	
	layertrue("修改成功")
End Sub	

Sub tag_list
	Dim rs,json,listjson,page,numPerPage,allRecordset,limit,i,orderby,descby,orderbystr,search,searchstr
	page=getform("offset","both")
	numPerPage=getform("limit","both")
	orderby=getform("sort","both")
	descby=getform("order","both")
	search=getform("search","both")
	if not isnul(search) then searchstr=""
	if isnul(orderby) or orderby="tid" then
		orderbystr="order by T_order asc,tid asc"
	else
		orderbystr="order by "&orderby&" "&descby&",tid desc"
	end if
 	if isnum(numPerPage) =0 then numPerPage=10
	if isnum(page) =0 then page=1
	sql="select *,(select count(0) from [dbpre]content as b where C_OnOff=1 and [b.C_Tag] like '%'+[a.T_Name]+'%') as tagcount from [dbpre]tag as a "&orderbystr
	set rs=dbsqlr1(sql)	
	if not rs.eof then  	
	  rs.pagesize	=numPerPage
	  allRecordset = rs.recordcount
	  Set json = jsObject()
		rs.absolutepage = page
		for i = 1 to numPerPage	
		 json("TID") = rs("TID")
		 json("T_name") = "<a onclick=opennew('tag_edit.asp?TID="&rs("TID")&"')>"&rs("T_name")&"</a>"
		 json("T_type") = rs("T_type")
		 json("T_count") = "<a href='/tag/?tag="&rs("T_enname")&"' target='_blank'>"&rs("tagcount")&"</a>"
		 json("T_order") = "<input type='number' placeholder='"&rs("T_order")&"' class='order'  min='0' max='99' id='T_order-"&rs("TID")&"' value="&rs("T_order")&">"
		 json("T_OnOff") = "<button type='button'  onclick=settag('T_onoff','"&rs("TID")&"') class='btn btn-"&rs("T_OnOff")&"  dim'><i class='fa fa-toggle-on'></i></button>"
		 json("T_edit") = "<button type='button' class='btn btn-info dim' onclick=opennew('tag_edit.asp?TID="&rs("TID")&"')><i class='fa fa-pencil'></i></button>　<button type='button'  onclick=deltag('"&rs("TID")&"')  class='btn btn-danger dim'><i class='fa fa-times'></i></button>"
		 listjson=listjson& json.jsString()&","
		 rs.movenext
		 if rs.eof then exit for
	next
		 echo "{""total"":"&allRecordset&",""rows"":["&endstr(listjson,",")&"]}"
	else
	 	echo sql
	end if
closers rs	
end sub
Sub getMobel(this)
	dim rs,sel,sql,OnOff
	sql="select Model_type,Model_Name from [dbpre]model where Model_OnOff=1 and Model_table='content'"
	set rs=conn.Exec(sql,"r1")
		Do While Not rs.Eof	
			IF CSTR(this)=CSTR(rs(0)) Then sel = "selected=""selected""" else sel="" end if
			dim rscount:rscount=0		
				echo "<option  value="""& rs(0) &""" "&sel&">"&rs(1)&"</option>" & vbcr				
			rs.MoveNext
		Loop
		Closers rs
end Sub
%>