<!--#include file="../../connshop.asp"-->
<!--#include file="../config.Inc"-->
<!--#include file="../Lebi_db_cls.asp"-->
<!--#include file="../Lebi_cache_cls.asp"-->
<!--#include file="../Lebi_cache.asp"-->
<!--#include file="../Lebi_LangInfo.asp"-->
<!--#include file="../Lebi_main.asp"-->
<!--#include file="../Lebi_function.asp"-->
<!--#include file="../Lebi_Word.asp"-->
<%
'**************************************
'* 最后更新 2012-06-30 by 56770.Kingdge
'* Copyright www.56770.com
'**************************************
connopen()
Select Case request("do")
       Case "redirect" redirect()
	   Case Else
	        main()
End Select

Sub redirect()
		Dim id
		id = Safereplace(request("Id"))
		Set rs = server.CreateObject("adodb.recordset")
		rs.open "select a_url,a_hits from [Lebi_ad] where a_tag = '"& id &"'",conn,1,3
		If Not rs.eof Then
				rs("a_hits") = rs("a_hits")+1
				rs.update()
				If rs("a_url") = "" Or rs("a_url") = "#" Then
						response.redirect Eshop_url
				Else
						response.redirect rs("a_url")
				End If
				response.End
		End If
		rs.close : Set rs = Nothing
End Sub

Sub main()
		Dim Adway,Adtype_Flash,Adtype_Pic,Adtype_Text,Sort_id,web_ad,App_web_ad,sql,Id,AdId
		Adway = request("Adway")
		If Not IsNumeric(Adway) Or IsEmpty(Adway) Then Adway = 0
		Adtype_Flash = request("Adtype_Flash")
		If Not IsNumeric(Adtype_Flash) Or IsEmpty(Adtype_Flash) Then Adtype_Flash = 0
		Adtype_Pic = request("Adtype_Pic")
		If Not IsNumeric(Adtype_Pic) Or IsEmpty(Adtype_Pic) Then Adtype_Pic = 0
		Adtype_Text = request("Adtype_Text")
		If Not IsNumeric(Adtype_Text) Or IsEmpty(Adtype_Text) Then Adtype_Text = 0
		Sort_id = request("Sort_id")
		If Not IsNumeric(Sort_id) Or IsEmpty(Sort_id) Then Sort_id = 0
		Id = Safereplace(request("Id"))
		If Id = "" Then
				cache.name="SiteRandAdv"&Adway&Adtype_Flash&Adtype_Pic&Adtype_Text&Sort_id
				cache.reloadtime= 5000
				If cache.objisempty() Then
						sql = "select a_id,a_info,a_pic,a_size,a_url,a_fontcolor,a_type,a_date,a_days,a_tag from [Lebi_ad] where a_state = 1"
						If Adtype_Flash = 1 Or Adtype_Pic = 1 Or Adtype_Text = 1 Then
							sql = sql &" and (1=1"
							If Adtype_Flash = 1 Then sql = sql &" or a_type = 0"
							If Adtype_Pic = 1 Then sql = sql &" or a_type = 1"
							If Adtype_Text = 1 Then sql = sql &" or a_type = 2"
							sql = sql &")"
						End If
						If IsSqlDataBase ="1" Then sql = sql &" and (a_days = 0 or datediff(d,a_date,getdate())<= a_days)"
						If IsSqlDataBase ="0" Then sql = sql &" and (a_days = 0 or datediff('d',a_date,now())<= a_days)"
						If Adway = 0 And IsSqlDataBase ="1" Then sql = sql &" and charindex('a',a_category)>0"
						If Adway = 0 And IsSqlDataBase ="0" Then sql = sql &" and instr(a_category,'a')>0"
						If Adway = 1 And Sort_id <> 0 And IsSqlDataBase ="1" Then sql = sql &" and charindex('"& sort_id &"',a_category)>0"
						If Adway = 1 And Sort_id <> 0 And IsSqlDataBase ="0" Then sql = sql &" and instr(a_category,'"& sort_id &"')>0"
						If Adway = 2 And IsSqlDataBase ="1" Then sql = sql &" and charindex('b',a_category)>0"
						If Adway = 2 And IsSqlDataBase ="0" Then sql = sql &" and instr(a_category,'b')>0"
						Set rs = conn.execute(sql)
						If rs.eof Then
								cache.value = ""
								cache.DataCount = 0
						Else
								cache.value = rs.getrows
								cache.DataCount = 1
						End If
						rs.close : Set rs = Nothing
				End If
				App_web_ad = cache.value
				If cache.DataCount = 1 Then
						web_ad = "ads = new Array();"&vbcrlf
						For ad_i = 0 To UBound(App_web_ad,2)
								If App_web_ad(6,ad_i) = 0 Then
										a_size = App_web_ad(3,ad_i)
										If InStr(a_size,"|")>0 Then
												a_width = Split(a_size,"|")(0)
												a_height = Split(a_size,"|")(1)
										Else
												a_width = 0
												a_height = 0
										End If
										AdId = Replace(Replace(App_web_ad(9,ad_i),"-",""),"_","")
										Response.Write("function AdClick"& AdId &"(){window.open("""& Eshop_url &"Include/Lebi_Html/SiteRandAdv.asp?do=redirect&id="& Id &""");}")&vbcrlf
										web_ad = web_ad &"ads["& ad_i &"]=""<button style=\""width:"& a_width &"px;height:"& a_height &"px;background:transparent;border:0;padding:0;cursor:pointer;\"" onclick=\""AdClick"& AdId &"()\""><object classid=\""clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"" codebase=\""http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\"" width=\"""& a_width &"\"" height=\"""& a_height &"\""><param name=\""movie\"" value=\"""& Eshop_url & Trim(App_web_ad(2,ad_i)) &"\""><param name=\""quality\"" value=\""high\""><param name=\""wmode\"" value=\""transparent\""><embed src=\"""& Eshop_url & Trim(App_web_ad(2,ad_i)) &"\"" quality=\""high\"" pluginspage=\""http://www.macromedia.com/go/getflashplayer\"" type=\""application/x-shockwave-flash\"" width=\"""& a_width &"\"" height=\"""& a_height &"\""></embed></object></button>"";"&vbcrlf
								End If
								If App_web_ad(6,ad_i) = 1 Then
										a_size = App_web_ad(3,ad_i)
										If InStr(a_size,"|")>0 Then
												a_width = Split(a_size,"|")(0)
												a_height = Split(a_size,"|")(1)
										Else
												a_width = 0
												a_height = 0
										End If
										If Trim(App_web_ad(4,ad_i))<>"" then
												web_ad = web_ad &"ads["& ad_i &"]=""<a href=\"""& Eshop_url &"Include/Lebi_Html/SiteRandAdv.asp?do=redirect&id="& App_web_ad(9,ad_i) &"\"" target=\""_blank\""><img src=\"""& Eshop_url & trim(App_web_ad(2,ad_i)) &"\"" border=\""0\"""
												If a_width <> "0" Then web_ad = web_ad &" width=\"""& a_width &"\"""
												If a_height <> "0" Then web_ad = web_ad &" height=\"""& a_height &"\"""
												web_ad = web_ad &" alt=\"""& App_web_ad(1,ad_i) &"\""></a>"";"&vbcrlf
										Else
												web_ad = web_ad &"ads["& ad_i &"]=""<img src=\"""& Eshop_url & trim(App_web_ad(2,ad_i)) &"\"" width=\"""& a_width &"\"" height=\"""& a_height &"\"" alt=\"""& App_web_ad(1,ad_i) &"\"">"";"&vbcrlf
										End If
								End If
								If App_web_ad(6,ad_i) = 2 Then
										If Trim(App_web_ad(4,ad_i))<>"" then
												web_ad = web_ad &"ads["& ad_i &"]=""<a href=\"""& Eshop_url &"Include/Lebi_Html/SiteRandAdv.asp?do=redirect&id="& App_web_ad(9,ad_i) &"\"" target=\""_blank\""><font color=\"""& App_web_ad(5,ad_i) &"\"">"& App_web_ad(1,ad_i) &"</font></a>"";"&vbcrlf
										Else
												web_ad = web_ad &"ads["& ad_i &"]=""<font color=\"""& App_web_ad(5,ad_i) &"\"">"& App_web_ad(1,ad_i) &"</font>"";"&vbcrlf
										End If
								End If
						Next
						response.write web_ad
						Response.write"index = Math.floor(Math.random() * ads.length);"&vbcrlf
						Response.write"document.write(ads[index]);"&vbcrlf
				End If
		Else
				cache.name="SiteRandAdv"&Id
				cache.reloadtime= 5000
				If cache.objisempty() Then
						sql = "select a_id,a_info,a_pic,a_size,a_url,a_fontcolor,a_type,a_date,a_days,a_state from [Lebi_ad] where a_tag = '"& Id &"'"
						If IsSqlDataBase ="1" Then sql = sql &" and (a_days = 0 or datediff(d,a_date,getdate())<= a_days)"
						If IsSqlDataBase ="0" Then sql = sql &" and (a_days = 0 or datediff('d',a_date,now())<= a_days)"
						Set rs = conn.execute(sql)
						If rs.eof Then
								cache.value = ""
								cache.DataCount = 0
						Else
								cache.value = rs.getstring(,1,"<>||<>","","")
								cache.DataCount = 1
						End If
						rs.close : Set rs = Nothing
				End If
				App_web_ad = cache.value
				If cache.DataCount = 1 Then
						If Split(App_web_ad,"<>||<>")(9) = 1 Then
								If Split(App_web_ad,"<>||<>")(6) = 0 Then
										a_size = Split(App_web_ad,"<>||<>")(3)
										If InStr(a_size,"|")>0 Then
												a_width = Split(a_size,"|")(0)
												a_height = Split(a_size,"|")(1)
										Else
												a_width = 0
												a_height = 0
										End If
										AdId = Replace(Replace(Id,"-",""),"_","")
										Response.Write("function AdClick"& AdId &"(){window.open("""& Eshop_url &"Include/Lebi_Html/SiteRandAdv.asp?do=redirect&id="& Id &""");}")&vbcrlf
										Response.Write("document.write('<button style=""width:"& a_width &"px;height:"& a_height &"px;background:transparent;border:0;padding:0;cursor:pointer;"" onclick=""AdClick"& AdId &"()""><object classid=""clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"" codebase=""http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"" width="""& a_width &""" height="""& a_height &"""><param name=""movie"" value="""& Eshop_url & Trim(Split(App_web_ad,"<>||<>")(2)) &"""><param name=""quality"" value=""high""><param name=""wmode"" value=""transparent""><embed src="""& Eshop_url & Trim(Split(App_web_ad,"<>||<>")(2)) &""" quality=""high"" pluginspage=""http://www.macromedia.com/go/getflashplayer"" type=""application/x-shockwave-flash"" width="""& a_width &""" height="""& a_height &"""></embed></object></button>');")
								End If
								If Split(App_web_ad,"<>||<>")(6) = 1 Then
										a_size = Split(App_web_ad,"<>||<>")(3)
										If InStr(a_size,"|")>0 Then
												a_width = Split(a_size,"|")(0)
												a_height = Split(a_size,"|")(1)
										Else
												a_width = 0
												a_height = 0
										End If
										If Trim(Split(App_web_ad,"<>||<>")(4))<>"" then
												Response.Write("document.write('<a href="""& Eshop_url &"Include/Lebi_Html/SiteRandAdv.asp?do=redirect&id="& Id &""" target=""_blank""><img src="""& Eshop_url & trim(Split(App_web_ad,"<>||<>")(2)) &""" border=""0""")
												If a_width <> "0" Then Response.Write(" width="""& a_width &"""")
												If a_height <> "0" Then Response.Write(" height="""& a_height &"""")
												Response.Write(" alt="""& Split(App_web_ad,"<>||<>")(1) &"""></a>');")
										Else
												Response.Write("document.write('<img src="""& Eshop_url & trim(Split(App_web_ad,"<>||<>")(2)) &"""")
												If a_width <> "0" Then Response.Write(" width="""& a_width &"""")
												If a_height <> "0" Then Response.Write(" height="""& a_height &"""")
												Response.Write(" alt="""& Split(App_web_ad,"<>||<>")(1) &""">');")
										End If
								End If
								If Split(App_web_ad,"<>||<>")(6) = 2 Then
										If Trim(Split(App_web_ad,"<>||<>")(4))<>"" then
												Response.Write("document.write('<a href="""& Eshop_url &"Include/Lebi_Html/SiteRandAdv.asp?do=redirect&id="& Id &""" target=""_blank""><font color="""& Split(App_web_ad,"<>||<>")(5) &""">"& Split(App_web_ad,"<>||<>")(1) &"</font></a>');")
										Else
												Response.Write("document.write('<font color="""& Split(App_web_ad,"<>||<>")(5) &""">"& Split(App_web_ad,"<>||<>")(1) &"</font>');")
										End If
								End If
						End If
				Else
						set rs=server.createobject("adodb.recordset")
						sql="select a_tag,a_info,a_url,a_size,a_type,a_state,a_hits,a_days,a_date from [Lebi_Ad] where a_tag = '"& Id &"'"
						rs.open sql, conn, 1, 3
						If rs.eof Then
								rs.addnew
								rs("a_tag") = Id
								rs("a_info") = "标签广告["& Id &"]"
								rs("a_url") = "http://www.56770.com/"
								rs("a_size") = "0|0"
								rs("a_type") = 2
								rs("a_state") = 1
								rs("a_hits") = 0
								rs("a_days") = 0
								rs("a_date") = Date()
								rs.update
						End If
						rs.close:set rs=Nothing
						Response.Write("document.write('标签广告["& Id &"]');")
				End If
		End If
End Sub
connclose()
%>