function user_admin_account

Form builder; User administration page.

See also

user_admin_account_validate()

user_admin_account_submit()

Related topics

1 string reference to 'user_admin_account'
user_admin in drupal/core/modules/user/user.admin.inc
@file Admin page callback file for the user module.

File

drupal/core/modules/user/user.admin.inc, line 144
Admin page callback file for the user module.

Code

function user_admin_account() {
  $header = array(
    'username' => array(
      'data' => t('Username'),
      'field' => 'u.name',
    ),
    'status' => array(
      'data' => t('Status'),
      'field' => 'u.status',
      'class' => array(
        RESPONSIVE_PRIORITY_LOW,
      ),
    ),
    'roles' => array(
      'data' => t('Roles'),
      'class' => array(
        RESPONSIVE_PRIORITY_LOW,
      ),
    ),
    'member_for' => array(
      'data' => t('Member for'),
      'field' => 'u.created',
      'sort' => 'desc',
      'class' => array(
        RESPONSIVE_PRIORITY_LOW,
      ),
    ),
    'access' => array(
      'data' => t('Last access'),
      'field' => 'u.access',
      'class' => array(
        RESPONSIVE_PRIORITY_LOW,
      ),
    ),
    'operations' => t('Operations'),
  );
  $query = db_select('users', 'u');
  $query
    ->condition('u.uid', 0, '<>');
  user_build_filter_query($query);
  $count_query = clone $query;
  $count_query
    ->addExpression('COUNT(u.uid)');
  $query = $query
    ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->extend('Drupal\\Core\\Database\\Query\\TableSortExtender');
  $query
    ->fields('u', array(
    'uid',
    'name',
    'status',
    'created',
    'access',
  ))
    ->limit(50)
    ->orderByHeader($header)
    ->setCountQuery($count_query);
  $result = $query
    ->execute();
  $form['options'] = array(
    '#type' => 'details',
    '#title' => t('Update options'),
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
  );
  $options = array();
  foreach (module_invoke_all('user_operations') as $operation => $array) {
    $options[$operation] = $array['label'];
  }
  $form['options']['operation'] = array(
    '#type' => 'select',
    '#title' => t('Operation'),
    '#title_display' => 'invisible',
    '#options' => $options,
    '#default_value' => 'unblock',
  );
  $options = array();
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );
  $destination = drupal_get_destination();
  $status = array(
    t('blocked'),
    t('active'),
  );
  $roles = array_map('check_plain', user_roles(TRUE));
  $accounts = array();
  foreach ($result as $account) {
    $account = user_load($account->uid);
    $users_roles = array();
    $roles_result = db_query('SELECT rid FROM {users_roles} WHERE uid = :uid', array(
      ':uid' => $account->uid,
    ));
    foreach ($roles_result as $user_role) {
      $users_roles[] = $roles[$user_role->rid];
    }
    asort($users_roles);
    $options[$account->uid] = array(
      'username' => theme('username', array(
        'account' => $account,
      )),
      'status' => $status[$account->status],
      'roles' => theme('item_list', array(
        'items' => $users_roles,
      )),
      'member_for' => format_interval(REQUEST_TIME - $account->created),
      'access' => $account->access ? t('@time ago', array(
        '@time' => format_interval(REQUEST_TIME - $account->access),
      )) : t('never'),
    );
    $links = array();
    $links['edit'] = array(
      'title' => t('edit'),
      'href' => 'user/' . $account->uid . '/edit',
      'query' => $destination,
    );
    if (module_invoke('translation_entity', 'translate_access', $account)) {
      $links['translate'] = array(
        'title' => t('translate'),
        'href' => 'user/' . $account->uid . '/translations',
        'query' => $destination,
      );
    }
    $options[$account->uid]['operations']['data'] = array(
      '#type' => 'operations',
      '#links' => $links,
    );
  }
  $form['accounts'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('No people available.'),
  );
  $form['pager'] = array(
    '#markup' => theme('pager'),
  );
  return $form;
}