You are here

function scs_node_selection in Simplenews Content Selection 6.2

Same name and namespace in other branches
  1. 6 scs.pages.inc \scs_node_selection()
  2. 7 scs.module \scs_node_selection()
1 string reference to 'scs_node_selection'
scs_menu in ./scs.module
Implements hook_menu()

File

./scs.pages.inc, line 12

Code

function scs_node_selection($form_state) {
  $filters = array();
  if (!empty($form_state['post'])) {
    if (!empty($form_state['post']['nid'])) {
      $filters['nid'] = $form_state['post']['nid'];
    }
    if (!empty($form_state['post']['title'])) {
      $filters['title'] = $form_state['post']['title'];
    }
    if (!is_numeric($form_state['post']['type'])) {
      $filters['type'] = $form_state['post']['type'];
    }
  }
  $form = array();
  if (is_null($form_state['storage'])) {

    //First step
    $form['step'] = array(
      '#type' => 'hidden',
      '#value' => 1,
    );
    $return = _scs_get_nodes(array(), $filters);
    $nodes = $return['nodes'];
    foreach ($nodes as $node) {
      $form['nid_' . $node->nid] = array(
        '#type' => 'checkbox',
        '#return_value' => $node->nid,
      );
    }
    $form['newsletter_title'] = array(
      '#type' => 'textfield',
      '#title' => t('Title'),
      '#description' => t('Enter the title of this newsletter'),
      '#default_value' => variable_get('scs_default_title', ''),
    );
    $form['newsletter_toc'] = array(
      '#type' => 'checkbox',
      '#title' => t('Create a table of contents'),
      '#description' => t('Create a table of contents at top of the newsletter with the titles of the selected nodes. If newsletter is HTML format, these table of contents will be bookmarks.'),
    );
    $content_types = variable_get('simplenews_content_types', array());
    if (count($content_types) != 1) {
      $form['newsletter_content_type'] = array(
        '#type' => 'select',
        '#title' => t('Content type'),
        '#description' => t('Select the content type of the newsletter you are creating. Only the content types selected ' . l('here', 'admin/settings/simplenews/general') . ' are displayed.'),
        '#options' => $content_types,
      );
    }
    if (variable_get('scs_types', '') != '' && count(_scs_get_types()) != 1) {
      $form['newsletter_type'] = array(
        '#type' => 'select',
        '#title' => t('Newsletter type'),
        '#options' => _scs_get_types(),
        '#default_value' => $type,
      );
    }

    //Filters
    $form['filters'] = array(
      '#type' => 'fieldset',
      '#title' => t('Filters'),
      '#collapsible' => TRUE,
      '#collapsed' => empty($filters) ? TRUE : FALSE,
    );
    $form['filters']['nid'] = array(
      '#type' => 'textfield',
      '#title' => t('Nid'),
      '#description' => t('Filter on nid'),
      '#size' => 10,
    );
    $form['filters']['title'] = array(
      '#type' => 'textfield',
      '#title' => t('Title'),
      '#description' => t('Filter on title. Used as LIKE \'title%\'.'),
    );
    $form['filters']['type'] = array(
      '#type' => 'select',
      '#title' => t('Type'),
      '#options' => _scs_get_typefilter(),
    );
    $form['filters']['filter'] = array(
      '#type' => 'button',
      '#value' => t('Filter'),
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Sort nodes'),
    );
  }
  else {
    $form['step'] = array(
      '#type' => 'hidden',
      '#value' => 2,
    );
    $form = array_merge($form, scs_sort_nodes($form_state['storage']['nodes']));
  }
  return $form;
}