◆ Record ID: A numeric record ID must be in the target list table to identify the customer record. ◆ E-mail field: An e-mail field must be there in the target list table. The field names can be anything. These two fields must be mapped during the list-creation process using the list management application. The e-campaign system allows you to map all the standard personalization fields shown in Table 15-1 during list creation so that you can use them in message personalization. Designing E-campaign Classes Based on the system diagram shown in Figure 15-1, you need to create a set of classes to provide the objects needed to implement the e-campaign system. In the following sections, I discuss the necessary classes in details. Creating a List class The purpose of this class is to provide the List object, which is needed to manipu- late the lists. An implementation of this class can be found in the ch15/apps/ class/class.EcampaignList.php file in the CDROM. This class implements the methods discussed in the following sections. EcampaignList() This is the constructor method. It does the following: ◆ Sets member variables list_tbl, list_field_map, assembly_tbl, unsub_tbl, and bounced_tbl to global configuration variables $ECAMPAIGN_LIST_TBL, $LIST_FIELD_MAP_TBL, $ECAMPAIGN_ASSEMBLY_ TBL , $ECAMPAIGN_UNSUB_TBL, and $ECAMPAIGN_BOUNCED_TBL, respectively. ◆ A member variable called dbi is set to $dbi, which is a DBI object passed from the application. ◆ A member variable called std_map_fields is set to an associative array that holds the field and field type for standard personalization fields sup- ported by the e-campaign system. ◆ Finally, this method calls the setEcampaignListID() method to set the list ID, which can also be passed from the application when creating an object. setEcampaignListID() This method sets the current object’s list ID to the given list ID, which is passed as a parameter. It always returns the current list ID. 516 Part III: Developing E-mail Solutions 19 549669 ch15.qxd 4/4/03 9:26 AM Page 516 getEcampaignListInfo() This method returns all the information about a given list. Information is returned as a standard row object. If no information is found about a list, null is returned. addNewEcampaignList() This method adds a new list to the database. modEcampaignList() This method updates an existing list. addMapping() This method stores standard personalization fields (FIRST, LAST, EMAIL, and so on) mapping information that is used to identify which customer database field matches with which standard personalization fields. getAvailableLists() This method returns a list of available lists. The method returns an associative array where LIST_ID is the key and NAME is the value. deleteList() This method deletes an existing list. prepareLocalList() This method creates a local copy of the list data necessary to execute a campaign. It does the following: ◆ Determines the list of mapped fields. ◆ Makes a SQL statement to get the mapped field data from the customer database table. ◆ Queries the customer database with the prepared statement. ◆ Inserts the data in the assembly table. ◆ Removes the customers who have previously unsubscribed from this list. ◆ Returns the total number of records inserted in the assembly table. pushMappedFields() This is a utility method that pushes a field name into an array if the field name is not null. map() This is a utility method that returns the field name for a given standard contact field name. Chapter 15: E-campaign System 517 19 549669 ch15.qxd 4/4/03 9:26 AM Page 517 getClientDBURL() This method returns the database URL for a given list. It retrieves the database information from the list record and constructs a database_type://user: password ↓tabase_hostname/database_name URL, which can be used to retrieve customer data. getTargetData() This method returns a list of row objects from the assembly table and then deletes the records from the assembly table. This method is used to fetch a specific number of rows from the assembly table for mail delivery. The returned array of rows uses REC_ID as the key and the row object as the value. addToBounced() This method inserts a record in the bounce e-mail table. This record is used in the report to determine how many e-mails bounced during delivery. When an e-mail is not bounced during delivery, it can still be bounced later after delivery by the recipient’s target mail server, which may try to delivery it to an internal mail server within an organization. Therefore, the bounce tracking done in the e-campaign is not 100-percent accurate.In fact,if e-mail addresses aren’t local to the mail server being used, the bounces usually aren’t right away. This problem can be avoided in a future version of the e-campaign system. modifyMapList() This method allows you to modify the standard personalization field map for a given list. Creating a URL class The purpose of this class is to provide the URL object, which is needed to manipu- late the URL. An implementation of this class can be found in ch15/apps/class/ class.EcampaignURL.php . This class implements the methods discussed in the following sections. EcampaignURL() This is the constructor method. It does the following: ◆ Sets the url_tbl variable to the configuration variable called $ECAMPAIGN_URL_TBL, which holds the name of the URL table in the campaign database. 518 Part III: Developing E-mail Solutions 19 549669 ch15.qxd 4/4/03 9:26 AM Page 518 ◆ Sets the home_url variable to configuration variable called $HOME_URL, which holds the home URL. ◆ Sets the dbi variable to the DBI object, which is passed to the URL object from the caller application. addURL() This method inserts a new URL in the URL table within the e-campaign database. getURL() This method gets the URL for a given URL ID. getURLInfo() This method returns the name and URL for a given URL ID from the URL table in the e-campaign database. modURL() This method updates an existing URL in the URL table in the e-campaign database. getURLList() This method returns a list of URLs in an associative array (key = URL_ID, value = name ) from the URL table in the e-campaign database. getURLLocationList() This method returns a list of URLs in an associative array (key = URL_ID, value = URL ) from the URL table in the e-campaign database. deleteURL() This method deletes an existing URL from the URL table in the e-campaign database. Creating a Message class The purpose of this class is to provide the Message object, which is needed to manipulate the message. An implementation of this class can be found in ch15/ apps/class/class.EcampaignMessage.php . This class implements the methods discussed in the following sections. EcampaignMessage() This is the constructor method for the Message class. It does the following: ◆ Sets message_tbl to $ECAMPAIGN_MESSAGE_TBL, which holds the name of the message table. The $ECAMPAIGN_MESSAGE_TBL is set in the ecampaign. conf configuration file. ◆ Sets header_tbl to $MESSAGE_HDRS_TBL, which holds the name of the header table. The $MESSAGE_HDRS_TBL is set in the ecampaign.conf configuration file. Chapter 15: E-campaign System 519 19 549669 ch15.qxd 4/4/03 9:26 AM Page 519 ◆ Sets msg_fields to an associative array, which contains the message table field names and their types (text or number). This associative array is used in other methods to determine which field value needs to be quoted and protected from embedded slashes using the addslashes() method. ◆ Sets hdr_fields to an associative array, which contains the message header table field names and their types (text or number). This associative array is used in other methods to determine which field value needs to be quoted and protected from embedded slashes using the addslashes() method. ◆ Calls setEcampaignMessageID() to set the campaign ID, which is passed to the constructor method from the application. setEcampaignMessageID() This method sets the message ID. getEcampaignMessageInfo() This method returns the message information for a given message ID or the current message ID. getEcampaignHeaderInfo() This method returns message header information for a given message ID or the cur- rent message ID. addNewEcampaignMessage() This method adds a new message in the message table and its headers in the header table. getAvailableMessages() This returns a list of messages in the current e-campaign database. The returned list is an associative array with the message ID (MSG_ID) being the key and the message name (NAME) as the value. deleteMessage() This method deletes a message and its header. UpdateEcampaignMessage() This method updates a message. UpdateEcampaignMessageHdr() This method updates headers of a message. 520 Part III: Developing E-mail Solutions 19 549669 ch15.qxd 4/4/03 9:26 AM Page 520 . lists. An implementation of this class can be found in the ch15/apps/ class/class.EcampaignList .php file in the CDROM. This class implements the methods discussed in the following sections. EcampaignList() This. manipu- late the URL. An implementation of this class can be found in ch15/apps/class/ class.EcampaignURL .php . This class implements the methods discussed in the following sections. EcampaignURL() This. message. An implementation of this class can be found in ch15/ apps/class/class.EcampaignMessage .php . This class implements the methods discussed in the following sections. EcampaignMessage() This