You are here

function advuser_filters in Advanced User 5.2

Same name and namespace in other branches
  1. 6.3 advuser.module \advuser_filters()
  2. 6.2 advuser_filters.inc \advuser_filters()
  3. 7.4 advuser.module \advuser_filters()
  4. 7.3 advuser.module \advuser_filters()

List advuser administration filters that can be applied.

3 calls to advuser_filters()
advuser_build_filter_query in ./advuser_filters.inc
Build query for advuser administration filters based on session.
advuser_filter_form in ./advuser_filters.inc
Return form for advuser administration filters.
advuser_filter_form_submit in ./advuser_filters.inc
Process result from user administration filter form.

File

./advuser_filters.inc, line 270
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_filters() {

  // Regular filters
  $filters = array();
  $options = array();
  $t_module = t('module');
  foreach (module_list() as $module) {
    if ($permissions = module_invoke($module, 'perm')) {
      asort($permissions);
      foreach ($permissions as $permission) {
        $options["{$module} {$t_module}"][$permission] = t($permission);
      }
    }
  }
  ksort($options);
  $filters['permission'] = array(
    'title' => t('Permission'),
    'where' => " ((u.uid %in (SELECT ur.uid FROM {users_roles} ur WHERE ur.rid %in (SELECT p.rid FROM {permission} p WHERE p.perm %op '%s'))) %andor u.uid %eq 1)",
    'options' => $options,
    'form_type' => 'select',
  );
  $filters['status'] = array(
    'title' => t('Status'),
    'where' => "u.status %op '%s'",
    'options' => array(
      1 => t('active'),
      0 => t('blocked'),
    ),
    'form_type' => 'select',
  );
  $filters['created'] = array(
    'title' => t('Created'),
    'where' => "u.created %op '%s'",
    'form_type' => 'date',
  );
  $filters['last_access'] = array(
    'title' => t('Accessed'),
    'where' => "u.access %op '%s'",
    'form_type' => 'date',
  );
  $filters['email'] = array(
    'title' => t('Email'),
    'where' => "u.mail %op '%s'",
    'form_type' => 'textfield',
  );
  $filters['uid'] = array(
    'title' => t('User Id'),
    'where' => "u.uid %op %d",
    'form_type' => 'id',
  );
  $roles = advuser_user_roles();
  if (count($roles)) {
    $filters['user_roles'] = array(
      'title' => t('Role'),
      'where' => "ur.rid %op %d",
      'form_type' => 'select',
      'options' => $roles,
    );
  }
  $profile_fields = advuser_profile_fields();
  foreach ($profile_fields as $field) {

    // Build array of options if they exist
    $opts = NULL;
    if (!empty($field->options)) {
      $opts = array();
      foreach (explode("\n", $field->options) as $opt) {
        $opt = trim($opt);
        $opts[$opt] = $opt;
      }
    }

    // Each user defined profile field needs a unique table identifier for the
    //  JOIN and WHERE clauses.
    // TODO: Make sure the $field->name contains valid information for a table
    //  identifier.  This comment is to identify the source of a problem yet
    //  to be discovered.
    $pv = $field->name;
    $filters[$field->name] = array(
      'title' => check_plain($field->title),
      'type' => $field->type,
      'class' => $field->name,
      'where' => "{$pv}.value %op '%s' AND {$pv}.uid = u.uid",
      'options' => $opts,
      'autocomplete' => $field->autocomplete ? $field->fid : FALSE,
    );
  }
  return $filters;
}