View source
<?php
function constant_contact_manage_lists() {
$lists = array();
$next_page = false;
$prev_page = false;
$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"> </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;
}
function constant_contact_edit_list($id) {
$node = array(
'id' => $id,
);
return drupal_get_form('constant_contact_edit_list_form', $node);
}
function constant_contact_edit_list_form($form, $formstate) {
$id = isset($formstate['id']) ? $formstate['id'] : 0;
$cc = constant_contact_create_object();
if (is_object($cc)) {
$cclist = $cc
->get_list($id);
$form = array();
$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;
}
}
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');
}
}
}
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;
}
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;
}
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');
}
}
}
}
}
function constant_contact_add_list() {
return drupal_get_form('constant_contact_add_list_form');
}
function constant_contact_add_list_form() {
$form = array();
$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;
}
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');
}
}
}