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

dim max_num,integral_del,actions,sql_add,action_temp,id,h2,view
tit="站内短信"
actions=Cls.code_query("actions")
id=Cls.code_id("id")
h2=0
if action="msg_write" or action="msg_reply" or action="del" or action="delete" or action="clear" or action="msg_fw" or action="msg_edit" then
h2=1
End If
if action="msg_view" or action="msg_reply" or action="msg_fw" or action="msg_edit" then
    view="<a href='?action=msg_reply&id="&id&"'><img src='"&Cls.Web_SkinDir&"Mail/reply.gif' border=0></a>" & _
		   vbcrlf&"<a href='?action=msg_fw&id="&id&"'><img src='"&Cls.Web_SkinDir&"Mail/fw.gif' border=0></a>" & _
		   vbcrlf&"<a href='?actions=del&id="&id&"'><img src='"&Cls.Web_SkinDir&"Mail/delete.gif' border=0></a>"& _
		   vbcrlf&"<a href='?actions=msg_write'><img src='"&Cls.Web_SkinDir&"Mail/to.gif' border=0></a>"
  End If
max_num=UserGroup_Config(17) '站内短信数
integral_del=UserGroup_Config(14)'发短信扣分数
call DoWebHead(2,h2)
'----------------------------左边 开始----------------------------
'----------------------------左边 结束----------------------------
'----------------------------中间 开始----------------------------
call UserMail_main()
'----------------------------中间 结束----------------------------
call DoWebEnd()
sub UserMail_main()
dim sTmp,view
call AsaiMHUserMail_Load()

select case actions
case "clear"
  call AsaiMHUserMail_Clear()
case "delete"
  call AsaiMHUserMail_Delete(0)
case "del"
  call AsaiMHUserMail_Delete(1)
case else
  select case action
  case "msg_write","msg_view","msg_reply","msg_fw","msg_edit"
    call AsaiMHUserMail_Msg()
  case "box_draft","box_out","box_recycle"
    call AsaiMHUserMail_Box()
  case else
    action="box_in"
    call AsaiMHUserMail_Box()
  end select
end select
End Sub

Function AsaiMHUserMail_Load()
  sql_add=""
  select case action
  case "msg_write"
    action_temp="撰写短信"
  case "msg_view"
    action_temp="浏览短信"
  case "msg_reply"
    action_temp="回复短信"
  case "msg_fw"
    action_temp="转发短信"
  case "msg_edit"
    action_temp="编辑短信"
  case "box_draft"
    sql_add=" send_u='"&login_username&"' and types=2"
    action_temp="草稿箱"
  case "box_out"
    sql_add=" send_u='"&login_username&"' and types=1"
    action_temp="发件箱"
  case "box_recycle"
    sql_add=" (accept_u='"&login_username&"' or send_u='"&login_username&"') and types=4"
    action_temp="废信箱"
  case else
    action="box_in"
    sql_add=" accept_u='"&login_username&"' and types=1"
    action_temp="收信箱"
  end select
End Function

Function AsaiMHUserMail_Clear()
  select case action
  case "box_recycle"
    sql="delete from AsaiMHUserMail where"&sql_add
  case else
    sql="update AsaiMHUserMail set types=4 where"&sql_add
  end select
  call Cls.exec(sql,0)
  Call Cls.Out_Msg("已成清空了"&action_temp&"中的短信！","?action="&action)
End Function

Function AsaiMHUserMail_Delete(dtype)
  dim sel_id,sdim,snum
  if dtype=0 then
    sel_id=trim(request.form("sel_id"))
    sel_id=replace(sel_id," ","")
    if sel_id="" then
      Call Cls.Out_Msg(action_temp&"中没有可删除的短信！","?action="&action)
    End If
  else
    sel_id=trim(request.querystring("id"))
    if not isnumeric(sel_id) then
      Call Cls.Out_Msg("没有可删除的短信！","?action="&action)
    End If
  End If
  sdim=split(sel_id,",")
  snum=ubound(sdim)
  for i=0 to snum
    if isnumeric(sdim(i)) then
      select case action
      case "box_recycle"
        sql="delete from AsaiMHUserMail where "&sql_add&" and id="&sdim(i)
      case else
        sql="update AsaiMHUserMail set types=4 where "&sql_add&" and id="&sdim(i)
      end select
      call Cls.exec(sql,0)
    End If
  next
  erase sdim
  Call Cls.Out_Msg("已从"&action_temp&"中成功删除"&(snum+1)&"条短信！","?action="&action)
End Function

sub AsaiMHUserMail_View()
  dim sTmp,accept_u,send_u,isread,word,send,topic
  sql="select top 1 * from AsaiMHUserMail where (accept_u='"&login_username&"' or send_u='"&login_username&"') and id="&id
  set rs=Cls.exec(sql,1)
  if rs.eof then
    rs.close
    Call Cls.Out_Msg("您要"&action_temp&"ID（"&id&"）不存在！\n\n点击返回……","javascript:history.back(1)")
    exit sub
  End If
  accept_u=rs("accept_u")
  send_u=rs("send_u")
  word=rs("word")
  isread=rs("isread")
  topic=rs("topic")
  word=Ubb.Ubbcode(word)
    if accept_u=login_username then
send="以上是 <font class=Gys>[ "&format_user_name(send_u,0,"")&" ]</font> 于 <font class=blue>"& Cls.time_type(rs("tim"),2)&"</font> 给您发送的短信"
 else
send="以上是您于 <font class=blue>"&Cls.time_type(rs("tim"),2)&"</font> 给 <font class=Gys>[ "&format_user_name(accept_u,0,"")&" ]</font> 发送的短信"
 End If
  rs.close
    Cls.HtmlRcod "body",Cls.ReadTemplate ("user_Mail_view")
	Cls.HtmlRcod "dir_skin",Cls.web_skindir
	Cls.HtmlRcod "body",sTmp
	Cls.HtmlRcod "tit",tit
	Cls.HtmlRcod "view",view
	Cls.HtmlRcod "action_temp",action_temp
	Cls.HtmlRcod "topic",Cls.code_html(topic,1,0)
	Cls.HtmlRcod "word",word
	Cls.HtmlRcod "send",send
	Cls.OutPage
	if accept_u=login_username and isread=false then
    call Cls.exec("update AsaiMHUserMail set isread=1 where id="&id,0)
    call Cls.exec("update AsaiMHUserData set login_msg=login_msg-1 where id="&login_id,0)
    Call Cls.Cache_Del("Web_Info")
  End If
End sub

Function AsaiMHUserMail_Msg()
dim sTmp
  if action<>"msg_write" then
    if int(id)<1 then
      Call Cls.Out_Msg("您要"&action_temp&"的ID为空或不是数字！\n\n点击返回……","javascript:history.back(1)")
      exit Function
    End If
  End If
  if action="msg_view" then
    call AsaiMHUserMail_View()
    exit Function
  End If
  dim accept_u,send_u,topic,word,found_err,types,isread,sendname
  if action="msg_write" then
    accept_u=Cls.code_query("accept")
    if ChkName(accept_u)=false then accept_u=""
  else
    sql="select top 1 send_u,accept_u,topic,word,tim from AsaiMHUserMail where (accept_u='"&login_username&"' or send_u='"&login_username&"') and id="&id
    set rs=Cls.exec(sql,1)
    if rs.eof then
      rs.close
      Call Cls.Out_Msg("您要"&action_temp&"ID（"&id&"）不存在！\n\n点击返回……","javascript:history.back(1)")
      exit Function
    End If
    accept_u=rs("send_u")
    send_u=rs("accept_u")
    topic=rs("topic")
    word=rs("word")
    rs.close
    select case action
    case "msg_reply"
      if lcase(left(topic,3))<>"re:" then topic="RE:"&topic
      word=""
    case "msg_fw"
      if lcase(left(topic,3))<>"fw:" then topic="FW:"&topic
    case "msg_edit"
      accept_u=send_u
    end select
  End If
  if frm_chk() then
    accept_u=Cls.Code_Form("accept_u")
    topic=Cls.Code_Form("topic")
    word=Cls.Code_Form("word")
    found_err=""
    if Not Cls.CodeIsTrue() then
      found_err=found_err&"+您提交的 <font class=red>验证码</font> 有错误，请勿非法提交！<br />"
    End If
    if true_accept(accept_u)=false then
      found_err=found_err&"+您输入的 <font class=red>收 件 人</font> 为空或不存在！<br />"
    End If
	If accept_u=login_username Then
      found_err=found_err&"+您输入的 <font class=red>收 件 人</font> 不能为您自己！！<br />"
    End If
    if topic="" or len(topic)>30 then
      found_err=found_err&"+您输入的 <font class=red>短信主题</font> 为空或长度超过30！<br />"
    End If
    if word="" or len(word)>250 then
      found_err=found_err&"+您输入的 <font class=red>短信内容</font> 为空或长度超过250！<br />"
    End If
    if int(login_integral)<int(integral_del) then
      found_err=found_err&"+发布短信要扣<font class=red>"&integral_del&"</font>分，您的积分不足（只有<font class=red>"&login_integral&"</font>分）！<br />"
    end if
    if found_err<>"" then
    Cls.HtmlRcod "body",Found_Error(Found_Err,460)
    Cls.HtmlRcod "tit","错误提示"
  Cls.OutPage
    exit Function
    End If
    types=1
    isread=0
    sendname="发送"
    if trim(request.form("send"))="later" then
      types=2
      isread=1
      sendname="保存"
    End If
    sql="insert into AsaiMHUserMail(send_u,accept_u,topic,word,tim,types,isread) " & _
	"values ('"&login_username&"','"&accept_u&"','"&topic&"','"&word&"','"&Cls.now_time&"',"&types&","&isread&")"
    call Cls.exec(sql,0)
    sql="update AsaiMHUserData set integral=integral-"&integral_del&" where id="&login_id
    call Cls.exec(sql,0)
    if trim(request.form("send"))<>"later" then
      sql="update AsaiMHUserData set login_msg=login_msg+1 where username='"&accept_u&"'"
      call Cls.exec(sql,0)
	end if
      Call Cls.Out_Msg("您已成功"&sendname&"一条站内短信！","?")
    Call Cls.Cache_Del("Web_Info")
    exit Function
  End If
%>
<script language=javascript>
function do_accept(addaccept)
{
  if (addaccept!="")
  { document.frm_post.accept_u.value=addaccept; }
}
function do_later()
{
  document.frm_post.send.value="later";
  return true;
}
</script>
<%
    Cls.HtmlRcod "body",Cls.ReadTemplate ("user_Mail_write")
	Cls.HtmlRcod "dir_skin",Cls.web_skindir
	Cls.HtmlRcod "tit",tit
	Cls.HtmlRcod "view",view
	Cls.HtmlRcod "action_temp",action_temp
	Cls.HtmlRcod "action",action
	Cls.HtmlRcod "id",id
	Cls.HtmlRcod "accept_u",accept_u
	Cls.HtmlRcod "friend",friend_select()
	Cls.HtmlRcod "topic",Cls.code_html(topic,1,0)
	Cls.HtmlRcod "GetCode",Cls.GetCode()
	Cls.HtmlRcod "editor",LoadUBBEditor("mail","frm_post","word","","simple",480,200)
	Cls.OutPage
End Function

function friend_select()
  dim rsf,ttt,temp1
  temp1=vbcrlf&"<select name=friend_select size=1 onchange=""javascript:do_accept(this.options[this.selectedIndex].value);"">" & _
	vbcrlf&"<option value='' >选择我的好友</option>"
  set rsf=Cls.exec("select username2 from AsaiMHUserFriend where username1='"&login_username&"' order by id",1)
  do while not rsf.eof
    ttt=rsf(0)
    temp1=temp1&vbcrlf&"<option value='"&ttt&"'>"&ttt&"</option>"
    rsf.movenext
  loop
  rsf.close
  set rsf=nothing
  temp1=temp1&vbcrlf&"</select>"
  friend_select=temp1
End Function

sub AsaiMHUserMail_Box()
  dim temp1,pageurl,ttim,isread,td_temp,read_pic,iid,link_temp,name_temp,num_perent,tmpchecked,tmp_new,sTmp
    temp1=""
	tmp_new=0
	Dim obj_page
	Set obj_page=new Cls_PageCute
	obj_page.pageurl="?action="&action&"&"		
	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("*","AsaiMHUserMail",sql_add,"id desc")
	SQL = obj_page.sql_count
	Set rs=Cls.Exec(SQL,1)
	obj_page.rssum=rs(0)
	Rs.Close
	Call obj_page.p_main("*","AsaiMHUserMail",sql_add,"id desc")
  if action="box_in" then
    num_perent=formatpercent(obj_page.rssum/max_num,1)
sTmp="<table border=0 align=center>" & _
vbcrlf&"<tr height=30>" & _
vbcrlf&"<td>您的"&action_temp&"总共可以储存<font class=red>"&max_num&"</font>条短信，</td>" & _
vbcrlf&"<td>目前已有<font class=red>"&obj_page.rssum&"</font>条短信，</td>" & _
vbcrlf&"<td>占<font class=red>"&num_perent&"</font>：</td>" & _
vbcrlf&"<td>" & _
vbcrlf&"<table cellpadding='0' border='0' cellspacing='0' style=""background-color:white; border: #104a7b 1px solid; padding-right: 0px; padding-left: 0px; padding-bottom: 2px; padding-top: 2px;"">" & _
vbcrlf&"<tr>" & _
vbcrlf&"<td width='120'>" & _
vbcrlf&"<div style='height:5px; width:"&num_perent&"; font-size:1px; background-color:#76D769'></div>" & _
vbcrlf&"</td>" & _
vbcrlf&"</tr>" & _
vbcrlf&"</table>" & _
vbcrlf&"</td>" & _
vbcrlf&"</tr>" & _
vbcrlf&"</table>"
  End If
sTmp=sTmp&"<table cellspacing=1 cellpadding=4 class=table>" & _
vbcrlf&"<form name=del_form action='?actions=delete&action="&action&"' method=post>" & _
vbcrlf&"<tr align=center class=tr>" & _
vbcrlf&"<td width='8%' class=td>状态</td>" & _
vbcrlf&"<td width='16%' class=td>"
if action="box_draft" or action="box_out" then
  sTmp=sTmp&"收"
else
  sTmp=sTmp&"发"
End If
  tmpchecked=""
  if action="box_out" then tmpchecked=" disabled"
sTmp=sTmp&"信人</td>" & _
vbcrlf&"<td width='44%' class=td>短信主题（"&action_temp&"）</td>" & _
vbcrlf&"<td width='14%' class=td>发送日期</td>" & _
vbcrlf&"<td width='10%' class=td>大小</td>" & _
vbcrlf&"<td width='8%' class=td>操作</td>" & _
vbcrlf&"</tr>"
	For i=1 To obj_page.page_num
    td_temp=""
    read_pic="state_old"
    link_temp="msg_view"
    iid=rs("id")
    isread=rs("isread")
    ttim=rs("tim")
    if isread=false then
      tmp_new=tmp_new+1
      td_temp=" class=btd"
      read_pic="state_new"
    End If
    if action="box_draft" then
      td_temp=" class=btd"
      read_pic="state_send"
      link_temp="msg_edit"
    End If
    if action="box_draft" or action="box_out" then
      name_temp=rs("accept_u")
    else
      name_temp=rs("send_u")
    End If
    ttim=Cls.time_type(ttim,3)
sTmp=sTmp&Cls.js_put("../style/select.js",0) & _
vbcrlf&"<tr class=tr align=center"&td_temp&">" & _
vbcrlf&"<td ><img src='"&Cls.Web_SkinDir&"Mail/"&read_pic&".gif' border=0></td>" & _
vbcrlf&"<td >"&format_user_name(name_temp,1,"")&"</td>" & _
vbcrlf&"<td  align=left><a href='?action="&link_temp&"&id="&iid&"'>"&Cls.code_html(rs("topic"),1,22)&"</a></td>" & _
vbcrlf&"<td ><font class=tims>"&ttim&"</font></td>" & _
vbcrlf&"<td  align=right><font class=tims><font class=blue>"&len(rs("word"))&"</font>Byte</font></td>" & _
vbcrlf&"<td ><input type=checkbox name=sel_id value='"&iid&"' s"&tmpchecked&"></td>" & _
vbcrlf&"</tr>"
    rs.movenext
  next
  rs.close
  if int(tmp_new)<>login_msg then
    call Cls.exec("update AsaiMHUserData set login_msg="&tmp_new&" where id="&login_id,0)
    Call Cls.Cache_Del("Web_Info")
  end if
sTmp=sTmp&"<tr class=tre height=30><td colspan=6 align=center>" & _
vbcrlf&"<table border=0 cellspacing=0 cellpadding=2>" & _
vbcrlf&"<tr>" & _
vbcrlf&"<td><font class=Gys>（为了节省空间，请及时删除无用信息）</font></td>" & _
vbcrlf&"<td><input type=checkbox name=sel_all value='yes' onclick=""javascript:select_all(this.form);"" >所有</td>" & _
vbcrlf&"<td><input class=btn type=submit value='删除所选' onclick=""return sel_click(this.form);""></td>" & _
vbcrlf&"<td><input class=btn type=button onclick=""javascript:box_clear();"" value='清空"&action_temp&"'></td>" & _
vbcrlf&"</tr>" & _
vbcrlf&"</table>" & _
vbcrlf&"</td></tr>" & _
vbcrlf&"</form>"
%>
<script language=javascript>
<!--
function box_clear()
{
  if (confirm('确定清空<%Response.Write action_temp%>所有的短信吗?\n\n清空后将无法恢复！'))
  {
    location.href='?actions=clear&action=<%Response.Write action%>';
  }
}
-->
</script>
<%
sTmp=sTmp&"<tr class=trs height=30>" & _
vbcrlf&"<td colspan=3>" & _
vbcrlf&"<table border=0 cellspacing=0 cellpadding=1>" & _
vbcrlf&"<tr>" & _
vbcrlf&"<td>"&obj_page.page_var&"</td>" & _
vbcrlf&"<td width=5></td>" & _
vbcrlf&"<td>分页：</td>" & _
vbcrlf&"<td>"&obj_page.page_cute&"</td>" & _
vbcrlf&"<td width=5></td>" & _
vbcrlf&""&obj_page.page_shortcut&"" & _
vbcrlf&"</tr>" & _
vbcrlf&"</table>" & _
vbcrlf&"</td>" & _
vbcrlf&"<td colspan=3 align=center>" & _
vbcrlf&"<table border=0 cellspacing=0 cellpadding=2>" & _
vbcrlf&"<tr>" & _
vbcrlf&"<td><img src='"&Cls.Web_SkinDir&"Mail/state_old.gif' border=0 align=absmiddle>&nbsp;已读</td>" & _
vbcrlf&"<td><img src='"&Cls.Web_SkinDir&"Mail/state_new.gif' border=0 align=absmiddle>&nbsp;未读</td>" & _
vbcrlf&"<td><img src='"&Cls.Web_SkinDir&"Mail/state_send.gif' border=0 align=absmiddle>&nbsp;草稿</td>" & _
vbcrlf&"</tr>" & _
vbcrlf&"</table>" & _
vbcrlf&"</td>" & _
vbcrlf&"</tr>" & _
vbcrlf&"</table>"
    Cls.HtmlRcod "body",Cls.ReadTemplate ("user_Mail")
	Cls.HtmlRcod "dir_skin",Cls.web_skindir
	Cls.HtmlRcod "body",sTmp
	Cls.HtmlRcod "tit",tit
	Cls.HtmlRcod "view",view
	Cls.OutPage
End sub
%>
