<% '*********************************************************************** ' System : ASPBanner ' Author : Christopher Williams of CJWSoft www.CJWSoft.com ' ' COPYRIGHT NOTICE ' ' See attached Software License Agreement ' ' (c) Copyright 2000 - 2001 by CJWSoft. All rights reserved '*********************************************************************** 'Function to randomize array order Function RandmizeArray(ByVal InputArray) SwapUpper = UBound(InputArray) SwapLower = LBound(InputArray) Randomize(Cbyte(Left(Right(Time(),5),2))) For SwapLoop = SwapLower to SwapUpper SwapPosition = Int(Rnd * (SwapUpper + 1)) TempVar = InputArray(SwapLoop) InputArray(SwapLoop) = InputArray(SwapPosition) InputArray(SwapPosition) = TempVar Next RandmizeArray = InputArray End Function Application.Lock For LocationIndex = 1 to 10 Application("BannerLocation" & LocationIndex) = "" Application("BannerLocation" & LocationIndex & "_Cycle") = "" Next Application.Unlock ' ************************************************************* ' Checks status settings for Banners in the database and changes them if necessary ' ************************************************************* Set DataConn = Server.CreateObject("ADODB.Connection") DataConn.Open BannerConnectionString Set cmdTemp = Server.CreateObject("ADODB.Command") Set CmdUpdateWaiting = Server.CreateObject("ADODB.Recordset") If BannerDatabaseType = "SQL" Then cmdTemp.CommandText = "UPDATE Banners SET Banner_Status = 'Active' WHERE (Banner_Status = 'Waiting') AND (Banner_Begin_Date <= '" & DATE & "')" ElseIf BannerDatabaseType = "MSACCESS" Then cmdTemp.CommandText = "UPDATE Banners SET Banner_Status = 'Active' WHERE (Banner_Status = 'Waiting') AND (Banner_Begin_Date <= #" & DATE & "#)" End IF cmdTemp.CommandType = 1 Set cmdTemp.ActiveConnection = DataConn CmdUpdateWaiting.Open cmdTemp, , 0, 1 CmdUpdateWaiting.Close Set CmdUpdateWaiting = Nothing Set cmdTemp = Server.CreateObject("ADODB.Command") Set CmdUpdateExpired = Server.CreateObject("ADODB.Recordset") If BannerDatabaseType = "SQL" Then cmdTemp.CommandText = "UPDATE Banners SET Banner_Status = 'Expired' WHERE (Banner_Status = 'Active') AND (NOT (Banner_End_Date IS NULL)) AND (Banner_End_Date <= '" & DATE & "')" ElseIf BannerDatabaseType = "MSACCESS" Then cmdTemp.CommandText = "UPDATE Banners SET Banner_Status = 'Expired' WHERE (Banner_Status = 'Active') AND (NOT (Banner_End_Date IS NULL)) AND (Banner_End_Date <= #" & DATE & "#)" End IF cmdTemp.CommandType = 1 Set cmdTemp.ActiveConnection = DataConn CmdUpdateExpired.Open cmdTemp, , 0, 1 CmdUpdateExpired.Close Set CmdUpdateExpired = Nothing Set cmdTemp = Server.CreateObject("ADODB.Command") Set CmdRetrieveImpLimitedAds = Server.CreateObject("ADODB.Recordset") cmdTemp.CommandText = "SELECT Banners.* FROM Banners WHERE (Banner_Status = 'Active') AND (Banner_End_Date IS NULL)" cmdTemp.CommandType = 1 Set cmdTemp.ActiveConnection = ConnPasswords CmdRetrieveImpLimitedAds.Open cmdTemp, , 0, 1 While Not CmdRetrieveImpLimitedAds.EOF Set cmdTemp = Server.CreateObject("ADODB.Command") Set CmdRetrieveImpressions = Server.CreateObject("ADODB.Recordset") cmdTemp.CommandText = "SELECT SUM(Banner_Impressions) AS TotalImpressions FROM Banner_Stats WHERE (Banner_ID = " & CmdRetrieveImpLimitedAds("Banner_ID") & ")" cmdTemp.CommandType = 1 Set cmdTemp.ActiveConnection = ConnPasswords CmdRetrieveImpressions.Open cmdTemp, , 0, 1 If Not CmdRetrieveImpressions.EOF Then If CmdRetrieveImpressions("TotalImpressions") >= CmdRetrieveImpLimitedAds("Banner_Impressions_Purchased") Then Set cmdTemp = Server.CreateObject("ADODB.Command") Set CmdUpdateImpHit = Server.CreateObject("ADODB.Recordset") cmdTemp.CommandText = "UPDATE Banners SET Banner_Status = 'ImpHit' WHERE (Banner_ID = " & CmdRetrieveImpLimitedAds("Banner_ID") & ")" cmdTemp.CommandType = 1 Set cmdTemp.ActiveConnection = DataConn CmdUpdateImpHit.Open cmdTemp, , 0, 1 End IF End If CmdRetrieveImpLimitedAds.MoveNext Wend CmdRetrieveImpLimitedAds.Close Set CmdRetrieveImpLimitedAds = Nothing CmdRetrieveImpressions.Close Set CmdRetrieveImpressions = Nothing CmdUpdateImpHit.Close Set CmdUpdateImpHit = Nothing DataConn.Close Set DataConn = Nothing For LocationIndex = 1 to 10 ' ************************************************************* ' Sets the Application Variables Needed for for BannerLocations ' ************************************************************* Set ConnPasswords = Server.CreateObject("ADODB.Connection") ConnPasswords.Open BannerConnectionString Set cmdTemp = Server.CreateObject("ADODB.Command") Set CmdRetrieveAds = Server.CreateObject("ADODB.Recordset") cmdTemp.CommandText = "SELECT Banners.* FROM Banners WHERE (Banner_Status = 'Active') And Banner_Area = " & LocationIndex cmdTemp.CommandType = 1 Set cmdTemp.ActiveConnection = ConnPasswords CmdRetrieveAds.Open cmdTemp, , 0, 1 If Not CmdRetrieveAds.EOF Then Application.Lock Application("BannerLocation" & LocationIndex) = "" CycleBannerTotal = 0 CycleList = "" NewCycleList = "" While Not CmdRetrieveAds.EOF For LoopBanner = 1 To CmdRetrieveAds("Banner_Weight") CycleBannerTotal = CycleBannerTotal + 1 If Application("BannerLocation" & LocationIndex) <> "" Then Application("BannerLocation" & LocationIndex) = Application("BannerLocation" & LocationIndex) & "|" End If Application("BannerLocation" & LocationIndex) = Application("BannerLocation" & LocationIndex) & CmdRetrieveAds("Banner_ID") & vbTab Application("BannerLocation" & LocationIndex) = Application("BannerLocation" & LocationIndex) & CmdRetrieveAds("Banner_Image_URL") & vbTab Application("BannerLocation" & LocationIndex) = Application("BannerLocation" & LocationIndex) & CmdRetrieveAds("Banner_Width") & vbTab Application("BannerLocation" & LocationIndex) = Application("BannerLocation" & LocationIndex) & CmdRetrieveAds("Banner_Height") & vbTab Application("BannerLocation" & LocationIndex) = Application("BannerLocation" & LocationIndex) & CmdRetrieveAds("Banner_Border") & vbTab Application("BannerLocation" & LocationIndex) = Application("BannerLocation" & LocationIndex) & CmdRetrieveAds("Banner_Text_Message") & vbTab Application("BannerLocation" & LocationIndex) = Application("BannerLocation" & LocationIndex) & CmdRetrieveAds("Banner_ALT_Text") & vbTab Application("BannerLocation" & LocationIndex) = Application("BannerLocation" & LocationIndex) & CmdRetrieveAds("Banner_Target") & vbTab Application("BannerLocation" & LocationIndex) = Application("BannerLocation" & LocationIndex) & CmdRetrieveAds("Banner_HTML_code") & vbTab Application("BannerLocation" & LocationIndex) = Application("BannerLocation" & LocationIndex) & CmdRetrieveAds("Banner_Type") & vbTab Next CmdRetrieveAds.MoveNext Wend For CycleLoop = 0 To CycleBannerTotal - 1 If CycleList <> "" Then CycleList = CycleList & "|" End If CycleList = CycleList & CycleLoop Next CycleListArray = Split(CycleList,"|") CycleListArray = RandmizeArray(CycleListArray) For CycleListArrayIndex = 0 To Ubound(CycleListArray) If NewCycleList <> "" Then NewCycleList = NewCycleList & "," End If NewCycleList = NewCycleList & CycleListArray(CycleListArrayIndex) Next Application("BannerLocation" & LocationIndex & "_Cycle") = "0|" & CycleBannerTotal & "|" & NewCycleList Application.Unlock End If CmdRetrieveAds.Close Set CmdRetrieveAds = Nothing Next ConnPasswords.Close Set ConnPasswords = Nothing Application.Lock Application("BannersLastUpdated") = Hour(time) Application.Unlock %>