You are here

function advuser_admin_account in Advanced User 5.2

Same name and namespace in other branches
  1. 6.3 forms/advuser_admin_account.inc \advuser_admin_account()
  2. 6.2 advuser.module \advuser_admin_account()
  3. 7.3 forms/advuser_admin_account.inc \advuser_admin_account()
1 string reference to 'advuser_admin_account'
advuser_admin in ./advuser.module

File

./advuser.module, line 81
Advanced user module allows you to select users based on an advanced set of filtering and apply actions to block, unblock, delete or email the selected users.

Code

function advuser_admin_account() {
  $filter = advuser_build_filter_query();
  $header = array(
    array(),
    array(
      'data' => t('Username'),
      'field' => 'u.name',
    ),
    array(
      'data' => t('Status'),
      'field' => 'u.status',
    ),
  );
  $roles = advuser_user_roles();
  if (count($roles)) {
    $header[] = t('Roles');
  }
  $header = array_merge($header, array(
    array(
      'data' => t('Member for'),
      'field' => 'u.created',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Last access'),
      'field' => 'u.access',
    ),
  ));
  $query = '';
  $ff = array();
  $pf = array();
  foreach (advuser_profile_fields() as $field) {
    $ff[] = array(
      'data' => t($field->title),
      'field' => "{$field->name}.value",
    );
    $pf[] = "LEFT JOIN {profile_values} {$field->name} ON {$field->name}.fid = {$field->fid} AND {$field->name}.uid = u.uid";
  }
  $header = array_merge($header, $ff);
  $header[] = t('Operations');
  $filter['join'] .= count($pf) ? ' ' . implode(' ', array_unique($pf)) : NULL;
  $sql = 'SELECT DISTINCT u.uid, u.name, u.status, u.created, u.access ' . $pquery . ' FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid ' . $filter['join'] . ' WHERE u.uid != 0 ' . $filter['where'];
  $sql .= tablesort_sql($header);
  $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'];
  $result = pager_query($sql, variable_get('advuser_listno', 50), 0, $query_count, $filter['args']);
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update options'),
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
  );
  $options = array();
  $operations = module_invoke_all('user_operations');
  $operations = array_merge($operations, module_invoke_all('advuser_operations'));
  foreach ($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 = advuser_user_roles();
  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'),
    );
    module_invoke('profile', 'load_profile', $account);
    foreach (advuser_profile_fields() as $field) {
      $form[$field->name][$account->uid] = array(
        '#value' => profile_view_field($account, $field),
      );
    }
    $fv = l(t('edit'), "user/{$account->uid}/edit", array(), $destination);
    if ($account->uid != 1) {
      $fv .= ' | ' . l(t('delete'), "user/{$account->uid}/delete", array(), $destination);
    }
    $form['operations'][$account->uid] = array(
      '#value' => $fv,
    );
  }
  $form['accounts'] = array(
    '#type' => 'checkboxes',
    '#options' => $accounts,
  );
  $form['pager'] = array(
    '#value' => theme('pager', NULL, 50, 0),
  );
  return $form;
}