You are here

function radioactivity_admin_profile_form in Radioactivity 6

Same name and namespace in other branches
  1. 5 radioactivity.module \radioactivity_admin_profile_form()
1 string reference to 'radioactivity_admin_profile_form'
radioactivity_menu in ./radioactivity.module

File

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

Code

function radioactivity_admin_profile_form($form_id, $dpid) {
  $form = array();
  $form[] = array(
    '#type' => 'item',
    '#title' => t('Profile id'),
    '#value' => $dpid > 0 ? $dpid : t('Unassigned'),
  );
  $form['decay_profile_id'] = array(
    '#type' => 'hidden',
    '#value' => $dpid,
  );

  // sanity check for $dpid
  $bad_dpid = FALSE;
  if (!isset($dpid) || !is_numeric($dpid) || $dpid != -1 && $dpid < 1) {
    $bad_dpid = TRUE;
  }
  if (!$bad_dpid) {
    if ($dpid > 0) {
      $decay_profiles = radioactivity_get_decay_profiles();
      if (isset($decay_profiles[$dpid])) {
        $decay_profile = $decay_profiles[$dpid];
      }
      else {
        $bad_dpid = TRUE;
      }
      unset($decay_profiles);
    }
    else {

      // defaults for new
      $decay_profile = array(
        'half_life' => 6 * 3600,
        'cut_off_energy' => 0.5,
        'energy' => array(
          'node' => array(
            'view' => 1,
          ),
        ),
      );
    }
  }
  if ($bad_dpid) {
    drupal_goto('admin/settings/radioactivity/list_profiles');
  }
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Profile label'),
    '#required' => TRUE,
    '#description' => t('The profile label. Used in views, links, etc'),
    '#default_value' => $decay_profile['label'],
  );
  $form['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#description' => t('The description of the profile.'),
    '#default_value' => $decay_profile['description'],
  );
  $form['half_life'] = array(
    '#type' => 'textfield',
    '#title' => t('Half-life of the radioactivity in seconds'),
    '#required' => TRUE,
    '#description' => t('Determines the decay rate of the radioactivity. For exaple, if the decay rate is ' . '3600 (one hour), the radioactivity halves once an hour. If it is now 1000, it will ' . 'be 500 after an hour, 250 after two hours, and so on. The default is 6 hours.'),
    '#default_value' => $decay_profile['half_life'],
  );
  $form['cut_off_energy'] = array(
    '#type' => 'textfield',
    '#title' => t('Cut-off energy'),
    '#required' => TRUE,
    '#description' => t('The cut-off energy. Below this energy level, the node is considered non-radioactive and ' . 'the radioactivity information will be deleted from the database. Leave 0 disable cut-off.'),
    '#default_value' => $decay_profile['cut_off_energy'],
  );
  $radioactivity_info = radioactivity_get_radioactivity_info();

  //  $form['debug']=
  //    array('#value' => print_r($radioactivity_info, TRUE));
  $form['energy'] = array(
    '#type' => 'fieldset',
    '#tree' => TRUE,
    '#title' => t('Energy settings'),
  );
  if (count($radioactivity_info["targets"]) == 0) {

    // no energy target classes
    $form['energy']['no_targets'] = array(
      '#type' => 'item',
      '#value' => t('You must enable at least one plug-in that provides an energy target class. ' . 'Try <em>radioactivity_node</em>.'),
    );
  }
  else {
    foreach ($radioactivity_info['targets'] as $oclass => $def) {
      $form['energy'][$oclass] = _radioactivity_oclassdef_to_form($oclass, $oclass, $def, $radioactivity_info['sources'][$oclass], $decay_profile['energy'][$oclass]);
      $form['energy'][$oclass]['#collapsed'] = FALSE;
    }
  }
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save decay profile'),
  );
  if ($dpid > 0) {
    $form['buttons']['delete'] = array(
      '#value' => l(t('Delete profile'), 'admin/settings/radioactivity/delete_profile/' . $dpid),
    );
  }
  if (!empty($_POST) && form_get_errors()) {
    drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
  }
  return $form;
}