<!--#include file="user_top.asp"-->
<!--#include file="inc/class_blog.asp"-->
<script language="javascript" src="inc/function.js"></script>
</head>
<body style="background:#fff">
		<ul id="user_page_top">
		<li id="p7"><a href="#" onclick="chk_idAll(myform,1)">全部选择</a></li>
		<li id="p8"><a href="#" onclick="chk_idAll(myform,0)">全部取消</a></li>
		<li id="p4"><a href="#" onclick="if (chk_idBatch(myform,'删除选中的名单吗?')==true) { document.myform.submit();}">删除</a></li>
		<li>&nbsp;&nbsp;</li>
		<li id="p1"><a href="user_friends.asp">好友名单</a></li>
		<li id="p1"><a href="user_friends.asp?action=add">添加好友</a></li>
		<li id="p1"><a href="user_friends.asp?cmd=1">黑名单</a></li>
		<li id="p1"><a href="user_friends.asp?action=add&type=black">添加黑名单</a></li>
	</ul>
<%
dim rs,sql,blog
dim id,cmd,action
cmd=trim(request("cmd"))
action=trim(request("action"))
id=Trim(Request("id") )
If id<>"" Then
	If Instr(id,",")>0 Then
		id=FilterIds(id)
	Else
		id=Int(id)
	End If
End If
if cmd="" then
	cmd=0
else
	cmd=clng(cmd)
end if
G_P_FileName="user_friends.asp?cmd=" & cmd & "&page="
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
%>

</body>
</html>
<%
sub main()
	dim ssql,i,lPage,lAll,lPages,iPage,sGuide,iCount
	sGuide=""
	ssql="id,username,nickname,user_dir,oblog_user.userid,oblog_friend.addtime,user_folder"
	select case cmd
		case 0
			sql="select "&ssql&" from oblog_friend,oblog_user where isblack=0 and oblog_friend.userid="&oblog.l_uid&" and oblog_friend.friendid=oblog_user.userid order by id desc"
			sGuide=sGuide & "好友列表"
		case 1
			sql="select "&ssql&" from oblog_friend,oblog_user where isblack=1 and oblog_friend.userid="&oblog.l_uid&" and oblog_friend.friendid=oblog_user.userid order by id desc"
			sGuide=sGuide & "黑名单"
		case else
	end select
	Set rs=Server.CreateObject("Adodb.RecordSet")
	'response.Write(sql)
	rs.Open sql,Conn,1,1
  iCount=rs.RecordCount
  '分页处理
  lAll=INT(rs.recordcount)
    If lAll=0 Then    	
    	rs.Close
    	Set rs=Nothing
    	%>
    	<div id="user_page_content">
		   <div id="content_li">
		   	<ul class="content_li_conten">
		   		<li class="t1"></li>
		   		<li class="t3">&nbsp;</li>
		   	</ul>
		   	<ul class="content_li_conten">
		   		<li class="t1"></li>
		   		<li class="t3"><%=sGuide & " 没有相关纪录" %></li></ul>
		  	</div>
		  </div>
    	<%
    	Exit Sub
    End If
    i=0
    iPage=12
	'分页
	If Request("page") = "" Or Request("page") ="0" then
		lPage = 1
	Else
		lPage = Int(Request("page"))
	End If
	
	'设置缓存大小 = 每页需显示的记录数目
	rs.CacheSize = iPage
	rs.PageSize = iPage
	rs.movefirst		
	lPages = rs.PageCount
	If lPage>lPages Then lPage=lPages
	rs.AbsolutePage = lPage
	i=0
	Dim sKey
	If cmd="1" Then 
		sKey="黑名单"
	Else
		sKey="好友"
	End If
%>
<style type="text/css">
<!--
	.content_li_top .t2 {width:88px;padding:0 0 0 10px;margin:-2px 0 0 0;}
	.content_li_top .t3 {width:38%;text-align:left}
	.content_li_top .t4 {width:170px; text-align:left}
	.content_li_top .t5 {width:100px;text-align:left;}
	#content_li .content_li_conten .t2 {width:85px;margin:-2px 0 0 0;text-align:left}
	#content_li .content_li_conten .t3 {width:38%;line-height:1.5;margin:-2px 0 0 0;text-align:left;overflow:hidden;color:#888;font-size:10px;}
	#content_li .content_li_conten .t4 {width:180px;text-align:center}
	#content_li .content_li_conten .t5 {width:120px;text-align:left}
-->
</style>
	<div id="showpage">	 	
	  <%=MakeMiniPageBar(lAll,iPage,lPage,G_P_FileName)%>
	</div>
	<div id="user_page_content">
		<ul class="content_li_top">
				<li class="t1">选中</li>
				<li class="t2"><%=sKey%>ID</li>
				<li class="t4"><%=sKey%>昵称</li>
				<li class="t3">添加时间</li>
				<li class="t5">操作</li>
				</ul>
				<ul class="list_top">
			 <div id="content_li">
				<form name="myform" method="Post" action="user_friends.asp?action=del&cmd=<%=cmd%>" onSubmit="return confirm('确定要执行选定的操作吗？');">		
	<%do while not rs.eof
		%>
		
		<ul class="content_li_conten" id="u<%=rs("id")%>"  onclick="chk_iddiv('<%=rs("id")%>')">		
	<li class="t1"><input name='id' type='checkbox' id="c<%=cstr(rs("id"))%>"   onclick="chk_iddiv('<%=cstr(rs("id"))%>')" value='<%=cstr(rs("id"))%>' onclick="chk_iddiv('<%=rs("id")%>')" /></li>
	<li class="t2"><a href="<%="go.asp?user="&rs("username")%>" target=_blank><%=oblog.filt_html(rs("username"))%>  </a> </li>
	<li class="t4"><%oblog.filt_html(rs("nickname"))%></li>
	<li class="t3"> <%=OB_IIF(rs("addtime"),"&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>=iPage then exit do
	rs.movenext
loop
%>
	</form>
</div>
<%
end sub

sub add()
dim str1,str2
if request("type")="black" then
	str1="添加黑名单"
	str2="黑名单用户名："
else
	str1="添加好友"
	str2="好友用户名："
end if	
%>
	<form action="user_friends.asp?action=saveadd&type=<%=request("type")%>" method="post" name="oblogform">
	<table  class="dTab12_body" align="center" border="0" cellpadding="0" cellspacing="1">
	  <tr>
		<td colspan="2" class="dTab12_body_top"><%=str1%></td>
	  </tr>
	  <tr>
		<td colspan="2" >	
			<%if request("type")="black" then%>
			加入黑名单以后，就不会受到这个用户的短信骚扰了。
			<%else%>
			把用户加为好友，可以方便的发送站内短信，还可以和好友共享私密日志!
			<%end if%>
		</td>
	</tr>
	<tr><td class="dTab12_body_td">	<%=str2%></td>
	<td><input name="friendname" type=text size="20" maxlength="30" value="<%=request("friendname")%>"/></td></tr>
	<%if request("type")<>"black" then%>
	<tr><td class="dTab12_body_td">	同时订阅：</td>
	<td><input type="checkbox" value="true" name="is_sub" checked="checked" /></td></tr>
	<%end if%>
	<tr><td class="dTab12_body_td">	</td>
	<td><input type="submit" value=" 提交 " /></td></tr>
	</table>
	</form>
	
<%
end sub

sub saveadd()
	dim friendname,uid,isblack,surl,ublogname,rs1
	friendname=oblog.filt_badstr(trim(request("friendname")))
	if friendname="" then
		oblog.adderrstr("错误：添加用户名不能为空")
		oblog.showusererr
		exit sub
	end if
	If friendname=oblog.l_uname Then
		oblog.adderrstr("错误：不能将自己添加为自己的好友或黑名单!")
		oblog.showusererr
		exit sub
	End If
	if request("type")="black" then isblack=1 else isblack=0
	sql="select userid,blogname,user_dir,user_folder 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("userid")
	surl=blogurl&rs("user_dir")&"/"&rs("user_folder")&"/rss2.xml"
	ublogname=rs("blogname")
	set rs=oblog.execute("select id from oblog_friend where userid="&oblog.l_uid&" and friendid="&uid&" and isblack="&isblack)
	if rs.eof then
		oblog.execute("insert into [oblog_friend] (userid,friendid,isblack) values ("&oblog.l_uid&","&uid&","&isblack&")")
		update_friends()
		'写入订阅
		if isblack=0 and request("is_sub")="true" then
			Set rs1=Server.CreateObject("Adodb.Recordset")
			rs1.Open "Select * From oblog_myurl Where userid="&oblog.l_uid&" and url='"&oblog.filt_badstr(surl)&"'",conn,1,3
			if not rs1.eof then
				rs1.close
			else
				rs1.AddNew
				rs1("classid") = 0
				rs1("subjectid")=0
				rs1("url")=sUrl
				rs1("userid")=oblog.l_uid
				rs1("addtime") = ServerDate(Now)
				rs1("encodeing")="gb2312"
				rs1("title")=ublogname
				rs1("mainuserid")=uid
				rs1("isupdate")=1
				rs1.Update
				rs1.Close
				set rs1=nothing
				oblog.execute("update oblog_user set sub_num=sub_num+1 where userid="&uid)			
			end if
		end if
		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
		oblog.execute("delete from [oblog_friend] where userid=" & oblog.l_uid &" and id In ("&id & ")")
	Else
		oblog.execute("delete from [oblog_friend] where userid=" & oblog.l_uid &" and id ="&id )
	End If
	update_friends()
	oblog.showok "删除成功！",""
end sub

sub update_friends()
	dim blog
	set blog=new class_blog
	blog.userid=oblog.l_uid
	blog.update_friends oblog.l_uid
	set blog=nothing
end sub
%>