<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../conn.asp"-->
<!--#include file="session.asp"-->
<%
dim act,title,votestatus,expiresTime
act=request.QueryString("act")
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>添加分类</title>
<style type="text/css">
<!--
.style1 {
	color: #FFFFFF;
	font-weight: bold;
	font-size: 14px;
}
-->
</style>
<LINK media=screen href="js/dhtmlgoodies_calendar.css" rel=stylesheet></LINK>
<SCRIPT src="js/dhtmlgoodies_calendar.js" type="text/javascript" ></SCRIPT>
<script type="text/javascript">
function checkDate(obj){
	var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/; 
	if(obj.value!="" && obj.value.match(reg)==null){
		alert("请输入正确的日期格式如:2007-01-01");	
		obj.focus();
		return false;
	}	
}
</script>
<link href="css.css" rel="stylesheet" type="text/css" />
</head>
<%
if(act="add") then
	if not isempty(request.Form("title")) then
		title=replace(trim(request.Form("title")),"'","")
	else
		response.Write("<script>alert(""分类名称不能为空!"");history.back();</script>")
		response.End()
	end if
	votestatus=Cint(request.Form("status"))
	expiresTime=trim(request.Form("expiresTime"))	 
	if(title<>"") then
		set rs=server.CreateObject("adodb.recordset")
		rs.open "select * from t_survey_catalog where title='"&title&"'",conn,3,3
		if not rs.eof and not rs.bof then
			response.Write("<script>alert(""此分类已存在!"");history.back();</script>")
			rs.close
			set rs=nothing
			call connclose()
			response.End()			
		else
			rs.addnew
			rs("title")=title
			rs("status")=votestatus
			rs("expiresTime")=expiresTime
			rs.update
			rs.close
			set rs=nothing
			
			set rs=server.CreateObject("adodb.recordset")
			rs.open "select id from t_survey_catalog order by id desc",conn,3,1
			if not rs.eof then
				lastid=rs(0)
			end if
			rs.close
			set rs=nothing
			'添加投票统计
			set rs=server.CreateObject("adodb.recordset")
			rs.open "select * from t_survey_stat",conn,3,3
			rs.addnew
			rs("catalogid")=lastid
			rs("votenum")=0
			rs.update
			rs.close
			set rs=nothing
			response.Write("<p align=""center"">成功添加投票项目！<br>下一步操作：<a href=""vote_add.asp?catalogid="&lastid&""">添加投票选项 </a>&nbsp;&nbsp;<a href=""catalog_manage.asp"">返回项目管理</a></p>")
			call connclose()
			response.End()
		end if
	else
		response.Write("<script>alert(""分类不能为空!"");history.back();</script>")
		call connclose()
		response.End()
	end if
else
%>
<body onload="document.form1.title.focus();">
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="45%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#EEFAFF">
  <tr>
    <td><form id="form1" name="form1" method="post" action="?act=add">
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td height="40" colspan="2" bgcolor="#006699"><div align="center" class="style1">添加调查项目</div></td>
          </tr>
        <tr>
          <td height="50"><div align="right">调查项目名称：</div></td>
          <td>
            <div align="left">
              <input name="title" type="text" id="title" size="15" />          
            </div></td>
        </tr>
        <tr>
          <td height="50"><div align="right">过期：</div></td>
          <td height="50">
					<INPUT name=expiresTime type=text id=expiresTime size="25" value="<%=date+31%>" onchange="return checkDate(this)">
            <input name="button2" type="button" onclick="displayCalendar(document.forms[0].expiresTime,'yyyy-mm-dd',this)" value="..." />
            
					</td>
        </tr>
				<TR bgcolor="#F5F5F5">
  <TD><div align="right">投票状态：</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>
          <td height="50" colspan="2"><div align="center">
            <input type="submit" name="Submit" value="添加" />&nbsp;&nbsp;
            <input type="reset" name="Submit2" value="重写" />
          </div></td>
          </tr>
      </table>
        </form>
    </td>
  </tr>
</table>
<%
end if
%>
</body>
</html>
<%
call connclose()
%>