<!-- #include file="include/skin.asp" -->
<%

dim vid
vid=trim(request.querystring("vid"))
if not joekoe_cms.int_true(vid) then vid=0
tit="查看投票结果"
if action="ballot" then tit="投上一票"
call web_head(0,0,4,0,0)
%>
<table border=0 cellspacing=0 cellpadding=0 width='100%' height='100%'>
<tr class=bg_td><td width='100%' height='100%'>
  <table border=0 cellspacing=0 cellpadding=0 width='100%' height='100%'>
  <tr><td align=center>
<%
if int(vid)<1 then
  response.write "<font class=red>投票（ID："&vid&"）不符合ID规则！</font>"
else
  select case action
  case "ballot"
    call vote_ballot()
  case else
    call vote_view()
  end select
end if
%>
  </td></tr>
  <tr><td height=30 align=center><%call web_copy()%></td></tr>
  </table>
</td></tr>
</table>
<%
call web_end(0,1)

sub vote_ballot()
  dim vote_id,vtype,vdim,vtmp
  vote_id=trim(request.form("vote_id"))
  if vote_id="" or isnull(vote_id) then 
    response.write "<font class=red>投票项不能为空！！！</font>"
    exit sub  
  end if
  sql="select top 1 vtype from vote where vid="&vid&" and vtype<>1 order by id"
  set rs=joekoe_cms.exec(sql,1)
  vtype=rs(0)
  rs.close
  if int(vtype)<>2 then
    if not joekoe_cms.int_true(vote_id) then
      response.write "<font class=red>投票参数有错误！你是不是搞错了？！</font>"
      exit sub
    end if
  end if
  vtmp="<br><br><a href='?type=view&vid="&vid&"'>查看投票结果</a><br><br><font class=gray>（系统将在 "&dim_num(21)&" 秒钟后自动返回）</font><br><meta http-equiv='refresh' content='"&dim_num(21)&"; url=?type=view&vid="&vid&"'>"
  if trim(request.cookies(joekoe_cms.web_cookies)("vote_vid"))="v"&vid then
    response.write "<font class=red2>您已经投过一票！不可以重复多投……</font>"&vtmp
    exit sub
  end if
  response.cookies(joekoe_cms.web_cookies)("vote_vid")="v"&vid
  if int(vtype)<>2 then
    call joekoe_cms.exec("update vote set counter=counter+1 where vid="&vid&" and id="&vote_id,0)
    response.write "<font class=red>投票成功！谢谢你的支持和参与！</font>"&vtmp
    exit sub
  end if
  vote_id=replace(vote_id," ","")
  vdim=split(vote_id,",")
  for i=0 to ubound(vdim)
    if joekoe_cms.int_true(vdim(i)) then
      call joekoe_cms.exec("update vote set counter=counter+1 where vid="&vid&" and id="&vdim(i),0)
    end if
  next
  response.write "<font class=red>投票成功！谢谢你的支持和参与！</font>"&vtmp
end sub

sub vote_view()
  dim vdim,vnum,vsum,nwid,nper
  sql="select vname,counter from vote where vid="&vid&" order by id"
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof then
    rs.close
    response.write "<font class=red>投票（ID："&vid&"）不存在！你是不是搞错了？！</font>"
    exit sub
  end if
  vdim=rs.getrows()
  rs.close
  vnum=ubound(vdim,2)
  vsum=0
  for i=0 to vnum
    vsum=vsum+vdim(1,i)
  next
%>
<table border=0 cellspacing=1 cellpadding=2 width='96%'>
<tr><td colspan=5 height=30 align=center><font class=blue size=3><b><%response.write vdim(0,0)%></b></font></td></tr>
<tr><td colspan=5 align=center>目前共有 <font class=red><%response.write vsum%></font> 人参与了投票</td></tr>
<tr>
<td width=10></td>
<td width=120></td>
<td width=*></td>
<td width=30></td>
<td width=40></td>
</tr>
<%
  for i=1 to vnum
    nwid=1
    nper="0%"
    if int(vdim(1,i))>0 then
      nwid=cint(replace(formatpercent(vdim(1,i)/vsum),"%",""))*1.5
      nper=formatpercent(vdim(1,i)/vsum,2)
    end if
%>
<tr height=24>
<td class=tims align=center><%response.write i%></td>
<td><%response.write vdim(0,i)%></td>
<td><img src='images/vote/vb<%response.write i%>.gif' border=0 height=10 width='<%response.write nwid%>'></td>
<td class=tims align=right><font class=blue><%response.write vdim(1,i)%></font>票</td>
<td class=tims><%response.write nper%></td>
</tr>
<%
  next
  erase vdim
%>
</table>
<%
end sub
%>