Author Topic: Online users statistics on ACP  (Read 3921 times)

0 Members and 1 Guest are viewing this topic.

Offline batu544

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • Free Celebrity wallpapers
Online users statistics on ACP
« on: August 01, 2010, 02:47:25 PM »
Hi,
    Is it possible to get small section on the top right hand corner of the ACP panel displaying total users online statistics.. ?? The most important point is.. can it be auto refreshable ??


Thank you ..
 

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Online users statistics on ACP
« Reply #1 on: August 01, 2010, 05:30:18 PM »
Maybe not exactly what you've asked, but I think it's close ;)


Create a new file admin/whosonline.php with the folowing code:
<?php
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: whosonline.php                                       *
 *        Copyright: (C) 2002-2010 Jan Sorgalla                           *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.7.8                                                *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (Lizenz.txt) f&#1100;r weitere Informationen.                 *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (Licence.txt) for further information.                              *
 *                                                                        *
 *************************************************************************/
$refresh 10;//in seconds (not used for ajax)

define('IN_CP'1);
define('ROOT_PATH''./../');
require(
'admin_global.php');

if (!
defined('USER_INTEGRATION')) {
  
$num_total_online 0;
  
$num_visible_online 0;
  
$num_invisible_online 0;
  
$num_registered_online 0;
  
$num_guests_online 0;
  
$user_online_list "";
  
$prev_user_id "";
  
$prev_ip "";
  
$return "";

  
$sql "SELECT ".get_user_table_field("u.""user_id").get_user_table_field(", u.""user_level").get_user_table_field(", u.""user_name").get_user_table_field(", u.""user_lastaction").get_user_table_field(", u.""user_location").get_user_table_field(", u.""user_invisible").", s.session_user_id, s.session_lastaction, s.session_ip
          FROM ("
.USERS_TABLE." u, ".SESSIONS_TABLE." s)
          WHERE "
.get_user_table_field("u.""user_id")." = s.session_user_id AND s.session_user_id <> ".GUEST." AND ".get_user_table_field("u.""user_lastaction")." > ".(time() - 300)."
          ORDER BY session_ip ASC"
;
  
$result $site_db->query($sql);
  while (
$row $site_db->fetch_array($result)) {
    if (
$row['session_user_id'] != $prev_user_id) {
      
$is_invisible = (isset($row[$user_table_fields['user_invisible']]) && $row[$user_table_fields['user_invisible']] == 1) ? 0;
      if (
$is_invisible) { // Invisible User but show to Admin
      
}
      else {
        
$num_visible_online++;
      }
      
$num_registered_online++;
    }
    
$prev_user_id $row['session_user_id'];
  }

  
$sql "SELECT session_user_id, session_lastaction, session_ip, session_location
          FROM "
.SESSIONS_TABLE."
          WHERE session_lastaction >= "
.(time() - 300)." AND session_user_id = ".GUEST;
  
$result $site_db->query($sql);

  
$num_guests_online 0;
  while (
$row $site_db->fetch_array($result)) {
    if (
$row['session_ip'] != $prev_ip) {
      
$num_guests_online++;
    }
    
$prev_ip $row['session_ip'];
  }


  
$num_total_online $num_registered_online $num_guests_online;
  
$num_invisible_online $num_registered_online $num_visible_online;

  
$lang['online_users'] = preg_replace("/".$site_template->start."num_total".$site_template->end."/siU"$num_total_online$lang['online_users']);
  
$lang['online_users'] = preg_replace("/".$site_template->start."num_registered".$site_template->end."/siU"$num_registered_online$lang['online_users']);
  
$lang['online_users'] = preg_replace("/".$site_template->start."num_guests".$site_template->end."/siU"$num_guests_online$lang['online_users']);
  
$return .= sprintf ("<b>%s</b><br /><br /><br />"$lang['online_users']);
// End defined('USER_INTEGRATION')
if ($action == "js")
{
  echo 
$return;
}
else
{
?>
<html dir="<?php echo $lang['direction']; ?>">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $lang['charset']; ?>">
    <link rel="stylesheet" href="./cpstyle.css">
    <meta http-equiv="Refresh" content="<?=$refresh?>;">
  </head>
  <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="15">
<?php
echo $return;
?>
  </body>
</html>
<?php
}
?>


Then in admin/index.php find:
Code: [Select]
       <td><img src="images/logo.gif"></td>
Insert below:
A. using <iframe>
Code: [Select]
       <td align="left" valign="top" style="overflow: hidden;">
          <iframe width="100%" height="47" frameborder="0" marginwidth="0" scrolling="no" marginheight="0" src="<?php echo $site_sess->url("whosonline.php"); ?>" style="background-color: transparent;"></iframe>
        </td>

B. using AJAX
Code: [Select]
       <td align="left" valign="top" style="overflow: hidden;">
          <div style="position:relative; top:15; width:100%" id="whosonline"></div>
          <script language="JavaScript" type="text/javascript">
          <!--
            function whosOnline()
            {
              var xmlHttp;
              try
              {
                // Firefox, Opera 8.0+, Safari
                xmlHttp=new XMLHttpRequest();
              }
              catch (e)
              {
                // Internet Explorer
                try
                {
                  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e)
                {
                  try
                  {
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                  }
                  catch (e)
                  {
                    return false;
                  }
                }
              }
            
              xmlHttp.onreadystatechange=function()
              {
                if(xmlHttp.readyState==4)
                {
                  if (xmlHttp.status != 404)
                  {
                    document.getElementById("whosonline").innerHTML = xmlHttp.responseText;
                  }
                  return true;
                }
                else
                {
                  //error
                }
              }
              try
              {
                xmlHttp.open("GET", "<?php echo $site_sess->url("whosonline.php?action=js"); ?>&" + (new Date().getTime()), true);
                xmlHttp.send(null);
              }
              catch(e)
              {
                return false;
              }
            }
            function getWhosOnline()
            {
              whosOnline();
              setTimeout("getWhosOnline()", 10000); //in miliseconds (10000 = 10 sec)
            }
            getWhosOnline();
          // -->
          </script>
        </td>

It will refresh every 10 sec, it's controlled by:
A
in admin/whosonline.php:
Code: [Select]
$refresh = 10;//in seconds (not used for ajax)
B
in admin/index.php:
Code: [Select]
             setTimeout("getWhosOnline()", 10000); //in miliseconds (10000 = 10 sec)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline batu544

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • Free Celebrity wallpapers
Re: Online users statistics on ACP
« Reply #2 on: August 02, 2010, 09:05:27 AM »
This is really great !!.. I just tried the AJAX part and it worked very well...

Thanks V@no for this Mod.. , but I think there is something which is not same between ACP's general whois online part and signature MOD's whois online calculation part, because for me these 2 details always shows me different numbers...


Thank  you.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Online users statistics on ACP
« Reply #3 on: August 02, 2010, 02:15:26 PM »
True, because in signature there is no filter for unique IPs, it just counts how many sessions were created in NNN specified period of time (it's a fake, but good for advertisement :D)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)