<!--#include file="../p_inc/Include_func.asp"-->
<!--#include file="../p_inc/openconn.asp"-->

<%

IF Request.Cookies(G_u_Cookies)("soojs_u")="" Then
	Response.End()
End IF


Response.Buffer=True
response.contenttype="text/html;charset=gb2312"


action=Request("action")
IF action="getSortList" Then
	Call getSortList()'获取每个收藏类别和统计数目
ElseIF action="getTypeList" Then
	Call getTypeList()'根据收藏类别，获取对应的收藏列表
ElseIF action="del" Then
	IF Request("cmd")="del_sort" Then
		Call del_sort()
	Else
		Call del() '删除一个收藏网址
	End IF
ElseIF action="up" Then
	IF Request("op")="up" Then
		Call up() '上移	
	ElseIF Request("op")="down" Then
		Call down() '下移
	End IF
ElseIF action="move" Then
	Call mov() '移动网址所对应的类别	
ElseIF action="input2" Then
	Call input2() '导入本地收藏夹	
ELse
	cmd=Request("cmd")
	IF cmd="edit_fav" Then
		Call edit_fav() '修改网址	
	ElseIF cmd="add_fav" Then
		Call add_fav() '增加网址	
	ElseIF cmd="edit_sort" Then
		Call edit_sort() '修改分类	
	ElseIF cmd="add_sort" Then
		Call add_sort() '增加分类				
	End IF	
End IF


Sub input2()
	For i=0 To 50
		s1=Trim(Request("fold["&i&"]"))
		IF s1<>"" Then
			s1=left(Replace(s1,"'",""),50)
			Sql="Select Top 1 * From qingtiandy_curl Where c_Uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And c_typename='"&s1&"'"
			Set oRs=Server.CreateObject(G_RS)
			oRs.open Sql,Conn,1,3
			IF oRs.Eof Then
				oRs.AddNew()
				oRs("c_typename")=s1
				oRs("c_no")=1
				oRs("c_uid")=Request.Cookies(G_u_Cookies)("soojs_id")
				oRs.Update()					
			End IF
			plist_type1=oRs("id")
			
			For ii=0 To 200
				s2=Request("url_key["&i&"]["&ii&"]")
				IF s2<>"" And Instr(s2,"^^")>0 Then
					s2_a=Split(s2,"^^")
					s2_1=s2_a(0) '链接地址
					s2_2=s2_a(1) '链接名
					s2_2=Trim(Replace(s2_2,"'",""))
					IF s2_2<>"" Then
						Sql="Select Top 1 * From qingtiandy_listurl Where list_uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And list_name='"&s2_2&"' Order By id Desc"
						Set oRs2=Server.CreateObject(G_RS)
						oRs2.open Sql,Conn,1,3
						IF  oRs2.Eof Then
							oRs2.AddNew()
							oRs2("list_url")=s2_1
							oRs2("list_name")=s2_2
							oRs2("list_biaoqian")=""	
							oRs2("list_type1")=plist_type1
							oRs2("list_content")=""
							oRs2("list_gx")=0
							oRs2("list_uid")=Request.Cookies(G_u_Cookies)("soojs_id")
							oRs2("list_date")=ForMatDate(Now(),55)
							oRs2("list_no")=0
							oRs2.update()		
						End IF
					End IF	
				End IF
			Next
		End IF
	Next
	Response.Write "<scr"&"ipt>parent.location.reload()</scr"&"ipt>"
End Sub

Sub add_sort()
	vSort=Replace(Request("vSort"),"'","")
	Sql="Select Top 1 * From qingtiandy_curl Where c_Uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And c_typename='"&vSort&"'"
	Set oRs=Server.CreateObject(G_RS)
	oRs.open Sql,Conn,1,3
	IF oRs.Eof Then
		oRs.AddNew()
		oRs("c_typename")=vSort
		oRs("c_no")=1
		oRs("c_uid")=Request.Cookies(G_u_Cookies)("soojs_id")
		oRs.Update()	
		str="<script language=""JavaScript"">parent.myfav.msg(""收藏分类添加成功"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");parent.myfav.clickSort('all');parent.myfav.reloadSort();</script>"	
	Else
		str="<script language=""JavaScript"">parent.myfav.msg(""该收藏分类已经存在"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");</script>"	
	End IF
	Response.Write str
End Sub

Sub del_sort()
	sdel_id=Replace(Request("del_id"),"'","")
	sdel_id=Bint(sdel_id)	
	Conn.Execute("Delete From qingtiandy_curl Where c_Uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And id="&sdel_id)
	str="<script language=""JavaScript"">parent.myfav.msg(""收藏分类删除成功"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");parent.myfav.clickSort('all');parent.myfav.reloadSort();</script>"
	Response.Write str
End SUb

Sub edit_sort()
	id=Replace(Request("id"),"'","")
	id=Bint(id)
	vSort=Replace(Request("vSort"),"'","")
	Sql="Select Top 1 * From qingtiandy_curl Where c_Uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And Id="&id
	Set oRs=Server.CreateObject(G_RS)
	oRs.open Sql,Conn,1,3
	IF Not oRs.Eof Then
		Set oRs2=Conn.Execute("Select Top 1 * From qingtiandy_curl Where c_Uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And c_typename='"&vSort&"' And Id<>"&id)
		IF oRs2.Eof Then
			oRs("c_typename")=vSort
			'oRs("c_no")=1
			'oRs("c_uid")=Request.Cookies(G_u_Cookies)("soojs_id")
			oRs.Update()
			str="<script language=""JavaScript"">parent.myfav.msg(""分类修改成功"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");parent.myfav.reloadSort();var version=1.0;</script>"
		Else
			str="<script language=""JavaScript"">parent.myfav.msg(""该分类已经存在"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");</script>"
		End IF
	Else
		str="<script language=""JavaScript"">parent.myfav.msg(""异常错误"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");</script>"
	End IF	
	oRs.close
	Response.Write str
End Sub

Sub add_fav()
	vTitle=Replace(Request("vTitle"),"'","")
	vUrl=Replace(Request("vUrl"),"'","")
	vSort=Bint(Replace(Request("vSort"),"'",""))
	Sql="Select Top 1 * From qingtiandy_listurl Where list_uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And list_name='"&vTitle&"' Order By id Desc"
	Set oRs=Server.CreateObject(G_RS)
	oRs.open Sql,Conn,1,3
	IF  oRs.Eof Then
		oRs.AddNew()
		oRs("list_url")=vUrl
		oRs("list_name")=vTitle
		oRs("list_biaoqian")=""	
		oRs("list_type1")=vSort
		oRs("list_content")=""
		oRs("list_gx")=0
		oRs("list_uid")=Request.Cookies(G_u_Cookies)("soojs_id")
		oRs("list_date")=ForMatDate(Now(),55)
		oRs("list_no")=0
		oRs.update()		
		str="<script language=""JavaScript"">parent.myfav.msg(""收藏添加成功"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");parent.myfav.clickSort('all');var version=1.0;</script>"
		
	Else
		str="<script language=""JavaScript"">parent.myfav.msg(""异常错误"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");</script>"
	End IF
	oRs.close
	
	Response.Write str	
End Sub

Sub edit_fav()
	sdel_id=Replace(Request("id"),"'","")
	aa=split(sdel_id,"|")
	b=Bint(aa(1))
	vTitle=Replace(Request("vTitle"),"'","")
	vUrl=Replace(Request("vUrl"),"'","")
	vSort=Bint(Replace(Request("vSort"),"'",""))
	Sql="Select Top 1 * From qingtiandy_listurl Where list_uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And id="&b&" Order By id Desc"
	Set oRs=Server.CreateObject(G_RS)
	oRs.open Sql,Conn,1,3
	IF Not oRs.Eof Then
		oRs("list_url")=vUrl
		oRs("list_name")=vTitle
		oRs("list_type1")=vSort
		oRs.update()		
		str="<script language=""JavaScript"">parent.myfav.msg(""收藏修改成功"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");parent.myfav.reloadSort();var version=1.0;</script>"
	Else
		str="<script language=""JavaScript"">parent.myfav.msg(""异常错误"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");</script>"
	End IF
	oRs.close
	
	Response.Write str	
End Sub

Sub mov()
	smsid=Replace(Request("msid"),"'","") '要移动到的类别ID
	smsid=Bint(smsid)
	a=Replace(Replace(Request("box[]"),"'","")," ","")
	aa=split(a,",")
	b=""
	For ii=0 To Ubound(aa)
		a1=split(aa(ii),"|")
		b=b&a1(1)&","
	Next
	b=FormatNumSerial(b)	
	Conn.execute("Update qingtiandy_listurl set list_type1="&smsid&" where list_uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And id in("&b&")")
	str="<script language=""JavaScript"">parent.myfav.msg(""收藏移动成功"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");parent.myfav.reloadSort();var version=1.0;</script>"
	Response.Write str
End Sub

Sub down()
	sid=Replace(Request("id"),"'","") '收藏网址ID
	sid=Bint(sid)
	Set oRs=Server.CreateObject(G_RS)
	Sql="Select * From qingtiandy_listurl Where list_uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And id<"&sid&" Order By id Desc"
	oRs.open Sql,Conn,1,3
	IF oRs.Eof Then
		str="<script language=""JavaScript"">parent.myfav.msg(""已经到最底端了，不能向下移动了"");</script>"
	Else
		aid=oRs("id")
		alist_url=oRs("list_url")
		alist_name=oRs("list_name")
		alist_biaoqian=oRs("list_biaoqian")
		alist_type1=oRs("list_type1")		
		alist_content=oRs("list_content")
		alist_gx=oRs("list_gx")		
		alist_uid=oRs("list_uid")
		alist_date=oRs("list_date")	
		alist_no=oRs("list_no")		
		
		Set oRs2=Server.CreateObject(G_RS)
		Sql="Select * From qingtiandy_listurl Where list_uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And id="&sid&" Order By id Desc"
		oRs2.open Sql,Conn,1,3		
		IF Not oRs2.Eof Then
			bid=oRs2("id")
			blist_url=oRs2("list_url")
			blist_name=oRs2("list_name")
			blist_biaoqian=oRs2("list_biaoqian")
			blist_type1=oRs2("list_type1")		
			blist_content=oRs2("list_content")
			blist_gx=oRs2("list_gx")		
			blist_uid=oRs2("list_uid")
			blist_date=oRs2("list_date")	
			blist_no=oRs2("list_no")		
			
			oRs("list_url")=blist_url
			oRs("list_name")=blist_name
			oRs("list_biaoqian")=blist_biaoqian	
			oRs("list_type1")=blist_type1
			oRs("list_content")=blist_content
			oRs("list_gx")=blist_gx
			oRs("list_uid")=blist_uid
			oRs("list_date")=blist_date
			oRs("list_no")=blist_no
			oRs.update()
			
			oRs2("list_url")=alist_url
			oRs2("list_name")=alist_name
			oRs2("list_biaoqian")=alist_biaoqian	
			oRs2("list_type1")=alist_type1
			oRs2("list_content")=alist_content
			oRs2("list_gx")=alist_gx
			oRs2("list_uid")=alist_uid
			oRs2("list_date")=alist_date
			oRs2("list_no")=alist_no
			oRs2.update()		
			str="<script language=""JavaScript"">parent.myfav.msg(""移动成功"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");parent.myfav.reloadSort();var version=1.0;</script>"	
		Else
			str="<script language=""JavaScript"">parent.myfav.msg(""异常错误"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");</script>"
		End IF		
	End IF
	Response.Write str	
End Sub

Sub up()
	sid=Replace(Request("id"),"'","") '收藏网址ID
	sid=Bint(sid)
	Set oRs=Server.CreateObject(G_RS)
	Sql="Select * From qingtiandy_listurl Where list_uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And id>"&sid&" Order By id Asc"
	oRs.open Sql,Conn,1,3
	IF oRs.Eof Then
		str="<script language=""JavaScript"">parent.myfav.msg(""已经到顶端了，不能向上移动了"");</script>"
	Else
		aid=oRs("id")
		alist_url=oRs("list_url")
		alist_name=oRs("list_name")
		alist_biaoqian=oRs("list_biaoqian")
		alist_type1=oRs("list_type1")		
		alist_content=oRs("list_content")
		alist_gx=oRs("list_gx")		
		alist_uid=oRs("list_uid")
		alist_date=oRs("list_date")	
		alist_no=oRs("list_no")		
		
		Set oRs2=Server.CreateObject(G_RS)
		Sql="Select * From qingtiandy_listurl Where list_uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And id="&sid&" Order By id Desc"
		oRs2.open Sql,Conn,1,3		
		IF Not oRs2.Eof Then
			bid=oRs2("id")
			blist_url=oRs2("list_url")
			blist_name=oRs2("list_name")
			blist_biaoqian=oRs2("list_biaoqian")
			blist_type1=oRs2("list_type1")		
			blist_content=oRs2("list_content")
			blist_gx=oRs2("list_gx")		
			blist_uid=oRs2("list_uid")
			blist_date=oRs2("list_date")	
			blist_no=oRs2("list_no")		
			
			oRs("list_url")=blist_url
			oRs("list_name")=blist_name
			oRs("list_biaoqian")=blist_biaoqian	
			oRs("list_type1")=blist_type1
			oRs("list_content")=blist_content
			oRs("list_gx")=blist_gx
			oRs("list_uid")=blist_uid
			oRs("list_date")=blist_date
			oRs("list_no")=blist_no
			oRs.update()
			
			oRs2("list_url")=alist_url
			oRs2("list_name")=alist_name
			oRs2("list_biaoqian")=alist_biaoqian	
			oRs2("list_type1")=alist_type1
			oRs2("list_content")=alist_content
			oRs2("list_gx")=alist_gx
			oRs2("list_uid")=alist_uid
			oRs2("list_date")=alist_date
			oRs2("list_no")=alist_no
			oRs2.update()		
			str="<script language=""JavaScript"">parent.myfav.msg(""移动成功"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");parent.myfav.reloadSort();var version=1.0;</script>"	
		Else
			str="<script language=""JavaScript"">parent.myfav.msg(""异常错误"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");</script>"
		End IF		
	End IF
	Response.Write str	
End Sub

Sub del()
	scmd=Replace(Request("cmd"),"'","") '判断是否常用软件删除
	sdel_id=Replace(Request("del_id"),"'","")'收藏网址id
	
	IF scmd="delall" Then
		a=Replace(Replace(Request("box[]"),"'","")," ","")
		aa=split(a,",")
		b=""
		For ii=0 To Ubound(aa)
			a1=split(aa(ii),"|")
			b=b&a1(1)&","
		Next
		b=FormatNumSerial(b)
		sql="Delete From qingtiandy_listurl Where Id in("&b&")"
	ElseIF scmd="del_fav" Then
		aa=split(sdel_id,"|")
		b=Bint(aa(1))
		sql="Delete From qingtiandy_listurl Where Id="&b
	End IF
	
	Conn.Execute(sql)
	str="<script language=""JavaScript"">parent.myfav.msg(""删除成功"");parent.myfav.hideDiv(""addNewSort"");parent.myfav.hideDiv(""addFav"");parent.myfav.reloadSort();var version=1.0;</script>"
	Response.Write str
End Sub

Sub getTypeList()
	str=""
	str2=""
	id=left(Replace(Request("id"),"'",""),6)
	vKey=left(Replace(Request("vKey"),"'",""),10)
	
	Sql="Select  * From qingtiandy_listurl Where list_uid="&Request.Cookies(G_u_Cookies)("soojs_id")
	IF id="All" Then
	ElseIF id="unknow" Then
		Sql=Sql&" And list_type1=0"
	Else
		IF id<>"" Then
			id=Bint(id)
			Sql=Sql&" And list_type1="&id
		Else
		
		End IF
	End IF
	
	IF vKey<>"" Then Sql=Sql&" And (list_name like '%"&vKey&"%' or list_url like '%"&vKey&"%')"
	
	Sql=Sql&" Order By list_no Desc,id Desc"

	Set oRs=Server.CreateObject(G_RS)
	oRs.open Sql,Conn,1,1
	IF Not oRs.Eof Then
		count=ubound(oRs.getrows,2)+1
		pagesize=20
		if (count mod pagesize)=0 then pagecount= count \ pagesize else pagecount= (count \ pagesize)+1
		curpage_=StayNub(request("page"))
		if curpage_<>"" then 
			page=int(request("page"))
		Else
			page=1
		End IF
		if page<=0 or page = "" then page=1
		if page>pagecount then page=pagecount
		oRs.movefirst
		oRs.move pagesize*(page-1)
	
		strp_page="action.asp?action=getTypeList&id="&id&"&vKey="&vKey
		strp=""
		if pagecount>1 Then
			if page>1 Then
				strp=strp&"<a href=javascript:void(0) onclick=changePage("""&strp_page&"&page=1"")>首页</a>&nbsp;"
				strp=strp&"<a href=javascript:void(0) onclick=changePage("""&strp_page&"&page="&(page-1)&""")>上一页</a>&nbsp;"
				strp=strp&""&page&"/"&pagecount&"页"
				if page<pagecount Then
					strp=strp&"<a href=javascript:void(0) onclick=changePage("""&strp_page&"&page="&(page+1)&""")>下一页</a>&nbsp;"
					strp=strp&"<a href=javascript:void(0) onclick=changePage("""&strp_page&"&page="&pagecount&""")>尾页</a>&nbsp;"
				else
					strp=strp&"下一页&nbsp;"
					strp=strp&"尾页&nbsp;"		
				end if
			else
				strp=strp&"首页&nbsp;"
				strp=strp&"上一页&nbsp;"
				strp=strp&""&page&"/"&pagecount&"页"
				strp=strp&"<a href=javascript:void(0) onclick=changePage("""&strp_page&"&page="&(page+1)&""")>下一页</a>&nbsp;"
				strp=strp&"<a href=javascript:void(0) onclick=changePage("""&strp_page&"&page="&pagecount&""")>尾页</a>&nbsp;"	
			end if
			strp=strp&"<select onchange=""changePage(this.value);"" name=""selectPage"">"
			For kii=1 To pagecount
				IF Cint(kii)=Cint(page) Then
					strp=strp&"<option selected=""selected""  value="""&strp_page&"&page="&kii&""">第"&kii&"页</option>"
				Else
					strp=strp&"<option  value="""&strp_page&"&page="&kii&""">第"&kii&"页</option>"
				End IF
			Next
			strp=strp&"</select>"
		end if
		
		ki=1
		for i=1 to pagesize
			if oRs.eof then exit for
			l_id=oRs("id")
			l_list_url=oRs("list_url")
			IF instr(l_list_url,"http://")=0 Then l_list_url="http://"&l_list_url
			l_list_name=oRs("list_name")
			l_list_date=ForMatDate(oRs("list_date"),5)
			l_list_no=oRs("list_no")
			l_list_type1=oRs("list_type1")
			str=str&"["""&l_id&""","""&l_list_type1&""","""&l_list_url&""","""&l_list_name&""","""&l_list_date&""","""&l_list_no&"""],"
			ki=ki+1
			oRs.Movenext
		next
		oRs.close
		IF str<>"" Then
			str=left(str,len(str)-1)
		End IF
		str2="myfav.isSearch = false;var favList_1300780159 = new Array("&str&");myfav.setFavList(favList_1300780159);myfav.initFav();myfav.setPage('"&strp&"');myfav.nowPage="&page&";version=1.0;"
	Else
		str2="myfav.isSearch = false;var favList_1300780159 = new Array("&str&");myfav.setFavList(favList_1300780159);myfav.initFav();myfav.setPage('');myfav.nowPage=1;version=1.0;"
	End IF
	
	Response.Write str2	
End Sub

Sub getSortList()
	str=""
	Set oRs2=conn.Execute("Select * From qingtiandy_curl Where c_uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" Order by id Asc")
	Do While Not oRs2.Eof
		oid=oRs2("id")
		oc_typename=oRs2("c_typename")
		oc_no=oRs2("c_no")
		Set oRs3=Conn.Execute("Select Count(*) From qingtiandy_listurl Where list_uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And list_type1="&oid)
		IF Not oRs3.Eof Then
			cTotal=Bint(oRs3(0))
		Else
			cTotal=0
		End IF
		oRs3.close
		
		p1=oid
		p2=oc_typename
		p3=cTotal
		
		str=str&"["""&p1&""","""&p2&""","""&p3&"""],"
		oRs2.MoveNext
	Loop
	oRs2.close
	
	Set oRs4=Conn.Execute("Select Count(*) From qingtiandy_listurl Where list_uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And list_type1=0")
	IF Not oRs4.Eof Then
		cTotal2=Bint(oRs4(0))
	Else
		cTotal2=0
	End IF	
	oRs4.close
	
	Set oRs4=Conn.Execute("Select Count(*) From qingtiandy_listurl Where list_uid="&Request.Cookies(G_u_Cookies)("soojs_id")&" And list_type1>0")
	IF Not oRs4.Eof Then
		cTotal3=Bint(oRs4(0))
	Else
		cTotal3=0
	End IF		
	oRs4.close
	
	IF str<>"" Then
		str=left(str,len(str)-1)
	End IF
	str2="var sortList_1300777026 = new Array("&str&");myfav.setSortList(sortList_1300777026);myfav.sortTotalNum = "&(cTotal3+cTotal2)&";myfav.sortCYNum = 6;myfav.sortUnknowNum = "&cTotal2&";version=1.0;"
	Response.Write str2
End Sub		
%>
