Web Connect How To : Show Me the Code!

 LAFOX Home How URL Maps to Code  LAFOX Design Oveview  Framework Extensions 
*Home.prg #INCLUDE WCONNECT.H DEFINE CLASS HOME AS rbPage ** Merge Variables For HTML Page ** rbPage Properties can be merged into our HTML template UserGroupHeader = [] UserGroupFooter = [] * OkToReWriteURL = .F. && Even if there is no cookie && Don't re-write the url to include SessionID ********************************************************** ** PUBLIC Functions ** Visible from the URL ** These functions are called by the Browser ********************************************************** ********************************************************** ** Show the main page ** Show next meeting ** Browser's URL calls this function ********************************************************** FUNCTION PAGE() ** Load up the header and footer ** OC and LA Fox have different messages ** but we want to use the same template file, home.htm THIS.UserGroupHeader = THIS.MergeToString([UserGroupHeaderFragment.htm]) THIS.UserGroupFooter = THIS.MergeToString([UserGroupFooterFragment.htm]) ******************************************************************************* ** DataSetup() and MeetingHTML() do most of the work (below - in this prg) ** Data manipulation and HTML generation should always be separate! ******************************************************************************* THIS.DataSetup() ** Create Dynamic Content for the Page THIS.Content = THIS.MeetingHTML() ** ok now merge template and content together ** (rbPage::Merge is like Rick's Response::ExpandTemplate) THIS.Merge("Home.htm") && This.Merge() sends page back to user ** cleanup - don't leave the cursor open THIS.CloseCursor('qResult') ENDFUNC
csCodeParser v0.9 stats: 47 lines in 0.00 seconds.

This.Page() handles the web hit.
Notice that this is just a supervisor function, and calls very little native VFP code.

IMPORTANT NOTE:
Keep Data handling separate from HTML generation.
If you mix data and HTML your code will be an awful mess.

Our basic template pages have placeholders for:
This.Content
This.ErrorMessage


FUNCTION SetCookie ** A small dummy page to just set the cookie ** and then send the user to /home.page.fox?SessionID=_71P0O15YP LOCAL lcHTML lcHTML = [] ** HTTP Headers (Not visible in Browser / View Source) Response.Writeln([HTTP/1.1 200 OK]) Response.Writeln([Content-type: text/html]) Response.Writeln([Expires: 0]) && Force reload Response.Writeln([Set-Cookie: SessionID=]+Process.SessionID+[; path=/] ) Response.Writeln('') ** Write the page to look like ** the top of the LAFox, etc. pages ** the image is a link so search engines can follow it. lcHTML = lcHTML+[<html>] + CRLF lcHTML = lcHTML+[] + CRLF lcHTML = lcHTML+[<head>] + CRLF lcHTML = lcHTML+[<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">] + CRLF lcHTML = lcHTML+[<meta http-equiv="REFRESH" content="0.1;URL=/home.page.fox?SessionID=_71P0O15YP">] lcHTML = lcHTML+[<title></title>] + CRLF lcHTML = lcHTML+[</head>] + CRLF lcHTML = lcHTML+[] + CRLF lcHTML = lcHTML+[<body>] + CRLF lcHTML = lcHTML+[<!-- Housekeeping - setting sessionid -->] + CRLF lcHTML = lcHTML+[</body>] + CRLF lcHTML = lcHTML+[] + CRLF lcHTML = lcHTML+[</html>] + CRLF Response.Writeln(lcHTML) ENDFUNC ****************************************************************** ** Hidden Functions Below ** Cannot be called by the Browser (that is why they are HIDDEN) ****************************************************************** **************************************************************** ** Set up data for page **************************************************************** HIDDEN PROCEDURE DataSetup() LOCAL ldDate ldDate = DATE() ** Get the next meeting SELECT TOP 1 mdate, bctopic, bcdescript, ; mt, mtdescript, ; bSpeaker AS bcspeaker, ; mSpeaker AS mtspeaker ; FROM (Site.DataPath + "Meetings.dbf") ; LEFT OUTER JOIN (Site.DataPath + "Speaker.dbf") AS BEGIN ON BEGIN.speakerid = bspeakerid ; LEFT OUTER JOIN (Site.DataPath + "Speaker.dbf") AS MAIN ON MAIN.speakerid = mspeakerid ; ORDER BY mdate ; WHERE mdate >= ldDate ; INTO CURSOR qResult NOFILTER READWRITE ** in case of nulls in speaker names SELECT qResult REPLACE bcspeaker WITH [] FOR ISNULL(bcspeaker) REPLACE mtspeaker WITH [] FOR ISNULL(mtspeaker) GO TOP && REPLACE FOR left us at EOF() ENDPROC *************************************************************************** ** MeetingHTML() ** Set up HTML Table Listing Upcoming Meetings for the page ** ** We could use Rick's wwShowCursor or our DataGrid class ** but here we want a custom layout ** - so lets just hand-code the HTML ** ** It is easier than it looks - Use FrontPage for the design ** and steal FrontPage's HTML ** ** Then use Web-Connect's Text Wrapper tool ** to turn the HTML into VFP code *************************************************************************** HIDDEN FUNCTION MeetingHTML() ** LAFox No longer meets RETURN [] ** LAFox No longer meets LOCAL lcHTML STORE [] TO lcHTML IF RECCOUNT("qResult") > 0 SELECT qResult lcHTML = lcHTML+[ <table border="0" cellpadding="2" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" width="610" id="AutoNumber1">] + CRLF lcHTML = lcHTML+[ <tr>] + CRLF lcHTML = lcHTML+[ <td width="150" bgcolor="#C0C0C0">]+TRANSFORM(mdate)+[</td>] + CRLF IF EMPTY(ALLTRIM(bctopic+bcspeaker+bcdescript)) lcHTML = lcHTML+[ </tr>] + CRLF ELSE lcHTML = lcHTML+[ <td width="650" bgcolor="#C0C0C0" colspan="2"><b>Jump Start</b></td>] + CRLF lcHTML = lcHTML+[ </tr>] + CRLF lcHTML = lcHTML+[ <tr>] + CRLF lcHTML = lcHTML+[ <td width="150" rowspan="5">&nbsp;</td>] + CRLF lcHTML = lcHTML+[ <td width="250" bgcolor="#C0C0C0">]+bctopic+[</td>] + CRLF lcHTML = lcHTML+[ <td width="400" bgcolor="#C0C0C0">]+bcspeaker+[</td>] + CRLF lcHTML = lcHTML+[ </tr>] + CRLF lcHTML = lcHTML+[ <tr>] + CRLF lcHTML = lcHTML+[ <td width="650" colspan="2">]+bcdescript+[</td>] + CRLF lcHTML = lcHTML+[ </tr>] + CRLF ENDIF lcHTML = lcHTML+[ <tr>] + CRLF lcHTML = lcHTML+[ <td width="650" bgcolor="#C0C0C0" colspan="2"><b>Main Topic</b></td>] + CRLF lcHTML = lcHTML+[ </tr>] + CRLF lcHTML = lcHTML+[ <tr>] + CRLF lcHTML = lcHTML+[ <td width="250" bgcolor="#C0C0C0">]+mt+[</td>] + CRLF lcHTML = lcHTML+[ <td width="400" bgcolor="#C0C0C0">]+mtspeaker+[</td>] + CRLF lcHTML = lcHTML+[ </tr>] + CRLF lcHTML = lcHTML+[ <tr>] + CRLF lcHTML = lcHTML+[ <td width="650" colspan="2">]+mtdescript+[</td>] + CRLF lcHTML = lcHTML+[ </tr>] + CRLF lcHTML = lcHTML+[ </table>] + CRLF ELSE ** Did we find anything? ** Either way, we must send back a page lcHTML = [So long, and thanks for all the fish.] ENDIF RETURN lcHTML ENDFUNC && MeetingHTML() ENDDEFINE && Home
csCodeParser v0.9 stats: 135 lines in 0.00 seconds.