<!-- #include file="include/config.asp" -->
<!-- #include file="../include/jk_pagecute.asp" -->
<!-- #include file="../include/jk_page_cute.asp" -->
<%
dim nummer,nums,rssum,page,viewpage,thepages
nummer=dim_num(0)
nums=nummer
page=1
tit="我的好友"

if action<>"" then
  call web_head(2,1,0,0,0)
else
  call web_head(2,0,0,0,0)
end if 
'----------------------------左边 开始----------------------------
call user_left(1)
'----------------------------左边 结束----------------------------
call web_center(0)
'----------------------------中间 开始----------------------------
response.write joekoe_cms.js_put("../style/hscms_select.js",0)

if action="add" and joekoe_cms.chk()=false then action=""

select case action
case "add"
  call user_friend_add()
case "clear"
  call user_friend_clear()
case "delete"
  call user_friend_delete()
case else
  call user_friend_main()
end select

response.write ukong
'----------------------------中间 结束----------------------------
call web_end(0,0)

sub user_friend_clear()
  sql="delete from user_friend where username1='"&login_username&"'"
  call joekoe_cms.exec(sql,0)
  call web_js_msg(1,"已成功清空全部好友信息！","?")
end sub

sub user_friend_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 user_friend where username1='"&login_username&"' and id="&sdim(i)
      call joekoe_cms.exec(sql,0)
    end if
  next
  erase sdim
  call web_js_msg(1,"已成功删除"&(snum+1)&"位我的好友！","?")
end sub

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

sub user_friend_main()
  dim pageurl,username,sex,sex_name,keyword,sql_add,sql_add2,web_n_sex
  pageurl="?"
  sql_add=""
  sql_add2=""
  keyword=joekoe_cms.code_form(request.querystring("keyword"))
  if keyword<>"" then
    sql_add=" and username2 like '%"&keyword&"%'"
    sql_add2=" and user_friend.username2 like '%"&keyword&"%'"
  end if
  sql="select count(id) from user_friend where username1='"&login_username&"'"&sql_add
  set rs=joekoe_cms.exec(sql,1)
  rssum=rs(0)
  rs.close
  call format_pagecute()
%>
<table cellspacing=1 cellpadding=4 class=table>
<tr><td class=td>&nbsp;<%response.write tit%>&nbsp;-&nbsp;相关操作</td></tr>
<tr><td class=tr align=center>
  <table border=0 width='100%'>
  <tr align=center>
  <td width='50%'>
    <table border=0>
    <form action='?' method=get onsubmit="javascript:frm_submitonce(this);">
    <input type=hidden name=action value='search'>
    <tr>
    <td>好友名称：</td>
    <td><input type=text name=keyword value='<%response.write keyword%>' size=15 maxlength=20></td>
    <td><input type=submit class=btn value='查找好友'></td>
    </tr>
    </form>
    </table>
  </td>
  <td width='50%'>
    <table border=0>
    <form action='?action=add' method=post onsubmit="javascript:frm_submitonce(this);">
    <input type=hidden name=chk value='yes'>
    <tr>
    <td>好友名称：</td>
    <td><input type=text name=username value='<%response.write code_admin("add_username",2,20)%>' size=15 maxlength=20></td>
    <td><input type=submit class=btn value='添加好友'></td>
    </tr>
    </form>
    </table>
  </td>
  </tr>
  </table>
</td></tr>
</table>
<%=ukong%>
<table cellspacing=1 cellpadding=4 class=table>
<form name=del_form action='?action=delete' method=post onsubmit="javascript:frm_submitonce(this);">
<input type=hidden name=chk value='yes'>
<tr align=center>
<td width='7%' class=td>序号</td>
<td width='37%' class=td>好友用户名称</td>
<td width='7%' class=td>类型</td>
<td width='7%' class=td>性别</td>
<td width='14%' class=td>积分</td>
<td width='14%' class=td>财富</td>
<td width='7%' class=td>短信</td>
<td width='7%' class=td>操作</td>
</tr>
<%
  sql="select top "&nummer*viewpage&" user_friend.id,user_friend.username2,user_data.power,user_data.sex,user_data.integral,user_data.emoney " & _
      "from user_friend,user_data where user_friend.username2=user_data.username and user_friend.username1='"&login_username&"'"&sql_add&" order by user_friend.id"
  call joekoe_cms.exec("",-1)
  rs.open sql,conn,1,1
  if int(viewpage)>1 then rs.move (viewpage-1)*nummer
  if int(viewpage*nummer)>int(rssum) then nums=nummer-(viewpage*nummer-rssum)
  for i=1 to nums
    username=rs("username2")
    sex="boy"
    web_n_sex=web_n_boy
    if rs("sex")=false then
      sex="girl"
      web_n_sex=web_n_girl
    end if
%>
<tr class=tr align=center>
<td><%response.write (viewpage-1)*nummer+i%></td>
<td><%response.write format_user_name(username,0,"")%></td>
<td><img border=0 src='<%response.write joekoe_cms.web_dir_skin%>small/icon_<%response.write format_power(rs("power"),0)%>.gif' alt='<%response.write username%> 是 <%response.write format_power(rs("power"),1)%>' align=absmiddle></td>
<td><img border=0 src='<%response.write joekoe_cms.web_dir_skin%>small/<%response.write sex%>.gif' alt='<%response.write username%> 是 <%response.write web_n_sex%>' align=absmiddle></td>
<td align=right><%response.write rs("integral")%>&nbsp;<font class=gray>分</font></td>
<td align=right><font class=red2><%response.write rs("emoney")%></font>&nbsp;<%response.write img_emoney%></td>
<td><a href='mail.asp?action=msg_write&accept=<%response.write server.urlencode(username)%>' target=_blank><img src='<%response.write joekoe_cms.web_dir_skin%>mail/msg.gif' alt='给 <%response.write username%> 发送短信' border=0></a></td>
<td><input type=checkbox name=sel_id value='<%response.write rs("id")%>' class=tr></td>
</tr>
<%
    rs.movenext
  next
  rs.close
%>
<tr class=trb height=30>
<td colspan=3>共有<font class=red><%response.write rssum%></font>位好友&nbsp;页次：<font class=red><%response.write viewpage&"</font>/<font class=red>"&thepages%></font>&nbsp;分页：<% response.write jk_pagecute(nummer,thepages,viewpage,pageurl,3,"#ff0000") %></td>
<td colspan=5 align=center>
  <table border=0 cellspacing=2 cellpadding=2>
  <tr>
  <td><input type=checkbox name=sel_all value='yes' onclick="javascript:select_all(this.form);" >所有</td>
  <td><input type=submit class=btn value='删除所选' onclick="javascript:return sel_click(this.form);"></td>
  <td><input type=button class=btn onclick="javascript:friend_clear();" value="清空所有"></td>
  </tr>
  </table>
</td>
</tr>
</form>
</table>
<table border=0>
<tr><td align=center height=25 valign=bottom><%response.write img_user()%></td></tr>
</table>
<script language=javascript>
<!--
function friend_clear()
{
  if (confirm('确定清空所有的好友吗?\n\n清空后将无法恢复！'))
  { location.href='?action=clear'; }
}
-->
</script>
<%
end sub
%>