<!--#include file="admin_inc.asp"-->
<%
'******************************************************************************************
' Software name: Max(马克斯) Content Management System
' Version:4.0
' Web: http://www.maxcms.net
' Author: 石头(maxcms2008@qq.com),yuet,长明,酒瓶
' Copyright (C) 2005-2009 马克斯官方 版权所有
' 法律申明：MaxCMS程序所有代码100%原创、未引入任何网上代码,对一切抄袭行为、坚决严肃追究法律责任
'******************************************************************************************

viewHead "专题管理" & "-" & menuList(1,0)

dim action : action = getForm("action", "get")


Select  case action
	case "last" : moveToLast
	case "next" : moveToNext
	case "del" : delTopic
	case "delall" : delAll
	case "edit" : editTopic
	case "add" : addTopic
	case else : main : popTopicWin
End Select 
viewFoot

dim id
Sub main
	dim dataListObj,topicArray,i,n,m_id
	id=getForm("id","get")
	set dataListObj =  mainClassobj.createObject("MainClass.DataList")
	dataListObj.fieldsStr="m_id,m_name,m_sort,m_template,m_enname,m_pic,m_des,(select count(*) as m_count from {pre}data d where d.m_topic=t.m_id)" 
	dataListObj.orderStr = "m_sort asc,m_id"
	dataListObj.dataSortType = "asc "
	dataListObj.tableStr = "{pre}topic as t"
	topicArray = dataListObj.getDataList()
%>
<div id="append_parent"></div>
<div class="container" id="cpcontainer">
<!--当前导航-->
<script type="text/JavaScript">if(parent.$('admincpnav')) parent.$('admincpnav').innerHTML='后台首页&nbsp;&raquo;&nbsp;<%=menuList(1,0)%>&nbsp;&raquo;&nbsp;专题管理';</script>
<%
	if isArray(topicArray) then 
		n=ubound(topicArray,2)
%>
<form   method="post" name="topicform">
<table class="tb">
<tr class="thead"><th colspan="8">专题管理</th></tr>
    <TR align="center">
      <TD width="7%">ID</TD>
      <TD width="17%">专题名称</TD>
      <TD width="20%">专题模板<br />
(放置于模板文件夹下)</TD>
       <TD width="12%">专题别名</TD>
       <TD width="20%">专题图片</TD>
       <TD width="6%">专题描述</TD>
      <TD width="7%">排序</TD>
      <TD width="11%">操作</TD>
    </TR>
    <%
		for i=0 to n
			m_id= trim(topicArray(0,i))
	%>
     <TR<%if id=m_id then %>  class="editlast"<%end if%> name="topictr"  id="topictr<%=m_id%>" align="center">

      <TD align="left"><input type="checkbox" value="<%=m_id%>" name="m_id"  checked="checked"  class="checkbox" /><%=m_id%></TD>
      <TD align="left"><input type="text" name="m_name<%=m_id%>" value="<%=topicArray(1,i)%>" size="20"/>(<font color="red"><%=topicArray(7,i)%></font>)</TD>
      <td><input type="text" name="m_template<%=m_id%>" value="<%=topicArray(3,i)%>" size="20"/></td>
      <td><input type="text" name="m_enname<%=m_id%>" value="<%=topicArray(4,i)%>" size="10"/></td>
      <td><input type="text" name="m_pic<%=m_id%>" value="<%=topicArray(5,i)%>" size="20"/></td>
	 <TD><img <% if not isNul(topicArray(6,i)) then%>src='imgs/modify1.gif'<%else%>src='imgs/modify.gif'<%end if%>  title='修改专题描述' style="cursor:pointer" onClick="viewCurrentTopicTr('<%=m_id%>');openTopicDesWin('topicdes','<%=m_id%>')" /></TD>
      <TD><input name="m_sort<%=m_id%>" type="text" value="<%=topicArray(2,i)%>"  size="3"/></TD>
      <TD><a  href="?action=last&id=<%=m_id%>">上移</a> <a  href="?action=next&id=<%=m_id%>">下移</a> <a  onclick="if(confirm('确定要删除吗')){return true;}else{return false;}" href="?action=del&id=<%=m_id%>">删除</a></TD>
    </TR>
    <%
		next
	%>
    <tr><td  colspan="9">全选<input type="checkbox" name="chkall" id="chkall" class="checkbox" onclick="checkAll(this.checked,'input','m_id')" />反选<input type="checkbox" name="chkothers" id="chkothers" class="checkbox" onclick="checkOthers('input','m_id')" /><input type="submit" value="批量删除" onclick="if(confirm('确定要删除吗')){topicform.action='?action=delall';}else{return false}" class="btn"  />&nbsp;&nbsp;<input type="submit" value="批量修改选中专题" name="Submit" class="btn" onclick="topicform.action='?action=edit';" /></td></tr>
</TABLE>
</form> 
<%
	else
%>
<table><tr><td>暂无专题</td></tr></table>
<%	
	end if	
%>
<form action="?action=add" method="post">
	<table class="tb mt20">
		<tr class="thead"><th colspan="8">添加专题</th></tr>
		<tr align="center">
			<TD width="6%">&nbsp;</TD>
		  <TD width="18%">名称<font color='red'>＊</font><br>
	      <input type="text" size="20" name="m_name" /></TD>
		  <TD width="20%">模板<br><input type="text" name="m_template"  size="20"/></TD>
			<TD width="12%">别名<font color='red'>＊</font><br><input type="text" name="m_enname"  size="10"/></TD>
			<TD width="20%">图片<font color='red'>＊</font><br><input type="text" name="m_pic"  size="20"/></TD>			
			<TD width="6%">&nbsp;</td>
			<TD width="7%">排序<br>
		  <input type="text" size="3" name="m_sort"/></TD>
			<TD width="11%">&nbsp;<br>
		  &nbsp;<input type="submit" value="添加专题" class="btn" /></TD>
	  </tr>
	</table>
</form>
<%
	set dataListObj = nothing
End Sub

Sub popTopicWin
%>
<div id="topicdes" style="top:100px; display:none;" class="popdiv">
	<div class="poptitie"><img src="../pic/btn_close.gif" alt="关闭" onClick="$('topicdes').style.display='none'" />自定义标签路径 </div>
    <div class="popbody"><div>
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
<form id="f_des"  action="admin_ajax.asp?action=submittopicdes" method="post">
<tr>
  <td width="554" >专题简介：<br>
  <input type="hidden" name="f_m_id"   >
  <textarea cols="72"  rows="14"  name="f_m_des"></textarea></td><td></td>
</tr>
<tr><td><input type="button" onClick="submitTopicDes('topicdes')" value="修     改" class="btn" /></td></tr>
</form>
</table>
</div></div>
</div>
<script type="text/javascript" src="imgs/drag.js"></script>	
<%	
End Sub

Sub moveToLast
	id=getForm("id","get")
	dim cur,cou,flag
	cur=conn.db("select m_sort from {pre}topic where m_id="&id,"execute")(0)
	cou=conn.db("select count(*) from {pre}topic  where m_sort<"&cur,"execute")(0)
	if cou>0 then 
		flag=conn.db("select top 1 m_sort from {pre}topic  where m_sort<"&cur&" order by m_sort desc","execute")(0)
		conn.db "update {pre}topic set m_sort="&flag&" where m_id="&id,"execute" 
	else
		conn.db "update {pre}topic set m_sort=m_sort-1 where m_id="&id,"execute" 
	end if
	alertMsg "","admin_topic.asp?id="&id
End Sub


Sub moveToNext
	id=getForm("id","get")
	dim cur,cou,flag
	cur=conn.db("select m_sort from {pre}topic where m_id="&id,"execute")(0)
	cou=conn.db("select count(*) from {pre}topic  where m_sort>"&cur,"execute")(0)
	if cou>0 then 
		flag=conn.db("select top 1 m_sort from {pre}topic  where m_sort>"&cur&" order by m_sort asc","execute")(0)
		conn.db "update {pre}topic set m_sort="&flag&" where m_id="&id,"execute" 
	else
		conn.db "update {pre}topic set m_sort=m_sort+1 where m_id="&id,"execute" 
	end if
	alertMsg "","admin_topic.asp?id="&id
End Sub

Sub delAll
	dim ids : ids=replaceStr(getForm("m_id","post")," ","")
	conn.db "delete from {pre}topic where m_id in ("&ids&")","execute" 
	conn.db "update {pre}data set m_topic=0 where m_topic in("&ids&")","execute"
	alertMsg "","admin_topic.asp"
End Sub

Sub delTopic
	id=getForm("id","get")
	conn.db "delete from {pre}topic where m_id="&id,"execute"
	conn.db "update {pre}data set m_topic=0 where m_topic="&id,"execute"
	alertMsg "","admin_topic.asp?id="&id
End Sub


Sub editTopic
	dim ids,idsArray,id,m_name,m_sort,sqlStr,m_template,m_enname,m_pic
	ids = replace(getForm("m_id","post")," ","")
	idsArray = split(ids,",")
	For Each id In idsArray
		m_name = getForm("m_name"&id,"post") : m_enname = getForm("m_enname"&id,"post") : m_pic = getForm("m_pic"&id,"post")
		if  isNul(m_name) or isNul(m_enname) or isNul(m_pic)   then  die "信息填写不完整，请检查"
		m_template = getForm("m_template"&id,"post") : if isNul(m_template) then m_template="topic.html"
		m_sort = getForm("m_sort"&id,"post") : if isNul(m_sort) then m_sort=conn.db("select max(m_sort) from {pre}topic","execute")(0)+1		
		if not isNum(m_sort) then die "排序必须为数字"
		sqlStr = "update {pre}topic set m_name='"&m_name&"',m_sort="&m_sort&",m_template='"&m_template&"',m_enname='"&m_enname&"',m_pic='"&m_pic&"' where m_id="&id
		conn.db sqlStr,"execute" 
	Next
	alertMsg "","admin_topic.asp" 
End Sub

Sub addTopic
	dim m_name,m_sort,sqlStr,m_template,m_enname,m_pic
	m_name = getForm("m_name"&id,"post") :  m_enname = getForm("m_enname","post") : m_pic = getForm("m_pic","post")
	if  isNul(m_name) or isNul(m_enname) or isNul(m_pic)   then  die "信息填写不完整，请检查"
	m_template = getForm("m_template","post") : if isNul(m_template) then m_template="topic.html"
	m_sort = getForm("m_sort","post") : if isNul(m_sort) then m_sort=conn.db("select max(m_sort) from {pre}topic","execute")(0)+1
	if not isNum(m_sort) then m_sort=1
	sqlStr = "insert into  {pre}topic(m_name,m_sort,m_template,m_enname,m_pic) values ('"&m_name&"',"&m_sort&",'"&m_template&"','"&m_enname&"','"&m_pic&"')"
	conn.db sqlStr,"execute" 
	alertMsg "","admin_topic.asp" 
End Sub
%>
