<!--#include file="../inc/config.asp" -->
<!--#include file="../inc/conn.asp" -->
<!--#include file="inc/function.asp" -->
<!-- #include file="inc/Session.asp" -->
<!-- #include file="inc/checkrole.asp" -->
<%
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p01")
'''''''''''''''''''''''''''''''''''''''''''''''
Dim ParentID,Result,ClassID,ParentCName,RsParentObj,iscatalog,CatalogName,AddTime,CatalogTemplate,SaveDir,LastCatalogId,SortId
act=Request("act")
if(request("id")<>"") then
	ParentID=Cint(Request("id"))
else
	call alertstr("请选择正确的父栏目",1)
end if
if(act="add") then
	CatalogName=request.Form("CatalogName")
	AddTime=request.Form("AddTime")
	CatalogTemplate=request.Form("CatalogTemplate")
	SaveDir=request.Form("SaveFilePath")
	SavePathType=Cint(request.Form("SavePathType"))
	if(SavePathType=1) then
	if not isempty(request("SaveFilePathRegix")) and len(request("SaveFilePathRegix"))>1 then
		SaveDir=request("SaveFilePathRegix")
		set rs=server.CreateObject("adodb.recordset")
		rs.open "select top 1 id from catalogs order by id desc",conn,3,1
		if not rs.eof and not rs.bof then
			LastCatalogId=rs("id")+1
		else
			LastCatalogId=1
		end if
		rs.close
		set rs=nothing
		SaveDir=ReplaceStaticLabel(SaveDir,LastCatalogId)
	end if
	else
		set rs=server.CreateObject("adodb.recordset")
		rs.open "select top 1 id from catalogs order by id desc",conn,3,1
		if not rs.eof and not rs.bof then
			LastCatalogId=rs("id")+1
		else
			LastCatalogId=1
		end if
		rs.close
		set rs=nothing
	end if
	
	iscatalog=Cint(request.Form("iscatalog"))
	if(iscatalog=1) then
		iscatalog=true
	else
		iscatalog=false
	end if
	SortId=Cint(request.Form("sortid"))
	ReturnCheckInfo =AddAndModifyClass(LastCatalogId,ParentID,CatalogName,iscatalog,AddTime,CatalogTemplate,SaveDir,SortId)
	if(ReturnCheckInfo=true) then
		application.Lock()
		application(CachePrefix&"_catalogoption_"&ParentID)=""
		application.UnLock()
		response.Write("<iframe src=""catalog_genjs.asp"" width=""0"" height=""0""></iframe>")
		response.Write("<script>alert(""成功添加分类!"");location.href=""tree.asp"";</script>")
		response.End()
	end if
else
	if ParentID <0 then
		ParentCName = "参数传递错误，请重新加载"
	elseif ParentID = 0 then
		ParentCName = "根栏目"
	else
		set rs=server.CreateObject("adodb.recordset")
		rs.open "select * from catalogs where id="&ParentID,conn,3,1
		if rs.Eof or rs.Bof then
			ParentCName = "父栏目不存在，请重新加载"
		else
			ParentCName = rs("title")
		end if
		rs.close
		Set rs = Nothing
	end if
%>
<!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;
}
.style2 {color: #333333}
-->
</style>
</head>
<link href="Class.css" rel="stylesheet">
<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;
}
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.SaveFilePath.value==""){
		alert("栏目保存路径不能为空!");
		obj.SaveFilePath.focus();
		obj.SaveFilePath.select();
		return false;
	}
}
</script>
<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=add" method="post" name="ClassForm" onSubmit="return check(this);">
      <tr> 
        <td height="5" colspan="2"></td>
      </tr>
      <tr> 
        <td width="19%"><div align="center">类别名称</div></td>
        <td width="81%"> <div align="center"> 
            <input value="<%=Request("CatalogName") %>" name="CatalogName" type="text" id="CatalogName" style="width:100%;">
          </div></td>
      </tr>
      <tr> 
        <td><div align="center">父 栏 目</div></td>
        <td> <div align="center"> 
            <input readonly value="<%=ParentCName %>" style="width:100%;" type="text" name="textfield3">
          </div></td>
      </tr>
      <tr> 
        <td><div align="center">栏目模板</div></td>
        <td nowrap> <div align="left"> 
            <input name="CatalogTemplate" type="text" style="width:78%;" value="<%=TempletDir%>" readonly><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>手动
          <input name="SavePathType" type="radio" value="0" onClick="disp1()" checked>　
        自动
        <input name="SavePathType" type="radio" value="1" onClick="disp2()"></td>
      </tr>
      <tr id="saveFilePath"> 
        <td><div align="center">保存路径</div></td>
        <td nowrap> <div align="left"> 
            <input readonly value="<%=WebRootDir%>" type="text" style="width:78%;" name="SaveFilePath"><input type="button" name="Submit" value="选择路径" onClick="OpenWindowAndSetValue('Inc/SelectPathFrame.asp?CurrPath=<%=WebRootDir%>',400,300,window,document.ClassForm.SaveFilePath);document.ClassForm.SaveFilePath.focus();">
          </div></td>
      </tr>
	  <tr id="saveFileParse" style="display:none; "> 
        <td><div align="center">保存路径规则</div></td>
        <td nowrap> <div align="left"> 
            <input value="<%if(WebRootDir<>"/") then response.Write(WebRootDir)%>/catalog/$classid$" type="text" style="width:50%;" name="SaveFilePathRegix">(系统自动)<br>
            (标签：$SiteUrl$,$Year$等,更多请到"标签管理"->"常用标签")
          </div></td>
      </tr>
      <tr>
        <td><div align="center">添加日期</div></td>
        <td><div align="left">
            <input readonly value="<%If Request("AddTime")="" then Response.Write(Now()) else Response.Write(Request("AddTime")) %>" 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">
          <span class="style2">注：如果选中<a href="send.asp?classid=0">发布栏目</a>时将生成频道首页，否则生成带分页的文章列表页</span></td>
      </tr>
	  <tr>
        <td><div align="center">允许投稿</div></td>
        <td><input name="sortid" type="checkbox" id="sortid" value="1"></td>
      </tr>
      <tr> 
        <td colspan="2">
		<div align="center"> 
                  <input type="submit" name="Submitgsdfg" value=" 确 定 ">                  
                  <input name="ClassID" value="<%=ClassID %>" type="hidden" id="ClassID">
                  <input name="id" value="<%=ParentID %>" type="hidden" id="ParentID">
                  <input type="button" name="Submit2" onClick="window.close();" value=" 取 消 ">
        </div></td>
      </tr>
    </form>
  </table>
</div>
<%
end if
%>
<script language="JavaScript">
function disp1(){
saveFilePath.style.display='';
saveFileParse.style.display='none';
}
function disp2(){
saveFileParse.style.display='';
saveFilePath.style.display='none';
}
</script>
</body>
</html>

<%
call connclose()
%>