Exemple #1
0
 if (is_array($lists) && sizeof($lists) > 0) {
     foreach ($lists as $key => $value) {
         if (isset($value->name) && $value->name == $list_name) {
             $list_id = $value->id;
         }
     }
 }
 if (isset($email) && strlen($email) > 1 && $list_id != null) {
     $action = "Getting Contact By Email Address";
     try {
         // check to see if a contact with the email addess already exists in the account
         $response = $cc->getContactByEmail($CC_ACCESS_TOKEN, $email);
         // create a new contact if one does not exist
         if (empty($response->results)) {
             $action = "Creating Contact";
             $contact = new Ctct\Components\Contacts\Contact();
             $contact->addEmail($email);
             $contact->addList($list_id);
             $contact->first_name = $firstname;
             $returnContact = $cc->addContact($CC_ACCESS_TOKEN, $contact, true);
             # success!
             echo json_encode(array("status" => "success"));
         } else {
             echo json_encode(array("status" => "error", "type" => "Email address already exists."));
         }
     } catch (CtctException $ex) {
         echo json_encode(array("status" => "error", "type" => "Looks like something went wrong. Please try again later."));
         errorlog("constantcontact", $ex->getErrors());
     }
 } else {
     echo json_encode(array("status" => "error", "type" => "Invalid list ID or email."));
 $api_action = '';
 // EMAIL FIELD FOR getContactByEmail()
 if (!empty($list_v['fields'])) {
     foreach ($list_v['fields'] as $fields_v) {
         if ($fields_v['list_field_id'] == 'email') {
             $api_contact_email = $element_ids_values[$fields_v['element_id']]['element_value'][0];
             break;
         }
     }
 }
 if ($api_contact_email) {
     try {
         $response = $cc->getContactByEmail($cfg[$service_id]['accesstoken'], $api_contact_email);
         // ADD
         if (empty($response->results)) {
             $cc_contact = new Ctct\Components\Contacts\Contact();
             $cc_contact->addEmail($api_contact_email);
             /*
             if(!empty($list_v['addresses'])){
             
             	foreach($list_v['addresses'] as $address_field_k=>$address_field_v){
             		
             		$address = new Ctct\Components\Contacts\Address();
             		
             		foreach($address_field_v['data'] as $address_data_k=>$address_data_v){
             			$address->{$address_data_k} = $element_ids_values[$address_data_v['element_id']]['element_value'][0];
             		}
             		
             		$address->address_type = $address_field_v['type']; // PERSONAL, BUSINESS, UNKNOWN
             		
             		$cc_contact->addAddress($address);