You are here

function session_limit_page in Session Limit 6

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. 7.2 session_limit.module \session_limit_page()

Display/Delete sessions..

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

File

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

Code

function session_limit_page() {
  global $user;
  if (variable_get('session_limit_auto_drop', 0)) {

    // Get the oldest sessions.
    $count = db_result(db_query("SELECT COUNT(sid) FROM {sessions} WHERE uid = %d", $user->uid));
    $max_sessions = $count - session_limit_user_max_sessions($user);
    $result = db_query_range("SELECT sid FROM {sessions} WHERE uid = %d ORDER BY timestamp", $user->uid, 0, $max_sessions);
    while ($sids = db_fetch_object($result)) {
      session_limit_invoke_session_limit($sids->sid, 'disconnect');
    }
    drupal_goto();
  }
  $result = db_query('SELECT * FROM {sessions} WHERE uid = %d', $user->uid);
  while ($obj = db_fetch_object($result)) {
    $message = $user->sid == $obj->sid ? t('Your current session.') : '';
    $sids[$obj->sid] = t('<strong>Host:</strong> %host (idle: %time) <b>@message</b>', array(
      '%host' => $obj->hostname,
      '@message' => $message,
      '%time' => format_interval(time() - $obj->timestamp),
    ));
  }
  $form['sid'] = array(
    '#type' => 'radios',
    '#title' => t('Select a session to disconnect.'),
    '#options' => $sids,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Disconnect session'),
  );
  return $form;
}