<!--#include file="../inc/config.asp" -->
<!--#include file="../inc/conn.asp" -->
<!-- #include file="inc/Session.asp" -->
<!--#include file="inc/function.asp" -->
<!-- #include file="inc/checkrole.asp" -->
<%
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p01")
'''''''''''''''''''''''''''''''''''''''''''''''
Dim act,ClassID,ParID,CatalogName,RsParentObj,CatalogTemplate,CatalogSaveDir,iscatalog,modiTime,parent_id,SortId
if(request("id")<>"") then
	ClassID=Cint(Request("id"))
else
	call connclose()
	call alertstr("错误的ID号",1)
end if
act=Request("act")
if(act="mod") then
	CatalogName=trim(request.Form("CatalogName"))
	parent_id=Cint(request.Form("parent_id"))	
	AddTime=trim(request.Form("AddTime"))
	CatalogTemplate=request.Form("CatalogTemplate")
	CatalogSaveDir=request.Form("CatalogSaveDir")
	if(CatalogName="" or len(CatalogName)<1) then		
		call alertstr("类别名称不能为空",1)
		response.End()
	end if	
	iscatalog=Cint(request.Form("iscatalog"))
	if(iscatalog=1) then
		iscatalog=true
	else
		iscatalog=false
	end if	
	SortId=Cint(request.Form("sortid"))
	ReturnCheckInfo =ModifyClass(ClassID,parent_id,CatalogName,iscatalog,AddTime,CatalogTemplate,CatalogSaveDir,SortId)
	if(ReturnCheckInfo=true) then
		application.Lock()
		application(CachePrefix&"_catalogoption_"&parent_id)=""
		application.UnLock()
		response.Write("<iframe src=""catalog_genjs.asp"" width=""0"" height=""0""></iframe>")
		response.Write("<script>alert(""成功修改栏目!"");location.href=""tree.asp"";</script>")		
	end if
else
	set rs=server.CreateObject("adodb.recordset")
	rs.open "select * from catalogs where id="&ClassID,conn,3,1
	if rs.Eof or rs.Bof then		
		rs.close
		set rs=nothing
		call connclose()
		call alertstr("栏目不存在，请重新加载",1)
	else
		CatalogName=rs("title")
		ParID =rs("parentid")
		CatalogTemplate=rs("templet")
		CatalogSaveDir=rs("savedir")
		iscatalog=rs("flag")
		modiTime=rs("moditime")
		SortId=rs("sortid")
		rs.close
		set rs = Nothing
	end if	
	'获得大类
	dim first
	dim i
	set rs=server.CreateObject("adodb.recordset")
	sql="select * from catalogs where parentid=0 order by id asc"
	rs.open sql,conn,3,1
	if rs.eof or rs.bof then
		response.Write("暂时没有分类")
		rs.close
		set rs=nothing
		call connclose()
	else
		first=rs.GetRows()
		rs.close
		set rs=nothing
	end if
	'获得所有par_id=<>的类别------主类：par_id=0

	Function getcatalogs(parentid,str)
		Dim Sql,rstemp,TemptempStr,tempStr	
		tempStr=str&"&nbsp;"
		sql="select * from catalogs where parentid="&ParentID
		Set rstemp = Conn.Execute(Sql)
		do while Not rstemp.Eof
			if(rstemp("id")=ParID) then
				sele=" selected"
			else
				sele=""
			end if
			getcatalogs = getcatalogs &"<option value="&rstemp("id")&sele&">│"&tempStr&"└"&rstemp("title")&"</option>"&Chr(10)
			getcatalogs = getcatalogs & getcatalogs(rstemp("id"),tempStr)
			rstemp.MoveNext
		loop
		rstemp.close
		Set rstemp = Nothing
	End Function
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>栏目修改</title>
<style type="text/css">
<!--
.style1 {
	color: #FFFFFF;
	font-weight: bold;
}
-->
</style>
<script type="text/javascript">
function OpenWindowAndSetValue(Url,Width,Height,WindowObj,SetObj)
{
	var ReturnStr=showModalDialog(Url,WindowObj,'dialogWidth:'+Width+'pt;dialogHeight:'+Height+'pt;status:no;help:no;scroll:no;');
	if (ReturnStr!='') SetObj.value=ReturnStr;
	return ReturnStr;
}
</script>
</head>
<link href="Class.css" rel="stylesheet">
<body>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><iframe src="right_top.htm" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" height="30" width="100%"></iframe></td>
  </tr>
</table>
<table width="100%" height="22"  border="0" cellpadding="0" cellspacing="0" bgcolor="#FF9900">
  <tr>
    <td><div align="center" class="style1">修改栏目</div></td>
  </tr>
</table>
<div align="center">
  <table width="100%" border="0" cellspacing="5" cellpadding="0" style="border:1px solid #000000; ">
    <form action="?act=mod" method="post" name="ClassForm" onSubmit="return check(this);">
      <tr> 
        <td height="5" colspan="2"></td>
      </tr>
      <tr> 
        <td width="18%"><div align="center">类别名称</div></td>
        <td> <div align="center"> 
            <input value="<%=CatalogName %>" name="CatalogName" type="text" id="CatalogName" style="width:100%;">
          </div></td>
      </tr>
      <tr> 
        <td><div align="center">父 栏 目</div></td>
        <td>  
		  <div align="left">
		    <select name="parent_id" >
		    <%
			if (ParID=0) then
				response.Write("<option value=0 selected>根目录</option>")
			else
				response.Write("<option value=0>根目录</option>")
			end if
 		 	for i=0 to ubound(first,2)
		 		if(first(0,i)=ParID) then
					sele=" selected"
				else
					sele=""
				end if			
				response.Write("<option value="&first(0,i)&sele&">├"&first(2,i)&"</option>"&Chr(10))	
    			response.Write(getcatalogs(first(0,i),""))		
		 	next	
			%>
	        </select>            
          </div></td>
      </tr>
      <tr> 
        <td><div align="center">栏目模板</div></td>
        <td nowrap> <div align="left"> 
            <input name="CatalogTemplate" type="text" style="width:78%;" value="<%=CatalogTemplate%>"><input type="button" name="Submit" value="选择模板" onClick="OpenWindowAndSetValue('Inc/SelectFileFrame.asp?CurrPath=<%=TempletDir %>',400,300,window,document.ClassForm.CatalogTemplate);document.ClassForm.CatalogTemplate.focus();">
          </div></td>
      </tr>
      <tr> 
        <td><div align="center">保存路径</div></td>
        <td nowrap> <div align="left"> 
            <input value="<%=CatalogSaveDir%>" type="text" style="width:78%;" name="CatalogSaveDir"><input type="button" name="Submit" value="选择路径" onClick="OpenWindowAndSetValue('Inc/SelectPathFrame.asp?CurrPath=<%=WebRootDir%>',400,300,window,document.ClassForm.CatalogSaveDir);document.ClassForm.CatalogSaveDir.focus();">
          </div></td>
      </tr>
      <tr>
        <td><div align="center">添加日期</div></td>
        <td><div align="left">
            <input readonly value="<%If modiTime="" then Response.Write(Now()) else Response.Write(modiTime) %>" type="text" style="width:77%;" name="AddTime"><input name="sdaf" type="button" id="sdaf" onClick="OpenWindowAndSetValue('Inc/SelectDate.asp',280,120,window,document.ClassForm.AddTime);document.ClassForm.AddTime.focus();" value="选择日期">
        </div></td>
      </tr>
      <tr>
        <td><div align="center">是否频道</div></td>
        <td><input name="iscatalog" type="checkbox" id="iscatalog" value="1" <%if(iscatalog=true) then response.Write("checked") end if%>></td>
      </tr>
	  <tr>
        <td><div align="center">允许投稿</div></td>
        <td><input name="sortid" type="checkbox" id="sortid" value="1" <%if(sortid=1) then response.Write("checked") end if%>></td>
      </tr>
      <tr> 
        <td colspan="2">
		<div align="center"> 
                  <input type="submit" name="submit" value=" 确 定 ">                  
                  <input name="id" value="<%=ClassID%>" type="hidden" id="id">                  
                  <input type="button" name="Submit2" onClick="history.back();" value=" 返 回 ">
        </div></td>
      </tr>
    </form>
  </table>
</div>
<%
end if
%>
<script language="JavaScript">
function check(obj)
{
	if(obj.CatalogName.value==""){
		alert("栏目名称不能为空!");
		obj.CatalogName.focus();
		obj.CatalogName.select();
		return false;
	}
	if(obj.CatalogTemplate.value==""){
		alert("栏目模板不能为空!");
		obj.CatalogTemplate.focus();
		obj.CatalogTemplate.select();
		return false;
	}
	if(obj.CatalogSaveDir.value==""){
		alert("栏目保存路径不能为空!");
		obj.CatalogSaveDir.focus();
		obj.CatalogSaveDir.select();
		return false;
	}
}
</script>
</body>
</html>
<%
call connclose()
%>