<!--#include file="../Conn.asp"-->
<!-- #include file="inc/const.asp" -->
<%
'测试帐号
'xiaozl@vip.265.com  密码是：123456

Head()
Dim admin_flag
Dim sType
sType = Trim(Request("t"))
admin_flag=",2,"

If Trim(Request("sessionid"))<>"" Then
	Response.Cookies(Dvbbs.Forum_sn)("AdsSessionid") = Trim(Request("sessionid"))
Else
	Response.Cookies(Dvbbs.Forum_sn)("AdsSessionid") = ""
End If

CheckAdmin(admin_flag)

If Request.QueryString("act") = "save" Then
	Save_AdsSetting()
Else
	If sType="" Then
		Main()
	Else
		AdsSetting()
	End If
End If

Footer()

Sub Main()
%>

<script type="text/javascript">
  var id            = 'cndw';
  var adtourl       = 'plus_ads265.asp';
  var sessionid     = '<%=Request.Cookies(Dvbbs.Forum_sn)("AdsSessionid")%>';
</script>
<script type="text/javascript" src='http://www.lianmeng.com/hezuo/show.js'></script>
<%
End Sub


'参数项：
't：广告类型 （1=文字/2=图片/3：调用代码）；
'w：文件宽度
'h：文件高度
's：广告数据 （广告文字/图片地址/调用代码）
'n：广告商信息
'u：广告链接地址


Sub AdsSetting()
	Dim AWidth,AHeight,AStr,Aurl,AName
	Dim Showstr,TName
	Dim Rs
	Showstr = ""
	AWidth = Request("w")
	AHeight = Request("h")
	AStr =  Trim(Request("s"))
	AUrl = Trim(Request("u"))
	AName = Trim(Request("n"))
	If AWidth="" or Not Isnumeric(AWidth) Then AWidth = 0
	If AHeight="" or Not Isnumeric(AHeight) Then AHeight = 0
	Select Case sType
		Case "1"
			Showstr = AStr
			TName = "文字"
		Case "2"
			Showstr = "<a href="""&AUrl&""" alt=""""><img src="""&Server.htmlencode(AStr)&""" width="""&AWidth&""" height="""&AHeight&""" border=""0""/></a>"
			TName = "图片"
		Case Else
			Showstr = AStr &"<hr/><textarea name=""adsstr"" style=""width:98%"" rows=""10"" onblur=""getstr(this.value);"">"&Server.htmlencode(AStr)&"</textarea>"
			TName = "代码"
	End Select
	%>

<script language="JavaScript">
<!--
function getstr(val){
	var adsstrobj = document.adsform.adsstr;
	if (adsstrobj)
	{
		document.adsform.adsstr.value = val;
	}
} 
//-->
</script>
<table width="95%" border="0" cellspacing="1" cellpadding="3"  align="center" class="tableBorder">
<tr> 
<th height="23" class="tableHeaderText" colspan="2">
<b>论坛联盟广告设置</b>
</th>
</tr>
<tr>
<td class="forumHeaderBackgroundAlternate" height="26" colspan="2">
<li><b>联盟广告信息</b></li>
</td>
</tr>
<tr>
<td class="forumRowHighlight" colspan="2">
<b>广告商：</b><%=AName%>
</td>
</tr>
<tr>
<td class="forumrow" colspan="2">
<b>广告类型：</b> <%=TName%> 
<%
If sType = "2" Then
	Response.Write " ("
	Response.Write AWidth
	Response.Write " * " 
	Response.Write AHeight
	Response.Write ")"
End If
%>
<div style="width:600px; margin : 5px 20px; border : 1px solid #cccccc; padding : 5px;background : #f3f3f3; line-height : normal;">
<%=Showstr%>
</div>
</td>
</tr>
<tr>
<td class="forumHeaderBackgroundAlternate" height="26" colspan="2">
<li><b>广告投放位置</b></li>
</td>
</tr>
<form method="post" action="?act=save" name="adsform">
<tr>
<td class="forumrow" valign="top" width="40%">
<input type="checkbox" name="getskinid" value="1" <%if request("getskinid")="1" or request("boardid")="" then Response.Write "checked"%>/><a href="forumads.asp?getskinid=1">论坛默认广告</a><BR> 点击此处返回论坛默认广告设置，默认广告设置包含所有<FONT COLOR="blue">除</FONT>包含具体版面内容（如帖子列表、帖子显示、版面精华、版面发贴等）<FONT COLOR="blue">以外</FONT>的页面。
<hr size="1" color="blue"/>
版面广告保存选项(请按 CTRL 键多选)<BR/>
<select name="getboard" size="28" style="width:100%" multiple>
<%
set rs=Dvbbs.Execute("select boardid,boardtype,depth from dv_board order by rootid,orders")
do while not rs.eof
Response.Write "<option "
if rs(0) = dvbbs.boardid then
Response.Write " selected"
end if
Response.Write " value="""&rs(0)&""">"
Select Case rs(2)
	Case 0
		Response.Write "╋"
	Case 1
		Response.Write "&nbsp;&nbsp;├"
End Select
If rs(2)>1 Then
	For ii=2 To rs(2)
		Response.Write "&nbsp;&nbsp;│"
	Next
	Response.Write "&nbsp;&nbsp;├"
End If
Response.Write rs(1)
Response.Write "</option>"
rs.movenext
loop
rs.close
set rs=nothing
%>
</select>
</td>
<td class="forumRowHighlight" width="60%" valign="top">
选取广告投放的位置：<hr/>
页面顶部广告：<input type="radio" name="adsset" value="1"/><br/>
页面底部广告：<input type="radio" name="adsset" value="2"/><br/>
页面浮动广告：<input type="radio" name="adsset" value="3"/><br/>
右下固定广告：<input type="radio" name="adsset" value="4"/><br/>
帖间随机广告：<input type="radio" name="adsset" value="5"/><br/>
页面文字广告：<input type="radio" name="adsset" value="6"/><br/>
<input type="hidden" name="adsstr" value="<%=Server.htmlencode(AStr)%>"/>
<input type="hidden" name="adsurl" value="<%=Server.htmlencode(AUrl)%>"/>
<input type="hidden" name="awidth" value="<%=AWidth%>"/>
<input type="hidden" name="aheight" value="<%=AHeight%>"/>
<input type="hidden" name="sType" value="<%=sType%>"/>
</td>
</tr>
<tr>
<td class="forumRowHighlight" colspan="2">
<input type="submit" name="submit" value="保存设置"> <input type="submit" name="gobake"  value="返回" onclick="javascript:history.go(-1);">
</td>
</tr>
</form>
</table>
<%

End Sub

Sub Save_AdsSetting()
	Dim iSetting,i,Forum_ads
	Dim adsset,adsstr,adsurl
	Dim Sql
	sType = Request.Form("sType")
	adsset = Request.Form("adsset")
	adsstr = Replace(Trim(Request.Form("adsstr")),"$","")
	adsurl = Replace(Trim(Request.Form("adsurl")),"$","")
	If adsset = ""  Then
		Errmsg=ErrMsg + "<BR/>请选取广告的投放位置！"
		dvbbs_error()
		Exit Sub
	End If
	If sType = "2" then
		adsstr = "<a href="""&adsurl&""" alt="""" target=""_blank""><img src="""&Server.htmlencode(adsstr)&""" width="""&Request.Form("awidth")&""" height="""&Request.Form("aheight")&""" border=""0""/></a>"
	End If
	If sType = "1" and (adsset="3" or adsset="4") Then
		Errmsg=ErrMsg + "<BR/>文字广告类型，不能设置在浮动或右下固定广告位！"
		dvbbs_error()
		Exit Sub
	End If
	'If sType = "3" and Not (adsset="1" or adsset="2") Then
		'Errmsg=ErrMsg + "<BR/>广告代码类型，只能设置在顶部或底部广告位！"
		'dvbbs_error()
		'Exit Sub
	'End If

	'Response.Write Forum_ads
	If Request("getskinid")="1" Then
		For i = 0 To 30
			iSetting = Trim(Dvbbs.Forum_ads(i))
			If (i = 2 or i = 7 or i = 13 or i=12 or i=15 or i = 17) and Dvbbs.Forum_ads(i)="" Then iSetting = 0

			If adsset = "1" and i=0 Then	'顶部
				iSetting = adsstr
			End If
			If adsset = "2" and i=1 Then	'底部
				iSetting = adsstr
			End If
			If adsset = "3" Then	'浮动广告
				If i = 2 Then
					iSetting = 1	'开启首页浮动广告
				End If
				If i = 3 Then
					iSetting = adsstr
				End If
				If i = 4 Then
					iSetting = adsurl
				End If
				If i = 5 Then
					iSetting = Request.Form("awidth")
				End If
				If i = 6 Then
					iSetting = Request.Form("aheight")
				End If
			End If
			If adsset = "4" Then	'右下固定广告
				If i = 13 Then
					iSetting = 1	'开启右下固定广告
				End If
				If i = 8 Then
					iSetting = adsstr
				End If
				If i = 9 Then
					iSetting = adsurl
				End If
				If i = 10 Then
					iSetting = Request.Form("awidth")
				End If
				If i = 11 Then
					iSetting = Request.Form("aheight")
				End If
			End If
			If adsset = "5" Then	'帖间随机广告
				If i = 7 Then
					iSetting = 1	'开启帖间随机广告
				End If
				If i = 14 Then
					If iSetting<>"" and iSetting<>"0" Then
						iSetting = iSetting & Chr(10) & adsstr
					Else
						iSetting = adsstr
					End If
				End If
			End If
			If adsset = "6" Then	'页面文字广告
				If i=12 Then
					iSetting = 1
				End If
				If i = 17 Then
					If iSetting = "0" Then
						iSetting = 1
					End If
				End If
				If i = 16 then
					If iSetting<>"" and iSetting<>"0" Then
						iSetting = iSetting & Chr(10) & adsstr
					Else
						iSetting = adsstr
					End If
				End If
			End If

			If i = 0 Then
				Forum_ads = iSetting
			Else
				Forum_ads = Forum_ads & "$" & iSetting
			End If
		Next
		Sql = "Update Dv_Setup Set Forum_ads='"&Replace(Forum_ads,"'","''")&"'"
		Dvbbs.Execute(sql)
	End If
	If Request("getboard")<>"" Then
		'查获更新版面数据，只更新设置投放广告项，避免清空原广告其他设置
		Dim Rs
		Set Rs = Dvbbs.Execute("select Boardid,Board_Ads from Dv_board where boardid in ("&Request("getboard")&")")
		do while not rs.eof
		Dvbbs.Forum_ads = Split(Rs(1),"$")
		For i = 0 To 30
			iSetting = Trim(Dvbbs.Forum_ads(i))
			If (i = 2 or i = 7 or i = 13 or i=12 or i=15 or i = 17) and Dvbbs.Forum_ads(i)="" Then iSetting = 0

			If adsset = "1" and i=0 Then	'顶部
				iSetting = adsstr
			End If
			If adsset = "2" and i=1 Then	'底部
				iSetting = adsstr
			End If
			If adsset = "3" Then	'浮动广告
				If i = 2 Then
					iSetting = 1	'开启首页浮动广告
				End If
				If i = 3 Then
					iSetting = adsstr
				End If
				If i = 4 Then
					iSetting = adsurl
				End If
				If i = 5 Then
					iSetting = Request.Form("awidth")
				End If
				If i = 6 Then
					iSetting = Request.Form("aheight")
				End If
			End If
			If adsset = "4" Then	'右下固定广告
				If i = 13 Then
					iSetting = 1	'开启右下固定广告
				End If
				If i = 8 Then
					iSetting = adsstr
				End If
				If i = 9 Then
					iSetting = adsurl
				End If
				If i = 10 Then
					iSetting = Request.Form("awidth")
				End If
				If i = 11 Then
					iSetting = Request.Form("aheight")
				End If
			End If
			If adsset = "5" Then	'帖间随机广告
				If i = 7 Then
					iSetting = 1	'开启帖间随机广告
				End If
				If i = 14 Then
					If iSetting<>"" and iSetting<>"0" Then
						iSetting = iSetting & Chr(10) & adsstr
					Else
						iSetting = adsstr
					End If
				End If
			End If
			If adsset = "6" Then	'页面文字广告
				If i=12 Then
					iSetting = 1
				End If
				If i = 17 Then
					If iSetting = "0" Then
						iSetting = 1
					End If
				End If
				If i = 16 then
					If iSetting<>"" and iSetting<>"0" Then
						iSetting = iSetting & Chr(10) & adsstr
					Else
						iSetting = adsstr
					End If
				End If
			End If

			If i = 0 Then
				Forum_ads = iSetting
			Else
				Forum_ads = Forum_ads & "$" & iSetting
			End If
		Next
			Sql = "Update Dv_Board Set Board_Ads='"&Replace(Forum_ads,"'","''")&"' Where BoardID ="&Rs(0)
			Dvbbs.Execute(Sql)
		Rs.movenext
		Loop
		Rs.close
		Set Rs = Nothing
	End If

	RestoreBoardCache()
	Dvbbs.loadSetup()
	Dv_suc("广告设置成功！")
End Sub

Sub RestoreBoardCache()
	Dim Board,node
	Dvbbs. LoadBoardList()
	For Each node in Application(Dvbbs.CacheName &"_style").documentElement.selectNodes("style/@id")
		Application.Contents.Remove(Dvbbs.CacheName & "_showtextads_"&node.text)
		For Each board in Application(Dvbbs.CacheName&"_boardlist").documentElement.selectNodes("board/@boardid")
			Dvbbs.LoadBoardData board.text
			Application.Contents.Remove(dvbbs.CacheName & "_Text_ad_"& board.text &"_"&node.text)
			Application.Contents.Remove(dvbbs.CacheName & "_Text_ad_"& board.text &"_"&node.text&"_-time")
		Next
		Application.Contents.Remove(dvbbs.CacheName & "_Text_ad_0_"& node.text)
		Application.Contents.Remove(dvbbs.CacheName & "_Text_ad_0_"& node.text&"_-time")
	Next
End Sub
%>