<!-- #include file="include/con_user.asp" -->
<!-- #include file="include/jk_convert.asp" -->
<!-- #include file="include/jk_page_cute.asp" -->
<!-- #include file="include/jk_pagecute.asp" -->
<!-- #include file="include/jk_val_code.asp" -->
<!-- #include file="include/jk_mail.asp" -->
<!-- #include file="include/jk_em.asp" -->
<!-- #include file="include/jk_ubb.asp" -->
<!-- #include file="include/jk_frm.asp" -->
<%
dim max_num,nummer,nums,rssum,page,viewpage,thepages,actions,sql_add,action_temp,id,h2,user_on
max_num=dim_num(19)
nummer=dim_num(0)
nums=nummer
page=1
tit="站内短信"
actions=trim(request.querystring("actions"))
id=trim(request.querystring("id"))
if not isnumeric(id) then id=0
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

call user_mail_load()
call web_head(2,h2,0,0,0)
call convert_load(login_mode)
max_num=format_convert(max_num,"+")
'----------------------------左边 开始----------------------------
call user_left("")
'----------------------------左边 结束----------------------------
call web_center(0)
'----------------------------中间 开始----------------------------
response.write joekoe_cms.js_put("style/joekoe_select.js",0)
call user_mail_menu()

select case actions
case "clear"
  call user_mail_clear()
case "delete"
  call user_mail_delete(0)
case "del"
  call user_mail_delete(1)
case else
  select case action
  case "msg_write","msg_view","msg_reply","msg_fw","msg_edit"
    response.write vbcrlf&"<table cellspacing=1 cellpadding=4 class=table>" & _
		   vbcrlf&"<tr><td colspan=2 align=center class=td>"&action_temp&"</td></tr>"
    call user_mail_msg()
    response.write vbcrlf&"</table>"
  case "box_draft","box_out","box_recycle"
    call user_mail_box()
  case else
    action="box_in"
    call user_mail_box()
  end select
end select

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

sub user_mail_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="where send_u='"&login_username&"' and types=2"
    action_temp="草稿箱"
  case "box_out"
    sql_add="where send_u='"&login_username&"' and types=1"
    action_temp="发件箱"
  case "box_recycle"
    sql_add="where (accept_u='"&login_username&"' or send_u='"&login_username&"') and types=4"
    action_temp="废信箱"
  case else
    action="box_in"
    sql_add="where accept_u='"&login_username&"' and types=1"
    action_temp="收信箱"
  end select
end sub

sub user_mail_clear()
  select case action
  case "box_recycle"
    sql="delete from user_mail "&sql_add
  case else
    sql="update user_mail set types=4 "&sql_add
  end select
  call joekoe_cms.exec(sql,0)
  call web_js_msg(1,"已成清空了"&action_temp&"中的短信！","?action="&action)
end sub

sub user_mail_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 web_js_msg(1,action_temp&"中没有可删除的短信！","?action="&action)
    end if
  else
    sel_id=trim(request.querystring("id"))
    if not isnumeric(sel_id) then
      call web_js_msg(1,"没有可删除的短信！","?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 user_mail "&sql_add&" and id="&sdim(i)
      case else
        sql="update user_mail set types=4 "&sql_add&" and id="&sdim(i)
      end select
      call joekoe_cms.exec(sql,0)
    end if
  next
  erase sdim
  call web_js_msg(1,"已从"&action_temp&"中成功删除"&(snum+1)&"条短信！","?action="&action)
end sub

sub user_mail_menu()
%>
<table border=0 width='98%' cellspacing=0 cellpadding=0>
<tr><td align=center height=50>
<a href='user_mail.asp?action=box_in'><img src='<%response.write joekoe_cms.web_dir_skin%>mail/box_in.gif' border=0></a>&nbsp;
<a href='user_mail.asp?action=box_draft'><img src='<%response.write joekoe_cms.web_dir_skin%>mail/box_draft.gif' border=0></a>&nbsp;
<a href='user_mail.asp?action=box_out'><img src='<%response.write joekoe_cms.web_dir_skin%>mail/box_out.gif' border=0></a>&nbsp;
<a href='user_mail.asp?action=box_recycle'><img src='<%response.write joekoe_cms.web_dir_skin%>mail/box_recycle.gif' border=0></a>&nbsp;
<a href='user_friend.asp'><img src='<%response.write joekoe_cms.web_dir_skin%>mail/address.gif' border=0></a>&nbsp;
<a href='user_mail.asp?action=msg_write'><img src='<%response.write joekoe_cms.web_dir_skin%>mail/write.gif' border=0></a><%
  if action="msg_view" or action="msg_reply" or action="msg_fw" or action="msg_edit" then
    response.write vbcrlf&"<a href='?action=msg_reply&id="&id&"'><img src='"&joekoe_cms.web_dir_skin&"mail/reply.gif' border=0></a>" & _
		   vbcrlf&"<a href='?action=msg_fw&id="&id&"'><img src='"&joekoe_cms.web_dir_skin&"mail/fw.gif' border=0></a>" & _
		   vbcrlf&"<a href='?actions=del&id="&id&"'><img src='"&joekoe_cms.web_dir_skin&"mail/delete.gif' border=0></a>"
  end if
%></td></tr>
</table>
<%
end sub

sub user_mail_view()
  dim accept_u,send_u,isread,word
  sql="select top 1 * from user_mail where (accept_u='"&login_username&"' or send_u='"&login_username&"') and id="&id
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof then
    rs.close
    response.write vbcrlf&"<tr><td class=bg_td colspan=2 height=100 align=center><font class=red>您要"&action_temp&"ID（"&id&"）不存在！</font></td></tr>"
    exit sub
  end if
  accept_u=rs("accept_u")
  send_u=rs("send_u")
  word=rs("word")
  isread=rs("isread")
  'word=joekoe_cms.code_html(word,2,0)
  'word=code_jk_em(word)
  word=code_jk(word)
%>
<tr class=bg_td><td colspan=2>短信主题：<font class=red2><%response.write joekoe_cms.code_html(rs("topic"),1,0)%></font></td></tr>
<tr class=bg_td><td colspan=2 align=center height=100>
  <table border=0 width='96%' class=tf>
  <tr><td class=bw><%response.write word%></td></tr>
  </table>
</td></tr>
<tr class=bg_tds><td colspan=2 align=center>
<% if accept_u=login_username then %>
以上是 <font class=gray>[ <%response.write format_user_name(send_u,0,"")%> ]</font> 于 <font class=blue><%response.write joekoe_cms.time_type(rs("tim"),2)%></font> 给您发送的短信
<% else %>
以上是您于 <font class=blue><%response.write joekoe_cms.time_type(rs("tim"),2)%></font> 给 <font class=gray>[ <%response.write format_user_name(accept_u,0,"")%> ]</font> 发送的短信
<% end if %>
</td></tr>
<%
  rs.close
  if accept_u=login_username and isread=false then
    call joekoe_cms.exec("update user_mail set isread=1 where id="&id,0)
  end if
end sub

sub user_mail_msg()
  if action<>"msg_write" then
    if int(id)<1 then
      call web_js_msg(1,"您要"&action_temp&"的ID为空或不是数字！","?")
      exit sub
    end if
  end if
  if action="msg_view" then
    call user_mail_view()
    exit sub
  end if
  dim accept_u,send_u,topic,word,found_err,types,isread,sendname
  if action="msg_write" then
    accept_u=trim(request.querystring("accept"))
    if symbol_name(accept_u)=false then accept_u=""
  else
    sql="select top 1 send_u,accept_u,topic,word,tim from user_mail where (accept_u='"&login_username&"' or send_u='"&login_username&"') and id="&id
    set rs=joekoe_cms.exec(sql,1)
    if rs.eof then
      rs.close
      response.write vbcrlf&"<tr><td class=bg_td colspan=2 height=100 align=center><font class=red>您要"&action_temp&"ID（"&id&"）不存在！</font></td></tr>"
      exit sub
    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=trim(request.form("accept_u"))
    topic=joekoe_cms.code_form(request.form("topic"))
    word=joekoe_cms.code_form(request.form("word"))
    'word=replace(word,vbcrlf,"")
    found_err=""
    if val_chk("user_mail")=false 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 topic="" or len(topic)>20 then
      found_err=found_err&"+您输入的 <font class=red>短信主题</font> 为空或长度超过20！<br>"
    end if
    if word="" or len(word)>250 then
      found_err=found_err&"+您输入的 <font class=red>短信内容</font> 为空或长度超过250！<br>"
    end if
    if found_err<>"" then
      response.write vbcrlf&"<tr><td class=bg_td colspan=2 align=center height=200>" & _
		     found_error(found_err,250) & _
		     vbcrlf&"</td></tr>"
      exit sub
    end if
    types=1
    isread=0
    sendname="发送"
    sql="select top 1 l_username from user_login where l_username='"&accept_u&"'"
    set rs=joekoe_cms.exec(sql,1)
    if not rs.eof then
      user_on=rs(0)
    end if
    rs.close
    sql="select id,username from user_data where username='"&accept_u&"'"
    set rs=joekoe_cms.exec(sql,1)
    if trim(request.form("send"))<>"later" and user_on=rs(1) then application(joekoe_cms.web_cookies&"_"&rs(0))=rs(0)
    rs.close
    if trim(request.form("send"))="later" then
      types=2
      isread=1
      sendname="保存"
    end if
    sql="insert into user_mail(send_u,accept_u,topic,word,tim,types,isread) " & _
	"values ('"&login_username&"','"&accept_u&"','"&topic&"','"&word&"','"&joekoe_cms.now_time&"',"&types&","&isread&")"
    call joekoe_cms.exec(sql,0)
    call web_js_msg(1,"已成功"&sendname&"一条站内短信！","?")
    call val_chk_end("user_mail")
    exit sub
  end if
%>
<form name=write_frm action='?action=<%response.write action%>&id=<%response.write id%>' method=post onsubmit="javascript:frm_submitonce(this);">
<input type=hidden name=chk value='yes'>
<input type=hidden name=send value=''>
<%response.write val_code_num("user_mail",1)%>
<tr class=bg_td>
<td <%response.write dd1%>>收 件 人：</td>
<td <%response.write dd2%>>
  <table border=0 cellspacing=0 cellpadding=0>
  <tr>
  <td><input type=text name=accept_u value='<%response.write accept_u%>' size=30 maxlength=20><%response.write redx%><=20</td>
  <td>　<%response.write friend_select()%></td>
  </tr>
  </table>
</td>
</tr>
<tr class=bg_tds>
<td>短信主题：</td>
<td><input type=text name=topic value='<%response.write joekoe_cms.code_html(topic,1,0)%>' size=60 maxlength=20></td>
</tr>
<tr class=bg_td>
<td><%call frm_ubb_type(" class=bg_td")%></td>
<td><%call frm_ubb("write_frm","word","",0)%></td>
</tr>
<tr class=bg_td>
<td class=htd>短信内容：<br>EM贴图支持<br>UBB不支持<br>HTML不支持<br>长度<=250字节</td>
<td><textarea name=word rows=7 cols=60><%response.write joekoe_cms.code_word(word)%></textarea></td>
</tr>
<tr class=bg_tds>
<td colspan=2 align=center><%response.write jk_em("write_frm","word")%></td>
</tr>
<tr class=bg_td><td height=30 colspan=2 align=center><input type=submit value='发送短信'>　　<input type=submit value='保存短信' onclick="javascript:return do_later();">　　<input type=reset value='重新填写'>　　<input type=button value='返回上一页' onclick="javascript:history.back(1);"></td></tr>
</form>
<script language=javascript>
function do_accept(addaccept)
{
  if (addaccept!="")
  { document.write_frm.accept_u.value=addaccept; }
}

function do_later()
{
  document.write_frm.send.value="later";
  return true;
}
</script>
<%
end sub

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='' class=bg_td>选择我的好友</option>"
  set rsf=joekoe_cms.exec("select username2 from user_friend 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 user_mail_box()
  dim temp1,pageurl,ttim,isread,td_temp,read_pic,iid,link_temp,name_temp,num_perent
  pageurl="?action="&action&"&"
  temp1=""
  sql="select count(id) from user_mail "&sql_add
  set rs=joekoe_cms.exec(sql,1)
  rssum=rs(0)
  rs.close
  if action="box_in" then
    num_perent=formatpercent(rssum/max_num,1)
%>
<table border=0>
<tr height=30>
<td>您的<%response.write action_temp%>总共可以储存<font class=red><%response.write max_num%></font>条短信，</td>
<td>目前已有<font class=red><%response.write rssum%></font>条短信，</td>
<td>占<font class=red><%response.write num_perent%></font>：</td>
<td>
  <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;">
  <tr>
  <td width="120">
  <div style="height:5px; width:<%response.write num_perent%>; font-size:1px; background-color:#76D769"></div>
  </td>
  </tr>
  </table>
</td>
</tr>
</table>
<%
  end if
%>
<table cellspacing=1 cellpadding=4 class=table>
<form name=del_form action='?actions=delete&action=<%response.write action%>' method=post>
<tr align=center>
<td width='6%' class=td>状态</td>
<td width='16%' class=td><%
if action="box_draft" or action="box_out" then
  response.write "收"
else
  response.write "发"
end if
%>信人</td>
<td width='48%' class=td>短信主题（<%response.write action_temp%>）</td>
<td width='14%' class=td>发送日期</td>
<td width='10%' class=td>大小</td>
<td width='6%' class=td>操作</td>
</tr>
<%
  call format_pagecute()
  sql="select top "&nummer*viewpage&" * from user_mail "&sql_add&" order by id desc"
  call joekoe_cms.exec("",-1)
  rs.open sql,conn,0,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
    td_temp=""
    read_pic="state_old"
    link_temp="msg_view"
    iid=rs("id")
    isread=rs("isread")
    ttim=rs("tim")
    if isread=false then
      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=joekoe_cms.time_type(ttim,3)
%>
<tr align=center<%response.write td_temp%>>
<td class=bg_tds><img src='<%response.write joekoe_cms.web_dir_skin%>mail/<%response.write read_pic%>.gif' border=0></td>
<td class=bg_td><%response.write format_user_name(name_temp,1,"")%></td>
<td class=bg_tds align=left><a href='?action=<%response.write link_temp%>&id=<%response.write iid%>'><%response.write joekoe_cms.code_html(rs("topic"),1,22)%></a></td>
<td class=bg_td><font class=tims><%response.write ttim%></font></td>
<td class=bg_td align=right><font class=tims><font class=blue><%response.write len(rs("word"))%></font>Byte</font></td>
<td class=bg_tds><input type=checkbox name=sel_id value='<%response.write iid%>' class=bg_tds></td>
</tr>
<%
    rs.movenext
  next
  rs.close
%>
<tr class=bg_td height=30><td colspan=6 align=center>
  <table border=0 cellspacing=0 cellpadding=2>
  <tr>
  <td><%response.write action_temp%>共有<font class=red><%response.write rssum%></font>条短信</td>
  <td><font class=gray>（为了节省空间，请及时删除无用信息）</font></td>
  <td><input type=checkbox name=sel_all value='yes' onclick="javascript:select_all(this.form);" class=bg_td>所有</td>
  <td><input type=submit value='删除所选' onclick="return sel_click(this.form);"></td>
  <td><input type=button onclick="javascript:box_clear();" value="清空<%response.write action_temp%>"></td>
  </tr>
  </table>
</td></tr>
</form>
<script language=javascript>
<!--
function box_clear()
{
  if (confirm('确定清空<%response.write action_temp%>所有的短信吗?\n\n清空后将无法恢复！'))
  {
    location.href='?actions=clear&action=<%response.write action%>';
  }
}
-->
</script>
<tr class=bg_tds height=30>
<td colspan=3>&nbsp;页次：<font class=red><%response.write viewpage&"</font>/<font class=red>"&thepages%></font>&nbsp;分页：<% response.write jk_pagecute(nummer,thepages,viewpage,pageurl,5,"#ff0000") %></td>
<td colspan=3 align=center>
  <table border=0 cellspacing=0 cellpadding=2>
  <tr>
  <td><img src='<%response.write joekoe_cms.web_dir_skin%>mail/state_old.gif' border=0 align=absmiddle>&nbsp;已读</td>
  <td><img src='<%response.write joekoe_cms.web_dir_skin%>mail/state_new.gif' border=0 align=absmiddle>&nbsp;未读</td>
  <td><img src='<%response.write joekoe_cms.web_dir_skin%>mail/state_send.gif' border=0 align=absmiddle>&nbsp;草稿</td>
  </tr>
  </table>
</td>
</tr>
</table>
<%
end sub
%>
