You are here

function support_filter_form in Support Ticketing System 6

Form builder; Return form for support ticket listing filters.

1 call to support_filter_form()
support_page_form in ./support.module
Display tickets

File

./support.module, line 2746
support.module

Code

function support_filter_form($client, $filters, $state) {

  // Ignore these values when determining if a given filter is active.
  unset($filters['join']);
  unset($filters['where']);
  unset($filters['or']);
  $form = array();
  $form['filter'] = array(
    '#type' => 'fieldset',
    '#title' => t('Filter by'),
    '#collapsible' => TRUE,
    '#collapsed' => empty($filters),
  );
  $options = _support_client_terms($client, $state);
  if (count($options)) {

    // Filter by taxonomy.
    $form['filter']['tags'] = array(
      '#type' => 'fieldset',
      '#title' => t('Tags'),
      '#collapsible' => TRUE,
      '#collapsed' => empty($filters['tid']),
    );
    $form['filter']['tags']['tid'] = array(
      '#type' => 'select',
      '#multiple' => TRUE,
      '#options' => $options,
      '#size' => count($options) > 10 ? 10 : 5,
      '#default_value' => isset($filters['tid']) ? $filters['tid'] : 0,
    );
  }

  // No point in filtering by user if showing only self-assigned tickets.
  if ($state != -2) {
    $options = array(
      '-1' => '- not assigned -',
    );
    if ($users = _support_client_users($client)) {
      $options += $users;
    }
    unset($options[0]);
    if (count($options)) {

      // Filter by who's assigned.
      $form['filter']['assigned'] = array(
        '#type' => 'fieldset',
        '#title' => t('Assigned'),
        '#collapsible' => TRUE,
        '#collapsed' => empty($filters['uid']),
      );
      $form['filter']['assigned']['uid'] = array(
        '#type' => 'select',
        '#multiple' => TRUE,
        '#options' => $options,
        '#default_value' => isset($filters['uid']) ? $filters['uid'] : 0,
      );
    }
  }

  // No point in filtering by state if only showing tickets in a specific state.
  if ($state < 1) {

    // Filter by states.
    $form['filter']['state'] = array(
      '#type' => 'fieldset',
      '#title' => t('State'),
      '#collapsible' => TRUE,
      '#collapsed' => empty($filters['sid']),
    );
    $options = _support_states();
    $form['filter']['state']['sid'] = array(
      '#type' => 'select',
      '#multiple' => TRUE,
      '#options' => $options,
      '#default_value' => isset($filters['sid']) ? $filters['sid'] : 0,
    );
  }

  // Filter by priorities.
  $form['filter']['priority'] = array(
    '#type' => 'fieldset',
    '#title' => t('Priority'),
    '#collapsible' => TRUE,
    '#collapsed' => empty($filters['pid']),
  );
  $options = _support_priorities();
  $form['filter']['priority']['pid'] = array(
    '#type' => 'select',
    '#multiple' => TRUE,
    '#options' => $options,
    '#default_value' => isset($filters['pid']) ? $filters['pid'] : 0,
  );

  // Allow filtering by client if there's more than 1.
  if (count($client) > 1) {
    $form['filter']['client'] = array(
      '#type' => 'fieldset',
      '#title' => t('Client'),
      '#collapsible' => TRUE,
      '#collapsed' => empty($filters['clid']),
    );
    $options = _support_access_tickets(FALSE);
    $form['filter']['client']['clid'] = array(
      '#type' => 'select',
      '#multiple' => TRUE,
      '#options' => $options,
      '#default_value' => isset($filters['clid']) ? $filters['clid'] : 0,
    );
  }
  $form['filter']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
    '#validate' => array(
      'support_filter_form_validate',
    ),
    '#submit' => array(
      'support_filter_form_submit',
    ),
  );
  $form['filter']['markup'] = array(
    '#type' => 'markup',
    '#value' => l(t('Reset'), 'support'),
  );
  return $form;
}