| This page shows the actual source code used on this site. 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... |
utils/Personalize.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.
// ============================================
// declare enums for ShowArticles ( )
var nByDate = 217;
var nByHits = 233;
var nByCategory = 723;
// ============================================
// introduction
// ============================================
function ShowIntro ( )
{
ContentTableTop ( 'Introduction' );
Out ( '<a href="/AboutASP.html">Active Server Pages</a> is fun! If you want to know how to use ASP to create a dynamic web site, you\'ve come to the right place.' );
Out ( '<p>You can <a href="/CYA.html">download</a> <i>all</i> the source code for this site, FREE. The site is completely self-documenting - every article describes how the site was written and introduces you to <a href="/DBAdmin.html">databases</a>, <a href="/Forms.html">forms</a>, <a href="/ContactDescr.html">email components</a> and all the other things you probably want to do. <a href="/AboutCYA.html">More...</a>' );
ContentTableBottom ( );
}
// ============================================
// suggested links
// ============================================
function ShowSuggestions ( )
{
ContentTableTop ( 'My personal favorites - a good place to start...' );
Out ( '<table><tr>' );
Out ( '<td width="50%" align="center" valign="top">' );
Out ( '<h3>New to ASP?</h3>' );
Out ( '<table>' );
Out ( '<tr><td align="left">• <a href="/AboutASP.html">Getting started - what is ASP?</a></td></tr>' );
Out ( '<tr><td align="left">• <a href="/PWS.html">Running ASP on your home PC</a></td></tr>' );
Out ( '<tr><td align="left">• <a href="/MetaTags.html">A simple example: Hiding your META tags</a></td></tr>' );
Out ( '<tr><td align="left">• <a href="/ContactDescr.html">Getting feedback emails from a <form></a></td></tr>' );
Out ( '<tr><td align="left">• <a href="/Diary.html">Display data from a database - my diary</a></td></tr>' );
Out ( '<tr><td align="left">• <a href="/WalkFolders.html">Walk through your files and folders</a></td></tr>' );
Out ( '<tr><td align="left">• <a href="/Columns.html">Implement Yahoo-style categories</a></td></tr>' );
Out ( '<tr><td align="left">• <a href="/CreditCards.html">Accept credit cards with ASP</a></td></tr>' );
Out ( '</table>' );
Out ( '</td>' );
Out ( '<td width="1" bgcolor="ff9900"> </td>' );
Out ( '<td width="50%" align="center" valign="top">' );
Out ( '<h3>Want the good stuff?</h3>' );
Out ( '<table>' );
Out ( '<tr><td align="left">• <a href="/DownloadCYA.html">Download the code for the entire site</a></td></tr>' );
Out ( '<tr><td align="left">• <a href="/DBAdmin.html">Administer your database online</a></td></tr>' );
Out ( '<tr><td align="left">• <a href="/MemberCode.html">The CoverYourASP membership system</a></td></tr>' );
Out ( '<tr><td align="left">• <a href="/BannerApp.html">A complete banner advertising system</a></td></tr>' );
Out ( '<tr><td align="left">• <a href="/DontRender.html">Using <% %> correctly in ASP</a></td></tr>' );
Out ( '<tr><td align="left">• <a href="/ValidateEmail.html">Validate your email addresses</a></td></tr>' );
Out ( '<tr><td align="left">• <a href="/DBException.html">Exception handling</a></td></tr>' );
Out ( '<tr><td align="left">• <a href="/SurveyDescr.html">Database-driven surveys with one function</a></td></tr>' );
Out ( '</table>' );
Out ( '</td>' );
Out ( '</tr></table>' );
ContentTableBottom ( );
}
// ============================================
// links to hidden content
// ============================================
function ShowHidden ( )
{
ContentTableTop ( 'Personalize this page' );
// show links to content if any is not shown
// because of personalization settings
// (ignore the intro though)
if ( !bDiary || !bSuggestions || !nNew || !nPopular || !bCategories || !bNews || !nNewSnippets || !nPopularSnippets )
{
if ( !IsLoggedIn ( ) )
{
Out ( '<b>Did you know?</b> You can choose the content on this page when you <a href="/MemberLogin.html">sign in as a member</a> - it\'s free to join, no personal info, no spam!' );
Out ( '<p><b>More great stuff:</b>' );
}
else
{
Out ( '<p>Content you\'ve hidden:<br>' );
}
if ( !bDiary )
Out ( ' <a href="AllContent.asp?Diary">The Diary</a>' );
if ( !bSuggestions )
Out ( ' <a href="AllContent.asp?Suggestions">Suggested articles</a>' );
if ( !nNew )
Out ( ' <a href="AllContent.asp?New">What\'s New?</a>' );
if ( !nPopular )
Out ( ' <a href="AllContent.asp?Popular">What\'s Popular</a>' );
if ( !bCategories )
Out ( ' <a href="AllContent.asp?Categories">Article by Category</a>' );
if ( !nNewSnippets )
Out ( ' <a href="AllContent.asp?NewSnippets">New snippets</a>' );
if ( !nPopularSnippets )
Out ( ' <a href="AllContent.asp?PopularSnippets">Popular snippets</a>' );
if ( !bNews )
Out ( ' <a href="AllContent.asp?News">ASPWire News</a>' );
}
else
{
// has anything been personalized?
if ( IsLoggedIn ( ) && nNew == 3 && nPopular == 3 && nNewSnippets == 5 && nPopularSnippets == 0 )
Out ( '<p><center><a href="/Personalize.html">Make your life easier at CoverYourASP - personalize the site!</a></center>' );
}
ContentTableBottom ( );
}
// ============================================
// diary - assume DBInitConnection called already
// ============================================
function ShowDiary ( )
{
ContentTableTop ( 'The Diary - bug fixes, thoughts, hints and tips... <a href="/Diary.html"><font color="black">(how is this done?)</font></a>' );
// the diary section - thoughts and fixes
if ( -1 != sAgent.indexOf ( 'msie 6' ) && '' != Request.QueryString ( 'ShowIE6' ) )
{
// buggy IE6: Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.0; .NET CLR 1.0.2914)
// released IE6: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.2914)
InlineDiary ( );
}
else
{
Out ( '<iframe src="/ShowDiary.html" width="100%" height="150" marginheight="0" marginwidth="0">' );
Out ( '[Your user agent does not support frames or is currently configured not to display frames. However, you may visit <A href="/ShowDiary.html">the related document.</A>]' );
Out ( '</iframe>' );
}
ContentTableBottom ( );
}
// ============================================
// show diary entries inline if iframe not supported
// ============================================
function InlineDiary ( )
{
DBGetRecords ( 'SELECT TOP 2 DiaryDate,Entry FROM Diary ORDER BY DiaryDate DESC' );
// find anything?
if ( !oRecordSet.EOF )
{
var sLastDate;
while ( !oRecordSet.EOF )
{
var sDate = FormatDateDM ( oRecordSet ( 0 ) );
// show date if it's changed
if ( sDate != sLastDate )
{
if ( sLastDate != undefined )
Out ( '</td></tr></table><hr color="#ff9900">' );
Out ( '<table border=0 cellpadding=3>' );
Out ( '<tr><td><b>' + sDate + '</b></td></tr>' );
Out ( '<tr><td>' );
sLastDate = sDate;
}
else
{
Out ( '<p>• ' );
}
Out ( oRecordSet ( 1 ) + '<br>' );
oRecordSet.MoveNext();
}
if ( sLastDate != undefined )
{
Out ( '<p><a href="/ShowDiary.html">View the diary for the last month..</a> <a href="ShowDiary.asp?all=1">View entire diary..</a>' );
Out ( '</td></tr></table>' );
}
}
}
// ============================================
// articles by date
// ============================================
function ShowNew ( nShowNew )
{
// the what's new section - the last articles to be published
ShowArticles ( 'What\'s new? The articles I\'ve been working on recently...', nByDate, nShowNew );
}
// ============================================
// articles by hits
// ============================================
function ShowPopular ( nShowPopular )
{
// the what's popular section - the most popular articles
ShowArticles ( 'What\'s popular? Read what your peers think is most interesting!', nByHits, nShowPopular );
}
// ============================================
// articles by category
// ============================================
function ShowCategories ( )
{
ShowArticles ( 'Articles by category', nByCategory );
}
// ============================================
// snippets by date
// ============================================
function ShowNewSnippets ( nShowNew )
{
// the what's new section - the last articles to be published
ShowSnippets ( 'New snippets...', nByDate, nShowNew );
}
// ============================================
// snippets by hits
// ============================================
function ShowPopularSnippets ( nShowPopular )
{
// the what's popular section - the most popular articles
ShowSnippets ( 'Popular snippets...', nByHits, nShowPopular );
}
// ============================================
// Aspin categories + ASPWire news feed
// ============================================
function ShowASPExternal ( )
{
Out ( '<a name="News"></a>' );
ContentTableTop ( 'The most up to date ASP news from all over the web...' );
Out ( '<table width="100%" cellpadding="3" border="0" align="center">' );
Out ( '<tr><td width="50%" nowrap valign="top">' );
Out ( '<a href="/eu_url_httpcoveryourasp.htmlin.comhomewebapps.html"><b>Applications</b></a><br>' );
Out ( '<i><a href="/eu_url_httpcoveryourasp.htmlin.comhomewebappsadmanage.html">Ad Manager</a>, <a href="/eu_url_httpcoveryourasp.htmlin.comhomewebappsbbs.html"> BBS</a>, ...</i><br><br>' );
Out ( '<a href="/eu_url_httpcoveryourasp.411asp.net.html"><b>ASP.NET Directory</b></a><br><i><a href="/eu_url_httpcoveryourasp.411asp.nethomewebapps.html">Apps</a>, <a href="/eu_url_httpcoveryourasp.411asp.nethomecomponents.html"> Assemblies</a>, ...</i><br><br>' );
Out ( '<a href="/eu_url_httpcoveryourasp.htmlin.comhomebooks.html"><b>Books & Media</b></a><br>' );
Out ( '<i><a href="/eu_url_httpcoveryourasp.htmlin.comhomebooksasp.html">ASP</a>, <a href="/eu_url_httpcoveryourasp.htmlin.comhomebookscomponen.html">Components</a>, <a href="/eu_url_httpcoveryourasp.htmlin.comhomebooksdatabase.html">Db</a>, ...</i><br><br>' );
Out ( '<a href="/eu_url_httpcoveryourasp.htmlin.comhomecommunity.html"><b>Community</b></a><br>' );
Out ( '<i><a href="/eu_url_httpcoveryourasp.htmlin.comhomecommunityaspclass.html">Classes</a>, <a href="/eu_url_httpcoveryourasp.htmlin.comhomecommunityconferen.html">Conferences</a>, ...</i><br><br>' );
Out ( '<a href="/eu_url_httpcoveryourasp.htmlin.comhomecomponents.html"><b>Components</b></a><br>' );
Out ( '<i><a href="/eu_url_httpcoveryourasp.htmlin.comhomecomponentsbrowser.html">Browser Utilities</a>, <a href="/eu_url_httpcoveryourasp.htmlin.comhomecomponentsbbs.html"> BBS</a>, ...</i>' );
Out ( '</td><td width="50%" nowrap valign="top">' );
Out ( '<a href="/eu_url_httpcoveryourasp.htmlin.comhomesites.html"><b>Other ASP Sites</b></a> <br>' );
Out ( '<i><a href="/eu_url_httpcoveryourasp.htmlin.comhomesitesaspdev.html">Developers</a>, <a href="/eu_url_httpcoveryourasp.htmlin.comhomesitesasphosts.html"> Hosts</a>, ...</i><br><br>' );
Out ( '<a href="/eu_url_httpcoveryourasp.htmlin.comhomereferences.html"><b>References</b></a><br>' );
Out ( '<i><a href="/eu_url_httpcoveryourasp.htmlin.comhomereferencescasestud.html">Case Studies</a>, <a href="/eu_url_httpcoveryourasp.htmlin.comhomereferencesdatabase.html">Db</a>, ...</i><br><br>' );
Out ( '<a href="/eu_url_httpcoveryourasp.htmlin.comhomesoftware.html"><b>Software & Server</b></a><br>' );
Out ( '<i><a href="/eu_url_httpcoveryourasp.htmlin.comhomesoftwareapplicat.html">Application Servers</a>, ...</i><br><br>' );
Out ( '<a href="/eu_url_httpcoveryourasp.htmlin.comhometutorial.html"><b> Tutorials & Code</b></a><br>' );
Out ( '<i><a href="/eu_url_httpcoveryourasp.htmlin.comhometutorialapplicat.html">Application Making</a>, ...</i><br><br>' );
Out ( '<b>Powered By:</b> <br><a href="/eu_url_httpwww.htmlin.com.html"><img align="textTop" border="0" height="30" src="http://coveryourasp.aspin.com/images/aspin/cobrand/aspin_cob.gif" width="130"></a>' );
Out ( '</td></tr>' );
Out ( '</table><p><hr color="#ff9900">' );
ShowNews();
ContentTableBottom ( );
}
// ============================================
// show the articles table ordered by various methods
// ============================================
function ShowArticles ( sTitle, nSortBy, nNumber )
{
var sSortBy;
var bShowFullDescr;
var bMouseOver = false; // set to true to add descriptions to category links
switch ( nSortBy )
{
case nByDate:
sSortBy = 'UpdateDate DESC';
bShowFullDescr = true;
break;
case nByHits:
sSortBy = 'Hits DESC';
bShowFullDescr = true;
break;
case nByCategory:
sSortBy = 'Category,ShortDescr';
bShowFullDescr = false;
if ( bMouseOver )
sTitle += ' - hover mouse to get description!';
break;
default:
return;
}
DBGetRecords ( 'SELECT Category,PublishDate,UpdateDate,ShortDescr,LongDescr,URL,Hits FROM Articles ORDER BY ' + sSortBy );
// find anything?
if ( !oRecordSet.EOF )
{
ContentTableTop ( sTitle );
Out ( '<table>' );
if ( bShowFullDescr )
{
var i = 0;
while ( !oRecordSet.EOF && i++ < nNumber )
{
// the category (strip off first two chars used for sorting)
var sCategory = "" + oRecordSet ( 0 );
sCategory = sCategory.slice ( 2 );
// the description (strip off first two chars used for sorting)
var sDescription = "" + oRecordSet ( 3 );
sDescription = sDescription.slice ( 2 );
Out ( '<tr><td>' );
// the short description of the article, as a hyperlink
Out ( '<b><a href="' + oRecordSet ( 5 ) + '">' + sDescription + '</a></b>' );
Out ( '</td></tr>' );
Out ( '<tr><td>' );
Out ( '<table cellpadding=3>' );
Out ( '<tr><td>' );
// the long description of the article
Out ( '' + oRecordSet ( 4 ) );
Out ( '</td></tr>' );
// show footer (category, date, hits)
Out ( '<tr><td>' );
// the category
Out ( '<i>From <b>' + sCategory + '</b>, ' );
// the date last updated, or the date first published
if ( oRecordSet ( 2 ) > oRecordSet ( 1 ) )
Out ( 'updated ' + FormatDateDM ( oRecordSet ( 2 ) ) );
else
Out ( 'published ' + FormatDateDM ( oRecordSet ( 1 ) ) );
// number of times viewed
Out ( ', ' + oRecordSet ( 6 ) + ' views</i>' );
Out ( '</td></tr>' );
Out ( '</table><hr color="#ff9900">' );
Out ( '</td></tr>' );
oRecordSet.MoveNext();
}
if ( oRecordSet.EOF )
bShowFullDescr = false;
}
else
{
var sLastCategory;
while ( !oRecordSet.EOF )
{
// the category (strip off first two chars used for sorting)
var sCategory = "" + oRecordSet ( 0 );
sCategory = sCategory.slice ( 2 );
// show category if it's changed
if ( sCategory != sLastCategory )
{
Out ( '</td></tr>' );
Out ( '<tr bgcolor="#ff9900"><td>' + sCategory + '<br></td></tr>' );
Out ( '<tr><td>' );
sLastCategory = sCategory;
}
// the description (strip off first two chars used for sorting)
var sDescription = "" + oRecordSet ( 3 );
sDescription = sDescription.slice ( 2 );
// mouseover text - uses title attribute to
// display full description on hyperlink
var sMouseOver = '';
if ( bMouseOver )
sMouseOver = ' title="' + oRecordSet ( 4 ) + ' - ' + oRecordSet ( 6 ) + ' views"';
// the short description of the article, as a hyperlink
Out ( '• <a href="' + oRecordSet ( 5 ) + '"' + sMouseOver + '>' + sDescription + '</a><br>' );
oRecordSet.MoveNext();
}
Out ( '</td></tr>' );
}
Out ( '</table>' );
if ( bShowFullDescr )
Out ( '<a href="/AllArticles.html">See a complete list of all my articles...</a>' );
ContentTableBottom ( );
}
}
// ============================================
// show snippets ordered by various methods
// ============================================
function ShowSnippets ( sTitle, nSortBy, nNumber )
{
var sSortBy;
var bShowFullDescr;
switch ( nSortBy )
{
case nByDate:
sSortBy = 'PublishDate DESC';
bShowFullDescr = true;
break;
case nByHits:
sSortBy = 'Hits DESC';
bShowFullDescr = true;
break;
default:
return;
}
DBGetRecords ( 'SELECT SnippetID,PublishDate,Title,Hits FROM Snippets ORDER BY ' + sSortBy );
// find anything?
if ( !oRecordSet.EOF )
{
ContentTableTop ( sTitle );
Out ( '<table>' );
var i = 0;
while ( !oRecordSet.EOF && i++ < nNumber )
{
Out ( '<tr><td>' );
if ( nSortBy == nByDate )
Out ( FormatDateDM ( oRecordSet ( 1 ) ) + ':' );
else
Out ( oRecordSet ( 3 ) + ' views:' );
Out ( '</td><td>' );
// the title of the snippet, as a hyperlink
Out ( '<b><a href="Snippet.asp?snip=' + oRecordSet ( 0 ) + '">' + oRecordSet ( 2 ) + '</a></b>' );
Out ( '</td></tr>' );
oRecordSet.MoveNext();
}
if ( oRecordSet.EOF )
bShowFullDescr = false;
Out ( '</table>' );
ContentTableBottom ( );
}
if ( bShowFullDescr )
Out ( '<a href="AllSnippets.asp">See a complete list of all my snippets...</a>' );
}
%> |
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. | |