You are here

function radioactivity_admin_profile_form in Radioactivity 5

Same name and namespace in other branches
  1. 6 radioactivity-admin-ui.inc \radioactivity_admin_profile_form()
1 string reference to 'radioactivity_admin_profile_form'
radioactivity_menu in ./radioactivity.module

File

./radioactivity.module, line 237

Code

function radioactivity_admin_profile_form($dpid) {
  $form = array();
  if (!(int) $dpid) {
    $dpid = -1;
  }
  $form[] = array(
    '#type' => 'item',
    '#title' => t('Profile id'),
    '#value' => $dpid > 0 ? $dpid : t('Unassigned'),
  );
  $form['decay_profile_id'] = array(
    '#type' => 'hidden',
    '#value' => $dpid,
  );
  if ($dpid > 0) {
    $decay_profiles = _radioactivity_get_decay_profiles();
    $decay_profile = $decay_profiles[$dpid];
    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,
        ),
      ),
      'label' => '',
      'description' => '',
    );
  }
  $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'),
  );
  $form['buttons']['delete'] = array(
    '#value' => l(t('Delete profile'), 'admin/settings/radioactivity/profile_' . $dpid . '/delete'),
  );
  if (!empty($_POST) && form_get_errors()) {
    drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
  }
  return $form;
}