<!-- #Include File="Con_User.asp" -->
<!-- #Include File="../Include/Cls_pagecute.asp" -->
<%
'=======================================================
' 欢迎使用《阿赛大型门户网站系统V3.0》，简称“AsaiMHV3”
' 技术支持、商业版咨询、官方唯一指定联系QQ“4941172”
' 官方网站：http://77ya.com      程序负责人：阿赛
'=======================================================

tit="我的好友"
if action<>"" then
  call DoWebHead(2,1)
else
  call DoWebHead(2,0)
End If
'----------------------------左边 开始----------------------------
'----------------------------左边 结束----------------------------
'----------------------------中间 开始----------------------------
if action="add" and Cls.chk()=false then action=""
select case action
case "add"
  call AsaiMHUserFriend_Add()
case "clear"
  call AsaiMHUserFriend_Clear()
case "delete"
  call AsaiMHUserFriend_Delete()
case else
  call AsaiMHUserFriend_Main()
end select
'----------------------------中间 结束----------------------------
call DoWebEnd()

sub AsaiMHUserFriend_Clear()
  sql="delete from AsaiMHUserFriend where username1='"&login_username&"'"
  call Cls.exec(sql,0)
  Call Cls.Out_Msg("已成功清空全部好友信息！","?")
End Sub

sub AsaiMHUserFriend_Delete()
  dim sel_id,sdim,snum
  sel_id=trim(request.form("sel_id"))
  sel_id=replace(sel_id," ","")
  sdim=split(sel_id,",")
  snum=ubound(sdim)
  for i=0 to snum
    if isnumeric(sdim(i)) then
      sql="delete from AsaiMHUserFriend where username1='"&login_username&"' and id="&sdim(i)
      call Cls.exec(sql,0)
    End If
  next
  erase sdim
  Call Cls.Out_Msg("已成功删除"&(snum+1)&"位我的好友！","?")
End Sub

sub AsaiMHUserFriend_Add()
  dim username,utrue
  username=trim(request.form("username"))
  if ChkName(username)=false then
    Call Cls.Out_Msg("要添加的好友用户名称为空或含有非法字符！","?")
    exit sub
  End If
  set rs=Cls.exec("select top 1 username from AsaiMHUserData where username='"&username&"'",1)
  if rs.eof then
    rs.close
	Call Cls.Out_Msg("要添加的好友用户名称为不存在！","?")
    exit sub
  End If
  rs.close
  set rs=Cls.exec("select top 1 username2 from AsaiMHUserFriend where username2='"&username&"' and username1='"&login_username&"'",1)
  if not rs.eof then
    rs.close
    Call Cls.Out_Msg("要添加的好友已在您的好友列表内！","?")
    exit sub
  End If
  rs.close
  call Cls.exec("insert into AsaiMHUserFriend(username1,username2) values('"&login_username&"','"&username&"')",0)
  Call Cls.Out_Msg("已成功将用户（"&username&"）加入到您的好友列表内！","?")
End Sub

sub AsaiMHUserFriend_Main()
  dim pageurl,username,sex,sex_name,keyword,sql_add,sql_add2,web_n_sex,sTmp
  pageurl="?"
  sql_add=""
  sql_add2=""
  keyword=Cls.Code_Var(request.querystring("keyword"))
  if keyword<>"" then
    sql_add=" and username2 like '%"&keyword&"%'"
    sql_add2=" and AsaiMHUserFriend.username2 like '%"&keyword&"%'"
  End If
	Dim obj_page
	Set obj_page=new Cls_PageCute
	obj_page.pageurl="?keyword="&server.urlencode(keyword)&"&"		
	obj_page.nummer=Format_Mid_Num(12)						
	obj_page.page_t=1									
	obj_page.page_p=5									
	obj_page.page_unit="位"
	obj_page.page_tit="好友"
	obj_page.v_id="id"
	Call obj_page.p_init("id,topic","AsaiMHUserFriend","username1='"&login_username&"'","id desc")
	SQL = obj_page.sql_count
	Set rs=Cls.Exec(SQL,1)
	obj_page.rssum=rs(0)
	Rs.Close
	Call obj_page.p_info()
  sql="select top "&obj_page.nummer*obj_page.viewpage&" AsaiMHUserFriend.id,AsaiMHUserFriend.username2,AsaiMHUserData.power,AsaiMHUserData.sex,AsaiMHUserData.integral,AsaiMHUserData.emoney " & _
      "from AsaiMHUserFriend,AsaiMHUserData where AsaiMHUserFriend.username2=AsaiMHUserData.username and AsaiMHUserFriend.username1='"&login_username&"'"&sql_add&" order by AsaiMHUserFriend.id"
  Call Cls.Exe_Conn(Rs,SQL,1)
  For i=1 To obj_page.page_num
    username=rs("username2")
    sex="boy"
    web_n_sex=Cls.Web_Boy
    if rs("sex")=false then
      sex="girl"
      web_n_sex=Cls.Web_girl
    End If
sTmp=sTmp&"<tr class=tr0 align=center>" & _
vbcrlf&"<td>"&obj_page.page_now+i&"</td>" & _
vbcrlf&"<td>"&format_user_name(username,0,"")&"</td>" & _
vbcrlf&"<td><img border=0 src='"&Cls.web_skindir&"sys/icon_"&format_power(rs("power"),0)&".gif' title='"&username&" 是 "&format_power(rs("power"),1)&"' align=absmiddle></td>" & _
vbcrlf&"<td><img border=0 src='"&Cls.web_skindir&"sys/"&sex&".gif' title='"&username&" 是 "&web_n_sex&"' align=absmiddle></td>" & _
vbcrlf&"<td align=right>"&rs("integral")&"&nbsp;<font class=Gys>分</font></td>" & _
vbcrlf&"<td align=right><font class=red2>"&rs("emoney")&"</font>&nbsp;"&Cls.web_unit&"</td>" & _
vbcrlf&"<td><a href='Mail.asp?action=msg_write&accept="&server.urlencode(username)&"' target=_blank><img src='"&Cls.web_skindir&"mail/msg.gif' title='给 "&username&" 发送短信' border=0></a></td>" & _
vbcrlf&"<td><input type=checkbox name=sel_id value='"&rs("id")&"' ></td>" & _
vbcrlf&"</tr>"
    rs.movenext
  next
  rs.close
%>
<script language=javascript>
<!--
function friend_clear()
{
  if (confirm('确定清空所有的好友吗?\n\n清空后将无法恢复！'))
  { location.href='?action=clear'; }
}
-->
</script>
<%
    Cls.HtmlRcod "body",Cls.ReadTemplate ("user_Friend")
  Cls.HtmlRcod "body",sTmp
  Cls.HtmlRcod "tit",tit
  Cls.HtmlRcod "add_username",Cls.code_admin("add_username",2,20)
  Cls.HtmlRcod "img_user",img_user()
  Cls.HtmlRcod "ends","<tr class=tr0><td colspan=8><div id=asaipage>"&obj_page.page_var&" "&obj_page.page_cute&" "&obj_page.page_shortcut&"</div></td></tr><tr><td colspan=8 align=right class=tr1><table border=0 cellspacing=0 cellpadding=1><tr><td><input type=checkbox name=sel_all value='yes' onclick=""javascript:select_all(this.form);"" s>所有</td><td><input class=btn type=submit value='删除所选' onclick=""javascript:return sel_click(this.form);""></td><td><input class=btn type=button onclick=""javascript:friend_clear();"" value='清空所有'></td></tr></table></td></tr>"
  Cls.OutPage
  set obj_page=nothing
End Sub
%>
