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

call time_lock()
if not isnumeric(viewid) then
  call format_redirect("forum.asp")
end if
%>
<!-- #include file="include/con_forum_fir.asp" -->
<!-- #include file="include/con_forum_vote.asp" -->
<%
dim fir_topic,fir_islock,fv_name,fv_num,fv_type,fv_tim,fv_day,fv_username,dim_vnum,num_vnum
sql="select top 1 bbs_topic.forum_id,bbs_topic.topic,bbs_topic.islock,bbs_vote.v_name,bbs_vote.v_num,bbs_vote.v_type,bbs_vote.v_tim,bbs_vote.v_day,bbs_vote.v_username " & _
    "from bbs_topic,bbs_vote where bbs_topic.isvote=1 and bbs_vote.reply_id="&viewid&" and bbs_topic.id="&viewid
set rs=joekoe_cms.exec(sql,1)
if rs.eof then
  call web_error("forum_viewid")
end if
forumid=rs(0)
fir_topic=rs(1)
fir_islock=rs(2)
fv_name=rs(3)
fv_num=rs(4)
fv_type=rs(5)
fv_tim=rs(6)
fv_day=rs(7)
fv_username=rs(8)
rs.close
ftit="投票"

call forum_first()
call web_head(0,0,h_var3,0,0)
call forum_load()
'----------------------------中间 开始----------------------------
call forum_grade()
call forum_top(tit)

if joekoe_cms.post_chk() then
  response.write vbcrlf&"<table cellspacing=1 cellpadding=4 class=table>"
  response.write vbcrlf&"<tr><td colspan=2 class=td0>&nbsp;"&img_skin(web_img_m)&"&nbsp;"&tit&"</td></tr>"
  response.write vbcrlf&"<tr><td colspan=2 class=bg_td align=center height=200>"
  dim_vnum=split(fv_num,"|")
  num_vnum=ubound(dim_vnum)
  call forum_vote_chk()
  erase dim_vnum
  response.write vbcrlf&"</td></tr>"
  response.write vbcrlf&"</table>"
  response.write vbcrlf&ukong
else
  call forum_vote_type()
end if
'----------------------------中间 结束----------------------------
call forum_end()
call web_end(0,0)

sub forum_vote_chk()
  dim found_err,vote_nid,vote_nid2,dim_nid,ii,vnum
  vote_nid=trim(request.form("vote_nid"))
  found_err=""
  if not post_tim() then
    found_err=found_err&"+对不起，投票的间隔时间为 <font class=red>"&int(dim_num(28))&"</font> 秒！<br>"
  end if  
  if int(fir_islock)>0 then
    found_err=found_err&"+<font class=red>此投票贴已被锁定，不能再对其进行投票！</font><br>"
  end if
  if login_mode="" then
    found_err=found_err&"+<font class=red>您还没有注册或登陆，因此不能投票！</font><br>"
  else
    if instr("|"&fv_username,"|"&login_username&":")>0 then
      found_err=found_err&"+您已经投过一票，不能再对其进行投票！<br>"
    end if
  end if
  if int(fv_day)>0 then
    if joekoe_cms.now_time<dateadd("d",fv_day,fv_tim) then
      found_err=found_err&"+本投票已过期，不能再对其进行投票！<br>"
    end if
  end if
  if vote_nid="" then
    found_err=found_err&"+您提交的投票项为空，至少要选择一项！<br>"
  else
    vote_nid2=vote_nid
    vote_nid2=replace(vote_nid2," ","")
    vote_nid2=replace(vote_nid2,",","")
    for i=1 to len(vote_nid2)
      if not isnumeric(mid(vote_nid2,i,1)) then
        found_err=found_err&"+<font class=red>您提交的投票项参数有严重错误！</font><br>"
        exit for
      end if
    next
    if fv_type=false then
      if not isnumeric(vote_nid) then
        found_err=found_err&"+您提交的投票项为空或参数有错误！<br>"
      else
        if int(vote_nid)>int(num_vnum) or int(vote_nid)<0 then
          found_err=found_err&"+您提交的投票项为空或参数有错误！<br>"
        end if
      end if
    end if
  end if
  if found_err<>"" then
    response.write found_error(found_err,250)
    exit sub
  end if
  
  vnum=0
  if fv_type then
    vote_nid=replace(vote_nid," ","")
    dim_nid=split(vote_nid,",")
    for i=0 to ubound(dim_nid)
      if isnumeric(dim_nid(i)) then
        if int(dim_nid(i))<=int(num_vnum) and int(dim_nid(i))>=0 then
          dim_vnum(dim_nid(i))=dim_vnum(dim_nid(i))+1
          vnum=vnum+1
        end if
      end if
    next
    erase dim_nid
  else
    dim_vnum(vote_nid)=dim_vnum(vote_nid)+1
    vnum=vnum+1
  end if
  fv_num=""
  for i=0 to num_vnum
    if fv_num="" then
      fv_num=dim_vnum(0)
    else
      fv_num=fv_num&"|"&dim_vnum(i)
    end if
  next
  if fv_username="" then
    fv_username=login_username&":"&vote_nid
  else
    fv_username=fv_username&"|"&login_username&":"&vote_nid
  end if
  sql="select top 1 v_num,v_username from bbs_vote where reply_id="&viewid
  call joekoe_cms.exec("",-1)
  rs.open sql,conn,1,3
  rs("v_num")=fv_num
  rs("v_username")=fv_username
  rs.update
  rs.close
  sql="update bbs_topic set vote_num=vote_num+"&vnum&",re_username='"&login_username&"',re_tim='"&joekoe_cms.now_time&"' where id="&viewid
  call joekoe_cms.exec(sql,0)
  sql="update bbs_forum set forum_new_info='"&login_username&"|"&joekoe_cms.now_time&"|"&viewid&"|"&fir_topic&"' where forum_id="&forumid
  call joekoe_cms.exec(sql,0)
  
  response.write vbcrlf&"<table border=0 width=300>" & _
        	 vbcrlf&"<tr><td align=center height=30><font class=red>"&tit&"成功！谢谢您的投票。</font></td></tr>" & _
        	 vbcrlf&"<tr><td height=30>您现在可以选择以下操作：</td></tr>" & _
        	 vbcrlf&"<tr><td>　　1、<a href='forum_view.asp?forum_id=" & forumid & "&view_id=" & viewid & "'>您所投票的主题</a>" & _
        	 vbcrlf&"<tr><td>　　2、<a href='forum_list.asp?forum_id=" & forumid & "'>返回 <b>" & forumname & "</b></a></td></tr>" & _
        	 vbcrlf&"<tr><td>　　3、<a href='forum.asp'>返回论坛首页</a></td></tr>" & _
        	 vbcrlf&"<tr><td height=30>系统将在 "&dim_num(2)&" 秒钟后自动返回 <b>" & forumname & "</b> ……</td></tr>" & _
		 vbcrlf&"</table><meta http-equiv='refresh' content='"&dim_num(2)&"; url=forum_list.asp?forum_id=" & forumid & "'>"

end sub

%>