function cc::update_contact in Constant Contact 7.3
Same name and namespace in other branches
- 6.3 class.cc.php \cc::update_contact()
- 6.2 class.cc.php \cc::update_contact()
Updates a contact.
@access public
File
- ./
class.cc.php, line 740 - Constant Contact PHP Class
Class
- cc
- @file Constant Contact PHP Class
Code
function update_contact($id, $email, $lists = array(), $additional_fields = array()) {
// Build the XML put data
$_url = str_replace('https:', 'http:', $this->api_url . "contacts");
$url = "{$_url}/{$id}";
$email = drupal_strtolower($email);
$xml_data = '<entry xmlns="http://www.w3.org/2005/Atom">
<id>' . $url . '</id>
<title type="text">Contact: ' . $email . '</title>
<updated>2008-04-25T19:29:06.096Z</updated>
<author></author>
<content type="application/vnd.ctct+xml">
<Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="' . $url . '">
<EmailAddress>' . $email . '</EmailAddress>
<OptInSource>' . $this->action_type . '</OptInSource>
<OptInTime>2009-11-19T14:48:41.761Z</OptInTime>
';
if ($additional_fields) {
foreach ($additional_fields as $field => $value) {
$xml_data .= "<{$field}>{$value}</{$field}>\n";
}
}
$xml_data .= "<ContactLists>\n";
if ($lists) {
if (is_array($lists)) {
foreach ($lists as $k => $list_id) {
$xml_data .= '<ContactList id="' . $this
->get_list_url($list_id) . '"></ContactList>';
}
}
else {
$xml_data .= '<ContactList id="' . $this
->get_list_url($lists) . '"></ContactList>';
}
}
$xml_data .= "</ContactLists>\n";
$xml_data .= '
</Contact>
</content>
</entry>
';
$this
->http_set_content_type('application/atom+xml');
$xml = $this
->load_url("contacts/{$id}", 'put', $xml_data, 204);
if ($xml or is_array($xml)) {
return TRUE;
}
return FALSE;
}