<!--#include file="system_manage.asp"-->
<%
Dim sid,stitle,scode,slevel,said,sif_hidden,idcount,emptyid,zero,alevel,getemptyid,souturl,fid,lenfid,aid,ssortlist
 	Dim soptions(1)
	Dim svalues(1)
	soptions(0)="文章"
	soptions(1)="单页面"
	svalues(0)=0
	svalues(1)=1
   Call DBConnBegin()
   Set rs = server.createobject("adodb.recordset")
Select Case Request("action")
    Case "addsave"
		postid=request("id")
		stitle=request.Form("title")
		said=CInt(request.Form("aid"))
		souturl=request.Form("outurl")
		ssortlist=request.Form("sortlist")
		sif_hidden=request.Form("if_hidden")
			 If stitle="" Then Call tx_common.message("·标题或者内容不能为空<meta http-equiv=refresh content='1;URL=admin_announce.asp'>",0)
   'save
   idcount=9999
  ' sqls="select id,code,level from tx_catasort where id="&said
set rsa=server.CreateObject("adodb.recordset")
			sqla="Select * from tx_catasort where id="&said
			rsa.Open sqla,conn,1,3
			if not rsa.EOF then
				alevel = rsa("level")
				aid=rsa("id")
				fid=rsa("code")
				lenfid=len(fid)
          Set rss=conn.execute("select right(code,"&Len(idcount)&") as code from tx_catasort where aid="&aid&" and len(code)="&lenfid+4&" and left(code,"&Lenfid&")="&fid&" order by code desc")
             If Not rss.eof Then
                 emptyid=CInt(rss("code"))
                  emptyid=emptyid+1
             End If 
          rss.close:Set rss=Nothing 
	      Zero=""
			for i=1 to (len(IdCount)-len(EmptyId))
				Zero=Zero+"0"
			next
			EmptyId=Cstr(Zero&Cstr(EmptyId))
				getEmptyId=fid&cstr(EmptyId)
				
else
		CRs=Conn.execute("select max(code) from tx_catasort where len(code)=4")
			 if isnull(CRs(0)) or CRs(0)=empty then
				  getemptyid="0001"
			else
				emptyid=cint(crs(0))
				emptyid=emptyid+1
			     Zero=""
			        for i=1 to (len(IdCount)-len(EmptyId))
				          Zero=Zero+"0"
			        next
			    EmptyId=Cstr(Zero&Cstr(EmptyId))
				getemptyid=cstr(emptyid)
			 end if
			      set CRs=nothing
				      alevel = 0
end If
rsa.close:Set rsa=Nothing 
	
			 If postid<>"" Then 
				sql="select * from tx_catasort where id="&postid
				rs.open sql,conn,2,2
		     Else
		        rs.open "tx_catasort",conn,2,2
				rs.addnew 
			 End If 
	    rs("title")=stitle
		rs("aid")=said
		rs("code")=getemptyid
		rs("level")=alevel+1
		rs("if_hidden")=sif_hidden
		rs("outurl")=souturl
		rs("sortlist")=ssortlist
		rs.update
		rs.close
		 Call tx_common.message("·网站分类添加成功<br>·如果你的浏览器不支持跳转，<a href='admin_catasort.asp'>点击这里返回</a><meta http-equiv=refresh content='3;URL=admin_catasort.asp'>",1)
    Case "del"
id=tx_common.checkstr(request.querystring("id"),1)
sql="delete from tx_catasort where id="&id
tx_common.execute sql
 Call tx_common.message("·网站分类删除成功<br>·如果你的浏览器不支持跳转，<a href='admin_catasort.asp'>点击这里返回</a><meta http-equiv=refresh content='3;URL=admin_catasotr.asp'>",1)
    Case "add"
content=tx_tables.formtop("?action=addsave","添加分类")
content =content & tx_tables.inputs("分类标题","title","text","")
content = content & tx_master.sortselect("所属分类","","aid","0")
content = content & tx_tables.Selects("分类属性","sortlist",0,svalues,soptions,0)
content =content & tx_tables.inputs("外部连接","outurl","text","")
content =content & tx_tables.yesno("是否隐藏","if_hidden",0)
content =content & tx_tables.formfoot
    Case "edit"

	postid=request("id")
	sql="select id,title,aid,if_hidden,outurl,sortlist from tx_catasort where id="&postid
	temps=tx_common.query(sql)
	If IsArray(temps) Then 
content=tx_tables.formtop("?action=addsave&id="&temps(0,0),"添加分类")
content =content & tx_tables.inputs("分类标题","title","text",temps(1,0))
content = content & tx_master.sortselect("所属分类","","aid",temps(2,0))
content = content & tx_tables.Selects("分类属性","sortlist",0,svalues,soptions,temps(5,0))
content =content & tx_tables.inputs("外部连接","outurl","text",temps(4,0))
content =content & tx_tables.yesno("是否隐藏","if_hidden",temps(3,0))
content =content & tx_tables.formfoot

else
 Call tx_common.message("·该分类不存在或者已经删除<br>·如果你的浏览器不支持跳转，<a href='admin_catasort.asp'>点击这里返回</a><meta http-equiv=refresh content='3;URL=admin_catasort.asp'>",1)
    End If 
Case else
content =  "<table width='100%' cellpadding=3 cellspacing=1 class=td1>"
content = content & "<tr class=td4><td colspan=6><strong>分类列表</strong></td></tr>"
content = content & "<tr class=td2><td nowap>ID</td><td width='30%'>名称</td><td width='20%'>外部连接</td><td width='10%'>移动</td><td width='10%'>操作</td></tr>"
sql="select id,title,outurl,[level] from tx_catasort order by code asc"
temps=tx_common.query(sql)
If IsArray(temps) Then 
For i=0 To UBound(temps,2)
content =content & "<tr class=td2><td>"&temps(0,i)&"</td><td>&nbsp;||"
        for j=1 to temps(3,i)-1
		content =content & "…"
    	next
content = content & temps(1,i)&"</td><td>"&temps(2,i)&"</td><td><A HREF=""admin_cataorder.asp?action=up&postid="&temps(0,i)&""" style=""color:#0099cc""> ↑ </A>||<A HREF=""admin_cataorder.asp?action=down&postid="&temps(0,i)&""" style=""color:#0099cc""> ↓ </A></td><td><a href=?action=edit&id="&temps(0,i)&">编辑</a> | <a href=?action=del&id="&temps(0,i)&">删除</a></td></tr>"
Next 
Else
content = content & "<tr class=td2><td colspan=6>暂时没有任何分类，请添加！</td></tr>"
End If 
End Select
Call ClassEnd()
Call DBConnEnd()
response.write content
Call GetBottom()
%>