<!--#INCLUDE FILE="setup.asp" -->
<!--#include file="checkuser.asp" -->
<!--#include file="theme.asp"-->
<!--#include file="include/char.asp"-->
<%locat="我的好友"
%>
<script language="javascript">
function DoTitle(addTitle) { 
var revisedTitle; 
var currentTitle = document.messager.touser.value; 
revisedTitle = currentTitle+addTitle; 
document.messager.touser.value=revisedTitle; 
document.messager.touser.focus(); 
return; }
</script>
<%

Dim msg,ErrMsg

if membername="" Then
  	ErrMsg=ErrMsg+"<br>"+"<li>您没有<a href=login.asp target=_blank>登录</a>。"
	founderr=True
End if
if founderr=True Then
	Call top(1,1)
	Call Error("Exclamation",ErrMsg)
Else
	Select Case Request("action")
	Case "info"
		Call top(1,1)
		Call info()
	Case "addF"
		act="添加好友"
		Call top(1,1)
		Call addF()
	Case "saveF"
		act="添加好友"
		Call top(1,1)
		Call saveF()
	Case "删除"
		act="删除好友"
		Call top(1,1)
		Call DelFriend()
	Case "清空好友"
		act="清空好友"
		Call top(1,1)
		Call AllDelFriend()
	Case Else
		Call top(1,1)
		Call info()
	End Select
	if founderr Then Call Error("Exclamation",ErrMsg)
End if

Sub nav()

Response.Write "<BR><TABLE border=0 width=""90%"" align=center><TBODY>"&_
				"<TR><TD align=left><a href='"& HostURL &"'></a></TD>"&_
				"<TD Align=right nowrap>  <a href=usersms.asp?action=inbox><img src=images/m_inbox.gif border=0 alt=收件箱></a> &nbsp; <a href=usersms.asp?action=outbox><img src=images/M_outbox.gif border=0 alt=发件箱></a> &nbsp; <a href=usersms.asp?action=issend><img src=images/M_issend.gif border=0 alt=已发送邮件></a>&nbsp; <a href=usersms.asp?action=recycle><img src=images/M_recycle.gif border=0 alt=废件箱></a>&nbsp; <a href=friendlist.asp><img src=images/M_address.gif border=0 alt=地址簿></a>&nbsp;<a href=usersms.asp?action=new&id=><img src=images/m_write.gif border=0 alt=发送消息></a> &nbsp;<a href=usersms.asp?action=new&touser="&htmlencode(Request("sender"))&"&id="&Request("id")&"><img src=images/m_reply.gif border=0 alt=回复消息></a> &nbsp;<a href=usersms.asp?action=fw&id="&Request("id")&"><img src=images/m_fw.gif border=0 alt=转发消息></a>&nbsp;<a href=usersms.asp?action=delete&id="&Request("id")&"><img src=images/m_delete.gif border=0 alt=删除消息></a>"&_
				"</TD></TR></TBODY></TABLE><br>"


End Sub


'收件箱
Sub info()
Call nav()
%>
<form action="friendlist.asp" method=post name=inbox>
    <table cellpadding=0 cellspacing=0 border=0 width="100%" Class=TableBorder align=center>
        <tr>
            <td>
                <table cellpadding=5 cellspacing=1 border=0 width=100%>
            <tr>
                <th valign=middle width="23%"><b>姓名</b></th>
                <th valign=middle width="25%"><b>邮件</b></th>
                <th valign=middle width="25%"><b>主页</b></th>
                <th valign=middle width="10%"><b>OICQ</b></th>
                <th valign=middle width="10%"><b>发短信</b></th>
                <th valign=middle width="7%"><b>操作</b></th>
            </tr>
<%
	Set rs=server.createobject("adodb.recordset")
	sql="Select F.*,U.email,U.homepage,U.oicq from Friend F inner join student U on F.F_Friend=U.userid where F.F_username='"&trim(membername)&"' order by F.f_addtime desc"
	rs.open sql,conn,1,1
	if rs.eof and rs.bof Then
%>
                <tr>
                <td Class=LightTableBody align=center valign=middle colspan=6>您的好友列表中没有任何内容。</td>
                </tr>
<%Else%>
<%do while not rs.eof%>
                <tr Class=LightTableBody>
                    <td align=center valign=middle><a href="profile.asp?name=<%=htmlencode(rs("F_friend"))%>" target=_blank><%=rs("F_friend")%></a></td>
                    <td align=center valign=middle><a href="mailto:<%=rs("email")%>"><%=rs("email")%></a></td>
                    <td align=center><a href="<%=rs("homepage")%>" target=_blank><%=htmlencode(rs("homepage"))%></a></td>
                    <td align=center><%=rs("oicq")%></td>
                    <td align=center><a href="usersms.asp?action=new&touser=<%=htmlencode(rs("f_friend"))%>">发送</a></td>
                <td align=center><input type=checkbox name=id value=<%=rs("f_id")%>></td>
                </tr>
<%
	rs.movenext
	loop
	End if
	rs.close
	Set rs=Nothing
%>      
        <tr Class=DarkTableBody> 
          <td align=right colspan=6><input type=checkbox name=chkall value=on onclick="CheckAll(this.form)">选中所有显示记录&nbsp;<input type=button name=action onclick="location.href='friendlist.asp?action=addF'" value="添加好友" class=button>&nbsp;<input type=submit name=action onclick="return confirm('确定删除选定的纪录吗?')" value="删除" class=button>&nbsp;<input type=submit name=action onclick="return confirm('确定清除所有的纪录吗?')" value="清空好友" class=button></td>
                </tr>
                </table></td></tr></table></form>
<%
End Sub

Sub delFriend()
Call nav()
delid=Request("id")
if delid="" or isnull(delid) Then
Errmsg=Errmsg+"<li>"+"请选择相关参数。"
Founderr=True
Else
	conn.execute("delete from Friend where F_username='"&trim(membername)&"' and F_id in ("&delid&")")

'modify point

	msg=msg+"<br>"+"<li><b>您已经删除选定的好友记录。"
	Call success("好友列表",msg)

End if
End Sub

Sub AllDelFriend()
Call nav()
	conn.execute("delete from Friend where F_username='"&trim(membername)&"'")
	msg=msg+"<br>"+"<li><b>您已经删除了所有好友列表。"
'modify point
	
	
	Call success("好友列表",msg)
End Sub

Sub addF()
Call nav()
%>
<form action="Friendlist.asp" method=post name=messager>
  <table cellpadding=0 cellspacing=0 border=0 width="100%"  Class=TableBorder align=center>
    <tr> 
      <td> 
        <table cellpadding=3 cellspacing=1 border=0 width=100%>
          <tr> 
            <th colspan=2 align=center> 
              <input type=hidden name="action" value="saveF">
              加入好友--请完整输入下列信息</th>
          </tr>
          <tr Class=LightTableBody height=50> 
            <td valign=middle width=70><b>好友：</b></font></td>
            <td valign=middle>
              <input type=text name="touser" size=50 value="<%=Request("myFriend")%>">
			  &nbsp;使用逗号（,）分开，最多5位用户</font>
            </td>
          </tr>
          <tr Class=DarkTableBody> 
            <td valign=middle colspan=2 align=center> 
              <input type=Submit value="保&nbsp;存" name=Submit class=button style="width:60px">
              &nbsp; 
              <input type="reset" name="Clear" value="清&nbsp;除" class=button style="width:60px">
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</form>
<%
End Sub

Sub saveF()
Call nav()
	if Request("touser")="" Then
		ErrMsg=ErrMsg+"<br>"+"<li>您忘记填写发送对象了吧。"
		founderr=True
	Else
		incept=Request("touser")
		incept=Split(incept,",")
	End if
	if not founderr Then
		for i=0 to ubound(incept)
		Set rs=server.createobject("adodb.recordset")
		sql="Select userid from student where userid='"&incept(i)&"'"
		rs.open sql,conn,1,1
		if rs.eof and rs.bof Then
			ErrMsg=ErrMsg+"<br>"+"<li>同学录没有这个用户，操作未成功。"
			founderr=True
		End if
		rs.close
		Set rs=Nothing

		if not founderr Then
		sql="Select F_friend from friend where F_username='"&membername&"' and  F_friend='"&incept(i)&"'"
		Set rs=conn.execute(sql)
		if rs.eof and rs.bof Then
		sql="insert into friend (F_username,F_friend,F_addtime) values ('"&membername&"','"&incept(i)&"',Now())"
		conn.execute(sql)

		sql="update student Set point=point+"&PointSet(8)&" where userid='"&membername&"'"
		conn.execute(sql)

		End if
			if i>4 Then
			ErrMsg=ErrMsg+"<br>"+"<li>每次最多只能添加5位用户，您的名单5位以后的请重新填写。"
			founderr=True
			Exit for
			End if
		End if
		next
		if not founderr Then
		msg=msg+"<br>"+"<li><b>恭喜您，好友添加成功。"
		Call success("好友列表",msg)
		End if
	End if
End Sub

%>

<%Call footer%>
