<!--#include file="inc_const.asp"-->
<%response.expires=0
Response.CacheControl = "Private"
application.lock

set cschat=server.createobject("ffcschat.cssbchat")
my_level=cschat.getLevel(Session,Application(ConstStr & "_user_list"),Application(ConstStr & "_room_list"))

application.unlock
if my_level-application( ConstStr & "_l_vote")<0 then
  set cschat=nothing
  response.redirect("showerr.asp?errtext=你没有权利执行此项操作！")  
  response.end
end if
myname=cschat.myname
room_id=cschat.room_id

function cn(n,min,max,d)
  if IsNumeric(n) then
    if n-min>=0 and n-max<=0 then
      cn=n
    else
      cn=d
    end if
  else
    cn=d
  end if
end function

if my_level-application( ConstStr & "_superlevel")=0 then myname="管理员"

sub prhead(ttl)%>
<META content="text/html; charset=gb2312" http-equiv=content-type>
<link rel="stylesheet" type="text/css" href="chat.css">
<style>p{margin-left:10px;margin-right:20px;margin-top:5px;margin-bottom:0px}</style>
<body  style="background-color:EAF2FF;color:112233;scrollbar-Base-Color: #b0d8ff;SCROLLBAR-DARKSHADOW-COLOR:#b0d8ff;SCROLLBAR-arrow-COLOR:#336699;SCROLLBAR-TRACK-COLOR: EAF2FF;SCROLLBAR-3DLIGHT-COLOR: #b0d8ff;SCROLLBAR-SHADOW-COLOR: #336699;SCROLLBAR-HIGHLIGHT-COLOR: #b0d8ff;" leftmargin=3 topmargin=20 style="color:green">
  <table height=100% width=100% ><tr><td align=center valign=center>
  <table align=center cellspacing=0 cellpadding=0 style="border:'1px solid navy'">
  <tr><td colspan=2 class=navy1 style="border:'1px solid #EAF2FF'"><%=ttl%></td>
<%end sub
errstr=""
if request("B1")="" then
  call prhead("产生投票事件")%>
  <form method="post" action="cstp.asp">
  <tr><td style="text-align:left;" nowrap><p>
  事件名称:<input type=text name=votename maxlength=50 size=30></p><p>
  选项个数:<input type=text name=op_num maxlength=10 size=10>(2<=选项个数<=30)</p><p>
  自动结束:<input type=text name=voteday maxlength=10 size=10 value=0>(0<=天数<=30)</p><p>
  经 验 值:<input type=text name=exp_num maxlength=10 size=10>(2<=经验值<=5000)<br>
　　　　　自动结束如果为0就为非自动结束<br>
　　　　　否则为多少天后投票事件自动结束。<br>
　　　　　经验值为具有投票资格的最小经验值<br>
　　　　　如果小于10，则为具有投票资格的级别。</p><p>
  <p><center><input type="submit" name="B1" value="提交" class=navy1>
  <input type="reset" name="cmdCancel" value="重置" class=navy1><center></p><p></p>
<%else
  cschat.FilterStr = Application(ConstStr & "_saysfilterstr")
  votename=cschat.trdb(request("votename"))
  op_num=request("op_num")
  exp_num=request("exp_num")
  voteday=cn(request("voteday"),0,30,0)
  Set Conn=Server.CreateObject("ADODB.Connection") 
  conn.open Application( ConstStr & "_connstr")
  set rs=conn.execute("select * from vote where votename='"&votename&"' and exp_num>1")
  if votename="" then
    errstr="投票事件名称不能为空！" 
  elseif not (rs.bof or rs.eof) then
    errstr="已经存在相同名字的投票事件！"
  elseif not (isnumeric(op_num) and isnumeric(exp_num)) then
    errstr="选项个数和经验值必须是数字！"
  else
    if op_num-2<0 or op_num-30>0 then
      errstr="选项个数必须是2～30之间的数字！"
    elseif exp_num-2<0 or exp_num-5000>0 then
      errstr="选项个数必须是2～5000之间的数字！"
    elseif request("B1")="提交" then
      op_num=int(op_num)
      exp_num=int(exp_num)
      call prhead("产生投票事件"&votename)%>
      <tr><td style="text-align:left"><form method="post" action="cstp.asp">
      <input type=hidden name=op_num value='<%=op_num%>'>
      <input type=hidden name=voteday value='<%=voteday%>'>
      <input type=hidden name=exp_num value='<%=exp_num%>'>
      <input type=hidden name=votename value='<%=votename%>'>
      <p>事件名称：<%=votename%></P>
      <p>选项个数：<%=op_num%></P>
      <p>自动结束：<%=voteday%></P>
      <p>经 验 值：<%=exp_num%></P>
      <p>请详细填写各选项的内容：</P>
      <%for i=1 to op_num%>
        <p>选项<%=i%>：<input type=text name='options<%=i%>' maxlength=50 size=30></p>
      <%next%>
      <p><center><input type="submit" name="B1" value="完成" class=navy1>
      <input type="reset" name="cmdCancel" value="重置" class=navy1><center></p><p></p>
    <%else
      dim options
      redim options(op_num-1)
      for i=1 to op_num
        options(i-1)=request("options"&i)
      next
      for i=0 to op_num-1
        if errstr<>"" then exit for
        if options(i)="" or options(i)=votename then
          errstr="选项名不能和投票事件一样，也不允许为空！"
        else
          for j=0 to op_num-1
            if j<>i and options(i)=options(j) then
              errstr="选项["&i&"]和选项["&j&"]一样！"
            end if
          next
        end if
      next
      if errstr="" then
        room_array=split(Application( ConstStr & "_room_list"),"<$"&room_id&"$>")
        room_array2=split(room_array(1),"$>")
        sql="INSERT INTO vote (votename,voteoptions,exp_num,begin_time,end_flag) VALUES ('"&votename&"','"&votename&"',"&exp_num&",'"&now()&"','"&dateAdd("d",voteday,now())&"')"
        conn.Execute(sql)
        for i=0 to op_num-1
          sql="INSERT INTO vote (votename,voteoptions,exp_num) VALUES ('"&votename&"','"&options(i)&"',1)"
          conn.Execute(sql)
        next
        occ_env=cschat.GetListValue(Application(ConstStr & "_room_list"), room_id, 0)&">"&myname&">"&Request.ServerVariables("REMOTE_ADDR")&">"&votename&"> >此处只作记录>产生投票事件%%"
        conn.Execute("INSERT INTO record (stype,occ_time,occ_env) VALUES (7,'"&now()&"','"&occ_env&"')")
        errstr="你成功地产生了投票事件"&votename&"！"
      end if
    end if
  end if
  rs.close
  set rs=nothing
  conn.close
  set conn=nothing
end if
application.unlock
set cschat=nothing
if errstr<>"" then
  response.redirect("showerr.asp?errtext="&errstr)
  response.end
end if%>
</table><br>[<a href='javascript:history.go(-1)'>后退</a>]</td></tr></table></form>
</body></html>

























