I'm quite rusty on my php programming so there are probably 10,000 things that could be improved. This works on my local server, so it is what it is. I'm too busy to upkeep this, but I figured I'd post it here as the community has been so helpful to me in the past. Use at your own risk.
I'm awaiting an email from the API support at Office Auto Pilot (it's a weekend, usually they are INSANELY fast to respond). The one flaw I can see in this so far is when a user is added to these sequences, they bypass the double opt-in, which I definitely prefer. So I'm guessing more info needs to be added to the code to specify to Office Auto Pilot to send out a confirmation email.
I'm using vb4.1.3.
Create a new plugin with a hook of register_addmember_process and paste this code.
Be sure to enter your API app and key info and make sure the fields are appropriate.
PHP Code:
<?php
// This will go in the Office Auto Pilot plugin
// Steal username from the vbulletin variables
$oap_user = $vbulletin->GPC['username'];
// Steal email address from the vbulletin variables
$oap_email = $vbulletin->GPC['email'];
// Determine Sequences
/* This code will determine which sequences from Office Auto Pilot to use. You can see that I have #1 and #4 here depending on what the user ultimately wants. I used the custom fields thingy in the Admincp which, for me, ended up being field 5 and field 7. I used phpmyadmin to determine the field names in the userfield table. These field names pop up throughout this little plugin so make sure they are all set accordingly.*/
if ($vbulletin->GPC['userfield']['field5'] ==2) {$oap_SU=1;}
if ($vbulletin->GPC['userfield']['field7'] ==2) {$oap_news=1;}
if ($oap_news and $oap_SU) { $oap_sequence = "*/*1*/*4*/*";}
if ($oap_news and !$oap_SU) { $oap_sequence = "*/*4*/*";}
if (!$oap_news and $oap_SU) {$oap_sequence = "*/*1*/*";}
// Subscribe 'em
// I decided that I'd just use the first name field in Office Auto Pilot to hold the vbulletin username.
if ($oap_sequence)
{
$data = <<<STRING
<contact>
<Group_Tag name="Contact Information">
<field name="First Name">$oap_user</field>
<field name="E-Mail">$oap_email</field>
</Group_Tag>
<Group_Tag name="Sequences and Tags">
<field name="Sequences">$oap_sequence</field>
<field name="Contact Tags"/>
</Group_Tag>
</contact>
STRING;
$data = urlencode(urlencode($data));
$appid = ""; // Your appid goes here.
$key = ""; // Your key goes here.
$reqType= "add";
$postargs = "appid=".$appid."&key=".$key."&return_id=1&reqType=".$reqType. "&data=" . $data;
$request = "http://api.moon-ray.com/cdata.php";
$session = curl_init($request);
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
header("Content-Type: text/xml");
//echo $response;
//SNAG RETURN ID FROM OAP
$xml = new SimpleXMLElement($response);
$oap_return_id = $xml->contact->attributes()->id;
// UPDATE FIELD6 OAP IN DATABASE
// In the event that I ever need to edit their email address, username, etc in Office Auto Pilot, I pulled the id variable out of Office Auto Pilot and stored it in this userfield.
$fieldvariable = array('field6' => $oap_return_id);
$userdata->set_userfields($fieldvariable, true, 'admin');
}
/// End of OAP plugin
?>
I hope this helps.