You are here

function session_limit_page in Session Limit 7.2

Same name and namespace in other branches
  1. 5 session_limit.module \session_limit_page()
  2. 6.2 session_limit.module \session_limit_page()
  3. 6 session_limit.module \session_limit_page()

Display or delete sessions form.

1 string reference to 'session_limit_page'
session_limit_menu in ./session_limit.module
Implements hook_menu().

File

./session_limit.module, line 425
Limits multiple sessions per user.

Code

function session_limit_page() {
  global $user;
  $form = array();
  if (variable_get('session_limit_behaviour', SESSION_LIMIT_DO_NOTHING) == SESSION_LIMIT_DISALLOW_NEW) {
    session_destroy();
    $user = drupal_anonymous_user();
    return;
  }
  $result = db_query('SELECT * FROM {sessions} WHERE uid = :uid', array(
    ':uid' => $user->uid,
  ));
  $active_sessions = array();
  $session_references = array();
  foreach ($result as $session_reference => $obj) {
    $active_sessions[$session_reference] = $obj->sid;
    $message = $user->sid == $obj->sid ? t('Your current session.') : '';
    $session_references[$session_reference] = t('<strong>Host:</strong> %host (idle: %time) <b>@message</b>', array(
      '%host' => $obj->hostname,
      '@message' => $message,
      '%time' => format_interval(time() - $obj->timestamp),
    ));
  }
  $form['active_sessions'] = array(
    '#type' => 'value',
    '#value' => $active_sessions,
  );
  $form['session_reference'] = array(
    '#type' => 'radios',
    '#title' => t('Select a session to disconnect.'),
    '#options' => $session_references,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Disconnect session'),
  );
  return $form;
}