You are here

function scs_node_selection_submit in Simplenews Content Selection 6.2

Same name and namespace in other branches
  1. 6 scs.pages.inc \scs_node_selection_submit()
  2. 7 scs.module \scs_node_selection_submit()

File

./scs.pages.inc, line 140

Code

function scs_node_selection_submit($form, &$form_state) {
  if ($form_state['values']['step'] == 1) {

    //Standard fields
    $form_state['storage']['title'] = $form_state['values']['newsletter_title'];
    $form_state['storage']['toc'] = $form_state['values']['newsletter_toc'];

    //Content type
    if (array_key_exists('newsletter_content_type', $form_state['values'])) {
      $form_state['storage']['type'] = $form_state['values']['newsletter_content_type'];
    }
    else {
      $types = variable_get('simplenews_content_types', array());
      foreach ($types as $type) {
        $form_state['storage']['type'] = $type;
      }
    }

    //Newsletter type
    if (array_key_exists('newsletter_type', $form_state['values'])) {
      $form_state['storage']['scs_type'] = $form_state['values']['newsletter_type'];
    }

    //Selected nodes
    foreach ($form_state['values'] as $field => $value) {
      if (ereg('nid_', $field) && $value != 0) {
        $nodes[] = $value;
      }
    }
    $form_state['storage']['nodes'] = $nodes;

    //Next step
    $form_state['storage']['step'] = 2;
    $form_state['rebuild'] = TRUE;
  }
  else {

    //Click on create newsletter
    $nodes = array();
    foreach ($form_state['values'] as $key => $value) {
      if (ereg('weight_', $key)) {
        $nid = explode('_', $key);
        $nid = $nid[1];
        $region = $form_state['values']['region_' . $nid];
        $nodes[$region][$nid] = $value;
      }
    }
    foreach ($nodes as $region => $elements) {
      asort($elements);
      $elements = array_keys($elements);
      $nodes[$region] = $elements;
    }

    //Create options array
    $options = array(
      'title' => $form_state['storage']['title'],
      'nodes' => $nodes,
      'toc' => $form_state['storage']['toc'],
      'content_type' => $form_state['storage']['type'],
    );
    if (array_key_exists('scs_type', $form_state['storage'])) {
      $options['newsletter_type'] = $form_state['storage']['scs_type'];
    }
    _scs_create_newsletter($options);
  }
}