<!-- #Include File="Include/AMH_Onlogin.asp" -->
<%
'=======================================================
' 欢迎使用《阿赛大型门户网站系统V2.0》，简称“AsaiMHV2”
' 技术支持、商业版咨询、官方唯一指定联系QQ“4941172”
' 官方网站：http://77ya.com      程序负责人：阿赛
'=======================================================

Dim iMenuID
iMenuID = Cls.Code_ID("MenuID")
Admins = True
'后台标识
Index_Url="menu"
Data_Name="AsaiMHMenu"
tit_fir="后台菜单"
tit="管理后台菜单"
Call AMH_Header(1)
%>
<tr><td align=center colspan=2 height=30>
  <table border=0>
  <tr>
  <td><a href='?'><%Response.Write tit%></a></td>
  <td width=10></td>
  <td><a href='?Action=Add'>添加新的<%Response.Write tit_fir%></a></td>
  <td width=10></td>
  <td><a href='AMH_Channel.asp'>网站频道管理</a></td>
  <td width=10></td>
  </tr>
  </table>
</td></tr>
</table>
<%
Call AMH_Table(1)
Select Case LCase(Action)
Case "add"
	AsaiMHMenu_Add()
Case "edit"
	AsaiMHMenu_Edit()
case "up","down"
	AsaiMHMenu_Order()
Case "delete"
	AsaiMHMenu_Delete()
Case Else
	AsaiMHMenu_Main()
End Select
Call AMH_Ender(tit)
'//* 菜单排序 *//
Sub AsaiMHMenu_Order()
	Dim nid,m_id,mid1,mid2,mo1,mo2
	m_id=iMenuID
	if int(m_id)<1 then exit sub
	sql_add=""
	If LCase(Action)="up" Then sql_add=" desc"
	SQL = "Select MenuID,MenuOrder From ["&Data_Name&"] Where ChannelIDs="&iChannelIDs&" Order By MenuOrder"&sql_add&",MenuID"
	Set Rs = Cls.Exec(SQL,1)
	Do While Not Rs.Eof
		nid=Int(Rs(0))
		If Int(m_id)=Int(nid) Then
			mid1=nid
			mo2=Rs(1)
			Rs.MoveNext
			If Rs.Eof Then Exit Do
			mid2=Rs(0)
			mo1=Rs(1)
			Call Cls.Exec("Update ["&Data_Name&"] Set MenuOrder="&mo1&" Where ChannelIDs="&iChannelIDs&" And MenuID="&mid1,0)
			Call Cls.Exec("Update ["&Data_Name&"] Set MenuOrder="&mo2&" Where ChannelIDs="&iChannelIDs&" And MenuID="&mid2,0)
			Exit Do
		End If
		Rs.MoveNext
	Loop
	Rs.Close
	Call Cls.Cache_Del("amh_menu")
	Call ReloadMenu(1)
	Call AsaiMHMenu_Main()
End Sub
'//* 添加后台菜单 *//
Sub AsaiMHMenu_Add()
	Dim MenuCid, MenuName, MenuUrl, MenuSort, MenuHidden,  Menulevel, MenuDataName, MenuTit, MenuTitFir, MenuOrder, iMenuHelp
	Call AMH_Td("添加"&Tit_Fir)
	If Chk() Then
		MenuName = Cls.Code_Admin("MenuName",1,20)
		If MenuName = "" Then
			Call AMH_Error("后台菜单标题不能为空！")
			Exit Sub
		End If
		MenuHidden = False
		If Cls.Code_Form("MenuHidden") = "yes" Then MenuHidden = True
		MenuTit = Cls.Code_Admin("MenuTit",1,20)
		If MenuTit = "" Then
			Call AMH_Error("后台菜单简称不能为空！")
			Exit Sub
		End If
		MenuUrl = Cls.Code_Admin("MenuUrl",1,100)
		If MenuUrl = "" Then
			Call AMH_Error("后台菜单链接地址不能为空！")
			Exit Sub
		End If
		MenuCid = Cls.Code_Int("ChannelIDs",0)
		MenuDataName = Cls.Code_Admin("MenuDataName",1,20)
		MenuSort = Cls.Code_Admin("MenuSort",1,20)
		iMenuHelp = Cls.Code_Remark("MenuHelp")
		MenuLevel = Cls.Code_Int("MenuLevel",MenuLevel)
		If MenuLevel > 10 or MenuLevel <0 Then
			Call AMH_Error("后台菜单管理权限必须是1-10！")
			Exit Sub
		End If		
		MenuOrder = 1
		SQL = "Select Top 1 MenuOrder From ["&Data_Name&"] Where ChannelIDs="&MenuCid&" Order By MenuOrder Desc"
		Set Rs = Cls.Exec(SQL,1)
		If Not(Rs.Eof) Then MenuOrder = Rs(0)+1
		Rs.Close
		SQL = "Select * From ["&Data_Name&"]"
		Call Cls.Exe_Conn(Rs,SQL,3)
		Rs.AddNew
			Rs("ChannelIDs") = MenuCid
			Rs("MenuName") = MenuName
			Rs("MenuTit") = MenuTit
			Rs("MenuUrl") = MenuUrl
			Rs("MenuHidden") = MenuHidden
			Rs("MenuDataName") = MenuDataName
			Rs("MenuSort") = MenuSort
			Rs("MenuLevel") = MenuLevel
			Rs("MenuOrder") = MenuOrder
			Rs("MenuHelp") = iMenuHelp
			Rs("MenuOpen") = True
		Rs.Update
		Rs.Close
		Call Cls.Cache_Del("amh_menu")
		Call ReloadMenu(1)
		Call AMH_Msg("成功添加一个后台" & Tit_Fir, "?", 1)
		Exit Sub
	End If
	Call Form_First()
%>
<form name=MenuFrm action='?Action=Add' method=post>
<input type=hidden name=chk value='yes'>
<tr>
<td width='20%'><%Response.Write tit_fir%>所属频道：</td>
<td width='80%'><%Response.Write Get_ChannelList(0)&Redx%>&nbsp;&nbsp;<font class=red>请选择对应的频道</font></td>
</tr>
<tr class=tr1>
<td>管理<%Response.Write tit_fir%>标题：</td>
<td><input name=MenuName type=text size=20 maxlength=20>&nbsp;&nbsp;<%Response.Write Redx%><font class=red>例：文章管理</font>&nbsp;&nbsp;<input name=MenuHidden type=checkbox value='yes'>&nbsp;&nbsp;是否隐藏后台菜单</td>
</tr>
<tr>
<td><%Response.Write tit_fir%>简称：</td>
<td><input name=MenuTit type=text size=10 maxlength=20>&nbsp;&nbsp;例：文章</td>
</tr>
<tr>
<td><%Response.Write tit_fir%>数据库名：</td>
<td><input name=MenuDataName type=text size=20 maxlength=20>&nbsp;&nbsp;可选，不填使用默认频道数据库。</td>
</tr>
<tr class=tr1>
<td><%Response.Write tit_fir%>链接：</td>
<td><input name=MenuUrl type=text size=49 maxlength=100>&nbsp;&nbsp;<%Response.Write Redx%></td>
</tr>
<tr>
<td><%Response.Write tit_fir%>标识：</td>
<td><input name=MenuSort type=text value='' size=20 maxlength=20>&nbsp;&nbsp;与管理文件里的标识相对应</td>
</tr>
<tr>
<td><%Response.Write tit_fir%>权限：</td>
<td><input name=MenuLevel type=text value='<%=Menulevel%>' size=2 maxlength=2>&nbsp;&nbsp;管理员管理此菜单所需等级(1-10)</td>
</tr>
<tr valign=top>
<td><%Response.Write tit_fir%>帮助：<br /><br /><font class=red>支持HTML格式。</font></td>
<td><%Call AMH_ReSize("MenuHelp",60,8,"",1)%></td>
</tr>
<%
	Call Submit_Add()
End Sub
'//* 编辑后台菜单 *//
Sub AsaiMHMenu_Edit()
	Dim MenuCid, MenuName, MenuUrl, MenuHidden, MenuLevel, MenuDataName, MenuTit, MenuOrder, MenuSort, iMenuHelp
	Set Rs = Cls.Exec("Select Top 1 * From ["&Data_Name&"] Where MenuID="&iMenuID,1)
	If Rs.Eof Then
		Rs.Close
		Call AMH_Msg(tit_fir&"ID（"&iMenuID&"）不存在！","?",1)
		Exit Sub
	End If
	MenuCid = Int(Rs("ChannelIDs"))
	MenuName = Rs("MenuName")
	MenuUrl = Rs("MenuUrl")
	MenuHidden = Rs("MenuHidden")
	MenuLevel = Int(Rs("MenuLevel"))
	MenuDataName = Rs("MenuDataName")
	MenuTit = Rs("MenuTit")
	MenuSort = Rs("MenuSort")
	iMenuHelp = Rs("MenuHelp")
	Rs.Close
	Call AMH_Td("编辑"&Tit_Fir&" ("&MenuName&")")
	If Chk() Then
		MenuName = Cls.Code_Admin("MenuName",1,20)
		If MenuName = "" Then
			Call AMH_Error("后台菜单标题不能为空！")
			Exit Sub
		End If
		MenuHidden = False
		If Cls.Code_Form("MenuHidden") = "yes" Then MenuHidden = True
		MenuTit = Cls.Code_Admin("MenuTit",1,20)
		If MenuTit = "" Then
			Call AMH_Error("后台菜单简称不能为空！")
			Exit Sub
		End If
		MenuUrl = Cls.Code_Admin("MenuUrl",1,100)
		If MenuUrl = "" Then
			Call AMH_Error("后台菜单链接地址不能为空！")
			Exit Sub
		End If
		MenuLevel = Cls.Code_Int("MenuLevel",100)
		If MenuLevel > 10 or MenuLevel <0 Then
			Call AMH_Error("后台菜单管理权限必须是1-10！")
			Exit Sub
		End If	
		MenuCid = Cls.Code_Int("ChannelIDs",0)
		MenuDataName = Cls.Code_Admin("MenuDataName",1,20)
		iMenuHelp = Cls.Code_Remark("MenuHelp")
		MenuSort = Cls.Code_Admin("MenuSort",1,20)
		SQL = "Select * From ["&Data_Name&"] Where MenuID="&iMenuID
		Call Cls.Exe_Conn(Rs,SQL,3)
			Rs("ChannelIDs") = MenuCid
			Rs("MenuName") = MenuName
			Rs("MenuTit") = MenuTit
			Rs("MenuUrl") = MenuUrl
			Rs("MenuHidden") = MenuHidden
			Rs("MenuDataName") = MenuDataName
			Rs("MenuSort") = MenuSort
			Rs("MenuLevel") = MenuLevel
			Rs("MenuHelp") = iMenuHelp
		Rs.Update
		Rs.Close
		Call Cls.Cache_Del("amh_menu")
		Call ReloadMenu(1)
		Call AMH_Msg("成功编辑了后台管理" & Tit_Fir, "?", 1)
		Exit Sub
	End If
	Call Form_First()
%>
<form name=MenuFrm action='?Action=Edit&MenuID=<%=iMenuID%>' method=post>
<input type=hidden name=chk value='yes'>
<tr>
<td width='20%'><%Response.Write tit_fir%>所属频道：</td>
<td width='80%'><%Response.Write Get_ChannelList(MenuCid)&Redx%>&nbsp;&nbsp;<font class=red>请选择对应的频道</font></td>
</tr>
<tr class=tr1>
<td>管理<%Response.Write tit_fir%>标题：</td>
<td><input name=MenuName type=text value='<%=MenuName%>' size=20 maxlength=20>&nbsp;&nbsp;<%Response.Write Redx%><font class=red>例：文章管理</font>&nbsp;&nbsp;<input name=MenuHidden type=checkbox value='yes'<%If MenuHidden = True Then Response.Write " checked"%>>&nbsp;&nbsp;是否隐藏后台菜单</td>
</tr>
<tr>
<td><%Response.Write tit_fir%>简称：</td>
<td><input name=MenuTit type=text value='<%=MenuTit%>' size=10 maxlength=20>&nbsp;&nbsp;例：文章</td>
</tr>
<tr>
<td><%Response.Write tit_fir%>数据库名：</td>
<td><input name=MenuDataName type=text value='<%=MenuDataName%>' size=20 maxlength=20>&nbsp;&nbsp;可选，不填使用默认频道数据库。</td>
</tr>
<tr class=tr1>
<td><%Response.Write tit_fir%>链接：</td>
<td><input name=MenuUrl type=text value='<%=MenuUrl%>' size=49 maxlength=100>&nbsp;&nbsp;<%Response.Write Redx%></td>
</tr>
<tr>
<td><%Response.Write tit_fir%>标识：</td>
<td><input name=MenuSort type=text value='<%=MenuSort%>' size=20 maxlength=20>&nbsp;&nbsp;为与管理文件里的标识相对应</td>
</tr>
<tr>
<td><%Response.Write tit_fir%>权限：</td>
<td><input name=MenuLevel type=text value='<%=MenuLevel%>' size=2 maxlength=2>&nbsp;&nbsp;管理员管理此菜单所需等级(1-10)</td>
</tr>
<tr valign=top>
<td><%Response.Write tit_fir%>帮助：<br /><br /><font class=red>支持HTML格式。</font></td>
<td><%Call AMH_ReSize("MenuHelp",60,8,Cls.Code_Word(iMenuHelp),1)%></td>
</tr>
<%
	Call Submit_Edit()
End Sub
Function Get_ChannelList(ByVal Mcid)
	Dim Mii, ChannelMenus, Tmpstr
	ChannelMenus = Cls.Channel_Menu
	For Mii = 0 To Ubound(ChannelMenus,2)
		If ChannelMenus(8,Mii) < 2 Then
			Tmpstr = Tmpstr & "<option value='"&ChannelMenus(0,Mii)&"'"
			If Int(Mcid) = Int(ChannelMenus(0,Mii)) Then Tmpstr = Tmpstr & " selected"
			Tmpstr = Tmpstr & ">"&ChannelMenus(13,Mii)&"管理</option>"
		End If
	Next
	Erase ChannelMenus
	Get_ChannelList = "<select name=ChannelIDs size=1><option value='0'"
	If Int(Mcid) = 0 Then Get_ChannelList = Get_ChannelList & " selected"
	Get_ChannelList = Get_ChannelList & ">系统管理</option>"&Tmpstr&"</select>"
End Function
Function Get_ChannelType(ByVal iCid)
	Dim Mii, ChannelMenus
	If iCid = 0 Then Get_ChannelType = "系统管理":Exit Function
	ChannelMenus = Cls.Cache_Get("web_menu")
	For Mii = 0 To Ubound(ChannelMenus,2)
		If Int(iCid) = ChannelMenus(0,Mii) Then
			Get_ChannelType = ChannelMenus(13,Mii) & "管理"
			Exit For
		End If
	Next
	Erase ChannelMenus
End Function
Sub AsaiMHMenu_Main()
	Dim VsTrue
	i = 0
%>
<tr><td class=td colspan=2><%Response.Write tit_fir%>列表</td></tr>
<tr>
<td width='20%'></td>
<td width='80%'>
  <table border=0 cellspacing=1 cellpadding=4 width='100%'>
  <tr><td width='50%'></td><td width='50%'></td></tr>
<%
	VsTrue = False
	SQL = "Select * From ["&Data_Name&"] Order By ChannelIDs,MenuOrder"
	Set Rs = Cls.Exec(SQL,1)
	Do While Not Rs.Eof
		If Int(Rs("ChannelIDs")) <> i Then
			i = i + 1
			VsTrue = False
			Response.Write vbcrlf&"  <tr><td colspan=2 height=10></td></tr>"
		End If
		If VsTrue = False Then	
			Response.Write vbcrlf&"  <tr><td colspan=2>"&img_admin("s_minus","")&"&nbsp;<b>"&Cls.Code_Html(Get_ChannelType(Int(Rs("ChannelIDs"))),1,0)&"</b></td></tr>"
			VsTrue = True
		End If
		Response.Write vbcrlf&"  <tr><td>&nbsp;&nbsp;&nbsp;&nbsp;"&img_admin("s_plus","")&"&nbsp;"&Cls.Code_Html(Rs("MenuName"),1,0)
		if Rs("MenuHidden")=True Then Response.Write " <font class=Gys>(隐藏)</font>"
		Response.Write " <font class=Gys>("&Rs("MenuLevel")&")</font></td><td><a href='?Action=Edit&MenuID="&Rs("MenuID")&"'>修改</a>&nbsp;&nbsp;" & _
		     "<a href='?Action=Up&ChannelIDs="&Rs("ChannelIDs")&"&MenuID="&Rs("MenuID")&"'>"&img_admin("up_1","向上移动此主"&tit_fir)&"</a>&nbsp;&nbsp;" & _
		     "<a href='?Action=Down&ChannelIDs="&Rs("ChannelIDs")&"&MenuID="&Rs("MenuID")&"'>"&img_admin("Down_1","向下移动此主"&tit_fir)&"</a>&nbsp;&nbsp;" & _
		     "<a href='?Action=Delete&MenuID="&Rs("MenuID")&"' onclick=""return del_menu('"&Cls.Code_Html(Rs("MenuName"),1,0)&"');"">删除</a>&nbsp;&nbsp;" & _
		     "</td></tr>"
		Rs.MoveNext
	Loop
	Rs.Close
%>
  </table>
</td>
</tr>
<script language=javascript>
<!--
function del_menu(t1)
{
  var cf=window.confirm("您确定要删除主<%Response.Write tit_fir%>（"+t1+"）吗？\n\n删除后将不可恢复！是否确定该操作？");
  if (cf)
  { return true; }
  else
  { return false; }
  return false;
}
-->
</script>
<%
End Sub
Sub AsaiMHMenu_Delete()
	Dim MenuCid, MenuName, MenuOrder
	Set Rs = Cls.Exec("Select Top 1 MenuName,MenuOrder,ChannelIDs From ["&Data_Name&"] Where MenuID="&iMenuID,1)
	If Rs.Eof Then
		Rs.Close
		Call AMH_Msg(tit_fir&"ID（"&iMenuID&"）不存在！","?",1)
		Exit Sub
	End If
	MenuName=Rs("MenuName")
	MenuOrder=Rs("MenuOrder")
	MenuCid=Rs("ChannelIDs")
	Rs.Close
    Call Cls.Exec("Delete From ["&Data_Name&"] Where MenuID="&iMenuID,0)
    Call Cls.Exec("Update ["&Data_Name&"] Set MenuOrder=MenuOrder-1 Where ChannelIDs="&MenuCid&" And MenuOrder>"&MenuOrder,0)
    Call AMH_Event("删除"&tit_fir&"（"&MenuName&"）。")
    Call Cls.Cache_Del("amh_menu")
    Call ReloadMenu(1)
    Call AMH_Msg("成功删除"&tit_fir&"（"&MenuName&"）！","?",1)
End Sub
%>
