<!--#include file="conn.asp" -->
<!--#include file="checkout.asp" -->
<%if (session("userkey")=1) then%>
  <script language=javascript>  
    alert( "错误：您无权进行用户管理！"  );
    location.href = "javascript:history.back()"  
  </script>
<%end if%>
<%
op=trim(request("op"))
if op="add" then
	title="增加"
elseif op="update" then
	title="修改"
elseif op="del" then
	title="删除"
end if
if op="add" then
	code=trim(request("code"))
	code_new=ucase(trim(request("code_new")))
	name=trim(request("name"))
	img=request("img")
	notes=request("notes")
	classMaster=session("admin_user")
	'先检查新的代码是否存在
	sql="select * from newclass where code='"&code&code_new&"'"
	set rs=server.createobject("adodb.recordset")
	rs.open sql,conn,1,3
	if not rs.eof then
		infostr="该分类代码"&code&code_new&"已存在，请换成其它代码！"
	else
		sql="insert into class(code,name,img,notes,classMaster) values('"&code&code_new&"','"&name&"','"&img&"','"&notes&"','"&classMaster&"')"
		conn.execute sql
		infostr=title & "分类添加成功！"	
	end if
elseif op="update" then
	code=trim(request("code"))
	code_new=ucase(trim(request("code_new")))
	name=trim(request("name"))
	img=request("img")
	notes=request("notes")
	classMaster=session("admin_user")
	'**********************************
	'取出原来的代码，看看修改后的代码是否与原来的不同。
	
	id=request("id")
    id=replace(trim(id),"'","")
    id=replace(trim(id)," ","")
	
	sql="select * from newclass where id="&id&""
	set rs=server.createobject("adodb.recordset")
	rs.open sql,conn,1,3
	if not rs.eof then
		code_old=trim(rs("code"))
	end if
	'**********************************
	'如果新代码与原代码不等，则要判断新代码是否存在。
	if (code&code_new)<>code_old then
		sql="select * from newclass where code='"&code&code_new&"'"
		set rs=server.createobject("adodb.recordset")
		rs.open sql,conn,1,3
		if not rs.eof then
			infostr="修改后的分类代码"&code&code_new&"已存在，请换成其它代码！"
		else
			sql="update newclass set code='"&code&code_new&"',name='"&name&"',img='"&img&"',notes='"&notes&"' ,classMaster='"&classMaster&"' where id="&id&""
			conn.execute sql
			infostr=title & "分类修改成功！"	
		end if
	else
		sql="update newclass set code='"&code&code_new&"',name='"&name&"',img='"&img&"',notes='"&notes&"',classMaster='"&classMaster&"' where id="&id&""
		conn.execute sql
		infostr=title & "分类修改成功！"		
	end if
elseif op="del" then

	id=request("id")
    id=replace(trim(id),"'","")
    id=replace(trim(id)," ","")
	
	sql="delete from newclass where id="&id&""
	conn.execute sql
	infostr=title & "分类成功！"
end if
if infostr="" then
	infostr="操作失败！"
end if
%>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><%=infostr%></title>
</head>
<body>
<p>
<script language="vbscript">
	msgbox "<%=infostr%>"
	window.location.href="news_class.asp?dt=<%=now()%>"
</script>
</p>
</body>
</html>
