Drupal 6: Silverpop AddRecipient Module

This module (which requires the Silverpop XML API module to be installed) provides the facility to add recipients to a Silverpop database. By default this is through a 'Subscribe now' block or node, both of which can be themed. In addition, there is functionality to delete a recipient from a Silverpop database. User permissions (for the nodes) and block permissions (for the blocks) can control the visibility of the forms.

Installation

Installation is by the usual Drupal mechanism. Once the module is installed, permissions should be set by going to admin/user/permissions. It is important to ensure that these are set correctly to prevent unauthorised access through to the Silverpop API.

Usage

To create a form to capture an email address, go to node/add/silverpop-subscribe-now. You will need to provide a title and a database id. This will provide both a unique block and a node. To make the block visible you will need to go to admin/build/block/list and configure as appropriate. The blocks can be identified by their nid or by the titles they were created with.

Those uses with the correct permissions will see a link to silverpop/remove_recipient in the navigation menu (providing this itself is visible on your system). Use the form from this link to delete email addresses from a database.

Limitations

This system captures email addresses which can be useful for newsletters and campaigns. It does not capture other information such as names / titles etc. It would be possible to re-factor the code to do this as an exercise at a later date.

The RemoveRecipient API call assumes there is only one key, of Email, in the database and will not work should this not be the case.

<?php// Copyright @badzillacouk <a href="http://www.badzilla.co.uk//" title="http://www.badzilla.co.uk//">http://www.badzilla.co.uk//</a> Licence GPL. This program may be distributed as per the terms of GPL and all credits// must be retained//// If you find this script useful, please consider a donation to help me fund my web presence// and encourage me to develop more products to be placed under the terms of GPL// To donate, go to <a href="http://www.badzilla.co.uk" title="http://www.badzilla.co.uk">http://www.badzilla.co.uk</a> and click on the donation button//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

silverpop_subscribe_now_form_submit($form, &$form_state) {// Construct the XML for the Silverpop API call$dom= newDOMDocument;$list_id=$dom->createTextNode($form['#parameters'][2]->sp_db);$list=$dom->createElement('LIST_ID');$cfrom_text=$dom->createTextNode('1');$cfrom=$dom->createElement('CREATED_FROM');$column=$dom->createElement('COLUMN');$name_text=$dom->createTextNode('EMAIL');$name=$dom->createElement('NAME');$value_text=$dom->createTextNode($form_state['values']['email_address']);$value=$dom->createElement('VALUE');$method=$dom->createElement('AddRecipient');$list->appendChild($list_id);$cfrom->appendChild($cfrom_text);$name->appendChild($name_text);$value->appendChild($value_text);$method->appendChild($list);$method->appendChild($cfrom);$method->appendChild($column);$column->appendChild($name);$column->appendChild($value);$dom->appendChild($method);module_load_include('inc','silverpop','silverpop_xml');$addrecipient= newsilverpop_xml($dom,FALSE); list($retcode,$response) =$addrecipient->apicall();$msg=''; if ($retcode)$msg=t('Thanks! You have now been suscribed to the mailing list'); else if (is_object($response) and isset($response->getElementsByTagName('errorid')->item(0)->nodeValue) and$response->getElementsByTagName('errorid')->item(0)->nodeValue==122)$msg=t('Thanks, but you are already subscribed'); else$msg=t('Sorry, unable to subscribe you at this present time');drupal_set_message($msg);}/*** Implementation of hook_theme().*/functionsilverpop_addrecipient_theme() {$ret['silverpop_subscribe_now_form'] = array('arguments'=> array('form'=>NULL));$ret['silverpop_remove_recipient_form'] = array('arguments'=> array('form'=>NULL));

silverpop_remove_recipient_form_submit($form, &$form_state) {// Construct the XML for the Silverpop API call$dom= newDOMDocument;$list_id=$dom->createTextNode($form_state['values']['sp_db']);$list=$dom->createElement('LIST_ID');$email_text=$dom->createTextNode($form_state['values']['email']);$email=$dom->createElement('EMAIL');$method=$dom->createElement('RemoveRecipient');$list->appendChild($list_id);$email->appendChild($email_text);$method->appendChild($list);$method->appendChild($email);$dom->appendChild($method);module_load_include('inc','silverpop','silverpop_xml');$removerecipient= newsilverpop_xml($dom,TRUE); list($retcode,$response) =$removerecipient->apicall();$msg=''; if ($retcode)$msg=t('Email address succesfully deleted from the specified database'); else if (is_object($response) and isset($response->getElementsByTagName('errorid')->item(0)->nodeValue) and$response->getElementsByTagName('errorid')->item(0)->nodeValue==138)$msg=t('The email address you specified does not exist in the Silverpop database'); else$msg=t('Sorry, the removal of the email address failed. Please contact your administrator');drupal_set_message($msg);}

function

theme_silverpop_remove_recipient_form($form) {$output='';$output.="To remove an email address from a Silverpop database, please use the form below";$output.=drupal_render($form['sp_db']);$output.=drupal_render($form['email']);$output.=drupal_render($form['submit']);$output.=drupal_render($form);