</div>
	</div>
<?php 
}
//
//	Campaigns UI
//
if ($active_tab == 'campaigns') {
    $listHash = array();
    $groupHash = array();
    $templatesHash = array();
    if (empty($apiKey)) {
        print "<p><em>No API Key has been saved yet!</em></p>";
    } else {
        // Create an object to interface with MailChimp
        $api = new MCAPI_13($apiKey);
        // This array holds the lists that have been selected
        $listArray = array();
        $myLists = $api->lists();
        if (null != $myLists) {
            // Need Javascript in order to switch out interest groups when a user changes
            // the mailing list.  ie, A change in the first select box causes the second
            // select box to change it's contents.
            $javaScript = " onchange=\"groupsHash={};";
            // For each mailing list...
            foreach ($myLists['data'] as $list) {
                $listName = $list['name'];
                $listID = $list['id'];
                // Add this list and it's ID to the hash which is used to create the select box.
                $listHash[$listName] = $listID;
                // Get this list's interest groups, if any.
Beispiel #2
0
function AC_ManageMailUser($mode, $user_info, $old_user_data, $writeDBMessages)
{
    $apiKey = get_option(WP88_MC_APIKEY);
    $api = new MCAPI_13($apiKey);
    $myLists = $api->lists();
    $errorCode = 0;
    if (null != $myLists) {
        $list_id = -1;
        // See if the user has selected some lists
        $selectedLists = get_option(WP88_MC_LISTS);
        // Put all of the selected lists into an array to search later
        $valuesArray = array();
        $valuesArray = preg_split("/[\\s,]+/", $selectedLists);
        foreach ($myLists['data'] as $list) {
            $list_id = $list['id'];
            // See if this mailing list should be selected
            foreach ($valuesArray as $searchableID) {
                $pos = strpos($searchableID, $list_id);
                if (false === $pos) {
                } else {
                    // First and last names are always added.  NOTE:  Email is only
                    // managed when a user is updating info 'cause email is used as
                    // the key when adding a new user.
                    $merge_vars = array('FNAME' => $user_info->first_name, 'LNAME' => $user_info->last_name);
                    // Grab the extra WP user info
                    $data = AC_FetchMappedWordPressData($user_info->ID);
                    // Add that info into the merge array.
                    AC_AddUserFieldsToMergeArray($merge_vars, $data);
                    // Gather the additional data from AutoChimp plugins
                    $syncPlugins = new ACSyncPlugins();
                    $syncPlugins->SyncData($merge_vars, $user_info->ID);
                    // This one gets static data...add it as well to the array.
                    $data = AC_FetchStaticData();
                    // Add that info into the merge array.
                    AC_AddUserFieldsToMergeArray($merge_vars, $data);
                    switch ($mode) {
                        case MMU_ADD:
                            // Check to see if the site wishes to bypass the double opt-in feature
                            $doubleOptIn = 0 === strcmp('1', get_option(WP88_MC_BYPASS_OPT_IN)) ? false : true;
                            $retval = $api->listSubscribe($list_id, $user_info->user_email, $merge_vars, 'html', $doubleOptIn);
                            // Start all error notifications with a date.
                            $errorString = date("(Y-m-d H:i:s) ");
                            if ($api->errorCode) {
                                $errorCode = $api->errorCode;
                                // Set latest activity - displayed in the admin panel
                                $errorString = "Problem pushing {$user_info->first_name} {$user_info->last_name} ('{$user_info->user_email}') to list {$list_id}.  Error Code: {$errorCode}, Message: {$api->errorMessage}, Data: ";
                                $errorString .= print_r($merge_vars, TRUE);
                            } else {
                                $errorString = "Pushed {$user_info->first_name} {$user_info->last_name} ('{$user_info->user_email}') to list {$list_id}.";
                            }
                            AC_Log($errorString);
                            if (FALSE != $writeDBMessages) {
                                update_option(WP88_MC_LAST_MAIL_LIST_ERROR, $errorString);
                            }
                            break;
                        case MMU_DELETE:
                            $deleteMember = '1' === get_option(WP88_MC_PERMANENTLY_DELETE_MEMBERS);
                            $sendGoodbye = '1' === get_option(WP88_MC_SEND_GOODBYE);
                            $sendNotify = '1' === get_option(WP88_MC_SEND_ADMIN_NOTIFICATION);
                            update_option(WP88_MC_LAST_MAIL_LIST_ERROR, $lastMessage);
                            $retval = $api->listUnsubscribe($list_id, $user_info->user_email, $deleteMember, $sendGoodbye, $sendNotify);
                            $rightNow = date("(Y-m-d H:i:s) ");
                            if ($api->errorCode) {
                                $errorCode = $api->errorCode;
                                if (FALSE != $writeDBMessages) {
                                    // Set latest activity - displayed in the admin panel
                                    update_option(WP88_MC_LAST_MAIL_LIST_ERROR, "{$rightNow} Problem removing {$user_info->first_name} {$user_info->last_name} ('{$user_info->user_email}') from list {$list_id}.  Error Code: {$errorCode}, Message: {$api->errorMessage}");
                                }
                            } else {
                                if (FALSE != $writeDBMessages) {
                                    update_option(WP88_MC_LAST_MAIL_LIST_ERROR, "{$rightNow} Removed {$user_info->first_name} {$user_info->last_name} ('{$user_info->user_email}') from list {$list_id}.");
                                }
                            }
                            break;
                        case MMU_UPDATE:
                            $updateEmail = $old_user_data->user_email;
                            $rightNow = date("(Y-m-d H:i:s) ");
                            // Potential update to the email address (more likely than name!)
                            $merge_vars['EMAIL'] = $user_info->user_email;
                            // No emails are sent after a successful call to this function.
                            $retval = $api->listUpdateMember($list_id, $updateEmail, $merge_vars);
                            if ($api->errorCode) {
                                $errorCode = $api->errorCode;
                                if (FALSE != $writeDBMessages) {
                                    // Set latest activity - displayed in the admin panel
                                    $errorString = "{$rightNow} Problem updating {$user_info->first_name} {$user_info->last_name} ('{$user_info->user_email}') from list {$list_id}.  Error Code: {$errorCode}, Message: {$api->errorMessage}, Data: ";
                                    $errorString .= print_r($merge_vars, TRUE);
                                    update_option(WP88_MC_LAST_MAIL_LIST_ERROR, $errorString);
                                }
                            } else {
                                if (FALSE != $writeDBMessages) {
                                    $errorString = "{$rightNow} Updated {$user_info->first_name} {$user_info->last_name} ('{$user_info->user_email}') from list {$list_id}.";
                                    // Uncomment this to see debug info on success
                                    //$errorString .= ' Data: ';
                                    //$errorString .= print_r( $merge_vars, TRUE );
                                    update_option(WP88_MC_LAST_MAIL_LIST_ERROR, $errorString);
                                }
                            }
                            break;
                    }
                }
            }
        }
    }
    return $errorCode;
}