public function getLists() { $res = array(); $ccList = new CC_List($this->getConfig('username'), $this->getConfig('password'), $this->getConfig('apikey')); foreach ($ccList->getLists() as $list) { $res[$list['id']] = array('title' => $list['title']); } return $res; }
$postFields["zip_code"] = $_REQUEST["PostalCode"]; $postFields["sub_zip_code"] = $_REQUEST["SubPostalCode"]; $postFields["notes"] = $_REQUEST["Note"]; $postFields["mail_type"] = $_REQUEST["EmailType"]; $postFields["success_url"] = $_REQUEST["SuccessURL"]; $postFields["failure_url"] = $_REQUEST["FailureURL"]; $postFields["request_type"] = $_REQUEST["RequestType"]; // ## PROCESS CUSTOM FIELDS ## // $postFields["custom_fields"] = array(); foreach ($_REQUEST as $key => $val) { if (strncmp($key, 'CustomField', strlen('CustomField')) === 0) { $postFields["custom_fields"][substr($key, strlen('CustomField'), strlen($key) - 1)] = $val; } } // ## PROCESS LISTS ## // $allLists = $ccListOBJ->getLists('', true); foreach ($allLists as $k => $item) { if ($_REQUEST['Lists'] && !empty($_REQUEST['Lists'])) { if (in_array($item['title'], $_REQUEST['Lists'])) { $postFields["lists"][] = $item['id']; } } } $email = $postFields["email_address"]; $info = $ccContactOBJ->getSubscribers($email); $contact = null; for ($i = 0; $i < count($info['items']); $i++) { if ($info['items'][$i]['EmailAddress'] == $email) { $contact = $info['items'][$i]; } }
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 constantcontact_getList($appkey, $appuser, $apppass) { $allLists = null; try { include_once 'cc_class.php'; $ccListOBJ = new CC_List(); $ccListOBJ->login = $appuser; $ccListOBJ->password = $apppass; $ccListOBJ->apikey = $appkey; $ccListOBJ->reconstruct(); $allLists = $ccListOBJ->getLists(); } catch (Exception $e) { $allLists = null; } return $allLists; }
<?php include_once './objects/CC_Utility.class.php'; include_once './objects/CC_List.class.php'; $cc = new CC_List(); echo "<pre>"; var_dump($cc->getLists()); echo "</pre>";
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(); } }