<!--#include file="conn.asp"-->
<!-- #include file="inc/const.asp" -->
<!--#include file="inc/dv_clsother.asp"-->
<%
Dim ErrCodes,Rs,Sql,TempLateStr
Dim AnnounceID,RootID,Topic,Url

If Request("action")="add" Then
	FavAdd_Main()
Else
	Main()
End If
Dvbbs.ActiveOnline()
Dvbbs.Footer()

Sub Main()
	Dvbbs.LoadTemplates("usermanager")
	Dvbbs.Stats=Dvbbs.MemberName&template.Strings(6)
	Dvbbs.Nav()
	Dvbbs.Head_var 0,0,template.Strings(0),"usermanager.asp"
	If Dvbbs.UserID=0 Then
		Dvbbs.AddErrCode(6)
		Dvbbs.Showerr()
	End If
	Response.Write Template.Html(0)
	TempLateStr=Split(template.html(17),"||")
	TempLateStr(1)=Replace(TempLateStr(1),"{$fav_del}",template.pic(13))

	If request("action")="delet" Then
		call delete()
	Else
		Response.Write TempLateStr(0)
		Response.Write TempLateStr(1)
		call favlist()
	End If
	If ErrCodes<>"" Then Response.redirect "showerr.asp?ErrCodes="&ErrCodes&"&action=OtherErr"
	Dvbbs.Showerr()
End Sub

Sub FavAdd_Main()
	Dvbbs.LoadTemplates("postjob")
	Dvbbs.stats=template.Strings(7)
	Dvbbs.nav()
	If Dvbbs.UserID=0 Then
		Dvbbs.AddErrCode(6)
	End If
	If Request("id")="" Then
		Dvbbs.AddErrCode(43)
	ElseIf Not Isnumeric(Request("id")) Then 
		Dvbbs.AddErrCode(30)
	Else
		AnnounceID=Clng(Request("id"))
	End If
	Dvbbs.ShowErr()
	Url = "dispbbs.asp?"
	Url = Url & "boardid="&Dvbbs.BoardID&"&id="&AnnounceID
	Call chkurl()
	Dvbbs.ShowErr()
	Call favadd()
	Dvbbs.ShowErr()
	Dvbbs.head_var 1,Dvbbs.BoardNode.attributes.getNamedItem("depth").text,"",""
	Dvbbs.Dvbbs_suc("<li>"&template.Strings(8))
End Sub


Sub favlist()
	Dim currentPage,page_count,totalrec,Pcount,PageListNum,i
	PageListNum=Cint(Dvbbs.Forum_Setting(11))
	currentPage=Request("page")
	If currentpage="" or not IsNumeric(currentpage) Then
		currentpage=1
	Else
		currentpage=clng(currentpage)
	End If
	set Rs=server.createobject("adodb.recordset")
	Sql="Select * From Dv_bookmark Where UserName='"&Dvbbs.membername&"' Order By id Desc"
	Dvbbs.SqlQueryNum=Dvbbs.SqlQueryNum+1
	If Not IsObject(Conn) Then ConnectionDatabase
	Rs.Open SQL,Conn,1,1
	If Rs.eof And Rs.bof Then
		ErrCodes=ErrCodes+"<li>"+template.Strings(50)
		Exit Sub
	Else
		Rs.PageSize = PageListNum
		Rs.AbsolutePage=currentpage
		page_count=0
		totalrec=Rs.recordcount
		Do While Not Rs.eof And (Not page_count = Rs.PageSize)
		Response.Write "<script>dvbbs_favlist_loop('"&rs("url")&"','"&EncodeJS(rs("topic"))&"','"&rs("addtime")&"',"&rs("id")&")</script>"
		page_count = page_count + 1
		Rs.movenext
		Loop
	End If
	Rs.close:Set rs=nothing
	If totalrec mod PageListNum=0 Then
     	Pcount= totalrec \ PageListNum
  	Else
     	Pcount= totalrec \ PageListNum+1
  	End If
	If page_count=0 Then CurrentPage=0
	Response.Write ShowPage(CurrentPage,Pcount,totalrec,PageListNum)
	Response.Write TempLateStr(2)
End Sub

Sub delete()
	If Dvbbs.chkpost=False Then
		Dvbbs.AddErrCode(16)
		Exit Sub
	End If
	If IsNumeric(request("id")) Then
		Sql="Delete From Dv_bookmark where Username='"&Dvbbs.membername&"' And Id="&cstr(request("id"))
		Dvbbs.Execute Sql
	End If
	Dvbbs.Dvbbs_Suc("<li>"+template.Strings(46))
End Sub

'·ÖÒ³Êä³ö
Function ShowPage(CurrentPage,Pcount,totalrec,PageNum)
	Dim SearchStr
	SearchStr=Request("action")
	ShowPage=template.html(16)
	ShowPage=Replace(ShowPage,"{$colSpan}",3)
	ShowPage=Replace(ShowPage,"{$CurrentPage}",CurrentPage)
	ShowPage=Replace(ShowPage,"{$Pcount}",Pcount)
	ShowPage=Replace(ShowPage,"{$PageNum}",PageNum)
	ShowPage=Replace(ShowPage,"{$totalrec}",totalrec)
	ShowPage=Replace(ShowPage,"{$SearchStr}",SearchStr)
	ShowPage=Replace(ShowPage,"{$redcolor}",Dvbbs.mainsetting(1))
End Function

Function EncodeJS(str)
	EncodeJS = Replace(Replace(Replace(Replace(str,"\","\\"),"'","\'"),VbCrLf,"\n"),chr(13),"")
End Function

Sub ChkUrl()
	Sql="Select Title From Dv_Topic Where TopicID="&AnnounceID
	Set Rs=Dvbbs.Execute(Sql)
	If Rs.Eof And Rs.Bof Then
		Dvbbs.AddErrCode(48)
	Else
		Topic=Dvbbs.HtmlEnCode(rs(0))
	End If
	Rs.Close:Set Rs=Nothing
End Sub
Sub favadd()
	Sql="Select * From Dv_bookmark Where UserName='"&Dvbbs.Membername&"' And Url='"&Url&"'"
	Set Rs=Server.Createobject("Adodb.Recordset")
	If Not IsObject(Conn) Then ConnectionDatabase
	Rs.Open Sql,Conn,1,3
	If Not (Rs.Eof And Rs.Bof) Then
		Dvbbs.AddErrCode(53)
	Else
		Rs.Addnew
		Rs("username")=Dvbbs.membername
		Rs("topic")=Left(Dvbbs.checkStr(trim(topic)),100)
		Rs("url")=Dvbbs.checkStr(trim(url))
		Rs("addtime")=Now()
		Rs.Update
	End If
	Rs.Close:set Rs=Nothing
End Sub
%>