<!--#include file="bbstop.asp"-->
<%	founderr=false
	set rs=server.createobject("adodb.recordset")

if membername="" then
  	errmsg=errmsg+"<br>"+"·您没有<a href=login.asp target=_blank>登录</a>。"
	founderr=true
end if

if founderr=true then
	call error()
else
	select case request("action")
	case "inbox"  call inbox()
	case "outbox" call outbox()
	case "new" call sendmsg()
	case "read" call read()
	case "outread" call read()
	case "delete" call delete()
	case "deleteall" call deleteall()
	case "send" call savemsg()
	case "newmsg" call newmsg()
	case else call error()
	end select
end if

'收件箱
sub inbox()
%>
<table cellpadding=0 cellspacing=0 border=0 width=762 align=center bgcolor=#ffffff class=pian>
        <tr>
            <td>
                <table cellpadding=3 cellspacing=1 border=0 width=100% bgcolor=#efefef>
            <tr bgcolor=#efefef>
                <td align=center colspan=3><font color=#ff0000>欢迎使用您的收件箱，<%=htmlencode(membername)%></td>
            </tr>
            <tr bgcolor=#ffffff>
                <td valign=middle align=center colspan=3><a href="messanger.asp?action=inbox"><img src="images/inboxpm.gif" border=0 alt="收件箱"></a> &nbsp; <a href="messanger.asp?action=outbox"><img src="images/outboxpm.gif" border=0 alt="发件箱"></a> &nbsp; <a href="messanger.asp?action=new"><img src="images/newpm.gif" border=0 alt="发送消息"></a></td>
            </tr>
            <tr bgcolor=#ffffff>
                <td align=center valign=middle><b>来自</b></td>
                <td align=center valign=middle><b>主题</b></td>
                <td align=center valign=middle><b>已读</b></td>
            </tr>
<%
	sql="select * from bbs_message where incept='"&trim(membername)&"' order by id desc"
	rs.open sql,conn,1,1
	if rs.eof and rs.bof then
%>
                <tr bgcolor=#ffffff>
                <td align=center valign=middle colspan=3>您还没有新留言噢：）</td>
                </tr>
<%else%>
<%do while not rs.eof%>
                <tr bgcolor=#ffffff>
                    <td align=center valign=middle><%=htmlencode(rs("sender"))%></td>
                    <td align=left valign=middle><a href="messanger.asp?action=read&id=<%=rs("id")%>"><%=htmlencode(rs("title"))%></a></td>
                    <td align=center valign=middle><%if rs("flag")=0 then%><font color=#ff3300>否</font><%else%>是<%end if%></td>
                </tr>
<%
	rs.movenext
	loop
	end if
	rs.close
%>
                <tr bgcolor=#ffffff>
                <td align=center valign=middle colspan=3><font face="宋体" color=#333333><a href="messanger.asp?action=deleteall">删除所有的短消息</a></td>
                </tr>
</table></td></tr></table>
<%
end sub
'发件箱
sub outbox()
%>
<table cellpadding=0 cellspacing=0 border=0 width=762 align=center bgcolor=#ffffff class=table-zuoyou>
<tr><td>
	<table width=100% cellpadding=3 cellspacing=1 bgcolor=#efefef class="pian">
	<tr bgcolor=#efefef>
	<td align=center colspan=2><font color=#ff0000>欢迎使用短消息发送，<%=htmlencode(membername)%></td>
	</tr>
	<tr bgcolor=#ffffff>
	<td valign=middle align=center colspan=3><a href="messanger.asp?action=inbox"><img src="images/inboxpm.gif" border=0 alt="收件箱"></a> &nbsp; <a href="messanger.asp?action=outbox"><img src="images/outboxpm.gif" border=0 alt="发件箱"></a> &nbsp; <a href="messanger.asp?action=new"><img src="images/newpm.gif" border=0 alt="发送消息"></a></td>
	</tr>
	<tr bgcolor=#ffffff>
	<td align=center valign=middle width=20%><font face="宋体" color=#333333><b>收件人</b></td>
	<td align=center valign=middle><font face="宋体" color=#333333><b>标题</b></td>
	</tr>
<%
	sql="select * from bbs_message where sender='"&trim(membername)&"'"
	rs.open sql,conn,1,1
	if rs.eof and rs.bof then
%>
	<tr bgcolor=#ffffff>
	<td align=center valign=middle colspan=2><font face="宋体" color=#333333>您还没有给别人发过信息呢~~</td>
	</tr>
<%else%>
<%do while not rs.eof%>
                <tr bgcolor=#ffffff>
                    <td align=center valign=middle width=20%><font face="宋体" color=#333333><%=htmlencode(rs("incept"))%></td>
                    <td align=left valign=middle><font face="宋体" color=#333333><a href="messanger.asp?action=outread&id=<%=rs("id")%>"><%=htmlencode(rs("title"))%></a></td>
                </tr>
<%
	rs.movenext
	loop
	end if
	rs.close
%>                
                <tr bgcolor=#ffffff>
                <td align=center valign=middle colspan=2><font face="宋体" color=#333333><a href="messanger.asp?action=deleteall">删除所有的短消息</a></td>
                </tr>
      </table></td></tr></table>
<%
end sub
'发送信息
sub sendmsg()
%>
<table cellpadding=0 cellspacing=0 border=0 width=762 align=center bgcolor=#ffffff class=pian>
<tr><td align=center>
     <table cellpadding=3 cellspacing=1 border=0 width=80% bgcolor=#efefef>
     <tr bgcolor=#efefef><td align=center colspan=3><font color=#ff0000>发送短消息</td>
       </tr>
            <tr bgcolor=#ffffff>
                <td valign=middle align=center colspan=3><a href="messanger.asp?action=inbox"><img src="images/inboxpm.gif" border=0 alt="收件箱"></a> &nbsp; <a href="messanger.asp?action=outbox"><img src="images/outboxpm.gif" border=0 alt="发件箱"></a> &nbsp; <a href="messanger.asp?action=new"><img src="images/newpm.gif" border=0 alt="发送消息"></a></td>
            </tr>
            <tr bgcolor=#ffffff>
            <td colspan=2 align=center>
            <form action="messanger.asp" method=post name=FORM>
            <input type=hidden name="action" value="send">
            <font face="宋体" color=#333333><b>请完整输入下列信息</b></td>
            </tr>
            <tr bgcolor=#ffffff>
            <td valign=middle><font face="宋体" color=#333333><b>收件人：</b></font></td>
            <td valign=middle><input type=text name="touser" value="<%=request("touser")%>" size=20></a></td></tr>
            <tr bgcolor=#ffffff>
            <td valign=top width=30%><font face="宋体" color=#333333><b>标题：</b></font></td>
            <td valign=middle><input type=text name="title" size=36 maxlength=80></td>
            </tr>
            <tr bgcolor=#ffffff>
            <td valign=top width=30%><font face="宋体" color=#333333><b>内容：</b></td>
            <td valign=middle><textarea cols=35 rows=6 name="message"></textarea></td>
            </tr>
            <tr bgcolor=#ffffff>
            <td valign=middle colspan=2 align=center>
            <input type=submit value="发送" name=submit>&nbsp;<input type=reset name="Clear" value="清除">
            </td></form></tr>
</table></td></tr></table>
<%
end sub
'读取信息
sub read()
%>
<%
   	sql="update bbs_message set flag=1 where ID="&cstr(request("id"))
   	rs.open sql,conn,1,3
	sql="select * from bbs_message where incept='"&membername&"' and id="&cstr(request("id"))
	rs.open sql,conn,1,1
	if rs.eof and rs.bof then
		errmsg=errmsg+"<br>"+"·你是不是跑到别人的信箱啦、或者该信息已经删除。"
		founderr=true
	end if
	if founderr=true then
		call error()
	else
%>
<table cellpadding=0 cellspacing=0 border=0 width=762 align=center bgcolor=#ffffff class=table-zuoyou>
<tr><td>
	<table width=100% cellpadding=3 cellspacing=1 bgcolor=#efefef class="pian">
	<tr>
	<td align=center colspan=3><font color=#ff0000>欢迎使用短消息接收，<%=htmlencode(membername)%></font></td>
        </tr>
            <tr bgcolor=#ffffff>
                <td valign=middle align=center colspan=3><a href="messanger.asp?action=delete&id=<%=rs("id")%>"><img src="images/deletepm.gif" border=0 alt="删除消息"></a> &nbsp; <a href="messanger.asp?action=inbox"><img src="images/inboxpm.gif" border=0 alt="收件箱"></a> &nbsp; <a href="messanger.asp?action=outbox"><img src="images/outboxpm.gif" border=0 alt="发件箱"></a> &nbsp;<a href="messanger.asp?action=new"><img src="images/newpm.gif" border=0 alt="发送消息"></a> &nbsp;<a href="messanger.asp?action=new&touser=<%=htmlencode(rs("sender"))%>"><img src="images/replypm.gif" border=0 alt="回复消息"></a></td>
            </tr>
                <tr bgcolor=#ffffff>
                    <td valign=middle><font color=blue>
<%if request("action")="outread" then%>                    在<b><%=rs("sendtime")%></b>，您发送此消息给<b><%=htmlencode(rs("incept"))%></b>！
<%else%>
在<b><%=rs("sendtime")%></b>，<b><%=htmlencode(rs("sender"))%></b>给您发送的消息！
<%end if%></font></td>
                </tr>
                <tr bgcolor=#ffffff>
                    <td valign=top align=left><font face="宋体" color=#333333>
                    <b>消息标题：<%=htmlencode(rs("title"))%></b><p>
                    <%if rs("sender")="乐购王" then%>
                    <%=rs("content")%>
                    <%else%>
                    <%=ubbcode(rs("content"))%>
                    <%end if%>
		    </td>
                </tr>
      </table></td></tr></table>
<%end if%>
<%end sub

sub savemsg()
	if request("touser")="" or request("title")="" or request("message")="" then
		errmsg=errmsg+"<br>"+"·看看你的发送信息写对了吗？"
		founderr=true
	else
		inceptor=request("touser")
		title=request("title")
		message=request("message")
	end if
	if founderr=true then
	call error()
	else

		sql="select * from huiyuan where huiyuan='"&inceptor&"'"
		rs.open sql,conn,1,1
		if rs.eof and rs.bof then
			errmsg=errmsg+"<br>"+"·论坛没有这个用户，看看你的发送对象写对了嘛？"
			founderr=true
		end if
		rs.close
		if founderr=true then
			call error()
		else
		sql="select * from bbs_message"
		rs.open sql,conn,1,3
		rs.addnew
		rs("incept")=inceptor
		rs("sender")=membername
		rs("title")=title
		rs("content")=message
		rs("sendtime")=Now()
		rs("flag")=0
		rs.update
		msg=msg+"<br>"+"·<b>恭喜您，发送短信息成功。</b><br>发送的消息同时保存在您的发件箱。"
		call success()
		rs.close
		end if
	end if
end sub

sub delete()
	sql="delete from bbs_message where incept='"&membername&"' and id="&cstr(request("id"))
	conn.execute sql
    	if err.Number<>0 then
	err.clear
	errmsg=errmsg+"<br>"+"·删 除 失 败 ！"
	founderr=true
	call error()
    	else
	msg=msg+"<br>"+"·短信息成功删除！"
	call success()
    	end if
end sub

sub deleteall()
	sql="delete from bbs_message where incept='"&membername&"'"
	conn.execute sql
    	if err.Number<>0 then
	err.clear
	errmsg=errmsg+"<br>"+"·删 除 失 败 ！"
	founderr=true
	call error()
    	else
	msg=msg+"<br>"+"短信息全部成功删除！"
	call success()
    	end if
end sub

sub success()
%>
<table cellpadding=0 cellspacing=0 border=0 width=762 align=center bgcolor=#ffffff class=table-zuoyou>
<tr>
<td>
	<table width=100% cellpadding=3 cellspacing=1 bgcolor=#efefef class="pian">
	<tr align="center"> 
	<td width="100%"><font color=blue>短信息发送成功！！</font></td>
	</tr>
	<tr bgcolor=#ffffff> 
	<td width="100%"><%=msg%>
	</td>
	</tr>
	<tr align="center"> 
	<td width="100%"><a href="javascript:history.go(-1)">&gt;&gt;&nbsp; 返回上一页</a>
      </td>
    </tr>  
    </table>   </td></tr></table>
<%
end sub
sub newmsg()
%>
<table cellpadding=0 cellspacing=0 border=0 width=762 align=center bgcolor=#ffffff class=table-zuoyou>
<tr><td><table width=100% cellpadding=3 cellspacing=1 bgcolor=#efefef class="pian">
<tr align="center"> 
<td width="100%">>短消息通知</td>
</tr>
<tr bgcolor=#ffffff> 
<td width="100%" align=center><br>
<font color="#333333"><a href=messanger.asp?action=inbox><img src="images/newmail.gif" border=0>有新的短消息</a><br><br><a href=messanger.asp?action=inbox>按此查看</a><br><br></font>
</td>
</tr>
</table></td></tr></table>
<%end sub%>
<!--#include file="bbsend.asp"-->