Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - bb<?php
 - class getresponse {
 - function getresponse() // constructor
 - {
 - }
 - //======== USER REGISTRATION / UPDATE / DELETE ========
 - // Add if user not there, else update
 - function register($userId, $productId, $params)
 - {
 - logToFile("getresponse.class.php: register()", LOG_INFO_DAP);
 - $dapuser = Dap_User::loadUserById($userId);
 - $email = trim($dapuser->getEmail());
 - $username = trim($dapuser->getUser_name());
 - $firstname = trim($dapuser->getFirst_name());
 - $lastname = trim($dapuser->getLast_name());
 - $phone = trim($dapuser->getPhone());
 - $data = explode(":",$params);
 - logToFile("getresponse.class.php: register(): phone =" . $phone, LOG_INFO_DAP);
 - if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $email)) {
 - logToFile("getresponse.class.php: register(): invalid email", LOG_INFO_DAP);
 - return "Email address is invalid";
 - }
 - // format: getresponse:<your API key>:<API username>:1:0
 - require_once 'jsonRPCClient.php';
 - # your API key
 - # available at http://www.getresponse.com/my_api_key.html
 - $api_key = $data[1];
 - logToFile("getresponse.class.php: register(): api_key =" . $api_key, LOG_INFO_DAP);
 - # API 2.x URL
 - $api_url = 'http://api2.getresponse.com';
 - # initialize JSON-RPC client
 - $client = new jsonRPCClient($api_url);
 - $compaign_name = $data[2];
 - logToFile("getresponse.class.php: register(): compaign_name =" . $compaign_name, LOG_INFO_DAP);
 - $result = NULL;
 - # get CAMPAIGN_ID of the campaign
 - try {
 - $result = $client->get_campaigns(
 - $api_key,
 - array (
 - # find by name literally
 - 'name' => array ( 'EQUALS' => $compaign_name )
 - )
 - );
 - logToFile("getresponse.class.php: register(): result returned", LOG_INFO_DAP);
 - }
 - catch (Exception $e) {
 - # check for communication and response errors
 - # implement handling if needed
 - logToFile("getresponse.class.php: register(): get_campaigns ERROR =" . $e->getMessage(), LOG_INFO_DAP);
 - return ($e->getMessage());
 - }
 - # uncomment this line to preview data structure
 - # print_r($result);
 - # since there can be only one campaign of this name
 - # first key is the CAMPAIGN_ID you need
 - $CAMPAIGN_ID = array_pop(array_keys($result));
 - logToFile("getresponse.class.php: register(): get_campaigns CAMPAIGN_ID =" . $CAMPAIGN_ID, LOG_INFO_DAP);
 - # add contact to 'sample_marketing' campaign
 - try {
 - $customs = array();
 - if($phone!="")
 - $customs[]= array('name' => 'phone','content' => $phone);
 - if($lastname!="")
 - $customs[]= array('name' => 'lastname','content' => $lastname);
 - $customsfound = count($customs);
 - logToFile("getresponse.class.php: register(): customsfound =" . $customsfound, LOG_INFO_DAP);
 - if($customsfound > 0) {
 - $result = $client->add_contact(
 - $api_key,
 - array (
 - 'campaign' => $CAMPAIGN_ID,
 - 'name' => $firstname,
 - 'email' => $email,
 - 'cycle_day' => '0',
 - 'customs' => $customs
 - )
 - );
 - }
 - else {
 - $result = $client->add_contact(
 - $api_key,
 - array (
 - 'campaign' => $CAMPAIGN_ID,
 - 'name' => $firstname,
 - 'email' => $email,
 - 'cycle_day' => '0'
 - )
 - );
 - }
 - }
 - catch (Exception $e) {
 - # check for communication and response errors
 - # implement handling if needed
 - logToFile("getresponse.class.php: register(): add_contact ERROR =" . $e->getMessage(), LOG_INFO_DAP);
 - return($e->getMessage());
 - }
 - logToFile("getresponse.class.php: add_contact complete", LOG_INFO_DAP);
 - return 0;
 - }
 - }
 - ?>
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment