2012-04-17 Sergio Martin <sergio.martin@artica.es>
* 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
This commit is contained in:
parent
14f5937b2f
commit
a4d15adbe0
|
@ -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 "<div class='nf'>".__('No other users connected')."</div>";
|
||||
|
@ -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] = '<a href="index.php?sec=gusuarios&sec2=godmode/users/configure_user&id='.$row["id_usuario"].'">'.$row["id_usuario"].'</a>';
|
||||
$data[1] = $row["ip_origen"];
|
||||
$data[2] = $row["fecha"];
|
||||
$data[0] = '<a href="index.php?sec=gusuarios&sec2=godmode/users/configure_user&id='.$row["id_user"].'">'.$row["id_user"].'</a>';
|
||||
$data[1] = $ip_origin;
|
||||
$data[2] = date($config["date_format"], $row['last_connect']);
|
||||
array_push ($table->data, $data);
|
||||
}
|
||||
|
||||
|
|
|
@ -110,6 +110,12 @@ $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"];
|
||||
|
|
Loading…
Reference in New Issue