Exemple #1
0
function mailchimp()
{
    global $wpdb;
    $mailchimpSettings = $wpdb->get_results("SELECT * FROM wp_options WHERE option_name LIKE '%efreetant_mailchimp_%'", OBJECT);
    $settings = array();
    foreach ($mailchimpSettings as $setting) {
        $settings[$setting->option_name] = $setting->option_value;
    }
    $output['error'] = 0;
    $comm = new MCAPI($settings['efreetant_mailchimp_key']);
    $listvar = $comm->listMergeVars($settings['efreetant_mailchimp_listid']);
    $html = "";
    $html .= '<form action="" method="post" id="mailchimpForm">';
    foreach ($listvar as $var) {
        if ($var['public'] === true && $var['show'] === true) {
            $html .= '<label>' . $var['name'] . '</label>';
            $html .= '<input type="' . $var['field_type'] . '" name="' . $var['tag'] . '" placeholder="' . $var['helptext'] . '" require="' . $var['req'] . '">';
        }
    }
    $html .= '<div class="msgField"></div>';
    $html .= '<input type="hidden" name="action" value="submitmailchimp">';
    $html .= '<p><button type="submit" class="mailchimpBtn">Subscribe</button></p>';
    $html .= '</form>';
    echo $html;
    die;
}
Exemple #2
0
 function get_mailchimp_merge_vars($id)
 {
     require_once PREMISE_LIB_DIR . 'mailchimp_api/MCAPI.class.php';
     $settings = $this->get_settings();
     $mailchimp = new MCAPI($settings['optin']['mailchimp-api']);
     if (!isset($this->_optin_MailChimpMergeVars[$id])) {
         $vars = get_transient('mailchimp_merge_vars_' . $id);
         if (!is_array($vars)) {
             $vars = $mailchimp->listMergeVars($id);
             set_transient('mailchimp_merge_vars_' . $id, $vars, 1 * 60 * 60);
         }
         $this->_optin_MailChimpMergeVars[$id] = $vars;
     }
     return $this->_optin_MailChimpMergeVars[$id];
 }
        trigger_error("Mailchimp API Error calling lists(): " . $api->errorMessage, E_USER_ERROR);
    }
    if (count($lists['data']) == 1) {
        $list_id = $lists['data'][0]['id'];
    }
    if (empty($list_id)) {
        trigger_error("Looked for a single List ID in Mailchimp but couldn't find one", E_USER_NOTICE);
        print_r($lists);
    }
}
if (empty($list_id)) {
    trigger_error("No List ID found - correct your config within " . __FILE__, E_USER_ERROR);
}
// Check that the list has the necessary merge vars
$vars = array();
$vars_res = $api->listMergeVars($list_id);
if (!empty($api->errorMessage)) {
    trigger_error("Mailchimp API Error calling listMergeVars(): " . $api->errorMessage, E_USER_ERROR);
}
foreach ($vars_res as $var_details) {
    $vars[] = $var_details['tag'];
}
$missing_vars = array_diff(array('STATUS', 'CONG', 'AGEBRACKET', 'GENDER'), $vars);
if (!empty($missing_vars)) {
    trigger_error("Your mailchimp list is missing the merge vars " . implode(', ', $missing_vars) . '.  Set these up in Mailchimp then try again.', E_USER_ERROR);
}
// Check that we have a report
if (!(int) $report_id) {
    trigger_error("No Report ID found - correct your config within " . __FILE__, E_USER_ERROR);
}
$report = $GLOBALS['system']->getDBObject('person_query', (int) $report_id);
 /**
  * Get all mailchimp list and the fields belongs to them
  */
 public function getMailchimpLists()
 {
     $mailchimp = new MCAPI($this->api_key, $this->ssl);
     // Get Mailchimp lists
     $list_response = $mailchimp->lists();
     if ($mailchimp->errorCode) {
         $this->message = array('text' => $this->l('Mailchimp error code:') . ' ' . $mailchimp->errorCode . '<br />' . $this->l('Milchimp message:') . ' ' . $mailchimp->errorMessage, 'type' => 'error');
         return;
     } else {
         $lists = '';
         foreach ($list_response['data'] as $key => $value) {
             $lists[$key] = $value;
             // Get list fields
             $lists[$key]['fields'] = $mailchimp->listMergeVars($value['id']);
         }
         $this->context->smarty->assign('mailchimp_list', $lists);
         return true;
     }
 }
Exemple #5
0
 function updateSettings($variables)
 {
     if (!isset($variables["mailchimp_secure"])) {
         $variables["mailchimp_secure"] = 0;
     }
     /**
      *   Check for a valid api key.
      */
     if ($variables["apikey_changed"] == "1" && $variables["mailchimp_apikey"] != "") {
         include_once "include/MCAPI.class.php";
         $api = new MCAPI($variables["mailchimp_apikey"]);
         $api->ping();
         if ($api->errorCode) {
             unset($variables["mailchimp_apikey"]);
             $this->updateErrorMessage = "Unable to change the MailChimp apikey: " . $api->errorMessage . " (" . $api->errorCode . ")";
             return $variables;
         }
         //end if
     }
     //end if
     /**
      *  Check for valid list id
      */
     if ($variables["apilist_changed"] == "1" && $variables["mailchimp_list_id"] != "") {
         include_once "include/MCAPI.class.php";
         /**
          *  Check to see if api is already defined (from a possible api key check)
          *  If not, define it and check the key/connection
          */
         if (!isset($api)) {
             $api = new MCAPI($variables["mailchimp_apikey"]);
             $api->ping();
             if ($api->errorCode) {
                 unset($variables["mailchimp_list_id"]);
                 $this->updateErrorMessage = "Unable to change the MailChimp list id: " . $api->errorMessage . " (" . $api->errorCode . ")";
                 return $variables;
             }
             //end if
         }
         //end if
         /**
          *   Look up the lists
          */
         $lists = $api->lists();
         if ($api->errorCode) {
             unset($variables["mailchimp_list_id"]);
             $this->updateErrorMessage = "Unable to change the MailChimp list id: " . $api->errorMessage . " (" . $api->errorCode . ")";
             return $variables;
         } else {
             /**
              *  Check to see if list id is valid
              */
             $validId = false;
             foreach ($lists as $list) {
                 if ($list["id"] == $variables["mailchimp_list_id"]) {
                     $validId = true;
                     break;
                 }
             }
             //endif
             if (!$validId) {
                 unset($variables["mailchimp_list_id"]);
                 $this->updateErrorMessage = "Unable to change the MailChimp list id: the id does not match a valid id on the account.";
                 return $variables;
             } else {
                 /**
                  *  Check to see if the list has a uuid.
                  */
                 $hasUuid = false;
                 $hasCompany = false;
                 $hasType = false;
                 $mergeVars = $api->listMergeVars($variables["mailchimp_list_id"]);
                 if ($api->errorCode) {
                     unset($variables["mailchimp_list_id"]);
                     $this->updateErrorMessage = "Unable to change the MailChimp list id: " . $api->errorMessage . " (" . $api->errorCode . ")";
                     return $variables;
                 }
                 //end if
                 $req = array();
                 foreach ($mergeVars as $mergeVar) {
                     switch ($mergeVar["tag"]) {
                         case "UUID":
                             $hasUuid = true;
                             break;
                         case "COMPANY":
                             $hasCompany = true;
                             break;
                         case "TYPE":
                             $hasType = true;
                             break;
                     }
                     //end switch
                 }
                 //end foreach
                 /**
                  *  If it doesn't have a uuid field, create it.
                  */
                 if (!$hasUuid) {
                     $req = array("req" => true, "public" => false, "field_type" => "text");
                     $api->listMergeVarAdd($variables["mailchimp_list_id"], "UUID", "phpBMS unique user id", $req);
                     if ($api->errorCode) {
                         unset($variables["mailchimp_list_id"]);
                         $this->updateErrorMessage = "Unable to change the MailChimp list id: " . $api->errorMessage . " (" . $api->errorCode . ")";
                         return $variables;
                     }
                     //end if
                 }
                 //end if
                 /**
                  *  If it doesn't have a company field, create it.
                  */
                 if (!$hasCompany) {
                     $req = array("req" => false, "public" => true, "field_type" => "text");
                     $api->listMergeVarAdd($variables["mailchimp_list_id"], "COMPANY", "Company", $req);
                     if ($api->errorCode) {
                         unset($variables["mailchimp_list_id"]);
                         $this->updateErrorMessage = "Unable to change the MailChimp list id: " . $api->errorMessage . " (" . $api->errorCode . ")";
                         return $variables;
                     }
                     //end if
                 }
                 //end if
                 /**
                  *  If it doesn't have a type field, create it.
                  */
                 if (!$hasType) {
                     $req = array("req" => false, "public" => true, "field_type" => "text");
                     $api->listMergeVarAdd($variables["mailchimp_list_id"], "TYPE", "Type", $req);
                     if ($api->errorCode) {
                         unset($variables["mailchimp_list_id"]);
                         $this->updateErrorMessage = "Unable to change the MailChimp list id: " . $api->errorMessage . " (" . $api->errorCode . ")";
                         return $variables;
                     }
                     //end if
                 }
                 //end if
                 /**
                  *  If the date list id has changed, the last sync date must be reset:
                  */
                 $variables["mailchimp_last_sync_date"] = "";
             }
             //end if
         }
         //end if
     }
     //end if
     return $variables;
 }
 /**
  * Action to process subscriptions
  * @param array $raw_data
  * @param Form $form
  * @return SilverChimpSubscriptionPage_Controller
  */
 function SubscribeAction($raw_data, $form)
 {
     $config = SiteConfig::current_site_config();
     $data = Convert::raw2sql($raw_data);
     // get list of mergeVars to check for from API
     $mergeVars = $this->api->listMergeVars($this->ListID);
     // initialise data container
     $postedVars = array();
     // loop through merge vars and only poopulate data required
     foreach ($mergeVars as $var) {
         if (isset($data[$var['tag']])) {
             $postedVars[$var['tag']] = $data[$var['tag']];
         }
     }
     // get all groups for list
     $groupData = $this->api->listInterestGroupings($this->ListID);
     // get all defaults for list
     $groupDefaults = unserialize($this->DefaultGroupSelections);
     if (is_array($groupData) || $groupData instanceof Traversable) {
         // loop through groups
         foreach ($groupData as $gr) {
             // initialise valiable containing the key for defaults test
             $defaultsName = 'SCG-' . preg_replace('/[^0-9A-Za-z]/', '-', $gr['name']);
             // if a GROUPINGS value for the current group exists
             if (isset($data['GROUPINGS'][$gr['name']])) {
                 $newGroups = array();
                 // check current group is in submitted values
                 foreach ($gr['groups'] as $gd) {
                     if (in_array($gd['bit'], $data['GROUPINGS'][$gr['name']])) {
                         $newGroups[] = $gd['name'];
                     }
                 }
                 // add groups to data for subscription
                 $postedVars['GROUPINGS'][] = array('name' => $gr['name'], 'groups' => implode(',', $newGroups));
             } else {
                 if (isset($groupDefaults[$defaultsName])) {
                     // if defaults present
                     $newGroups = array();
                     // loop through groups and check in defaults
                     foreach ($gr['groups'] as $gd) {
                         if (in_array($gd['bit'], $groupDefaults[$defaultsName])) {
                             $newGroups[] = $gd['name'];
                         }
                     }
                     // add groups to data for subscription
                     $postedVars['GROUPINGS'][] = array('name' => $gr['name'], 'groups' => implode(',', $newGroups));
                 }
             }
         }
     }
     $this->extend('updateSilverChimpSignupAction', $data, $postedVars);
     // send subscription data to MailChimp
     $result = $this->api->listSubscribe($this->ListID, $postedVars['EMAIL'], $postedVars, $config->ChimpEmailType, $config->ChimpDoubleOptIn, $this->AllowUpdateExisting, $config->ChimpReplaceGroups, $config->ChimpSendWelcome);
     if (true === $result) {
         //    success!
         Session::set('SilverChimp.SUCCESS', true);
         return $this->subscribeSuccess();
     } else {
         //    failure!
         $form->sessionMessage($this->api->errorMessage, 'warning');
         return $this;
     }
 }
 public function UpdateLists()
 {
     $api = new MCAPI($this->apikey);
     $retval = $api->lists();
     if ($api->errorCode) {
         SS_Log::log("Unable to load lists()! Error Code = " . $api->errorCode . " Error Msg = " . $api->errorMessage, SS_Log::ERR);
         return false;
     } else {
         foreach ($retval['data'] as $list) {
             // Get DataList of All MCLists
             $dl = MCList::get();
             $l = $dl->where("ListID = '" . $list['id'] . "'")->first();
             // If the Current Iterations List Object Does Not Yet Exist, Create It
             if (!is_object($l)) {
                 $l = new MCList();
                 $l->setField("ListID", $list['id']);
             }
             // Populate/Overwrite the List Data
             $l->setField("Name", $list['name']);
             $l->setField("WebID", $list['web_id']);
             $l->setField("Subscribed", $list['stats']['member_count']);
             $l->setField("Unsubscribed", $list['stats']['unsubscribe_count']);
             $l->setField("Cleaned", $list['stats']['cleaned_count']);
             $l->write();
             // Add/Delete any New/Removed Merge Tags
             // (Newly Added Merge Tags Will Need Linking/Relating to the Appropriate DB Field Name
             // via Admin -> Setting -> MC Lists -> List Field Relationships)
             $retval = $api->listMergeVars($l->ListID);
             if ($api->errorCode) {
                 SS_Log::log("Unable to load listMergeVars()! Code = " . $api->errorCode . " Msg = " . $api->errorMessage, SS_Log::ERR);
                 return false;
             } else {
                 $currTags = array();
                 foreach ($retval as $mergeTagData) {
                     $currTags[] = $mergeTag = $mergeTagData['tag'];
                     $listField = $l->getComponents("MCListFields", "\"MergeTag\" = '" . $mergeTag . "'")->first();
                     if (empty($listField)) {
                         $lf = new MCListField();
                         $lf->setField("MergeTag", $mergeTag);
                         $lf->write();
                         $l->getComponents("MCListFields")->add($lf);
                     }
                 }
                 // Create DataList of All Existing MC List Fields Which Are No Longer Present In MailChimp (Old Merge Tags) and Delete Them
                 $dl = new DataList("MCListField");
                 $filter = "\"MCListID\" = '" . $l->ID . "' AND \"MergeTag\" NOT IN (" . $this->arrayToCSV($currTags) . ")";
                 SS_Log::log("Cleaning up historical merge fields. MCListField delete filter = '" . $filter . "'", SS_Log::NOTICE);
                 $dl->removeByFilter($filter);
             }
         }
     }
     return true;
 }
Exemple #8
0
function mailchimpSF_setup_page()
{
    $msg = '';
    if (get_option('mc_password') != '') {
        //some upgrade code for < 0.5 users - we want to rip out the password we've been saving.
        $api = new MCAPI(get_option('mc_username'), get_option('mc_password'));
        if ($api->errorCode == '') {
            update_option('mc_apikey', $api->api_key);
            //this should already be here, but let's make sure anyway
            $req = $api->getAffiliateInfo();
            update_option('mc_user_id', $req['user_id']);
        } else {
            $msg = "<span class='error_msg'>" . __("While upgrading the plugin setup, we were unable to login to your account. You will need to login again and setup your list.", 'mailchimp_i18n') . "<br/>";
        }
        delete_option('mc_password');
    }
    ?>
<div class="wrap">
<h2><?php 
    echo __('MailChimp List Setup', 'mailchimp_i18n');
    ?>
 </h2>
<?php 
    if ($_REQUEST['action'] === 'logout') {
        update_option('mc_apikey', '');
    }
    //see if we need to set/change the username & password.
    if (isset($_REQUEST['mc_username']) && isset($_REQUEST['mc_password'])) {
        $delete_setup = false;
        $api = new MCAPI($_REQUEST['mc_username'], $_REQUEST['mc_password']);
        if ($api->errorCode == '') {
            $msg = "<span class='success_msg'>" . htmlentities(__("Success! We were able to verify your username & password! Let's continue, shall we?", 'mailchimp_i18n')) . "</span>";
            update_option('mc_username', $_REQUEST['mc_username']);
            update_option('mc_apikey', $api->api_key);
            $req = $api->getAffiliateInfo();
            update_option('mc_user_id', $req['user_id']);
            if (get_option('mc_list_id') != '') {
                $lists = $api->lists();
                //but don't delete if the list still exists...
                $delete_setup = true;
                foreach ($lists as $list) {
                    if ($list['id'] == get_option('mc_list_id')) {
                        $list_id = $_REQUEST['mc_list_id'];
                        $delete_setup = false;
                    }
                }
            }
        } else {
            $msg .= "<span class='error_msg'>" . htmlentities(__('Uh-oh, we were unable to login and verify your username & password. Please check them and try again!', 'mailchimp_i18n')) . "<br/>";
            $msg .= __('The server said:', 'mailchimp_i18n') . "<i>" . $api->errorMessage . "</i></span>";
            if (get_option('mc_username') == '') {
                $delete_setup = true;
            }
        }
        if ($delete_setup) {
            delete_option('mc_user_id');
            delete_option('mc_rewards');
            delete_option('mc_use_javascript');
            delete_option('mc_use_unsub_link');
            delete_option('mc_list_id');
            delete_option('mc_list_name');
            delete_option('mc_interest_groups');
            delete_option('mc_show_interest_groups');
            $mv = get_option('mc_merge_vars');
            if (!is_array($mv)) {
                $mv = unserialize($mv);
            }
            if (is_array($mv)) {
                foreach ($mv as $var) {
                    $opt = 'mc_mv_' . $var['tag'];
                    delete_option($opt);
                }
            }
            delete_option('mc_merge_vars');
        }
        //set these for the form fields below
        $user = $_REQUEST['mc_username'];
    } else {
        $user = get_option('mc_username');
        $pass = get_option('mc_password');
    }
    if (get_option('mc_apikey') != '') {
        $GLOBALS["mc_api_key"] = get_option('mc_apikey');
        $api = new MCAPI('no_login', 'is_needed');
        $lists = $api->lists();
        foreach ($lists as $list) {
            if ($list['id'] == $_REQUEST['mc_list_id']) {
                $list_id = $_REQUEST['mc_list_id'];
                $list_name = $list['name'];
            }
        }
        $orig_list = get_option('mc_list_id');
        if ($list_id != '') {
            update_option('mc_list_id', $list_id);
            update_option('mc_list_name', $list_name);
            if ($orig_list != $list_id) {
                update_option('mc_header_content', __('Sign up for', 'mailchimp_i18n') . ' ' . $list_name);
                update_option('mc_submit_text', __('Subscribe', 'mailchimp_i18n'));
                update_option('mc_custom_style', 'on');
                update_option('mc_use_javascript', 'on');
                update_option('mc_use_unsub_link', 'off');
                update_option('mc_header_border_width', '1');
                update_option('mc_header_border_color', 'E3E3E3');
                update_option('mc_header_background', 'FFFFFF');
                update_option('mc_header_text_color', 'CC6600');
                update_option('mc_form_border_width', '1');
                update_option('mc_form_border_color', 'C4D3EA');
                update_option('mc_form_background', 'EEF3F8');
                update_option('mc_form_text_color', '555555');
                update_option('mc_show_interest_groups', 'on');
            }
            $mv = $api->listMergeVars($list_id);
            $ig = $api->listInterestGroups($list_id);
            update_option('mc_merge_vars', serialize($mv));
            foreach ($mv as $var) {
                $opt = 'mc_mv_' . $var['tag'];
                //turn them all on by default
                if ($orig_list != $list_id) {
                    update_option($opt, 'on');
                }
            }
            update_option('mc_interest_groups', serialize($ig));
            $msg = '<span class="success_msg">' . sprintf(__('Success! Loaded and saved the info for %d Merge Variables and %d Interest Groups from your list'), sizeof($mv), sizeof($ig)) . ' "' . $list_name . '"<br/><br/>' . __('Now you should either Turn On the MailChimp Widget or change your options below, then turn it on.', 'mailchimp_i18n') . '</span>';
        }
    }
    if (isset($_REQUEST['reset_list'])) {
        delete_option('mc_list_id');
        delete_option('mc_list_name');
        delete_option('mc_merge_vars');
        delete_option('mc_interest_groups');
        delete_option('mc_use_javascript');
        delete_option('mc_use_unsub_link');
        delete_option('mc_header_content');
        delete_option('mc_submit_text');
        delete_option('mc_custom_style');
        delete_option('mc_header_border_width');
        delete_option('mc_header_border_color');
        delete_option('mc_header_background');
        delete_option('mc_header_text_color');
        delete_option('mc_form_border_width');
        delete_option('mc_form_border_color');
        delete_option('mc_form_background');
        delete_option('mc_form_text_color');
        $msg = '<span class="success_msg">' . __('Successfully Reset your List selection... Now you get to pick again!', 'mailchimp_i18n') . '</span>';
    }
    if (isset($_REQUEST['change_form_settings'])) {
        if (isset($_REQUEST['mc_rewards'])) {
            update_option('mc_rewards', 'on');
            if ($msg) {
                $msg .= '<br/>';
            }
            $msg .= '<span class="success_msg">' . __('Monkey Rewards turned On!', 'mailchimp_i18n') . '</span>';
        } else {
            if (get_option('mc_rewards') != 'off') {
                update_option('mc_rewards', 'off');
                if ($msg) {
                    $msg .= '<br/>';
                }
                $msg .= '<span class="success_msg">' . __('Monkey Rewards turned Off!', 'mailchimp_i18n') . '</span>';
            }
        }
        if (isset($_REQUEST['mc_use_javascript'])) {
            update_option('mc_use_javascript', 'on');
            if ($msg) {
                $msg .= '<br/>';
            }
            $msg .= '<span class="success_msg">' . __('Fancy Javascript submission turned On!', 'mailchimp_i18n') . '</span>';
        } else {
            if (get_option('mc_use_javascript') != 'off') {
                update_option('mc_use_javascript', 'off');
                if ($msg) {
                    $msg .= '<br/>';
                }
                $msg .= '<span class="success_msg">' . __('Fancy Javascript submission turned Off!', 'mailchimp_i18n') . '</span>';
            }
        }
        if (isset($_REQUEST['mc_use_unsub_link'])) {
            update_option('mc_use_unsub_link', 'on');
            if ($msg) {
                $msg .= '<br/>';
            }
            $msg .= '<span class="success_msg">' . __('Unsubscribe link turned On!', 'mailchimp_i18n') . '</span>';
        } else {
            if (get_option('mc_use_unsub_link') != 'off') {
                update_option('mc_use_unsub_link', 'off');
                if ($msg) {
                    $msg .= '<br/>';
                }
                $msg .= '<span class="success_msg">' . __('Unsubscribe link turned Off!', 'mailchimp_i18n') . '</span>';
            }
        }
        $content = stripslashes($_REQUEST['mc_header_content']);
        $content = str_replace("\r\n", "<br/>", $content);
        update_option('mc_header_content', $content);
        $submit_text = stripslashes($_REQUEST['mc_submit_text']);
        $submit_text = str_replace("\r\n", "", $submit_text);
        update_option('mc_submit_text', $submit_text);
        if (isset($_REQUEST['mc_custom_style'])) {
            update_option('mc_custom_style', 'on');
        } else {
            update_option('mc_custom_style', 'off');
        }
        //we told them not to put these things we are replacing in, but let's just make sure they are listening...
        update_option('mc_header_border_width', str_replace('px', '', $_REQUEST['mc_header_border_width']));
        update_option('mc_header_border_color', str_replace('#', '', $_REQUEST['mc_header_border_color']));
        update_option('mc_header_background', str_replace('#', '', $_REQUEST['mc_header_background']));
        update_option('mc_header_text_color', str_replace('#', '', $_REQUEST['mc_header_text_color']));
        update_option('mc_form_border_width', str_replace('px', '', $_REQUEST['mc_form_border_width']));
        update_option('mc_form_border_color', str_replace('#', '', $_REQUEST['mc_form_border_color']));
        update_option('mc_form_background', str_replace('#', '', $_REQUEST['mc_form_background']));
        update_option('mc_form_text_color', str_replace('#', '', $_REQUEST['mc_form_text_color']));
        if (isset($_REQUEST['mc_show_interest_groups'])) {
            update_option('mc_show_interest_groups', 'on');
        } else {
            update_option('mc_show_interest_groups', 'off');
        }
        $mv = get_option('mc_merge_vars');
        if (!is_array($mv)) {
            $mv = unserialize(get_option('mc_merge_vars'));
        }
        foreach ($mv as $var) {
            $opt = 'mc_mv_' . $var['tag'];
            if (isset($_REQUEST[$opt]) || $var['req'] == 'Y') {
                update_option($opt, 'on');
            } else {
                update_option($opt, 'off');
            }
        }
        if ($msg) {
            $msg .= '<br/>';
        }
        $msg .= '<span class="success_msg">' . __('Successfully Updated your List Subscribe Form Settings!', 'mailchimp_i18n') . '</span>';
    }
    if ($msg) {
        echo '<div id="mc_message" class=""><p><strong>' . $msg . '</strong></p></div>';
    }
    //wp_nonce_field('update-options');
    if (get_option('mc_apikey') == '') {
        ?>
<div>
<form method="post" action="options-general.php?page=mailchimpSF_setup_page">
<h3><?php 
        echo __('Login Info', 'mailchimp_i18n');
        ?>
</h3>
<?php 
        echo __('To start using the MailChimp plugin, we first need to login and get your API Key. Please enter your MailChimp username and password below.', 'mailchimp_i18n');
        ?>
<br/>
<?php 
        echo __("Don't have a MailChimp account? <a href='http://www.mailchimp.com/tryit.phtml' target='_blank'>Try one for Free</a>!", 'mailchimp_i18n');
        ?>
<br/>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php 
        echo __('Username', 'mailchimp_i18n');
        ?>
:</th>
<td><input name="mc_username" type="text" id="mc_username" class="code" value="<?php 
        echo $user;
        ?>
" size="20" /></td>
</tr>
<tr valign="top">
<th scope="row"><?php 
        echo __('Password', 'mailchimp_i18n');
        ?>
:</th>
<td><input name="mc_password" type="text" id="mc_password" class="code" value="<?php 
        echo $pass;
        ?>
" size="20" /></td>
</tr>
</table>
<input type="hidden" name="action" value="update"/>
<input type="hidden" name="page_options" value="mc_username,mc_password" />
<input type="submit" name="Submit" value="<?php 
        echo htmlentities(__('Save & Check'));
        ?>
" class="button" />
</form>
</div>
<?php 
        if (get_option('mc_username') != '') {
            echo '<strong>' . __('Notes', 'mailchimp_i18n') . ':</strong><ul>
		    <li><i>' . __('Changing your settings at MailChimp.com may cause this to stop working.', 'mailchimp_i18n') . '</i></li>
		    <li><i>' . __('If you change your login to a different account, the info you have setup below will be erased.', 'mailchimp_i18n') . '</i></li>
		    <li><i>' . __('If any of that happens, no biggie - just reconfigure your login and the items below...', 'mailchimp_i18n') . '</i></li></ul>
	    <br/>';
        }
        echo '</p>';
    } else {
        ?>
<table style="min-width:400px;"><tr><td><h3><?php 
        echo __('Logged in as', 'mailchimp_i18n');
        ?>
: <?php 
        echo get_option('mc_username');
        ?>
</h3>
</td><td>
<form method="post" action="options-general.php?page=mailchimpSF_setup_page">
<input type="hidden" name="action" value="logout"/>
<input type="submit" name="Submit" value="<?php 
        echo __('Logout', 'mailchimp_i18n');
        ?>
" class="button" />
</form>
</td></tr></table>
<?php 
    }
    //Just get out if nothing else matters...
    if (get_option('mc_apikey') == '') {
        return;
    }
    if (get_option('mc_apikey') != '') {
        //wp_nonce_field('update-options');
        ?>
<h3><?php 
        echo __('Your Lists', 'mailchimp_i18n');
        ?>
</h3>
<div>
<?php 
        echo __('Please select the List you wish to create a Signup Form for.', 'mailchimp_i18n');
        ?>
<br/>
<form method="post" action="options-general.php?page=mailchimpSF_setup_page">
<?php 
        $GLOBALS["mc_api_key"] = get_option('mc_apikey');
        $api = new MCAPI('no_login', 'is_needed');
        $lists = $api->lists();
        rsort($lists);
        if (sizeof($lists) == 0) {
            echo "<span class='error_msg'>" . sprintf(__("Uh-oh, you don't have any lists defined! Please visit %s, login, and setup a list before using this tool!", 'mailchimp_i18n'), "<a href='http://www.mailchimp.com/'>MailChimp</a>") . "</span>";
        } else {
            echo '<table style="min-width:400px"><tr><td>
    	    <select name="mc_list_id" style="min-width:200px;">
            <option value=""> --- ' . __('Select A List', 'mailchimp_i18n') . ' --- </option>';
            foreach ($lists as $list) {
                if ($list['id'] == get_option('mc_list_id')) {
                    $sel = ' selected="selected" ';
                } else {
                    $sel = '';
                }
                echo '<option value="' . $list['id'] . '" ' . $sel . '>' . htmlentities($list['name']) . '</option>';
            }
            ?>
</select></td><td>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="mc_list_id" />
<input type="submit" name="Submit" value="<?php 
            echo __('Update List', 'mailchimp_i18n');
            ?>
" class="button" />
</td></tr>
<tr><td colspan="2">
<strong><?php 
            echo __('Note:', 'mailchimp_i18n');
            ?>
</strong> <em><?php 
            echo __('Updating your list will not cause settings below to be lost. Changing to a new list will.', 'mailchimp_i18n');
            ?>
</em>
</td></tr>
</table>
</form>
</div>
<br/>
<?php 
        }
        //end select list
    } else {
        //display the selected list...
        ?>

<?php 
        //wp_nonce_field('update-options');
        ?>
<p class="submit">
<form method="post" action="options-general.php?page=mailchimpSF_setup_page">
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="mc_list_id" />
<input type="submit" name="reset_list" value="<?php 
        echo __('Reset List Options and Select again', 'mailchimp_i18n');
        ?>
" class="button" />
</form>
</p>
<h3><?php 
        echo __('Subscribe Form Widget Settings for this List', 'mailchimp_i18n');
        ?>
:</h3>
<h4><?php 
        echo __('Selected MailChimp List', 'mailchimp_i18n');
        ?>
: <?php 
        echo get_option('mc_list_name');
        ?>
</h4>
<?php 
    }
    //Just get out if nothing else matters...
    if (get_option('mc_list_id') == '') {
        return;
    }
    $mv = get_option('mc_merge_vars');
    $ig = get_option('mc_interest_groups');
    if (!is_array($mv)) {
        //apparently in WP 2.6 get_option() unserializes arrays for us.
        $mv = unserialize($mv);
        $ig = unserialize($ig);
    }
    if (!is_array($ig)) {
        //means we got false returned
        $ig = unserialize($ig);
    }
    ?>

<div>
<form method="post" action="options-general.php?page=mailchimpSF_setup_page">
<div style="width:600px;">
<input type="submit" name="change_form_settings" value="<?php 
    echo __('Update Subscribe Form Settings', 'mailchimp_i18n');
    ?>
" class="button" />
<table class="widefat">
    <tr valign="top">
    <th scope="row"><?php 
    echo __('Monkey Rewards', 'mailchimp_i18n');
    ?>
:</th>
    <td><input name="mc_rewards" type="checkbox" <?php 
    if (get_option('mc_rewards') == 'on' || get_option('mc_rewards') == '') {
        echo 'checked="checked"';
    }
    ?>
 id="mc_rewards" class="code" />
    <i><label for="mc_rewards"><?php 
    echo __('turning this on will place a "powered by MailChimp" link in your form that will earn you credits with us. It is optional and can be turned on or off at any time.');
    ?>
</label></i>
    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php 
    echo __('Use Javascript Support?', 'mailchimp_i18n');
    ?>
:</th>
    <td><input name="mc_use_javascript" type="checkbox" <?php 
    if (get_option('mc_use_javascript') == 'on') {
        echo 'checked="checked"';
    }
    ?>
 id="mc_use_javascript" class="code" />
    <i><label for="mc_use_javascript"><?php 
    echo __('turning this on will use fancy javascript submission and should degrade gracefully for users not using javascript. It is optional and can be turned on or off at any time.');
    ?>
</label></i>
    </td>
    </tr>
    <tr valign="top">
    <th scope="row"><?php 
    echo __('Include Unsubscribe link?', 'mailchimp_i18n');
    ?>
:</th>
    <td><input name="mc_use_unsub_link" type="checkbox" <?php 
    if (get_option('mc_use_unsub_link') == 'on') {
        echo 'checked="checked"';
    }
    ?>
 id="mc_use_unsub_link" class="code" />
    <i><label for="mc_use_unsub_link"><?php 
    echo __('turning this on will add a link to your host unsubscribe form');
    ?>
</label></i>
    </td>
    </tr>
    <tr valign="top">
	<th scope="row"><?php 
    echo __('Header content', 'mailchimp_i18n');
    ?>
:</th>
	<td>
	<textarea name="mc_header_content" rows="2" cols="50"><?php 
    echo htmlentities(get_option('mc_header_content'));
    ?>
</textarea><br/>
	<i><?php 
    echo __('You can fill this with your own Text, HTML markup (including image links), or Nothing!', 'mailchimp_i18n');
    ?>
</i>
	</td>
	</tr>

	<tr valign="top">
	<th scope="row"><?php 
    echo __('Submit Button text', 'mailchimp_i18n');
    ?>
:</th>
	<td>
	<input type="text" name="mc_submit_text" size="30" value="<?php 
    echo get_option('mc_submit_text');
    ?>
"/>
	</td>
	</tr>

	<tr valign="top">
	<th scope="row"><?php 
    echo __('Custom Styling', 'mailchimp_i18n');
    ?>
:</th>
	<td>
	<table class="widefat">

		<tr><th><label for="mc_custom_style"><?php 
    echo __('Turned On?', 'mailchimp_i18n');
    ?>
</label></th><td><input type="checkbox" name="mc_custom_style" id="mc_custom_style" <?php 
    if (get_option('mc_custom_style') == 'on') {
        echo 'checked="checked"';
    }
    ?>
 /></td></tr>
        <tr><th colspan="2"><?php 
    echo __('Header Settings (only applies if there are no HTML tags in the Header Content area above)', 'mailchimp_i18n');
    ?>
:</th></tr>
		<tr><th><?php 
    echo __('Border Width', 'mailchimp_i18n');
    ?>
:</th><td><input type="text" name="mc_header_border_width" size="3" maxlength="3" value="<?php 
    echo get_option('mc_header_border_width');
    ?>
"/> px<br/>
			<i><?php 
    echo __('Set to 0 for no border, do not enter <strong>px</strong>!', 'mailchimp_i18n');
    ?>
</i>
		</td></tr>
		<tr><th><?php 
    echo __('Border Color', 'mailchimp_i18n');
    ?>
:</th><td>#<input type="text" name="mc_header_border_color" size="7" maxlength="6" value="<?php 
    echo get_option('mc_header_border_color');
    ?>
"/><br/>
			<i><?php 
    echo __('do not enter initial <strong>#</strong>', 'mailchimp_i18n');
    ?>
</i>
		</td></tr>
		<tr><th>Text Color:</th><td>#<input type="text" name="mc_header_text_color" size="7" maxlength="6" value="<?php 
    echo get_option('mc_header_text_color');
    ?>
"/><br/>
			<i><?php 
    echo __('do not enter initial <strong>#</strong>', 'mailchimp_i18n');
    ?>
</i>
		</td></tr>
		<tr><th>Background Color:</th><td>#<input type="text" name="mc_header_background" size="7" maxlength="6" value="<?php 
    echo get_option('mc_header_background');
    ?>
"/><br/>
			<i><?php 
    echo __('do not enter initial <strong>#</strong>', 'mailchimp_i18n');
    ?>
</i>
		</td></tr>
		
        <tr><th colspan="2"><?php 
    echo __('Form Settings', 'mailchimp_i18n');
    ?>
:</th></tr>
		<tr><th><?php 
    echo __('Border Width', 'mailchimp_i18n');
    ?>
:</th><td><input type="text" name="mc_form_border_width" size="3" maxlength="3" value="<?php 
    echo get_option('mc_form_border_width');
    ?>
"/> px<br/>
			<i><?php 
    echo __('Set to 0 for no border, do not enter <strong>px</strong>!', 'mailchimp_i18n');
    ?>
</i>
		</td></tr>
		<tr><th><?php 
    echo __('Border Color', 'mailchimp_i18n');
    ?>
:</th><td>#<input type="text" name="mc_form_border_color" size="7" maxlength="6" value="<?php 
    echo get_option('mc_form_border_color');
    ?>
"/><br/>
			<i><?php 
    echo __('do not enter initial <strong>#</strong>', 'mailchimp_i18n');
    ?>
</i>
		</td></tr>
		<tr><th>Text Color:</th><td>#<input type="text" name="mc_form_text_color" size="7" maxlength="6" value="<?php 
    echo get_option('mc_form_text_color');
    ?>
"/><br/>
			<i><?php 
    echo __('do not enter initial <strong>#</strong>', 'mailchimp_i18n');
    ?>
</i>
		</td></tr>
		<tr><th>Background Color:</th><td>#<input type="text" name="mc_form_background" size="7" maxlength="6" value="<?php 
    echo get_option('mc_form_background');
    ?>
"/><br/>
			<i><?php 
    echo __('do not enter initial <strong>#</strong>', 'mailchimp_i18n');
    ?>
</i>
		</td></tr>
	</table>
</td>
</tr>
</table>
</div>
<input type="submit" name="change_form_settings" value="<?php 
    echo __('Update Subscribe Form Settings', 'mailchimp_i18n');
    ?>
" class="button" />
<div style="width:400px;">
<h4><?php 
    echo __('Merge Variables Included', 'mailchimp_i18n');
    ?>
</h4>
<?php 
    if (sizeof($mv) == 0 || !is_array($mv)) {
        echo "<i>" . __('No Merge Variables found.', 'mailchimp_i18n') . "</i>";
    } else {
        ?>
	
	<table class='widefat'>
	<tr valign="top">
	<th><?php 
        echo __('Name', 'mailchimp_i18n');
        ?>
</th>
	<th><?php 
        echo __('Tag', 'mailchimp_i18n');
        ?>
</th>
	<th><?php 
        echo __('Required?', 'mailchimp_i18n');
        ?>
</th>
	<th><?php 
        echo __('Include?', 'mailchimp_i18n');
        ?>
</th>
	</tr>
	<?php 
        foreach ($mv as $var) {
            echo '<tr valign="top">
			<td>' . htmlentities($var['name']) . '</td>
			<td>' . $var['tag'] . '</td>
			<td>' . ($var['req'] == 1 ? 'Y' : 'N') . '</td><td>';
            if (!$var['req']) {
                $opt = 'mc_mv_' . $var['tag'];
                echo '<input name="' . $opt . '" type="checkbox" ';
                if (get_option($opt) == 'on') {
                    echo ' checked="checked" ';
                }
                echo 'id="' . $opt . '" class="code" />';
            } else {
                echo ' - ';
            }
            echo '</td></tr>';
        }
        echo '</table>';
    }
    echo '<h4>' . __('Interest Groups', 'mailchimp_i18n') . '</h4>';
    if (!$ig || $ig == '' || $ig == 'N') {
        echo "<i>" . __('No Interest Groups Setup for this List', 'mailchimp_i18n') . "</i>";
    } else {
        ?>
	<table class='widefat'>
	<tr valign="top">
	<th width="75px"><label for="mc_show_interest_groups"><?php 
        echo __('Show?', 'mailchimp_i18n');
        ?>
</label></th><th>
	<input name="mc_show_interest_groups" id="mc_show_interest_groups" type="checkbox" <?php 
        if (get_option('mc_show_interest_groups') == 'on') {
            echo 'checked="checked"';
        }
        ?>
 id="mc_show_interest_groups" class="code" />
	</th></tr>
	<tr valign="top">
	<th><?php 
        echo __('Name', 'mailchimp_i18n');
        ?>
:</th><th><?php 
        echo $ig['name'];
        ?>
</th>
	</tr>
	<tr valign="top">
	<th><?php 
        echo __('Input Type', 'mailchimp_i18n');
        ?>
:</th><td><?php 
        echo $ig['form_field'];
        ?>
</td>
	</tr>
	<tr valign="top">
	<th><?php 
        echo __('Options', 'mailchimp_i18n');
        ?>
:</th><td><ul>
	<?php 
        foreach ($ig['groups'] as $interest) {
            echo '<li>' . htmlentities($interest);
        }
        echo '</ul></td></tr></table>';
    }
    ?>
<p class="submit">
<input type="hidden" name="action" value="update" />
<input type="submit" name="change_form_settings" value="<?php 
    echo __('Update Subscribe Form Settings', 'mailchimp_i18n');
    ?>
" class="button" />
</p>
</div>
</form>
</div>
</div><!--wrap-->
<?php 
}