function cc::create_contacts in Constant Contact 6.3
Same name and namespace in other branches
- 6.2 class.cc.php \cc::create_contacts()
- 7.3 class.cc.php \cc::create_contacts()
* This method is used to add 25 or more contacts * Pass this method an associative array of contact details * Alternatively you can give the path to a local or remote file * The file should be text or CSV format: * @link http://constantcontact.custhelp.com/cgi-bin/constantcontact.cfg/php/endu... * * *
Parameters
mixed This can be an array or a path to a file: * @param array An array of contact list ID's to add the user to * * @access public
File
- ./
class.cc.php, line 1175
Class
- cc
- @file
Code
function create_contacts($contacts, $lists) {
$params['activityType'] = 'SV_ADD';
if (is_array($contacts) && count($contacts) > 0) {
// get fieldnames from keys of the first contact array
$fieldnames = array_keys($contacts[0]);
$contacts = array_values($contacts);
// transform the given array into a CSV formatted string
$contacts_string = '';
foreach ($contacts as $k => $contact) {
foreach ($fieldnames as $k => $fieldname) {
if (isset($contact[$fieldname]) || is_null($contact[$fieldname])) {
$contacts_string .= $contact[$fieldname] . ",";
}
else {
$this->last_error = 'contacts array is not formatted correctly, please ensure all contact entries have the same fields and values';
return false;
}
}
$contacts_string .= "{$this->http_linebreak}";
}
$params['data'] = implode(',', $fieldnames) . "{$this->http_linebreak}" . $contacts_string;
}
elseif (file_exists($contacts) && is_readable($contacts)) {
// grab the file and output it directly in the request
$params['data'] = file_get_contents($contacts);
}
if (is_array($lists)) {
foreach ($lists as $id) {
$params['lists'][] = $this
->get_list_url($id);
}
}
$this
->http_set_content_type('application/x-www-form-urlencoded');
$xml = $this
->load_url("activities", 'post', $params, 201);
if ($xml) {
return true;
}
/*
if(isset($this->http_response_headers['Location']) && trim($this->http_response_headers['Location']) != ''):
return $this->get_id_from_link($this->http_response_headers['Location']);
endif;
*/
return false;
}