<%
class joekoe_mail
  public sort,closes,chk,mhei,h_sel,h_accept,h_topic,h_word,h_send
  public m_tit,m_frm,m_accept,m_topic,m_word,ok_var
  
  private sub class_initialize()
    sort="mail"
    closes=false
    chk=false
    mhei=200
    m_tit="发送站内短信"
    h_sel="请选择收信人"
    h_accept="收 件 人"
    h_topic="短信主题"
    h_word="短信内容"
    h_send="发送短信"
    ok_var="已成功发送一条站内短信！"
  end sub
  
  sub mail_chk()
    response.write vbcrlf&"<table cellspacing=1 cellpadding=4 class=table>" & _
		   vbcrlf&"<tr><td class=td colspan=2>&nbsp;"&img_skin("m_")&m_tit&"</td></tr>"
    if login_mode="" then
      if closes then
        response.write "<script language=javascript>alert(""您现在还没有登陆本站！\n\n请先注册并登陆本站。"");window.close();</script>"
      else
        response.write "<tr><td class=bg_td height="&mhei&" colspan=2>&nbsp;"&web_nologin&"</td></tr>"
      end if
    else
      if joekoe_cms.chk() then
        call mail_send()
      else
        call mail_body()
      end if
    end if
    response.write vbcrlf&"</table>"
  end sub
  
  sub mail_send()
    response.write vbcrlf&"<tr><td class=bg_td colspan=2 height="&mhei&" align=center class=htd>"
    dim found_err,accept_u,topic,word,types,isread
    types=1
    isread=0
    accept_u=trim(request.form("accept_u"))
    topic=joekoe_cms.code_form(request.form("topic"))
    word=joekoe_cms.code_form(request.form("word"))
    found_err=""
    if val_chk(sort)=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>"&h_accept&"</font> 为空或不存在！<br>"
    end if
    if topic="" or len(topic)>20 then
      found_err=found_err&"+您输入的 <font class=red>"&h_topic&"</font> 为空或长度超过20！<br>"
    end if
    if word="" or len(word)>250 then
      found_err=found_err&"+您输入的 <font class=red>"&h_word&"</font> 为空或长度超过250！<br>"
    end if
    if found_err<>"" then
      response.write found_error(found_err,250)
      response.write vbcrlf&"</td></tr>"
      exit sub
    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)
    response.write vbcrlf&"<font class=red>"&ok_var&"</font>"
    if closes then response.write "<br><br><a href='javascript:window.close();'>关闭本窗口（系统将在"&dim_num(21)&"秒后自动关闭）</a><script language=javascript>setTimeout(""window.close()"","&dim_num(21)*1000&");</script>"
    response.write vbcrlf&"</td></tr>"
    call val_chk_end(sort)
    chk=true
  end sub
  
  sub mail_body()
    dim ai,adim,afir,atmp
    afir=""
    adim=split(m_accept,"|")
    for ai=0 to ubound(adim)
      if afir="" then afir=adim(ai)
      atmp=atmp&vbcrlf&"<option value='"&adim(ai)&"'>"&adim(ai)&"</option>"
    next
    erase adim
%>
<form name=write_frm action='<%response.write m_frm%>' method=post onsubmit="javascript:frm_submitonce(this);">
<input type=hidden name=chk value='yes'>
<%response.write val_code_num(sort,1)%>
<tr class=bg_td>
<td <%response.write dd1%>><%response.write h_accept%>：</td>
<td <%response.write dd2%>>
  <table border=0 cellspacing=0 cellpadding=0>
  <tr>
  <td><input type=text name=accept_u value='<%response.write afir%>' readonly size=30 maxlength=20><%response.write redx%><=20</td>
  <td>&nbsp;<select name=friend_select size=1 onchange="javascript:do_accept(this.options[this.selectedIndex].value);">
<option value='' class=bg_td><%response.write h_sel%></option>
<%response.write atmp%>
</select></td>
  </tr>
  </table>
</td>
</tr>
<tr class=bg_tds>
<td><%response.write h_topic%>：</td>
<td><input type=text name=topic value='<%response.write m_topic%>' size=60 maxlength=20></td>
</tr>
<tr class=bg_td>
<td class=htd><%response.write h_word%>：<br>EM贴图支持<br>UBB不支持<br>HTML不支持<br>长度<=250字节</td>
<td><textarea name=word rows=7 cols=60><%response.write joekoe_cms.code_word(m_word)%></textarea></td>
</tr>
<tr class=bg_tds>
<td colspan=2 align=center height=30><%response.write jk_em("write_frm","word")%></td>
</tr>
<tr class=bg_td><td height=40 colspan=2 align=center><input type=submit class=btn value=' <%response.write h_send%> '>　　　<input type=reset class=btn value=' 重新填写 '></td></tr>
</form>
<script language=javascript>
function do_accept(addaccept)
{
  if (addaccept!="")
  { document.write_frm.accept_u.value=addaccept; }
}
</script>
<%
  end sub
end class

function true_accept(auser)
  true_accept=false
  if symbol_name(auser)=true then
    dim rsf
    set rsf=joekoe_cms.exec("select top 1 username from user_data where username='"&auser&"'",1)
    if not rsf.eof then
      auser=rsf(0)
      true_accept=true
    end if
    rsf.close
    set rsf=nothing
  end if
end function
%>