<!--#include file="conn.asp"-->
<!--#include file="inc/function.asp"-->
<%
dim id,rs,sql,qid,a
id=Trim(Request.QueryString("id"))
qid=Trim(Request.QueryString("qid"))
a=Trim(Request.QueryString("a"))
if Request.Cookies("Muser")="" then
   Response.Write("请先登录")
   Response.End()
end if

Dim AskD
Set AskD = Server.CreateObject("KwAsk.FunAsk")
	opendb
	set AskD.myConn =conn
	AskD.myPredb =predb
	AskD.Getsetting()
	siteinfo=AskD.siteinfo
	setting=AskD.setting

set rs=conn.execute("select state from "&predb&"ask where askid="&qid)
if rs(0)<>4 then
   Response.Write("投票已经结束，谢谢！")
   Response.End()
   set rs=nothing
end if
set rs=nothing


set rs= Server.CreateObject("adodb.recordset")
sql="select myTp from "&predb&"user where id="&Request.Cookies("Muser")
rs.open sql,conn,1,3

	if instr(rs(0)&",",","&id&",")>0 then
	   Response.Write("已经投过该问题")
	else
	   rs(0)=rs(0)&","&id
	   rs.update
	   if a="zc" then
	      conn.execute("update "&predb&"ans set zctp=zctp+1 where askid="&qid)
	   elseif a="fd" then
	      conn.execute("update "&predb&"ans set fdtp=fdtp+1 where askid="&qid)
	   else
	      conn.execute("update "&predb&"ans set tpNum=tpNum+1 where ansid="&id)
	   end if
	      conn.execute("update "&predb&"ask set Sumtp=Sumtp+1 where askid="&qid)
	   Response.Write("投票成功")
	   Call AskD.Score(Request.Cookies("Muser"),setting(16),"参与投票")
	end if
rs.close
set rs=nothing

dim ansid,ansuser,rs1
set rs= Server.CreateObject("adodb.recordset")
sql="select AskTime,tpmax,sumtp,state,bcnUser,bcnAns from "&predb&"ask where askid="&qid
rs.open sql,conn,1,3
   if DateDiff("h",rs(0),now())>=setting(27)*24 then
      if rs(2)=0 then
	     rs("state")=2
	  else
		  if a="" then	 
			 set rs1=conn.execute("select top 1 ansid,ansuser from "&predb&"ans where askid="&qid&" and istp=1 order by tpnum desc")
			 ansid=rs1(0)
			 ansuser=rs1(1)
			 set rs1=nothing
			 conn.execute("update "&predb&"ans set isCn=1 where ansid="&ansid)
			 conn.execute("update "&predb&"user set Bcn=Bcn+1 where id="&ansuser)
			 rs("state")=5
			 rs("bcnUser")=ansUser
			 rs("bcnAns")=ansID
		  else
			 set rs1=conn.execute("select ansid,ansuser from "&predb&"ans where askid="&qid&" and istp=1")
			 ansid=rs1(0)
			 ansuser=rs1(1)
			 set rs1=nothing
			 conn.execute("update "&predb&"ans set isCn=1 where zctp>fdtp and ansid="&ansid)
			 conn.execute("update "&predb&"user set Bcn=Bcn+1 where id="&ansuser)
			 rs("state")=5
			 rs("bcnUser")=ansUser
			 rs("bcnAns")=ansID
		  end if
	  end if
   else
      if rs(2)>=rs(1) then
	     if a="" then
			 set rs1=conn.execute("select top 1 ansid,ansuser from "&predb&"ans where askid="&qid&" and istp=1 order by tpnum desc")
			 ansid=rs1(0)
			 ansuser=rs1(1)
			 set rs1=nothing
			 conn.execute("update "&predb&"ans set isCn=1 where ansid="&ansid)
			 conn.execute("update "&predb&"user set Bcn=Bcn+1 where id="&ansuser)
			 rs("state")=5
			 rs("bcnUser")=ansUser
			 rs("bcnAns")=ansID
		 else
			 set rs1=conn.execute("select ansid,ansuser from "&predb&"ans where askid="&qid&" and istp=1")
			 ansid=rs1(0)
			 ansuser=rs1(1)
			 set rs1=nothing
			 conn.execute("update "&predb&"ans set isCn=1 where zctp>fdtp and ansid="&ansid)
			 conn.execute("update "&predb&"user set Bcn=Bcn+1 where id="&ansuser)
			 rs("state")=5
			 rs("bcnUser")=ansUser
			 rs("bcnAns")=ansID
		 end if
	  end if
   end if
rs.update

rs.close
set rs=nothing
set AskD.myConn =Nothing
closedb
Set AskD = Nothing
%>
<input type="button" name="button2" id="button2" value="  确 定  " onClick="new parent.dialog().reset();"/>