You are here

function search_log_report_form in Search Log 7

Same name and namespace in other branches
  1. 6 search_log.admin.inc \search_log_report_form()

Report filter form.

1 string reference to 'search_log_report_form'
search_log_report in ./search_log.admin.inc
Display search log report.

File

./search_log.admin.inc, line 279
Admin page callbacks file for the search_log module.

Code

function search_log_report_form($form, &$form_state, $date = array(), $filter = array()) {
  $form = array();

  // Search period
  $today = date('Y-m-d', _search_log_get_time());
  $form['period'] = array(
    '#type' => 'fieldset',
    '#title' => t('Period'),
  );
  $links[] = array(
    'title' => t('Today'),
    'href' => 'admin/reports/search/today',
  );
  $links[] = array(
    'title' => t('This week'),
    'href' => 'admin/reports/search/week',
  );
  $links[] = array(
    'title' => t('This month'),
    'href' => 'admin/reports/search/month',
  );
  $links[] = array(
    'title' => t('This year'),
    'href' => 'admin/reports/search/year',
  );
  $form['period']['links']['#markup'] = theme('links', array(
    'links' => $links,
    'attributes' => array(
      'class' => 'search-log-links',
    ),
  ));
  $form['period']['from_date'] = array(
    '#type' => 'textfield',
    '#title' => t('From'),
    '#default_value' => $date['from'] ? $date['from'] : $today,
  );
  $form['period']['to_date'] = array(
    '#type' => 'textfield',
    '#title' => t('To'),
    '#default_value' => $date['to'] ? $date['to'] : $today,
    '#description' => t('Enter custom period for search reporting.'),
  );

  // Search result.
  if (db_query_range('SELECT qid FROM {search_log} WHERE result = :result', 0, 1, array(
    ':result' => SEARCH_LOG_RESULT_FAILED,
  ))
    ->fetchField()) {
    $result_options = array(
      SEARCH_LOG_RESULT_UNKNOWN => t('All'),
      SEARCH_LOG_RESULT_SUCCESS => t('Success'),
      SEARCH_LOG_RESULT_FAILED => t('Failed'),
    );
    $form['result'] = array(
      '#type' => 'fieldset',
      '#title' => t('Result'),
    );
    $form['result']['result'] = array(
      '#type' => 'radios',
      '#description' => t('Select result to include in search reporting.'),
      '#options' => $result_options,
      '#default_value' => $filter['result'] ? $filter['result'] : SEARCH_LOG_RESULT_UNKNOWN,
      '#required' => TRUE,
    );
  }

  // Search modules.
  $module_options = array();
  $query = db_query('SELECT DISTINCT module FROM {search_log}');
  while ($row = $query
    ->fetchObject()) {
    $module_options[$row->module] = $row->module;
  }
  if (count($module_options) > 1) {
    $module_default = !empty($filter['modules']) ? $filter['modules'] : array_keys($module_options);
    $form['modules'] = array(
      '#type' => 'fieldset',
      '#title' => t('Modules'),
    );
    $form['modules']['modules'] = array(
      '#type' => 'checkboxes',
      '#description' => t('Select modules to include in search reporting.'),
      '#options' => $module_options,
      '#default_value' => $module_default,
    );
  }

  // Search languages.
  $language_options = array();
  $query = db_query('SELECT DISTINCT language FROM {search_log}');
  while ($row = $query
    ->fetchObject()) {
    $language_options[$row->language] = $row->language;
  }
  if (count($language_options) > 1) {
    $language_default = !empty($filter['languages']) ? $filter['languages'] : array_keys($language_options);
    $form['languages'] = array(
      '#type' => 'fieldset',
      '#title' => t('Languages'),
    );
    $form['languages']['languages'] = array(
      '#type' => 'checkboxes',
      '#description' => t('Select languages to include in search reporting.'),
      '#options' => $language_options,
      '#default_value' => $language_default,
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update Report'),
  );
  $form['#action'] = url('admin/reports/search');
  return $form;
}