You are here

function advuser_filter_form in Advanced User 6.2

Same name and namespace in other branches
  1. 5.2 advuser_filters.inc \advuser_filter_form()

Return form for advuser administration filters.

2 string references to 'advuser_filter_form'
advuser_admin in ./advuser.module
advuser_filter_form_validate in ./advuser_filters.inc
Validate values entered.

File

./advuser_filters.inc, line 13
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_filter_form() {
  $session =& $_SESSION['advuser_overview_filter'];
  $session = is_array($session) ? $session : array();
  $filters = advuser_filters();
  $i = 0;
  $form['filters'] = array(
    '#type' => 'fieldset',
    '#title' => t('Show only users where'),
    '#theme' => 'advuser_filters',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  foreach ($session as $filter) {
    list($type, $value, $op, $qop) = $filter;

    // Merge an array of arrays into one if necessary.
    if ($filters[$type]['form_type'] == 'select') {
      $options = $type == 'permission' ? call_user_func_array('array_merge', $filters[$type]['options']) : $filters[$type]['options'];
      $params = array(
        '%property' => $filters[$type]['title'],
        '%value' => $options[$value],
      );
    }
    else {
      $params = array(
        '%property' => $filters[$type]['title'],
        '%value' => $value,
      );
    }
    if ($i++ > 0) {
      $form['filters']['current'][] = array(
        '#value' => t('<em>' . $op . '</em> where <strong>%property</strong> ' . _qop($qop) . ' <strong>%value</strong>', $params) . ($i == count($session) ? ')' : ''),
      );
    }
    else {
      $form['filters']['current'][] = array(
        '#value' => t('(<strong>%property</strong> ' . _qop($qop) . ' <strong>%value</strong>', $params) . ($i == count($session) ? ')' : ''),
      );
    }
  }
  foreach ($filters as $key => $filter) {
    $names[$key] = $filter['title'];
    switch ($filter['form_type']) {
      case 'select':
        $form['filters']['status'][$key] = array(
          '#type' => 'select',
          '#options' => $filter['options'],
        );
        break;
      case 'date':
        $form['filters']['status'][$key] = array(
          '#type' => 'textfield',
          '#size' => 20,
          '#maxlength' => 25,
          '#default_value' => 'now',
          '#description' => 'You can enter this as an actual date (e.g. "' . date('M d Y') . '") or how long ago (e.g. "1 month 4 day 13hours ago")',
        );
        break;
      case 'id':
        $form['filters']['status'][$key] = array(
          '#type' => 'textfield',
          '#size' => 5,
          '#maxsize' => 10,
        );
        break;
      case 'textfield':
        $form['filters']['status'][$key] = array(
          '#type' => 'textfield',
          '#size' => 30,
        );
        break;
      default:
        $autocomplete = '';
        if ($filter['autocomplete']) {
          $autocomplete = "profile/autocomplete/" . $filter['autocomplete'];
        }
        switch ($filter['type']) {
          case 'selection':
            $form['filters']['status'][$key] = array(
              '#type' => 'select',
              '#options' => $filter['options'],
              '#autocomplete_path' => $autocomplete,
            );
            break;
          case 'checkbox':
            $form['filters']['status'][$key] = array(
              '#type' => 'checkbox',
            );
            break;
          default:
            $form['filters']['status'][$key] = array(
              '#type' => $filter['type'],
              '#options' => $filter['options'],
              '#autocomplete_path' => $autocomplete,
              '#size' => 20,
            );
            break;
        }

        //End switch ($filter['type']).
        break;
    }
  }
  $form['filters']['filter'] = array(
    '#type' => 'radios',
    '#options' => $names,
  );
  $form['filters']['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => count($session) ? t('Refine') : t('Filter'),
  );
  if (count($session)) {
    $form['filters']['buttons']['undo'] = array(
      '#type' => 'submit',
      '#value' => t('Undo'),
    );
    $form['filters']['buttons']['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Reset'),
    );
  }
  $form['filters']['filters_ops'] = array(
    '#type' => 'select',
    '#options' => array(
      'AND' => t('and'),
      ') OR (' => t('or'),
    ),
  );
  $form['filters']['filters_qops'] = array(
    '#type' => 'select',
    '#options' => array(
      '=' => 'EQ',
      '!=' => 'NE',
      '<' => 'LT',
      '>' => 'GT',
      '<=' => 'LE',
      '>=' => 'GE',
      'LIKE' => 'CO',
      'NOT LIKE' => 'NC',
      'BEGINS WITH' => 'BE',
      'ENDS WITH' => 'EN',
    ),
    '#attributes' => array(
      'title' => t("\n      'EQ' => 'is equal to'\n      'NE' => 'is not equal to'\n      'LT' => 'is less than'\n      'GT' => 'is greater than'\n      'LE' => 'is less than or equal to'\n      'GE' => 'is greater than or equal to'\n      'CO' => 'contains'\n      'NC' => 'does not contain'\n      'BE' => 'begins with'\n      'EN' => 'ends with'"),
    ),
  );
  return $form;
}