You are here

contactlists.admin.inc in Constant Contact 6.2

File

contactlists.admin.inc
View source
<?php

/**
 * @file
 */

/**
 * Displays the manage contact lists admin page
 */
function constant_contact_manage_lists() {
  $lists = array();
  $next_page = false;
  $prev_page = false;

  // if we have an object get the users contact lists
  $cc = constant_contact_create_object();
  if (is_object($cc)) {
    $_lists = $cc
      ->get_lists();
    if ($_lists) {
      foreach ($_lists as $k => $v) {
        $lists[$v['id']] = t($v['Name']);
      }
    }
    if ($cc->list_meta_data->next_page) {
      $next_page = $cc->list_meta_data->next_page;
    }
  }
  $html = '';
  $html .= '<p>' . l(t('Add a new contact list'), "admin/constant_contact/lists/add") . '</p>';
  $html .= '<table cellspacing="3" cellpadding="3" border="0">';
  $html .= '<tr><th>List Name</th><th colspan="2">&nbsp;</th></tr>';
  foreach ($lists as $id => $name) {
    $html .= '<tr>';
    $html .= '<td>' . $name . '</td>';
    $html .= '<td>' . l(t('Edit'), "admin/constant_contact/lists/edit/{$id}") . '</td>';
    $html .= '<td>' . l(t('Delete'), "admin/constant_contact/lists/delete/{$id}") . '</td>';
    $html .= '</tr>';
  }
  if ($next_page) {
    $html .= '<tr><td colspan="3" align="right">' . l(t('Next Page'), "admin/constant_contact/lists/{$next_page}") . '</td></tr>';
  }
  $html .= '</table>';
  return $html;
}

/**
 * Displays the manage contact lists page in the admin
 */
function constant_contact_edit_list($id) {
  $node = array(
    'id' => $id,
  );
  return drupal_get_form('constant_contact_edit_list_form', $node);
}

/**
 * Displays the manage contact lists page in the admin
 */
function constant_contact_edit_list_form($form, $formstate) {
  $id = isset($formstate['id']) ? $formstate['id'] : 0;

  // if we have an object do the stuff...
  $cc = constant_contact_create_object();
  if (is_object($cc)) {
    $cclist = $cc
      ->get_list($id);
    $form = array();

    // add account settings
    $form['list'] = array(
      '#type' => 'textfield',
      '#title' => t('List Name'),
      '#description' => t('Enter a name for the contact list'),
      '#default_value' => htmlentities($cclist['Name']),
      '#size' => 60,
    );
    $form['#redirect'] = 'admin/constant_contact/lists';
    $form['id'] = array(
      '#type' => 'value',
      '#value' => $id,
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'),
    );
    return $form;
  }
}

/**
 * Submit handler for the add contact list admin page
 */
function constant_contact_edit_list_form_submit($form, &$form_state) {
  $id = isset($form_state['values']['id']) ? $form_state['values']['id'] : 0;
  $list = isset($form_state['values']['list']) ? $form_state['values']['list'] : '';
  $cc = constant_contact_create_object();
  if (is_object($cc)) {
    $status = $cc
      ->update_list($id, $list);
    if ($status) {
      drupal_set_message(t("The contact list has been saved"));
    }
    else {
      drupal_set_message(t("The contact list could not be saved: {$cc->last_error}"), 'error');
    }
  }
}

/**
 * delete a contact list
 */
function constant_contact_delete_list($id) {
  $node = array(
    'id' => $id,
  );
  $html = '<p>Please confirm you would like to delete this contact list?</p>';
  $html .= drupal_get_form('constant_contact_delete_list_form', $node);
  return $html;
}

/**
 * delete a contact list
 */
function constant_contact_delete_list_form($form, $formstate) {
  $id = isset($formstate['id']) ? $formstate['id'] : 0;
  $form = array();
  $form['#redirect'] = 'admin/constant_contact/lists';
  $form['id'] = array(
    '#type' => 'value',
    '#value' => $id,
  );
  $form['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Continue'),
  );
  return $form;
}

/**
 * Submit handler for the delete contact list admin page
 */
function constant_contact_delete_list_form_submit($form, &$form_state) {
  if (isset($form_state['values']['op'])) {
    if ($form_state['values']['op'] == 'Continue') {
      $id = isset($form_state['values']['id']) ? $form_state['values']['id'] : 0;
      $cc = constant_contact_create_object();
      if (is_object($cc)) {
        $status = $cc
          ->delete_list($id);
        if ($status) {
          drupal_set_message(t('The Contact list has been deleted'));
        }
        else {
          drupal_set_message(t("Failed to delete contact list: {$cc->last_error}"), 'error');
        }
      }
    }
  }
}

/**
 * Add a new contact list page in the admin function
 */
function constant_contact_add_list() {
  return drupal_get_form('constant_contact_add_list_form');
}

/**
 * Add a new contact list page in the admin function
 */
function constant_contact_add_list_form() {
  $form = array();

  // add account settings
  $form['list'] = array(
    '#type' => 'textfield',
    '#title' => t('List Name'),
    '#description' => t('Enter a name for the new contact list'),
    '#default_value' => '',
    '#size' => 60,
  );
  $form['#redirect'] = 'admin/constant_contact/lists';
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}

/**
 * Submit handler for the add contact list admin page
 */
function constant_contact_add_list_form_submit($form, &$form_state) {
  $list = isset($form_state['values']['list']) ? $form_state['values']['list'] : '';
  $cc = constant_contact_create_object();
  if (is_object($cc)) {
    $status = $cc
      ->create_list($list);
    if ($status) {
      drupal_set_message(t('A new contact list has been created'));
    }
    else {
      drupal_set_message(t("Failed to create new contact list: {$cc->last_error}"), 'error');
    }
  }
}

Functions

Namesort descending Description
constant_contact_add_list Add a new contact list page in the admin function
constant_contact_add_list_form Add a new contact list page in the admin function
constant_contact_add_list_form_submit Submit handler for the add contact list admin page
constant_contact_delete_list delete a contact list
constant_contact_delete_list_form delete a contact list
constant_contact_delete_list_form_submit Submit handler for the delete contact list admin page
constant_contact_edit_list Displays the manage contact lists page in the admin
constant_contact_edit_list_form Displays the manage contact lists page in the admin
constant_contact_edit_list_form_submit Submit handler for the add contact list admin page
constant_contact_manage_lists Displays the manage contact lists admin page