<!--#include file="inc/config.asp"-->
<!--#include file="inc/conn.asp"-->
<HTML>
<HEAD>
<TITLE>查看投票</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<style>
body,td,input,textarea {font-size:9pt}
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.style1 {
	color: #FFFFFF;
	font-weight: bold;
}
</style>

</HEAD>
<BODY>
<%
dim id,title,optionType,voteType,totalNum
id=Clng(request("id"))
if(id<1) then
	response.Write("没有找到id="&id&"的记录！")
	response.End()
end if
if isnull(request.cookies("TotVote")) or request.cookies("TotVote")="" then
	response.cookies("TotVote")="|"
	response.cookies("TotVote").Expires=Date+365
end if
Set rs = Server.CreateObject("Adodb.RecordSet")				 
rs.Open "Select top 1 * from vote where id="&id,conn,3,1
if not rs.eof then
	title=rs("title")
	optionType=rs("optionType")
	if(optionType=0) then
		voteType="radio"
	else
		voteType="checkbox"
	end if
	if(rs("status")<>1) then
		response.Write("投票已过期或暂时关闭.")
		response.End()
	end if
	If datediff("s",now(),formatdatetime(rs("expiresTime")))<0 then
		response.Write("投票已过期.")
		response.End()
	end if
	if instr(request.cookies("TotVote"),"|"&id&"|")<>0 then 
		Response.Write("<script>alert(""已经投过票了！"");</script>")  
		call show()
		response.end
	end if
	if voteType="radio" then 
		if isnull(request("vote")) or request("vote")="" then 
			Response.Write("<script>alert(""请选择您要投票的选项！"");window.close();</script>")  
			response.end
		end if
		conn.Execute("update voteitem set clicks=clicks+1 where id="&Cint(request("vote")))
		Response.Write("<script>alert(""成功投票！"");location.href=""vote_result.asp?id="&id&"""</script>") 
	elseif voteType="checkbox" then
		if request("vote").count=0 then
			Response.Write("<script>alert(""请选择您要投票的选项！"");window.close();</script>")  
			response.end
		end if
		for i=1 to request("vote").count
			sql="update voteitem set clicks=clicks+1 where id="&Cint(request("vote")(i))
			conn.Execute(sql)
		next
		Response.Write("<script>alert(""成功投票！"");location.href=""vote_result.asp?id="&id&"""</script>") 
	end if
	response.cookies("TotVote")=request.cookies("TotVote")&id&"|"
	response.cookies("TotVote").Expires=Date+365
else
	response.Write("没有找到记录")
	response.End()
end if
rs.close
set rs=nothing
call show()
Function show
	response.write "<script>location.href=""vote_result.asp?id="&id&""";</script>"
	response.end
End Function
%>
</BODY>
</HTML>
<%
call connclose()
%>