| This page shows the actual source code used on this site. You can read the article that discusses this code here. If this is the first CYA source code you've seen you should read this overview first. Did you know you can download all the source code (and the database) of this site? Then get my newsletter to be emailed when I update the source code! Please spread the word by recommending my site to your friends and colleagues! This is JScript (server-side JavaScript), not the more common VBScript. More... |
Rotate.asp<!--#include file = "/include/Startup.html"-->
<%
// ============================================
// NOTE: all source code downloaded from CoverYourASP was written by
// James Shaw (unless stated otherwise), and is copyright (c) 2000-2002
// by James Shaw. You can use the code for any purpose, but do not
// publish or distribute the content in any way.
//
// See http://CoverYourASP.com/Legal.asp for up-to-date details.
// ============================================
// output relevant meta tags
Init( "Rotate banners" );
// output common top of page
Header( 'Rotate banners' );
// output page content
Content ( );
// output common bottom of page
Footer( );
// ============================================
// the content of this page
// ============================================
function Content ( )
{
Out ( '<td valign="top" class="content">' );
Out ( 'See that extra content on the right of this page? Refresh the page and you\'ll see that different items are displayed in a different order each time. (Actually, the one or two top items may not change - they are reserved for advertisers)' );
Out ( '<p>This shows a good use (maybe the only one) of JavaScript\'s Math.random() function. Using this and a couple of arrays it\'s a snap to provide functionality like this.' );
Out ( '<p>Just as on most of my pages I don\'t have enough space to show all my links, so I can pass into the <a href="/ShowSource_page_Rotate.html">ShowBanners</a> function the number to display.' );
Out ( '<p>(If you do want to see <b>all</b> the links on a page reserved for just for them, <a href="resources.asp">go here</a>).' );
Out ( '<p>The banners are stored in my database (in the <a href="DBEditTable.asp?table=MyBanners">MyBanners</a> table), and the contents copied into Application variables at the start of each day.' );
Out ( '<p>This method is perfect for banners - they change rarely, but are displayed often (on virtually every page), so the speed and scalability of Application variables has a huge effect. Read more about this process in <a href="/BannerApp.html">this article</a>.' );
Out ( '<p><center><a href="/ShowSource_page_Rotate.html"><img src="/images/source.gif" border=0></a></center>' );
ShowBottomBanner()
Out ( '</td>' );
Out ( '<td background="images/gx/navgap.gif" valign="top">' );
// show rotating banners
ShowBanners ( 4 );
Out ( '</td>' );
}
%> |
utils/Banners.asp<%
// ============================================
// NOTE: all source code downloaded from CoverYourASP was written by
// James Shaw (unless stated otherwise), and is copyright (c) 2000-2002
// by James Shaw. You can use the code for any purpose, but do not
// publish or distribute the content in any way.
//
// See http://CoverYourASP.com/Legal.asp for up-to-date details.
// ============================================
// ============================================
// show a specific banner if passed in, else the next available banner
// ============================================
function ShowAd ( sShowBanner )
{
// should we make a plain page for printing?
if ( bPlainJane )
{
Out ( ' ' );
return;
}
var nTopBanners = Application ( 'TotalTopBanners' );
if ( !nTopBanners )
{
// if there are no CYA banners left, optionally
// display ASPAlliance banners instead
if ( bDisplayAllianceBanners )
{
DebugOut ( '<font color="blue">showing ASPAlliance 468 banner</font>' );
ShowAllianceAd ( 468, 1 );
}
else
{
DebugOut ( '<font color="blue">[no banners]</font>' );
}
return;
}
// do we need to display a particular banner?
if ( sShowBanner )
{
DebugOut ( '<font color="blue">' + nTopBanners + ' banners, showing ' + sShowBanner + '</font>' );
// search for the banner and display
for ( var i=0; i<nTopBanners; i++ )
{
var sBanner = Application ( 'TopBanner' + i );
if ( -1 != sBanner.indexOf ( sShowBanner ) )
{
Out ( sBanner );
return; // we're done
}
}
// if not found, continue to show the next available banner...
}
// increment banner counter
Application.Lock ( );
if ( ++Application ( 'CurrentTopBanner' ) >= nTopBanners )
Application ( 'CurrentTopBanner' ) = 0;
Application.Unlock ( );
// output banner html
Out ( Application ( 'TopBanner' + Application ( 'CurrentTopBanner' ) ) );
}
// ============================================
// show given number of affilate sites (that publish my articles)
// nNumberToDisplay specifies how many to display
// ============================================
function ShowAffiliates ( nNumberToDisplay )
{
// should we make a plain page for printing?
if ( bPlainJane )
{
Out ( ' ' );
return;
}
Out ( '<p><a href="/eu_url_httpwww.htmlconnections.comrefer.html" target="CYAexternal"><img src="images/affiliates/ASPNETConnections100x69.jpg" width="100" height="69" border="0"></a>' );
var nAffiliates = Application ( 'TotalAffiliates' );
if ( !nAffiliates )
{
DebugOut ( '<font color="blue">[no affiliates]</font>' );
}
else
{
// be safe!
if ( nNumberToDisplay > nAffiliates )
nNumberToDisplay = nAffiliates;
DebugOut ( '<font color="blue">' + nAffiliates + ' affiliates, showing ' + nNumberToDisplay + '</font>' );
// start from the next affiliate
var nNext = Application ( 'CurrentAffiliate' );
for ( var i=0; i<nNumberToDisplay; i++ )
{
// check for rollover
if ( nNext+i > nAffiliates-1 )
nNext = -i;
var nAffiliate = nNext + i;
DebugOut ( '<font color="blue">' + nAffiliate + ':</font>' );
// output banner image
Out ( '<p>' + Application ( 'Affiliate' + nAffiliate ) );
}
// move pointer to current affiliate
Application.Lock ( );
Application ( 'CurrentAffiliate' ) = nNext + nNumberToDisplay;
Application.Unlock ( );
}
}
// ============================================
// show given number of content items in random order
// nNumberToDisplay specifies how many to display
// ============================================
function ShowBanners ( nNumberToDisplay )
{
// should we make a plain page for printing?
if ( bPlainJane )
{
Out ( ' ' );
return;
}
// with new left navigation bar we always
// show a minimum of 4 banners
if ( nNumberToDisplay < 4 )
nNumberToDisplay = 4;
NavTableTop ( 'Featured sponsor' );
// show the next 125x125 advertiser banner at top
var nSideBanners = Application ( 'TotalSideBanners' );
if ( !nSideBanners )
{
if ( bDisplayAllianceBanners )
{
DebugOut ( '<font color="blue">showing ASPAlliance square</font>' );
Out ( '<center>' );
ShowAllianceAd ( 126, 1 );
Out ( '</center>' );
NavTableBottom ( );
NavTableTop ( 'My favorite resources' );
Out ( '<center>' );
// Out ('<h3><a href="http://www.royaltiki.com/" target="CYAexternal">Tiki Statues - Tiki Masks - Tiki Totems</a></h3><hr>');
DebugOut ( '<font color="blue">showing ASPAlliance textad</font>' );
ShowAllianceAd ( 100, 1 );
Out ( '</center>' );
// decrement number of rotating banners by one
if ( --nNumberToDisplay == 0 )
{
NavTableBottom ( );
return;
}
}
else
{
DebugOut ( '<font color="blue">[no banners]</font>' );
}
}
else
{
// increment banner counter
Application.Lock ( );
if ( ++Application ( 'CurrentSideBanner' ) >= nSideBanners )
Application ( 'CurrentSideBanner' ) = 0;
Application.Unlock ( );
// output banner html
Out ( '<center>' + Application ( 'SideBanner' + Application ( 'CurrentSideBanner' ) ) + '</center>' );
// decrement number of rotating banners by one
if ( --nNumberToDisplay == 0 )
{
NavTableBottom ( );
return;
}
}
if ( bDisplayAllianceBanners )
{
// show an ASPAlliance button
Out ( '<center>' );
Out ( '<p>' );
DebugOut ( '<font color="blue">showing ASPAlliance textad</font>' );
ShowAllianceAd ( 100, 2 );
Out ( '<p>' );
DebugOut ( '<font color="blue">showing ASPAlliance square</font>' );
ShowAllianceAd ( 125, 1 );
Out ( '<p>' );
Out ( '</center>' );
// decrement number of rotating banners by one
if ( --nNumberToDisplay == 0 )
{
NavTableBottom ( );
return;
}
}
// fill the remaining slots with my rotating side content
// how many banners do I have to choose from?
var nContent = Application ( 'TotalMyBanners' );
if ( !nContent )
{
DebugOut ( '<font color="blue">[no banners]</font>' );
return;
}
// be safe!
if ( nNumberToDisplay > nContent )
nNumberToDisplay = nContent;
// the random list of unique numbers
var nOrder = new Array ( nNumberToDisplay );
// an easy way to see if I've had this random number before
var bUsed = new Array ( nContent );
// the total number of random numbers I had to generate
var nLoops = 0;
for ( var i=0; i<nNumberToDisplay; i++ )
{
// generate a random number, and stay in loop until it's unique
// ========================================
// this loop should always quit on its own, but PLEASE remember
// to always write safe code rather than clever code! There are
// probably other sites on your server that you will hang up too.
//
// in this case I allow the loop to run 50 times, then I quit anyway
// ========================================
for ( var j=0; j<50; j++ )
{
// generate a random integer between 0 and nContent-1
nRandom = Math.floor ( Math.random () * nContent );
// increment our debug counter
nLoops++;
// have I used this number before?
if ( !bUsed [ nRandom ] )
{
bUsed [ nRandom ] = true;
break;
}
}
nOrder [ i ] = nRandom;
}
Out ( '<center>' );
// display the content in random order
for ( i=0; i<nNumberToDisplay; i++ )
Out ( Application ( 'MyBanner' + nOrder [ i ] ) + '<p>' );
if ( bDisplayAllianceBanners )
{
DebugOut ( '<font color="blue">showing ASPAlliance square</font>' );
ShowAllianceAd ( 125, 2 );
}
Out ( '</center>' );
// display the number of random numbers I had to waste!
DebugOut ( '<font color="blue">[I had to generate ' + (nLoops-nNumberToDisplay) + ' wasted numbers!]</font>' );
NavTableBottom ( );
}
// ============================================
// show the bottom banner
// ============================================
function ShowBottomBanner ( )
{
if ( bDisplayAllianceBanners )
{
DebugOut ( '<font color="blue">showing ASPAlliance 468 banner</font>' );
Out ( '<p align="center">' );
ShowAllianceAd ( 469, 1 );
Out ( '</p>' );
}
}
// ============================================
// show the next available advertisement
// ============================================
function ShowTestimonials ( )
{
// should we make a plain page for printing?
if ( bPlainJane )
{
Out ( ' ' );
return;
}
NavTableTop ( 'Testimonials' );
// put these into database later..
Out ( 'Some kind words from readers...' );
Out ( '<hr color="#ff9900"><i>"No book I have bought, or forum I have read can compare to the simplistic and clean hands on structure you have developed in your site which inspires learning. Truly genius. T.J."</i>' );
Out ( '<hr color="#ff9900"><i>"Just wanted to offer kudos for an application well done. I\'ve played around with other "complete" web sites like WebWrox and other such things, but they lacked polish. Yours kicks serious ass. S.C."</i>' );
Out ( '<hr color="#ff9900"><i>"All in all an excellent "how-to" site. R.A."</i>' );
Out ( '<hr color="#ff9900"><i>"I am really in awe of your site. It has everything that one can ask for. S.N."</i>' );
Out ( '<hr color="#ff9900"><i>"Wicked site by the way... L.W."</i>' );
Out ( '<hr color="#ff9900"><i>"Awesome site. Keep up the good work. J."</i>' );
NavTableBottom ( );
}
// ============================================
// show all affilates - used by Resource.asp
// ============================================
function DumpAffiliates ( )
{
// how many banners to loop through
var nAffiliates = Application ( 'TotalAffiliates' );
var nNext = Application ( 'CurrentAffiliate' );
for ( var i=0; i<nAffiliates; i++ )
{
// check for rollover
if ( nNext+i > nAffiliates-1 )
nNext = -i;
var nAffiliate = nNext + i;
// output banner image
Out ( Application ( 'Affiliate' + nAffiliate ) + ' ' );
}
// move pointer to current affiliate
Application.Lock ( );
Application ( 'CurrentAffiliate' ) = nNext + nAffiliates;
Application.Unlock ( );
}
// ============================================
// show all content in three columns - used by Resource.asp
// ============================================
function DumpContent ( )
{
// how many banners to loop through
var nContent = Application ( 'TotalMyBanners' );
Out ( '<table width="100%" border=0 cellpadding=10 cellspacing=0>' );
for ( var nRow=0; nRow < nContent; nRow+=3 )
{
Out ( '<tr>' );
for ( var nOffset=0; nOffset<3; nOffset++)
{
Out ( '<td width="33%" align="center" valign="top"><table width="152"><tr><td>' );
var nIndex = nRow + nOffset;
if ( nIndex < nContent )
Out ( Application ( 'MyBanner' + nIndex ) );
else
Out ( ' ' );
Out ( '</td></tr></table></td>' );
}
Out ( '</tr>' );
}
Out ( '</table>' );
}
// ============================================
// show an ASP Alliance ad
// ============================================
function ShowAllianceAd ( nWidth, nPage )
{
return;
// if the ads have to be taken offline, set this flag
var bOffline = false;
var nHeight;
var nType, sType;
switch ( nWidth )
{
case 469:
nType = 1; // was 7
nWidth = 468;
nHeight = 60;
sType = '468x60';
break;
case 468:
nType = 1;
nHeight = 60;
sType = '468x60';
break;
case 126:
nType = 5; // was 6;
nWidth = 125;
nHeight = 125;
sType = '125x125';
break;
case 125:
nType = 5;
nHeight = 125;
sType = '125x125';
break;
case 100:
nType = 2;
nHeight = 30;
sType = '';
break;
case 1:
nType = 2; // was 10
sType = '1x2';
break;
case 0:
nType = 3;
sType = '1x2';
break;
default:
return;
}
if ( bOffline )
{
Out ( '<table width="' + nWidth +'" height="' + nHeight + '"><tr><td>Ads offline</td></tr></table>' );
return;
}
if (sType == '')
return;
Out ( '<div class="lqm_ad" lqm_publisher="lqm.coveryourasp.site" lqm_zone="ron" lqm_format="' + sType + '"></div>' );
// Out ( '<script type="text/javascript">\n<!-- \nlqm_channel=1;\nlqm_publisher=6;\nlqm_zone=' + nPage + ';\nlqm_format=' + nType + ';\n//-->\n</script>\n' );
// Out ( '<script type="text/javascript" src="http://a.lakequincy.com/s.js"></script>' );
// Out ( '<iframe src="http://ads.aspalliance.com/displayad.aspx?m=6&t=' + nType + '&page=' + nPage + '&target=CYAexternal" width="' + nWidth +'" height="' + nHeight + '" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no">' );
// Out ( '<script language="javascript" src="http://ads.aspalliance.com/displayad.asp?m=6&t=' + nType + '&page=' + nPage + '&target=CYAexternal"></script>' );
// Out ( '</iframe>' );
}
%> |
utils/Init.asp<%
// ============================================
// NOTE: all source code downloaded from CoverYourASP was written by
// James Shaw (unless stated otherwise), and is copyright (c) 2000-2002
// by James Shaw. You can use the code for any purpose, but do not
// publish or distribute the content in any way.
//
// See http://CoverYourASP.com/Legal.asp for up-to-date details.
// ============================================
// ============================================
// the standard meta tags to start document
// ============================================
function Init ( sTitle, sKeywords )
{
// uncomment this line to redirect everyone to a maintainance page
// Redirect ( '/Maintainance.htm' );
// setup commonly used server variables
sServer = '' + Request.ServerVariables ( 'SERVER_NAME' );
sServer = sServer.toLowerCase ( );
sAgent = '' + Request.ServerVariables ( 'HTTP_USER_AGENT' );
sAgent = sAgent.toLowerCase ( );
// are we running on CoverYourASP server?
// (content changes if not, and not indexed by spiders)
bRunningOnCYA = ( -1 != sServer.indexOf ( 'coveryourasp.com' ) );
// now I'm going to test if I've been redirected from ShawThing.com
// and if so point them at the article explaining what happened!
bRefered = Request.QueryString ( 'FromShawThing' ).Count;
// if we're passed in 'plain' or 'print' in the querystring we'll make
// the page as plain as possible for printing
bPlainJane = Request.QueryString ( 'plain' ).Count + Request.QueryString ( 'print' ).Count;
if ( bPlainJane)
{
// check that a page on this site is asking for printer-friendly page
var sReferer = "" + Request.ServerVariables ( "HTTP_REFERER" );
if ( "undefined" != sReferer && sReferer.indexOf ( sServer ) <= 0 )
bPlainJane = false;
}
// if I'm not running on CoverYourASP server,
// or was a Shawthing page, tell spiders to please don't index
if ( !bRunningOnCYA || bReferred )
bAllowIndex = false;
// do anything that gets done once per day
BrandNewDay ( );
// redirect spiders used for offline browsing to a
// descriptive html page that points to the download
RedirectSpiders ( sAgent );
Out ( '<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">' );
Out ( '<html><head>' );
// set the base href for all relative URLs to
// the current server plus an optional offset
SetBaseHref ( );
// output meta tags
MetaTags ( sAgent, sKeywords );
// output title
Out ( '<title>' + sTitle +'</title>' );
// use some very basic cascading style sheets
Out ( '<style type="text/css"><!--\n' );
Out ( 'a:link { color:#FF3300; text-decoration:none; }' );
Out ( 'a:visited { color:#FF3300; text-decoration:none; }' );
Out ( 'a:hover, a:active { color:#CC0000; text-decoration:underline; }' );
Out ( 'td { font-family: Verdana, Tahoma, Arial, sans-serif; font-size: 11px; }' );
Out ( 'td.content { font-size: 13px; }' );
Out ( '//-->\n</style></head>' );
// use my quick and dirty article counter
IncrementArticleCounter ( );
}
// ============================================
// am I being run from a special debug URL?
// ============================================
var bDebug;
function IsDebug ( )
{
// for efficiency, only work out if I'm in debug mode
// the first time I'm used on a page.
if ( bDebug == undefined )
{
// the test can be if I'm on localhost (i.e. on development machine)
/*
var sServer = "" + Request.ServerVariables ( "SERVER_NAME" );
bDebug = ( -1 != sServer.indexOf ( "localhost" ) );
*/
//..or for demo purposes, if a certain QueryString exists
bDebug = ( 0 != Request.QueryString ( "debug" ).Count );
}
return bDebug;
}
// ============================================
// only display when in debug mode as defined in IsDebug() above
// ============================================
function DebugOut ( sHTML )
{
if ( !IsDebug () )
return;
Out ( sHTML );
}
// ============================================
// simple wrapper for Response.Write, although could be used to
// redirect content to a file for indexing (for example)
// ============================================
var nByteCount = 0;
function Out ( sHTML )
{
Response.Write ( sHTML );
/*
// as an experiment to find bug in IE, add cr/lf every 1k
nByteCount += sHTML.length;
if (nByteCount > 1000)
{
Response.Write('\r\n');
nByteCount = 0;
}*/
}
// ============================================
// get password from URL
// ============================================
function LookForMagicWord ( )
{
// simple password in URL to stop anyone from modifying database.
// it works very simply. if you add the password to the URL then you
// can do anything!
//
// the password is specified in include/config.asp
//
// assuming it is SECRET, and the page you are viewing is Test.asp
// you would use the URL Test.asp?SECRET=1
bValidUser = Request.QueryString ( sPassword ).Count;
// pass on the password to other pages automatically
if ( bValidUser )
sMagicWord = '&' + sPassword + '=1';
}
// ============================================
// use Response.Redirect or Server.Transfer depending on ASP version
// ============================================
function Redirect ( sDestination )
{
// use expensive round-trip redirect always
// Server.Transfer caused problems
Response.Redirect ( sDestination );
}
// ============================================
// returns string containing HTML for link to external site
// ============================================
function ExternalLink ( sURL, sTitle )
{
return '<a href="' + sURL + '" target="CYAexternal">' + sTitle + '</a>';
}
// ============================================
// redirect spiders used for offline browsing to a
// descriptive html page that points to the download
// ============================================
function RedirectSpiders ( sAgent )
{
var sCrawlers = new Array ( 'teleport', 'webcopier', 'offline explorer', 'flashget', 'httrack', 'webzip', 'webfountain', 'ecatch', 'openbot', 'wget' );
for ( var nAgentLoop=0; nAgentLoop<sCrawlers.length; nAgentLoop++)
if ( -1 != sAgent.indexOf ( sCrawlers [ nAgentLoop ] ) )
Redirect ( '/JustDownload.htm' );
}
// ============================================
// set the base href for all relative URLs to
// the current server plus an optional offset
// ============================================
function SetBaseHref ( )
{
// if running securely, use https://
var sRoot = '' + Request.ServerVariables ( 'HTTPS' );
var sBaseServer = 'http' + ( sRoot == 'on' ? 's' : '' ) + '://' + sServer;
// if running on non-standard port, use it
var nPort = Request.ServerVariables ( 'SERVER_PORT' ) - 0;
if ( nPort != 80 )
sBaseServer += ':' + nPort;
// test which URL I am running from
for ( var i=0; i<sURLTest.length; i++ )
{
if ( -1 != sBaseServer.indexOf ( sURLTest [ i ] ) )
{
// apply the offset if one given
if ( sURLOffset [ i ].length )
sBaseServer += '/' + sURLOffset [ i ];
break;
}
}
Out ( '<base href="' + sBaseServer + '/" target="_top">' );
}
// ============================================
// output meta tags
// ============================================
function MetaTags ( sAgent, sKeywords )
{
// meta tags applicable to all browsers
Out ( '<link rev=MADE href="mailto:[email protected]">' );
Out ( '<meta name="resource-type" content="document">' );
Out ( '<meta http-equiv="Content-Type" Content="text-html; charset=iso-8859-1">' );
Out ( '<meta http-equiv="PICS-Label" content=\'(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true for "http://CoverYourASP.com/" r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true for "http://CoverYourASP.com/" r (n 0 s 0 v 0 l 0))\'>' );
Out ( '<meta name="verify-v1" content="yyLqkV+qUz8TDpxokViWvtTuHhyGU+7gDjtc8usZB3A=" /> ' );
Out ( '<meta name="botwspider" />' );
// tell spiders whether they can index and follow links or not
if ( bAllowIndex )
Out ( '<meta name="robots" content="INDEX,FOLLOW">' );
else
Out ( '<meta name="robots" content="NOINDEX,NOFOLLOW">' );
// now meta tags specific to certain browsers
// for spiders only - I hide these lines from browsers
if ( IsDebug ( ) || !IsKnownBrowser ( sAgent ) )
{
// it's an unknown browser - maybe a spider
Out ( '<meta name="Keywords" content="' );
// add any passed-in keywords
if ( sKeywords != undefined )
Out ( sKeywords + ',' );
Out ( 'coveryourasp,cya,james shaw,asp,active server pages,active,server,pages,scripts,microsoft,iis,email,cdonts,form,access,database,free code,source,code,programmer,programming,developer,development,javascript,jscript,com,atl,c++' );
Out ( '"><meta name="Description" content="The site IS the content - download the entire source code of the site! Live examples of membership management, newsletter, online database add/edit/delete, yahoo-style categories and much more.">' );
Out ( '<meta name="revisit-after" content="10 days">' );
Out ( '<meta name="Author" content="James Shaw">' );
}
else
{
// it's a known browser - show "throwaway" keywords so I don't arouse suspicion!
Out ( '<meta name="Keywords" content="CoverYourASP,ASP">' );
Out ( '<meta name="Description" content="CoverYourASP - an Active Server Pages resource.">' );
}
}
// ============================================
// anything that needs doing once per day!
// ============================================
function BrandNewDay ( )
{
if ( Application ( 'BrandNewDay' ) == 1 )
{
// now set data into Application variables
Application.Lock ( );
// get date for use wherever 12/12/2000 format is needed
Application ( 'Date' ) = DBWrapDate ( FormatDateDMY ( new Date ) );
// clear the list if IP addresses that are ignored
Application ( 'ClickFromIP' ) = '';
Application ( 'BrandNewDay' ) = 0;
Application.Unlock ( );
// get todays banners
GetDaysBanners ( );
// send out email to unconfirmed members
RemindMembers ( );
}
}
// ============================================
// get the banners that will be shown today
// ============================================
function GetDaysBanners ( )
{
// get date for use wherever 12/12/2000 format is needed
var sDate = Application ( 'Date' );
// get current advertising banners into array
DBInitConnection ( );
DBGetRecords ( 'SELECT BannerID,BannerDescr,BannerURL FROM Banners WHERE ClicksLeft > 0' );
var sBanners = new Array;
var nBannerIDs = new Array;
var bSideBanners = new Array;
var nBanners = 0;
// loop through banners
while ( !oRecordSet.EOF )
{
var nBannerID = oRecordSet ( 0 ) - 0;
var sBannerDescr = '' + oRecordSet ( 1 );
var sBannerURL = '' + oRecordSet ( 2 );
// small image to track impressions first
var sBanner = '<img src="BannerCounter.asp?ID=' + nBannerID + '" border=0 width=1 height=1>';
// add URL (patched through our counter)
sBanner += '<a href="BannerCounter.asp?ID=' + nBannerID + '&CYAredir=' + Server.URLEncode ( sBannerURL ) + '" target="CYAExternal">'
// add gif image
sBanner += '<img src="images/ads/' + sBannerDescr + '.gif" border=0';
// if it starts with sm_ it's a small banner
// for the side of the page, not a 468x60
bSideBanners [ nBanners ] = ( 0 == sBannerDescr.indexOf ( 'sm_' ) );
if ( !bSideBanners [ nBanners ] )
sBanner += ' width=468 height=60';
sBanner += '></a>';
// store banner IDs for later use
nBannerIDs [ nBanners ] = nBannerID;
sBanners [ nBanners++ ] = sBanner + '<p>';
oRecordSet.moveNext ( );
}
// now create new entries in BannerStats table for today
for ( var i=0; i<nBanners; i++ )
{
// see if it already exists
DBGetRecords ( 'SELECT BannerID FROM BannerStats WHERE BannerDate=' + sDate + ' AND BannerID=' + nBannerIDs [ i ] );
// create it if it doesnt exist
if ( oRecordSet.EOF )
oConnection.Execute ( 'INSERT INTO BannerStats (BannerDate,BannerID) VALUES (' + sDate + ',' + nBannerIDs [ i ] + ')' );
}
// get my banners from database
var sMyBanners = new Array;
var nMyBanners = 0;
DBGetRecords ( 'SELECT BannerData FROM MyBanners' );
// loop through banners
while ( !oRecordSet.EOF )
{
sMyBanners [ nMyBanners++ ] = '' + oRecordSet ( 0 );
oRecordSet.moveNext ( );
}
// get my affiliates from database
var sAffiliates = new Array;
var nAffiliates = 0;
DBGetRecords ( 'SELECT AffiliateData FROM Affiliates' );
// loop through affiliates
while ( !oRecordSet.EOF )
{
var sData = '' + oRecordSet ( 0 );
// the data comes in this format: URL|image|description (description isn't currently used)
// so we split it into it's separate parts
var sParts = sData.split ( '|' );
// now make it back up into meaningful HTML
sAffiliates [ nAffiliates++ ] = '<a href="eu.asp?url=http://' + sParts [ 0 ] + '" target="CYAExternal"><img src="images/affiliates/' + sParts [ 1 ] + '" border="0" width="100" height="30"></a>';
oRecordSet.moveNext ( );
}
DBReleaseConnection ( );
// now set data into Application variables
Application.Lock ( );
var nTopBanners = 0;
var nSideBanners = 0;
for ( var i=0; i<nBanners; i++)
{
if ( bSideBanners [ i ] )
Application ( 'SideBanner' + nSideBanners++ ) = sBanners [ i ];
else
Application ( 'TopBanner' + nTopBanners++ ) = sBanners [ i ];
}
Application ( 'TotalTopBanners' ) = nTopBanners;
Application ( 'TotalSideBanners' ) = nSideBanners;
for ( var i=0; i<nMyBanners; i++)
Application ( 'MyBanner' + i ) = sMyBanners [ i ];
Application ( 'TotalMyBanners' ) = nMyBanners;
for ( var i=0; i<nAffiliates; i++)
Application ( 'Affiliate' + i ) = sAffiliates [ i ];
Application ( 'TotalAffiliates' ) = nAffiliates;
Application.Unlock ( );
}
// ============================================
// increment the article counter
// ============================================
function IncrementArticleCounter ( )
{
// get the name of myself (the asp file). it may have been set for us
// if I am viewing a "subpage" in an article. for example,
// GetNews2.asp sets the article page to GetNews.asp so I
// increment that counter.
if ( sIncArticlePage == undefined )
{
sIncArticlePage = "" + Request.ServerVariables ( 'SCRIPT_NAME' );
// strip off the folders (if there are any)
var nSlashPos = sIncArticlePage.lastIndexOf ( "/" );
if ( -1 != nSlashPos )
sIncArticlePage = sIncArticlePage.slice ( nSlashPos+1 );
}
// open the database
DBInitConnection ( );
Response.Write("<z"+sIncArticlePage+">");
// increment counter
if ( oConnection )
oConnection.Execute( 'UPDATE Articles SET Hits=Hits+1 WHERE URL=\'' + sIncArticlePage + '\'' );
// release the database asap
DBReleaseConnection ( );
}
// ============================================
// remind members that they haven't confirmed their email
// ============================================
function RemindMembers ( )
{
// get cutoff date, which is todays date - 10 days
var dCutoff = new Date;
var nDate = dCutoff.getDate ( ) - 10;
dCutoff.setDate ( nDate );
// get email date, which is todays date - 11 days
var dEmail = new Date;
dEmail.setDate ( nDate-1 );
nDate = dEmail.getDate ( );
// now get the members that are not confirmed after 10 days
DBInitConnection ( );
DBGetRecords ( 'SELECT MemberID,Email,Name,LastVisit FROM Members WHERE Confirmed=False AND LastVisit<=' + DBWrapDate ( FormatDateDMY ( dCutoff ) ) );
var sDelete = '';
while ( !oRecordSet.EOF )
{
var nID = oRecordSet ( 0 ) - 0;
var dDate = new Date ( oRecordSet ( 3 ) );
// either send an email, or delete them..
if ( dDate.getDate ( ) == nDate )
{
var sEmail = '' + oRecordSet ( 1 );
var sName = '' + oRecordSet ( 2 );
var sDate = FormatDateDMY ( dDate );
// send Email with our generic function
var sBody = 'Dear ' + sName + '\n\n';
sBody += 'Today is your last chance to confirm your membership on CoverYourASP.com!\n\n';
sBody += 'Membership accounts have to be confirmed via email - and unconfirmed accounts are only kept for 10 days. Since you registered on ' + sDate + ' your membership account will be deleted tomorrow unless you confirm your account.\n\n';
sBody += 'To confirm your CoverYourASP membership account please click on the link below, or copy and paste the entire URL into your browser.\n\n';
sBody += 'IMPORTANT: if the link below is wrapped onto two lines by your email software please copy from the "http" to the end of the number on the second line, then paste that into your browser.\n\n';
sBody += 'http://CoverYourASP.com/C.asp?a=a&e=' + sEmail + '&i=' + nID + '\n\n';
sBody += 'I hope to hear back from you soon!\n\n';
sBody += 'Member Services\n';
sBody += '[email protected]\n';
sBody += 'http://CoverYourASP.com/';
if ( -1 == sServer.indexOf ( 'localhost' ) )
SendEmail ( 'MemberServices@' + sHostDomain, sEmail, 'MemberServices@' + sHostDomain, 'Final Notice: Lapsing CoverYourASP membership', sBody );
}
else
{
if ( sDelete.length )
sDelete += ' OR ';
sDelete += 'MemberID=' + nID;
}
oRecordSet.moveNext ( );
}
if ( sDelete.length )
oConnection.Execute ( 'DELETE FROM Members WHERE ' + sDelete );
DBReleaseConnection ( );
}
%> |
Hopefully much of this is self-explanatory. If not, or if you see ways that I can improve the code, please drop me a line. To see the source code for this page, click on the icon below. | |