function tripal_stock_add_chado_properties_navigate_submit

1.x tripal_stock-secondary_tables.inc tripal_stock_add_chado_properties_navigate_submit($form, $form_state)

Related topics

File

tripal_stock/includes/tripal_stock-secondary_tables.inc, line 146
@todo Add file header description

Code

function tripal_stock_add_chado_properties_navigate_submit($form, $form_state) {

  $raw_steps = preg_split('/::/', $form_state['values']['steps']);

  $steps = array();
  $current_index = 'EMPTY';
  $i = 0;

  foreach ($raw_steps as $raw_step) {
    $step = preg_split('/;/', $raw_step);
    $steps[$i] = $step;

    if ($step[0] == $form_state['values']['current_step']) {
      $current_index = $i;
    }

    $i++;
  }
  $num_steps = $i;

  if (strcmp($current_index, 'EMPTY') == 0) {
    // No Matching Step
    drupal_set_message(t('Could not determine next step - %currentstep, please contact the administrator', array('%currentstep' => $form_state['values']['current_step'])), 'error');
  }
  elseif ($current_index == 0) {
    $next_goto = $steps[$current_index + 1][1];
  }
  elseif ($current_index == ($num_steps -1)) {
    $prev_goto = $steps[$current_index -1][1];
    $next_goto = 'node/%node';
  }
  else {
    $prev_goto = $steps[$current_index -1][1];
    $next_goto = $steps[$current_index + 1][1];
  }

  if ($form_state['clicked_button']['#value'] == t('Previous Step')) {
    //replace %node
    $prev_goto = preg_replace('/%node/', $form_state['values']['nid'], $prev_goto);
    $_REQUEST['destination'] = $prev_goto;
  }
  elseif ($form_state['clicked_button']['#value'] == t('Next Step')) {
    $next_goto = preg_replace('/%node/', $form_state['values']['nid'], $next_goto);
    $_REQUEST['destination'] = $next_goto;
  }
  elseif ($form_state['clicked_button']['#value'] == t('Finish')) {
    $next_goto = preg_replace('/%node/', $form_state['values']['nid'], $next_goto);
    $_REQUEST['destination'] = $next_goto;
  }

}