You are here

function userprotect_protected_roles in User protect 5

Same name and namespace in other branches
  1. 6 userprotect.module \userprotect_protected_roles()
  2. 7 userprotect.admin.inc \userprotect_protected_roles()

Builds a form for the role protection settings.

Return value

An array representing the form.

1 string reference to 'userprotect_protected_roles'
userprotect_menu in ./userprotect.module
Implementation of hook_menu().

File

./userprotect.module, line 720

Code

function userprotect_protected_roles() {
  $form = array();

  // Get the list of all protections, and the current default settings.
  $options = userprotect_get_protection_display();

  // Build the header.
  $header = array(
    t('Role'),
  );
  foreach ($options as $field => $data) {
    $header[] = $data;
  }

  // Grab all roles but the anonymous role, and grab the current default settings.
  $roles = db_query('SELECT * FROM {role} WHERE rid > %d ORDER BY name', DRUPAL_ANONYMOUS_RID);
  $protected_roles = variable_get('userprotect_role_protections', array());

  // This is a complete list of protections for reference.
  $protections = array_keys(userprotect_user_protection_defaults());

  // Pass in the header and protections so they're available for the theme function.
  // Also, we want this as one big array to save in the variables table, so tree it.
  $form['role_table']['#header'] = $header;
  $form['role_table']['#theme'] = 'userprotect_admin_role_table';
  $form['role_table']['#protections'] = $protections;
  $form['role_table']['userprotect_role_protections']['#tree'] = TRUE;

  // Build a row for each role.
  while ($role = db_fetch_object($roles)) {
    $form['role_table']['userprotect_role_protections'][$role->rid]['name'] = array(
      '#value' => $role->name,
    );

    // Build protections for the row.
    foreach ($protections as $protection) {
      $form['role_table']['userprotect_role_protections'][$role->rid][$protection] = array(
        '#type' => 'checkbox',
      );
      if (isset($protected_roles[$role->rid][$protection])) {
        $form['role_table']['userprotect_role_protections'][$role->rid][$protection]['#default_value'] = $protected_roles[$role->rid][$protection];
      }
    }
  }
  return system_settings_form($form);
}