<!--#include file="Head.asp"-->
<br>
<table width="98%" border="1" cellspacing="0" cellpadding="3" align="center" bordercolorlight="#ECEEE4" bordercolordark="#CCCABC">
    <tr> 
      
    <td height="30" class="14p"><a href="admin_vote_list.asp"><b>>> 项目列表</b></a> 
      | <a href="?cmd=4"><b>>> 添加投票</b></a> | <a href="admin_vote_code.asp"><b>&gt;&gt; 
      调用代码</b></a></td>
    </tr>
    </table>
<br>
<%
  Set conn=Server.CreateObject("ADODB.Connection")
  conn.open ConnStr
  cmd=Cint(Request("cmd"))
  id=Request("ID")
select case cmd
  case "1" '上下线命令
    sql="Update Vote_List Set online=Not(online) Where ID="&id
	conn.execute sql
	call listvote()
  case "2" '删除命令
    sql="Delete From Vote_List Where ID="&id
    sql1="Delete From Vote_Answer Where ListID="&id
	conn.execute sql
	conn.execute sql1
	call listvote()
  case "3" '编辑命令
	call editvote()
  case "4" '增加命令
	call addvote()
  case else
	call listvote()
end select
%>


<% sub  listvote()%>
<style type="text/css">
.dot_bt{border-bottom : 1px dotted #9f9f9f;}
</style>
 <table border=1 cellspacing="0" cellpadding="3" bordercolorlight="#ECEEE4" bordercolordark="#CCCABC" width="98%" align=center>
            <tr> 
              <td width="4%" height="30" background="image/tablebg.gif" align="center"> 
                <b>ID</b></td>
              <td width="45%" background="image/tablebg.gif" align="center"> 
                <b>投 票 说 明</b></td>
              <td width="5%" background="image/tablebg.gif" align="center"> 
                <b>多选</b></td>
              <td width="13%" background="image/tablebg.gif" align="center"> 
                <b>活动状态</b></td>
              <td colspan="3" background="image/tablebg.gif" align="center"> 
                <b>操 作</b></td>
</tr><tr><td colspan="7">
 <table border=0 cellspacing="0" cellpadding="3" bordercolorlight="#ECEEE4" bordercolordark="#CCCABC" width="100%" align=center><tr height="5"><td colspan="7" class="dot_bt"><IMG SRC="image/spacer.gif" WIDTH="1" HEIGHT="15" BORDER=0></td></tr>
<%
  Set rs=conn.execute("Select * From Vote_List Order By ID")
  IF rs.eof THEN
    Response.write "<tr><td colspan=""7"" height=""50"" bgcolor=""#ffffff"" align=""center"">当前没有投票项目! <a href=""admin_vote_list.asp?cmd=4""><font color=""red"">[马上增加]</font></a></td><tr>"
  ELSE
    While NOT rs.eof
	%>          
          <tr height="25">
            <td class="dot_bt" align="center" width="4%"><%=rs(0)%></td>
            <td class="dot_bt" width="45%"><%=rs(1)%></td>
            <td class="dot_bt" align="center" width="5%"><%if rs(2)=true then%>多选<%else%>单选<%end if%></td>
            <td class="dot_bt" align="center" width="13%"><%if rs(3)=true then%><img src="image/poll_0.gif"><%else%><img src="image/poll_1.gif"><%end if%></td>
            <td class="dot_bt" width="40%" align="center"><a href="?cmd=1&ID=<%=rs(0)%>">设为<% IF rs(3) THEN Response.write "不" %>活动</a> | <a href="?cmd=3&ID=<%=rs(0)%>">编辑</a> | <a href="?cmd=2&ID=<%=rs(0)%>">删除</a> | <a href="#" onclick="javascript:window.open('admin_vote_view.asp?ID=<%=rs(0)%>','','width=420,height=350,scrollbars=yes')">投票结果</a>
            </td>
          </tr>
<%
      rs.MoveNext
    Wend
  END IF
  rs.close
  Set rs=nothing
  conn.close
  Set conn=nothing
%>          
</table><br>
</td></tr></table>
<%end sub%>

</body>
</html>

<%sub addvote()%>
<table width="98%" border="1" cellspacing="0" cellpadding="5" align="center" bordercolorlight="#ECEEE4" bordercolordark="#CCCABC">
 <form method="POST" action="?cmd=4">
<input type="hidden" name="IsSub" value="YES">
<%
   IF Request.Form("IsSub")="YES" THEN
     txt1=Server.HTMLEncode(Request.Form("txt1"))
     txt2=Server.HTMLEncode(Request.Form("txt2"))
     txt2=Trim(txt2)

     IF txt1="" THEN errMessage="<li>项目描述 栏不能为空"
     IF txt2="" THEN errMessage=errMessage&"<li>投票项目 栏不能为空"
     vote=Split(txt2,VBCrlf) 
     IF Ubound(vote)<=0 or Ubound(vote)>9 THEN errMessage=errMessage&"<li>请检查：投票项目至少 2 项，最多 10 项"
     IF Request.Form("rad")="YES" THEN
       mul=True
     ELSE
       mul=False
     END IF
     IF errMessage<>"" THEN
       Response.write "<tr><td><b>：：发现错误：：</b><ul>"&errMessage&"</ul>&nbsp;<a href=javascript:history.back()>>>点击返回</a></td></tr>"
     ELSE
       Set conn=Server.CreateObject("ADODB.Connection")
       conn.open ConnStr
       conn.execute "Insert Into Vote_List(Project,MultiSelect,Vote_Limit) Values('"&txt1&"',"&mul&",'"&request("times")&"')"
       Set rs=conn.execute("Select ID From Vote_List Order By ID DESC")
       ID=rs(0)
       rs.close
       Set rs=nothing
       FOR i=0 TO Ubound(vote)
         IF vote(i)<>"" THEN conn.execute "Insert Into Vote_Answer(ListID,VoteContent) Values("&ID&",'"&vote(i)&"')"
       NEXT
       conn.close
       Set conn=nothing
       Response.write "<tr><td><b>：：操作完成：：</b><br><ul><li>投票项目添加成功，</ul>&nbsp;<a href=?cmd=4><font color=#000000>>>点击继续添加</font></a></td><tr>"
     END IF
   ELSE
%>        
         <tr>
		 <td colspan=2 height="30" background="image/tablebg.gif" align="center"><b class="14p">添加新投票项目</b></td>
         </tr>
          <tr>
            <td height="30" width="100">项目描述：</td>
			<td><textarea rows="3" name="txt1" cols="80"></textarea></td>
          </tr>
          <tr>
		  <td>投票项目：</td>
			 <td><textarea rows="9" name="txt2" cols="80"></textarea><BR>（以回车换行来分隔投票项目，最多10项）</td>
		  </tr>
          <tr>
		  <td>允许多选：</td>
		   <td><input type="radio" value="YES" name="rad"> 多选&nbsp;&nbsp;<input type="radio" name="rad" value="NO" checked> 单选</td>
		  </tr>
          <tr>
		  <td>投票限制：</td>
		   <td><input type="radio"name="times" value="1" checked> 不限制
              <input type="radio" name="times" value="2"> 每位访问者一天只能投一次
           </td>
		  </tr>
          <tr>
		  <td colspan="2" align="center"><input type="submit" value="提交新投票项目" name="B1">
            </td>
          </tr>
<%
END IF
%>
</form></table>
<%end sub

sub editvote()
%>
<table width="98%" border="1" cellspacing="0" cellpadding="5" align="center" bordercolorlight="#ECEEE4" bordercolordark="#CCCABC">
 <form method="POST" action="?cmd=3">
<input type="hidden" name="IsSub" value="YES">
<%
IF Request.Form("IsSub")="YES" THEN
     txt1=Server.HTMLEncode(Request.Form("txt1"))
     txt2=Server.HTMLEncode(Request.Form("txt2"))
     VoteResult2=trim(Server.HTMLEncode(Request.Form("VoteResult2")))
     txt2=Trim(txt2)

     IF txt1="" THEN errMessage="<li>项目描述 栏不能为空"
     IF txt2="" THEN errMessage=errMessage&"<li>投票项目 栏不能为空"
     vote=Split(txt2,VBCrlf) 
	 VoteResult=Split(VoteResult2,VBCrlf)
     IF Ubound(vote)<=0 or Ubound(vote)>9 THEN errMessage=errMessage&"<li>请检查：投票项目至少 2 项，最多 10 项"
     IF errMessage<>"" THEN
       Response.write "<tr><td><b>：：发现错误：：</b><ul>"&errMessage&"</ul>&nbsp;<a href=javascript:history.back()>>>点击返回</a></td></tr>"
     ELSE

       Set conn=Server.CreateObject("ADODB.Connection")
       conn.open ConnStr
       conn.execute "Update Vote_List set Project='"&txt1&"',MultiSelect="&Request.Form("rad")&",Vote_Limit='"&request("times")&"' where id="&request("ID")
	  conn.execute "delete from Vote_Answer where ListID="&ID
       FOR i=0 TO Ubound(vote)
         IF vote(i)<>"" THEN conn.execute "Insert Into Vote_Answer(ListID,VoteContent,VoteResult) Values("&ID&",'"&vote(i)&"','"&VoteResult(i)&"')"
      NEXT
       conn.close
       Set conn=nothing
       Response.write "<tr><td><b>：：操作完成：：</b><br><ul><li>投票项目修改成功，</ul>&nbsp;<a href=?cmd=4><font color=#000000>>>点击继续添加</font></a></td><tr>"
     END IF
 ELSE
	if ID="" then 
	response.write "参数错误！"
	response.end
	end if
	sql="select a.Project,a.MultiSelect,a.Vote_Limit,b.ListID,b.VoteContent,b.VoteResult from Vote_list a,Vote_Answer b where a.id=b.ListID and a.id="&ID
	Set rs=conn.execute(sql)

	sql2="select VoteContent,VoteResult from Vote_Answer where listid="&ID
	set rs2=Server.CreateObject("ADODB.recordset")
	rs2.open sql2,conn,1,1 
	do while not rs2.eof 
		VoteContent=rs2(0)&chr(13)&VoteContent
		VoteResult=rs2(1)&chr(13)&VoteResult
		rs2.movenext
	loop
	rs2.close
	set rs2=nothing
%>        
         <tr>
		 <td colspan=2 height="30" background="image/tablebg.gif" align="center"><b class="14p">编辑现有投票项目</b></td>
         </tr>
          <tr>
            <td height="30" width="100">项目描述：</td>
			<td><textarea rows="3" name="txt1" cols="80"><%=rs("Project")%></textarea></td>
          </tr>
          <tr>
		  <td>投票项目：</td>
			 <td><textarea rows="9" name="txt2" cols="50"><%=VoteContent%></textarea>
			 <textarea rows="9" name="VoteResult2" cols="50"><%=VoteResult%></textarea><BR>（以回车换行来分隔投票项目，最多10项）</td>
		  </tr>
          <tr>
		  <td>允许多选：</td>
		   <td><input type="radio" value="true" name="rad"<%if rs("MultiSelect")=true then response.write" checked"%>> 多选&nbsp;&nbsp;<input type="radio" name="rad" value="false"<%if rs("MultiSelect")=false then response.write" checked"%>> 单选</td>
		  </tr>
          <tr>
		  <td>投票限制：</td>
		   <td><input type="radio"name="times" value="1"<%if rs("Vote_Limit")="1" then response.write" checked"%>> 不限制
              <input type="radio" name="times" value="2"<%if rs("Vote_Limit")="2" then response.write" checked"%>> 每位访问者一天只能投一次
             </td>
		  </tr>
          <tr>
		  <td colspan="2" align="center"><INPUT TYPE="hidden" name="ID" value="<%=ID%>"> <input type="submit" value="修改投票项目" name="B1">
            </td>
          </tr>
<%
END IF
%>
</form></table>
<%
end sub
%>
