diff --git a/database/database.mssql b/database/database.mssql index d2ca4730e33..027ca668cf8 100644 --- a/database/database.mssql +++ b/database/database.mssql @@ -20,7 +20,7 @@ CREATE TABLE [dbo].[accesslog] ( GO CREATE TABLE [dbo].[authmap] ( - [aid] [numeric](10, 0) NULL , + [aid] [numeric](10, 0) IDENTITY NULL , [uid] [int] NOT NULL , [authname] [varchar] (128) NOT NULL , [module] [varchar] (128) NOT NULL diff --git a/modules/statistics.module b/modules/statistics.module index bd071d0bf34..032f642f0da 100644 --- a/modules/statistics.module +++ b/modules/statistics.module @@ -668,56 +668,32 @@ function statistics_display_online_block() { /* count users with activity in the past defined period */ $time_period = variable_get("statistics_block_online_time", 2700); - /* - ** This call gathers all the info we need on users/guests in a single - ** database call, thus is quite efficient. - */ - $result = db_query("SELECT COUNT(DISTINCT hostname) AS count, uid, MAX(timestamp) AS max_timestamp FROM {accesslog} WHERE timestamp >= %d GROUP BY uid ORDER BY max_timestamp DESC", (time() - $time_period)); - - $users = $guests = 0; - /* Count number of users & guests currently online based on db query */ - while ($users_online = db_fetch_array($result)) { - if ($users_online["uid"]) { - /* Has uid, so is a registered user */ - $user_list[$users] = $users_online[uid]; - $users++; - } - else { - /* - ** There's only going to be one return with a uid of 0, and that's - ** the guest(s). Hence, the count of this field is the total number - ** of guests currently online. - */ - $guests = $users_online["count"]; - } - } + $guests = db_fetch_object(db_query("SELECT COUNT(DISTINCT sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0", time() - $time_period)); + $users = db_query("SELECT DISTINCT uid, MAX(timestamp) AS max_timestamp FROM {sessions} WHERE timestamp >= %d AND uid != 0 GROUP BY uid ORDER BY max_timestamp DESC", time() - $time_period ); + $total_users = db_affected_rows(); /* format the output with proper grammar */ - if ($users == 1 && $guests == 1) { - $output .= t("There is currently %members and %visitors online.", array("%members" => format_plural($users, "1 user", "%count users"), "%visitors" => format_plural($guests, "1 guest", "%count guests"))); + if ($total_users == 1 && $guests->count == 1) { + $output .= t("There is currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests"))); } else { - $output .= t("There are currently %members and %visitors online.", array("%members" => format_plural($users, "1 user", "%count users"), "%visitors" => format_plural($guests, "1 guest", "%count guests"))); + $output .= t("There are currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests"))); } - if (user_access("access userlist") && $users) { + if (user_access("access userlist") && $total_users) { /* Display a list of currently online users */ $max_users = variable_get("statistics_block_online_max_cnt", 10); - $uid = reset($user_list); - while (($uid) && ($max_users)) { - $user = user_load(array("uid" => $uid)); - /* When displaying name, be sure it's not more than defined max length */ + $items = array(); + while ($uid = db_fetch_object($users)) { + $user = user_load(array("uid" => $uid->uid)); + /* Display only max_length characters of username */ $items[] = format_name($user); - $uid = next($user_list); - /* - ** When $max_users reaches zero, we break out even if there are - ** more online (as defined by the admin) - */ - $max_users--; } - $output .= "

"; - $output .= theme("theme_item_list", $items, variable_get("statistics_block_online_subtitle", "Online users:")); + if ($items) { + $output .= "

"; + $output .= theme("theme_item_list", $items, variable_get("statistics_block_online_subtitle", "Online users:")); + } } } else { diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index bd071d0bf34..032f642f0da 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -668,56 +668,32 @@ function statistics_display_online_block() { /* count users with activity in the past defined period */ $time_period = variable_get("statistics_block_online_time", 2700); - /* - ** This call gathers all the info we need on users/guests in a single - ** database call, thus is quite efficient. - */ - $result = db_query("SELECT COUNT(DISTINCT hostname) AS count, uid, MAX(timestamp) AS max_timestamp FROM {accesslog} WHERE timestamp >= %d GROUP BY uid ORDER BY max_timestamp DESC", (time() - $time_period)); - - $users = $guests = 0; - /* Count number of users & guests currently online based on db query */ - while ($users_online = db_fetch_array($result)) { - if ($users_online["uid"]) { - /* Has uid, so is a registered user */ - $user_list[$users] = $users_online[uid]; - $users++; - } - else { - /* - ** There's only going to be one return with a uid of 0, and that's - ** the guest(s). Hence, the count of this field is the total number - ** of guests currently online. - */ - $guests = $users_online["count"]; - } - } + $guests = db_fetch_object(db_query("SELECT COUNT(DISTINCT sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0", time() - $time_period)); + $users = db_query("SELECT DISTINCT uid, MAX(timestamp) AS max_timestamp FROM {sessions} WHERE timestamp >= %d AND uid != 0 GROUP BY uid ORDER BY max_timestamp DESC", time() - $time_period ); + $total_users = db_affected_rows(); /* format the output with proper grammar */ - if ($users == 1 && $guests == 1) { - $output .= t("There is currently %members and %visitors online.", array("%members" => format_plural($users, "1 user", "%count users"), "%visitors" => format_plural($guests, "1 guest", "%count guests"))); + if ($total_users == 1 && $guests->count == 1) { + $output .= t("There is currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests"))); } else { - $output .= t("There are currently %members and %visitors online.", array("%members" => format_plural($users, "1 user", "%count users"), "%visitors" => format_plural($guests, "1 guest", "%count guests"))); + $output .= t("There are currently %members and %visitors online.", array("%members" => format_plural($total_users, "1 user", "%count users"), "%visitors" => format_plural($guests->count, "1 guest", "%count guests"))); } - if (user_access("access userlist") && $users) { + if (user_access("access userlist") && $total_users) { /* Display a list of currently online users */ $max_users = variable_get("statistics_block_online_max_cnt", 10); - $uid = reset($user_list); - while (($uid) && ($max_users)) { - $user = user_load(array("uid" => $uid)); - /* When displaying name, be sure it's not more than defined max length */ + $items = array(); + while ($uid = db_fetch_object($users)) { + $user = user_load(array("uid" => $uid->uid)); + /* Display only max_length characters of username */ $items[] = format_name($user); - $uid = next($user_list); - /* - ** When $max_users reaches zero, we break out even if there are - ** more online (as defined by the admin) - */ - $max_users--; } - $output .= "

"; - $output .= theme("theme_item_list", $items, variable_get("statistics_block_online_subtitle", "Online users:")); + if ($items) { + $output .= "

"; + $output .= theme("theme_item_list", $items, variable_get("statistics_block_online_subtitle", "Online users:")); + } } } else { diff --git a/modules/user.module b/modules/user.module index 2e0702e0c19..5c36461e4e3 100644 --- a/modules/user.module +++ b/modules/user.module @@ -549,6 +549,7 @@ function user_get_authmaps($authname = NULL) { } function user_set_authmaps($account, $authmaps) { + foreach ($authmaps as $key => $value) { $module = explode("_", $key, 2); if ($value) { @@ -1535,10 +1536,11 @@ function user_admin_edit($edit = array()) { if ($edit["status"] == 0) { db_query("DELETE FROM {users} WHERE uid = %d", $account->uid); db_query("DELETE FROM {authmap} WHERE uid = %d", $account->uid); - $output .= t("The account has been deleted."); + $output .= status(t("the account has been deleted.")); } else { - $output .= t("Failed to delete account: the account has to be blocked first."); + $error = t("Failed to delete account: the account has to be blocked first."); + $output .= theme("theme_error", $error); } } diff --git a/modules/user/user.module b/modules/user/user.module index 2e0702e0c19..5c36461e4e3 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -549,6 +549,7 @@ function user_get_authmaps($authname = NULL) { } function user_set_authmaps($account, $authmaps) { + foreach ($authmaps as $key => $value) { $module = explode("_", $key, 2); if ($value) { @@ -1535,10 +1536,11 @@ function user_admin_edit($edit = array()) { if ($edit["status"] == 0) { db_query("DELETE FROM {users} WHERE uid = %d", $account->uid); db_query("DELETE FROM {authmap} WHERE uid = %d", $account->uid); - $output .= t("The account has been deleted."); + $output .= status(t("the account has been deleted.")); } else { - $output .= t("Failed to delete account: the account has to be blocked first."); + $error = t("Failed to delete account: the account has to be blocked first."); + $output .= theme("theme_error", $error); } }