<!--#include file="inc_const.asp"-->
<%response.expires=0
Response.CacheControl = "Private"
application.lock
set cschat=server.createobject("ffcschat.cssbchat")
all_user_array=split(Application(ConstStr & "_user_list"),"$><$")
says = Application(ConstStr & "_says")
current = Application(ConstStr & "_current")
clear_str=""
for i=0 to UBound(all_user_array) step 2
  all_user_array2=split(all_user_array(i),"$>")
  if datediff("s",all_user_array2(6),now())>300 then
    user_name=replace(all_user_array2(0),"<$","")
    application(ConstStr & "_user_list")=cschat.DelList(application(ConstStr & "_user_list"),user_name)
 
    room_id=all_user_array2(5)
    if instr(Application(ConstStr & "_room_list"),"<$"&room_id&"$>")<>0 then  Application( ConstStr & "_room_list")=cschat.SetListValue(Application( ConstStr & "_room_list"), room_id, 12, user_name, -1)
    say_mess=split(application(ConstStr & "_userloseshow"),"::")
    say_mess(0)=say_mess(0) & "<\script>parent.dell(\'" & user_name & "\')</\script>"
    cschat.newsay user_name,"大家",0,room_id,say_mess(0),say_mess(1),say_mess(2),-2,says,current
    clear_str=clear_str & ",'" & user_name & "'"
  end if
next
Set Conn=Server.CreateObject("ADODB.Connection")
conn.open Application( ConstStr & "_connstr")
if clear_str<>"" then
 clear_str=mid(clear_str,2)
 conn.Execute("UPDATE user SET out_time='"&now()&"',out_info=1,room_id=0 WHERE username in ("& clear_str &")")
end if

set rs=conn.execute("select * from scrollad where ad_new_flag=1 order by ID desc")
if not (rs.eof or rs.bof) then
  adstr="<\script>"
  do while not rs.eof
   adstr=adstr&"parent.addnews(\'" & rs("ad_link") & "\',\'" & rs("ad_title") & "\');"
   rs.movenext
  loop
  adstr=adstr&"</\script>"
  cschat.newsay "大家","",0,-2,adstr,"","",-5,says,current
  conn.execute("update scrollad set ad_new_flag=0 where ad_new_flag=1")
end if
if Application(ConstStr & "_enablequestion")="1" then
 if isempty(Application( ConstStr & "_answers")) or isnull(Application( ConstStr & "_answers")) then
    dim Ianswers(7)
    Ianswers(0)=0
    Ianswers(5)=now()
    Application( ConstStr & "_answers")=Ianswers
    Set qConn=Server.CreateObject("ADODB.Connection")
    qconn.open "DBQ="+server.mappath("questions.asp")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
    set qrs=qconn.execute("select count(*) as qc from questlib")
    Application( ConstStr & "_quest_num")=qrs("qc")
    qrs.close
    qconn.close
    set qconn=nothing
    set qrs=nothing
 else
  answers=Application( ConstStr & "_answers")
  if answers(0)=1 then
    if answers(6)-Application( ConstStr & "_questionasktimes")>0 then
      answers(0)=0
      answers(5)=now()
      say_mess=split(application(ConstStr & "_questionendshow"),"::")
      say_mess(0)=replace( replace(say_mess(0),"$Q",answers(2)) ,"$T",answers(1))
      cschat.newsay Application( ConstStr & "_questionautoman"),"大家",0,answers(7),say_mess(0),say_mess(1),say_mess(2),-2,says,current
    else
      answers(5)=now()
      answers(6)=answers(6)+1
      say_mess=split(application(ConstStr & "_questionaskshow"),"::")
      say_mess(0)=replace(replace(say_mess(0),"$Q",answers(2)),"$T",answers(1))&"<a href=\'\' style=color:3366ff onclick=\""var a=prompt(\'请输入答案！\',\'答案\');if (a) window.open(\'qanswer.asp?answer=\'+escape(a),\'newsay\');return false;\"">点击此处答题！</a>"
      cschat.newsay Application( ConstStr & "_questionautoman"),"大家",0,answers(7),say_mess(0),say_mess(1),say_mess(2),-2,says,current
    end if
  elseif datediff("n",answers(5),now())-application(ConstStr & "_questiontimeinterval")>0 then
    all_user_array=split(Application(ConstStr & "_user_list"),"$><$")
    all_user_num=(UBound(all_user_array)+1)\2
    if all_user_num-Application( ConstStr & "_questionminpeople")>=0 and all_user_num-Application( ConstStr & "_questionmaxpeople")<=0 then
      randomize
      Set qConn=Server.CreateObject("ADODB.Connection")
      qconn.open "DBQ="+server.mappath("questions.asp")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
      set qrs=qconn.execute("select * from questlib where ID="&clng(rnd*Application( ConstStr & "_quest_num")+1))
      if not (qrs.eof or qrs.bof) then
        answers(0)=1
        answers(1)=qrs("stype")
        answers(2)=qrs("squestion")
        answers(3)=qrs("sanswer")
        answers(4)=qrs("addexp")
        answers(5)=now()
        answers(6)=2
        if Application( ConstStr & "_questionroomid") <>"-2" then
          roomindex=cint(Application( ConstStr & "_questionroomid"))
          if roomindex<1 then
            answers(7)=-2
          else
            all_room_array=split(Application(ConstStr & "_room_list"),"$><$")
            if ubound(all_room_array)<((roomindex-1)*2+1) then
              answers(7)=-2
            else
              answers(7)=replace(all_room_array((roomindex-1)*2+1),"$>","")
            end if
          end if
        else
          answers(7)=-2
        end if
        say_mess=split(application(ConstStr & "_questionaskshow"),"::")
        say_mess(0)=replace(replace(say_mess(0),"$Q",answers(2)),"$T",answers(1))&"<a href=\'\' style=color:3366ff onclick=\""var a=prompt(\'请输入答案！\',\'答案\');if (a) window.open(\'qanswer.asp?answer=\'+escape(a),\'newsay\');return false;\"">点击此处答题！</a>"
        cschat.newsay Application( ConstStr & "_questionautoman"),"大家",0,answers(7),say_mess(0),say_mess(1),say_mess(2),-2,says,current
      end if
      qrs.close
      qconn.close
      set qconn=nothing
      set qrs=nothing
    end if
  end if
  Application( ConstStr & "_answers")=answers
 end if
end if
Application(ConstStr & "_says") = says
Application(ConstStr & "_current") = current

set cschat=nothing
votes=application(ConstStr & "_votes")
if (votes(0)>0 and datediff("s",votes(5),now())>60 and votes(6)) or (votes(0)>0 and datediff("s",votes(5),now())>120) then
 response.redirect "votecheck.asp"
end if
application.unlock%>