Web Connect How To : Show Me the Code!

 LAFOX Home How URL Maps to Code  LAFOX Design Oveview  Framework Extensions 
*Tipsubmit.prg * UrlSubmit.prg * 02/28/2002-pa & mc * 02/28/2002-reviewed by mc #INCLUDE WCONNECT.H ************************************************************* DEFINE CLASS TipSubmit AS rbPage ************************************************************* ********************************************************** ** Page() - PUBLIC - ** Show URL submit page ********************************************************** FUNCTION Page() This.PageTitle = [Submit URL] ** create a blank data object - table has char(10) for URLID col This.oData = This.DataObject('-1') ** Merge the page fragment (always a blank entry form) This.Content = this.MergeToString('TipSubmit.htm') ** Logged In template has the Member menu on it ** Merge the final page This.Merge('TemplatePage.htm') ENDFUNC ********************************************************** ** Submit() - PUBLIC - ** ********************************************************** FUNCTION Submit() ** Read Form This.oData = This.ReadForm("tip","tipid") This.oData.PostedDate=DATE() This.oData.Approved=.f. ** validate & save IF this.Validate(This.oData) AND This.Save(This.oData) ** send new URL to approve Email to admin this.EmailToAdmin() This.Content = "Thanks for the Tip!<br>"+; "The Webmaster has been notified.<br>"+; "Please allow 24 hours for your tip to be approved and show on the site." ** Merge the final page This.PageTitle = [Submit Tips] This.Merge('TemplatePage.htm') ELSE ** failed validation so redisplay page ** Merge the page fragment with the user entered data values ** pcError, which is set in this.validate(), is displayed at top of page This.Content = this.MergeToString('TipSubmit.htm') ** Logged In template has the Member menu on it ** Merge the final page This.Merge('TemplatePage.htm') ENDIF ENDFUNC **************************************************************** ** Helper Functions Below **************************************************************** ********************************************************** ** DataObject() ** Open Table and Create a data object ** ID "-1" for blank object ********************************************************** HIDDEN FUNCTION DataObject(tcID) LOCAL loData ** for a given UrlID ** create data object ** if UrlID not found then create a blank data object IF NOT USED('TIP') USE (Site.DataPath + 'TIP.dbf' ) IN 0 SHARED AGAIN ENDIF SELECT Tip IF ( not EMPTY(tcID) ) AND SEEK(tcID, 'TIP', 'TIPID') * found a row SCATTER MEMO NAME loData ELSE * we should be eof() SCATTER MEMO BLANK NAME loData endif RETURN loData ENDFUNC ********************************************************** ** ReadForm() ** Reads form into data object ********************************************************** HIDDEN Function ReadForm() LOCAL loDataMan, lcTIPID * get the URLID from the form lcTIPID = request.form('TIPID') ** Get a blank data object loDataMan = this.DataObject(lcTIPID) ** Read the form into the data object request.FormVarsToObject(loDataMan) RETURN loDataMan ENDFUNC ********************************************************** ** Validate(tcError) ** tcError must be passed by reference ** (for Perry - the tag <br> is a line feed - use if multiple errors ) ** Is the submitted form OK? ********************************************************** HIDDEN Function Validate(toData) This.ErrorMessage=[] IF EMPTY(toData.Title) This.AddError([Title must not be blank]) ENDIF IF EMPTY(toData.PostedBy) This.AddError([Your Name must not be blank]) ENDIF IF EMPTY(toData.Email) This.AddError([Your Email must not be blank]) ENDIF IF EMPTY(toData.Tip) This.AddError([Tip must not be blank]) ENDIF * return .f. if any errors RETURN EMPTY(This.ErrorMessage) ENDFUNC ********************************************************** ** Save() ********************************************************** HIDDEN Function Save(toData) ** Get xID etc. ** make sure the table is used IF NOT USED('TIP') USE (Site.DataPath + 'TIP.dbf' ) IN 0 SHARED AGAIN ENDIF SELECT TIP ** Save data record in table ** does the URLID already exist in the table? IF ( not EMPTY(toData.TIPID) ) ; AND SEEK(toData.TIPID, 'TIP', 'TIPID') ** overwrite record GATHER NAME toData MEMO ELSE ** insert the record & get the newly issued URLID value APPEND BLANK toData.TIPID=TIP.TIPID GATHER NAME toData MEMO endif ENDFUNC ********************************************************** ** EMailToAdmin() ********************************************************** HIDDEN Function EMailToAdmin() ** Ask for approval ** Include link to approval page *** Pass: tcMailServer - IP Address or domain name of the server *** tcSenderName - Sender Display Name (Rick Strahl) *** tcSenderMailAddress Sender's full email address (rstrahl@west-wind.com) *** tcRecipientList - Recipients separated by commas (ben@test.com, jim@test.com) *** tcCCList - List of CCs separated by commas *** tcSubject - Subject Header *** tcMessage - Message Body *** tcAttachement - Not supported any longer *** tcBCC - BCC List Server.SendMail( ; "mail.bricksoftware.com", ; Site.SiteName, ; 'website@' + site.SiteName + '.org' , ; 'webmaster@' + site.SiteName + '.org', ; [], ; "New URL for Approval", ; 'http://www.' + site.SiteName + '.org/UrlApprove.page.fox?SessionID=_4WE0C01IL' ) ENDFUNC ENDDEFINE && URLSubmit
csCodeParser v0.9 stats: 198 lines in 0.01 seconds.