You are here

function mailchimp_lists_overview_page in Mailchimp 7.5

Same name and namespace in other branches
  1. 7.2 modules/mailchimp_lists/includes/mailchimp_lists.admin.inc \mailchimp_lists_overview_page()
  2. 7.3 modules/mailchimp_lists/includes/mailchimp_lists.admin.inc \mailchimp_lists_overview_page()
  3. 7.4 modules/mailchimp_lists/includes/mailchimp_lists.admin.inc \mailchimp_lists_overview_page()

Administrative display showing existing lists/audiences and allowing edits/adds.

1 string reference to 'mailchimp_lists_overview_page'
mailchimp_lists_menu in modules/mailchimp_lists/mailchimp_lists.module
Implements hook_menu().

File

modules/mailchimp_lists/includes/mailchimp_lists.admin.inc, line 11
mailchimp_lists module admin settings.

Code

function mailchimp_lists_overview_page() {
  $mc_lists = mailchimp_get_lists();
  $rows = array();
  $webhook_url = mailchimp_webhook_url();
  foreach ($mc_lists as $mc_list) {
    $webhooks = mailchimp_webhook_get($mc_list->id);
    $enabled = FALSE;
    if ($webhooks) {
      foreach ($webhooks as $webhook) {
        if ($webhook_url == $webhook->url) {
          $enabled = TRUE;
          continue;
        }
      }
    }
    if ($enabled) {

      // This is a webhook for this MailChimp Module.
      $webhook_status = t('ENABLED') . ' (' . l(t('disable'), 'admin/config/services/mailchimp/lists/' . $mc_list->id . '/webhook/disable') . ')';
    }
    else {
      $webhook_status = t('disabled') . ' (' . l(t('enable'), 'admin/config/services/mailchimp/lists/' . $mc_list->id . '/webhook/enable') . ')';
    }
    $rows[] = array(
      l($mc_list->name, 'https://admin.mailchimp.com/lists/dashboard/overview?id=' . $mc_list->web_id, array(
        'attributes' => array(
          'target' => '_blank',
        ),
      )),
      $mc_list->stats->member_count,
      $webhook_status,
    );
  }
  $table = array(
    'header' => array(
      t('Name'),
      t('Members'),
      t('Webhook Status'),
    ),
    'rows' => $rows,
  );
  $refresh_link = l(t('Refresh audiences from MailChimp'), 'admin/config/services/mailchimp/list_cache_clear', array(
    'query' => array(
      'destination' => 'admin/config/services/mailchimp/lists',
    ),
  ));
  if (empty($mc_lists)) {
    $table['caption'] = $refresh_link;
    drupal_set_message(t('You don\'t have any audiences configured in your MailChimp account, (or you haven\'t configured your API key correctly on the Global Settings tab). Head over to !link and create some audiences, then come back here and click "Refresh audiences from MailChimp"', array(
      '!link' => l(t('MailChimp'), 'https://admin.mailchimp.com/lists/'),
    )), 'warning');
  }
  else {
    $options = t('Currently Available MailChimp audiences') . ':<i>';
    foreach ($mc_lists as $mc_list) {
      $options .= ' ' . $mc_list->name . ',';
    }
    $options = rtrim($options, ',');
    $options .= ".</i><br />" . $refresh_link;
    $table['caption'] = $options;
  }
  return theme('table', $table);
}