<?PHP
/* JAG Online -------------------------- 06/03/2004 ------------------ v1.31 [6.5~7.1] */
/*                                                                                     */
/*      ////////// //\\ \\\\\\\\\\       Created by Dashe at http://nsd.jagamarog.com  */
/*             // //  \\ \\                                                            */
/*            // //    \\ \\             Email Address:           dashe@jagamarog.com  */
/*           // /////\\\\\ \\   \\\\\                                                  */
/*          // //        \\ \\      \\                                                 */
/*         // //          \\ \\\\\\\\\\                                                */
/* /////////  a g a m a r o g . c o m   N u k e   S c r i p t   D e v e l o p m e n t  */
/*                                                                                     */     
/* Created By Dashe -> http://nsd.jagamarog.com                                        */ 
/*  تعريب ملتقى العرب  http://arabmultaqa.com                                                                                    */
/* ----------------------------------------------------------------------------------- */

/* DO NOT EDIT BELOW UNLESS YOU KNOW WHAT YOU ARE DOING ------------------------------ */
/* Set Global Variables & General Variables ------------------------------------------ */
global $user, $cookie, $prefix, $user_prefix, $db, $name, $REQUEST_URI;

$QH1 = "SELECT show_module_unknown, past_time
		FROM ".$prefix."_jag_online_config";
$RH1 =  $db -> sql_query($QH1);
list($ModuleUnkown, $PastTime) = sql_fetch_row($RH1);

$guest 		= 0;
$ctime  	= time();
$past		= $ctime - $PastTime;

	if (getenv("HTTP_CLIENT_IP")) 		$host_ip = getenv("HTTP_CLIENT_IP");
elseif (getenv("HTTP_X_FORWARDED_FOR")) $host_ip = getenv("HTTP_X_FORWARDED_FOR");
else   						 			$host_ip = getenv("REMOTE_ADDR");

if (is_user($user)) 
	{
	cookiedecode($user);
	$username = $cookie[1];
	
	$QH2 = "SELECT user_id, username, user_from
			FROM ".$user_prefix."_users
			WHERE username = '$username'";
	$RH2 =  $db -> sql_query($QH2);
	list($user_id, $username, $user_from) = sql_fetch_row($RH2);
	}
else
	{
	$QH3 = "SELECT bot_ip, bot_name
			FROM ".$prefix."_jag_online_botlist";
	$RH3 =  $db -> sql_query($QH3); 
	while (list($bot_ip, $bot_name) = sql_fetch_row($RH3)) 
		{	
		if ($bot_ip != "" AND strstr("$host_ip", $bot_ip)) 
			{							
			$username 	= "$bot_name";
   	 		$guest 		= 2;
			break;
			}
		}
	if ($guest == 0)
		{
   	 	$username 	= "$host_ip";
    	$guest 		= 1;
		}
	}

if ($name == "")
	{
	$name = "$ModuleUnkown";
	}
else
	{
	$check_name = eregi_replace(" ", "_", "$name");

	$QH4 = "SELECT custom_title 
			FROM ".$prefix."_modules
			WHERE title = '$check_name'";
	$RH4 =  $db -> sql_query($QH4) or die("Bad QH4:".mysql_error());
	list($custom_title) = sql_fetch_row($RH4);

	if ($custom_title == "") 	$name = $name;
	else						$name = $custom_title;
	}

/* Update The Sessions Table ---------------------------------------------- */
$QH5 = "SELECT jag_online_username
		FROM ".$prefix."_jag_online
		WHERE jag_online_username = '$username'";
$RH5 =  $db -> sql_query($QH5);

if ($row = sql_fetch_array($RH5))
	{
	$QH6 = "UPDATE ".$prefix."_jag_online 
			SET jag_online_user_id = '$user_id', jag_online_username = '$username', jag_online_user_from = '$user_from', jag_online_time = '$ctime', jag_online_ip = '$host_ip', jag_online_guest = '$guest', jag_online_module = '$name', jag_online_url = '$REQUEST_URI'
			WHERE jag_online_username = '$username'";
	$RH6 =  $db -> sql_query($QH6);
	} 
else 
	{
	$QH7 = "DELETE FROM ".$prefix."_jag_online
			WHERE jag_online_ip = '$host_ip'";
	$RH7 =  $db -> sql_query($QH7);
	
    $QH8 = "INSERT 
			INTO ".$prefix."_jag_online (jag_online_user_id, jag_online_username, jag_online_user_from, jag_online_time, jag_online_ip, jag_online_guest, 
			jag_online_module, jag_online_url) VALUES ('$user_id', '$username', '$user_from', '$ctime', '$host_ip', '$guest', '$name', '$REQUEST_URI')";
	$RH8 =  $db -> sql_query($QH8);
	}

/* Delete Any Users Gone Past The Set Time Period ------------------------------------ */	
	$QH9 = "DELETE FROM ".$prefix."_jag_online
			WHERE jag_online_time < '$past'";
	$RH9 =  $db -> sql_query($QH9);
?>
