You are here

function newsletter_template_list in Newsletter 7

Menu callback; present an administrative template listing.

1 string reference to 'newsletter_template_list'
newsletter_menu in ./newsletter.module
Implements hook_menu().

File

includes/newsletter.admin.inc, line 1144
Admin page callbacks for the newsletter module.

Code

function newsletter_template_list($form, &$form_state) {
  if (isset($form_state['storage']['confirm'])) {
    $form['operation'] = array(
      '#type' => 'hidden',
      '#value' => 'delete',
    );
    $form['template'] = array(
      '#type' => 'hidden',
      '#value' => $form_state['values']['template'],
    );
    $templates = newsletter_template_load($form_state['values']['template']);
    $output = t('Are you sure you want to delete the following templates?');
    $output .= '<ul>';
    foreach ($templates as $template) {
      $output .= !empty($template) ? '<li>' . check_plain($template->subject) . '</li>' : '';
    }
    $output .= '</ul>';
    $output .= t('This action cannot be undone.');
    return confirm_form($form, t('Delete the following?'), 'admin/config/media/newsletter/templates', filter_xss($output));
  }
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Options'),
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
  );
  $options['delete'] = t('Delete the selected templates');
  $form['options']['operation'] = array(
    '#type' => 'select',
    '#title' => t('Operation'),
    '#title_display' => 'invisible',
    '#options' => $options,
    '#default_value' => 'delete',
  );
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );
  $header = array(
    'id' => array(
      'data' => t('ID'),
      'field' => 'ntid',
    ),
    'title' => array(
      'data' => t('Title'),
      'field' => 'subject',
    ),
    'exposed' => array(
      'data' => t('Exposed'),
      'field' => 'exposed',
    ),
    'created' => array(
      'data' => t('Created'),
      'field' => 'created',
      'sort' => 'desc',
    ),
    'operations' => array(
      'data' => t('Operations'),
    ),
  );
  $query = db_select('newsletter_template', 'templates')
    ->extend('PagerDefault')
    ->extend('TableSort');
  $result = $query
    ->fields('templates', array(
    'ntid',
    'subject',
    'exposed',
    'created',
  ))
    ->condition('basic', 0)
    ->limit(50)
    ->orderByHeader($header)
    ->execute();
  $options = array();
  $destination = drupal_get_destination();
  foreach ($result as $row) {
    $options[$row->ntid] = array(
      'id' => (int) $row->ntid,
      'title' => check_plain($row->subject),
      'exposed' => $row->exposed ? t('Yes') : t('No'),
      'created' => format_date($row->created, 'short'),
      'operations' => array(
        'data' => array(
          array(
            '#type' => 'link',
            '#title' => t('edit'),
            '#href' => 'admin/config/media/newsletter/templates/edit/' . $row->ntid,
            '#options' => array(
              'query' => $destination,
            ),
          ),
          array(
            '#markup' => ' | ',
          ),
          array(
            '#type' => 'link',
            '#title' => t('delete'),
            '#href' => 'admin/config/media/newsletter/templates/delete/' . $row->ntid,
            '#options' => array(
              'query' => $destination,
            ),
          ),
        ),
      ),
    );
  }
  $form['template'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('No templates available.'),
  );
  $form['pager'] = array(
    '#theme' => 'pager',
  );
  return $form;
}