public function changeSubscription(User $user, array $addLists, array $deleteLists) { $ccContact = new CC_Contact($this->getConfig('username'), $this->getConfig('password'), $this->getConfig('apikey')); $postFields = array('status' => 'active', 'email_address' => $user->email, 'first_name' => $user->name_f, 'last_name' => $user->name_l, 'city_name' => $user->city, 'state_code' => $user->state, 'country_code' => $user->country, 'zip_code' => $user->zip, 'address_line_1' => $user->street, 'lists' => $addLists); if ($ccContact->subscriberExists($user->email)) { $contact = $ccContact->getSubscriberDetails($user->email); $contactXML = $ccContact->createContactXML($contact['id'], $postFields); $ccContact->editSubscriber($contact['id'], $contactXML); } else { $contactXML = $ccContact->createContactXML(null, $postFields); $ccContact->addSubscriber($contactXML); } return true; }
} if ($contact != null && $contact['status'] == "Active") { $return_code = 409; } else { if ($contact == null) { $newContactXML = $ccContactOBJ->createContactXML(null, $postFields); $return_code = $ccContactOBJ->addSubscriber($newContactXML); } else { if ($contact != null && $contact['status'] == "Removed") { $currentDetails = $ccContactOBJ->getSubscriberDetails($postFields["email_address"]); $contactInfo = $currentDetails; $contactInfo['lists'] = $postFields['lists']; $contactInfo['first_name'] = $postFields['first_name']; $contactInfo['last_name'] = $postFields['last_name']; $updateXml = $ccContactOBJ->createContactXML($contactInfo['id'], $contactInfo); $return_code = $ccContactOBJ->editSubscriber($contactInfo['id'], $updateXml); } } } if ($postFields['request_type'] == 'ajax') { $postFields["success_url"] = ''; $postFields["failure_url"] = ''; } if ($return_code == 201) { $error = false; if ($postFields["success_url"]) { header('Location:' . $postFields["success_url"]); } else { echo '<div id="code" title="201"></div><h2>One more step!</h2><br /><p style="font-size:15px">Please click on the confirmation link in the email we\'ve sent to the address you provided. Thank you!</p><button id="close" href="#" style="float:right">Close</button>'; } } else {
function AddGuests() { foreach ($_POST['guest_email'] as $i => $email) { if (!empty($email)) { $cc_contact = new CC_Contact(); if ($cc_contact->subscriberExists($email) == true) { $details = $cc_contact->getSubscriberDetails($email); $id = explode('/', $details['id'][0]); $contact = $cc_contact->getContact($id[7]); $ccl = new CC_List(); $found = false; foreach ($contact->content->Contact->ContactLists->ContactList as $contact_list) { /** * @todo: replace this url with appropriate Constant Contact list ID * List of CC List IDs can be seen on /test.php */ if ($contact_list['id'] == 'http://api.constantcontact.com/ws/customers/JamhourUS/lists/42') { $found = true; } } if ($found == false) { $count = sizeof($contact->content->Contact->ContactLists->ContactList); /** * @todo: replace this url with appropriate Constant Contact list ID * List of CC List IDs can be seen on /test.php */ $contact->content->Contact->ContactLists->ContactList[$count]['id'] = 'http://api.constantcontact.com/ws/customers/JamhourUS/lists/42'; } $found = false; foreach ($contact->content->Contact->ContactLists->ContactList as $contact_list) { /** * @todo: replace this url with appropriate Constant Contact list ID * List of CC List IDs can be seen on /test.php */ if ($contact_list['id'] == 'http://api.constantcontact.com/ws/customers/JamhourUS/lists/25') { $found = true; } } if ($found == false) { $count = sizeof($contact->content->Contact->ContactLists->ContactList); /** * @todo: replace this url with appropriate Constant Contact list ID * List of CC List IDs can be seen on /test.php */ $contact->content->Contact->ContactLists->ContactList[$count]['id'] = 'http://api.constantcontact.com/ws/customers/JamhourUS/lists/25'; } $new = $contact->asXML(); $add = $cc_contact->editSubscriber($details['id'][0], $contact->asXML()); } else { $params = array(); $params['status'] = ''; $params['email_address'] = $email; $params['first_name'] = $_POST['guest_first_name'][$i]; $params['last_name'] = $_POST['guest_last_name'][$i]; $params['middle_name'] = $_POST['guest_middle_initial'][$i]; $params['company_name'] = ''; $params['home_number'] = ''; $params['work_number'] = ''; $params['address_line_1'] = ''; $params['city_name'] = ''; $params['state_code'] = ''; $params['country_code'] = ''; $params['zip_code'] = ''; $params['custom_fields'][2] = $_POST['guest_custom_fields'][$i]; $cc_list = new CC_List(); $lists = $cc_list->getLists(); foreach ($lists as $list) { if ($list['title'] == 'Website Testing') { $params['lists'] = array($list['id']); break; } } $xml = $cc_contact->createContactXML(null, $params); $add = $cc_contact->addSubscriber($xml); } } } }
function Process($method = '') { if (isset($_POST['register_too'])) { $cc_list = new CC_List(); $cc_contact = new CC_Contact(); $lists = $cc_list->getLists(); $params = $_POST; if ($cc_contact->subscriberExists($params['email_address']) == true) { $details = $cc_contact->getSubscriberDetails($params['email_address']); $id = explode('/', $details['id'][0]); $contact = $cc_contact->getContact($id[7]); $params['home_phone'] = $_POST['residence'] == 0 ? $params['phone'] : (string) $details['home_number']; $params['work_phone'] = $_POST['residence'] == 1 ? $params['phone'] : (string) $details['work_number']; $params['Addr1'] = $params['address_line_1']; $params['City'] = $params['city_name']; $params['PostalCode'] = $params['zip_code']; unset($params['address_line_1']); unset($params['city_name']); unset($params['zip_code']); unset($params['phone']); unset($params['residence']); foreach ($params as $key => $val) { if (!is_array($val)) { $tmp = explode('_', $key); foreach ($tmp as $i => $k) { $tmp[$i] = ucfirst($k); } $new_key = implode('', $tmp); $params[$new_key] = $val; if (sizeof($tmp) > 1) { unset($params[$key]); } } } foreach ($params['custom_fields'] as $key => $val) { $field = 'CustomField' . $key; $params[$field] = $val; unset($params['custom_fields']); } $countries = $cc_contact->getCountries(); $states = $cc_contact->getStates(); $ccl = new CC_List(); $found = false; foreach ($contact->content->Contact->ContactLists->ContactList as $contact_list) { /** * @todo: replace this url with appropriate Constant Contact list ID * List of CC List IDs can be seen on /test.php */ if ($contact_list['id'] == 'http://api.constantcontact.com/ws/customers/JamhourUS/lists/42') { $found = true; } } if ($found == false) { $count = sizeof($contact->content->Contact->ContactLists->ContactList); /** * @todo: replace this url with appropriate Constant Contact list ID * List of CC List IDs can be seen on /test.php */ $contact->content->Contact->ContactLists->ContactList[2]['id'] = 'http://api.constantcontact.com/ws/customers/JamhourUS/lists/42'; } $contact->content->Contact->LastName = !empty($params['LastName']) ? $params['LastName'] : $contact->content->Contact->LastName; $contact->content->Contact->FirstName = !empty($params['FirstName']) ? $params['FirstName'] : $contact->content->Contact->FirstName; $contact->content->Contact->MiddleName = !empty($params['MiddleName']) ? $params['MiddleName'] : $contact->content->Contact->MiddleName; $contact->content->Contact->CompanyName = !empty($params['CompanyName']) ? $params['CompanyName'] : $contact->content->Contact->CompanyName; /* $contact->content->Contact->StateCode = ( !empty($params['StateCode']) ) ? strtoupper($params['StateCode']) : $contact->content->Contact->StateCode; $contact->content->Contact->StateName = $states[(string)$contact->content->Contact->StateCode]; $contact->content->Contact->CountryCode = $params['CountryCode']; $contact->content->Contact->CountryName = $countries[$params['CountryCode']]; * */ $contact->content->Contact->Addr1 = !empty($params['Addr1']) ? $params['Addr1'] : $contact->content->Contact->Addr1; $contact->content->Contact->City = !empty($params['City']) ? $params['City'] : $contact->content->Contact->City; $contact->content->Contact->PostalCode = !empty($params['PostalCode']) ? $params['PostalCode'] : $contact->content->Contact->PostalCode; $contact->content->Contact->HomePhone = !empty($params['HomePhone']) ? $params['HomePhone'] : $contact->content->Contact->HomePhone; $contact->content->Contact->WorkPhone = !empty($params['WorkPhone']) ? $params['WorkPhone'] : $contact->content->Contact->WorkPhone; $contact->content->Contact->CustomField2 = !empty($params['CustomField2']) ? $params['CustomField2'] : $contact->content->Contact->CustomField2; $contact->content->Contact->CustomField7 = !empty($params['CustomField7']) ? $params['CustomField7'] : $contact->content->Contact->CustomField7; $new = $contact->asXML(); $add = $cc_contact->editSubscriber($details['id'][0], $contact->asXML()); } else { $params = $_POST; $params['status'] = ''; $cc_list = new CC_List(); $lists = $cc_list->getLists(); foreach ($lists as $list) { if ($list['title'] == 'Website Testing') { $params['lists'] = array($list['id']); break; } } if ($_POST['residence'] == 0) { $params['home_number'] = $_POST['phone']; $params['work_number'] = ''; } else { $params['home_number'] = ''; $params['work_number'] = $_POST['phone']; } $xml = $cc_contact->createContactXML(null, $params); $add = $cc_contact->addSubscriber($xml); } } if ($method == 'ByCheck') { header("Location:http://" . $_SERVER['HTTP_HOST'] . "/Donate/Confirmation/ByCheck/"); } else { $this->PayPalRedir(); } }