From a4d15adbe0b01e4085a34eeb5790630a1f150e7e Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Tue, 17 Apr 2012 13:44:10 +0000 Subject: [PATCH] 2012-04-17 Sergio Martin * include/config_process.php extensions/users_connected.php: Improved users connected extension to know users connected last 5 minutes (connected means charge any page, not only login) git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6001 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- .../extensions/users_connected.php | 47 ++++++++++++++----- pandora_console/include/config_process.php | 8 +++- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/pandora_console/extensions/users_connected.php b/pandora_console/extensions/users_connected.php index 46832c3bc3..1b49a16103 100644 --- a/pandora_console/extensions/users_connected.php +++ b/pandora_console/extensions/users_connected.php @@ -30,25 +30,27 @@ function users_extension_main_god ($god = true) { // Header ui_print_page_header (__("Users connected"), "images/group.png", false, "", $god); + // Get user conected last 5 minutes switch ($config["dbtype"]) { case "mysql": - $sql = "SELECT id_usuario, ip_origen, fecha, accion - FROM tsesion - WHERE descripcion = '" . io_safe_input('Logged in') . "' AND utimestamp > (UNIX_TIMESTAMP(NOW()) - 3600) GROUP BY id_usuario, ip_origen, accion"; + $sql = "SELECT id_user, last_connect + FROM tusuario + WHERE last_connect > (UNIX_TIMESTAMP(NOW()) - 300) ORDER BY last_connect DESC"; break; case "postgresql": - $sql = "SELECT id_usuario, ip_origen, fecha, accion - FROM tsesion - WHERE descripcion = '" . io_safe_input('Logged in') . "' AND utimestamp > (ceil(date_part('epoch', CURRENT_TIMESTAMP)) - 3600) GROUP BY id_usuario, ip_origen, fecha, accion"; + $sql = "SELECT id_user, last_connect + FROM tusuario + WHERE last_connect > (ceil(date_part('epoch', CURRENT_TIMESTAMP)) - 300) ORDER BY last_connect DESC"; break; case "oracle": - $sql = "SELECT id_usuario, ip_origen, fecha, accion - FROM tsesion - WHERE to_char(descripcion) = '" . io_safe_input('Logged in') . "' AND utimestamp > (ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - 3600) GROUP BY id_usuario, ip_origen,fecha, accion"; + $sql = "SELECT id_user, last_connect + FROM tusuario + WHERE last_connect > (ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - 300) ORDER BY last_connect DESC"; break; } - + $rows = db_get_all_rows_sql ($sql); + if (empty ($rows)) { $rows = array (); echo "
".__('No other users connected')."
"; @@ -71,6 +73,25 @@ function users_extension_main_god ($god = true) { // Get data foreach ($rows as $row) { + // Get ip_origin of the last login of the user + switch ($config["dbtype"]) { + case "mysql": + case "postgresql": + $ip_origin = db_get_value_sql(sprintf("SELECT ip_origen + FROM tsesion + WHERE id_usuario = '%s' + AND descripcion = '" . io_safe_input('Logged in') . "' + ORDER BY fecha DESC",$row["id_user"])); + break; + case "oracle": + $ip_origin = db_get_value_sql(sprintf("SELECT ip_origen + FROM tsesion + WHERE id_usuario = '%s' + AND to_char(descripcion) = '" . io_safe_input('Logged in') . "' + ORDER BY fecha DESC",$row["id_user"])); + break; + } + if ($rowPair) $table->rowclass[$iterator] = 'rowPair'; else @@ -79,9 +100,9 @@ function users_extension_main_god ($god = true) { $iterator++; $data = array (); - $data[0] = ''.$row["id_usuario"].''; - $data[1] = $row["ip_origen"]; - $data[2] = $row["fecha"]; + $data[0] = ''.$row["id_user"].''; + $data[1] = $ip_origin; + $data[2] = date($config["date_format"], $row['last_connect']); array_push ($table->data, $data); } diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php index b914be3238..337e32cfb8 100644 --- a/pandora_console/include/config_process.php +++ b/pandora_console/include/config_process.php @@ -109,7 +109,13 @@ $config["global_flash_charts"] = $config["flash_charts"]; if (isset ($config['id_user'])){ $userinfo = get_user_info ($config['id_user']); - + + // Refresh the last_connect info in the user table + // if last update was more than 5 minutes ago + if($userinfo['last_connect'] < (time()-SECONDS_1MINUTE)) { + update_user($config['id_user'], array('last_connect' => time())); + } + // If block_size or flash_chart are provided then override global settings if (!empty($userinfo["block_size"]) && ($userinfo["block_size"] != 0)) $config["block_size"] = $userinfo["block_size"];