/[drupal]/contributions/modules/single_login/single_login.module
ViewVC logotype

Diff of /contributions/modules/single_login/single_login.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2, Wed Oct 8 06:21:34 2008 UTC revision 1.3, Wed Oct 8 06:47:32 2008 UTC
# Line 1  Line 1 
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.
# Line 66  function single_login_init() { Line 66  function single_login_init() {
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));
# Line 245  function single_login_history_form_uid_s Line 246  function single_login_history_form_uid_s
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    }    }
# Line 255  function single_login_history_form_uid_s Line 255  function single_login_history_form_uid_s
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    }    }
# Line 277  function single_login_history_form_list( Line 276  function single_login_history_form_list(
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  }  }
# Line 314  function single_login_user($op, &$edit, Line 313  function single_login_user($op, &$edit,
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));

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2