<!--#include file="const.asp"-->
<!--#include file="conn.asp"-->
<%
if session("admin")="" then
response.Write "<script language='javascript'>alert('请先登录！');history.go(-1);</script>"
response.End
else
if request.cookies("timesshop")("admin")="" then
response.Write "<script language='javascript'>alert('请先登录！');history.go(-1);</script>"
response.End
end if
end if
if session("rank")>2 then
response.Write "<script language='javascript'>alert('你无权管理网站设置！');history.go(-1);</script>"
response.End
end if

if request("id")<>"del" then
err=0
title=request("title")
if title="" then
err=1
error=error+"标题不能为空\n"
end if
a=0
for i=1 to request("xz").count
if request("xz")(i)="" then
exit for
end if
a=a+1
next
if a=0 then
err=1
error=error+"选择内容不能为空\n"
end if
if err=1 then
response.write "<script>alert('"&error&"');</script>"
response.write "<script>history.back(1);</script>"
response.end
end if
end if

if request("id")="xg" then
conn.execute("update class set title='"&title&"',style='"&request("style")&"' where id="&request("classid"))
conn.execute("delete from vote where class="&request("classid"))
for i=1 to request("xz").count
if request("xz")(i)<>"" then
conn.execute("insert into vote (vote,color,class) values ('"&request("xz")(i)&"','"&request("color")(i)&"',"&request("classid")&")")
else
exit for
end if
next
response.write "<script>alert('修改投票成功');</script>"
response.write "<script>location.href='votelist.asp';</script>"
elseif request("id")="del" then
conn.execute("delete from vote where class="&request("classid"))
conn.execute("delete from class where id="&request("classid"))
response.write "<script>alert('删除投票成功');</script>"
response.write "<script>location.href='votelist.asp';</script>"
else
conn.execute("insert into class (title,style,ren) values ('"&title&"','"&request("style")&"','"&session("admin")&"')")
set rs=server.createobject("adodb.recordset")
sql="select top 1 * from class where title='"&title&"' order by id desc"
rs.open sql,conn,3,1
classid=rs("id")
rs.close
set rs=nothing
for i=1 to request("xz").count
if request("xz")(i)<>"" then
conn.execute("insert into vote (vote,color,class) values ('"&request("xz")(i)&"','"&request("color")(i)&"',"&classid&")")
else
exit for
end if
next
response.write "<script>alert('添加投票成功');</script>"
response.write "<script>location.href='step1.asp';</script>"
end if
conn.close
set conn=nothing
%>