<html>
<body>
<?php 
    $ConstantContact = new ConstantContact("oauth2", $apikey, $username, $accessToken);
    // This is to see if a post was made
    if ($_POST) {
        if ($_POST["action"]) {
            $action = true;
        }
        if ($_POST["action"] == "logout") {
            //If the user clicks on the Log Out button then we will end the session.
            session_destroy();
            die("Logged Out, <a href='index.php'>Click Here</a> to continue.");
        } else {
            //Otherwise search the email address associated with this action.
            $search = $ConstantContact->searchContactsByEmail($_POST["searchEmailAddress"]);
        }
    }
    ?>

	<!-- this form searches for a contact by their email address -->
	<H1>Search for a contact</H1>
	<form action="index.php" method="post">
		<input type="hidden" name="action" value="search" />
		<input type="text" name="searchEmailAddress" maxlength="50">
		<input type="submit" name="submit" value="Submit" />
	</form>
	<!-- The HTML code from here to the end is Preformatted so that the information returned by the API is readable.-->
	<pre>
	
<?php 
Esempio n. 2
0
function constantcontact_addContact($info, $list, $appkey, $appusername, $apptoken)
{
    if (!$apptoken || $apptoken == "") {
        return null;
    }
    if (!class_exists("ConstantContact")) {
        require_once 'CTCT-OAuth2/ConstantContact.php';
    }
    try {
        $ConstantContact = new ConstantContact("oauth2", $apikey, $appusername, $apptoken);
        $search = $ConstantContact->searchContactsByEmail($info["email"]);
        if ($search && isset($search[0])) {
            $details = $ConstantContact->getContactDetails($search[0]);
            if (isset($details->lists)) {
                $list_added = false;
                foreach ($details->lists as $l) {
                    if ($l == $list) {
                        $list_added = true;
                    }
                }
                if (!$list_added) {
                    $list_array = $details->lists;
                    array_push($list_array, $list);
                    $details->lists = $list_array;
                    $details->status = "Active";
                    $ConstantContact->updateContact($details);
                    return true;
                }
                return true;
            }
        }
    } catch (Exception $e) {
        return false;
    }
    $postFields = array();
    $postFields["emailAddress"] = $info["email"];
    $postFields["firstName"] = $info["first_name"];
    $postFields["lastName"] = $info["last_name"];
    $postFields["optInSource"] = "ACTION_BY_CONTACT";
    $postFields["lists"] = array($list);
    try {
        $ConstantContact = new ConstantContact("oauth2", $apikey, $appusername, $apptoken);
        $newContact = new Contact($postFields);
        $result = $ConstantContact->addContact($newContact);
        return true;
    } catch (Exception $e) {
        return false;
    }
    return false;
}
    echo $emailAddress;
    ?>
" name="email_address"><br />
            Sends <input type="radio" name="event_type" value="sends"><br />
            Clicks <input type="radio" name="event_type" value="clicks"><br />
            Opens <input type="radio" name="event_type" value="opens"><br />
            Forwards <input type="radio" name="event_type" value="forwards"><br />
            OptOuts <input type="radio" name="event_type" value="optouts"><br />
            Bounces <input type="radio" name="event_type" value="bounces"><br />
            <br /><input type="submit" value="submit" name="submit">
        </form>
        </body>
        </html>
    <?php 
    if ($_GET['email_address']) {
        $contactSearch = $ConstantContact->searchContactsByEmail($_GET['email_address']);
        if (!$contactSearch) {
            exit('Email not found');
        }
        // Find the appropriate event type for the verified contact
        $page = isset($_GET['nextLink']) ? $_GET['nextLink'] : null;
        switch ($_GET['event_type']) {
            case 'sends':
                $event = $ConstantContact->getContactSends($contactSearch[0], $page);
                break;
            case 'clicks':
                $event = $ConstantContact->getContactClicks($contactSearch[0], $page);
                break;
            case 'opens':
                $event = $ConstantContact->getContactOpens($contactSearch[0], $page);
                break;
$Datastore->addUser($sessionConsumer);
$username = $sessionConsumer['username'];
$DatastoreUser = $Datastore->lookupUser($username);
// Is there an active session with a username attached? If so we will allow them to search their contacts for an email address.
if ($DatastoreUser) {
    $ConstantContact = new ConstantContact("oauth2", $apikey, $username, $accessToken);
    $constantparam = $_SESSION['constantparam']['data'];
    $_SESSION['constantresult'] = "";
    // This is to see if a post was made
    if ($_SESSION['constantaction'] != "") {
        // print_r($_POST);exit;
        $action = true;
        if ($_SESSION['constantaction'] == 'Search Email') {
            //Otherwise search the email address associated with this action.
            $email = $constantparam['email'];
            $_SESSION['constantresult'] = $ConstantContact->searchContactsByEmail($email);
        } else {
            if ($_SESSION['constantaction'] == 'Add Email') {
                //Otherwise search the email address associated with this action.
                $email = $constantparam['emailAddress'];
                if ($email != "") {
                    $chkEmailexist = $ConstantContact->searchContactsByEmail($email);
                    if ($chkEmailexist == "") {
                        $objUserinfo = new Contact($constantparam);
                        // print_r($objUserinfo);exit;
                        $addEmailReturn = $ConstantContact->addContact($objUserinfo);
                        if ($addEmailReturn) {
                            $_SESSION['constantresult'] = "Email subscribed sucessfully!";
                        }
                    } else {
                        $_SESSION['constantresult'] = "Email subscribed failed!";