<!--#include file="../inc/conn.asp"-->
<%
'============================================================
'插件名称：投票
'Website：http://www.sdcms.cn
'Author：sdcms.cn
'Date：2008-8-25
'============================================================
set sdcms=new sdcms_Power
set sdcms_f=new sdcms_function
show=sdcms_f.LoadFile(""&Load_temp_dir&"sdcms_vote.htm")
sdcms.sdcms_power(id)
response.Write show
	
Sub showvote
show_vote=""
    id=sdcms_f.Requestint(id)
	select case action
		case "shows":shows_vote
		case "add":add_vote:shows_vote
		case else:shows_vote
	end select
end sub	
set sdcms_f=nothing
set sdcms=nothing

sub add_vote

set rs=server.CreateObject("adodb.recordset")
sql="select result from sd_vote where id="&id&""
Rs.Open sql,Conn,1,3 

if  rs.eof then
show_vote=show_vote&"没有此投票" 
else
	if Request.Form("vote")="" then
	show_vote=show_vote&"请投票"
	response.End()
	end if
	if request.cookies("vote_"&id&"")="" then
	   for each ho in Request.Form("vote")
			pollresult=split(Rs(0),"|")
			for i = 0 to (ubound(pollresult)-1)
				if not pollresult(i)="" then
				 
					if int(ho)=i then
						pollresult(i)=pollresult(i)+1
					end if
					allpollresult=""&allpollresult&""&pollresult(i)&"|"
				end if
			next
			 
			Rs(0)=allpollresult
			Rs.update
			allpollresult=""
		next
	 show_vote=show_vote&"<div id=""vote_msg"">恭喜您，投票成功！</div>"
	 response.cookies("vote_"&id&"")=id
	else
	show_vote=show_vote&"<div id=""vote_msg"">您已经投过票了,请勿重复投票</div>"
	end if 
    show_vote=show_vote&"<script>setTimeout(""document.getElementById('vote_msg').style.display = 'none'"",""5000"");</script>"
end if	
end sub

sub shows_vote
sql="select title,vote,result,stype from sd_vote where id="&id&""
set rs=conn.execute(sql)
if rs.eof then
	show_vote=show_vote&"没找到您要的投票"
else
	vote=rs(1)
	result=rs(2)
	total_vote=0
	vote=split(vote,"|")
	result=split(result,"|")
	for i=0 to ubound(result)
	if not result(i)="" then total_vote=result(i)+total_vote
	next
	
	show_vote=show_vote&"<h5>"&rs(0)&"</h5>"
	show_vote=show_vote&"<ul>"
	for i=0 to (ubound(vote)-1)
	if result(i)=0 then
	bl="0%"
	else
	bl=Formatpercent(result(i)/total_vote,0)
	end if
	show_vote=show_vote&"<li>"&i+1&"."&vote(i)&"</li><li><div style=""width:"&bl&";""></div></li><li>"&result(i)&" ("&bl&")</li>"
	next
	show_vote=show_vote&"<li></li><li></li><li><b>总数：</b>"&total_vote&"</li>"
	show_vote=show_vote&"</ul>"
end if
end sub
%>