<!-- #include file=../../inc/BBSsetup.asp -->
<!-- #include file=../../inc/Board_Popfun.asp -->
<!-- #include file=../inc/bbsmanage_Fun.asp -->
<%
DEF_BBS_HomeUrl = "../../"
initDatabase
GBL_CHK_TempStr = ""
checkSupervisorPass

Dim Action
Action = Left(Request("Action"),14)
If Action <> "Join" and Action <> "Modify" and Action <> "Delete" Then
	Action = "Manage"
End If

Dim LMT_OrderID,LMT_BoardID,LMT_AssortName,LMT_GoodNum
LMT_OrderID = 0
LMT_BoardID = 0
LMT_GoodNum = 0

Dim LMT_ID

SiteHead(DEF_SiteNameString & " - 管理员")

UserTopicTopInfo
DisplayUserNavigate("论坛版面专区管理")%>
<p><a href=ForumBoardAssort.asp>管理版面专区</a>
<a href=ForumBoardAssort.asp?action=Join>添加版面专区</a>
<br><br><%If GBL_CHK_Flag=1 Then
	Select Case Action:
		Case "Join": Join
		Case "Modify": Join
		Case "Delete": Delete
		Case "Manage": Manage
	End Select
Else%>
	<table width=96%>
	<tr>
	<td>
	<%
	If Request("submitflag")="" Then
		Response.Write "<br><b>请先登录</b>"
	Else
		Response.Write "<br><p align=left><font color=ff0000 class=RedFont><b>" & GBL_CHK_TempStr & "</b></font>"
	End If
	DisplayLoginForm
	Response.Write "</p>"%>
	</td>
	</tr>
	</table>
<%End If
UserTopicBottomInfo
closeDataBase
SiteBottom
If GBL_ShowBottomSure = 1 Then Response.Write GBL_SiteBottomString

Function Join

	If Action = "Modify" Then
		LMT_ID = Left(Trim(Request("ID")),14)
		If isNumeric(LMT_ID) = 0 Then LMT_ID = 0
		LMT_ID = Fix(cCur(LMT_ID))
		If LMT_ID = 0 or CheckParentAssortIDExist(LMT_ID) = 0 Then
			Response.Write "<br><b>编辑的专区不存在!<br>" & VbCrLf
			Exit Function
		End If
	End If
	%>
	<b><%
	If Action = "Modify" Then
		Response.Write "编辑"
	Else
		Response.Write "添加"
	End If%>版面专区</b>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
	<td>
		<table width="100%" border="0" cellspacing="0" cellpadding="1" bgcolor="<%=DEF_BBS_LightColor%>" class=TBBG1 align=right>
		<tr>
			<td>
				<table width="100%" border="0" cellspacing="1" cellpadding="15">
				<tr bgcolor="<%=DEF_BBS_LightestColor%>" class=TBBG9>
					<td><%
						GBL_CHK_TempStr = ""
						If Request.Form("submitflag")="LKOkxk2" Then
							If CheckFormData=0 Then
								Response.Write "<font color=ff0000 class=RedFont><b>错误信息：" & GBL_CHK_TempStr & "</b></font><br>" & VbCrLf
								DisplayJoinForm
			          		Else
								If UpdateAssort = 0 Then
									Response.Write "<font color=ff0000 class=RedFont><b>插入出错：" & GBL_CHK_TempStr & "</b></font><br>" & VbCrLf
									DisplayJoinForm
								Else
									Response.Write "<font color=008800 class=GreenFont><b>成功操作!</b></font><br>" & VbCrLf
								End If
							End If
						Else
							DisplayJoinForm
						End If%>
					</td>
				</tr>
				</table>
			</td>
		</tr>
		</table>
	</td>
</tr>
</table>
<%

End Function

Function DisplayJoinForm

	If Action = "Modify" Then
		DisplayModifyForm
		Exit Function
	End If%>
	<form action=ForumBoardAssort.asp method=post name=form1 id=form1>
	<table>
	<tr valign=top>
		<td width=80>
			<input name=action type=hidden value="Join">
			<input name=submitflag type=hidden value="LKOkxk2">
			排列序号：</td>
		<td align=left><input name=Form_AssortID size=4 maxlength=4 value="<%=htmlencode(LMT_OrderID)%>" class=fminpt>
			显示在版面分类中的前后顺序，数字越小越靠前</td>
	</tr>
	<tr valign=top>
		<td width=80>
			所属版面:</td>
		<td>
			<!-- #include file=../../inc/incHTM/BoardForMoveList.asp -->
		<script>
			var provincebox = document.form1.BoardID2.options,i;
			for(i = 0; i < provincebox.length; i++)
			{
				if(provincebox.options[i].value=="<%=LMT_BoardID%>")
				{provincebox.selectedIndex = i;break;}
			}
		</script>
		</td>
	</tr>
	<tr valign=top>
		<td width=80>
			专区名称：</td>
		<td align=left><input name=LMT_AssortName size=40 maxlength=255 value="<%=htmlencode(LMT_AssortName)%>" class=fminpt>
			<br>允许使用HTML，最长255字</td>
	</tr>
	<tr>
		<td colspan=2>
			<input name=LMT_GoodNum type=hidden value="0">
			<input type=submit value="提交" class=fmbtn> <input type=reset value="取消" class=fmbtn>
		</td>
	</tr>
	</table></form>

<%End Function

Function DisplayModifyForm

	%>
	<form action=ForumBoardAssort.asp method=post name=form1 id=form1>
	<table>
	<tr valign=top>
		<td width=80>
			<input name=action type=hidden value="Modify">
			<input name=submitflag type=hidden value="LKOkxk2">
			<input name=ID type=hidden value="<%=LMT_ID%>">
			排列序号：</td>
		<td align=left><input name=LMT_OrderID size=4 maxlength=4 value="<%=htmlencode(LMT_OrderID)%>" class=fminpt>
			显示在版面分类中的前后顺序，数字越小越靠前</td>
	</tr>
	<tr valign=top>
		<td width=80>
			专区名称：</td>
		<td align=left><input name=LMT_AssortName size=40 maxlength=255 value="<%=htmlencode(LMT_AssortName)%>" class=fminpt>
			<br>允许使用HTML，最长255字</td>
	</tr>
	<tr valign=top>
		<td width=80>
			重新统计：</td>
		<td align=left><input name=LMT_GoodNum type=checkbox value="yes" class=fmchkbox checked>重新统计此专区所拥有的帖子数量</td>
	</tr>
	<tr>
		<td colspan=2>
			<input type=submit value="提交" class=fmbtn> <input type=reset value="取消" class=fmbtn>
		</td>
	</tr>
	</table></form>

<%End Function

Function CheckFormData

	Dim Temp

	LMT_OrderID = Left(Trim(Request.Form("LMT_OrderID")),14)
	If Action = "Join" Then LMT_BoardID = Left(Trim(Request.Form("BoardID2")),14)
	LMT_AssortName = Trim(Request.Form("LMT_AssortName"))

	If isNumeric(LMT_OrderID) = 0 Then LMT_OrderID = 0
	LMT_OrderID = Fix(cCur(LMT_OrderID))
	If LMT_OrderID < 0 Then LMT_OrderID = 0

	If isNumeric(LMT_BoardID) = 0 or LMT_BoardID = "" Then
		GBL_CHK_TempStr = "请选择正确的所属版面。<br>" & VbCrLf
		CheckFormData = 0
		Exit Function
	End If
	
	LMT_BoardID = Fix(cCur(LMT_BoardID))
	Temp = Application(DEF_MasterCookies & "BoardInfo" & LMT_BoardID)
	If isArray(Temp) = False Then
		ReloadBoardInfo(LMT_BoardID)
		Temp = Application(DEF_MasterCookies & "BoardInfo" & LMT_BoardID)
	End If

	If isArray(Temp) = False Then
		GBL_CHK_TempStr = "所属版面不存在，请确定是否已经正确选择!<br>" & VbCrLf
		CheckFormData = 0
	End If

	If Len(LMT_AssortName) > 255 or LMT_AssortName = "" Then
		GBL_CHK_TempStr = "必须填写专区名字并且不能长于255字。<br>" & VbCrLf
		CheckFormData = 0
		Exit Function
	End If

	If inStr(LCase(LMT_AssortName),"""") > 0 or inStr(LCase(LMT_AssortName),"<script") > 0 or inStr(LCase(LMT_AssortName),"<\script") > 0 or inStr(LCase(LMT_AssortName),"</script") > 0 Then
		GBL_CHK_TempStr = GBL_CHK_TempStr & "Error: 专区名字不允许插入js等其它编码，不允许使用双引号<br>" & VbCrLf
		CheckFormForumBoardData = 0
		Exit Function
	End If		

	CheckFormData = 1

End Function

Function UpdateAssort

	If Action = "Join" Then
		LMT_GoodNum = 0
		Con.ExeCute("inSert into LeadBBS_GoodAssort(OrderID,BoardID,AssortName,GoodNum) Values(" & _
				LMT_OrderID & "," & LMT_BoardID & ",'" & Replace(LMT_AssortName,"'","''") & "'," & LMT_GoodNum & ")")
		ReloadTopicAssort(LMT_BoardID)
	Else
		If Request.Form("LMT_GoodNum") <> "" Then
			Dim Rs
			Set Rs = Con.ExeCute("Select count(*) from LeadBBS_Topic where GoodAssort=" & LMT_ID)
			If Rs.Eof Then
				LMT_GoodNum = 0
			Else
				LMT_GoodNum = Rs(0)
				If isNull(LMT_GoodNum) Then LMT_GoodNum = 0
				LMT_GoodNum = cCur(LMT_GoodNum)
			End If
			Rs.Close
			Set Rs = Nothing
		End If
		Con.ExeCute("Update LeadBBS_GoodAssort Set OrderID=" & LMT_OrderID & _
			",AssortName='" & Replace(LMT_AssortName,"'","''") & "'" & _
			",GoodNum=" & LMT_GoodNum & _
			" where ID=" & LMT_ID)
		ReloadTopicAssort(LMT_BoardID)
	End If
	UpdateAssort = 1

End Function

Rem 检测专区编号ID是否存在
Function CheckParentAssortIDExist(ID)

	Dim Rs
	If ID = 0 Then
		CheckParentAssortIDExist = 1
		Exit Function
	End If
	Set Rs = Con.ExeCute("Select top 1 ID,OrderID,BoardID,AssortName,GoodNum from LeadBBS_GoodAssort where ID=" & ID)
	If Rs.Eof Then
		CheckParentAssortIDExist = 0
	Else
		LMT_OrderID = cCur(Rs("OrderID"))
		LMT_BoardID = cCur(Rs("BoardID"))
		LMT_AssortName = Rs("AssortName")
		LMT_GoodNum = cCur(Rs("GoodNum"))
		CheckParentAssortIDExist = 1
	End if
	Rs.Close
	Set Rs = Nothing

End Function

Function Manage

	%>
	<script language=javascript>
	var lastID=0,Count=0,oldBoardID;
	function s(ID,OrderID,BoardID,AssortName,GoodNum,BoardName)
	{
		if(ID=="")return;
		if(oldBoardID != BoardID)
		{
			oldBoardID = BoardID;
			document.write("<tr class=TBBG9 bgcolor=<%=DEF_BBS_LightestColor%>><td colspan=5><b>版面：<a href=<%=DEF_BBS_HomeUrl%>Board/Board.asp?BoardID=" + BoardID + ">" + BoardName + "</a></td></tr>")
		}
		lastID=ID;
		document.write("<tr class=TBBG9 bgcolor=<%=DEF_BBS_LightestColor%> valign=top><td>" + ID + "</td>");
		document.write("<td><a href=ForumBoardAssort.asp?action=Modify&ID=" + ID + ">" + AssortName + "</a></td>");
		document.write("<td>" + GoodNum + "</td><td><a href=<%=DEF_BBS_HomeUrl%>Board/Board.asp?BoardID=" + BoardID + ">" + BoardName + "</a></td>");
		document.write("<td><a href=ForumBoardAssort.asp?action=Delete&ID=" + ID + ">删除</a></td></tr>");
	}
	</script>
	<table border="0" cellspacing="0" cellpadding="0" align=center width=100%>
	<tr>
		<td><br>
			<p align=center><b>版面专区管理</b><br><br></p>
			<table width=100% border="0" cellspacing="1" cellpadding="4" bgcolor="<%=DEF_BBS_LightColor%>" class=TBBG1>
			<tbody>
			<tr height="19" class=TBfour>
				<td width=30><img src=../images/null.gif width=2 height=1><br>编号</td>
				<td><img src=../images/null.gif width=2 height=1><br>专区名称(修改)</td>
				<td><img src=../images/null.gif width=2 height=1><br>帖子量</td>
				<td><img src=../images/null.gif width=2 height=1><br>所属版面</td>
				<td><img src=../images/null.gif width=2 height=1><br>删除</td>
			</tr>
				<%
	Dim Rs,SQL
	SQL = "select T1.ID,T1.OrderID,T1.BoardID,T1.AssortName,T1.GoodNum,T2.BoardName from LeadBBS_GoodAssort as T1 left join LeadBBS_Boards as T2 on T1.BoardID=T2.BoardID Order by T1.BoardID,T1.OrderID"

	OpenDatabase
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	Dim Num
	Dim GetData
	If Not rs.Eof Then
		Response.Write "<script language=javascript>" & VbCrLf & "s("""
		Response.Write Rs.GetString(,,""",""",""");" & VbCrLf & "s(""","")
		%>","","","");
		</script>
		<%
	Else
		Num = -1
	End If
	Rs.close
	Set Rs = Nothing
	closeDataBase%>
			</table>
		</td>
	</tr>
	</table>
	<%

End Function

Function Delete

	Dim ID
	ID = Left(Request("ID"),14)
	If isNumeric(ID) = 0 Then ID = 0
	ID = Fix(cCur(ID))
	If Request.Form("DeleteSuer")="E72ksiOkw2" Then
		If DeleteTopicAssort(ID) > 0 Then
			Response.Write "<p><font color=008800 class=GreenFont><b>已经成功删除编号为" & ID & "的版面专区！</b></font></p>"
		Else
			Response.Write "<p><font color=ff0000 class=RedFont><b>" & GBL_CHK_TempStr & "</b></font></p>"
		End If
	Else
		%><p><form action=ForumBoardAssort.asp method=post>
		注意：删除版面专区并不删除一切专区下的帖子信息<br>
		<br><b><font color=ff0000 class=RedFont>确认信息： 真的要删除此专区吗？<br><br>
		
		<input type=hidden name=Action value="Delete">
		<input type=hidden name=ID value="<%=urlencode(ID)%>">
		<input type=hidden name=DeleteSuer value="E72ksiOkw2">
			
		<input type=button value=不能删啊 onclick="javascript:history.go(-1);" class=fmbtn>
		<input type=submit value=当然删除 class=fmbtn>
		</form>
	<%End If

End Function

Function DeleteTopicAssort(ID)

	GBL_CHK_TempStr = ""
	Dim Rs,BoardID
	Set Rs = Con.ExeCute("select top 1 ID,AssortName,BoardID from LeadBBS_GoodAssort where ID=" & ID)
	If Rs.Eof Then
		GBL_CHK_TempStr = "错误，不存在此专题区．"
		DeleteTopicAssort = 0
		Rs.Close
		Set Rs = Nothing
		Exit Function
	Else
		BoardID = cCur(Rs(2))
	End If
	Rs.Close
	Set Rs = Nothing
	Con.ExeCute("Update LeadBBS_Announce Set GoodAssort=0 where GoodAssort=" & ID)
	Con.ExeCute("Update LeadBBS_Topic Set GoodAssort=0 where GoodAssort=" & ID)
	Con.ExeCute("Delete from LeadBBS_GoodAssort where ID=" & ID)
	ReloadTopicAssort(BoardID)
	DeleteTopicAssort = 1

End Function

Sub ReloadTopicAssort(BoardID)

	Dim Rs
	Set Rs = Con.ExeCute("select ID,AssortName,0,0,0 from LeadBBS_GoodAssort where BoardID=" & BoardID & " Order by BoardID,OrderID ASC")
	If Not Rs.Eof Then
		Application.Lock
		Application(DEF_MasterCookies & "BoardInfo" & BoardID & "_TI") = Rs.GetRows(-1)
		Application.UnLock
	Else
		Application.Lock
		Set Application(DEF_MasterCookies & "BoardInfo" & BoardID & "_TI") = Nothing
		Application(DEF_MasterCookies & "BoardInfo" & BoardID & "_TI") = "yes"
		Application.UnLock
	End If
	Rs.Close
	Set Rs = Nothing

End Sub%>