You are here

function site_disclaimer_admin_settings in Site Disclaimer 7

Same name and namespace in other branches
  1. 6 site_disclaimer.admin.inc \site_disclaimer_admin_settings()

Menu callback; show settings form.

See also

site_disclaimer_admin_settings_validate()

1 string reference to 'site_disclaimer_admin_settings'
site_disclaimer_menu in ./site_disclaimer.module
Implements hook_menu().

File

./site_disclaimer.admin.inc, line 119
Administration settings for Site Disclaimer module.

Code

function site_disclaimer_admin_settings($form, &$form_state) {
  $langcode = NULL;

  // Get the language of the multiplingual form to show preview in that language
  if (module_exists('variable_realm')) {
    module_load_include('form.inc', 'variable_realm');
    $langcode = variable_realm_form_key_current('language');
  }
  _site_disclaimer_admin_decode_settings($form_state);

  // Adding the fieldset for node specification.
  $form['site_disclaimer_text'] = array(
    '#type' => 'fieldset',
    '#prefix' => '<div id="fieldset-wrapper">',
    '#suffix' => '</div>',
    '#title' => t('Node to include with Site Disclaimer'),
    '#description' => t('This node typically contains legal statements such as Site Disclaimer, Terms of Use, etc. It is either included entirely in the Site Disclaimer form, or linked from the [x] ckeckbox label (if @link token is used). The node should already exist.'),
  );
  if ($form_state['#site_disclaimer_mode'] == 'node_title') {
    $form['site_disclaimer_text']['site_disclaimer_node_title'] = array(
      '#type' => 'textfield',
      '#title' => t('Node title'),
      '#default_value' => $form_state['values']['site_disclaimer_node_title'],
      '#description' => t('Enter the <em>title</em> of an existing node. Leave empty and also use no token in the [x] checkbox label below to disable Site Disclaimer.'),
      '#autocomplete_path' => 'site_disclaimer/autocomplete',
    );
  }
  else {
    $form['site_disclaimer_text']['site_disclaimer_node_id'] = array(
      '#type' => 'textfield',
      '#title' => t('Node id'),
      '#default_value' => $form_state['values']['site_disclaimer_node_id'],
      '#description' => t('Enter the <em>id</em> of an existing node. Leave empty and also use no token in the [x] checkbox label below to disable Site Disclaimer.'),
    );
  }

  // D7 AHAH is happy when we change '#value' of existing button (in D6 this does not work).
  $form['site_disclaimer_text']['site_disclaimer_pick_node_id'] = array(
    '#type' => 'button',
    '#weight' => 10,
    '#value' => $form_state['#site_disclaimer_mode'] == 'node_title' ? SITE_DISCLAIMER_NODE_ID : SITE_DISCLAIMER_NODE_TITLE,
    '#ajax' => array(
      'callback' => 'site_disclaimer_js',
      'wrapper' => 'fieldset-wrapper',
    ),
  );

  // Adding the fieldset for form specification.
  $form['site_disclaimer_form'] = array(
    '#type' => 'fieldset',
    '#title' => t('Site Disclaimer form settings'),
  );
  $form['site_disclaimer_form']['site_disclaimer_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => isset($form_state['values']['site_disclaimer_title']) ? $form_state['values']['site_disclaimer_title'] : variable_get('site_disclaimer_title', SITE_DISCLAIMER_DEFAULT_TITLE),
    '#description' => t('Enter a title to put on the Site Disclaimer form.'),
  );
  $form['site_disclaimer_form']['site_disclaimer_fieldset'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enclose in a fieldset'),
    '#default_value' => isset($form_state['values']['site_disclaimer_fieldset']) ? $form_state['values']['site_disclaimer_fieldset'] : variable_get('site_disclaimer_fieldset', 1),
    '#description' => t('Enclose the Site Disclaimer form and the [x] checkbox in a fieldset. Helps visually group the form as typically themes display fieldset in a box / add borders.'),
  );
  $form['site_disclaimer_form']['site_disclaimer_checkbox_label'] = array(
    '#type' => 'textfield',
    '#maxlength' => 256,
    // Increase max length to allow lengthier fields (Site Disclaimer can be wordy)
    '#title' => t('[x] checkbox label'),
    '#default_value' => isset($form_state['values']['site_disclaimer_checkbox_label']) ? $form_state['values']['site_disclaimer_checkbox_label'] : variable_get('site_disclaimer_checkbox_label', SITE_DISCLAIMER_DEFAULT_CHECKBOX_LABEL),
    '#description' => t('Enter a Site Disclaimer statement that visitors have to accept, something like <b>I agree with these terms</b>, or <b>I CERTIFY THAT I AM OVER THE AGE OF 18 YEARS OLD</b>.!tokens!example<p>You may want to link to the Terms page if you prefer not to show the full text of the Terms in the registration form.</p><p>If you use any tokens, the full text of the Terms will not be shown.</p>', array(
      '!tokens' => t('<p>The following tokens are substituted on the label:</p><ul><li>@link - a link to the Site Disclaimer node (must be provided above).</li><li>@"Post Title" - a link to a post with title <b>Post Title</b>. If post title contains a double quote, prepend it with a backslash \\".</li></ul>'),
      '!example' => t('<p>For example, the label can be: "I agree with the @link", without quotes.</p>'),
    )),
  );
  $form['site_disclaimer_form']['site_disclaimer_node_height'] = array(
    '#type' => 'textfield',
    '#title' => t('Max height'),
    '#default_value' => isset($form_state['values']['site_disclaimer_node_height']) ? $form_state['values']['site_disclaimer_node_height'] : variable_get('site_disclaimer_node_height', ''),
    '#description' => t('Leave empty to show Site Disclaimer form with text in full height. Enter something like <b>20em</b> or <b>120px</b> to set the height of the Site Disclaimer form. Vertical scrollbar is added automatically if text height exceeds the max height setting.'),
  );
  $form['site_disclaimer_advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Site Disclaimer version'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $version = variable_get('site_disclaimer_version', 1);
  $options = array(
    $version => t('@version (current version)', array(
      '@version' => $version,
    )),
    $version + 1 => t('@version (add a new version)', array(
      '@version' => $version + 1,
    )),
  );
  $form['site_disclaimer_advanced']['site_disclaimer_version'] = array(
    '#type' => 'radios',
    '#title' => t('Add new version'),
    '#description' => t('WARNING: Changing Site Disclaimer version is not reversible. It will require every already registered user to accept the new Site Disclaimer terms upon their login before they can do anything else on the website.'),
    '#options' => $options,
    '#default_value' => isset($form_state['values']['site_disclaimer_version']) ? $form_state['values']['site_disclaimer_version'] : $version,
  );
  $form['site_disclaimer_advanced']['site_disclaimer_version_details'] = array(
    '#type' => 'textarea',
    '#title' => t('Changes'),
    '#description' => t('Describe changes in the latest version. Note: if you are not changing version, this description will be shown to all users who have not accepted the current version.'),
    '#default_value' => isset($form_state['values']['site_disclaimer_version_details']) ? $form_state['values']['site_disclaimer_version_details'] : variable_get('site_disclaimer_version_details', ''),
  );

  //Show a preview of Site Disclaimer forms
  $form['site_disclaimer_preview'] = array(
    '#type' => 'fieldset',
    '#title' => t('Preview'),
    '#description' => t('This is a preview of current configuration. To see how your changes will look, you have to save configuration.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['site_disclaimer_preview']['user_register'] = array(
    '#type' => 'fieldset',
    '#title' => t('User registration page'),
    '#description' => '',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $preview_form = array();
  $form_state_tmp = array();
  site_disclaimer_form_user_register_form_alter($preview_form, $form_state_tmp, 'user_register_form', $langcode, TRUE);
  if (!empty($preview_form)) {
    $preview_form['#type'] = 'item';

    // Use of drupal_render will make the form not affecting the submit process
    $form['site_disclaimer_preview']['user_register']['form']['#markup'] = drupal_render($preview_form);
  }
  else {
    $form['site_disclaimer_preview']['user_register']['#description'] = '<br />' . t('(Site Disclaimer disabled)');
  }
  $form['site_disclaimer_preview']['accept_new'] = array(
    '#type' => 'fieldset',
    '#title' => t('Accept changes page'),
    '#description' => '',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  module_load_include('inc', 'site_disclaimer', 'site_disclaimer.pages');
  $preview_confirm = array();
  $form_state_tmp = array();
  $preview_confirm = site_disclaimer_confirm($preview_confirm, $form_state_tmp, $langcode, TRUE);
  if (!empty($preview_confirm)) {
    $preview_confirm['#type'] = 'item';

    // Use of drupal_render will make the form not affecting the submit process
    $form['site_disclaimer_preview']['accept_new']['form_confirm']['#markup'] = drupal_render($preview_confirm);
  }
  else {
    $form['site_disclaimer_preview']['accept_new']['form_confirm']['#markup'] = '<br />' . t('(Site Disclaimer disabled)');
  }
  $form = system_settings_form($form);

  // Add our handler after the one system_settings_form() adds, so all variables get saved.
  $form['#submit'][] = 'site_disclaimer_admin_settings_submit';
  return $form;
}