You are here

function subuser_settings_form in Subuser 6

Sub user settings form.

1 string reference to 'subuser_settings_form'
subuser_menu in ./subuser.module
Implementation of hook_menu().

File

./subuser.pages.inc, line 12
Allows users of a particular role to create sub user account in another role.

Code

function subuser_settings_form(&$form_state) {
  $form = array();

  // Get all non-default roles.
  $roles = user_roles(TRUE);
  unset($roles[DRUPAL_ANONYMOUS_RID]);
  unset($roles[DRUPAL_AUTHENTICATED_RID]);
  $form['display'] = array(
    '#type' => 'fieldset',
    '#title' => t('Display'),
    '#description' => t('Configure the wording used for creating a subuser.'),
  );
  $form['display']['subuser_parent'] = array(
    '#type' => 'textfield',
    '#title' => t('Parent'),
    '#description' => t('Name for parent user.'),
    '#default_value' => SUBUSER_PARENT,
  );
  $form['display']['subuser_list'] = array(
    '#type' => 'textfield',
    '#title' => t('List'),
    '#description' => t('Displayed above a users list of subusers.'),
    '#default_value' => SUBUSER_LIST,
  );
  $form['display']['subuser_create'] = array(
    '#type' => 'textfield',
    '#title' => t('Create'),
    '#description' => t('The text used for the link and page title when creating a subuser.'),
    '#default_value' => SUBUSER_CREATE,
  );
  $form['display']['subuser_administer'] = array(
    '#type' => 'textfield',
    '#title' => t('Administer'),
    '#description' => t('The text used for the link and page title when administering subusers.'),
    '#default_value' => SUBUSER_ADMINISTER,
  );
  if ($roles) {
    $form['roles'] = array(
      '#type' => 'fieldset',
      '#title' => t('Roles'),
      '#description' => t('Choose the roles you would like for sub users to automatically have when created.'),
    );
    $form['roles']['subuser_roles'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Available roles'),
      '#options' => $roles,
      '#default_value' => variable_get('subuser_roles', array()),
    );
  }
  else {
    drupal_set_message(t('No available roles to select. Please <a href="@admin-role">create a role</a>.', array(
      '@admin-role' => url("admin/user/roles"),
    )), 'error');
  }
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced settings'),
  );
  $form['advanced']['subuser_limit'] = array(
    '#type' => 'textfield',
    '#title' => t('Subuser account limit'),
    '#default_value' => variable_get('subuser_limit', 0),
    '#description' => t("Specify a maximum number of subuser accounts per user. Leave as '0' for no limit."),
    '#size' => 3,
  );
  $form['advanced']['subuser_children_block'] = array(
    '#type' => 'select',
    '#title' => t('When parents are blocked are children blocked?'),
    '#description' => t("If 'yes' is selected when a parent account is blocked the associated children will be blocked as well"),
    '#options' => array(
      0 => 'No',
      1 => 'Yes',
    ),
    '#default_value' => variable_get('subuser_children_block', 1),
  );
  $form['advanced']['subuser_children_unblock'] = array(
    '#type' => 'select',
    '#title' => t('When parents are unblocked are children unblocked?'),
    '#description' => t("If 'yes' is selected when a parent account is unblocked the associated children will be unblocked as well."),
    '#options' => array(
      0 => 'No',
      1 => 'Yes',
    ),
    '#default_value' => variable_get('subuser_children_unblock', 1),
  );
  $form['advanced']['subuser_children_roles'] = array(
    '#type' => 'select',
    '#title' => t('When parents roles change should the child account change to match?'),
    '#description' => t("If 'yes' is selected and the roles of a parent account change the child accounts will have the same role additions or subtractions."),
    '#options' => array(
      0 => 'No',
      1 => 'Yes',
    ),
    '#default_value' => variable_get('subuser_children_roles', 1),
  );
  $form['advanced']['subuser_cascade_exempt_rid'] = array(
    '#type' => 'select',
    '#title' => t('Should we exempt any role from the cascading behavior?'),
    '#description' => t('A role set here will not cascade down to subusers. This allows one role to be given add subuser permission, without that role accidentally propagating down to subusers.'),
    '#options' => user_roles(),
    '#default_value' => variable_get('subuser_cascade_exempt_rid', NULL),
  );
  $form['advanced']['subuser_copy_parent_roles'] = array(
    '#type' => 'select',
    '#title' => t('On subuser creation, the subuser should get all the roles of a parent (except for the role prevented from cascading behaviour)'),
    '#description' => t("If 'yes' is selected, the subuser should get all the roles of a parent (except the role exempt from cascading behaviour). Also the roles marked above in 'Choose the roles you would like for subusers to automatically have when created will be given to the subuser in addition to parent roles."),
    '#options' => array(
      0 => 'No',
      1 => 'Yes',
    ),
    '#default_value' => variable_get('subuser_copy_parent_roles', 0),
  );
  $form['advanced']['subuser_orphaned_children'] = array(
    '#type' => 'select',
    '#title' => t('How are orphaned child accounts handled?'),
    '#default_value' => variable_get('subuser_orphaned_children', 0),
    '#description' => t('Choose how to handle subuser accounts when the parent account is deleted.'),
    '#options' => array(
      0 => t('Do Nothing'),
      1 => t('Block the Subusers'),
      // TODO It would be nice to allow a role shift here instead too...
      2 => t('Delete the Subusers'),
    ),
  );

  // Should we show the default administer links on the user page?
  $form['advanced']['subuser_show_admin'] = array(
    '#type' => 'select',
    '#title' => t('Show administer link on user form'),
    '#options' => array(
      0 => t('No'),
      1 => t('Yes'),
    ),
    '#default_value' => variable_get('subuser_show_admin', 1),
  );

  // Should parent be cc'd when subusers are sent mail?
  $form['advanced']['subuser_cc_parent'] = array(
    '#type' => 'select',
    '#title' => t('CC parent when subusers are sent mail'),
    '#options' => array(
      0 => t('No'),
      1 => t('Yes'),
    ),
    '#default_value' => variable_get('subuser_cc_parent', 0),
  );

  // Ensure that menu rebuild takes place after variables have been saved.
  $form = system_settings_form($form);
  $form['#validate'][] = 'subuser_settings_form_validate';
  $form['#submit'][] = 'subuser_settings_form_submit';
  return $form;
}