You are here

function radioactivity_admin_profile_form_submit in Radioactivity 6

Same name and namespace in other branches
  1. 5 radioactivity.module \radioactivity_admin_profile_form_submit()

File

./radioactivity-admin-ui.inc, line 259
Radioactivity core admin UI.

Code

function radioactivity_admin_profile_form_submit($form_id, $form) {
  $form_values = $form['values'];
  $dpid = (int) $form_values['decay_profile_id'];
  if ($dpid == 0) {

    // internal error
    drupal_set_message(t('Internal error: decay_profile_id=@dpid', array(
      '@dpid' => $dpid,
    )), 'error');
    return FALSE;
  }
  $decay_profiles = radioactivity_get_decay_profiles();
  if ($dpid < 0) {

    // get new $dpid
    $dpids = array_keys($decay_profiles);
    if (count($dpids) > 0) {
      $dpid = 1 + max($dpids);
    }
    else {
      $dpid = 1;
    }
    $new_profile = TRUE;
  }
  else {
    $new_profile = FALSE;
  }

  // build profile array
  $decay_profile = array();
  $decay_profile['label'] = $form_values['label'];
  $decay_profile['description'] = $form_values['description'];
  $half_life = (int) $form_values['half_life'];
  if ($half_life <= 0) {
    $half_life = 6 * 3600;
  }
  $decay_profile['half_life'] = $half_life;
  $decay_profile['cut_off_energy'] = (double) $form_values['cut_off_energy'];
  $decay_profile['energy'] = _radioactivity_prune_array($form_values['energy']);
  $decay_profiles[$dpid] = $decay_profile;
  _radioactivity_set_decay_profiles($decay_profiles);
  drupal_set_message(t('Profile @dpid saved.', array(
    '@dpid' => $dpid,
  )));
  if ($new_profile) {

    // we need a jump, as this profile's edit url just changed
    drupal_goto('admin/settings/radioactivity/edit_profile/' . $dpid);
  }
}