? single_login_5to6.patch Index: single_login.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/single_login/single_login.info,v retrieving revision 1.1.2.2 diff -u -p -r1.1.2.2 single_login.info --- single_login.info 8 Oct 2008 06:15:56 -0000 1.1.2.2 +++ single_login.info 1 Apr 2009 13:58:09 -0000 @@ -1,5 +1,7 @@ -; $Id: single_login.info,v 1.1.2.2 2008/10/08 06:15:56 sanduhrs Exp $ +; $Id: + name = Single Login description = Allows users to be logged on only on a single browser in one time. package = "User" -dependencies = profile \ No newline at end of file +dependencies[] = profile +core = 6.x Index: single_login.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/single_login/single_login.install,v retrieving revision 1.1.2.3 diff -u -p -r1.1.2.3 single_login.install --- single_login.install 8 Oct 2008 06:19:43 -0000 1.1.2.3 +++ single_login.install 1 Apr 2009 13:59:29 -0000 @@ -1,5 +1,5 @@ fid); - db_query('DELETE FROM {profile_values} WHERE fid = %d', $row->fid); - } - } + drupal_uninstall_schema('single_login'); + + $fid = db_result(db_query('SELECT fid FROM {profile_fields} WHERE name = \'profile_current_session_id\'')); + if ($fid) { + db_query('DELETE FROM {profile_fields} WHERE fid = %d', $fid); + db_query('DELETE FROM {profile_values} WHERE fid = %d', $fid); + } +} + +function single_login_schema() { + $schema['single_login'] = array( + 'fields' => array( + 'single_login_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), + 'counter' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => 0), + ), + 'unique keys' => array( + 'uid' => array('uid') + ), + 'indexes' => array( + 'counter' => array('counter') + ), + 'primary key' => array('single_login_id'), + ); + + $schema['single_login_history'] = array( + 'fields' => array( + 'history_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => 10), + 'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => 10), + 'session_id' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE), + 'date' => array('type' => 'int', 'not null' => TRUE, 'disp-width' => 11), + 'ip' => array('type' => 'varchar', 'length' => 15, 'not null' => TRUE), + 'browser' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE), + 'type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'login'), + ), + 'unique keys' => array( + 'session_id' => array('session_id') + ), + 'indexes' => array( + 'uid' => array('uid') + ), + 'primary key' => array('history_id'), + ); + + return $schema; } +?> Index: single_login.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/single_login/single_login.module,v retrieving revision 1.1.2.3 diff -u -p -r1.1.2.3 single_login.module --- single_login.module 7 Oct 2008 22:10:21 -0000 1.1.2.3 +++ single_login.module 1 Apr 2009 14:00:43 -0000 @@ -1,5 +1,5 @@ uid)) { - $time = time(); + if (intval($user->uid)) { + $time = time(); - if (_single_login_is_user_single(array_keys($user->roles))) { - $sql = "INSERT INTO {single_login_history} SET - uid = %1\$d, session_id = '%2\$s', date = %3\$d, - ip = '%4\$s', browser = '%5\$s', type = 'cookie' - ON DUPLICATE KEY UPDATE - date = %3\$d"; - $sql = sprintf($sql, $user->uid, session_id(), $time, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT']); - db_query($sql); - - $sql = "SELECT * FROM {sessions} WHERE uid = %d AND %d - timestamp < %d"; - $sql = sprintf($sql, $user->uid, $time, variable_get(SINGLE_LOGIN_TREAT_ONLINE, SINGLE_LOGIN_DEF_TREAT_ONLINE)); - if (db_num_rows(db_query($sql)) > 1) { - // if the current user is not the only logged with this account - $sql = "INSERT INTO {single_login} (uid, counter) VALUES (%d, %d) ON DUPLICATE KEY UPDATE counter = counter + 1"; - db_query(sprintf($sql, $user->uid, 1)); - $sql = "DELETE FROM {sessions} WHERE uid = %d AND sid <> '%s'"; - db_query(sprintf($sql, $user->uid, session_id())); - } - else { - // if current user is the only who logged in with current account - db_query(sprintf("DELETE FROM {single_login} WHERE uid = %d", $account->uid)); - } - } - - _single_login_update_sess_field($user->uid); - } -} - -/** - * Implementation of hook_menu(). - */ -function single_login_menu($may_cache) { - $items = array(); - if ($may_cache) { - $items[] = array( - 'path' => 'admin/settings/single_login', - 'title' => t('Single login settings'), - 'callback' => 'drupal_get_form', - 'callback arguments' => 'single_login_settings', - 'access' => user_access('administer site configuration'), - 'type' => MENU_NORMAL_ITEM, - ); - $items[] = array( - 'path' => 'admin/settings/single_login_history', - 'title' => t('Single login session history'), - 'callback' => 'single_login_history', - 'access' => user_access('administer site configuration'), - 'type' => MENU_NORMAL_ITEM, - ); - $items[] = array( - 'path' => 'single_login/blocked', - 'title' => t('Account was blocked'), - 'callback' => 'single_login_static_page', - 'callback arguments' => 'blocked', - 'access' => TRUE, - 'type' => MENU_CALLBACK, - ); - } + if (_single_login_is_user_single(array_keys($user->roles))) { + $sql = "INSERT INTO {single_login_history} SET + uid = %1\$d, session_id = '%2\$s', date = %3\$d, + ip = '%4\$s', browser = '%5\$s', type = 'cookie' + ON DUPLICATE KEY UPDATE + date = %3\$d"; + $sql = sprintf($sql, $user->uid, session_id(), $time, ip_address(), $_SERVER['HTTP_USER_AGENT']); + db_query($sql); + + $sql = "SELECT * FROM {sessions} WHERE uid = %d AND %d - timestamp < %d"; + $sql = sprintf($sql, $user->uid, $time, variable_get(SINGLE_LOGIN_TREAT_ONLINE, SINGLE_LOGIN_DEF_TREAT_ONLINE)); + $result = db_query($sql); + db_fetch_object($result); + if (db_fetch_object($result)) { + // if the current user is not the only logged with this account + $sql = "INSERT INTO {single_login} (uid, counter) VALUES (%d, %d) ON DUPLICATE KEY UPDATE counter = counter + 1"; + db_query(sprintf($sql, $user->uid, 1)); + $sql = "DELETE FROM {sessions} WHERE uid = %d AND sid != '%s'"; + db_query(sprintf($sql, $user->uid, session_id())); + } else { + // if current user is the only who logged in with current account + db_query(sprintf("DELETE FROM {single_login} WHERE uid = %d", $account->uid)); + } + } + + _single_login_update_sess_field($user->uid); + } +} + +/** + * Implementation of hook_menu() + * + * @return array of menu items + */ +function single_login_menu() +{ + $items = array(); + $items['admin/settings/single_login'] = array( + 'title' => t('Single login settings'), + 'description' => 'Configure the settings for single login.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('single_login_settings'), + 'access arguments' => array('administer site configuration'), + 'type' => MENU_NORMAL_ITEM, + ); + $items['admin/settings/single_login_history'] = array( + 'title' => t('Single login session history'), + 'description' => 'Browse single login session history.', + 'page callback' => 'single_login_history', + 'access arguments' => array('administer site configuration'), + 'type' => MENU_NORMAL_ITEM, + ); + $items['single_login/blocked'] = array( + 'title' => t('Account was blocked'), + 'page callback' => 'single_login_static_page', + 'page arguments' => array('blocked'), + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); - return $items; + return $items; } /** - * Administration settings page + * Admin 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; - } - - $form = array(); - $form['sub_main'] = array( - '#type' => 'fieldset', - '#title' => t('Main settings'), - '#collapsible' => TRUE, - '#collapsed' => FALSE, - ); - $form['sub_main'][SINGLE_LOGIN_CHECK_ROLES] = array( - '#title' => t('Check login for roles'), - '#type' => 'select', - '#multiple' => TRUE, - '#options' => $user_roles, - '#default_value' => variable_get(SINGLE_LOGIN_CHECK_ROLES, array()), - '#size' => 10, - ); - $form['sub_main'][SINGLE_LOGIN_TREAT_ONLINE] = array( - '#type' => 'textfield', - '#title' => t('Treat user online for seconds'), - '#default_value' => variable_get(SINGLE_LOGIN_TREAT_ONLINE, SINGLE_LOGIN_DEF_TREAT_ONLINE), - ); - $form['sub_main'][SINGLE_LOGIN_MAX_RECONNECTIONS] = array( - '#type' => 'textfield', - '#title' => t('Max login ping-pong values'), - '#default_value' => variable_get(SINGLE_LOGIN_MAX_RECONNECTIONS, SINGLE_LOGIN_DEF_MAX_RECONNECTIONS), - ); - $form['sub_main'][SINGLE_LOGIN_STORE_HISTORY] = array( - '#type' => 'textfield', - '#title' => t('Store sessions history for days (0 - infinite)'), - '#default_value' => variable_get(SINGLE_LOGIN_STORE_HISTORY, SINGLE_LOGIN_DEF_STORE_HISTORY), - ); - $form['sub_msg'] = array( - '#type' => 'fieldset', - '#title' => t('Messages settings'), - '#collapsible' => TRUE, - '#collapsed' => FALSE, - ); - $form['sub_msg'][SINGLE_LOGIN_MSG_RELOGGED] = array( - '#type' => 'textfield', - '#title' => t('Relogin message'), - '#maxlength' => 500, - '#default_value' => variable_get(SINGLE_LOGIN_MSG_RELOGGED, SINGLE_LOGIN_DEF_RELOGGED), - ); - $form['sub_msg'][SINGLE_LOGIN_MSG_BLOCKED] = array( - '#type' => 'textfield', - '#title' => t('Account blocked message'), - '#maxlength' => 500, - '#default_value' => variable_get(SINGLE_LOGIN_MSG_BLOCKED, SINGLE_LOGIN_DEF_BLOCKED), - ); - if (module_exists('googleanalytics')) { - $form['sub_google'] = array( - '#type' => 'item', - '#title' => t('Google Analytics user sessionID tracking'), - '#description' => t('Goto !page and select \'Current Session ID\' in \'Track\' setting', array('!page' => l('Google Analytics setting', 'admin/settings/googleanalytics'))), - ); - } + $form = array(); + $form['sub_main'] = array( + '#type' => 'fieldset', + '#title' => t('Main settings'), + '#collapsible' => true, + '#collapsed' => false, + ); + $form['sub_main'][SINGLE_LOGIN_CHECK_ROLES] = array( + '#title' => t('Check login for roles'), + '#type' => 'select', + '#multiple' => true, + '#options' => user_roles(), + '#default_value'=> variable_get(SINGLE_LOGIN_CHECK_ROLES, array()), + '#size' => 10, + ); + $form['sub_main'][SINGLE_LOGIN_TREAT_ONLINE] = array( + '#type' => 'textfield', + '#title' => t('Treat user online for seconds'), + '#default_value' => variable_get(SINGLE_LOGIN_TREAT_ONLINE, SINGLE_LOGIN_DEF_TREAT_ONLINE), + ); + $form['sub_main'][SINGLE_LOGIN_MAX_RECONNECTIONS] = array( + '#type' => 'textfield', + '#title' => t('Max login ping-pong values'), + '#default_value' => variable_get(SINGLE_LOGIN_MAX_RECONNECTIONS, SINGLE_LOGIN_DEF_MAX_RECONNECTIONS), + ); + $form['sub_main'][SINGLE_LOGIN_STORE_HISTORY] = array( + '#type' => 'textfield', + '#title' => t('Store sessions history for days (0 - infinite)'), + '#default_value' => variable_get(SINGLE_LOGIN_STORE_HISTORY, SINGLE_LOGIN_DEF_STORE_HISTORY), + ); + $form['sub_msg'] = array( + '#type' => 'fieldset', + '#title' => t('Messages settings'), + '#collapsible' => true, + '#collapsed' => false, + ); + $form['sub_msg'][SINGLE_LOGIN_MSG_RELOGGED] = array( + '#type' => 'textfield', + '#title' => t('Relogin message'), + '#maxlength' => 500, + '#default_value' => variable_get(SINGLE_LOGIN_MSG_RELOGGED, SINGLE_LOGIN_DEF_RELOGGED), + ); + $form['sub_msg'][SINGLE_LOGIN_MSG_BLOCKED] = array( + '#type' => 'textfield', + '#title' => t('Account blocked message'), + '#maxlength' => 500, + '#default_value' => variable_get(SINGLE_LOGIN_MSG_BLOCKED, SINGLE_LOGIN_DEF_BLOCKED), + ); + if (module_exists('googleanalytics')) { + $form['sub_google'] = array( + '#type' => 'item', + '#title' => t('Google Analytics user sessionID tracking'), + '#description' => t('Goto ' . l('Google Analytics setting', 'admin/settings/googleanalytics') . ' and select \'Current Session ID\' in \'Track\' setting'), + ); + } - return system_settings_form($form); + return system_settings_form($form); } -/** - * - */ function single_login_history() { - $uid = variable_get(SINGLE_LOGIN_HISTORY_UID, 0); - $uname = variable_get(SINGLE_LOGIN_HISTORY_UNAME, ''); + $uid = variable_get(SINGLE_LOGIN_HISTORY_UID, 0); + $uname = variable_get(SINGLE_LOGIN_HISTORY_UNAME, ''); - $out = ''; - $out .= drupal_get_form('single_login_history_form_uid', $uid, $uname); - $out .= drupal_get_form('single_login_history_form_list', $uid); + $out = ''; + $out .= drupal_get_form('single_login_history_form_uid', array('uid' => $uid, 'uname' => $uname)); + $out .= drupal_get_form('single_login_history_form_list', $uid); + + return $out; +} + +function single_login_history_form_uid($edit = array()) { + $form = array(); + + $form['uid_fieldset'] = array( + '#type' => 'fieldset', + '#title' => t('User history preferences'), + '#collapsible' => true, + '#collapsed' => false, + ); + $form['uid_fieldset']['history_for_uid'] = array( + '#type' => 'textfield', + '#title' => t('User ID'), + '#default_value' => $edit['uid'], + ); + $form['uid_fieldset']['history_for_uname'] = array( + '#type' => 'textfield', + '#title' => t('User name'), + '#default_value' => $edit['uname'], + '#description' => t('If name is set ID is selected automatically by name'), + ); + $form['uid_fieldset']['submit_btn'] = array( + '#type' => 'submit', + '#value' => t('Show'), + ); + + return $form; +} + +function single_login_history_form_uid_submit($form, &$form_state) { + $values = $form_state['values']; + + if (strlen($values['history_for_uname']) && $values['history_for_uid'] == variable_get(SINGLE_LOGIN_HISTORY_UID, 0)) { + $name = $values['history_for_uname']; + $id = 0; + + $res = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", $name)); + if ($res) { + $id = $res; + } + } else { + $id = intval($values['history_for_uid']); + $name = ''; + + $res = db_result(db_query("SELECT name FROM {users} WHERE uid = %d", $id)); + if ($res) { + $name = $res; + } + } - return $out; + variable_set(SINGLE_LOGIN_HISTORY_UID, $id); + variable_set(SINGLE_LOGIN_HISTORY_UNAME, $name); } -/** - * - */ -function single_login_history_form_uid($uid, $uname) { - $form = array(); - - $form['uid_fieldset'] = array( - '#type' => 'fieldset', - '#title' => t('User history preferences'), - '#collapsible' => TRUE, - '#collapsed' => FALSE, - ); - $form['uid_fieldset']['history_for_uid'] = array( - '#type' => 'textfield', - '#title' => 'User ID', - '#default_value' => $uid, - ); - $form['uid_fieldset']['history_for_uname'] = array( - '#type' => 'textfield', - '#title' => 'User name', - '#default_value' => $uname, - '#description' => t('If name is set ID is selected automatically by name'), - ); - $form['uid_fieldset']['submit_btn'] = array( - '#type' => 'submit', - '#value' => 'Show', - ); - - return $form; -} - -/** - * - */ -function single_login_history_form_uid_submit($form_id, $form_values) { - if (strlen($form_values['history_for_uname']) && $form_values['history_for_uid'] == variable_get(SINGLE_LOGIN_HISTORY_UID, 0)) { - $name = $form_values['history_for_uname']; - $id = 0; - - $res = db_query("SELECT * FROM {users} WHERE name = '%s'", $name); - if (db_num_rows($res)) { - $row = db_fetch_object($res); - $id = $row->uid; - } - } - else { - $id = intval($form_values['history_for_uid']); - $name = ''; - - $res = db_query("SELECT * FROM {users} WHERE uid = %d", $id); - if (db_num_rows($res)) { - $row = db_fetch_object($res); - $name = $row->name; - } - } - - variable_set(SINGLE_LOGIN_HISTORY_UID, $id); - variable_set(SINGLE_LOGIN_HISTORY_UNAME, $name); -} - -/** - * - */ function single_login_history_form_list($uid) { - $result = db_query("SELECT * FROM {single_login_history} WHERE uid = %d", $uid); + $result = db_query("SELECT * FROM {single_login_history} WHERE uid = %d", $uid); - $form = array(); - $form['head'] = array( - '#type' => 'item', - '#title' => t('Result'), - ); - - if (!db_num_rows($result)) { - $form['head']['#description'] = t('History for this user is empty'); - } - else { - $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); - } - $form['body'] = array( - '#prefix' => '
', - '#value' => theme('table', array(t('ID'), t('Date'), t('IP'), t('Browser')), $rows), - '#suffix' => '
', - ); - } + $form = array(); + $form['head'] = array( + '#type' => 'item', + '#title' => t('Result'), + ); + + if (!db_result($result)) { + $form['head']['#description'] = t('History for this user is empty'); + } else { + $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); + } + $form['body'] = array( + '#prefix' => '
', + '#value' => theme('table', array(t('ID'), t('Date'), t('IP'), t('Browser')), $rows), + '#suffix' => '
', + ); + } - return $form; + return $form; } /** * Implementation of hook_user() + * + * @param string $op + * @param array $edit + * @param object $account + * @param string $category */ function single_login_user($op, &$edit, &$account, $category = NULL) { - global $user; + global $user; - switch ($op) { - case 'login': - if (_single_login_is_user_single(array_keys($user->roles))) { - $time = time(); - - $sql = "INSERT INTO {single_login_history} SET - uid = %1\$d, session_id = '%2\$s', date = %3\$d, - ip = '%4\$s', browser = '5\$%s' - ON DUPLICATE KEY UPDATE - date = %3\$d, type = 'login'"; - $sql = sprintf($sql, $account->uid, session_id(), $time, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT']); - db_query($sql); - - $sql = "SELECT * 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)); - if (db_num_rows(db_query($sql)) > 0) { - // if the current user is not the only logged with this account - $sql = "INSERT INTO {single_login} (uid, counter) VALUES (%d, %d) ON DUPLICATE KEY UPDATE counter = counter + 1"; - db_query(sprintf($sql, $account->uid, 1)); - $sql = "DELETE FROM {sessions} WHERE uid = %d AND sid <> '%s'"; - db_query(sprintf($sql, $account->uid, session_id())); - } - else { - // if current user is the only who logged in with current account - db_query(sprintf("DELETE FROM {single_login} WHERE uid = %d", $account->uid)); - } - - $res = db_query(sprintf("SELECT counter FROM {single_login} WHERE uid = %d", $account->uid)); - $ping_pong_val = (($row = db_fetch_object($res)) === FALSE) ? 0 : $row->counter; - if ($ping_pong_val >= variable_get(SINGLE_LOGIN_MAX_RECONNECTIONS, SINGLE_LOGIN_DEF_MAX_RECONNECTIONS)) { - db_query(sprintf("UPDATE {users} SET status = 0 WHERE uid = %d", $account->uid)); - - $_REQUEST['destination'] = 'single_login/blocked'; - - user_logout(); - } - elseif ($ping_pong_val) { - $relogins_left = variable_get(SINGLE_LOGIN_MAX_RECONNECTIONS, SINGLE_LOGIN_DEF_MAX_RECONNECTIONS) - $ping_pong_val; - drupal_set_message(variable_get(SINGLE_LOGIN_MSG_RELOGGED, SINGLE_LOGIN_DEF_RELOGGED) . $relogins_left); - } - } + switch ($op) { + case 'login': + if (_single_login_is_user_single(array_keys($user->roles))) { + $time = time(); + + $sql = "INSERT INTO {single_login_history} SET + uid = %1\$d, session_id = '%2\$s', date = %3\$d, + ip = '%4\$s', browser = '5\$%s' + ON DUPLICATE KEY UPDATE + date = %3\$d, type = 'login'"; + $sql = sprintf($sql, $account->uid, session_id(), $time, ip_address(), $_SERVER['HTTP_USER_AGENT']); + db_query($sql); + + $sql = "SELECT * 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)); + if (db_result(db_query($sql))) { + // if the current user is not the only logged with this account + $sql = "INSERT INTO {single_login} (uid, counter) VALUES (%d, %d) ON DUPLICATE KEY UPDATE counter = counter + 1"; + db_query(sprintf($sql, $account->uid, 1)); + $sql = "DELETE FROM {sessions} WHERE uid = %d AND sid != '%s'"; + db_query(sprintf($sql, $account->uid, session_id())); + } else { + // if current user is the only who logged in with current account + db_query(sprintf("DELETE FROM {single_login} WHERE uid = %d", $account->uid)); + } + + $res = db_query(sprintf("SELECT counter FROM {single_login} WHERE uid = %d", $account->uid)); + $ping_pong_val = (($row = db_fetch_object($res)) === false) ? 0 : $row->counter; + if ($ping_pong_val >= variable_get(SINGLE_LOGIN_MAX_RECONNECTIONS, SINGLE_LOGIN_DEF_MAX_RECONNECTIONS)) { + db_query(sprintf("UPDATE {users} SET status = 0 WHERE uid = %d", $account->uid)); + + $_REQUEST['destination'] = 'single_login/blocked'; + + user_logout(); + } elseif ($ping_pong_val) { + $relogins_left = variable_get(SINGLE_LOGIN_MAX_RECONNECTIONS, SINGLE_LOGIN_DEF_MAX_RECONNECTIONS) - $ping_pong_val; + drupal_set_message(variable_get(SINGLE_LOGIN_MSG_RELOGGED, SINGLE_LOGIN_DEF_RELOGGED) . $relogins_left); + } + } - _single_login_update_sess_field($account->uid); + _single_login_update_sess_field($account->uid); - break; - } + break; + } } -/** - * - */ function single_login_static_page($op) { - switch ($op) { - case 'blocked': - return variable_get(SINGLE_LOGIN_MSG_BLOCKED, SINGLE_LOGIN_DEF_BLOCKED); - default: - drupal_goto(); - } + switch ($op) { + case 'blocked': + return variable_get(SINGLE_LOGIN_MSG_BLOCKED, SINGLE_LOGIN_DEF_BLOCKED); + default: + drupal_goto(); + } } /** - * Implementation of hook_cron(). + * Implementation of cron job. + * */ function single_login_cron() { - $clear_older_than_days = intval(variable_get(SINGLE_LOGIN_STORE_HISTORY, SINGLE_LOGIN_DEF_STORE_HISTORY)); - if ($clear_older_than_days > 0) { - $clear_older_than_secs = $clear_older_than_days * 24 * 60 * 60; - $sql = "DELETE FROM {single_login_history} WHERE %d - date > %d"; - $sql = sprintf($sql, time(), $clear_older_than_secs); - db_query($sql); - } -} - -/** - * - */ -function _single_login_is_user_single(array $user_roles) { - $roles_single_login = variable_get(SINGLE_LOGIN_CHECK_ROLES, array()); + $clear_older_than_days = intval(variable_get(SINGLE_LOGIN_STORE_HISTORY, SINGLE_LOGIN_DEF_STORE_HISTORY)); + if ($clear_older_than_days > 0) { + $clear_older_than_secs = $clear_older_than_days * 24 * 60 * 60; + $sql = "DELETE FROM {single_login_history} WHERE %d - date > %d"; + $sql = sprintf($sql, time(), $clear_older_than_secs); + db_query($sql); + } +} + +function _single_login_is_user_single($user_roles) { + $roles_single_login = variable_get(SINGLE_LOGIN_CHECK_ROLES, array()); + + foreach ($user_roles as $role_id) { + if (in_array($role_id, $roles_single_login)) return true; + } - foreach ($user_roles as $role_id) { - if (in_array($role_id, $roles_single_login)) { - return TRUE; - } - } - - return FALSE; + return false; } -/** - * - */ function _single_login_get_session_id_fid() { - $res = db_query('SELECT fid FROM {profile_fields} WHERE name = \'profile_current_session_id\''); - $row = db_fetch_object($res); - return $row->fid; + $res = db_query('SELECT fid FROM {profile_fields} WHERE name = \'profile_current_session_id\''); + $row = db_fetch_object($res); + return $row->fid; } -/** - * - */ function _single_login_update_sess_field($uid) { - $fid = _single_login_get_session_id_fid(); - db_query("DELETE FROM {profile_values} WHERE uid = %d AND fid = %d", $uid, $fid); - $sql = "INSERT INTO - {profile_values} - SET - fid = %d, - uid = %d, - value = '%s'"; - db_query(sprintf($sql, $fid, $uid, session_id())); -} \ No newline at end of file + $fid = _single_login_get_session_id_fid(); + db_query("DELETE FROM {profile_values} WHERE uid = %d AND fid = %d", $uid, $fid); + $sql = "INSERT INTO + {profile_values} + SET + fid = %d, + uid = %d, + value = '%s'"; + db_query(sprintf($sql, $fid, $uid, session_id())); +}