You are here

function login_history_report_callback in Login History 6

Same name and namespace in other branches
  1. 7 includes/login_history.pages.inc \login_history_report_callback()
1 string reference to 'login_history_report_callback'
login_history_menu in ./login_history.module
Implements hook_menu(). Define menu items and page callbacks.

File

includes/login_history.pages.inc, line 3

Code

function login_history_report_callback($account = NULL) {
  if (empty($account->uid) && !user_access('view all login histories')) {

    // This should never happen, but be cautious in case calling code is weak.
    global $user;
    $account = $user;
  }
  $header = array(
    array(
      'data' => t('Date'),
      'field' => 'lh.login',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Username'),
      'field' => 'u.name',
    ),
    array(
      'data' => t('IP Address'),
      'field' => 'lh.hostname',
    ),
    array(
      'data' => t('One-time login?'),
      'field' => 'lh.one_time',
    ),
    array(
      'data' => t('User Agent'),
      'field' => 'lh.user_agent',
    ),
  );
  $sql = "SELECT lh.login, u.name, lh.hostname, lh.one_time, lh.user_agent FROM {login_history} lh INNER JOIN {users} u ON lh.uid = u.uid";

  // Add condition for individual user report.
  $uid = NULL;
  if ($account) {
    $sql .= " WHERE lh.uid = %d";
    $uid = $account->uid;
  }
  $query = pager_query($sql . tablesort_sql($header), 50, 0, NULL, $uid);
  $result = array();
  while ($row = db_fetch_object($query)) {
    $result[] = $row;
  }
  return login_history_output($result, 'table', $header);
}