View source
<?php
define('MAILCHIMP_LISTTYPE_REQUIRED', 'required');
define('MAILCHIMP_LISTTYPE_OPTIN', 'optin');
define('MAILCHIMP_LISTTYPE_OPTOUT', 'optout');
define('MAILCHIMP_USERSTATUS_PENDING', 'pending');
define('MAILCHIMP_USERSTATUS_CURRENT', 'current');
function mailchimp_form_user_register_form_alter(&$form, &$form_state, $form_id) {
$account = $form['#user'];
$category = $form['#user_category'];
if (variable_get('mailchimp_user_register', TRUE)) {
$account->roles = array(
2 => 'authenticated',
);
if (count(_mailchimp_get_available_lists($account)) > 0) {
$form['mailchimp_lists'] = array(
'#type' => 'fieldset',
'#title' => t('Newsletters'),
);
$form['mailchimp_lists'][] = mailchimp_subscribe_auth_form(NULL, NULL, $account, FALSE);
}
}
}
function mailchimp_user_insert(&$edit, $account, $category) {
if ($q = _mailchimp_get_api_object()) {
foreach ((array) _mailchimp_get_available_lists($account) as $list) {
if ($list->listtype == MAILCHIMP_LISTTYPE_REQUIRED) {
if (!variable_get('mailchimp_cron', FALSE)) {
$is_allowed = FALSE;
$roles = $edit['roles'];
if (!is_array($roles)) {
$roles = $account->roles;
}
foreach ($list->roles as $key => $value) {
if (array_key_exists($key, $roles)) {
$is_allowed = TRUE;
break;
}
}
if ($is_allowed) {
$userinfo = _mailchimp_load_user_list_mergevars($account, $list->id);
$userinfo['EMAIL'] = $edit['mail'];
_mailchimp_subscribe_user($list, $account->mail, $userinfo, FALSE, $q);
}
else {
_mailchimp_unsubscribe_user($list, $account->mail, FALSE, $q);
}
}
else {
$result = db_query("SELECT uid FROM {mailchimp_user} WHERE uid = :uid", array(
':uid' => $account->uid,
));
if ($result
->rowCount() == 0) {
db_insert('mailchimp_user')
->fields(array(
'uid' => $account->uid,
'status' => MAILCHIMP_USERSTATUS_PENDING,
))
->execute();
}
}
}
else {
$ret = TRUE;
$selected = @$edit['mailchimp_list_' . $list->id];
if ($selected) {
$merge_vars = _mailchimp_load_user_list_mergevars($account, $list->id);
if (!empty($edit['mailchimp_list_' . $list->id . '_INTERESTS'])) {
$merge_vars['INTERESTS'] = implode(',', array_filter($edit['mailchimp_list_' . $list->id . '_INTERESTS']));
}
$ret = _mailchimp_subscribe_user($list, $account->mail, $merge_vars, TRUE, $q);
}
if (!$ret) {
drupal_set_message(t('There was a problem with your newsletter signup: @msg', array(
'@msg' => $q->errorMessage,
)));
}
}
}
}
}
function mailchimp_user_delete($account) {
if ($q = _mailchimp_get_api_object()) {
foreach ((array) _mailchimp_get_required_lists() as $list) {
db_delete('mailchimp_user')
->condition('uid', $account->uid)
->execute();
_mailchimp_unsubscribe_user($list, $account->mail, FALSE, $q);
}
}
}
function mailchimp_user_update(&$edit, $account, $category) {
if ($q = _mailchimp_get_api_object()) {
foreach ((array) _mailchimp_get_required_lists() as $list) {
if (!variable_get('mailchimp_cron', FALSE)) {
$is_allowed = FALSE;
$roles = $account->roles;
foreach ($list->roles as $key => $value) {
if (array_key_exists($key, $roles)) {
$is_allowed = TRUE;
break;
}
}
if ($is_allowed) {
$userinfo = _mailchimp_load_user_list_mergevars($account, $list->id);
if (isset($edit['mail'])) {
$userinfo['EMAIL'] = $edit['mail'];
}
_mailchimp_subscribe_user($list, $account->mail, $userinfo, FALSE, $q);
}
else {
_mailchimp_unsubscribe_user($list, $account->mail, FALSE, $q);
}
}
else {
db_update('mailchimp_user')
->fields(array(
'status' => MAILCHIMP_USERSTATUS_PENDING,
))
->condition('uid', $account->uid)
->execute();
}
}
}
}
function mailchimp_subscribe_auth_form($form, $form_state, $account, $standalone = TRUE, $list = NULL) {
$form = array();
$lists = !empty($list) ? array(
$list,
) : _mailchimp_get_available_lists($account, TRUE);
if (count($lists) == 0) {
$form['value'] = array(
'#markup' => t('There are no available newsletters subscriptions.'),
'#prefix' => '<div>',
'#suffix' => '</div>',
);
}
else {
if ($q = _mailchimp_get_api_object()) {
if ($account->uid > 0) {
$form['uid'] = array(
'#type' => 'hidden',
'#value' => $account->uid,
);
}
else {
$account->roles = array(
2 => 'authenticated',
);
}
foreach ($lists as $list) {
mailchimp_auth_newsletter_form($form, $list, $account, $q);
}
if ($standalone) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('save settings'),
'#weight' => 100,
);
}
}
}
return $form;
}
function mailchimp_auth_newsletter_form(&$form, $list, $account, $q) {
$is_subscribed = FALSE;
if ($account && $account->uid > 0) {
$memberinfo = $q
->listMemberInfo($list->id, $account->mail);
$is_subscribed = $memberinfo['status'] == 'subscribed';
$default_value = $is_subscribed;
}
else {
$default_value = $list->listtype == MAILCHIMP_LISTTYPE_OPTOUT ? TRUE : FALSE;
}
$form['wrapper' . $list->id] = array(
'#prefix' => '<div class="mailchimp-newsletter-wrapper">',
'#suffix' => '</div>',
);
$form['wrapper' . $list->id]['mailchimp_list_' . $list->id] = array(
'#type' => 'checkbox',
'#title' => $list->label ? t($list->label) : t('Subscribe to the @newsletter newsletter', array(
'@newsletter' => $list->name,
)),
'#default_value' => $default_value,
'#description' => $list->description,
'#attributes' => array(
'class' => array(
'mailchimp-newsletter-checkbox-' . $list->id,
),
),
);
if (variable_get('mailchimp_interest_groups_user_forms', FALSE)) {
if ($intgroup = $q
->listInterestGroups($list->id)) {
switch ($intgroup['form_field']) {
case 'radio':
$field_type = 'radios';
break;
case 'checkbox':
$field_type = 'checkboxes';
break;
default:
$field_type = $intgroup['form_field'];
}
$options = array();
foreach ((array) $intgroup['groups'] as $group) {
$options[$group] = $group;
}
$form['wrapper' . $list->id]['mailchimp_list_' . $list->id . '_INTERESTS'] = array(
'#type' => $field_type,
'#title' => $intgroup['name'],
'#options' => $options,
'#default_value' => $is_subscribed ? explode(",", str_replace(', ', ',', $memberinfo['merges']['INTERESTS'])) : array(),
'#attributes' => array(
'class' => array(
'mailchimp-newsletter-interests-' . $list->id,
),
),
);
drupal_add_js('$(document).ready(function(){
if($(".mailchimp-newsletter-checkbox-' . $list->id . '").attr("checked")){
$(".mailchimp-newsletter-interests-' . $list->id . '").parent(".form-item").show();
} else {
$(".mailchimp-newsletter-interests-' . $list->id . '").parent(".form-item").hide();
}
$(".mailchimp-newsletter-checkbox-' . $list->id . '").click(function(){ $(".mailchimp-newsletter-interests-' . $list->id . '").parent(".form-item").toggle("slow");});
});', 'inline');
}
}
return $form;
}
function mailchimp_subscribe_auth_form_submit($form, &$form_state) {
if ($q = _mailchimp_get_api_object()) {
$account = new stdClass();
if (!empty($form_state['values']['uid'])) {
$account = user_load($form_state['values']['uid']);
}
else {
$account = $form_state['user'];
}
$lists = _mailchimp_get_available_lists($account);
foreach ($lists as $list) {
if ($list->listtype !== MAILCHIMP_LISTTYPE_REQUIRED) {
$is_subscribed = _mailchimp_is_subscribed($list->id, $account->mail, $q);
$ret = TRUE;
$selected = @$form_state['values']['mailchimp_list_' . $list->id];
if ($is_subscribed && !$selected && $form['#id'] != 'user-register') {
$ret = _mailchimp_unsubscribe_user($list, $account->mail, TRUE, $q);
}
elseif ($selected) {
$merge_vars = _mailchimp_load_user_list_mergevars($account, $list->id);
if (!empty($form_state['values']['mail']) && $is_subscribed) {
$merge_vars['EMAIL'] = $form_state['values']['mail'];
}
if (!empty($form_state['values']['mailchimp_list_' . $list->id . '_INTERESTS'])) {
$merge_vars['INTERESTS'] = implode(',', array_filter($form_state['values']['mailchimp_list_' . $list->id . '_INTERESTS']));
}
$ret = _mailchimp_subscribe_user($list, $account->mail, $merge_vars, TRUE, $q);
}
if (!$ret) {
drupal_set_message(t('There was a problem with your newsletter signup: @msg', array(
'@msg' => $q->errorMessage,
)));
}
}
}
}
}
function mailchimp_cron() {
if (variable_get('mailchimp_cron', FALSE) && ($q = _mailchimp_get_api_object())) {
$sql = "SELECT uid FROM {mailchimp_user} WHERE status = :status";
$result = db_query_range($sql, 0, variable_get('mailchimp_batch_limit', 100), array(
':status' => MAILCHIMP_USERSTATUS_PENDING,
));
if ($result) {
$lists = _mailchimp_get_required_lists();
$batches = array();
foreach ($result as $row) {
if ($account = user_load($row->uid)) {
db_query('UPDATE {mailchimp_user} SET status = :status WHERE uid = :uid', array(
':status' => MAILCHIMP_USERSTATUS_CURRENT,
':uid' => $account->uid,
));
if ($account->status) {
foreach ($lists as $key => $list) {
foreach ($account->roles as $rid => $info) {
if (isset($list->roles[$rid])) {
$batches[$list->id][] = _mailchimp_load_user_list_mergevars($account, $list->id);
break;
}
}
}
}
}
else {
db_query('DELETE FROM {mailchimp_user} WHERE uid = :uid', array(
':uid' => $account->uid,
));
}
}
$count = 0;
$ret = array();
foreach ($batches as $listid => $batch) {
if (count($batch)) {
$ret = $q
->listBatchSubscribe($listid, $batch, FALSE, TRUE);
if ($ret['error_count'] > 0) {
foreach ((array) $ret['errors'] as $error) {
watchdog('mailchimp', 'MCAPI Error: %errmsg', array(
'!errmsg' => $error['message'],
), WATCHDOG_ERROR);
}
}
}
$count += $ret['success_count'];
}
watchdog('mailchimp', 'Updated !count records in MailChimp', array(
'!count' => $count,
), WATCHDOG_NOTICE);
}
}
}
function mailchimp_menu() {
$items = array();
$items['user/%user/mailchimp'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array(
'mailchimp_subscribe_auth_form',
1,
),
'title' => 'Newsletter Subscriptions',
'type' => MENU_LOCAL_TASK,
'access callback' => 'mailchimp_user_edit_access',
'access arguments' => array(
1,
),
'tab_parent' => 'user/%/edit',
);
$items['mailchimp/subscribe'] = array(
'page callback' => 'mailchimp_subscribe_page',
'title' => 'Newsletter Subscription',
'type' => MENU_NORMAL_ITEM,
'access arguments' => array(
'access content',
),
);
$items['mailchimp/unsubscribe'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array(
'mailchimp_unsubscribe_form',
),
'title' => 'Newsletter Unsubscribe',
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
$items['mailchimp/unsubscribe/success'] = array(
'page callback' => 'mailchimp_unsubscribe_success',
'title' => 'Unsubscription Confirmed',
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
$items['mailchimp/unsubscribe/failure'] = array(
'page callback' => 'mailchimp_unsubscribe_failure',
'title' => 'Unsubscription Failed',
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
$items['admin/config/services/mailchimp'] = array(
'title' => 'MailChimp',
'description' => 'Manage MailChimp Settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'mailchimp_admin_settings',
),
'access arguments' => array(
'administer mailchimp',
),
'type' => MENU_NORMAL_ITEM,
'file' => 'mailchimp.admin.inc',
);
$items['mailchimp/rebuild'] = array(
'title' => 'Rebuild Users Table',
'page callback' => 'mailchimp_rebuild_users',
'access arguments' => array(
'administer mailchimp',
),
'weight' => 10,
);
return $items;
}
function mailchimp_user_edit_access($user) {
if (variable_get('mailchimp_user_edit', TRUE) && user_edit_access($user)) {
return TRUE;
}
else {
return FALSE;
}
}
function mailchimp_permission() {
return array(
'administer mailchimp' => array(
'title' => t('administer mailchimp'),
'description' => t('TODO Add a description for administer mailchimp'),
),
);
}
function mailchimp_subscribe_page() {
global $user;
$ret = '';
if ($user->uid) {
$ret = drupal_get_form('mailchimp_subscribe_auth_form', $user);
}
elseif ($q = _mailchimp_get_api_object()) {
$ret = drupal_get_form('mailchimp_subscribe_anon_form_all', $q);
}
return $ret;
}
function mailchimp_subscribe_anon_form_all($form, $form_state, $q) {
$form = array(
'#tree' => TRUE,
);
global $user;
$lists = _mailchimp_get_available_lists($user);
foreach ($lists as $list) {
$form['mailchimp_lists'][$list->id] = array(
'#type' => 'fieldset',
'#title' => t('@name', array(
'@name' => $list->name,
)),
'#description' => t('@desc', array(
'@desc' => $list->description,
)),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
_mailchimp_subscribe_anon_form($list, $q, $form['mailchimp_lists'][$list->id]);
if ($form['mailchimp_lists'][$list->id]['EMAIL']) {
$form['mailchimp_lists'][$list->id]['EMAIL']['#required'] = FALSE;
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Sign Up!'),
'#weight' => 100,
);
$form['#submit'][] = 'mailchimp_subscribe_anon_form_submit';
return $form;
}
function mailchimp_subscribe_anon_form_submit($form, &$form_state) {
$lists = $form_state['values']['mailchimp_lists'];
foreach ($lists as $list) {
if (!empty($list['EMAIL'])) {
$success = FALSE;
if (!empty($list['INTERESTS'])) {
$list['INTERESTS'] = implode(',', array_filter($list['INTERESTS']));
}
$success = _mailchimp_subscribe_user($list['list'], $list['EMAIL'], $list, TRUE);
if ($success) {
$msg = variable_get('mailchimp_subscription_success_message', t('Thank you, you have been successfully subscribed.'));
}
else {
$msg = variable_get('mailchimp_subscription_failure_message', t('We were unable to subscribe you at this time. Please try again later.'));
}
drupal_set_message($msg);
}
}
}
function mailchimp_subscribe_anon_form($form, $form_state, $list, $q) {
$form += array(
'#tree' => TRUE,
'#id' => 'mailchimp_subscribe_anon_form_' . $list->id,
);
$form['description'] = array(
'#value' => $list->description,
);
_mailchimp_subscribe_anon_form($list, $q, $form['mailchimp_lists'][$list->id]);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Sign Up!'),
'#weight' => 100,
);
return $form;
}
function _mailchimp_subscribe_anon_form($list, $q, &$form) {
$form['list'] = array(
'#type' => 'value',
'#value' => $list,
);
global $user;
$mergevalues = NULL;
if ($user->uid) {
$mergevalues = _mailchimp_load_user_list_mergevars($user, $list->id);
}
foreach ((array) $q
->listMergeVars($list->id) as $mergevar) {
if ($mergevalues && isset($mergevalues[$mergevar['tag']]) && $mergevalues[$mergevar['tag']]) {
$mergevar['default'] = $mergevalues[$mergevar['tag']];
}
$form[$mergevar['tag']] = _mailchimp_insert_drupal_form_tag($mergevar);
}
if ($intgroup = $q
->listInterestGroups($list->id)) {
switch ($intgroup['form_field']) {
case 'radio':
$field_type = 'radios';
break;
case 'checkbox':
$field_type = 'checkboxes';
break;
default:
$field_type = $intgroup['form_field'];
}
foreach ((array) $intgroup['groups'] as $group) {
$options[$group] = $group;
}
$form['INTERESTS'] = array(
'#type' => $field_type,
'#title' => $intgroup['name'],
'#options' => $options,
);
}
}
function _mailchimp_insert_drupal_form_tag($mergevar) {
$input = array(
'#title' => $mergevar['name'],
'#weight' => $mergevar['order'],
'#required' => $mergevar['req'],
'#default_value' => $mergevar['default'],
);
switch ($mergevar['field_type']) {
case 'dropdown':
$input['#type'] = 'select';
foreach ($mergevar['choices'] as $choice) {
$choices[$choice] = $choice;
}
$input['#options'] = $choices;
break;
case 'radio':
$input['#type'] = 'radios';
foreach ($mergevar['choices'] as $choice) {
$choices[$choice] = $choice;
}
$input['#options'] = $choices;
break;
default:
$input['#type'] = 'textfield';
$input['#size'] = $mergevar['size'];
break;
}
if ($mergevar['public'] == FALSE) {
$input['#type'] = 'hidden';
}
return $input;
}
function mailchimp_unsubscribe_form($form, $form_state) {
$form = array();
$form['intro'] = array(
'#type' => 'markup',
'#value' => t('Use this form to unsubscribe from all of our newsletters.'),
);
$form['EMAIL'] = array(
'#type' => 'textfield',
'#title' => t('Email Address'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Unsubscribe'),
);
return $form;
}
function mailchimp_unsubscribe_form_submit($form, &$form_state) {
if ($q = _mailchimp_get_api_object()) {
$success = TRUE;
foreach ((array) $q
->lists() as $list) {
$success = $success && _mailchimp_unsubscribe_user($list, $form_state['values']['EMAIL'], TRUE, $q);
if ($success) {
drupal_set_message(variable_get('mailchimp_unsubscription_success_message', t('Thank you, you have been successfully unsubscribed.')));
}
else {
drupal_set_message(variable_get('mailchimp_unsubscription_failure_message', t('We were unable to unsubscribe you at this time. Please try again later.')));
}
}
}
}
function mailchimp_unsubscribe_form_validate($form, &$form_state) {
if (!$form_state['values']['EMAIL']) {
form_set_error('EMAIL', t('Please enter your email address.'));
}
else {
if ($q = _mailchimp_get_api_object()) {
$subscribed = FALSE;
foreach ((array) $q
->lists() as $list) {
$subscribed = $subscribed || _mailchimp_is_subscribed($list['id'], $form_state['values']['EMAIL'], $q);
}
if (!$subscribed) {
form_set_error('', t('That email address could not be found.'));
}
}
else {
form_set_error('', t('There was an error processing your request. Please try again later.'));
}
}
}
function _mailchimp_load_user_list_mergevars($account, $list_id) {
$values = array();
$lists = variable_get('mailchimp_lists', array());
$list = $lists[$list_id];
if (!empty($list->mergevars)) {
$mergevars = array_filter($list->mergevars);
$mergevars = array_flip($mergevars);
$values = token_generate('user', $mergevars, array(
'user' => $account,
));
foreach ($values as $key => $value) {
$values[$key] = strip_tags($value);
}
$values += array(
'EMAIL' => $account->mail,
);
}
return $values;
}
function _mailchimp_is_subscribed($listid, $mail, $q = NULL) {
$is_subscribed = FALSE;
if ($q || ($q = _mailchimp_get_api_object())) {
$sub_info = $q
->listMemberInfo($listid, $mail);
$is_subscribed = @$sub_info['status'] == 'subscribed';
}
return $is_subscribed;
}
function _mailchimp_subscribe_user($list, $email, $merge_vars, $message = TRUE, $q = NULL) {
if ($q || ($q = _mailchimp_get_api_object())) {
$double_optin = $list->doublein;
if (empty($merge_vars)) {
$merge_vars = '';
}
if (_mailchimp_is_subscribed($list->id, $email, $q)) {
$action = 'updated in';
$success = $q
->listUpdateMember($list->id, $email, $merge_vars);
if ($success && $message) {
drupal_set_message(t('You have updated your settings in %list.', array(
'%list' => $list->name,
)));
}
}
else {
$action = 'subscribed to';
$success = $q
->listSubscribe($list->id, $email, $merge_vars, 'html', $double_optin, TRUE);
if ($message && $success && $double_optin) {
drupal_set_message(t('You have chosen to subscribe to %list. An email will be sent to your address. Click the link in the email to confirm the subscription.', array(
'%list' => $list->name,
)));
}
elseif ($message && $success) {
drupal_set_message(t('You have subscribed to %list.', array(
'%list' => $list->name,
)));
}
}
}
if ($success) {
watchdog('mailchimp', '@email was @action list @list.', array(
'@action' => $action,
'@email' => $merge_vars['EMAIL'],
'@list' => $list->name,
), WATCHDOG_NOTICE);
}
else {
watchdog('mailchimp', 'A problem occurred subscribing @email to list @list. Message: @msg', array(
'@email' => $merge_vars['EMAIL'],
'@list' => $list->name,
'@msg' => $q->errorMessage,
), WATCHDOG_WARNING);
}
return $success;
}
function _mailchimp_unsubscribe_user($list, $mail, $message = TRUE, $q = NULL) {
$success = FALSE;
if ($q || ($q = _mailchimp_get_api_object())) {
if (_mailchimp_is_subscribed($list->id, $mail, $q)) {
$success = $q
->listUnsubscribe($list->id, $mail, FALSE, FALSE, FALSE);
if ($message && $success) {
drupal_set_message(t('You have unsubscribed from %list.', array(
'%list' => $list->name,
)));
}
}
}
return $success;
}
function _mailchimp_get_available_lists($user, $exclude_required = FALSE) {
$all_lists = variable_get('mailchimp_lists', NULL);
$available_lists = array();
if (is_array($all_lists)) {
foreach ($all_lists as $key => $list) {
if ($exclude_required && $list->listtype === MAILCHIMP_LISTTYPE_REQUIRED) {
continue;
}
foreach ($user->roles as $rid => $info) {
if (!empty($list->roles[$rid])) {
$available_lists[$list->id] = $list;
break;
}
}
}
}
return $available_lists;
}
function _mailchimp_get_required_lists() {
$lists = variable_get('mailchimp_lists', NULL);
if (is_array($lists)) {
foreach ($lists as $key => $list) {
if ($list->listtype !== MAILCHIMP_LISTTYPE_REQUIRED) {
unset($lists[$key]);
}
}
}
return $lists;
}
function _mailchimp_get_api_object() {
module_load_include('php', 'mailchimp', 'MCAPI.class');
$q = new MCAPI(variable_get('mailchimp_api_key', ''));
$q
->setTimeout(60);
if ($q->errorCode) {
watchdog('mailchimp', 'MCAPI Error: %errmsg', array(
'!errmsg' => $q->errorMessage,
), WATCHDOG_ERROR);
return NULL;
}
return $q;
}
function mailchimp_block_info() {
$blocks = array();
$all_lists = variable_get('mailchimp_lists', NULL);
if (is_array($all_lists)) {
foreach ($all_lists as $key => $list) {
if ($list->listtype !== MAILCHIMP_LISTTYPE_REQUIRED) {
$blocks[$list->id] = array(
'info' => t('Mailchimp Subscription Form: @name', array(
'@name' => $list->name,
)),
'cache' => DRUPAL_CACHE_PER_USER,
);
}
}
}
return $blocks;
}
function mailchimp_block_view($delta = '') {
global $user;
$block = array();
$lists = _mailchimp_get_available_lists($user);
$list = isset($lists[$delta]) ? $lists[$delta] : array();
if (!empty($list) && ($q = _mailchimp_get_api_object())) {
$block['subject'] = t('Subscribe to @title', array(
'@title' => $list->name,
));
$block['content'] = drupal_get_form('mailchimp_subscribe_anon_form', $list, $q);
}
return $block;
}
function mailchimp_rebuild_users() {
db_query("DELETE FROM {mailchimp_user}");
db_query("INSERT INTO {mailchimp_user} (uid, status) SELECT uid, '" . MAILCHIMP_USERSTATUS_PENDING . "' FROM {users} WHERE uid > 0");
drupal_set_message('The MailChimp User\'s Table has been rebuilt with all user\'s status set to pending.', 'status');
drupal_goto('admin/config/services/mailchimp');
}