You are here

function autologout_user in Automated Logout 5

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

Implementation of hook_user()

File

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

Code

function autologout_user($op, &$edit, &$account, $category = NULL) {
  _autologout_debug("autologout_user({$op})");
  if ($account->uid < 2) {
    return;

    // UID 0 or UID 1 not appliciable
  }
  if (!$category) {
    $category = "account";
  }
  switch ($op) {
    case 'login':
      $_SESSION['lastaccess'] = time();
      break;
    case 'load':
      if (_autologout_user_in_by_user_role($account)) {
        $account->autologout = 0;
        $r = db_query("SELECT setting FROM {autologout} WHERE uid = %d", $account->uid);
        if (db_num_rows($r) > 0) {
          $row = db_fetch_object($r);
          $account->autologout = (int) $row->setting;
        }
      }
      break;
    case 'form':
      if (_autologout_user_in_by_user_role($account) && 'account' == $category) {
        $form = array();
        $form[$category]['autologout'] = array(
          '#type' => 'checkbox',
          '#title' => t('Disable inactivity Automated Logout'),
          '#default_value' => $account->autologout,
          '#weight' => 10,
        );
        return $form;
      }
      break;
    case 'update':
      $_SESSION['lastaccess'] = time();
      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']);
          unset($edit['autologout']);
        }
      }
      break;
    case 'delete':
      db_query("DELETE FROM {autologout} WHERE uid = %d", $account->uid);
      break;
  }
  return;
}