<!--#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"))
myname=cschat.myname
set cschat=nothing
application.unlock
if my_level=0 then
  response.redirect("showerr.asp")  
  response.end
end if

votename=request("name")
sel_op=request("sel_op")
Set Conn=Server.CreateObject("ADODB.Connection")
conn.open Application( ConstStr & "_connstr")
set rs=conn.execute("select * from vote where votename='"&votename&"' and voteoptions='"&sel_op&"'")
errText=""
if rs.eof or rs.bof then
  errText="投票事件不存在或你提交的候选为非法！"
else
  set rs=conn.execute("select * from vote where votename='"&votename&"' and exp_num<>1")
  if rs("begin_time")<>rs("end_flag") and datediff("s",rs("end_flag"),now())>0 then
    Response.Redirect("tpjg.asp?name="&votename)
    response.end
  elseif instr(rs("voted_user"),myname&" ")<>0 then
    errText="你已经投过票了！"
  else
    set rs1=conn.execute("select * from user where username='"&myname&"'")
    if DATEDIFF("s",rs1("log_time"),rs("begin_time"))<0 then
      errText="你是投票事件产生后才注册的用户！"
    elseif rs("exp_num")<10 and rs1("user_level")<rs("exp_num") then
      errText=rs("exp_num")&"级及以上用户才有投票的资格！"
    elseif rs("exp_num")>10 and rs1("exp_num")<rs("exp_num") then
      errText="经验值"&rs("exp_num")&"点及以上用户才有投票的资格！"
    else
      conn.execute("UPDATE vote SET votenum=votenum+1,voted_user=voted_user&'"&myname&" ' WHERE votename='"&votename&"' and voteoptions='"&sel_op&"'")
      conn.execute("UPDATE vote SET votenum=votenum+1,voted_user=voted_user&'"&myname&" ' WHERE votename='"&votename&"' and exp_num<>1")
      errText="你成功地投出了一票！"
    end if
    rs1.close
    set rs1=nothing
  end if
end if
rs.close
set rs=nothing
conn.close
set conn=nothing
response.redirect("showerr.asp?errtext="&errText)%>