<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../Conn/conn.asp"-->
<!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" />
<link rel="stylesheet" href="../css/indexTwo.css" type="text/css">
<title>网站后台</title>
</head>
<body>
<script type="text/javascript">
function CheckForm()
{
			if(document.form.SortName.value=="")
			{
				alert("请输入新类别名！");
				document.form.SortName.focus();
				return false;
			}
			if(document.form.SortOrder.value=="")
			{
				alert("请输入序号！");
				document.form.SortOrder.focus();
				return false;
			}
			if(isNaN(document.form.SortOrder.value))
			{   
				  alert("序号必须输入整数");
				  return false;
			 }
			
}
</script>
<%
rank=request("rank")
if request("action")<>"add" then
	SortID=request("SortID")
	sql="select id from TbNews where sort="&SortID
	rs.open sql,conn,1,1
	if not rs.eof then
		response.write "<script> alert('该栏目内有信息数据，不允许在其下添加新栏目，请先删除其信息数据');window.document.location.href='News_Sort_List.asp';   </script>"
		response.End()
	end if
	rs.close
end if

if request("action")="add" then
	Pid=request.Form("Pid")
	SortName=request.Form("SortName")
	SortOrder=request.Form("SortOrder")
	
	sql="select * from TbNewsSort where name='"&SortName&"'"
	rs.open sql,conn,1,3
	if not rs.eof then
		rs.close
		ErrorMessage="该名称已经存在"
		response.write("<script>alert('"&ErrorMessage&"');history.back()</script>")
		response.End()
	else
		rs.addnew
		rs("name")=SortName
		rs("pid")=Pid
		rs("order")=SortOrder
		
		sql2="select id,mode from TbNewsSet where id=2 "
		rs2.open sql2,conn,1,1
		if not rs2.eof then
			if clng(rank+1)<clng(rs2("mode")) then
				rs("setmode")=1
				rs("addmode")=1
				rs("editmode")=1
				rs("delmode")=1
			end if
			if clng(rank+1)=clng(rs2("mode")) then
				rs("setmode")=1
				rs("addmode")=0
				rs("editmode")=1
				rs("delmode")=1
			end if
		end if
		rs2.close
		
		rs.update
	end if
	rs.close
	response.write "<script> alert('添加成功');window.document.location.href='News_Sort_List.asp';   </script>"
	response.End()
end if
%>
<table width="100%" border="0" cellspacing="1" class="Navi2">
  <tr>
    <th colspan="2">信息类别添加</th>
    <th><a href="News_Sort_List.asp" class="link2">返回</a></th>
  </tr>
</table>
<form name="form"  method="post" action="?rank=<%=rank%>" onsubmit="return CheckForm(this);">
  <input type="hidden" name="action" value="add" />
  <table width="100%" border="0" cellspacing="1" class="Navi2">
    <tr>
      <td style="width:150px;text-align:right; padding-right:8px;">父类名称</td>
      <td style="text-align:left;padding-left:8px;"><%call pidSort(SortID)%>
      </td>
    </tr>
    <tr>
      <td style="text-align:right; padding-right:8px;">类别名称</td>
      <td style="text-align:left;padding-left:8px;"><input type="text" name="SortName" value="" style="width:200px;" maxlength="250" />
      </td>
    </tr>
    <tr>
      <td style="text-align:right; padding-right:8px;">类别序号</td>
      <td style="text-align:left;padding-left:8px;"><input type="text" name="SortOrder" value="<%call addorder(SortID)%>" style="width:200px;" maxlength="250" />
      </td>
    </tr>
    <tr>
      <td colspan="2" style=" text-align:left; padding-left:158px;"><input type="submit" name="submit" value="提交" /></td>
    </tr>
    <tr>
      <td colspan="2">&nbsp;</td>
    </tr>
  </table>
</form>
</body>
</html>
<!--#include file="../Conn/conn_close.asp"-->
<%
sub pidSort(SortID)
	response.Write("<select name='Pid' style='width:200px;'>")
	if clng(SortID)=0 then	
		response.Write("	<option value='0'>根目录</option>")	
	else
		sql="select * from TbNewsSort where pid in(select pid from TbNewsSort where id="&SortID&")"
		rs.open sql,conn,1,1
		if not rs.eof then
			do while not rs.eof
				if clng(rs("id"))=clng(SortID) then
					response.Write("	<option value='"&rs("id")&"' selected>"&rs("name")&"</option>")
				else
					response.Write("	<option value='"&rs("id")&"'>"&rs("name")&"</option>")
				end if
				rs.movenext
			loop
		end if
		rs.close
	end if
	response.Write("</select>")
end sub
sub addorder(SortID)
	sql="select id from TbNewsSort where pid ="&SortID&" order by id desc"
	rs.open sql,conn,1,1
	if rs.eof then
		response.Write("1")
	else
		response.Write(rs.recordcount+1)
	end if
	rs.close
end sub
%>
