<!--#include file="user_top.asp"-->
<!--#include file="inc/class_blog.asp"-->
<div id="main">
  <div class="submenu">
  	<div class="side_c1 side11"></div>
    <div class="side_c2 side21"></div>
	<div class="submenu_content">
		&#8226; <a href="user_friends.asp">好友管理</a>
		&#8226; <a href="user_friends.asp?action=add">添加好友</a>
		&#8226; <a href="user_friends.asp?usersearch=1">黑名单管理</a>
		&#8226; <a href="user_friends.asp?action=add&type=black">添加黑名单</a>
	</div>
  </div>
  <div class="content">
  	<div class="content_top">
		  	<div class="side_d1 side11"></div>
		    <div class="side_d2 side21"></div>
			好友及黑名单管理
	</div>
	
    <div class="content_body">
<%const MaxPerPage=20
dim strFileName,totalPut,TotalPages
dim rs,sql,blog
dim id,usersearch,action
usersearch=trim(request("usersearch"))
action=trim(request("action"))
id=oblog.filt_badstr(trim(Request("id")))
if usersearch="" then
	usersearch=0
else
	usersearch=clng(usersearch)
end if
strFileName="user_friends.asp?usersearch=" & usersearch
if request("page")<>"" then
    currentPage=cint(request("page"))
else
	currentPage=1
end if
select case action
	case "add"
	call add()
	case "saveadd" 
	call saveadd()
	case "del" 
	call del()
	case else
	call main()
end select
set rs=nothing
set blog=nothing
%>
	</div>
	
    <div class="content_bot">
		  	<div class="side_e1 side12"></div>
   			<div class="side_e2 side22"></div>
 	</div>
	
  </div>
</div>  
  
  
  <div id="bottom"><%=oblog.user_copyright%></div>

</body>
</html>
<%
sub main()
%>
<style type="text/css">
<!--
	#list ul{ width: 90%} 
	#list ul li.t1 { width: 60px} 
	#list ul li.t2 { width: 120px} 
	#list ul li.t3 { width: 120px} 
	#list ul li.t4 { width: 200px} 
	#list ul li.t5 { width: 160px} 
-->
</style>

	<h1>

<%
	dim strGuide,ssql
	ssql="id,username,nickname,user_dir,oblog_user.userid,oblog_friend.addtime,oblog_user.user_folder"
	strGuide="当前选择&nbsp;&gt;&gt;&nbsp;"
	select case usersearch
		case 0
			sql="select "&ssql&" from oblog_friend,oblog_user where isblack=0 and oblog_friend.userid="&oblog.logined_uid&" and oblog_friend.friendid=oblog_user.userid order by id desc"
			strGuide=strGuide & "好友列表"
		case 1
			sql="select "&ssql&" from oblog_friend,oblog_user where isblack=1 and oblog_friend.userid="&oblog.logined_uid&" and oblog_friend.friendid=oblog_user.userid order by id desc"
			strGuide=strGuide & "黑名单"
		case else
	end select
	Set rs=Server.CreateObject("Adodb.RecordSet")
	'response.Write(sql)
	rs.Open sql,Conn,1,1
  	if rs.eof and rs.bof then
		strGuide=strGuide & " (共有0个)</h1></div>"
		response.write strGuide
	else
    	totalPut=rs.recordcount
		strGuide=strGuide & " (共有" & totalPut & "个)</h1>"
		response.write strGuide
		if currentpage<1 then
       		currentpage=1
    	end if
    	if (currentpage-1)*MaxPerPage>totalput then
	   		if (totalPut mod MaxPerPage)=0 then
	     		currentpage= totalPut \ MaxPerPage
		  	else
		      	currentpage= totalPut \ MaxPerPage + 1
	   		end if
    	end if
	    if currentPage=1 then
        	showContent
        	response.write oblog.showpage(strFileName,totalput,MaxPerPage,true,true,"个纪录")
   	 	else
   	     	if (currentPage-1)*MaxPerPage<totalPut then
         	   	rs.move  (currentPage-1)*MaxPerPage
         		dim bookmark
           		bookmark=rs.bookmark
            	showContent
            	response.write oblog.showpage(strFileName,totalput,MaxPerPage,true,true,"个纪录")
        	else
	        	currentPage=1
           		showContent
           		response.write oblog.showpage(strFileName,totalput,MaxPerPage,true,true,"个纪录")
	    	end if
		end if
	end if
	rs.Close
	set rs=Nothing
end sub

sub showContent()
   	dim i
    i=0
%>
<div id="list">
  <form name="myform" method="Post" action="user_friends.asp" onSubmit="return confirm('确定要执行选定的操作吗？');">
	<ul class="list_top">
	<li class="t1">选中</li>
	<li class="t2">好友ID</li>
	<li class="t3">好友昵称</li>
	<li class="t4">添加时间</li>
	<li class="t5">操作</li>
	</ul>
	<%do while not rs.eof %>
	<ul class="list_content" onMouseOver="fSetBg(this)" onMouseOut="fReBg(this)"> 
	<li class="t1" ><input name='id' type='checkbox' onClick="unselectall()" id="id" value='<%=cstr(rs("id"))%>'></li>
	<li class="t2"><a href="<%=rs("user_dir")&"/"&rs("user_folder")&"/index."&f_ext%>" target=_blank><%=oblog.filt_html(rs("username"))%>  </a> </li>
	<li class="t3"><%oblog.filt_html(rs("nickname"))%></li>
	<li class="t4"> <%if rs("addtime")<>"" then	response.write rs("addtime") else response.write "&nbsp;" %> </li>
	<li class="t5">
<%
		response.write "<a href='user_friends.asp?action=del&id=" & rs("id") &"' onClick='return confirm(""确定要删除吗？"");'>删除</a>"
		response.write " <a href=""javascript:openScript('user_pm.asp?action=send&incept="&oblog.filt_html(rs("username"))&"',450,400)"">发送短信</a>"
%> </li>
	</ul>
<%
	i=i+1
	if i>=MaxPerPage then exit do
	rs.movenext
loop
%>
	<ul class="list_bot">
	<input name="chkAll" type="checkbox" id="chkAll" onClick="CheckAll(this.form)" value="checkbox" />
	 全选
	<input name="action"  type="hidden" value="del" />
	<input type="submit" name="Submit" value="批量删除" />
	</ul>
	</form>
</div>
<%
end sub

sub add()
dim str1,str2
if request("type")="black" then
	str1="添加黑名单"
	str2="黑名单用户名："
else
	str1="添加好友"
	str2="好友用户名："
end if	
%>
<h1><%=str1%></h1>
<div id="list">
	<ul class="list_edit"> 
	<%if request("type")="black" then%>
	加入黑名单以后，就不会受到这个用户的短信骚扰了。
	<%else%>
	把用户加为好友，可以方便的发送站内短信，还可以和好友共享私密日志!
	<%end if%>
	<hr>
	<form action="user_friends.asp?action=saveadd&type=<%=request("type")%>" method="post" name="oblogform">
	<%=str2%>
	<input name="friendname" type=text size="20" maxlength="30" />
	<input type="submit" value="添加" />
	</form>
	</ul>
</div>
<%
end sub

sub saveadd()
	dim friendname,uid,isblack
	friendname=oblog.filt_badstr(trim(request("friendname")))
	if friendname="" then
		oblog.adderrstr("错误：添加用户名不能为空")
		oblog.showusererr
		exit sub
	end if
	if request("type")="black" then isblack=1 else isblack=0
	sql="select userid from oblog_user where username='"&friendname&"'"
	set rs=oblog.execute(sql)
	if rs.eof then
		oblog.adderrstr("错误：无此用户")
		oblog.showusererr
		exit sub
	end if
	uid=rs(0)
	'判断时都存在与好友/黑名单中名单中
	set rs=oblog.execute("select id from oblog_friend where userid="&oblog.logined_uid&" and friendid="&uid&" and isblack="&ABS(isblack-1))
	If Not rs.Eof Then
		If isblack="0" Then
			oblog.adderrstr("错误：该用户已经存在于你的黑名单中，请先从黑名单中删除，然后再进行添加")
		Else
			oblog.adderrstr("错误：该用户已经存在于你的好友名单中，请先从好友名单中删除，然后再进行添加")
		End If
		oblog.showusererr
		exit sub
	End If
	set rs=oblog.execute("select id from oblog_friend where userid="&oblog.logined_uid&" and friendid="&uid&" and isblack="&isblack)
	if rs.eof then
		oblog.execute("insert into [oblog_friend] (userid,friendid,isblack) values ("&oblog.logined_uid&","&uid&","&isblack&")")
		set rs=nothing
		oblog.showok "添加成功","user_friends.asp"
	else
		set rs=nothing
		oblog.adderrstr("错误：此用户已经在列表中")
		oblog.showusererr
	end if
end sub


sub del()
	if id="" then
		oblog.adderrstr( "错误：请指定要删除的对象！")
		oblog.showusererr
		exit sub
	end if
	if instr(id,",")>0 then
		dim n,i
		id=FilterIDs(id)
		n=split(id,",")
		for i=0 to ubound(n)
			delone(n(i))
		next
	else
		delone(id)
	end if
	set rs=nothing
	oblog.showok "删除成功！",""
end sub

sub delone(id)
	id=clng(id)
	sql="delete from [oblog_friend] where id=" & clng(id)&" and userid="&oblog.logined_uid
	oblog.execute(sql)
end sub
%>