| 1 |
<?php |
<?php |
| 2 |
// $Id: single_login.module,v 1.1.2.3 2008/10/07 22:10:21 sanduhrs Exp $ |
// $Id: single_login.module,v 1.2 2008/10/08 06:21:34 sanduhrs Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Single Login is a session management system for Drupal. |
* Single Login is a session management system for Drupal. |
| 66 |
ip = '%4\$s', browser = '%5\$s', type = 'cookie' |
ip = '%4\$s', browser = '%5\$s', type = 'cookie' |
| 67 |
ON DUPLICATE KEY UPDATE |
ON DUPLICATE KEY UPDATE |
| 68 |
date = %3\$d"; |
date = %3\$d"; |
| 69 |
$sql = sprintf($sql, $user->uid, session_id(), $time, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT']); |
$sql = sprintf($sql, $user->uid, session_id(), $time, ip_address(), $_SERVER['HTTP_USER_AGENT']); |
| 70 |
db_query($sql); |
db_query($sql); |
| 71 |
|
|
| 72 |
$sql = "SELECT * FROM {sessions} WHERE uid = %d AND %d - timestamp < %d"; |
$sql = "SELECT COUNT(*) as count FROM {sessions} WHERE uid = %d AND %d - timestamp < %d"; |
| 73 |
$sql = sprintf($sql, $user->uid, $time, variable_get(SINGLE_LOGIN_TREAT_ONLINE, SINGLE_LOGIN_DEF_TREAT_ONLINE)); |
$sql = sprintf($sql, $user->uid, $time, variable_get(SINGLE_LOGIN_TREAT_ONLINE, SINGLE_LOGIN_DEF_TREAT_ONLINE)); |
| 74 |
if (db_num_rows(db_query($sql)) > 1) { |
$sessions = db_result(db_query($sql)); |
| 75 |
|
if ($sessions > 1) { |
| 76 |
// if the current user is not the only logged with this account |
// if the current user is not the only logged with this account |
| 77 |
$sql = "INSERT INTO {single_login} (uid, counter) VALUES (%d, %d) ON DUPLICATE KEY UPDATE counter = counter + 1"; |
$sql = "INSERT INTO {single_login} (uid, counter) VALUES (%d, %d) ON DUPLICATE KEY UPDATE counter = counter + 1"; |
| 78 |
db_query(sprintf($sql, $user->uid, 1)); |
db_query(sprintf($sql, $user->uid, 1)); |
| 246 |
$id = 0; |
$id = 0; |
| 247 |
|
|
| 248 |
$res = db_query("SELECT * FROM {users} WHERE name = '%s'", $name); |
$res = db_query("SELECT * FROM {users} WHERE name = '%s'", $name); |
| 249 |
if (db_num_rows($res)) { |
if ($row = db_fetch_object($res)) { |
|
$row = db_fetch_object($res); |
|
| 250 |
$id = $row->uid; |
$id = $row->uid; |
| 251 |
} |
} |
| 252 |
} |
} |
| 255 |
$name = ''; |
$name = ''; |
| 256 |
|
|
| 257 |
$res = db_query("SELECT * FROM {users} WHERE uid = %d", $id); |
$res = db_query("SELECT * FROM {users} WHERE uid = %d", $id); |
| 258 |
if (db_num_rows($res)) { |
if ($row = db_fetch_object($res)) { |
|
$row = db_fetch_object($res); |
|
| 259 |
$name = $row->name; |
$name = $row->name; |
| 260 |
} |
} |
| 261 |
} |
} |
| 276 |
'#title' => t('Result'), |
'#title' => t('Result'), |
| 277 |
); |
); |
| 278 |
|
|
| 279 |
if (!db_num_rows($result)) { |
$rows = array(); |
| 280 |
$form['head']['#description'] = t('History for this user is empty'); |
while ($row = db_fetch_object($result)) { |
| 281 |
|
$rows[] = array($row->history_id, date("d.m.Y G:i", $row->date), $row->ip, $row->browser); |
| 282 |
} |
} |
| 283 |
else { |
if (count($rows)) { |
|
$rows = array(); |
|
|
while ($row = db_fetch_object($result)) { |
|
|
$rows[] = array($row->history_id, date("d.m.Y G:i", $row->date), $row->ip, $row->browser); |
|
|
} |
|
| 284 |
$form['body'] = array( |
$form['body'] = array( |
| 285 |
'#prefix' => '<div>', |
'#prefix' => '<div>', |
| 286 |
'#value' => theme('table', array(t('ID'), t('Date'), t('IP'), t('Browser')), $rows), |
'#value' => theme('table', array(t('ID'), t('Date'), t('IP'), t('Browser')), $rows), |
| 287 |
'#suffix' => '</div>', |
'#suffix' => '</div>', |
| 288 |
); |
); |
| 289 |
} |
} |
| 290 |
|
else { |
| 291 |
|
$form['head']['#description'] = t('History for this user is empty'); |
| 292 |
|
} |
| 293 |
|
|
| 294 |
return $form; |
return $form; |
| 295 |
} |
} |
| 313 |
$sql = sprintf($sql, $account->uid, session_id(), $time, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT']); |
$sql = sprintf($sql, $account->uid, session_id(), $time, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT']); |
| 314 |
db_query($sql); |
db_query($sql); |
| 315 |
|
|
| 316 |
$sql = "SELECT * FROM {sessions} WHERE uid = %d AND %d - timestamp < %d"; |
$sql = "SELECT COUNT(*) as count FROM {sessions} WHERE uid = %d AND %d - timestamp < %d"; |
| 317 |
$sql = sprintf($sql, $account->uid, $time, variable_get(SINGLE_LOGIN_TREAT_ONLINE, SINGLE_LOGIN_DEF_TREAT_ONLINE)); |
$sql = sprintf($sql, $account->uid, $time, variable_get(SINGLE_LOGIN_TREAT_ONLINE, SINGLE_LOGIN_DEF_TREAT_ONLINE)); |
| 318 |
if (db_num_rows(db_query($sql)) > 0) { |
$sessions = db_result(db_query($sql)); |
| 319 |
|
if ($sessions > 0) { |
| 320 |
// if the current user is not the only logged with this account |
// if the current user is not the only logged with this account |
| 321 |
$sql = "INSERT INTO {single_login} (uid, counter) VALUES (%d, %d) ON DUPLICATE KEY UPDATE counter = counter + 1"; |
$sql = "INSERT INTO {single_login} (uid, counter) VALUES (%d, %d) ON DUPLICATE KEY UPDATE counter = counter + 1"; |
| 322 |
db_query(sprintf($sql, $account->uid, 1)); |
db_query(sprintf($sql, $account->uid, 1)); |