◆ First, it checks to see if all required fields — campaign name ($name), list ID ($lid), and message ID ($mid) — are provided. If not, error messages are displayed and the user is returned to the previous screen. ◆ A Campaign object is created and its addCampaign() is called to add the campaign in the database. ◆ Finally, an appropriate status message reflecting the success or failure of the add operation is displayed. updateCampaign() This method updates an existing campaign in the database as follows: ◆ First, it checks to see if all required fields — campaign name ($name), list ID ($lid), and message ID ($mid) — are provided. If not, error messages are displayed and the user is returned to the previous screen. ◆ A Campaign object is created and its modifyCampaign() is called to modify the campaign in the database. ◆ Finally, an appropriate status message reflecting the success or failure of the modification operation is displayed. Creating a Campaign Execution Application The campaign execution application delivers e-mails by fetching the appropriate list data and localizing them in the assembly table and then delivering e-mails to them. Because large e-mail campaigns require a great deal of time, performing them in one shot is not possible via the Web due to the potential for browser timeout. This is why this execution application performs a chunk-size number of delivery and then calls itself from the Web status screen using an HTTP meta refresh trick. The entire execution process is shown in Figure 15-7. The campaign execution application called ecampaign_execution.php, which can be found in ch15/apps directory in the CDROM, performs the e-mail delivery using the methods discussed in the following sections. run() This method calls the executeCampaign() method to perform the e-mail delivery task. Chapter 15: E-campaign System 541 19 549669 ch15.qxd 4/4/03 9:26 AM Page 541 Figure 15-7: How the campaign execution application works. executeCampaign() This method performs all the tasks necessary to execute the campaign. It works as follows: ◆ If the user has not selected a campaign ID ($campaign_id) from the main user interface to execute, an alert message is displayed and user is returned to the main interface. ◆ A Campaign object is created, and the selected campaign data is loaded. ◆ If the selected campaign is loaded, its status is checked using the getStatus() method. If the status is -1, then the campaign execution has already finished. The status value is stored in the $lastrow variable. ◆ The campaign’s message ID is retrieved via the Campaign object’s getMessageID(). Get List ID and Message ID for the campaign Fetch mapped fields from remote database and store in assembly table. Remove records that match rows in unsubscription table Get message template from database Get a chunk of records from the assembly table. Load the records in memory and delete the records from the assembly table Deliver emails to the current chunk of records Set up HTML meta refresh tag to call self and restart the entire process until campaign is completely executed Load list configuration data Outgoing emails 542 Part III: Developing E-mail Solutions 19 549669 ch15.qxd 4/4/03 9:26 AM Page 542 ◆ The campaign’s list ID is retrieved via the Campaign object’s getListID(). ◆ The server name and the application path are stored in $server and $appPath variables, respectively. ◆ If $lastrow is empty, then this is the first time the campaign is being run. In other words, the executeCampaign() method is running for the first time for this campaign. So it needs to assemble the campaign data in the e-campaign database by fetching the required data from the remote table in the database pointed by the list configuration. ◆ A List object is used to retrieve the client database URL using the getClientDBURL() method. A connection to the client database holding the list is made using a DBI object called $client_dbi. ◆ The prepareLocalList() of the List object is called to prepare the assembly table. ◆ If the prepareLocalList() method returns 0, then there are no data to pump out via e-mail and, therefore, an error message is shown. ◆ The getTargetData() method is used to retrieve chunk-size (set by $MAX_DELIVERY_AT_A_TIME in the ecampaign.conf configuration file) records to execute. ◆ A Message object is created and message data is retrieved using the getEcampaignMessageInfo() of the object. If message data is not found, the execution halts with an error message. ◆ The body of the message is retrieved from the Message object and it is inserted into a message template. ◆ The message headers are retrieved using the getEcampaignHeaderInfo(). E-mail is sent via the built-in mail() method. ◆ For each record in the current chunk or rows, the message is personalized using the data retrieved from the assembly table, the URL tags are replaced with redirection URL, and the UNSUB tag is replaced with a personalized unsubscription link. ◆ The campaign status field is set to indicate where the next chunk should start. ◆ A status template is shown after each chunk size of message is sent. This template has a meta refresh tag, which recalls the execution application after $MAX_WAIT_PER_DELIVERY (configuration variable) seconds to con- tinue with the next chunk of messages. authorize() See the authorize() method in the e-campaign user interface application called ecampaign_mngr.php for details. Chapter 15: E-campaign System 543 19 549669 ch15.qxd 4/4/03 9:26 AM Page 543 Creating a URL Tracking and Redirection Application When the campaign execution application sends e-mail, the URLs are transformed into the redirection URL. Figure 15-8 shows how such redirection URLs are tracked and redirected using the URL tracking application. Figure 15-8: How the URL tracking and redirection application works. The redir.php, which can be found in the ch15/apps directory in the CDROM, implements the tracking and URL redirection using the following methods. run() This method first determines if the redirection request mode is test or not. If the redirection mode is test, which is true during message preview, the redirectTest() method is called to redirect the tester to the target URL without recording the track in the database. If the mode is not test, the checksum value of the redirection request is com- pared with the calculated checksum. If both checksum values match, the redirection Yes Show error message Start URL Tracking ApplicationCampaign Message Is URL Request Valid? Locate URL target and redirect user to the target URL End No E-campaign Database Add track record in database Dear Joe, Thank you for visiting our Web site and filling out the inquiry form. Based on your interest we have identified the following resources for you. Please visit at your convenience. Click here to visit ROI Mail Thanks again! Kind Regards, PHP Team, EVOKNOW Click here to remove from future mailing 544 Part III: Developing E-mail Solutions 19 549669 ch15.qxd 4/4/03 9:26 AM Page 544 request is considered valid and the keepTrackAndRedirect() method is called to track and redirect the end-user to the target URL. computeCheckSum() This method implements a simple checksum algorithm using the URL ID ($u), USER ID ($uid), campaign ID ($c), and a random number stored in configuration file called $SECRET. This checksum value is compared with the campaign-execution-application- generated checksum stored in the redirection link to check the validity of the redi- rection request. Using this checksum technique, we can avoid invalid requests from unfriendly users who want to distort the tracking data. keepTrackAndRedirect() This method tracks the URL request in the database and redirects the user to the tar- get URL. It creates a URL Track object and calls the storeTrack() method to store the track data. It also creates a URL object and gets the URL for the given URL ID ($u) and redi- rects the user to the target URL via the HTTP location header. redirectTest() This method creates a URL object and redirects the user to the target URL by finding the target URL using the getURL() method and redirecting using the HTTP location header. Creating an Unsubscription Tracking Application When an end-user clicks on the unsubscription link sent by the campaign execution application, it is processed by the unsubscription process shown in Figure 15-9. The unsub.php, which can be found in ch15/apps directory in the CDROM, implements the unsubscription application using the following methods. run() This method first determines if the unsubscription redirection request mode is test or not. If the mode is test, which is true during message preview, the alert() method is used to display a message stating that the unsubscription request is a test and therefore it isn’t tracked and stored in the database. Chapter 15: E-campaign System 545 19 549669 ch15.qxd 4/4/03 9:26 AM Page 545 . shown in Figure 15-7. The campaign execution application called ecampaign_execution .php, which can be found in ch15/apps directory in the CDROM, performs the e-mail delivery using the methods discussed. application. Figure 15-8: How the URL tracking and redirection application works. The redir .php, which can be found in the ch15/apps directory in the CDROM, implements the tracking and URL redirection using. execution application, it is processed by the unsubscription process shown in Figure 15-9. The unsub .php, which can be found in ch15/apps directory in the CDROM, implements the unsubscription application using the