<%@ LANGUAGE = VBScript CodePage = 936%>
<!--#include file="conn.asp"-->
<!--#include file="inc/class_sys.asp"-->
<!--#include file="inc/md5.asp"-->
<!--#include file="inc/class_blog.asp"-->
<%
dim oblog
set oblog=new class_sys
oblog.start
if not oblog.checkuserlogined() then
	response.Redirect("login.asp?fromurl="&replace(oblog.GetUrl,"&","$"))
end if
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Oblog 短消息管理</title>
<link href="OblogStyle/OblogStyleAdminMain.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="content">
  	<div class="content_top">
		  	<div class="side_d1 side11"></div>
		    <div class="side_d2 side21"></div>
			站内短消息
	</div>
	
    <div class="content_body">
<%
dim action
action=request("action")
select case action
	case "send"
		call send
	case "save"
		call save
	case "read0"
		call read(0)
	case "read1"
		call read(1)
end select
%>
	</div>
	
    <div class="content_bot">
		  	<div class="side_e1 side12"></div>
   			<div class="side_e2 side22"></div>
 	</div>
	
  </div>
  <div id="bottom"><%=oblog.user_copyright%></div>
</body>
</html>
<%
sub send()
	dim rs
%>
<SCRIPT language=javascript>
function changincept()
{
	document.oblogform.incept.value = document.oblogform.selectincept.value;
}
</SCRIPT>
<style type="text/css">
<!--
	#list ul { width: 100%; MARGIN: 0px; padding:0px;} 
	#list li{MARGIN: 0px; padding:10px 0px;}
	#list ul li.t1 { width: 60px;text-align: right;} 
	#list ul li.t2 { width: 260px;text-align: left;} 
-->
</style>
<div id="list">
<form action="user_pm.asp?action=save" method="post" name="oblogform">
  <h1>发送站内短消息</h1>
  <ul> 
    <li class="t1">收件人：</li>
    <li class="t2">
	<input type="text" name="incept" id="incept" width="20" value="<%=trim(request("incept"))%>" />
	<select size="1" id="selectincept" onChange='javascript:changincept()'>
	<option value="">选择好友</option>
<%
set rs=oblog.execute("select username from oblog_user,oblog_friend where oblog_user.userid=oblog_friend.friendid and oblog_friend.isblack=0 and oblog_friend.userid="&oblog.logined_uid)
while not rs.eof
	response.Write("<option value='"&oblog.filt_html(rs(0))&"'>"&oblog.filt_html(rs(0))&"</option>")
	rs.movenext
wend
set rs=nothing
%>
	</select>
	</li>
  </ul>
  <ul> 
    <li class="t1">标题：</li>
	<li class="t2"><input type="text" name="topic" size="45" maxlength="50" value="<%=oblog.filt_html(trim(request("topic")))%>" /></li>
  </ul>
   <ul> 
    <li class="t1">内容：<br />(250字内)</li>
	<li class="t2"><textarea name="content" cols="45" rows="8"></textarea></li>
  </ul>
  <ul> 
    <INPUT type="hidden" name="id" value="">
        <input type="submit"  value=" 提交 ">
		　　<input type="button" onClick="window.close();" value=" 关闭 ">
  </ul>
</form>
</div>
<%
end sub

sub save()
	dim incept,content,sql,rs,inceptid,topic
	incept=oblog.filt_badstr(trim(request("incept")))
	content=trim(request("content"))
	topic=trim(request("topic"))
	if incept="" then oblog.adderrstr("错误：收件人不能为空")
	if content="" then oblog.adderrstr("错误：短消息内容不能为空")
	if topic="" then oblog.adderrstr("错误：短消息标题不能为空")
	if oblog.errstr<>"" then
		oblog.showusererr
		exit sub
	end if	
	sql="select userid from [oblog_user] where username='"&incept&"'"
	set rs=oblog.execute(sql)
	if rs.eof then
		response.Write("<ul><li>错误：无此用户，<a href='javascript:history.go(-1)'>返回上一页</a></li></ul>")
		exit sub
	end if
	inceptid=clng(rs(0))
	set rs=oblog.execute("select id from oblog_friend where isblack=1 and userid="&inceptid&" and friendid="&oblog.logined_uid)
	if not rs.eof then
		response.Write("<ul><li>错误：你在收件人的黑名单中，无法发送短消息，<a href='javascript:history.go(-1)'>返回上一页</a></li></ul>")
		exit sub
	end if
	sql="select top 1 * from oblog_pm"
	set rs=server.createobject("adodb.recordset")
	rs.open sql,conn,1,3
	rs.addnew
	rs("incept")=oblog.Interceptstr(incept,50)
	rs("topic")=oblog.Interceptstr(oblog.filt_badword(topic),100)
	rs("content")=oblog.Interceptstr(oblog.filt_badword(content),250)
	rs("sender")=oblog.logined_uname
	rs.update
	rs.close
	set rs=nothing
	response.Write("<ul><li>短消息发送成功，<a href='javascript:window.close();'>关闭窗口</a></li></ul>")

end sub

sub read(sAction)
	dim id,rs
	id=clng(trim(request("id")))
	if sAction="0" Then
		set rs=oblog.execute("select * from oblog_pm where id="&id & " And Incept='"&oblog.logined_uname&"' And delR=0")
	Elseif sAction="1" Then
		set rs=oblog.execute("select * from oblog_pm where id="&id & " And sender='"&oblog.logined_uname&"' And delS=0")
	Else
		response.Write("<ul><li>错误的参数，<a href='javascript:window.close();'>关闭窗口</a></li></ul>")
		exit sub
	End If
	
	if rs.eof then
		set rs=nothing
		response.Write("<ul><li>无此纪录，<a href='javascript:window.close();'>关闭窗口</a></li></ul>")
		exit sub
	end if	
%>
<style type="text/css">
<!--
	#list ul { width: 100%; MARGIN: 0px; } 
	#list ul li.t1 { width: 90px;text-align: right;padding: 0px;} 
	#list ul li.t2 { width: 300px;text-align: left;padding: 0px;} 
-->
</style>

<div id="list">
    <h1>查看短消息</h1>
  <ul> 
    <li class="t1">收件人：</li>
    <li class="t2"><%=rs("incept")%></li>
  </ul>
    <ul> 
    <li class="t1">发件人：</li>
    <li class="t2"><%=rs("sender")%></li>
  </ul>
  <ul> 
    <li class="t1">发送时间：</li>
	<li class="t2"><%=rs("addtime")%></li>
  </ul>
  <ul> 
    <li class="t1">标题：</li>
	<li class="t2"><%=oblog.filt_html(rs("topic"))%></li>
  </ul>
   <ul> 
    <li class="t1">内容：</li>
	<li class="t2"><%=oblog.filt_html_b(rs("content"))%></li>
	</ul>
    <ul>
		<%If sAction="0" Then%>
			<input type="button" onClick="window.location='user_pm.asp?action=send&incept=<%=rs("sender")%>&topic=<%="回复:"&oblog.filt_html(rs("topic"))%>'" value=" 回复 ">
		<%End If%>
		<input type="button" onClick="window.close();" value=" 关闭 ">
  </ul>
</div>
<%
	if oblog.logined_uname=rs("incept") then
		oblog.execute("update oblog_pm set isreaded=1 where id="&id&" and incept='"&oblog.logined_uname&"'")
	end if
	set rs=nothing
end sub
%>
