/[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.3, Wed Oct 8 06:47:32 2008 UTC revision 1.3.2.1, Wed Apr 1 15:32:35 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: single_login.module,v 1.2 2008/10/08 06:21:34 sanduhrs Exp $  // $Id: single_login.module,v 1.1.2.3 2008/10/07 22:10:21 sanduhrs Exp $
3    
4  /**  /**
5   * Single Login is a session management system for Drupal.   * Single Login is a session management system for Drupal.
# Line 41  define('SINGLE_LOGIN_HISTORY_UID', 'sing Line 41  define('SINGLE_LOGIN_HISTORY_UID', 'sing
41  define('SINGLE_LOGIN_HISTORY_UNAME', 'single_login_history_uname__');  define('SINGLE_LOGIN_HISTORY_UNAME', 'single_login_history_uname__');
42    
43  /**  /**
44   * Implementation of hook_enable().   * Implentation of hook_init().
  */  
 function single_login_enable() {  
   $exists = db_result(db_query("SELECT fid FROM {profile_fields} WHERE name='profile_current_session_id'"));  
   if (!$exists) {  
     // needed for google analytics  
     db_query("INSERT INTO {profile_fields} (title, name, explanation, category, page, type, weight, required, register, visibility, autocomplete, options) VALUES ('Current Session ID', 'profile_current_session_id', 'User session ID', 'User Information', '', 'textfield', 0, 0, 0, 4, 0, '')");  
   }  
 }  
   
 /**  
  * Implementation of hook_init().  
45   */   */
46  function single_login_init() {  function single_login_init() {
47    global $user;    global $user;
# Line 61  function single_login_init() { Line 50  function single_login_init() {
50      $time = time();      $time = time();
51    
52      if (_single_login_is_user_single(array_keys($user->roles))) {      if (_single_login_is_user_single(array_keys($user->roles))) {
53        $sql = "INSERT INTO {single_login_history} SET        $sql = "INSERT INTO {single_login_history}
54              uid = %1\$d, session_id = '%2\$s', date = %3\$d,                  SET uid = %d, session_id = '%s', date = %d, ip = '%s', browser = '%s', type = 'cookie'
55              ip = '%4\$s', browser = '%5\$s', type = 'cookie'                  ON DUPLICATE KEY UPDATE date = %d";
56            ON DUPLICATE KEY UPDATE        db_query($sql, $user->uid, session_id(), $time, ip_address(), $_SERVER['HTTP_USER_AGENT'], $time);
57              date = %3\$d";  
58        $sql = sprintf($sql, $user->uid, session_id(), $time, ip_address(), $_SERVER['HTTP_USER_AGENT']);        $sql = "SELECT * FROM {sessions} WHERE uid = %d AND %d - timestamp < %d";
59        db_query($sql);        $result = db_query($sql, $user->uid, $time, variable_get(SINGLE_LOGIN_TREAT_ONLINE, SINGLE_LOGIN_DEF_TREAT_ONLINE));
60    
61        $sql = "SELECT COUNT(*) as count FROM {sessions} WHERE uid = %d AND %d - timestamp < %d";        if (db_fetch_object($result)) {
       $sql = sprintf($sql, $user->uid, $time, variable_get(SINGLE_LOGIN_TREAT_ONLINE, SINGLE_LOGIN_DEF_TREAT_ONLINE));  
       $sessions = db_result(db_query($sql));  
       if ($sessions > 1) {  
62          // if the current user is not the only logged with this account          // if the current user is not the only logged with this account
63          $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";
64          db_query(sprintf($sql, $user->uid, 1));          db_query(sprintf($sql, $user->uid, 1));
65          $sql = "DELETE FROM {sessions} WHERE uid = %d AND sid <> '%s'";  
66            $sql = "DELETE FROM {sessions} WHERE uid = %d AND sid != '%s'";
67          db_query(sprintf($sql, $user->uid, session_id()));          db_query(sprintf($sql, $user->uid, session_id()));
68        }        }
69        else {        else {
# Line 90  function single_login_init() { Line 77  function single_login_init() {
77  }  }
78    
79  /**  /**
80   * Implementation of hook_menu().   * Implementation of hook_menu()
81     *
82     * @return array of menu items
83   */   */
84  function single_login_menu($may_cache) {  function single_login_menu() {
85    $items = array();    $items = array();
86    if ($may_cache) {    $items['admin/settings/single_login'] = array(
87      $items[] = array(      'title' => t('Single login settings'),
88        'path' => 'admin/settings/single_login',      'description' => 'Configure the settings for single login.',
89        'title' => t('Single login settings'),      'page callback' => 'drupal_get_form',
90        'callback' => 'drupal_get_form',      'page arguments' => array('single_login_settings'),
91        'callback arguments' => 'single_login_settings',      'access arguments' => array('administer site configuration'),
92        'access' => user_access('administer site configuration'),      'type' => MENU_NORMAL_ITEM,
93        'type' => MENU_NORMAL_ITEM,    );
94      );    $items['admin/settings/single_login_history'] = array(
95      $items[] = array(      'title' => t('Single login session history'),
96        'path' => 'admin/settings/single_login_history',      'description' => 'Browse single login session history.',
97        'title' => t('Single login session history'),      'page callback' => 'single_login_history',
98        'callback' => 'single_login_history',      'access arguments' => array('administer site configuration'),
99        'access' => user_access('administer site configuration'),      'type' => MENU_NORMAL_ITEM,
100        'type' => MENU_NORMAL_ITEM,    );
101      );    $items['single_login/blocked'] = array(
102      $items[] = array(      'title' => t('Account was blocked'),
103        'path' => 'single_login/blocked',      'page callback' => 'single_login_static_page',
104        'title' => t('Account was blocked'),      'page arguments' => array('blocked'),
105        'callback' => 'single_login_static_page',      'access callback' => TRUE,
106        'callback arguments' => 'blocked',      'type' => MENU_CALLBACK,
107        'access' => TRUE,    );
       'type' => MENU_CALLBACK,  
     );  
   }  
108    
109    return $items;    return $items;
110  }  }
111    
112  /**  /**
113   * Administration settings page   * Admin settings
114     *
115   */   */
116  function single_login_settings() {  function single_login_settings() {
   $user_roles = array();  
   $res = db_query("SELECT * FROM {role} WHERE 1");  
   while ($row = db_fetch_object($res)) {  
     $user_roles[$row->rid] = $row->name;  
   }  
   
117    $form = array();    $form = array();
118    $form['sub_main'] = array(    $form['sub_main'] = array(
119      '#type' => 'fieldset',      '#type'          => 'fieldset',
120      '#title' => t('Main settings'),      '#title'         => t('Main settings'),
121      '#collapsible' => TRUE,      '#collapsible'   => true,
122      '#collapsed' => FALSE,      '#collapsed'     => false,
123    );    );
124    $form['sub_main'][SINGLE_LOGIN_CHECK_ROLES] = array(    $form['sub_main'][SINGLE_LOGIN_CHECK_ROLES] = array(
125      '#title' => t('Check login for roles'),      '#title'         => t('Check login for roles'),
126      '#type' => 'select',      '#type'      => 'select',
127      '#multiple' => TRUE,      '#multiple'    => true,
128      '#options' => $user_roles,      '#options'    => user_roles(),
129      '#default_value' => variable_get(SINGLE_LOGIN_CHECK_ROLES, array()),      '#default_value'=> variable_get(SINGLE_LOGIN_CHECK_ROLES, array()),
130      '#size' => 10,      '#size'      => 10,
131    );    );
132    $form['sub_main'][SINGLE_LOGIN_TREAT_ONLINE] = array(    $form['sub_main'][SINGLE_LOGIN_TREAT_ONLINE] = array(
133      '#type' => 'textfield',      '#type'          => 'textfield',
134      '#title' => t('Treat user online for seconds'),      '#title'         => t('Treat user online for seconds'),
135      '#default_value' => variable_get(SINGLE_LOGIN_TREAT_ONLINE, SINGLE_LOGIN_DEF_TREAT_ONLINE),      '#default_value' => variable_get(SINGLE_LOGIN_TREAT_ONLINE, SINGLE_LOGIN_DEF_TREAT_ONLINE),
136    );    );
137    $form['sub_main'][SINGLE_LOGIN_MAX_RECONNECTIONS] = array(    $form['sub_main'][SINGLE_LOGIN_MAX_RECONNECTIONS] = array(
138      '#type' => 'textfield',      '#type'          => 'textfield',
139      '#title' => t('Max login ping-pong values'),      '#title'         => t('Max login ping-pong values'),
140      '#default_value' => variable_get(SINGLE_LOGIN_MAX_RECONNECTIONS, SINGLE_LOGIN_DEF_MAX_RECONNECTIONS),      '#default_value' => variable_get(SINGLE_LOGIN_MAX_RECONNECTIONS, SINGLE_LOGIN_DEF_MAX_RECONNECTIONS),
141    );    );
142    $form['sub_main'][SINGLE_LOGIN_STORE_HISTORY] = array(    $form['sub_main'][SINGLE_LOGIN_STORE_HISTORY] = array(
143      '#type' => 'textfield',      '#type'          => 'textfield',
144      '#title' => t('Store sessions history for days (0 - infinite)'),      '#title'         => t('Store sessions history for days (0 - infinite)'),
145      '#default_value' => variable_get(SINGLE_LOGIN_STORE_HISTORY, SINGLE_LOGIN_DEF_STORE_HISTORY),      '#default_value' => variable_get(SINGLE_LOGIN_STORE_HISTORY, SINGLE_LOGIN_DEF_STORE_HISTORY),
146    );    );
147    $form['sub_msg'] = array(    $form['sub_msg'] = array(
148      '#type' => 'fieldset',      '#type'          => 'fieldset',
149      '#title' => t('Messages settings'),      '#title'         => t('Messages settings'),
150      '#collapsible' => TRUE,      '#collapsible'   => true,
151      '#collapsed' => FALSE,      '#collapsed'     => false,
152    );    );
153    $form['sub_msg'][SINGLE_LOGIN_MSG_RELOGGED] = array(    $form['sub_msg'][SINGLE_LOGIN_MSG_RELOGGED] = array(
154      '#type' => 'textfield',      '#type'          => 'textfield',
155      '#title' => t('Relogin message'),      '#title'         => t('Relogin message'),
156      '#maxlength' => 500,      '#maxlength'     => 500,
157      '#default_value' => variable_get(SINGLE_LOGIN_MSG_RELOGGED, SINGLE_LOGIN_DEF_RELOGGED),      '#default_value' => variable_get(SINGLE_LOGIN_MSG_RELOGGED, SINGLE_LOGIN_DEF_RELOGGED),
158    );    );
159    $form['sub_msg'][SINGLE_LOGIN_MSG_BLOCKED] = array(    $form['sub_msg'][SINGLE_LOGIN_MSG_BLOCKED] = array(
160      '#type' => 'textfield',      '#type'          => 'textfield',
161      '#title' => t('Account blocked message'),      '#title'         => t('Account blocked message'),
162      '#maxlength' => 500,      '#maxlength'     => 500,
163      '#default_value' => variable_get(SINGLE_LOGIN_MSG_BLOCKED, SINGLE_LOGIN_DEF_BLOCKED),      '#default_value' => variable_get(SINGLE_LOGIN_MSG_BLOCKED, SINGLE_LOGIN_DEF_BLOCKED),
164    );    );
165    if (module_exists('googleanalytics')) {    if (module_exists('googleanalytics')) {
166      $form['sub_google'] = array(      $form['sub_google'] = array(
167        '#type' => 'item',        '#type' => 'item',
168        '#title' => t('Google Analytics user sessionID tracking'),        '#title' => t('Google Analytics user sessionID tracking'),
169        '#description' => t('Goto !page and select \'Current Session ID\' in \'Track\' setting', array('!page' => l('Google Analytics setting', 'admin/settings/googleanalytics'))),        '#description' => t("Goto !page and select 'Current Session ID' in 'Track' setting", array('!page' => l(t('Google Analytics setting'), 'admin/settings/googleanalytics'))),
170      );      );
171    }    }
172    
173    return system_settings_form($form);    return system_settings_form($form);
174  }  }
175    
 /**  
  *  
  */  
176  function single_login_history() {  function single_login_history() {
177    $uid = variable_get(SINGLE_LOGIN_HISTORY_UID, 0);    $uid = variable_get(SINGLE_LOGIN_HISTORY_UID, 0);
178    $uname = variable_get(SINGLE_LOGIN_HISTORY_UNAME, '');    $uname = variable_get(SINGLE_LOGIN_HISTORY_UNAME, '');
179    
180    $out = '';    $output = '';
181    $out .= drupal_get_form('single_login_history_form_uid', $uid, $uname);    $output .= drupal_get_form('single_login_history_form_uid', array('uid' => $uid, 'uname' => $uname));
182    $out .= drupal_get_form('single_login_history_form_list', $uid);    $output .= drupal_get_form('single_login_history_form_list', $uid);
183    
184    return $out;    return $output;
185  }  }
186    
187  /**  function single_login_history_form_uid($edit = array()) {
  *  
  */  
 function single_login_history_form_uid($uid, $uname) {  
188    $form = array();    $form = array();
189    
190    $form['uid_fieldset'] = array(    $form['uid_fieldset'] = array(
191      '#type' => 'fieldset',      '#type'          => 'fieldset',
192      '#title' => t('User history preferences'),      '#title'         => t('User history preferences'),
193      '#collapsible' => TRUE,      '#collapsible'   => true,
194      '#collapsed' => FALSE,      '#collapsed'     => false,
195    );    );
196    $form['uid_fieldset']['history_for_uid'] = array(    $form['uid_fieldset']['history_for_uid'] = array(
197      '#type' => 'textfield',      '#type' => 'textfield',
198      '#title' => 'User ID',      '#title' => t('User ID'),
199      '#default_value' => $uid,      '#default_value' => $edit['uid'],
200    );    );
201    $form['uid_fieldset']['history_for_uname'] = array(    $form['uid_fieldset']['history_for_uname'] = array(
202      '#type' => 'textfield',      '#type' => 'textfield',
203      '#title' => 'User name',      '#title' => t('User name'),
204      '#default_value' => $uname,      '#default_value' => $edit['uname'],
205      '#description' => t('If name is set ID is selected automatically by name'),      '#description' => t('If name is set ID is selected automatically by name'),
206    );    );
207    $form['uid_fieldset']['submit_btn'] = array(    $form['uid_fieldset']['submit_btn'] = array(
208      '#type' => 'submit',      '#type' => 'submit',
209      '#value' => 'Show',      '#value' => t('Show'),
210    );    );
211    
212    return $form;    return $form;
213  }  }
214    
215  /**  function single_login_history_form_uid_submit($form, &$form_state) {
216   *    $values = $form_state['values'];
217   */  
218  function single_login_history_form_uid_submit($form_id, $form_values) {    if (strlen($values['history_for_uname']) && $values['history_for_uid'] == variable_get(SINGLE_LOGIN_HISTORY_UID, 0)) {
219    if (strlen($form_values['history_for_uname']) && $form_values['history_for_uid'] == variable_get(SINGLE_LOGIN_HISTORY_UID, 0)) {      $name = $values['history_for_uname'];
     $name = $form_values['history_for_uname'];  
220      $id = 0;      $id = 0;
221    
222      $res = db_query("SELECT * FROM {users} WHERE name = '%s'", $name);      $res = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", $name));
223      if ($row = db_fetch_object($res)) {      if ($res) {
224        $id = $row->uid;        $id = $res;
225      }      }
226    }    } else {
227    else {      $id = intval($values['history_for_uid']);
     $id = intval($form_values['history_for_uid']);  
228      $name = '';      $name = '';
229    
230      $res = db_query("SELECT * FROM {users} WHERE uid = %d", $id);      $res = db_result(db_query("SELECT name FROM {users} WHERE uid = %d", $id));
231      if ($row = db_fetch_object($res)) {      if ($res) {
232        $name = $row->name;        $name = $res;
233      }      }
234    }    }
235    
# Line 264  function single_login_history_form_uid_s Line 237  function single_login_history_form_uid_s
237    variable_set(SINGLE_LOGIN_HISTORY_UNAME, $name);    variable_set(SINGLE_LOGIN_HISTORY_UNAME, $name);
238  }  }
239    
 /**  
  *  
  */  
240  function single_login_history_form_list($uid) {  function single_login_history_form_list($uid) {
241    $result = db_query("SELECT * FROM {single_login_history} WHERE uid = %d", $uid);    $result = db_query("SELECT * FROM {single_login_history} WHERE uid = %d", $uid);
242    
# Line 276  function single_login_history_form_list( Line 246  function single_login_history_form_list(
246      '#title' => t('Result'),      '#title' => t('Result'),
247    );    );
248    
249    $rows = array();    if (!db_result($result)) {
250    while ($row = db_fetch_object($result)) {      $form['head']['#description'] = t('History for this user is empty');
251      $rows[] = array($row->history_id, date("d.m.Y G:i", $row->date), $row->ip, $row->browser);    } else {
252    }      $rows = array();
253    if (count($rows)) {      while ($row = db_fetch_object($result)) {
254          $rows[] = array($row->history_id, date("d.m.Y G:i", $row->date), $row->ip, $row->browser);
255        }
256      $form['body'] = array(      $form['body'] = array(
257        '#prefix' => '<div>',        '#prefix' => '<div>',
258        '#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),
259        '#suffix' => '</div>',        '#suffix' => '</div>',
260      );      );
261    }    }
   else {  
     $form['head']['#description'] = t('History for this user is empty');  
   }  
262    
263    return $form;    return $form;
264  }  }
265    
266  /**  /**
267   * Implementation of hook_user()   * Implementation of hook_user()
268     *
269     * @param string $op
270     * @param array $edit
271     * @param object $account
272     * @param string $category
273   */   */
274  function single_login_user($op, &$edit, &$account, $category = NULL) {  function single_login_user($op, &$edit, &$account, $category = NULL) {
275    global $user;    global $user;
# Line 305  function single_login_user($op, &$edit, Line 279  function single_login_user($op, &$edit,
279        if (_single_login_is_user_single(array_keys($user->roles))) {        if (_single_login_is_user_single(array_keys($user->roles))) {
280          $time = time();          $time = time();
281    
282          $sql = "INSERT INTO {single_login_history} SET          $sql = "INSERT INTO {single_login_history}
283                uid = %1\$d, session_id = '%2\$s', date = %3\$d,                    SET uid = %d, session_id = '%s', date = %d, ip = '%s', browser = '%s'
284                ip = '%4\$s', browser = '5\$%s'                  ON DUPLICATE KEY UPDATE date = %d, type = 'login'";
285              ON DUPLICATE KEY UPDATE          db_query($sql, $account->uid, session_id(), $time, ip_address(), $_SERVER['HTTP_USER_AGENT'], $time);
286                date = %3\$d, type = 'login'";  
287          $sql = sprintf($sql, $account->uid, session_id(), $time, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT']);          $sql = "SELECT * FROM {sessions} WHERE uid = %d AND %d - timestamp < %d";
288          db_query($sql);          $result = db_query($sql, $account->uid, $time, variable_get(SINGLE_LOGIN_TREAT_ONLINE, SINGLE_LOGIN_DEF_TREAT_ONLINE));
289            if (db_result($result)) {
         $sql = "SELECT COUNT(*) as count FROM {sessions} WHERE uid = %d AND %d - timestamp < %d";  
         $sql = sprintf($sql, $account->uid, $time, variable_get(SINGLE_LOGIN_TREAT_ONLINE, SINGLE_LOGIN_DEF_TREAT_ONLINE));  
         $sessions = db_result(db_query($sql));  
         if ($sessions > 0) {  
290            // if the current user is not the only logged with this account            // if the current user is not the only logged with this account
291            $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";
292            db_query(sprintf($sql, $account->uid, 1));            db_query($sql, $account->uid, 1);
293            $sql = "DELETE FROM {sessions} WHERE uid = %d AND sid <> '%s'";  
294            db_query(sprintf($sql, $account->uid, session_id()));            $sql = "DELETE FROM {sessions} WHERE uid = %d AND sid != '%s'";
295              db_query($sql, $account->uid, session_id());
296          }          }
297          else {          else {
298            // if current user is the only who logged in with current account            // if current user is the only who logged in with current account
299            db_query(sprintf("DELETE FROM {single_login} WHERE uid = %d", $account->uid));            $sql = "DELETE FROM {single_login} WHERE uid = %d";
300              db_query($sql, $account->uid);
301          }          }
302    
303          $res = db_query(sprintf("SELECT counter FROM {single_login} WHERE uid = %d", $account->uid));          $sql = "SELECT counter FROM {single_login} WHERE uid = %d";
304          $ping_pong_val = (($row = db_fetch_object($res)) === FALSE) ? 0 : $row->counter;          $res = db_query($sql, $account->uid);
305            $ping_pong_val = (($row = db_fetch_object($res)) === false) ? 0 : $row->counter;
306          if ($ping_pong_val >= variable_get(SINGLE_LOGIN_MAX_RECONNECTIONS, SINGLE_LOGIN_DEF_MAX_RECONNECTIONS)) {          if ($ping_pong_val >= variable_get(SINGLE_LOGIN_MAX_RECONNECTIONS, SINGLE_LOGIN_DEF_MAX_RECONNECTIONS)) {
307            db_query(sprintf("UPDATE {users} SET status = 0 WHERE uid = %d", $account->uid));            $sql = "UPDATE {users} SET status = 0 WHERE uid = %d";
308              db_query($sql, $account->uid);
309    
310            $_REQUEST['destination'] = 'single_login/blocked';            $_REQUEST['destination'] = 'single_login/blocked';
311    
312            user_logout();            user_logout();
313          }          }
314          elseif ($ping_pong_val) {          else if($ping_pong_val) {
315              //TODO: Clean that up and make it readable
316            $relogins_left = variable_get(SINGLE_LOGIN_MAX_RECONNECTIONS, SINGLE_LOGIN_DEF_MAX_RECONNECTIONS) - $ping_pong_val;            $relogins_left = variable_get(SINGLE_LOGIN_MAX_RECONNECTIONS, SINGLE_LOGIN_DEF_MAX_RECONNECTIONS) - $ping_pong_val;
317            drupal_set_message(variable_get(SINGLE_LOGIN_MSG_RELOGGED, SINGLE_LOGIN_DEF_RELOGGED) . $relogins_left);            drupal_set_message(variable_get(SINGLE_LOGIN_MSG_RELOGGED, SINGLE_LOGIN_DEF_RELOGGED) . $relogins_left);
318          }          }
# Line 349  function single_login_user($op, &$edit, Line 324  function single_login_user($op, &$edit,
324    }    }
325  }  }
326    
 /**  
  *  
  */  
327  function single_login_static_page($op) {  function single_login_static_page($op) {
328    switch ($op) {    switch ($op) {
329      case 'blocked':      case 'blocked':
# Line 369  function single_login_cron() { Line 341  function single_login_cron() {
341    if ($clear_older_than_days > 0) {    if ($clear_older_than_days > 0) {
342      $clear_older_than_secs = $clear_older_than_days * 24 * 60 * 60;      $clear_older_than_secs = $clear_older_than_days * 24 * 60 * 60;
343      $sql = "DELETE FROM {single_login_history} WHERE %d - date > %d";      $sql = "DELETE FROM {single_login_history} WHERE %d - date > %d";
344      $sql = sprintf($sql, time(), $clear_older_than_secs);      db_query($sql, time(), $clear_older_than_secs);
     db_query($sql);  
345    }    }
346  }  }
347    
348  /**  function _single_login_is_user_single($user_roles) {
  *  
  */  
 function _single_login_is_user_single(array $user_roles) {  
349    $roles_single_login = variable_get(SINGLE_LOGIN_CHECK_ROLES, array());    $roles_single_login = variable_get(SINGLE_LOGIN_CHECK_ROLES, array());
350    
351    foreach ($user_roles as $role_id) {    foreach ($user_roles as $role_id) {
352      if (in_array($role_id, $roles_single_login)) {      if (in_array($role_id, $roles_single_login)) return true;
       return TRUE;  
     }  
353    }    }
354    
355    return FALSE;    return false;
356  }  }
357    
 /**  
  *  
  */  
358  function _single_login_get_session_id_fid() {  function _single_login_get_session_id_fid() {
359    $res = db_query('SELECT fid FROM {profile_fields} WHERE name = \'profile_current_session_id\'');    $sql = "SELECT fid FROM {profile_fields} WHERE name = 'profile_current_session_id'";
360      $res = db_query($sql);
361    $row = db_fetch_object($res);    $row = db_fetch_object($res);
362    return $row->fid;    return $row->fid;
363  }  }
364    
 /**  
  *  
  */  
365  function _single_login_update_sess_field($uid) {  function _single_login_update_sess_field($uid) {
366    $fid = _single_login_get_session_id_fid();    $fid = _single_login_get_session_id_fid();
367    db_query("DELETE FROM {profile_values} WHERE uid = %d AND fid = %d", $uid, $fid);    $sql = "DELETE FROM {profile_values} WHERE uid = %d AND fid = %d";
368    $sql = "INSERT INTO    db_query($sql, $uid, $fid);
369          {profile_values}    $sql = "INSERT INTO {profile_values}
370        SET              SET fid = %d, uid = %d, value = '%s'";
371          fid = %d,    db_query($sql, $fid, $uid, session_id());
         uid = %d,  
         value = '%s'";  
   db_query(sprintf($sql, $fid, $uid, session_id()));  
372  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.2