<!--#include file="inc/const.asp"-->
<!--#include file="inc/check.asp"-->
<!--#include file="inc/head.inc"-->
<%
Dim Rs,SQL,i,Action
Dim maxperpage,CurrentPage,totalnumber,TotalPageNum

Call InnerLocation("我的收藏夹")

If CInt(GroupSetting(3)) = 0 Then
	ErrMsg = ErrMsg + "<li>对不起！您没有使用收藏夹的权限，如有什么问题请联系管理员。</li>"
	Founderr = True
End If
Action = NewAsp.CheckStr(LCase(Trim(Request("action"))))
Select Case Trim(Action)
	Case "save","添加"
		Call SaveFavorite
	Case "add"
		Call AddFavorite
	Case "del"
		Call DelFavorite
	Case "清空收藏夹"
		Call DelAllFavorite
	Case Else
		Call showmain
End Select

If Founderr = True Then
	Call ToErrors(ErrMsg)
End If
Sub showmain()
	If Founderr = True Then Exit Sub
	maxperpage = 20 '###每页显示数
	CurrentPage = NewAsp.ChkNumeric(Request("page"))
	If CurrentPage=0 Then CurrentPage=1
%>
<table class="Usertableborder" cellspacing="1" cellpadding="3" align="center" border="0">
	<tr>
		<th colspan="3">&gt;&gt; 我的收藏夹 &lt;&lt;</th>
	</tr>
	<tr>
		<td class="Usertablerow2" align="center" width="65%"><b class="userfont2">标题</b></td>
		<td class="Usertablerow2" align="center" width="23%"><b class="userfont2">收藏时间</b></td>
		<td class="Usertablerow2" align="center" width="12%"><b class="userfont2">操作</b></td>
	</tr>
        <%
	TotalNumber = NewAsp.Execute("SELECT COUNT(FavoriteID) FROM NC_Favorite WHERE username='"& MemberName &"'")(0)
	TotalPageNum = CInt(TotalNumber / maxperpage)  '得到总页数
	If TotalPageNum < TotalNumber / maxperpage Then TotalPageNum = TotalPageNum + 1
	If CurrentPage < 1 Then CurrentPage = 1
	If CurrentPage > TotalPageNum Then CurrentPage = TotalPageNum
	Set Rs = NewAsp.CreateAXObject("ADODB.Recordset")
	SQL = "SELECT * FROM [NC_Favorite] WHERE username='"& MemberName &"' ORDER BY FavoriteID DESC"
	Rs.Open SQL, Conn, 1, 1
	NewAsp.SqlQueryNum = NewAsp.SqlQueryNum + 1
	If Not (Rs.bof And Rs.EOF) Then
		If TotalPageNum > 1 then Rs.Move (CurrentPage - 1) * maxperpage
		i = 0
		Do While Not Rs.EOF And i < CInt(maxperpage)
%>
	<tr>
		<td class="Usertablerow1"><a target="_blank" href="<%=Rs("fondurl")%>"><%=Server.HTMLEncode(Rs("fondtopic"))%></a></td>
		<td class="Usertablerow1" align="center"><%=Rs("addTime")%></td>
		<td class="Usertablerow1" align="center"><a onclick="showClick('删除后将不能恢复，您确定要删除吗?')" href="?action=del&amp;favid=<%=Rs("FavoriteID")%>"><img height="16" alt="删除" width="52" border="0" src="images/delete.gif" /></a></td>
	</tr>
    <%
		Rs.movenext
			i = i + 1
			If i >= maxperpage Then Exit Do
		Loop
	End If
	Rs.Close:Set Rs = Nothing
%>
	<tr>
		<td class="Usertablerow1" align="center" colspan="3"><%Response.Write ShowPages (CurrentPage,TotalPageNum,TotalNumber,maxperpage,"")%></td>
	</tr>
	<tr>
		<th colspan="3">&gt;&gt; 添加收藏 &lt;&lt;</th>
	</tr>
	<form action="" method="post" name="myform">
		<tr>
			<td class="Usertablerow1" align="center" colspan="3"><b class="userfont2">标题：</b><input name="fondtopic" type="text" /> <b class="userfont2">URL：</b><input size="30" name="fondurl" value="http://" type="text" /> <input class="button" type="submit" name="action" value="添加" /> <input class="button" type="submit" onclick="{if(confirm('清空后将不能恢复，确定清除所有的纪录吗?')){this.document.myform.submit();return true;}return false;}" name="action" value="清空收藏夹" /><br />
			<div><b>注意：</b><%If CLng(GroupSetting(5)) <> 0 Then%>你最多只能收藏 <b class="userfont1"><%=GroupSetting(5)%></b>条信息，<%End If%>请定时删除无用的信息。</div>
			</td>
		</tr>
	</form>
</table>
<%
End Sub
'================================================
' 过程名：DelFavorite
' 作  用：删除收藏信息
'================================================
Sub DelFavorite()
	If NewAsp.CheckPost=False Then
		ErrMsg = Postmsg
		Founderr = True
		Exit Sub
	End If
	If Not IsNumeric(Request("favid")) Then
		ErrMsg = ErrMsg + "<li>对不起！您没有使用收藏夹的权限，如有什么问题请联系管理员。</li>"
		Founderr = True
		Exit Sub
	End If
	NewAsp.Execute("DELETE FROM NC_Favorite WHERE username='"& Membername &"' And FavoriteID="& CLng(Request("favid")))
	Call ToSucceed("<li>记录删除成功！</li>")
End Sub
'================================================
' 过程名：DelAllFavorite
' 作  用：清空用户收藏夹
'================================================
Sub DelAllFavorite()
	If NewAsp.CheckPost=False Then
		ErrMsg = Postmsg
		Founderr = True
		Exit Sub
	End If
	NewAsp.Execute("DELETE FROM NC_Favorite WHERE username='"& Membername &"'")
	Call ToSucceed("<li>收藏夹清空完成！</li>")
End Sub
'================================================
' 过程名：SaveFavorite
' 作  用：保存收藏
'================================================
Sub SaveFavorite()
	If NewAsp.ChkRefresh Then
		ErrMsg = ErrMsg + "友情提示!\n\n本页面起用了防刷新机制,请不要连续刷新本页面!"
		Founderr = True
	End If
	If Trim(Request.Form("fondtopic")) = "" Then
		ErrMsg = ErrMsg + "<li>收藏的标题不能为空！</li>"
		Founderr = True
	End If
	If Trim(Request.Form("fondurl")) = "" Then
		ErrMsg = ErrMsg + "<li>收藏的URL不能为空！</li>"
		Founderr = True
	End If
	If CLng(GroupSetting(5)) <> 0 Then
		TotalNumber = NewAsp.Execute("SELECT COUNT(FavoriteID) FROM NC_Favorite WHERE username='"& Membername &"'")(0)
		If CLng(TotalNumber) >= CLng(GroupSetting(5)) Then
			ErrMsg = ErrMsg + "<li>对不起！你最多只能收藏" & GroupSetting(5) & "条信息。</li>"
			Founderr = True
		End If
	End  If
	If Founderr = True Then Exit Sub
	Set Rs = NewAsp.CreateAXObject("ADODB.Recordset")
	SQL = "SELECT * FROM [NC_Favorite] WHERE (FavoriteID is null)"
	Rs.Open SQL, Conn, 1, 3
	Rs.Addnew
		Rs("userid") = memberid
		Rs("username") = Membername
		Rs("fondtopic") = NewAsp.RequestForm(Trim(Request.Form("fondtopic")),80)
		Rs("fondurl") = NewAsp.RequestForm(Request.Form("fondurl"),220)
		Rs("addTime") = Now()
	Rs.update
	Rs.Close:Set Rs = Nothing
	Call ToSucceed("<li>恭喜您！添加收藏成功。</li>")
End Sub
'================================================
' 过程名：AddFavorite
' 作  用：添加收藏
'================================================
Sub AddFavorite()
	Dim fondtopic,fondurl
	If Trim(Request("topic")) = "" Then
		ErrMsg = ErrMsg + "<li>收藏的标题不能为空！</li>"
		Founderr = True
	Else
		fondtopic = Trim(Request("topic"))
	End If
	If CLng(GroupSetting(5)) <> 0 Then
		TotalNumber = NewAsp.Execute("SELECT COUNT(FavoriteID) FROM NC_Favorite WHERE username='"& MemberName &"'")(0)
		If CLng(TotalNumber) >= CLng(GroupSetting(5)) Then
			ErrMsg = ErrMsg + "<li>对不起！你最多只能收藏" & GroupSetting(5) & "条信息。</li>"
			Founderr = True
		End If
	End  If
	If Founderr = True Then Exit Sub
	Set Rs = NewAsp.CreateAXObject("ADODB.Recordset")
	SQL = "SELECT * FROM [NC_Favorite] WHERE (FavoriteID is null)"
	Rs.Open SQL, Conn, 1, 3
	Rs.Addnew
		Rs("userid") = memberid
		Rs("username") = Membername
		Rs("fondtopic") = NewAsp.RequestForm(Trim(fondtopic),80)
		Rs("fondurl") = NewAsp.RequestForm(Request.ServerVariables("HTTP_REFERER"),220)
		Rs("addTime") = Now()
	Rs.update
	Rs.Close:Set Rs = Nothing
	Call ToSucceed("<li>恭喜您！添加收藏成功。</li>")
End Sub
%>
<!--#include file="inc/foot.inc"-->