You are here

function legal_administration in Legal 7.2

Same name and namespace in other branches
  1. 5 legal.module \legal_administration()
  2. 6.8 legal.admin.inc \legal_administration()
  3. 6.7 legal.module \legal_administration()
  4. 7 legal.admin.inc \legal_administration()

Module settings form.

1 string reference to 'legal_administration'
legal_menu in ./legal.module
Implements hook_menu().

File

./legal.admin.inc, line 41
Administration UI for the Legal module.

Code

function legal_administration($form_state) {
  $form = array();
  $conditions = legal_get_conditions();
  if (module_exists('locale')) {
    $languages = locale_language_list();
    $language_default = language_default();
    $language = $language_default->language;
    $version_options = array(
      'version' => t('All users (new version)'),
      'revision' => t('Language specific users (a revision)'),
    );
    $version_handling = 'version';
  }
  else {
    $languages = array(
      'en' => t('English'),
    );
    $language = 'en';
    $version_handling = 'version';
  }
  $form = array_merge($form, legal_display_fields($conditions));
  $form['conditions'] = array(
    '#type' => 'textarea',
    '#title' => t('Terms & Conditions'),
    '#default_value' => $conditions['conditions'],
    '#description' => t('Your Terms & Conditions'),
    '#required' => TRUE,
  );

  // Set this here or array will flatten out and override real values.
  $form['legal']['#tree'] = TRUE;

  // Overide accept checbox requirement on preview.
  $form['legal']['legal_accept']['#required'] = FALSE;

  // Overide display setting.
  $form['display'] = array(
    '#type' => 'radios',
    '#title' => t('Display Style'),
    '#default_value' => variable_get('legal_display', '0'),
    '#options' => array(
      t('Scroll Box'),
      t('Scroll Box (CSS)'),
      t('HTML Text'),
      t('Page Link'),
    ),
    '#description' => t('How terms & conditions should be displayed to users.'),
    '#required' => TRUE,
  );

  // Only display options if there's more than one language available.
  if (count($languages) > 1) {

    // Language and version handling options.
    $form['language'] = array(
      '#type' => 'fieldset',
      '#title' => t('Language'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['language']['language'] = array(
      '#type' => 'select',
      '#title' => t('Language'),
      '#options' => $languages,
      '#default_value' => $language,
    );
    $form['language']['version_handling'] = array(
      '#type' => 'select',
      '#title' => t('Ask To Re-accept'),
      '#description' => t('<strong>All users</strong>: all users will be asked to accept the new version of the T&C, including users who accepted a previous version.<br />
                           <strong>Language specific</strong>: only new users, and users who accepted the T&C in the same language as this new revision will be asked to re-accept.'),
      '#options' => $version_options,
      '#default_value' => $version_handling,
    );
  }
  else {
    $form['language']['language'] = array(
      '#type' => 'value',
      '#value' => $language,
    );
    $form['language']['version_handling'] = array(
      '#type' => 'value',
      '#value' => $version_handling,
    );
  }

  // Additional checkboxes.
  $form['extras'] = array(
    '#type' => 'fieldset',
    '#title' => t('Additional Checkboxes'),
    '#description' => t('Each field will be shown as a checkbox which the user must tick to register.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => TRUE,
  );
  $extras_count = count($conditions['extras']) < 10 ? 10 : count($conditions['extras']);
  for ($counter = 1; $counter <= $extras_count; $counter++) {
    $extra = isset($conditions['extras']['extras-' . $counter]) ? $conditions['extras']['extras-' . $counter] : '';
    $form['extras']['extras-' . $counter] = array(
      '#type' => 'textarea',
      '#title' => t('Label'),
      '#default_value' => $extra,
    );

    // Overide extra checkboxes.
    if (!empty($conditions['extras']['extras-' . $counter])) {
      $form['legal']['extras-' . $counter] = array(
        '#type' => 'checkbox',
        '#title' => filter_xss_admin($extra),
        '#default_value' => 0,
        '#weight' => 2,
        '#required' => FALSE,
      );
    }
  }

  // Notes about changes to T&C.
  $form['changes'] = array(
    '#type' => 'fieldset',
    '#title' => t('Explain Changes'),
    '#description' => t('Explain what changes were made to the T&C since the last version. This will only be shown to users who accepted a previous version. Each line will automatically be shown as a bullet point.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['changes']['changes'] = array(
    '#type' => 'textarea',
    '#title' => t('Changes'),
  );
  $form['#after_build'] = array(
    'legal_preview',
  );
  $form['preview'] = array(
    '#type' => 'button',
    '#value' => t('Preview'),
  );
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}