You are here

function user_admin_account in Drupal 6

Same name and namespace in other branches
  1. 4 modules/user.module \user_admin_account()
  2. 5 modules/user/user.module \user_admin_account()
  3. 7 modules/user/user.admin.inc \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 modules/user/user.admin.inc
Page callback: Generates the appropriate user administration form.

File

modules/user/user.admin.inc, line 143
Admin page callback file for the user module.

Code

function user_admin_account() {
  $filter = user_build_filter_query();
  $header = array(
    array(),
    array(
      'data' => t('Username'),
      'field' => 'u.name',
    ),
    array(
      'data' => t('Status'),
      'field' => 'u.status',
    ),
    t('Roles'),
    array(
      'data' => t('Member for'),
      'field' => 'u.created',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Last access'),
      'field' => 'u.access',
    ),
    t('Operations'),
  );
  if ($filter['join'] != "") {
    $sql = 'SELECT DISTINCT u.uid, u.name, u.status, u.created, u.access FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid ' . $filter['join'] . ' WHERE u.uid != 0 ' . $filter['where'];
    $query_count = 'SELECT COUNT(DISTINCT u.uid) FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid ' . $filter['join'] . ' WHERE u.uid != 0 ' . $filter['where'];
  }
  else {
    $sql = 'SELECT u.uid, u.name, u.status, u.created, u.access FROM {users} u WHERE u.uid != 0 ' . $filter['where'];
    $query_count = 'SELECT COUNT(u.uid) FROM {users} u WHERE u.uid != 0 ' . $filter['where'];
  }
  $sql .= tablesort_sql($header);
  $result = pager_query($sql, 50, 0, $query_count, $filter['args']);
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update options'),
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
  );
  $options = array();
  foreach (module_invoke_all('user_operations') as $operation => $array) {
    $options[$operation] = $array['label'];
  }
  $form['options']['operation'] = array(
    '#type' => 'select',
    '#options' => $options,
    '#default_value' => 'unblock',
  );
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );
  $destination = drupal_get_destination();
  $status = array(
    t('blocked'),
    t('active'),
  );
  $roles = user_roles(TRUE);
  $accounts = array();
  while ($account = db_fetch_object($result)) {
    $accounts[$account->uid] = '';
    $form['name'][$account->uid] = array(
      '#value' => theme('username', $account),
    );
    $form['status'][$account->uid] = array(
      '#value' => $status[$account->status],
    );
    $users_roles = array();
    $roles_result = db_query('SELECT rid FROM {users_roles} WHERE uid = %d', $account->uid);
    while ($user_role = db_fetch_object($roles_result)) {
      $users_roles[] = $roles[$user_role->rid];
    }
    asort($users_roles);
    $form['roles'][$account->uid][0] = array(
      '#value' => theme('item_list', $users_roles),
    );
    $form['member_for'][$account->uid] = array(
      '#value' => format_interval(time() - $account->created),
    );
    $form['last_access'][$account->uid] = array(
      '#value' => $account->access ? t('@time ago', array(
        '@time' => format_interval(time() - $account->access),
      )) : t('never'),
    );
    $form['operations'][$account->uid] = array(
      '#value' => l(t('edit'), "user/{$account->uid}/edit", array(
        'query' => $destination,
      )),
    );
  }
  $form['accounts'] = array(
    '#type' => 'checkboxes',
    '#options' => $accounts,
  );
  $form['pager'] = array(
    '#value' => theme('pager', NULL, 50, 0),
  );
  return $form;
}