<!--#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" -->
<%
' 如果编辑的内容很多，上传速度太慢，请设置以下的时间，单位秒
Server.ScriptTimeout = 999999
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p02")
'''''''''''''''''''''''''''''''''''''''''''''''
dim act
act=request.querystring("act")
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>生成栏目导航JS</title>
<link href="style/global.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {	color: #FFFFFF;
	font-weight: bold;
}
-->
</style>
<script type="text/javascript">
function check(obj){
	with(obj){
		if(!checkMultipleRadio(obj.catalogs)){
			alert('至少选择一个栏目!');			
			return false;
		}else{
			return true;
		}
	}
}
function checkMultipleRadio(rb) {
	for (var i=0;i<rb.length;i++) {		
		if (rb[i].checked) {
			return true;
		}
	}
	return false;
}

</script>
</head>
<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" style="border-left:1px solid #000000;border-right:1px solid #000000;border-top:1px solid #000000;">
  <tr>
    <td><div align="center" class="style1">生成栏目导航JS</div></td>
  </tr>
</table>
<%
if(act="do") then
	dim catalogs
	catalogs=request.form("catalogs")
	call CreateNavJs(catalogs)
else
%>
<form name="form1" method="post" action="?act=do" style="margin:0px;" onSubmit="return check(this)">
<table width="100%" border="0" bgcolor="#D4D0C8" style="border:1px solid #000">
  <tr>
    <td>选择要发布到导航的栏目：</td>
  </tr>
  <tr>
    <td style="padding-left:100px;">
		<%
		set rs=server.CreateObject("adodb.recordset")
		rs.open "select id,title from catalogs where flag=1 order by id asc",conn,3,1
		while not rs.eof
			response.write("<input type=""checkbox"" name=""catalogs"" value="""&rs(0)&""">"&rs(1)&"<br>"&Chr(10))
			rs.movenext
		wend
		rs.close
		set rs=nothing
		%>		
      </td>
  </tr>
  <tr>
    <td>
      <div align="center">	  	
        <input class=Button type="button" name="chkall" value="全选" onClick="CheckAll(this.form)">
        <input class=Button type="button" name="chksel" value="反选" onClick="ContraSel(this.form)">
        <input type="submit" name="Submit" value=" 选好了，现在发布! ">
        
        </div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</form>
<script>
function CheckAll(form) { 	
	for (var i=0;i<form.elements.length;i++)  {  
		var e = form.elements[i];  
		if (e.name == 'catalogs')  
		e.checked = true // form.chkall.checked;  
	}  
} 
 
function ContraSel(form) {
	for (var i=0;i<form.elements.length;i++){
		var e = form.elements[i];
		if (e.name == 'catalogs')
		e.checked=!e.checked;
	}
}
</script>
<%end if%>
</body>
</html>
<%
sub CreateNavJs(catalog)
dim channel,subcatalog,navcontent,navi,navii,navrs
navcontent="var menuItems = ["&Chr(10)
set rs=server.createobject("adodb.recordset")
rs.open "select id,title,domainurl from catalogs where id in ("&catalog&") order by id asc",conn,3,1
if not rs.eof and not rs.bof then
	channel=rs.GetRows()
	'遍历频道
	for navi=0 to ubound(channel,2)
		navcontent=navcontent&"	['"&channel(1,navi)&"','"&channel(2,navi)&"', , , , , , , ,],"&Chr(10)
		set navrs=server.createobject("adodb.recordset")
		navrs.open "select title,savedir from catalogs where parentid="&channel(0,navi)&" order by id asc",conn,3,1
		'遍历子栏目
		while not navrs.eof			
			navcontent=navcontent&"		['|"&navrs(0)&"','"&navrs(1)&"/index_1.htm', , , , , , , ,],"&Chr(10)
			navrs.movenext			
		wend
		navrs.close
		set navrs=nothing		
		'navcontent=navcontent&"	],"&Chr(10)
	next
	rs.close
	set rs=nothing
else
	rs.close
	set rs=nothing
end if
navcontent=navcontent&"];"&Chr(10)
navcontent=navcontent&"dm_init();"&Chr(10)
'生成Navigate js file
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set file_w = fs.CreateTextFile(server.MapPath("../js/menu_items.js"))
file_w.WriteLine(navcontent)
response.Write("Success!<br>生成生成导航文件。文件已保存到："&server.MapPath("../js/nav.js")&"<br>以下为导航的引用代码，请将其复制到要显示导航的模板对应位置上。")		
file_w.close
set file_w=nothing
set fs=nothing
response.Write("<textarea style=""width:100%;"" rows=""5""><script language=""JavaScript"" type=""text/javascript"" src=""js/nav.js""></script>	</textarea>")
end sub
call connclose()
%>