<%@ Language=VBScript%>
<!-- #include file="../dsn.asp" -->
<!-- #include file="../links.asp" -->
<%
Response.Buffer=true
Response.Expires=0
%>
<%
if session("adminusername")="" then
		session("xhy")=1
		Response.Redirect linkwarn
end if
id=cint(Request.QueryString("id"))
pid=cint(Request.QueryString("pid"))
ppid=cint(Request.QueryString("ppid"))
lbpid=cint(Request.QueryString ("lbpid"))


backhtml=linklbadmin&"?pid="&pid&"&ppid="&ppid&"&lbpid="&lbpid
creadate=now()
set cn=Server.CreateObject("ADODB.Connection")
set rs1=Server.CreateObject("ADODB.Recordset")
set rs2=Server.CreateObject("ADODB.Recordset")
set rs3=Server.CreateObject("ADODB.Recordset")
cn.Open mycnstr
if pid=0 then 
		tabname="scool"
		classesname="大类"
end if
if pid=1 then 
		tabname="classes"
		classesname="小类"
end if
%>


<%
if Request.ServerVariables("REQUEST_METHOD")="POST" then
		yx=Request.Form("c1")
		if pid=0 and ppid=0 then
				flagtxt=Request.Form ("c2")
		end if
		if pid=1 then
				lbpid=cint(Request.Form ("s1"))
		end if
		title=trim(Request.Form("title"))
		pl=trim(Request.Form("t1"))
		if pl="" or not isnumeric(pl) then 
				sqltext3="select max(pl) as maxpl from "+tabname
				rs2.Open sqltext3,cn,1,1
				if not rs2.EOF then
						pl=rs2("maxpl")+1
				end if
				rs2.Close 
			else
				pl=cint(pl)
		end if
		if pl="" or not isnumeric(pl) then pl=1
		if id=0 then
		     if pid=1 then
				sqltext3="select * from "+tabname+" where title='"+title+"' and pid="&lbpid
			 else	
				sqltext3="select * from "+tabname+" where title='"+title+"'"
			 end if	
				rs2.Open sqltext3,cn,1,1
				if not rs2.EOF then
						errtxt="错误：标题:“"&title&"”已存在，请换名重试！"
						title=""
					else						
						sqltext2="select * from "+tabname
						rs1.Open sqltext2,cn,1,2
						rs1.AddNew
						rs1.Update
						id=rs1("id")
						rs1.Close
				end if
				rs2.Close 
		end if
				sqltext2="select * from "+tabname+" where id="&id
				rs1.Open sqltext2,cn,1,2
			if not rs1.EOF then	
				rs1("title")=title
				rs1("pl")=pl
				if yx="on" then
					rs1("enable")=1
				end if
				if yx="" then
					rs1("enable")=0
				end if
				if pid=1 then
						rs1("pid")=lbpid
				end if
				if pid=0 and ppid=0 then
					if flagtxt="on" then
						rs1("flag")=1
					end if
					if flagtxt="" then
						rs1("flag")=0
					end if		
				end if
				rs1.Update
				id=rs1("id")
				Response.Redirect backhtml
			end if	
			rs1.Close 
end if

if id<>0 then
		sqltext1="select * from "+tabname+" where id="&id
		rs1.Open sqltext1,cn,1,1
		title=rs1("title")
		yxx=rs1("enable")
		pl=rs1("pl")
		if pid=0 and ppid=0 then
			flag=rs1("flag")
		end if
		rs1.Close
		if len(title)>18 then
				title=left(title,18)&"..."
			else
				title=title
		end if
	else
		title="增加新条目"
		yxx=1
		dateyxx=1 
end if

%>
<html>
<head>
<title>网站管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body {font-size: 12px; color: #000000; font-family: 宋体}
td {font-size: 12px; color: #000000; font-family: 宋体;line-height:130%}
.t1 {font:12px 宋体;color=000000} 
.t2 {font:12px 宋体;color:ffffff} 
.t3 {font:12px 宋体;color:336699} 
.t4 {font:12px 宋体;color:ff0000} 
.t5 {font:12px 宋体;color:ff6600} 


.bt1 {font:14px 宋体;color=000000} 
.bt2 {font:12px 宋体;color:ffffff} 
.bt3 {font:14px 宋体;color:336699} 
.bt4 {font:14px 宋体;color:ff0000} 
.bt5 {font:14px 宋体;color:0000ff}
.bt10 {font:14px 宋体;color:0000ff}

.td1 {font-size:12px;background-color:#3388bb;color:#ffffff}
.td2 {font-size:12px;background-color:#ffffff;color:#000000;}

A:link {color: #000077}
A:visited {color: #000077}
A:hover {color: #ff0000}

A.r1:link {text-decoration:none;color:#304556;}
A.r1:visited {text-decoration:none;color:#304556;}
A.r1:hover {text-decoration:underline;color:ff6600;}

A.r2:link {text-decoration:none;color:#ffffff;}
A.r2:visited {text-decoration:none;color:#ffffff;}
A.r2:hover {text-decoration:underline;color:cccc00;}

-->
</style>
</head>

<body bgcolor=#ffffff topmargin=10>
<form action="<%=linklbadminedit%>?id=<%=id%>&pid=<%=pid%>&ppid=<%=ppid%>&lbpid=<%=lbpid%>" method=post name=editform>
 
 <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr><td><font class=t5>当前位置:类别管理→　<%=classesname%>类别→　<%=title%></b></font>
		← <a href="<%=backhtml%>">返回列表</a></td>
	</tr>
	<tr><td><hr size=1></td></tr>
	<tr bgcolor=ffe4c4><td height=20><font class=t1>具体内容</font><br>
	</td></tr>
	<tr><td height=5></td></tr>
 </table>
 <div align=center class=t1><font color="red"><b><%=errtxt%></b></font></div>
 <table width="100%" border="0" cellspacing="1" cellpadding="0" align="center">
	<tr><td width=70 align=right>有效性</td>
		<td>
			<%if yxx=1 then%>
					<input type="checkbox" checked name="c1">
				<%else%>
					<input type="checkbox" name="c1">
			<%end if%>					  	
		&nbsp;&nbsp;（创建日期：<font color=000000><%=creadate%></font>
			<%if pid=0 and ppid=0 then%>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			 	用户能否增加分类:	<input type="checkbox" <%if flag=1 then Response.Write ("checked")%> name="c2">
			<%end if%>
			）</td>
		</td></tr>
	<tr><td width=70 align=right>序号</td><td><input type="text" value="<%=pl%>" name="t1" maxlength=60 size=10><font color=red>（系统按此序号从小到大排列）</font></td></tr>
	<tr><td width=70 align=right>名称</td>
		<td><input type="text" value="<%=title%>" name=title maxlength=60 size=35><font color=red>*</font></td></tr>
		<%if pid=1 then%>
	<tr><td width=70 align=right>所属大类</td><td>
			<select name=s1 size=1>
				<%sqltext="select id,title from scool"
				rs1.Open sqltext,cn,1,1
				do while not rs1.EOF 
				if rs1("id")=lbpid then%>			
						<option value="<%=rs1("id")%>" selected><%=rs1("title")%></option>
					<%else%>
						<option value="<%=rs1("id")%>"><%=rs1("title")%></option>
				
				<%end if
				rs1.MoveNext 
				loop
				rs1.Close %>
			</select>
	</td></tr>
	<%end if%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr><td width=200></td><td height=10></td></tr>
	<tr>
	<td width=200></td>
	<td align=left>
		<input type="button" name="button1" value="确认提交" onclick="check1()">&nbsp;&nbsp;&nbsp;&nbsp;
	</td></tr>
	<tr><td width=200></td><td height=10></td></tr>
</table>

</form>
<script language=vbscript>
		sub check1()
			dim form1
			set form1=document.editform 
			if form1("title").value="" then
					alert("名称不能为空!")
					form1.title.focus 									
				else
					form1.submit
			end if
			
		end sub

</script>

