You are here

function login_history_report_callback in Login History 7

Same name and namespace in other branches
  1. 6 includes/login_history.pages.inc \login_history_report_callback()

Page callback for the login history page.

Parameters

object $account: Optional user object.

Return value

string A string of html to be printed.

1 string reference to 'login_history_report_callback'
login_history_menu in ./login_history.module
Implements hook_menu().

File

includes/login_history.pages.inc, line 17
The login history page-related code.

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'),
    ),
  );
  $query = db_select('login_history', 'lh')
    ->extend('TableSort')
    ->extend('PagerDefault');
  $query
    ->join('users', 'u', 'lh.uid = u.uid');
  if ($account) {
    $query
      ->condition('lh.uid', $account->uid);
  }
  $result = $query
    ->fields('lh')
    ->fields('u', array(
    'name',
  ))
    ->orderByHeader($header)
    ->limit(50)
    ->execute()
    ->fetchAll();
  return login_history_output($result, 'table', $header);
}