You are here

function login_history_output in Login History 6

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

Render login histories.

@todo Add XML output format.

Parameters

$history: A list of login history objects to output.

$format: (optional) The format to output log entries in; one of 'table', 'list' or 'text'.

$header: (optional) An array containing header data for $format 'table'.

1 call to login_history_output()
login_history_report_callback in includes/login_history.pages.inc

File

includes/login_history.pages.inc, line 49

Code

function login_history_output(array $history, $format = 'table', array $header = array()) {
  switch ($format) {
    case 'text':

      // Output delimiter in first line, since this may change.
      $output = '\\t' . "\n";
      foreach ($history as $entry) {
        $one_time = empty($entry->one_time) ? t('Regular login') : t('One-time login');
        $row = array(
          format_date($entry->login, 'small'),
          check_plain($entry->name),
          check_plain($entry->hostname),
          empty($entry->one_time) ? t('Regular login') : t('One-time login'),
          check_plain($entry->user_agent),
        );
        $output .= implode("\t", $row) . "\n";
      }
      break;
    case 'list':
      $output = '';
      foreach ($history as $entry) {
        $one_time = empty($entry->one_time) ? t('Regular login') : t('One-time login');
        $output .= '<li>';
        $output .= '<span class="login-history-info">' . check_plain($entry->name) . ' ' . format_date($entry->login, 'small') . ' ' . check_plain($entry->hostname) . ' ' . $one_time . ' ' . check_plain($entry->user_agent) . '</span>';
        $output .= '</li>';
      }
      if ($output) {
        $output = '<ul id="login-history-backlog">' . $output . '</ul>';
      }
      break;
    case 'table':
    default:
      $rows = array();
      foreach ($history as $entry) {
        $rows[] = array(
          format_date($entry->login, 'small'),
          check_plain($entry->name),
          check_plain($entry->hostname),
          empty($entry->one_time) ? t('Regular login') : t('One-time login'),
          check_plain($entry->user_agent),
        );
      }
      if (!empty($rows)) {
        $output = theme('table', $header, $rows);
        $output .= theme('pager');
      }
      else {
        $output = t('No login history available.');
      }
      break;
  }
  return $output;
}