<!-- #Include File="Include/Config.asp" -->
<!-- #include file="Include/Con_bbs_Fir.asp" -->
<!-- #include file="Include/Con_bbs_Vote.asp" -->
<%

'=======================================================
' 欢迎使用《阿赛大型门户网站系统V3.0》，简称“AsaiMHV3”
' 技术支持、商业版咨询、官方唯一指定联系QQ“4941172”
' 官方网站：http://77ya.com      程序负责人：阿赛
'=======================================================

tit_fir=Cls.ChannelName
dim dim_votetopic,dim_vnum,num_vnum
sql="select top 1 t.bbs_id,t.topic,t.islock,v.v_name,v.v_num,v.v_type,v.v_tim,v.v_day,t.vote_num,v.v_username " & _
    "from AsaiMHBbsTopic as t,AsaiMHBbsVote  as v where t.isvote=1 and v.reply_id="&viewid&" and t.id="&viewid
set rs=Cls.exec(sql,1)
if rs.eof then
  rs.close
  call web_error("bbs_view")
end if
dim_votetopic=rs.getrows()
rs.close
Bbsid=dim_votetopic(0,0)
ftit="投票"
call bbs_first()
call DoWebHead(2,1)
Cls.LoadTemplate(4)
Response.write Cls.ReHtml(ShowWebHead(1),1)
call bbs_load_power()
'----------------------------中间 开始----------------------------
call bbs_grade(0)
call bbs_top(0,"")
if Cls.post_chk() then
  dim_vnum=split(dim_votetopic(4,0),"|")
  num_vnum=ubound(dim_vnum)
  call bbs_vote_chk()
  erase dim_vnum
else
 Response.write bbs_vote_type()
end if
'----------------------------中间 结束----------------------------
call bbs_end()
Response.write Cls.ReHtml(ShowWebEnd(1),1)
call DoWebEnd()
sub bbs_vote_chk()
  dim tmp1,found_err,orderid,vote_nid,vote_nid2,dim_nid,ii,vnum
  vote_nid=Cls.code_form("vote_nid")
  found_err=""
  if int(dim_votetopic(2,0))>0 then
    found_err=found_err&"+<font class=red>此投票贴已被锁定，不能再对其进行投票！</font><br>"
  end if
  if instr("|"&dim_votetopic(9,0),"|"&login_username&":")>0 then
    found_err=found_err&"+您已经投过一票，不能再对其进行投票！<br>"
  end if
  response.write dim_votetopic(7,0)&"<br>"&dim_votetopic(6,0)&"<br>"&dateadd("d",dim_votetopic(7,0),dim_votetopic(6,0))&"<br>"
  if int(dim_votetopic(7,0))>0 then
    if Cls.now_time>dateadd("d",dim_votetopic(7,0),dim_votetopic(6,0)) 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 dim_votetopic(5,0)=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
    call bbs_msg(found_err) 'Response.Write found_error(found_err,250)
    exit sub
  end if
  vnum=0
  if dim_votetopic(5,0) 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
  dim_votetopic(4,0)=""
  for i=0 to num_vnum
    if dim_votetopic(4,0)="" then
      dim_votetopic(4,0)=dim_vnum(0)
    else
      dim_votetopic(4,0)=dim_votetopic(4,0)&"|"&dim_vnum(i)
    end if
  next
  if dim_votetopic(9,0)="" then
    dim_votetopic(9,0)=login_username&":"&vote_nid
  else
    dim_votetopic(9,0)=dim_votetopic(9,0)&"|"&login_username&":"&vote_nid
  end if
  sql="select top 1 v_num,v_username from AsaiMHBbsVote where reply_id="&viewid
  call Cls.exe_conn(rs,sql,3)
  rs("v_num")=dim_votetopic(4,0)
  rs("v_username")=dim_votetopic(9,0)
  rs.update
  rs.close
  orderid=Cls.Max_ID("AsaiMHBbsTopic","order_id","bbs_id="&Bbsid)
  orderid=orderid+1
  sql="update AsaiMHBbsTopic set order_id="&orderid&",vote_num=vote_num+"&vnum&",re_username='"&login_username&"',re_tim='"&Cls.now_time&"' where id="&viewid
  call Cls.exec(sql,0)
  sql="update AsaiMHBbsClass set bbs_new_info='"&login_username&"|"&Cls.now_time&"|"&viewid&"|"&dim_votetopic(1,0)&"' where bbs_id="&Bbsid
  call Cls.exec(sql,0)
  call bbs_post_chk()
end sub
%>
