You are here

function subscriptions_user_settings_form in Subscriptions 6

Same name and namespace in other branches
  1. 5.2 subscriptions.admin.inc \subscriptions_user_settings_form()
  2. 7 subscriptions.admin.inc \subscriptions_user_settings_form()
  3. 2.0.x subscriptions.admin.old.php \subscriptions_user_settings_form()

Returns the form definition for the settings part of the overview page. This subform is also used for admin/settings/subscriptions/userdefaults.

@params $account Must be a valid user account from user_load() or NULL (for the admin form).

1 string reference to 'subscriptions_user_settings_form'
subscriptions_page_user_overview in ./subscriptions.admin.inc
Construct the overview page, which displays a summary of subscriptions per type as well as the user settings at user/UID/subscriptions. This form is also used for admin/settings/subscriptions/userdefaults.

File

./subscriptions.admin.inc, line 488
Subscriptions module (load-on-demand admin functions).

Code

function subscriptions_user_settings_form(&$form_state, $account) {
  global $user;
  $uid = isset($account) ? $account->uid : -DRUPAL_AUTHENTICATED_RID;
  $tr = 't';
  $form['settings'] = array(
    '#type' => 'fieldset',
    '#title' => $tr('Settings'),
    '#weight' => 5,
    '#collapsible' => isset($account),
    '#collapsed' => isset($account),
  );
  if ($uid < 0) {
    $form['settings']['info'] = array(
      '#type' => 'fieldset',
      '#title' => $tr('Admin Information'),
      '#attributes' => array(
        'class' => 'error',
      ),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['settings']['info'][] = array(
      '#type' => 'item',
      '#value' => '<div>' . t("The subtabs here under %User_defaults mirror those found at !My_account_Subscriptions, except that the fieldsets here come up already expanded. Please go there now and familiarize yourself with what's there!", array(
        '%User_defaults' => $tr('User defaults'),
        '!My_account_Subscriptions' => l($tr('My account') . '|' . $tr('Subscriptions'), 'user/' . $user->uid . '/subscriptions'),
        '%Settings' => $tr('Settings'),
      )) . '</div>',
    );
    $form['settings']['info'][] = array(
      '#type' => 'item',
      '#value' => '<div>' . t("The default settings that you define here are used for those users that haven't (yet) saved their own settings.", array(
        '%User_defaults' => $tr('User defaults'),
        '!My_account_Subscriptions' => l($tr('My account') . '|' . $tr('Subscriptions'), 'user/' . $user->uid . '/subscriptions'),
        '%Settings' => $tr('Settings'),
      )) . '</div>',
    );
    $form['settings']['info']['hide_overview_page'] = array(
      '#type' => 'checkbox',
      '#title' => t('Hide the %Overview page from your users', array(
        '%Overview' => t('Overview'),
      )),
      '#default_value' => variable_get('subscriptions_hide_overview_page', 0),
      '#description' => t("If you hide this page, your users won't be able to change any of these settings. The default is OFF.") . '<br />' . t('Also, you must give your users the %subscribe_to_content permission, so that they have access to the %Pages_Threads page!', array(
        '%subscribe_to_content' => $tr('subscribe to content'),
        '%Pages_Threads' => $tr('Pages/Threads'),
      )),
    );
  }
  $form['settings']['autosub'] = array(
    '#type' => 'fieldset',
    '#title' => t('Auto-subscribe'),
    '#access' => !isset($account) || user_access('subscribe to content', $account),
  );
  $form['settings']['autosub']['autosub_post'] = array(
    '#type' => 'checkbox',
    '#title' => t('Auto-subscribe to new content'),
    '#default_value' => _subscriptions_get_setting('autosub_on_post', $account),
    '#description' => t('Automatically subscribes you to items that you create.'),
  );
  $form['settings']['autosub']['autosub_update'] = array(
    '#type' => 'checkbox',
    '#title' => t('Auto-subscribe to updated content'),
    '#default_value' => _subscriptions_get_setting('autosub_on_update', $account),
    '#description' => t('Automatically subscribes you to items that you update (if you have that permission).'),
  );
  $form['settings']['autosub']['autosub_comment'] = array(
    '#type' => 'checkbox',
    '#title' => t('Auto-subscribe to comments'),
    '#default_value' => _subscriptions_get_setting('autosub_on_comment', $account),
    '#description' => t('Automatically subscribes you to items that you comment on (or where you update a comment, if you have that permission).'),
    '#access' => module_exists('comment') && (!isset($account) || user_access('post comments', $account) || user_access('post comments without approval', $account)),
  );
  $form['settings']['sendself'] = array(
    '#type' => 'checkbox',
    '#title' => t('Notify poster of own posts'),
    '#default_value' => _subscriptions_get_setting('send_self', $account),
    '#description' => t("Sends you notifications about your own posts (if you're subscribed)."),
  );
  $form['settings']['digest'] = array(
    '#type' => 'checkbox',
    '#title' => t('Digest mode'),
    '#default_value' => _subscriptions_get_setting('digest', $account),
    '#description' => t("Merges your notifications into a single email, sent at the interval you specify."),
  );
  if (_subscriptions_get_setting('send_interval_visible', $account) == -2) {
    $interval = _subscriptions_send_intervals();
    $interval = $interval[_subscriptions_get_setting('send_interval', $account)];
    $form['settings']['digest']['#description'] = t('Merges your notifications into a single email, sent at regular intervals (%interval).', array(
      '%interval' => $interval,
    ));
  }
  $form['settings']['preferences'] = array(
    '#type' => 'fieldset',
    '#title' => t('Preferences'),
    '#access' => FALSE,
  );
  $form['settings']['preferences']['send_interval'] = array(
    '#title' => t('Send interval'),
    '#type' => 'select',
    '#options' => _subscriptions_send_intervals(),
    '#default_value' => _subscriptions_get_setting('send_interval', $account),
    '#description' => t('The frequency of notifications; it may take longer, but notifications will not be sent more frequently than indicated.'),
  );
  $form['settings']['preferences']['send_updates'] = array(
    '#title' => t('On updates'),
    '#type' => 'checkbox',
    '#default_value' => _subscriptions_get_setting('send_updates', $account),
    '#description' => t('Sends a notification when an item is updated.'),
  );
  $form['settings']['preferences']['send_comments'] = array(
    '#title' => t('On comments'),
    '#type' => 'checkbox',
    '#default_value' => _subscriptions_get_setting('send_comments', $account),
    '#description' => t('Sends a notification when an item receives a comment or reply.'),
  );
  $form['settings']['preferences']['description'] = array(
    '#value' => t('Any changes you make here will only apply to newly created subscriptions.'),
  );
  $form['settings']['visibility'] = array(
    '#type' => 'fieldset',
    '#title' => t('Visibility of controls'),
    '#collapsible' => isset($account),
    '#collapsed' => isset($account),
    '#access' => FALSE,
  );
  $form['settings']['visibility'][] = array(
    '#type' => 'item',
    '#description' => t('The control(s) mentioned below appear(s) as one or more columns<br /> a) in the %Subscribe subform of node pages and<br /> b) on the sibling subtabs of this %Overview page.<br /> After you have set your %Preferences right above, you may want to hide the corresponding column(s), if you never change those values anyway.', array(
      '%Subscribe' => $tr('Subscribe'),
      '%Overview' => $tr('Overview'),
      '%Preferences' => $tr('Preferences'),
    )),
  );
  $visibility_options = array(
    t('Visible'),
    t('Hidden'),
  );
  if (!isset($account)) {
    $visibility_options[] = t('Permanently hidden, except for the %preferences', array(
      '%preferences' => 'Preferences',
    ));
    $visibility_options[] = t('Completely inaccessible to the user');
    $form['settings']['visibility']['info'] = array(
      '#type' => 'fieldset',
      '#title' => $tr('Admin Information'),
      '#attributes' => array(
        'class' => 'error',
      ),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['settings']['visibility']['info'][] = array(
      '#type' => 'item',
      '#value' => t("Beyond defining the %Visible/%Hidden defaults for your users, you can", array(
        '%Visible' => $tr('Visible'),
        '%Hidden' => $tr('Hidden'),
      )) . '<ul><li>' . t("permanently hide the columns (and the corresponding visibility controls), so that the users cannot make them visible anymore (they can still change their %Preferences though), or", array(
        '%Preferences' => $tr('Preferences'),
      )) . '</li>' . '<li>' . t("you can even hide the %Preferences, so that what you've set right above is cast in stone.", array(
        '%Preferences' => $tr('Preferences'),
      )) . '</li></ul>',
    );
  }
  foreach (array(
    'interval',
    'updates',
    'comments',
  ) as $parm) {
    $site_setting = _subscriptions_get_setting('send_' . $parm . '_visible', 0);
    $suppress_comment_controls = $parm == 'comments' && !module_exists('comment');
    $pref_access = (!isset($account) || $site_setting >= -1) && !$suppress_comment_controls;
    $control_access = (!isset($account) || $site_setting >= 0) && !$suppress_comment_controls;
    $form['settings']['visibility']['send_' . $parm . '_visible'] = array(
      '#title' => $parm == 'interval' ? t('Send interval') : ($parm == 'updates' ? t('On updates') : t('On comments')),
      '#type' => 'radios',
      '#options' => $visibility_options,
      '#default_value' => 1 - _subscriptions_get_setting('send_' . $parm . '_visible', $account),
      '#access' => $control_access,
    );
    if ($control_access) {
      $form['settings']['visibility']['#access'] = TRUE;
    }
    $form['settings']['preferences']['send_' . $parm]['#access'] = $pref_access;
    if ($pref_access) {
      $form['settings']['preferences']['#access'] = TRUE;
    }
  }
  $form['settings']['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  if ($uid > 0 && !_subscriptions_get_setting('uses_defaults', $account)) {
    $form['settings']['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Reset to site defaults'),
    );
  }
  return $form;
}