<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!-- #include file="inc/Session.asp" -->
<!-- #include file="inc/checkrole.asp" -->
<HTML>
<HEAD>
<TITLE>添加投票</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<style>
body,td,input,textarea {font-size:9pt}
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.style1 {
	color: #FFFFFF;
	font-weight: bold;
}
</style>
<script language="JavaScript" src="../js/PublicJS.js"></script>
</HEAD>
<BODY>
<%
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p13")
'''''''''''''''''''''''''''''''''''''''''''''''
%>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><iframe src="right_top.htm" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" height="30" width="100%"></iframe></td>
  </tr>
</table>
<%
dim act,title,optionNum,optionType,votestatus,expiresTime,currentTime,randomNum
currentTime=now
act=request.QueryString("act")

if(act="add") then	
	title=trim(request.Form("title"))
	If  title="" then
	    Response.Write("<script>alert(""投票名称不能为空""); history.back();</script>")
		Response.End
	end if
	optionNum=Cint(request.Form("optionNum"))	
	if optionNum<1 then
	 	Response.Write("<script>alert(""选项个数必须为数字类型"");history.back();</script>")
		Response.End
	End if
	optionType=Cint(request.Form("optionType"))
	votestatus=Cint(request.Form("status"))
	expiresTime=trim(request.Form("expiresTime"))	 
	if expiresTime<>"" and isdate(expiresTime)=false then
	 	Response.Write("<script>alert(""过期时间类型出错,如果不设置过期时间,请置空"");history.back();</script>")
		Response.End
	end if
	 For i=1 to optionNum
	     if Request.Form("Options"&i&"")="" or isnull(Request.Form("Options"&i&"")) then
		    Response.Write("<script>alert(""选项"&i&"内容不能为空"");history.back();</script>")
			Response.End
		 end if
	 Next
	'添加到库
	set rs=server.createobject("adodb.recordset")
	sql="select top 1 * from vote order by id desc"
	rs.open sql,conn,3,3
	if not rs.eof then
		randomNum=Cint(rs("id"))+1
	else
		randomNum=1
	end if
	rs.addnew
	rs("id")=randomNum
	rs("title")=title
	rs("optionNum")=optionNum
	rs("optionType")=optionType
	if(votestatus=1) then
		If datediff("s",now(),formatdatetime(expiresTime))<0 then
			rs("status")=2
		else
			rs("status")=votestatus
		end if
	else
		rs("status")=votestatus
	end if	
	rs("expiresTime")=expiresTime
	rs("modiTime")=now	
	rs.update
	rs.close
	set rs=nothing
	'================================添加选项======================================
	For i = 1 to optionNum
			Set rs = Server.CreateObject("Adodb.RecordSet")				 
			rs.Open "Select top 1 * from voteitem where 1=0",conn,3,3
			rs.AddNew
			rs("voteid") = randomNum
			rs("itemName") = Replace(Replace(Request.Form("Options"&i&""),"""",""),"'","")
			rs("clicks")=0
			If Request.Form("Color"&i&"")<>"" then
				rs("colors") = Request.Form("Color"&i&"")
			End If
			rs("ords") = i
			rs.Update
			rs.Close
	Next
	set rs=nothing
	'=================================================================================
	response.Write("<p align=""center"">添加投票成功~!</p>")
	response.Write("<p align=""center""><br><a href=vote_add.asp>继续添加==></a></p>")
else
%>
<FORM method="POST" name="VoteForm" action="vote_add.asp?act=add" style="margin:0 0 0 0;">
  <TABLE width="100%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#666666">
<TR bgcolor="#FF9900">
  <TD height="24" colspan="2"><div align="center" class="style1">添加投票</div></TD>
  </TR>
<TR bgcolor="#F5F5F5">
  <TD width="14%"><div align="center">投票标题：</div></TD>
  <TD width="86%"><input name="title" type="text" id="title" size="30"></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD><div align="center">选项个数：</div></TD>
  <TD><div align="left">
    <input name="optionNum" type="text" id="optionNum" onBlur="ChooseOption()" onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;" value="4" size="10">
  </div></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD><div align="center">选项类型：</div></TD>
  <TD><div align="left">
    <input name="optionType" type="radio" value="0" checked>
  单选　
  <input name="optionType" type="radio" value="1">
  多选</div></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD><div align="center">投票状态：</div></TD>
  <TD><div align="left">
    <input name="status" type="radio" value="0">
  关闭 
  <input name="status" type="radio" value="1" checked>
  开启 
  <input name="status" type="radio" value="2">
  过期</div></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD><div align="center">过期时间：</div></TD>
  <TD><div align="left">
    <input name="expiresTime" type="text" id="rolename3" size="30" value="<%=dateadd("d",now,30)%>">
    <input name="sdaf" type="button" id="sdaf" onClick="OpenWindowAndSetValue('Inc/SelectDate.asp',280,120,window,document.VoteForm.expiresTime);document.VoteForm.expiresTime.focus();" value="选择日期">
  </div></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD align=right><div align="center">选项设置：</div></TD>
  <TD align=right><p align="left" id="Options">&nbsp;</p></TD>
</TR>
<TR bgcolor="#F5F5F5">
	<TD align=right>&nbsp;	  </TD>
    <TD align=right><div align="left"> 
        <input type=submit name=b1 value="提 交">&nbsp;&nbsp;
        <input type=reset name=b2 value="重 填">       
    </div></TD>
</TR>
</TABLE>
</FORM>
<script>
function ChooseOption()
 {
  var optionNum =parseInt(document.VoteForm.optionNum.value);
  var i,Optionstr;
	  Optionstr = '<table width="400px" border="0" cellspacing="2" cellpadding="4" align="left">';
  for (i=1;i<=optionNum;i++)
      {
	   Optionstr = Optionstr+'<tr><td><div align="right">&nbsp;选&nbsp;项&nbsp;'+i+'：</div></td><td><div align="left"><input type="text" size="20" name="Options'+i+'" value="">&nbsp;色彩&nbsp;<input type="text" size="11" name="Color'+i+'" value="#FF0000">&nbsp;<input type="button" name="Submit'+i+'" value="选色" onClick="OpenWindowAndSetValue(\'editor/selcolor.htm\',230,190,window,document.VoteForm.Color'+i+');"></div></td></tr>';
	   }
	Optionstr = Optionstr+'</table>';  
    document.all.Options.innerHTML = Optionstr;
  }
  ChooseOption();
</script>
<%
end if
%>
</BODY>
</HTML>
<%
call connclose()
%>