<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="admin.asp"-->
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/function.asp"-->
<%
tab=trim(request("tab"))
if tab="" then response.Write("<script>alert('参数错误');history.back();</script>")
%>
<!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" />
<title>无标题文档</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<script src="style/js.js" type="text/javascript"></script>
<script type="text/javascript">
function checks()
{
  if (document.form1.title.value=="")
  {
    alert('分类名称不能为空!');
	document.form1.title.focus();
	return;
  }
    if (document.form1.html.value=="")
  {
    alert('生成目录不能为空!');
	document.form1.html.focus();
	return;
  }
  document.form1.submit();
}

</script>
</head>

<body id="page">
<h2 class="title">分类管理</h2>
<%
if request("action")=1 then
  if check(tab,"classid="&request("id"))>0 then
  response.Write("<script>alert('此分类下有信息，请先删除信息！');history.back();</script>")
  response.End()
  end if
  if check(tab&"_class","followid="&request("id"))>0 then
  response.Write("<script>alert('此分类有下级分类，请先删除下级分类！');history.back();</script>")
  response.End()
  end if
  conn.execute("delete from "&tab&"_class where id="&request("id"))
  response.Write("<script>location.href='cw_class.asp?tab="&tab&"';</script>")
  response.End()  
end if

if request("action")=2 then
call htmls(cw_news&request("html")&"/")
set rs=server.CreateObject("adodb.recordset")
sql="select * from "&tab&"_class where html='"&request("html")&"'"
rs.open sql,conn,1,3
rs.addnew
rs("title")=trim(request("title"))
rs("ordnum")=request("ordnum")
rs("followid")=request("followid")
rs("html")=request("shtml")&replace(request("html"),"/","")&"/"
rs("pages")=request("pages")
rs("keyword")=replace(trim(request("keyword")),"，",",")
rs("description")=trim(request("description"))
rs("pic")=request("pic")
rs("islist")=request("islist")
rs("temp")=request("temp")
rs("show")=request("show")
rs("ispass")=request("ispass")
rs.update
id=rs("id")
rs.close
if tab="cw_bbs" then response.Redirect"cw_class.asp?tab="&tab
call c_index()'生成首页
qid=cw_class("followid",tab&"_class",id)
if qid=0 then
    call c_list(id,"1",0,tab&"_class")
else
    call c_list(id,"1",0,tab&"_class")
	gid=cw_class("followid",tab&"_class",qid)
	if gid=0 then
	   call c_list(qid,"1",0,tab&"_class")
	else
	   call c_list(qid,"1",0,tab&"_class")
	   call c_list(gid,"1",0,tab&"_class")
	end if
end if
set rs=nothing
  response.Write("<script>var url='cw_class.asp?tab="&tab&"'; setTimeout('location.href=(url)',2000)</script>")
  response.End()
end if

if request("action")=3 then
call htmlf(cw_news&request("html")&"/",request("id"))'检测生成目录是否存在
set rs=server.CreateObject("adodb.recordset")
sql="select * from "&tab&"_class where id="&request("id")
rs.open sql,conn,1,3
rs("title")=trim(request("title"))
rs("ordnum")=request("ordnum")
rs("html")=request("shtml")&replace(request("html"),"/","")&"/"
rs("pages")=request("pages")
rs("keyword")=replace(trim(request("keyword")),"，",",")
rs("description")=trim(request("description"))
rs("pic")=request("pic")
rs("islist")=request("islist")
rs("temp")=request("temp")
rs("show")=request("show")
rs("ispass")=request("ispass")
rs.update
rs.close
if tab="cw_bbs" then response.Redirect"cw_class.asp?tab="&tab
call c_index()'生成首页
qid=cw_class("followid",tab&"_class",request("id"))
if qid=0 then
    call c_list(request("id"),"1",0,tab&"_class")
else
    call c_list(request("id"),"1",0,tab&"_class")
	gid=cw_class("followid",tab&"_class",qid)
	if gid=0 then
	   call c_list(qid,"1",0,tab&"_class")
	else
	   call c_list(qid,"1",0,tab&"_class")
	   call c_list(gid,"1",0,tab&"_class")
	end if
end if
set rs=nothing
  response.Write("<script>var url='cw_class.asp?tab="&tab&"'; setTimeout('location.href=(url)',2000)</script>")
  response.End()
end if

function htmls(html)
  set ht=server.CreateObject("adodb.recordset")
  htq="select * from "&tab&"_class where html='"&html&"'"
  ht.open htq,conn,1,1
  if ht.recordcount>0 then
    response.Write("<script>alert('生成目录己经存在，请更换！');history.back();</script>")
    response.End()
  end if
  ht.close
  set ht=nothing
end function

function htmlf(html,id)
  set ht=server.CreateObject("adodb.recordset")
  htq="select * from "&tab&"_class where html='"&html&"' and id<>"&id
  ht.open htq,conn,1,1
  if ht.recordcount>0 then
    response.Write("<script>alert('生成目录己经存在，请更换！');history.back();</script>")
    response.End()
  end if
  ht.close
  set ht=nothing
end function

'删除分类验证关联
function check(tab,wher)
set ch=server.CreateObject("adodb.recordset")
chq="select * from "&tab&" where "&wher
ch.open chq,conn,1,1
check=ch.recordcount
ch.close
set ch=nothing
end function
%>
<table width="99%" border="0" align="center" class="line_table">
  <tr>
    <td height="20">&nbsp;网站后台管理 &gt;&gt; <a href="cw_class.asp?tab=<%=tab%>">分类管理</a>&nbsp;&nbsp;&nbsp;&nbsp;【<a href="cw_class.asp?add=1&followid=0&tab=<%=tab%>" style="color:#FF0000">添加一级分类</a>】</td>
  </tr>
</table>
	<%if request("add")="" then%>
	<table width="99%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
      <tr>
	    <td width="7%" height="20" bgcolor="#F0F3F5"><div align="center" style="font-weight: bold">分类ID</div></td>
        <td width="29%" bgcolor="#F0F3F5"><div align="center" style="font-weight: bold">分类名称</div></td>
        <td width="13%" bgcolor="#F0F3F5"><div align="center" style="font-weight: bold">排序</div></td>
        <td width="14%" bgcolor="#F0F3F5"><div align="center" style="font-weight: bold">类型</div></td>
        <td width="31%" bgcolor="#F0F3F5"><div align="center" style="font-weight: bold">分类操作</div></td>
      </tr>
<%
	set rf=server.CreateObject("adodb.recordset")
	rfq="select * from "&tab&"_class where followid=0 order by id asc"
	rf.open rfq,conn,1,1
	if not rf.eof then
	do while not rf.eof 
%>
      <tr >
	    <td height="20" align="center" bgcolor="#B3D8F9"><%=rf("id")%></td>
        <td bgcolor="#B3D8F9">&nbsp;┗ <%=rf("title")%> (<a href="<%=cf_root&rf("html")%>" target="_blank"><%=cf_root&rf("html")%></a>)</td>
        <td align="center" bgcolor="#B3D8F9" ><%=rf("ordnum")%></td>
        <td align="center" bgcolor="#B3D8F9" ><%if rf("islist")=0 then%><span style="color:#FF0000">频道</span><%else%>列表<%end if%></td>
        <td align="center" bgcolor="#B3D8F9" ><a href="cw_class.asp?add=1&followid=<%=rf("id")%>&shtml=<%=rf("html")%>&tab=<%=tab%>">添加下级分类</a> | <a href="cw_class.asp?id=<%=rf("id")%>&add=2&shtml=&tab=<%=tab%>">编辑分类</a> | <a href="cw_class.asp?id=<%=rf("id")%>&action=1&tab=<%=tab%>" onclick="return confirm('你确定要删除吗？')">删除分类</a></td>
      </tr>
	  <%
	  set js=server.CreateObject("adodb.recordset")
	  jsq="select * from "&tab&"_class where followid="&rf("id")&" order by ordnum asc,id asc" 
	  js.open jsq,conn,1,1
	  if not js.eof then
	  do while not js.eof
	  %>
	  <tr >
	    <td height="20" align="center" bgcolor="#E8E8E8"><%=js("id")%></td>
        <td bgcolor="#E8E8E8">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;┣ <%=js("title")%> (<a href="<%=cf_root&js("html")%>" target="_blank"><%=cf_root&js("html")%></a>)</td>
        <td align="center" bgcolor="#E8E8E8" ><%=js("ordnum")%></td>
        <td align="center" bgcolor="#E8E8E8" ><%if js("islist")=0 then%>频道<%else%>列表<%end if%></td>
        <td align="center" bgcolor="#E8E8E8" ><a href="cw_class.asp?add=1&followid=<%=js("id")%>&shtml=<%=js("html")%>&tab=<%=tab%>">添加下级分类</a> | <a href="cw_class.asp?id=<%=js("id")%>&add=2&shtml=<%=rf("html")%>&tab=<%=tab%>">编辑分类</a> | <a href="cw_class.asp?id=<%=js("id")%>&action=1&tab=<%=tab%>" onclick="return confirm('你确定要删除吗？')">删除分类</a></td>
      </tr>
	  <%
         set j3=server.CreateObject("adodb.recordset")
		 j3q="select * from "&tab&"_class where followid="&js("id")
		 j3.open j3q,conn,1,1
		 if not j3.eof then
		 do while not j3.eof
         %>
	  <tr >
	    <td height="20" align="center" bgcolor="#FFFFFF"><%=j3("id")%></td>
        <td bgcolor="#FFFFFF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;┣ <%=j3("title")%> (<a href="<%=cf_root&j3("html")%>" target="_blank"><%=cf_root&j3("html")%></a>)</td>
        <td align="center" bgcolor="#FFFFFF" ><%=j3("ordnum")%></td>
        <td align="center" bgcolor="#FFFFFF" ><%if j3("islist")=0 then%>频道<%else%>列表<%end if%></td>
        <td align="center" bgcolor="#FFFFFF" ><a href="cw_class.asp?id=<%=j3("id")%>&add=2&shtml=<%=js("html")%>&tab=<%=tab%>">编辑分类</a> | <a href="cw_class.asp?id=<%=j3("id")%>&action=1&tab=<%=tab%>" onclick="return confirm('你确定要删除吗？')">删除分类</a></td>
      </tr>
	  <%
	  j3.movenext
	  loop
	  end if
	  j3.close
	  set j3=nothing
	  %>
	  <%
	  js.movenext
	  loop
	  end if
	  js.close
	  set js=nothing
	  %>
<%
rf.movenext
loop
else
response.Write("<div align='center'><span style='color: #FF0000'>暂无数据！</span></div>")
end if
rf.close
set rf=nothing
%>
    </table>
	<%end if%>
<%if request("add")=1 then%>
<table width="99%" border="0">
	  <form id="form1" name="form1" method="post" action="cw_class.asp?action=2&tab=<%=tab%>">
        <tr>
          <td height="20" colspan="2" align="center"><h3>添加分类</h3></td>
        </tr>
        <tr>
          <td width="31%" height="20" align="right">分类名称：</td>
          <td width="69%"><input name="title" type="text" id="title" size="40" /></td>
        </tr>
        <tr>
          <td height="20" align="right">生成目录：</td>
          <td><input name="html" type="text" id="html" size="40" />
          *news 此目录将生成在栏目目录下</td>
        </tr>
		<%
		select case tab
		case "cw_news"
		   tp_1=tp_news
		   tp_2=tp_news_list
		   tp_3=tp_news_show
		case "cw_info"
		   tp_1=tp_info
		   tp_2=tp_info_list
		   tp_3=tp_info_show
		case "cw_bbs"
		   tp_1=tp_bbs
		   tp_2=tp_bbs_list
		   tp_3=tp_bbs_show
		case "cw_hous"
		   tp_1=tp_hous
		   tp_2=tp_hous_list
		   tp_3=tp_hous_show
		case "cw_shop"
		   tp_1=tp_shop
		   tp_2=tp_shop_list
		   tp_3=tp_shop_show
		case "cw_job"
		   tp_1=tp_job
		   tp_2=tp_job_list
		   tp_3=tp_job_show
		end select
		%>
        <tr>
          <td height="20" align="right">父级分类：</td>
          <td>
		  <select name="followid" id="followid">
		  <option value="0" <%if cint(Request("followid"))=0 then%>selected="selected"<%end if%>>顶级分类</option>
	<%
	set rf=server.CreateObject("adodb.recordset")
	rfq="select * from "&tab&"_class where followid=0 order by ordnum asc,id asc"
	rf.open rfq,conn,1,1
	if not rf.eof then
	do while not rf.eof
	%>
	<option value="<%=rf("id")%>" <%if cint(request("followid"))=rf("id") then%>selected="selected"<%end if%>><%=rf("title")%></option>
	<%
	set ri=server.CreateObject("adodb.recordset")
	riq="select * from "&tab&"_class where followid="&rf("id")&" order by ordnum asc,id asc"
	ri.open riq,conn,1,1
	if not ri.eof then
	do while not ri.eof
	%>
	<option value="<%=ri("id")%>" <%if cint(request("followid"))=ri("id") then%>selected="selected"<%end if%>>&nbsp;&nbsp;<%=ri("title")%></option>
	<%
	set rj=server.CreateObject("adodb.recordset")
	rjq="select * from "&tab&"_class where followid="&ri("id")&" order by ordnum asc,id asc"
	rj.open rjq,conn,1,1
	if not rj.eof then
	do while not rj.eof
	%>
	<option value="<%=rj("id")%>" <%if cint(request("followid"))=rj("id") then%>selected="selected"<%end if%>>&nbsp;&nbsp;&nbsp;&nbsp;<%=rj("title")%></option>
	<%
	rj.movenext
	loop
	end if
	rj.close
	set rj=nothing
	ri.movenext
	loop
	end if
	ri.close
	set ri=nothing
	rf.movenext
	loop
	  end if
	  rf.close
	  set rf=nothing
	  %>
	  </select>
		  </td>
        </tr>
        <tr>
          <td height="20" align="right">频道或目录：</td>
          <td><input name="islist" type="radio" value="0" checked="checked" onclick="document.form1.temp.value='<%=tp_1%>'" />
            频道
              <input type="radio" name="islist" value="1" onclick="document.form1.temp.value='<%=tp_2%>'" />
            列表</td>
        </tr>
        <tr>
          <td height="20" align="right">是否可添加数据：</td>
          <td><select name="ispass" id="ispass">
              <option value="0">是</option>
              <option value="1">否</option>
            </select>          </td>
        </tr>
        <tr>
          <td height="20" align="right">分类模板：</td>
          <td><input name="temp" type="text" value="<%=tp_1%>" size="40" />
          <input type="button" name="Submit12" value="选择" onclick="Open_w('Cw_temp.asp',320,200,window,document.form1.temp)" /></td>
        </tr>
        <tr>
          <td height="20" align="right">内容模板：</td>
          <td><input name="show" type="text" value="<%=tp_3%>" size="40" />
          <input type="button" name="Submit12" value="选择" onclick="Open_w('Cw_temp.asp',320,200,window,document.form1.show)" /></td>
        </tr>
        <tr>
          <td height="20" align="right">分页显示数量：</td>
          <td><input name="pages" type="text" id="pages" value="20" />
            *作为列表时一页显示多少条记录</td>
        </tr>
        <tr>
          <td height="20" align="right">分类关键词：</td>
          <td><input name="keyword" type="text" id="keyword" size="62" /></td>
        </tr>
        <tr>
          <td height="20" align="right">分类描述：</td>
          <td><textarea name="description" cols="60" rows="6" id="description"></textarea></td>
        </tr>
        
        <tr>
          <td height="20" align="right">分类排序：</td>
          <td><input name="ordnum" type="text" id="ordnum" size="40" value="0" /></td>
        </tr>
        <tr>
          <td height="20" align="right">分类图片：</td>
          <td><input type="text" name="pic" id="pic" value="" readonly="" size="40" style="display:none"  /><iframe src="../inc/upload.asp?lei=5&pid=pic&fid=fm&rid=class" frameborder="0" width="400" height="25" scrolling="No" id="fm"></iframe></td>
        </tr>
        <tr>
          <td height="20">&nbsp;</td>
          <td><input name="Submit" type="button" class="btn" onclick="checks()" value="添加分类" />
            <input name="shtml" type="hidden" id="shtml" value="<%=request("shtml")%>" /></td>
        </tr>
  </form>
</table>
<%end if%>

<%if request("add")=2 then%>
<table width="99%" border="0">
<%
set up=server.CreateObject("adodb.recordset")
sql="select * from "&tab&"_class where id="&request("id")
up.open sql,conn,1,1
if not up.eof then
%>
	  <form id="form1" name="form1" method="post" action="cw_class.asp?action=3&tab=<%=tab%>">
        <tr>
          <td height="20" colspan="2" align="center"><h3>修改分类</h3></td>
          </tr>
        <tr>
          <td width="31%" height="20" align="right">分类名称：</td>
          <td width="69%"><input name="title" type="text" id="title" value="<%=up("title")%>" size="40" /></td>
        </tr>
        <tr>
          <td height="20" align="right">生成目录：</td>
          <td><input name="html" type="text" id="html" value="<%=replace(replace(up("html"),request("shtml"),""),"/","")%>" size="40" />
*news 此目录将生成在栏目目录下</td>
        </tr>
		<%
		select case tab
		case "cw_news"
		   tp_1=tp_news
		   tp_2=tp_news_list
		   tp_3=tp_news_show
		case "cw_info"
		   tp_1=tp_info
		   tp_2=tp_info_list
		   tp_3=tp_info_show
		case "cw_ask"
		   tp_1=tp_ask
		   tp_2=tp_ask_list
		   tp_3=tp_ask_show
		case "cw_hous"
		   tp_1=tp_hous
		   tp_2=tp_hous_list
		   tp_3=tp_hous_show
		case "cw_shop"
		   tp_1=tp_shop
		   tp_2=tp_shop_list
		   tp_3=tp_shop_show
		case "cw_job"
		   tp_1=tp_job
		   tp_2=tp_job_list
		   tp_3=tp_job_show
		end select
		%>
        <tr>
          <td height="20" align="right">父级分类：</td>
          <td>
		  <select name="followid" id="followid">
		  <option value="0" <%if up("followid")=0 then%>selected="selected"<%end if%>>顶级分类</option>
	<%
	set rf=server.CreateObject("adodb.recordset")
	rfq="select * from "&tab&"_class where followid=0 order by ordnum asc,id asc"
	rf.open rfq,conn,1,1
	if not rf.eof then
	do while not rf.eof
	%>
	<option value="<%=rf("id")%>" <%if up("followid")=rf("id") then%>selected="selected"<%end if%>><%=rf("title")%></option>
	<%
	set ri=server.CreateObject("adodb.recordset")
	riq="select * from "&tab&"_class where followid="&rf("id")&" order by ordnum asc,id asc"
	ri.open riq,conn,1,1
	if not ri.eof then
	do while not ri.eof
	%>
	<option value="<%=ri("id")%>" <%if up("followid")=ri("id") then%>selected="selected"<%end if%>>&nbsp;&nbsp;<%=ri("title")%></option>
	<%
	set rj=server.CreateObject("adodb.recordset")
	rjq="select * from "&tab&"_class where followid="&ri("id")&" order by ordnum asc,id asc"
	rj.open rjq,conn,1,1
	if not rj.eof then
	do while not rj.eof
	%>
	<option value="<%=rj("id")%>" <%if up("followid")=rj("id") then%>selected="selected"<%end if%>>&nbsp;&nbsp;&nbsp;&nbsp;<%=rj("title")%></option>
	<%
	rj.movenext
	loop
	end if
	rj.close
	set rj=nothing
	ri.movenext
	loop
	end if
	ri.close
	set ri=nothing
	rf.movenext
	loop
	  end if
	  rf.close
	  set rf=nothing
	  %>
	  </select>
          </td>
        </tr>
        <tr>
          <td height="20" align="right">频道或目录：</td>
          <td><input name="islist" type="radio" value="0" <%if up("islist")=0 then%>checked="checked"<%end if%> onclick="document.form1.temp.value='<%=tp_1%>'"  />
            频道
              <input type="radio" name="islist" value="1" <%if up("islist")=1 then%>checked="checked"<%end if%> onclick="document.form1.temp.value='<%=tp_2%>'"  />
            列表</td>
        </tr>
        <tr>
          <td height="20" align="right">是否可添加数据：</td>
          <td><select name="ispass" id="ispass">
              <option value="0" <%if up("ispass")=0 then%> selected="selected"<%end if%>>是</option>
              <option value="1" <%if up("ispass")=1 then%> selected="selected"<%end if%>>否</option>
            </select>
		  </td>
        </tr>
        <tr>
          <td height="20" align="right">分类模板：</td>
          <td><input name="temp" type="text" value="<%=up("temp")%>" /><input type="button" name="Submit12" value="选择" onclick="Open_w('Cw_temp.asp',320,200,window,document.form1.temp)" /></td>
        </tr>
        <tr>
          <td height="20" align="right">内容模板：</td>
          <td><input name="show" type="text" value="<%=up("show")%>" /><input type="button" name="Submit12" value="选择" onclick="Open_w('Cw_temp.asp',320,200,window,document.form1.show)" /></td>
        </tr>
        <tr>
          <td height="20" align="right">分页显示数量：</td>
          <td><input name="pages" type="text" id="pages" value="<%=up("pages")%>" />
            *作为列表时一页显示多少条记录</td>
        </tr>
        <tr>
          <td height="20" align="right">分类关键词：</td>
          <td><input name="keyword" type="text" id="keyword" value="<%=up("keyword")%>" size="62" /></td>
        </tr>
        <tr>
          <td height="20" align="right">分类描述：</td>
          <td><textarea name="description" cols="60" rows="6" id="description"><%=up("description")%></textarea></td>
        </tr>
        
        <tr>
          <td height="20" align="right">分类排序：</td>
          <td><input name="ordnum" type="text" id="ordnum" value="<%=up("ordnum")%>" size="40" /></td>
        </tr>
        <tr>
          <td height="20" align="right">分类图片：</td>
          <td><input type="text" name="pic" id="pic" value="<%=up("pic")%>" readonly="" size="40"  /><iframe src="../inc/upload.asp?lei=5&pid=pic&fid=form1" frameborder="0" width="400" height="25" scrolling="No" id="fm" style="display:none"></iframe> <a  onclick="document.getElementById('pic').style.display='none';document.getElementById('fm').style.display='inline';document.getElementById('s1').style.display='none'" id="s1" style="cursor:pointer">修改</a></td>
        </tr>
        <tr>
          <td height="20">&nbsp;</td>
          <td><input name="Submit" type="button" class="btn" onclick="checks()" value="修改分类"  />
            <input name="id" type="hidden" id="id" value="<%=up("id")%>" />
            <input name="shtml" type="hidden" id="shtml" value="<%=request("shtml")%>" /></td>
        </tr>
		</form>
		<%
		else
		response.Write("<tr><td>此分类不存！</td></tr>")
		end if
		up.close
		set up=nothing
		%>
    </table>
<%end if%>
<%
call closes()
%>
</body>
</html>
