<%
''''''''''' (C) Stefan Holmberg 1999 - 2006
''''''''''' Free to use if these sourcecode lines is not deleted
''''''''''' http://www.aspcode.net
''''''''''' Please read license at http://www.aspcode.net
'''''''''''
''''''''''''''''Config - global variables
Dim g_AdMentor_AdMentorRedirPath '
Dim g_Admentor_strConnect ' Connect string
Dim g_AdMentor_MaxRecords
Dim g_AdMentor_PathToAdServe ' HTTP path to adserve.asp and adclick.asp, like http://www.aspcode.net/ads
Dim g_AdMentor_DatabaseType ' SQLServer or Access
Dim g_AdMentor_TablePrefix ' if you renamed your tables...
Dim g_AdMentor_BannerMediaDirectory ' for upload
''''''''''''TODO 1. Database type
g_AdMentor_DatabaseType = "Access"
'g_AdMentor_DatabaseType = "SQLServer"
''''''''''''TODO 2. The path to where your admentor is installed
g_AdMentor_PathToAdServe = "http://namiami.com/admentorasp"
''''''''''''TODO 3. Connection string
'g_Admentor_strConnect = "Driver={SQL Server};Server=(local);Database=admtest;Uid=sa;Pwd=stefan;"
g_Admentor_strConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="& Server.MapPath("/admentorasp/db/db3.mdb")
'g_Admentor_strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("/admentorasp/db/db3.mdb") & ";Persist Security Info=False"
g_AdMentor_BannerMediaDirectory = "bannermedia"
''''''''''''TODO 4. Database table prefix
'Maybe you want to use a prefix on all your database tables
g_AdMentor_TablePrefix = ""
g_AdMentor_MaxRecords = 100
If Right(g_AdMentor_PathToAdServe,1) <> "/" Then
g_AdMentor_PathToAdServe = g_AdMentor_PathToAdServe & "/"
End If
''''''''''''''''DONT CHANGE ANYTHING BELOW
g_AdMentor_AdMentorRedirPath = g_AdMentor_PathToAdServe & "admentorredir.asp" ' This should be the path to admentorredir.asp
g_AdMentor_Demo = False ' If true then you can really update/add/delete stuff
Dim g_MaxLongInt, g_MaxEndDate
g_MaxLongInt = 2147483647 ' Virtually forever, max for a long integer in Access
g_MaxEndDate = "2020-01-01" ' This date means forever...
If Right(g_AdMentor_PathToAdServe,1) <> "/" Then
g_AdMentor_PathToAdServe = g_AdMentor_PathToAdServe & "/"
End If
%>
<%
'--------------------------------------------------------------------
' Microsoft ADO
'
' (c) 1996 Microsoft Corporation. All Rights Reserved.
'
'
'
' ADO constants include file for VBScript
'
'--------------------------------------------------------------------
'---- CursorTypeEnum Values ----
Const adOpenForwardOnly = 0
Const adOpenKeyset = 1
Const adOpenDynamic = 2
Const adOpenStatic = 3
Const adTypeBinary = 1
COnst adSaveCreateOverWrite = 2
'---- CursorOptionEnum Values ----
Const adHoldRecords = &H00000100
Const adMovePrevious = &H00000200
Const adAddNew = &H01000400
Const adDelete = &H01000800
Const adUpdate = &H01008000
Const adBookmark = &H00002000
Const adApproxPosition = &H00004000
Const adUpdateBatch = &H00010000
Const adResync = &H00020000
Const adNotify = &H00040000
'---- LockTypeEnum Values ----
Const adLockReadOnly = 1
Const adLockPessimistic = 2
Const adLockOptimistic = 3
Const adLockBatchOptimistic = 4
'---- ExecuteOptionEnum Values ----
Const adRunAsync = &H00000010
'---- ObjectStateEnum Values ----
Const adStateClosed = &H00000000
Const adStateOpen = &H00000001
Const adStateConnecting = &H00000002
Const adStateExecuting = &H00000004
'---- CursorLocationEnum Values ----
Const adUseServer = 2
Const adUseClient = 3
'---- DataTypeEnum Values ----
Const adEmpty = 0
Const adTinyInt = 16
Const adSmallInt = 2
Const adInteger = 3
Const adBigInt = 20
Const adUnsignedTinyInt = 17
Const adUnsignedSmallInt = 18
Const adUnsignedInt = 19
Const adUnsignedBigInt = 21
Const adSingle = 4
Const adDouble = 5
Const adCurrency = 6
Const adDecimal = 14
Const adNumeric = 131
Const adBoolean = 11
Const adError = 10
Const adUserDefined = 132
Const adVariant = 12
Const adIDispatch = 9
Const adIUnknown = 13
Const adGUID = 72
Const adDate = 7
Const adDBDate = 133
Const adDBTime = 134
Const adDBTimeStamp = 135
Const adBSTR = 8
Const adChar = 129
Const adVarChar = 200
Const adLongVarChar = 201
Const adWChar = 130
Const adVarWChar = 202
Const adLongVarWChar = 203
Const adBinary = 128
Const adVarBinary = 204
Const adLongVarBinary = 205
'---- FieldAttributeEnum Values ----
Const adFldMayDefer = &H00000002
Const adFldUpdatable = &H00000004
Const adFldUnknownUpdatable = &H00000008
Const adFldFixed = &H00000010
Const adFldIsNullable = &H00000020
Const adFldMayBeNull = &H00000040
Const adFldLong = &H00000080
Const adFldRowID = &H00000100
Const adFldRowVersion = &H00000200
Const adFldCacheDeferred = &H00001000
'---- EditModeEnum Values ----
Const adEditNone = &H0000
Const adEditInProgress = &H0001
Const adEditAdd = &H0002
Const adEditDelete = &H0004
'---- RecordStatusEnum Values ----
Const adRecOK = &H0000000
Const adRecNew = &H0000001
Const adRecModified = &H0000002
Const adRecDeleted = &H0000004
Const adRecUnmodified = &H0000008
Const adRecInvalid = &H0000010
Const adRecMultipleChanges = &H0000040
Const adRecPendingChanges = &H0000080
Const adRecCanceled = &H0000100
Const adRecCantRelease = &H0000400
Const adRecConcurrencyViolation = &H0000800
Const adRecIntegrityViolation = &H0001000
Const adRecMaxChangesExceeded = &H0002000
Const adRecObjectOpen = &H0004000
Const adRecOutOfMemory = &H0008000
Const adRecPermissionDenied = &H0010000
Const adRecSchemaViolation = &H0020000
Const adRecDBDeleted = &H0040000
'---- GetRowsOptionEnum Values ----
Const adGetRowsRest = -1
'---- PositionEnum Values ----
Const adPosUnknown = -1
Const adPosBOF = -2
Const adPosEOF = -3
'---- enum Values ----
Const adBookmarkCurrent = 0
Const adBookmarkFirst = 1
Const adBookmarkLast = 2
'---- MarshalOptionsEnum Values ----
Const adMarshalAll = 0
Const adMarshalModifiedOnly = 1
'---- AffectEnum Values ----
Const adAffectCurrent = 1
Const adAffectGroup = 2
Const adAffectAll = 3
'---- FilterGroupEnum Values ----
Const adFilterNone = 0
Const adFilterPendingRecords = 1
Const adFilterAffectedRecords = 2
Const adFilterFetchedRecords = 3
Const adFilterPredicate = 4
'---- SearchDirection Values ----
Const adSearchForward = 1
Const adSearchBackward = -1
'---- ConnectPromptEnum Values ----
Const adPromptAlways = 1
Const adPromptComplete = 2
Const adPromptCompleteRequired = 3
Const adPromptNever = 4
'---- ConnectModeEnum Values ----
Const adModeUnknown = 0
Const adModeRead = 1
Const adModeWrite = 2
Const adModeReadWrite = 3
Const adModeShareDenyRead = 4
Const adModeShareDenyWrite = 8
Const adModeShareExclusive = &Hc
Const adModeShareDenyNone = &H10
'---- IsolationLevelEnum Values ----
Const adXactUnspecified = &Hffffffff
Const adXactChaos = &H00000010
Const adXactReadUncommitted = &H00000100
Const adXactBrowse = &H00000100
Const adXactCursorStability = &H00001000
Const adXactReadCommitted = &H00001000
Const adXactRepeatableRead = &H00010000
Const adXactSerializable = &H00100000
Const adXactIsolated = &H00100000
'---- XactAttributeEnum Values ----
Const adXactCommitRetaining = &H00020000
Const adXactAbortRetaining = &H00040000
'---- PropertyAttributesEnum Values ----
Const adPropNotSupported = &H0000
Const adPropRequired = &H0001
Const adPropOptional = &H0002
Const adPropRead = &H0200
Const adPropWrite = &H0400
'---- ErrorValueEnum Values ----
Const adErrInvalidArgument = &Hbb9
Const adErrNoCurrentRecord = &Hbcd
Const adErrIllegalOperation = &Hc93
Const adErrInTransaction = &Hcae
Const adErrFeatureNotAvailable = &Hcb3
Const adErrItemNotFound = &Hcc1
Const adErrObjectInCollection = &Hd27
Const adErrObjectNotSet = &Hd5c
Const adErrDataConversion = &Hd5d
Const adErrObjectClosed = &He78
Const adErrObjectOpen = &He79
Const adErrProviderNotFound = &He7a
Const adErrBoundToCommand = &He7b
Const adErrInvalidParamInfo = &He7c
Const adErrInvalidConnection = &He7d
Const adErrStillExecuting = &He7f
Const adErrStillConnecting = &He81
'---- ParameterAttributesEnum Values ----
Const adParamSigned = &H0010
Const adParamNullable = &H0040
Const adParamLong = &H0080
'---- ParameterDirectionEnum Values ----
Const adParamUnknown = &H0000
Const adParamInput = &H0001
Const adParamOutput = &H0002
Const adParamInputOutput = &H0003
Const adParamReturnValue = &H0004
'---- CommandTypeEnum Values ----
Const adCmdUnknown = &H0008
Const adCmdText = &H0001
Const adCmdTable = &H0002
Const adCmdStoredProc = &H0004
'---- SchemaEnum Values ----
Const adSchemaProviderSpecific = -1
Const adSchemaAsserts = 0
Const adSchemaCatalogs = 1
Const adSchemaCharacterSets = 2
Const adSchemaCollations = 3
Const adSchemaColumns = 4
Const adSchemaCheckConstraints = 5
Const adSchemaConstraintColumnUsage = 6
Const adSchemaConstraintTableUsage = 7
Const adSchemaKeyColumnUsage = 8
Const adSchemaReferentialContraints = 9
Const adSchemaTableConstraints = 10
Const adSchemaColumnsDomainUsage = 11
Const adSchemaIndexes = 12
Const adSchemaColumnPrivileges = 13
Const adSchemaTablePrivileges = 14
Const adSchemaUsagePrivileges = 15
Const adSchemaProcedures = 16
Const adSchemaSchemata = 17
Const adSchemaSQLLanguages = 18
Const adSchemaStatistics = 19
Const adSchemaTables = 20
Const adSchemaTranslations = 21
Const adSchemaProviderTypes = 22
Const adSchemaViews = 23
Const adSchemaViewColumnUsage = 24
Const adSchemaViewTableUsage = 25
Const adSchemaProcedureParameters = 26
Const adSchemaForeignKeys = 27
Const adSchemaPrimaryKeys = 28
Const adSchemaProcedureColumns = 29
%>
<%
Function DanDate (strDate, strFormat)
Dim intPosItem
Dim intHourPart
Dim strHourPart
Dim strMinutePart
Dim strSecondPart
Dim strAMPM
If not IsDate(strDate) Then
DanDate = strDate
Exit Function
End If
intPosItem = Instr(strFormat, "%m")
Do While intPosItem > 0
strFormat = Left(strFormat, intPosItem-1) & _
DatePart("m",strDate) & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%m")
Loop
intPosItem = Instr(strFormat, "%b")
Do While intPosItem > 0
strFormat = Left(strFormat, intPosItem-1) & _
MonthName(DatePart("m",strDate),True) & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%b")
Loop
intPosItem = Instr(strFormat, "%B")
Do While intPosItem > 0
strFormat = Left(strFormat, intPosItem-1) & _
MonthName(DatePart("m",strDate),False) & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%B")
Loop
intPosItem = Instr(strFormat, "%d")
Do While intPosItem > 0
strFormat = Left(strFormat, intPosItem-1) & _
DatePart("d",strDate) & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%d")
Loop
intPosItem = Instr(strFormat, "%j")
Do While intPosItem > 0
strFormat = Left(strFormat, intPosItem-1) & _
DatePart("y",strDate) & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%j")
Loop
intPosItem = Instr(strFormat, "%y")
Do While intPosItem > 0
strFormat = Left(strFormat, intPosItem-1) & _
Right(DatePart("yyyy",strDate),2) & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%y")
Loop
intPosItem = Instr(strFormat, "%Y")
Do While intPosItem > 0
strFormat = Left(strFormat, intPosItem-1) & _
DatePart("yyyy",strDate) & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%Y")
Loop
intPosItem = Instr(strFormat, "%w")
Do While intPosItem > 0
strFormat = Left(strFormat, intPosItem-1) & _
DatePart("w",strDate,1) & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%w")
Loop
intPosItem = Instr(strFormat, "%a")
Do While intPosItem > 0
strFormat = Left(strFormat, intPosItem-1) & _
WeekDayName(DatePart("w",strDate,1),True) & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%a")
Loop
intPosItem = Instr(strFormat, "%A")
Do While intPosItem > 0
strFormat = Left(strFormat, intPosItem-1) & _
WeekDayName(DatePart("w",strDate,1),False) & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%A")
Loop
intPosItem = Instr(strFormat, "%I")
Do While intPosItem > 0
intHourPart = DatePart("h",strDate) mod 12
if intHourPart = 0 then intHourPart = 12
strFormat = Left(strFormat, intPosItem-1) & _
intHourPart & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%I")
Loop
intPosItem = Instr(strFormat, "%H")
Do While intPosItem > 0
strHourPart = DatePart("h",strDate)
if strHourPart < 10 Then strHourPart = "0" & strHourPart
strFormat = Left(strFormat, intPosItem-1) & _
strHourPart & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%H")
Loop
intPosItem = Instr(strFormat, "%M")
Do While intPosItem > 0
strMinutePart = DatePart("n",strDate)
if strMinutePart < 10 then strMinutePart = "0" & strMinutePart
strFormat = Left(strFormat, intPosItem-1) & _
strMinutePart & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%M")
Loop
intPosItem = Instr(strFormat, "%S")
Do While intPosItem > 0
strSecondPart = DatePart("s",strDate)
if strSecondPart < 10 then strSecondPart = "0" & strSecondPart
strFormat = Left(strFormat, intPosItem-1) & _
strSecondPart & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%S")
Loop
intPosItem = Instr(strFormat, "%P")
Do While intPosItem > 0
if DatePart("h",strDate) >= 12 then
strAMPM = "PM"
Else
strAMPM = "AM"
End If
strFormat = Left(strFormat, intPosItem-1) & _
strAMPM & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%P")
Loop
intPosItem = Instr(strFormat, "%%")
Do While intPosItem > 0
strFormat = Left(strFormat, intPosItem-1) & "%" & _
Right(strFormat, Len(strFormat) - (intPosItem + 1))
intPosItem = Instr(strFormat, "%S")
Loop
DanDate = strFormat
End Function
Function Date_GetYear( dDate )
Date_GetYear = DatePart( "yyyy", dDate )
End Function
Function Date_GetMonthNo( dDate )
Date_GetMonthNo = DatePart( "m", dDate )
End Function
Function Date_GetDayNo( dDate )
Date_GetDayNo = DatePart( "d", dDate )
End Function
Function Date_GetMonthName( nMonthNo )
Select Case nMonthNo
Case 1
Date_GetMonthName = "Jan"
Case 2
Date_GetMonthName = "Feb"
Case 3
Date_GetMonthName = "Mar"
Case 4
Date_GetMonthName = "Apr"
Case 5
Date_GetMonthName = "May"
Case 6
Date_GetMonthName = "Jun"
Case 7
Date_GetMonthName = "Jul"
Case 8
Date_GetMonthName = "Aug"
Case 9
Date_GetMonthName = "Sep"
Case 10
Date_GetMonthName = "Oct"
Case 11
Date_GetMonthName = "Nov"
Case 12
Date_GetMonthName = "Dec"
End Select
End Function
Sub Date_FillBoxWithHours( nDefault )
Dim nHour, nHourWrite
For nHour = 0 To 24
Response.Write "
" & nHourWrite & " "
Next
End Sub
Sub Date_FillBoxWithMinutes( nDefault )
Dim nHour, nHourWrite
For nHour = 0 To 59
Response.Write "
" & nHourWrite & " "
Next
End Sub
Function IncGeneral_ConvertDateToShort( dDate )
Dim nYear, nMonth, nDay
nYear = DatePart("yyyy", dDate )
nMonth = DatePart("m", dDate )
If nMonth < 10 Then
nMonth = "0" & nMonth
End If
nDay = DatePart("d", dDate )
If nDay < 10 Then
nDay = "0" & nDay
End If
IncGeneral_ConvertDateToShort = nYear & "-" & nMonth & "-" & nDay
End Function
Sub Date_FillBoxWithYears( nFirst, nLast, nDefault )
Dim nYear
If nDefault = "" Then
nDefault = Date_GetYear( Now() )
End If
For nYear = nFirst To nLast
Response.Write "
" & nYear & " "
Next
End Sub
Sub Date_FillBoxWithDays( nDefault )
Dim nDay
If nDefault = "" Then
nDefault = Date_GetDayNo( Now() )
End If
For nDay = 1 To 31
Response.Write "
" & nDay & " "
Next
End Sub
Sub Date_FillBoxWithMonths( nDefault, fUseNumbersAsValue )
Dim nMonth
If nDefault = "" Then
nDefault = Date_GetMonthNo( Now() )
End If
For nMonth = 1 To 12
Response.Write "
" & Date_GetMonthName(nMonth) & " "
Next
End Sub
%>
<%
''''''''''' (C) Stefan Holmberg 1999
''''''''''' Free to use if these sourcecode lines is not deleted
''''''''''' Contact me at webmaster@sqlexperts.com
''''''''''' http://www.sqlexperts.com
''''''''''' AdMentor homepage at http://www.create-a-webshop.com
' Version 1.11 contains contribution from Shawn Willmon - traceclicks code
Function Internal_AdMentordb_GetDateFunction()
If g_AdMentor_DatabaseType = "SQLServer" Then
Internal_AdMentordb_GetDateFunction = "getdate()"
Else
Internal_AdMentordb_GetDateFunction = "date()"
End If
End Function
Function Internal_AdMentordb_GetBoolValue( fTrue )
If g_AdMentor_DatabaseType = "SQLServer" Then
If fTrue = True Then
Internal_AdMentordb_GetBoolValue = "1"
Else
Internal_AdMentordb_GetBoolValue = "0"
End If
Else
If fTrue = true Then
Internal_AdMentordb_GetBoolValue = "true"
Else
Internal_AdMentordb_GetBoolValue = "false"
End If
End If
End Function
Function AdMentor_DBOpenConnection()
Dim oConn
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open g_AdMentor_strConnect
Set AdMentor_DBOpenConnection = oConn
End Function
Function AdMentor_DBOpenConnectionStats()
Dim oConn
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open g_Admentor_strConnectStats
Set AdMentor_DBOpenConnectionStats = oConn
End Function
Function AdMentor_DBGetBannersInFarm( oConn, nBannerFarm )
Dim oRS
Set oRS = CreateObject("ADODB.Recordset")
oRS.CursorLocation = adUseClient
oRS.MaxRecords = g_AdMentor_MaxRecords
oRS.CacheSize = g_AdMentor_MaxRecords
oRS.CursorType = adOpenForwardOnly
oRS.Open "select bannerid, gifurl, weight, alttext, undertext, xsize, ysize from " & g_AdMentor_TablePrefix & "banner where farmid=" & nBannerFarm & " and weight > 0 and showcount < maximpressions AND clickcount+underclickcount < maxclicks AND validtodate >= " & Internal_AdMentordb_GetDateFunction() & " AND validfromdate <= " & Internal_AdMentordb_GetDateFunction(), oConn
Set oRS.ActiveConnection = Nothing
Set AdMentor_DBGetBannersInFarm = oRS
End Function
Sub AdMentor_DBAddShowCount( oConn, nBanner )
oConn.Execute "update " & g_AdMentor_TablePrefix & "banner set showcount=showcount+1 where bannerid=" & nBanner
End Sub
Function AdMentor_DBUpdateClickCountAndGetUrl( oConn, nBannerId, fUnderText )
Dim sSQL
Dim oRSTC
If fUnderText = True Then
sSQL = "update " & g_AdMentor_TablePrefix & "banner set underclickcount = underclickcount +1 where bannerid = " & nBannerId
Else
sSQL = "update " & g_AdMentor_TablePrefix & "banner set clickcount = clickcount +1 where bannerid = " & nBannerId
End if
oConn.Execute ( sSQL )
Set oRSTC = Server.CreateObject("ADODB.Recordset")
Set oRSTC.ActiveConnection = oConn
oRSTC.Open "select * from " & g_AdMentor_TablePrefix & "traceclicks where bannerid = -1 ", ,adOpenKeyset,adLockOptimistic
oRSTC.AddNew()
oRSTC("bannerid")=nBannerId
oRSTC("page")=Request.ServerVariables("HTTP_REFERER")
oRSTC("dt") = now()
oRSTC("ip")=Request.ServerVariables( "REMOTE_ADDR" )
oRSTC("undertext")=False
oRSTC.Update
oRSTC.Close
Set oRSTC = Nothing
AdMentor_DBUpdateClickCountAndGetUrl = AdMentor_DBGetUrl(oConn, nBannerId, False )
End Function
Function AdMentor_DBGetUrl( oConn, nBanner, fUnderText )
Dim oRS
Dim sSQL2
If fUnderText = True Then
sSQL2 = "select underurl as url from " & g_AdMentor_TablePrefix & "banner where bannerid= " & nBanner
Else
sSQL2 = "select redirurl as url from " & g_AdMentor_TablePrefix & "banner where bannerid= " & nBanner
End if
Set oRS = oConn.Execute ( sSQL2 )
AdMentor_DBGetUrl = oRS("url").Value
oRS.Close
Set oRS = Nothing
End Function
Function AdSQL_AddAndWhere( strWhere, strWhat )
If strWhere = "" Then
strWhere = " WHERE "
Else
strWhere = strWhere & " AND "
End If
strWhere = strWhere & " " & strWhat
AdSQL_AddAndWhere = strWhere
End Function
Function AdMentor_DBGetAvailBanners( oConn, fASP, strZones, nFarm, nBannerId, fCanUseHTML )
Dim oRS
Set oRS = CreateObject("ADODB.Recordset")
oRS.CursorLocation = adUseClient
oRS.MaxRecords = g_AdMentor_MaxRecords
oRS.CacheSize = g_AdMentor_MaxRecords
oRS.CursorType = adOpenStatic
oRS.Open GetAdSQL(fASP, strZones, nFarm, nBannerId, fCanUseHTML ), oConn
Set oRS.ActiveConnection = Nothing
Set AdMentor_DBGetAvailBanners = oRS
End Function
Function AdMentor_GetHTMLCode( oConn, nBannerId )
Dim oRS
Set oRS = CreateObject("ADODB.Recordset")
oRS.CursorLocation = adUseClient
oRS.MaxRecords = 1
oRS.CacheSize = 1
oRS.CursorType = adOpenForwardOnly
oRS.Open "select htmlcode from " & g_AdMentor_TablePrefix & "banner where bannerid="&nBannerId, oConn
AdMentor_GetHTMLCode = oRS("htmlcode").Value
oRS.Close
Set oRS = Nothing
End Function
Function GetAdSQL( fASP, sZone, nFarm, nBannerId, fCanUseHTML )
Dim strSQL
Dim strWhere
strSQL = "select distinct " & g_AdMentor_TablePrefix & "banner.bannerid, " & g_AdMentor_TablePrefix & "banner.gifurl, " & g_AdMentor_TablePrefix & "banner.weight "
If fASP Then
strSQL = strSQL & ", " & g_AdMentor_TablePrefix & "banner.AltText, " & g_AdMentor_TablePrefix & "banner.UnderText, " & g_AdMentor_TablePrefix & "banner.xsize, " & g_AdMentor_TablePrefix & "banner.ysize "
End If
If fCanUseHTML Then
strSQL = strSQL & ",ishtml"
End If
If strAdmentor_strAlreadyOnPage <> "" Then
strWhere = AdSQL_AddAndWhere( strWhere, g_AdMentor_TablePrefix & "banner.bannerid not in ( " & strAdmentor_strAlreadyOnPage & ")" )
End If
strSQL = strSQL & " from " & g_AdMentor_TablePrefix & "banner "
If sZone <> "0" Then
strSQL = strSQL & "," & g_AdMentor_TablePrefix & "banzone "
strWhere = AdSQL_AddAndWhere( strWhere, g_AdMentor_TablePrefix & "banner.bannerid=" & g_AdMentor_TablePrefix & "banzone.bannerid" )
strWhere = AdSQL_AddAndWhere( strWhere, g_AdMentor_TablePrefix & "banzone.zoneid in ( " & sZone & ")" )
End If
If nBannerId <> "" Then
strWhere = AdSQL_AddAndWhere( strWhere, g_AdMentor_TablePrefix & "banner.bannerid=" & nBannerId )
Else
If nFarm <> 0 Then
strWhere = AdSQL_AddAndWhere( strWhere, g_AdMentor_TablePrefix & "banner.farmid=" & nFarm )
End If
strWhere = AdSQL_AddAndWhere( strWhere, "weight > 0 and showcount < maximpressions AND validtodate >= " & Internal_AdMentordb_GetDateFunction() & " AND validfromdate <= " & Internal_AdMentordb_GetDateFunction() )
If fCanUseHTML = True Then
strWhere = AdSQL_AddAndWhere( strWhere, " ( ( clickcount+underclickcount < maxclicks ) OR ishtml=" & Internal_AdMentordb_GetBoolValue(true) & " )" )
Else
strWhere = AdSQL_AddAndWhere( strWhere, "ishtml <> " & Internal_AdMentordb_GetBoolValue(true) )
End If
End If
strSQL = strSQL & strWhere
' If you want banners with no zoning to mean all zones then add these
' lines
' If sZone <> "0" Then
' strSQL = strSQL & "union select distinct banner.bannerid, banner.gifurl, banner.weight "
' If fASP Then
' strSQL = strSQL & ", banner.AltText, banner.UnderText, banner.xsize, banner.ysize "
' End If
' If fCanUseHTML Then
' strSQL = strSQL & ",ishtml"
' End If
' strSQL = strSQL & " from banner "
' strSQL = strSQL & " where bannerid not in (select bannerid from banzone)"
' If strAdmentor_strAlreadyOnPage <> "" Then
' strSQL = strSQL & " AND banner.bannerid not in ( " & strAdmentor_strAlreadyOnPage & ")"
' End If
' End If
GetAdSQL = strSQL
End Function
%>
<%
''''''''''' (C) Stefan Holmberg 1999
''''''''''' Free to use if these sourcecode lines is not deleted
''''''''''' Contact me at webmaster@sqlexperts.com
''''''''''' http://www.sqlexperts.com
''''''''''' AdMentor homepage at http://www.create-a-webshop.com
''''''''''''''''The public functions
'This should be called from ASP pages on SAME server
'The QueryString parameter is just that - a querystring string
'where you specify zone etc the same way as when
'using NonSSI version
Public Function AdMentor_GetAdASP( strQueryString )
Dim sArr, n
Dim sArr2
'Setable parameters
Dim sZones, nFarm, nBannerId
sArr = Split( strQueryString, "&" )
For n=LBound(sArr) To UBound(sArr)
sArr2 = Split( sArr(n), "=" )
Select Case sArr2(0)
Case "Z"
sZones = sArr2(1)
Case "F"
nFarm = sArr2(1)
Case "B"
nBannerId = sArr2(1)
Case "N"
nBannerOnPage = sArr2(1)
End Select
Next
'If we have selected a certain banner to run on this
'specific spot then just don't care about the rest...
AdMentor_GetAdASP = AdMentor_GetAdEx( True, sZones, nFarm, nBannerId, nBannerOnPage, True )
End Function
Public Function AdMentor_GetAdNonSSI()
'Setable parameters
Dim sZones, nFarm, nBannerId, nBannerOnPage
sZones = Request.QueryString("Z")
nFarm = Request.QueryString("F")
nBannerId = Request.QueryString("B")
nBannerOnPage = Request.QueryString("N")
AdMentor_GetAdNonSSI = AdMentor_GetAdEx( False, sZones, nFarm, nBannerId, nBannerOnPage, False )
End Function
'Private functions
Private Function AdMentor_AddToUsedList( nBannerId )
If strAdmentor_strAlreadyOnPage <> "" Then
strAdmentor_strAlreadyOnPage = strAdmentor_strAlreadyOnPage & ","
End If
strAdmentor_strAlreadyOnPage = strAdmentor_strAlreadyOnPage & CStr(nBannerId)
End Function
' If ASP then it returns the HTML
' else it simply returns the bannerid
' fASP = true or false
Private Function AdMentor_GetAdEx( fASP, strZone, nFarm, nBannerId, nBannerOnPage, fCanUseHTML )
Dim oConn
Dim oRS
Dim nSumWeight
Dim nTempIndex
Dim nWeight
Dim nTempIndex2
Dim nBanner
Dim nCurRow
Dim nMax
Set oConn = AdMentor_DBOpenConnection()
If strZone = "" Then
strZone = "0"
End If
If nFarm = "" Then
nFarm = "0"
End If
' Get Total Weight
Set oRS = AdMentor_DBGetAvailBanners( oConn, fASP, strZone, nFarm, nBannerId, fCanUseHTML )
If oRS.EOF Then
'There is no banner in this banner farm
'TODO: RETURN DEFAULT BANNER!!!!!
oRS.Close
Set oRS = Nothing
oConn.Close
Set oConn = Nothing
AdMentor_GetAdEx = "No banner in farm"
Exit Function
End If
'Now lets get the total weight
nSumWeight = 0
While Not oRS.EOF
nSumWeight = nSumWeight + oRS("weight").Value
oRS.MoveNext
Wend
' Lets get a random banner
Randomize
nBanner = Int((nSumWeight * Rnd) + 1)
oRS.MoveFirst
nCurVal = 0
While nCurVal + oRS("weight").Value < nBanner
nCurVal = nCurVal + oRS("weight").Value
oRS.MoveNext
Wend
nBanner = oRS("bannerid").Value
AdMentor_AddToUsedList nBanner
If Not fASP Then
AdMentor_GetAdEx = nBanner & "---" & oRS("gifurl").Value
AdMentor_DBAddShowCount oConn, nBanner
oRS.Close
Set oRS = Nothing
oConn.Close
Set oConn = Nothing
Exit Function
End If
If fCanUseHTML And oRS("ishtml").Value = True Then
Dim sHTMCode
oRS.Close
Set oRS = Nothing
sHTMCode = AdMentor_GetHTMLCode( oConn, nBanner )
sHTMCode = Replace(sHTMCode, "
", g_AdMentor_AdMentorRedirPath & "?id=" & nBanner & "&way=ban")
AdMentor_GetAdEx = FixupSpecialVariables(sHTMCode)
AdMentor_DBAddShowCount oConn, nBanner
oConn.Close
Set oConn = Nothing
Exit Function
End If
' Now we have the banner id, lets create the actual HTML
'Move into temp variables only to make it more readable
Dim sRedirUrl
Dim sGifUrl
Dim sAltText
Dim sUnderText
Dim sUnderUrl
Dim sRet
Dim nXSize
Dim nYSize
sRedirUrl = g_AdMentor_AdMentorRedirPath & "?id=" & nBanner & "&way=ban"
If IsNull( oRS("gifurl").Value ) Then
sGifUrl = ""
Else
sGifUrl = oRS("gifurl").Value
End if
If IsNull( oRS("AltText").Value ) Then
sAltText = ""
Else
sAltText = oRS("AltText").Value
End if
If IsNull( oRS("UnderText").Value ) Then
sUnderText = ""
Else
sUnderText = oRS("UnderText").Value
End if
sUnderUrl = g_AdMentor_AdMentorRedirPath & "?id=" & nBanner & "&way=txt"
nXSize=oRS("xsize").Value
nYSize=oRS("ysize").Value
sRet = "" & " 0 Then
sRet = sRet & " width=""" & nXSize & """"
End if
If nYSize > 0 Then
sRet = sRet & " height=""" & nYSize & """"
End if
sRet = sRet & ">" & " "
If sUnderText <> "" Then
sRet = sRet & "" & sUnderText & " "
Else
'
End If
sRet = sRet & " "
AdMentor_GetAdEx = sRet
' Lets update impression for it
AdMentor_DBAddShowCount oConn, nBanner
oRS.Close
Set oRS = Nothing
oConn.Close
Set oConn = Nothing
End Function
Public Function AdMentor_ClickAd(nBannerId, sWay)
Dim oConn
Dim sSQL
Dim sSQL2
Dim oRS
Dim sRedir
Dim fIsUnderText
If sWay ="txt" Then
fIsUnderText = true
Else
fIsUnderText = false ' Clicked on actual banner
End If
'Pretty easy...
Set oConn = AdMentor_DBOpenConnection()
sRedir = AdMentor_DBUpdateClickCountAndGetUrl( oConn, nBannerId, fIsUnderText )
oConn.Close
Set oConn = Nothing
AdMentor_ClickAd = sRedir
End Function
Private Function FixupSpecialVariables( sHTML )
'Now check for ' 0 Then
sLeftHTML = Left( sHTML, nIndStart -1 )
nIndEnd = InStr( nIndStart, sHTML, ">" )
sRightHTML = Mid( sHTML, nIndEnd + 1 )
sSubStr = Mid( sHTML, nIndStart, nIndEnd - nIndStart )
vData = Split( sSubStr, "-")
If vData(1) = "LAST" Then
nNumber = Session("AdMentor_RndNumber")
Else
nLow = CLng(vData(1))
nHigh = CLng(vData(2))
Randomize
nNumber = CLng((nHigh * Rnd) + nLow)
Session("AdMentor_RndNumber") = nNumber
End If
sHTML = sLeftHTML & CStr(nNumber) & sRightHTML
End If
If InStr( 1,CStr(sHTML), " 0 Then
fCont = True
Else
fCont = False
End If
Wend
FixupSpecialVariables = sHTML
End Function
Public Function GetAdminPagesBannerCode()
'Want to advertise on your admin pages?
'Then just change this function to what you want...
'What I do is just call AdMentorGetAd with a special banner id
'to get by Datais-banners showed
' Dim sRet
' sRet = AdMentor_GetAdASP("B=93")
GetAdminPagesBannerCode = ""
End Function
%>
<%=AdMentor_GetAdASP("F=11&Z=0&N=1")%>