| 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... |
BannerReports.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.
// ============================================
// increment the parent articles counter
sIncArticlePage = '/Advertise.html';
// get password from URL - see utils/Init.asp
LookForMagicWord ( );
// output relevant meta tags
Init( "Banner Reports" );
// output common top of page
Header( 'Banner reports' );
// output page content
Content ( );
// output common bottom of page
Footer( );
// ============================================
// the content of this page
// ============================================
function Content ( )
{
Out ( '<td colspan=2 width="80%" valign="top" class="content">' );
// as always, the form is submitted to the same page so that
// all the logic for the form is in the same place. you'll see
// later where this is done.
Out ( 'The number of clicks shown here will almost certainly be less than what your site receives. I only log clicks from well-known browsers, so spiders will not "waste" the clickthroughs you\'ve purchased. Also, only one clickthrough will be registered per IP address per day. <a href="/LimitIP.html">See how.</a>' );
// which reports should I see?
// - I can see everything
// - an advertiser (member level = 4) can see his
// - everyone else can see the demo reports
var sWhere;
var bAllowMove = false;
if ( bValidUser )
{
// I can see everything
sWhere = '1';
bAllowMove = true;
}
else
{
// I show a demo report if the member isn't an advertiser
sWhere = 'Banners.MemberID=';
if ( nMemberLevel != 4 )
{
sWhere += '1';
}
else
{
sWhere += nMemberID;
bAllowMove = true;
}
}
// data from form if submitted
var sReportButton = ' Get Report ';
var sMoveButton = ' Move clicks ';
var sAction = '';
// do any processing required from form
if ( Request.Form.Count )
{
sAction = '' + Request.Form ( 'action' );
if ( bAllowMove && sAction == sMoveButton )
{
var nMove = Request.Form ( 'clicks' ) - 0;
if ( nMove > 0 )
{
var nFromID = Request.Form ( 'movefrom' ) - 0;
var nToID = Request.Form ( 'moveto' ) - 0;
// lets move the clicks - a perfect example of what
// I should (but don't) use transactions for
DBInitConnection ( );
DBGetRecords ( 'SELECT ClicksLeft FROM Banners WHERE BannerID=' + nFromID );
// make sure I don't move too many
var nMax = oRecordSet ( 0 ) - 0;
if ( nMove > nMax )
nMove = nMax;
// subtract first
oConnection.Execute ( 'UPDATE Banners SET ClicksLeft=ClicksLeft-' + nMove + ' WHERE BannerID=' + nFromID );
// now add to other banner
oConnection.Execute ( 'UPDATE Banners SET ClicksLeft=ClicksLeft+' + nMove + ' WHERE BannerID=' + nToID );
// release database
DBReleaseConnection ( );
// reload the banners in case they've changed
GetDaysBanners ( );
}
}
}
// show the relevant table of results
if ( sAction == sReportButton )
{
var sStart = Request.Form ( 'startmonth' ) + '/' +Request.Form ( 'startdate' ) + '/' + Request.Form ( 'startyear' );
var sEnd = Request.Form ( 'endmonth' ) + '/' + Request.Form ( 'enddate' ) + '/' + Request.Form ( 'endyear' );
var nBannerID = Request.Form ( 'report' ) - 0;
// connect to database
DBInitConnection ( );
DBGetRecords ( 'SELECT Banners.BannerDescr, BannerDate, ImpressionCount, ClickCount, [ClickCount]*100/[ImpressionCount] AS Rate FROM BannerStats INNER JOIN Banners ON BannerStats.BannerID = Banners.BannerID WHERE ' + sWhere + ' AND BannerStats.BannerID=' + nBannerID + ' AND BannerDate>=' + DBWrapDate ( sStart )+ ' AND BannerDate<=' + DBWrapDate ( sEnd ) + ' GROUP BY Banners.BannerDescr, BannerStats.BannerDate, BannerStats.ImpressionCount, BannerStats.ClickCount' );
if ( oRecordSet.EOF )
{
Out ( '<h4>[ No data between ' + sStart + ' and ' + sEnd + ' ]</h4>' );
}
else
{
// use extremely fast GetString function instead of moveNext ( )
var sData = oRecordSet.GetString ( 2, -1, '</td><td>', '</td></tr><tr><td>', '(null)' );
// now get the totals
DBGetRecords ( 'SELECT Sum(ImpressionCount) AS TotalImpressions, Sum(ClickCount) AS TotalClicks FROM BannerStats INNER JOIN Banners ON BannerStats.BannerID = Banners.BannerID WHERE ' + sWhere + ' AND BannerStats.BannerID=' + nBannerID + ' AND BannerDate>=' + DBWrapDate ( sStart )+ ' AND BannerDate<=' + DBWrapDate ( sEnd ) );
var sTotals = '<tr bgcolor="#dddddd"><td> </td><td> </td><td>' + oRecordSet ( 0 ) + '</td><td>' + oRecordSet ( 1 ) + '</td><td> </td></tr>';
// release database
DBReleaseConnection ( );
Out ( '<h4>Banner Summary by day</h4>' );
Out ( '<table border=1 cellpadding=5>' );
// output table heading
Out ( '<tr bgcolor="#dddddd"><td>Banner</td><td>Date</td><td>Impressions</td><td>Clicks</td><td>Click rate</td></tr>' );
// output rest of the rows!
Out ( '<tr><td>' + sData + '</td></tr>' );
// output totals
Out ( sTotals );
Out ( '</table>' );
}
}
else
{
// connect to database
DBInitConnection ( );
/*
DBGetRecords ( 'SELECT V.*, V.TotalClicks*100.0/V.TotalImpressions AS Rate FROM ( SELECT Banners.BannerDescr, Min(BannerDate) AS StartDate, Max(BannerDate) AS EndDate, Sum(ImpressionCount) AS TotalImpressions, Sum(ClickCount) AS TotalClicks, Banners.ClicksLeft FROM BannerStats INNER JOIN Banners ON BannerStats.BannerID = Banners.BannerID WHERE ' + sWhere + ' GROUP BY Banners.BannerDescr, Banners.ClicksLeft ) AS V' );
*/
// get banner summary
DBGetRecords ( 'SELECT Banners.BannerDescr, Min(BannerDate) AS StartDate, Max(BannerDate) AS EndDate, Sum(ImpressionCount) AS TotalImpressions, Sum(ClickCount) AS TotalClicks, Banners.ClicksLeft, Round([TotalClicks]*100/[TotalImpressions],2) AS Rate, Round(([ClicksLeft]/[Rate]*100.0)*([EndDate]-[StartDate])/TotalImpressions,0) AS DaysLeft FROM BannerStats INNER JOIN Banners ON BannerStats.BannerID = Banners.BannerID WHERE ' + sWhere + ' GROUP BY Banners.BannerDescr, Banners.ClicksLeft' );
if ( oRecordSet.EOF )
{
Out ( '<h4>[No banner data found]</h4>' );
}
else
{
// use extremely fast GetString function instead of moveNext ( )
var sData = oRecordSet.GetString ( 2, -1, '</td><td>', '</td></tr><tr><td>', '(null)' );
// release database
DBReleaseConnection ( );
Out ( '<h4>Banner Summary</h4>' );
Out ( '<table border=1 cellpadding=5>' );
// output table heading
Out ( '<tr bgcolor="#dddddd"><td>Banner</td><td>Start date</td><td>End date</td><td>Impressions</td><td>Clicks</td><td>Clicks left</td><td>Click rate</td><td>Days left</td></tr>' );
// output the rest of the rows!
Out ( '<tr><td>' + sData + '</td></tr>' );
Out ( '</table>' );
}
}
// fill drop down box with available banners
var sDropDown = '';
// connect to database
DBInitConnection ( );
// get list of banners
DBGetRecords ( 'SELECT BannerID,BannerDescr FROM Banners WHERE ' + sWhere );
while ( !oRecordSet.EOF )
{
sDropDown += '<option value="' + oRecordSet ( 0 ) + '">' + oRecordSet ( 1 ) + '</option>';
oRecordSet.moveNext ( );
}
// release database
DBReleaseConnection ( );
// here's the form tag. the action attribute is the name of
// the file that will be called with the answer - in this case
// it's the same page. the method can be "post" to send the
// form data 'behind the scenes' or "get" to appending the
// data to the URL in the style page.asp?data1=a&data2=b
//
// use post most of the time - it's neater and "get" is limited
// in the amount of data that can be sent.
Out ( '<form action="BannerReports.asp?pad=1' + sMagicWord + '" method="post">' );
// this table holds the two forms
Out ( '<table border="1" cellpadding="10">' );
Out ( '<tr bgcolor="#dddddd"><td align="center"><b>Get "Banner by Day" Report</b></td><td align="center"><b>Move clicks between banners</b></td></tr>' );
Out ( '<tr><td align="center">' );
// another table to line up the titles and inputs
Out ( '<table border="0" cellpadding="0">' );
Out ( '<tr><td align="right">' );
Out ( 'Banner:' );
Out ( '</td><td align="left">' );
Out ( '<select name="report" size="1">' );
Out ( sDropDown );
Out ( '</select>' );
Out ( '</td></tr>' );
Out ( '<tr><td align="right">' );
Out ( 'Start date:' );
Out ( '</td><td align="left">' );
DateFields ( 'start' );
Out ( '</td></tr>' );
Out ( '<tr><td align="right">' );
Out ( 'End date:' );
Out ( '</td><td align="left">' );
DateFields ( 'end' );
Out ( '</td></tr>' );
Out ( '<tr><td align="right">' );
Out ( ' ' );
Out ( '</td><td align="left">' );
// type='submit" provides a submit button to perform the
// form action. the button says "Submit" unless you override
// with the value attribute.
Out ( '<input type="submit" name="action" value="' + sReportButton + '">' );
Out ( '</td></tr>' );
Out ( '</table>' );
Out ( '</td><td align="center">' );
Out ( '<table border="0" cellpadding="0">' );
Out ( '<tr><td align="right">' );
Out ( 'Move from:' );
Out ( '</td><td align="left">' );
Out ( '<select name="movefrom" size="1">' );
Out ( sDropDown );
Out ( '</select>' );
Out ( '</td></tr>' );
Out ( '<tr><td align="right">' );
Out ( 'Move to:' );
Out ( '</td><td align="left">' );
Out ( '<select name="moveto" size="1">' );
Out ( sDropDown );
Out ( '</select>' );
Out ( '</td></tr>' );
Out ( '<tr><td align="right">' );
Out ( 'Clicks to move:' );
Out ( '</td><td align="left">' );
Out ( '<input type="text" name="clicks">' );
Out ( '</td></tr>' );
Out ( '<tr><td align="right">' );
Out ( ' ' );
Out ( '</td><td align="left">' );
// type='submit" provides a submit button to perform the
// form action. the button says "Submit" unless you override
// with the value attribute.
Out ( '<input type="submit" name="action" value="' + sMoveButton + '">' );
Out ( '</td></tr>' );
Out ( '</table>' );
Out ( '</td></tr>' );
Out ( '</table>' );
Out ( '</form>' );
Out ( '<p>Do you want to see how this form reports data from my database?<br>All the source code is just a click away!' );
Out ( '<p><center><a href="/ShowSource_page_BannerReports.html"><img src="/images/source.gif" border=0></a></center>' );
Out ( '</td>' );
}
// ============================================
// output fields for selecting date
// ============================================
function DateFields ( sPrefix )
{
var date = new Date;
// date
Out ( '<select name="' + sPrefix + 'date" size="1">' );
for ( var i=1; i<32; i++ )
Out ( '<option ' + ( i==date.getDate ( ) ? 'selected ' : '' ) + 'value="' + i + '">' + i + '</option>' );
Out ( '</select>' );
// month
Out ( '<select name="' + sPrefix + 'month" size="1">' );
for ( var i=0; i<12; i++ )
Out ( '<option ' + ( i==date.getMonth ( ) ? 'selected ' : '' ) + 'value="' + (i+1) + '">' + sMonths [ i ] + '</option>' );
Out ( '</select>' );
// year
Out ( '<select name="' + sPrefix + 'year" size="1">' );
for ( var i=2000; i<2005; i++ )
Out ( '<option ' + ( i==date.getFullYear ( ) ? 'selected ' : '' ) + 'value="' + i + '">' + i + '</option>' );
Out ( '</select>' );
}
%> |
utils/Database.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.
// ============================================
// globals
var oConnection;
var oRecordSet;
// enums
// Connection.State and Recordset.State property
var adStateClosed = 0; // the object is closed.
var adStateOpen = 1; // the object is open.
var adStateConnecting = 2; // the object is connecting.
var adStateExecuting = 4; // the object is executing a command.
var adStateFetching = 8; // the rows of the object are being fetched.
// Recordset.Cursor property
var adOpenUnspecified = -1; // does not specify the type of cursor.
var adOpenForwardOnly = 0; // (default) a forward-only cursor, i.e. you get only one pass thru the data!
var adOpenKeyset = 1; // can go in any direction, and as a bonus you'll see changes other users make. EXPENSIVE!
var adOpenDynamic = 2; // as Keyset, but also you can see additions/deletions other users make. EXPENSIVE!
var adOpenStatic = 3; // can go in any direction, but read-only.
// Recordset.LockType property
var adLockUnspecified = -1; // does not specify a type of lock.
var adLockReadOnly = 1; // (default) guess!
var adLockPessimistic = 2; // guaranteed to work
var adLockOptimistic = 3; // records locked only when you call Update. fingers crossed
var adLockBatchOptimistic = 4;// required for batch update mode
var adCmdUnspecified = -1; // Does not specify the command type argument.
var adCmdUnknown = 8; // Default. Indicates that the type of command in the CommandText property is not known.
var adCmdText = 1; // a textual definition of a command or stored procedure call.
var adCmdTable = 2; // a table name whose columns are all returned by an internally generated SQL query.
var adCmdStoredProc = 4; // a stored procedure name.
var adCmdFile = 256; // a persisted Recordset.
var adCmdTableDirect = 512; // a table name whose columns are all returned.
// SchemaEnum - specifies the type of schema Recordset to be retrieved by the OpenSchema method
var adSchemaTables = 20; // returns the tables
var adSchemaForeignKeys = 27 // returns the foreign keys (relationships)
// ============================================
// example usage:
// DBInitConnection ( );
//
// DBGetRecords ( "SELECT * FROM Somewhere" );
//
// ...use oRecordSet
//
// DBReleaseRecords ( ); // optional step
//
// DBGetRecords ( "SELECT * FROM SomewhereElse" );
//
// ...use oRecordSet
//
// DBReleaseRecords ( ); // optional step
//
// DBReleaseConnection ( );
// ============================================
// ============================================
// initializes database variables for first use on page - leave it to the
// last possible second before calling this function
// ============================================
function DBInitConnection ( )
{
// don't open it again if already opened!
if ( oConnection != undefined )
return;
// don't bother trying to open if path is below SSI folders
if ( -1 != sDBPath.indexOf ( '\\utils\\' ) || -1 != sDBPath.indexOf ( '\\include\\' ) )
return;
// you can open Recordset objects without a Connection object, but
// it's far less efficient if you are opening multiple Recordsets.
//
// if you don't create a Connection object ADO creates a new one for
// each new Recordset.Open, even if you use the same connection string.
oConnection = Server.CreateObject( 'ADODB.Connection' );
try
{
// open the database, catching any errors that occur
oConnection.Open( sConnectionString );
}
catch ( e )
{
// display error message, and send email
DatabaseException ( e );
// quit running the script completely
Response.End ( );
}
// create a Recordset
oRecordSet = Server.CreateObject( 'ADODB.Recordset' );
}
// ============================================
// tidies up after DBInitConnection
// ============================================
function DBReleaseConnection ( )
{
// don't release the connection if not connected!
if ( oConnection == undefined )
return;
// close and delete the Recordset object
DBReleaseRecords ( );
oRecordSet = undefined;
// Don't call Close if the Recordset failed to Open properly, i.e. its
// State is still adStateClosed (0)
if ( oConnection.State != adStateClosed )
oConnection.Close();
oConnection = undefined;
}
// ============================================
// executes the passed in SQL statement and returns a read-only
// forward-only oRecordSet object
// ============================================
function DBGetRecords ( sSQL )
{
// if the Recordset is already open, close it
DBReleaseRecords ( );
// I could use oRecordSet = oConnection.Execute( sSQL ) here
// but then I will always get back a read-only, forward-only cursor.
// (admittedly this is the most used type, but still)
// use oRecordSet.Open and I have far more control. For details
// read the definitions of the enums at the top of this file.
//Out ( sSQL );Response.Flush();
try
{
// remember that this can fail if passed garbage, and hence the
// Recordset will remain closed, State == adStateClosed
if ( oConnection )
oRecordSet.Open ( sSQL, oConnection, adOpenForwardOnly, adLockReadOnly );
}
catch ( e )
{
// display error message, and send email
DatabaseException ( e );
// quit running the script completely
Response.End ( );
}
}
// ============================================
// tidies up after DBGetRecords
// ============================================
function DBReleaseRecords ( )
{
// when you have finished with an open Recordset object, call the
// Close method to release its resources. You can call Open again.
// Don't call Close if the Recordset failed to Open properly, i.e. its
// State is still adStateClosed
if ( oRecordSet != undefined && oRecordSet.State != adStateClosed )
oRecordSet.Close();
}
// ============================================
// display exception message, but strip out database path if necessary
// ============================================
function DatabaseException ( e )
{
Out ( '<table bgcolor="#ff0000" cellpadding="20"><tr><td>' );
Out ( '<h4><font color="white">An error has occured while connecting to the database:</font></h4>' );
var sMessage = e.description;
// strip out the database path if present
var nStart = sMessage.indexOf ( sDBPath )
if ( -1 != nStart )
sMessage = sMessage.slice ( 0, nStart ) + '[database path]' + sMessage.slice ( nStart + sDBPath.length );
Out ( '<h4> "' + sMessage + '"</h4>' );
Out ( '<h4><font color="white">Don\'t despair - this problem is probably well-documented in my <a href="http://CoverYourASP.com/Trouble.asp"><font color="white">trouble-shooting</font></a> section.</font></h4>' );
Out ( '</td></tr></table>' );
// make up the message body
var sBody = 'The file "' + Request.ServerVariables ( "URL" ) + '?' + Request.QueryString ( ) + '" generated a database error\n\n';
sBody += 'Referrer: "' + Request.ServerVariables ( "HTTP_REFERER" ) + '".\n';
sBody += 'Browser: "' + Request.ServerVariables ( "HTTP_USER_AGENT" ) + '".\n';
sBody += 'IP address: "' + Request.ServerVariables ( "REMOTE_ADDR" ) + '".\n';
var dateToday = new Date();
sBody += 'Time: "' + dateToday.getHours() + ':' + dateToday.getMinutes() + '".\n';
sBody += sMessage;
// send the email
SendEmail ( 'Database.Exception', 'BadDB@' + sHostDomain, '', 'Reporting exception', sBody );
}
// ============================================
// are we using Jet engine db, or SQL server?
// ============================================
var bUsingJet;
function DBIsJet ( )
{
// for efficiency, only work out if which I'm using
// the first time I'm used on a page.
if ( bUsingJet == undefined )
bUsingJet = ( -1 != sDBDriver.indexOf ( '.Jet.' ) );
return bUsingJet;
}
// ============================================
// wrap date in relevant delimeters depending on db engine
// ============================================
function DBWrapDate ( sDate )
{
return ( DBIsJet ( ) ? '#' + sDate + '#' : '\'' + sDate + '\'' );
}
// ============================================
//
// ============================================
function DBIsNull ( )
{
return ( DBIsJet ( ) ? 'Is Null' : '= null' );
}
// ============================================
// stores dropdown lists in Application variables for use with foreign keys
// ============================================
function DBGatherForeignKeys ( )
{
if ( !Application ( 'GatheredForeignKeys' ) )
{
DBInitConnection ( );
bDebug = true;
oRecordSet = oConnection.OpenSchema ( adSchemaForeignKeys );
var nFields = oRecordSet.Fields.Count;
var bHeaders = false;
var sRefTables = new Array;
var sRefColumns = new Array;
var sForeignTables = new Array;
var sForeignColumns = new Array;
var nForeign = 0;
while ( !oRecordSet.EOF )
{
if ( IsDebug ( ) )
{
if ( !bHeaders )
{
Out ( '<table border="1"><tr>' );
for ( i=0; i<nFields; i++ )
Out ( '<td>' + oRecordSet.Fields ( i ).Name + '</td>' );
Out ( '</tr>' );
bHeaders= true;
}
Out ( '<tr>' );
for ( i=0; i<nFields; i++ )
Out ( '<td>' + oRecordSet ( i ) + '</td>' );
Out ( '</tr>' );
}
sRefTables [ nForeign ] = '' + oRecordSet ( 'FK_TABLE_NAME' );
sRefColumns [ nForeign ] = '' + oRecordSet ( 'FK_COLUMN_NAME' );
sForeignTables [ nForeign ] = '' + oRecordSet ( 'PK_TABLE_NAME' );
sForeignColumns [ nForeign++ ] = '' + oRecordSet ( 'PK_COLUMN_NAME' );
oRecordSet.MoveNext ( );
}
if ( bHeaders )
DebugOut ( '</table>' );
for ( i=0; i<nForeign; i++ )
{
DBGetRecords ( 'SELECT * FROM ' + sForeignTables [ i ] );
try
{
var sList = '<select name="' + sRefColumns [ i ] + '">';
var sForeignColumn = sForeignColumns [ i ];
while ( !oRecordSet.EOF )
{
// I assume that the second field is
// the one to show in dropdown list
sList += '<option value="' + oRecordSet ( sForeignColumn ) + '">' + oRecordSet ( 1 ) + '</option>';
oRecordSet.MoveNext ( );
}
sList += '</select>';
Application ( sRefTables [ i ] + ':' + sRefColumns [ i ] ) = sList;
DebugOut ( '<p>Created ' + sRefTables [ i ] + ':' + sRefColumns [ i ] );
DebugOut ( '<p>' + sRefColumns [ i ] + '=' + sForeignTables [ i ] + ':' + sForeignColumn + ' output:'+ Server.HTMLEncode ( sList ) + sList );
}
catch ( e )
{
DebugOut ( '<p>Failed to create dropdown list for ' + sRefTables [ i ] + ':' + sRefColumns [ i ] );
}
}
DBReleaseConnection ( );
Application ( 'GatheredForeignKeys' ) = true;
}
}
// ============================================
// display (not editable) recordset column value
// ============================================
function DBDisplayValue ( oRecordSet, sTableName, nColumn )
{
var sColumnName = oRecordSet.Fields ( nColumn ).Name;
var oValue = oRecordSet ( nColumn );
// get dropdown list if a foreign key
var sHTML = Application ( sTableName + ':' + sColumnName );
// DebugOut ( '<p>Application ( ' + sTableName + ':' + sColumnName + '=' + sHTML );
if ( sHTML )
{
// disable control
var nIndex = sHTML.indexOf ( ' name' );
if ( nIndex != -1 )
sHTML = sHTML.slice ( 0, nIndex ) + ' disabled' + sHTML.slice ( nIndex );
// place 'selected' in the correct spot
var nIndex = sHTML.indexOf ( ' value="' + oValue );
if ( nIndex != -1 )
sHTML = sHTML.slice ( 0, nIndex ) + ' selected' + sHTML.slice ( nIndex );
}
else
{
// show prettier dates
if ( oValue.Type == 7/*date*/ )
sHTML = FormatDateDMY ( oValue );
else
sHTML = "" + Server.HTMLEncode ( '' + oValue );
// for brevity show the first x characters only
if ( sHTML.length > 35 )
sHTML = sHTML.slice ( 0, 35 ) + '...';
}
return sHTML;
}
// ============================================
// display editable recordset column value
// ============================================
function DBEditValue ( oRecordSet, sTableName, nColumn )
{
var sColumnName = oRecordSet.Fields ( nColumn ).Name;
var oValue = oRecordSet ( nColumn );
// get dropdown list if a foreign key
var sHTML = Application ( sTableName + ':' + sColumnName );
// DebugOut ( '<p>Application ( ' + sTableName + ':' + sColumnName + '=' + sHTML );
if ( sHTML )
{
// place 'selected' in the correct spot
var nIndex = sHTML.indexOf ( ' value="' + oValue );
if ( nIndex != -1 )
sHTML = sHTML.slice ( 0, nIndex ) + ' selected' + sHTML.slice ( nIndex );
}
else
{
// show prettier dates
if ( oValue.Type == 7/*date*/ )
sHTML = FormatDateDMY ( oValue );
else
sHTML = "" + Server.HTMLEncode ( '' + oValue );
sHTML = '<input type="text" name="' + sColumnName + '" size="45" value="' + sHTML + '">';
}
return sHTML;
}
// ============================================
// return value with ' replaced by SQL-safe ''
// ============================================
function DBEncode ( sValue )
{
return sValue.replace ( /\'/g, '\'\'' );
}
%>
|
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.
| |