You are here

function autologout_user in Automated Logout 6.2

Same name and namespace in other branches
  1. 5 autologout.module \autologout_user()
  2. 6 autologout.module \autologout_user()

Implementation of hook_user().

1 call to autologout_user()
autologout_init in ./autologout.module
Implementation of hook_init().

File

./autologout.module, line 237
Used to automagically log out a user after a preset time, AjK May 2006

Code

function autologout_user($op, $edit, &$account, $category = NULL) {

  // Do nothing for anonymous users.
  if ($account->uid == 0) {
    return;
  }
  if ($op == 'form' && $category == 'account') {
    if (_autologout_user_in_by_user_role($account)) {
      $form = array();
      $form[$category]['autologout'] = array(
        '#type' => 'checkbox',
        '#title' => t('Disable inactivity Automated Logout'),
        '#default_value' => $account->autologout,
        '#weight' => 10,
      );
      return $form;
    }
  }
  else {
    if ($op == 'login') {

      // one session checking
      $return = _autologout_check_one_session();
      if ($return) {
        _autologout_invalidate_other_sessions($account);
      }
      $_SESSION['lastaccess'] = time();
    }
    else {
      if ($op == 'load') {
        if (_autologout_user_in_by_user_role($account)) {
          $account->autologout = 0;
          $result = db_query("SELECT setting FROM {autologout} WHERE uid = %d", $account->uid);
          while ($row = db_fetch_object($result)) {
            $account->autologout = (int) $row->setting;
          }
        }
      }
      else {
        if ($op == 'update') {
          if (_autologout_user_in_by_user_role($account)) {
            if (isset($edit['autologout'])) {
              db_query("DELETE FROM {autologout} WHERE uid = %d", $account->uid);
              db_query("INSERT INTO {autologout} SET uid = %d, setting = %d", $account->uid, $edit['autologout']);

              // If they are turning off the disable setting, set lastaccess so they are not immediately logged out.
              if ($edit['autologout'] == 0) {
                $_SESSION['lastaccess'] = $nowtime;
              }
            }
          }
        }
        else {
          if ($op == 'delete') {
            db_query("DELETE FROM {autologout} WHERE uid = %d", $account->uid);
          }
        }
      }
    }
  }
  return;
}