<!--#include file="inc_const.asp"-->
<%response.expires=0
Response.CacheControl = "Private"
application.lock

set cschat=server.createobject("ffcschat.cssbchat")
my_level=cschat.getLevel(Session,Application(ConstStr & "_user_list"),Application(ConstStr & "_room_list"))

if my_level=0 then
  set cschat=nothing
  application.unlock
  response.end
end if
myname=cschat.myname

songzj = replace(replace(replace(Trim(Request.Form("songzj")),".",""),"/",""),"\","") 
song = Trim(Request.Form("song"))
cschat.FilterStr = Application(ConstStr & "_saysfilterstr")
towho = cschat.Trdb(Request.Form("towho"))
zc = cschat.trdb(Request.Form("zc"))
If songzj = "" Or song = "" Then
  errText="请选择所需曲目。"
elseIf towho = "" Then
 errText="请指定发送对象。"
elseIf towho = myname Then
 errText="不需要给自己点歌。"
elseIf zc = "" Then
 errText="祝词不能为空。"
elseIf Len(zc) > 300 Then
 errText="祝词不能超过 300 个字符。"
elseif instr(Application( ConstStr & "_user_list"),"<$"&towho&"$>")=0 then
 errText="对方不在聊天室中，不能发送！"
else
  midipath = Server.MapPath("mid\" & songzj & "\" & song)
  Set fs = CreateObject("Scripting.FileSystemObject")
  cz = fs.FileExists(midipath)
  Set fs = Nothing

  If cz = False Then
    errText="选定的曲目不存在！\n\n请返回并刷新曲目列表。"
  else
    Set Conn=Server.CreateObject("ADODB.Connection")
    conn.open Application( ConstStr & "_connstr")
    sql = "SELECT username FROM user WHERE username = '" & towho & "'"
    set rs=conn.execute(sql)
    If rs.EOF And rs.Bof Then
     errText="用户名还未注册！"
    else
     midipath="mid/"&songzj&"/"&song
     zc = "<font color=black style=font-size:10.5pt>【点歌】</font>"&zc&"<br>　<a target=_blank href=" &chr(34)& replace(midipath,"'","\''") &chr(34)&">[未经编码的链接]</a>　<a target=_blank href=" &chr(34)& Server.URLEncode(midipath) &chr(34)& ">[经UTF-8编码的链接]</a>"
     conn.execute("insert into calls (who,towho,callmess,calltime,read) values ('"&myname&"','"&towho&"','"&zc&"','"&now()&"',false)")

     says = Application(ConstStr & "_says")
     current = Application(ConstStr & "_current")
     cschat.newsay towho,towho,1,-2,"<\script>window.open(\'getcall.asp\',\'\',\'width=500,height=300,scrollbars=1\');</\script>","#","#",-5,says,current
     Application(ConstStr & "_says") = says
     Application(ConstStr & "_current") = current

     errText="歌曲已经发送给“" + towho + "”。"
    end if
    rs.Close
    conn.Close
    Set rs = Nothing
    Set conn = Nothing
  end if
end if
set cschat=nothing
 Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=gb2312'><meta http-equiv='pragma' content='no-cache'><body>"
 Response.Write "<script Language=JavaScript>"
 Response.Write "parent.chcolor();alert('" & errText & "');history.go(-1);"
 Response.Write "</script>"
 application.unlock
 Response.End
%>