<?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 ------------------------------ */

/* Check for Hack Attack ------------------------------------------------------------- */
if (eregi("block-JAG_Online.php", $_SERVER['PHP_SELF'])) 
	{
    header("Location: index.php");
    die();
	}
	
function table_check($table, $dbname) 
	{ 
	global $dbname;
	
	$tables = mysql_list_tables($dbname); 
	while (list($temp) = mysql_fetch_array($tables)) 
		{ 
  		if($temp == $table) 
  			return TRUE; 
		}	 
	return FALSE; 
	} 
	
function IPLookup($dotted_ip_address)
	{
	global $prefix, $db;
	
	if (table_check("".$prefix."_jag_online_iplookup", $dbname))
		{
		$Q00 = "SELECT country 
				FROM ".$prefix."_jag_online_iplookup
				WHERE inet_aton('$dotted_ip_address') >= ip_from AND inet_aton('$dotted_ip_address') <= ip_to";
		$R00 =  $db -> sql_query($Q00) or die("Bad Q00:".mysql_error());	
		list($found_country) = sql_fetch_row($R00);
		
		$country = ucwords(strtolower($country));
		$country = eregi_replace(" ", "_", $found_country);	
		}

	return "$country";
	}				

/* Get Total Numer of Members Online ------------------------------------------------- */
$Q01 = "SELECT *
		FROM ".$prefix."_jag_online
		WHERE jag_online_guest = '0'";
$R01 =  $db -> sql_query($Q01) or die("Bad Q01:".mysql_error());
$num_on_mem = sql_num_rows($R01);

/* Getting Number of Guests Online --------------------------------------------------- */
$Q02 = "SELECT *
		FROM ".$prefix."_jag_online
		WHERE jag_online_guest = '1'";
$R02 =  $db -> sql_query($Q02) or die("Bad Q02:".mysql_error());
$num_on_gue = sql_num_rows($R02);

/* Getting Number of SPiders Online -------------------------------------------------- */
$Q03 = "SELECT *
		FROM ".$prefix."_jag_online
		WHERE jag_online_guest = '2'
		GROUP BY jag_online_username HAVING COUNT(*) > 0";
$R03 =  $db -> sql_query($Q03) or die("Bad Q03:".mysql_error());

$Q04 = "SELECT *
		FROM ".$prefix."_jag_online
		WHERE jag_online_guest = '2'";
$R04 =  $db -> sql_query($Q04) or die("Bad Q04:".mysql_error());
$num_on_spd = sql_num_rows($R04);

$num_on_tot = ($num_on_mem + $num_on_gue + $num_on_spd);
$FlagPath = "images/flags/";	

function GetPercentOn($num_on, $num_tot)
	{
	$percent_on = round((($num_on / $num_tot) * 100), 0)."%";
	return $percent_on;
	}
	
/* Start The Script For The Block ---------------------------------------------------- */
	if ($OnlineCfg[show_online_total] == 1) 	$cur_title_num	= number_format($num_on_tot);
	
	$content .= "<TABLE WIDTH='100%' BORDER='0' CELLPADDING='0' CELLSPACING='0'>\n";
	$content .= "	<TR>\n";
	$content .= "		<TD ALIGN='right' 	VALIGN='MIDDLE'>\n";
	$content .= "			<TABLE WIDTH='100%' BORDER='0' CELLPADDING='0' CELLSPACING='0'>\n";
	$content .= "				<TR>\n";
	$content .= "					<TD ALIGN='right' VALIGN='MIDDLE' CLASS='boxcontent'>\n";
	$content .= "						<NOBR><B>"._ONLINE_TITLE."</B></NOBR></TD>\n";
	$content .= "					<TD ALIGN='RIGHT' VALIGN='MIDDLE' CLASS='boxcontent'>\n";
	$content .= "						<NOBR><B>$cur_title_num</B></NOBR></TD>\n";
	$content .= "				</TR>\n";
	$content .= "			</TABLE>\n";
	$content .= "		</TD>\n";
	$content .= "	</TR>\n";
	
/* Members Stats Section ------------------------------------------------------------- */	
if($OnlineCfg[show_mem] == 1)
	{
	if ($OnlineCfg[show_mem_detail_num] == 1) 	
		{
		$mem_title_num	= number_format($num_on_mem)."&nbsp;";
		}
	if ($OnlineCfg[show_mem_detail_per] == 1)	
		{
		$mem_title_num .= "-";
		$mem_on_per 	= "".GetPercentOn($num_on_mem, $num_on_tot)."";
		}

	$content .= "	<TR>\n";
	$content .= "		<TD ALIGN='right' VALIGN='MIDDLE'>\n";
	$content .= "			<TABLE WIDTH='100%' BORDER='0' CELLPADDING='0' CELLSPACING='0' STYLE='PADDING-TOP:2;'>\n";
	$content .= "				<TR>\n";
	$content .= "					<TD ALIGN='right' VALIGN='MIDDLE' CLASS='boxcontent'>\n";
	$content .= "						<NOBR><B>"._ONLINE_MEMS.":</B></NOBR></TD>\n";
	$content .= "					<TD ALIGN='RIGHT' VALIGN='MIDDLE' CLASS='boxcontent'>\n";
	$content .= "						<NOBR>$mem_title_num</NOBR></TD>\n";
	$content .= "					<TD ALIGN='RIGHT' VALIGN='MIDDLE' WIDTH='038' CLASS='boxcontent'>\n";
	$content .= "						<NOBR>$mem_on_per</NOBR></TD>\n";
	$content .= "				</TR>\n";
	$content .= "			</TABLE>\n";
	$content .= "		</TD>\n";
	$content .= "	</TR>\n";	
	}	
	
if ($OnlineCfg[show_mem] == 1 && $OnlineCfg[show_mem_detail] == 1)
	{
	$content .= "	<TR>\n";
	$content .= "		<TD ALIGN='right' VALIGN='MIDDLE'>\n";
	$content .= "			<TABLE WIDTH='100%' BORDER='0' CELLPADDING='0' CELLSPACING='0' STYLE='PADDING-BOTTOM:1;'>\n";
	
	while ($mem_on = sql_fetch_array($R01))
		{
		if (isset($mem_on[jag_online_guest]) && $mem_on[jag_online_guest] == 0)
			{
			$Q05 = "SELECT *
					FROM ".$prefix."_jag_online
					WHERE jag_online_username = '$mem_on[jag_online_username]'";
			$R05 =  $db -> sql_query($Q05) or die("Bad Q05:".mysql_error());
			$mem_info = sql_fetch_array($R05);
			
			$content .= "				<TR>\n";
			$content .= "					<TD ALIGN='right' VALIGN='MIDDLE' WIDTH='100%' CLASS='boxcontent'>\n";
			
			if (strlen($mem_info[jag_online_username]) > $OnlineCfg[show_mem_detail_name_size])
				{
				$online_username = substr($mem_info[jag_online_username], 0, ($OnlineCfg[show_mem_detail_name_size] - 1))."&hellip;";
				}
			else
				{
				$online_username = $mem_info[jag_online_username];
				}
					
			if ($mem_info[jag_online_username] == $userinfo[username])
				{
				$content .= "						<A HREF='modules.php?name=Your_Account&op=edituser'>$online_username</A>";
				}
			else
				{
				$content .= "						<A HREF='modules.php?name=Forums&file=profile&mode=viewprofile&u=$mem_info[jag_online_user_id]'>$online_username</A>";
				}
				
			$content .= "					</TD>\n";
			$content .= "					<TD ALIGN='RIGHT' VALIGN='MIDDLE'>\n";
			
			if ($OnlineCfg[show_mem_detail_group] == 1)
				{
				$Q06 = "SELECT icon_image
						FROM ".$prefix."_jag_online_icons
						WHERE icon_username = '$mem_on[jag_online_username]'";
				$R06 =  $db -> sql_query($Q06) or die("Bad Q06:".mysql_error());
				
				if ($row = sql_fetch_array($R06))
					{
					$content .= "						<IMG SRC='images/blocks/JAG_Online/$row[icon_image].gif' WIDTH='27' HEIGHT='6' VSPACE='1' ALT='".eregi_replace("_", " ", $row[icon_image])."'>&nbsp;\n";
					}
				else
					{
					$content .= "						<IMG SRC='images/blank.gif' WIDTH='27' HEIGHT='6' VSPACE='1'>&nbsp;\n";
					}
				}
				
			$content .= "					</TD>\n";
			$content .= "					<TD ALIGN='RIGHT' VALIGN='BOTTOM'>\n";
		
			if ($OnlineCfg[show_mem_detail_flag] == 1)
				{		
				$FlagInfo = eregi_replace(" ", "_", $mem_info[jag_online_user_from]);
				$FlagFile = $FlagInfo.".gif";
				
				if(($mem_info[jag_online_user_from] != "") && (file_exists($FlagPath.$FlagFile)))
					{
					$show_image_alt = "";
					
					if (eregi("/", "$FlagInfo"))	
						{
						$i = 0;						
						$image_alt = explode("/", "$FlagInfo");
						while ($image_alt[$i] != "")	$i++;
							
						$i = $i - 1;
						while ($image_alt[$i] != "")
							{						
							$show_image_alt .= ucfirst(eregi_replace("_", " ", $image_alt[$i]));			
							$i = $i - 1;
							if ($image_alt[$i] != "") $show_image_alt .= ", ";
							}
						}
					else
						{
						$show_image_alt = "$FlagInfo";
						}
						
					$FlagPathFile = $FlagPath.$FlagFile;
					$content .= "						<IMG SRC='$FlagPathFile' WIDTH='30' HEIGHT='15' ALIGN='TOP' ALT='".eregi_replace("_", " ", "$show_image_alt")."'>\n";
					}				
				elseif($OnlineCfg[show_mem_detail_flag_auto] == 1)
					{	
					$Location = IPLookup($mem_info[jag_online_ip]);
					$FlagFile = $Location.".gif";
					
					if (file_exists($FlagPath.$FlagFile))
						{		
						$FlagPathFile = $FlagPath.$FlagFile;
						$content .= "						<IMG SRC='$FlagPathFile' WIDTH='30' HEIGHT='15' ALT='".eregi_replace("_", " ", "$Location")."'>\n";
						}
					else
						{
						$content .= "						<IMG SRC='images/blank.gif' WIDTH='30' HEIGHT='15' ALT=''>\n";
						}
					}
				else
					{
					$content .= "						<IMG SRC='images/blank.gif' WIDTH='30' HEIGHT='15' ALT=''>\n";
					}
				}		
			$content .= "					</TD>\n";
			$content .= "				</TR>\n";

			if ($OnlineCfg[show_mem_detail_loca] == 1)
				{
				if (strlen($mem_info[jag_online_module]) > $OnlineCfg[show_mem_detail_modu_size])
					{
					$module = substr($mem_info[jag_online_module], 0, ($OnlineCfg[show_mem_detail_modu_size] - 1))."&hellip;";
					}
				else
					{
					$module = "$mem_info[jag_online_module]";
					}
			
				$content .= "				<TR>\n";
				$content .= "					<TD ALIGN='right' 	VALIGN='BOTTOM' COLSPAN='3' CLASS='boxcontent'>\n";
				$content .= "						&nbsp;&nbsp;&nbsp;<A HREF='$mem_info[jag_online_url]'>&raquo; ".ereg_replace("_"," ", $module)."</TD>\n";
				$content .= "				</TR>\n";
				}
			}
		}
		
	$content .= "			</TABLE>\n";
	$content .= "		</TD>\n";
	$content .= "	</TR>\n";		
	}

/* Guests Stats Section -------------------------------------------------------------- */
if($OnlineCfg[show_gue] == 1)
	{
	if ($OnlineCfg[show_gue_detail_num] == 1) 	
		{
		$gue_title_num	= number_format($num_on_gue)."&nbsp;";
		}
	if ($OnlineCfg[show_gue_detail_per] == 1)	
		{
		$gue_title_num .= "-";
		$gue_on_per 	= "".GetPercentOn($num_on_gue, $num_on_tot)."";
		}

	$content .= "	<TR>\n";
	$content .= "		<TD ALIGN='right' VALIGN='MIDDLE'>\n";
	$content .= "			<TABLE WIDTH='100%' BORDER='0' CELLPADDING='0' CELLSPACING='0' STYLE='PADDING-TOP:2;'>\n";
	$content .= "				<TR>\n";
	$content .= "					<TD ALIGN='right' VALIGN='MIDDLE' CLASS='boxcontent'>\n";
	$content .= "						<NOBR><B>"._ONLINE_GUES.":</B></NOBR></TD>\n";
	$content .= "					<TD ALIGN='RIGHT' VALIGN='MIDDLE' CLASS='boxcontent'>\n";
	$content .= "						<NOBR>$gue_title_num</NOBR></TD>\n";
	$content .= "					<TD ALIGN='RIGHT' VALIGN='MIDDLE' WIDTH='038' CLASS='boxcontent'>\n";
	$content .= "						<NOBR>$gue_on_per</NOBR></TD>\n";
	$content .= "				</TR>\n";
	$content .= "			</TABLE>\n";
	$content .= "		</TD>\n";
	$content .= "	</TR>\n";	
	}	

if ($OnlineCfg[show_gue] == 1 && $OnlineCfg[show_gue_detail] == 1)
	{
	$gue_count = 1;
	
	$content .= "	<TR>\n";
	$content .= "		<TD ALIGN='right' 	VALIGN='MIDDLE'>\n";
	$content .= "			<TABLE WIDTH='100%' BORDER='0' CELLPADDING='0' CELLSPACING='0' STYLE='PADDING-BOTTOM:1;'>\n";

	while ($gue_on = sql_fetch_array($R02))
		{
		if (isset($gue_on[jag_online_guest]) && $gue_on[jag_online_guest] == 1)
			{
			$Q07 = "SELECT *
					FROM ".$prefix."_jag_online
					WHERE jag_online_username = '$gue_on[jag_online_username]'";
			$R07 =  $db -> sql_query($Q07) or die("Bad Q07:".mysql_error());
			$gue_info = sql_fetch_array($R07);	

			$content .= "				<TR>\n";
			$content .= "					<TD ALIGN='right' VALIGN='TOP' WIDTH='100%'>\n";
					
			if (is_admin($admin) && $gue_info[jag_online_username] != "")
				{
				$new_guest_name = "<A HREF='http://www.ripe.net/perl/whois?query=$gue_info[jag_online_username]' TARGET='_new'>$gue_info[jag_online_username]</A>";						
				}
			elseif ($OnlineCfg[show_gue_detail_ipadd] == 1 && $gue_info[jag_online_username] != "")
				{
				$old_guest_name = explode(".", $gue_info[jag_online_username]);
				$new_guest_name = "".$old_guest_name[0].".".$old_guest_name[1].".***.***";
				}
			else
				{
				$new_guest_name = ""._ONLINE_GUE." ".JAG_Online_Leading_Zero(2, $gue_count)."";
				}
															
			$content .= "						$new_guest_name\n";
			$content .= "					</TD>\n";
			$content .= "					<TD ALIGN='RIGHT' VALIGN='BOTTOM'>\n";
			
			if ($OnlineCfg[show_gue_detail_flag] == 1)
				{	
				$Location = eregi_replace(" ", "", IPLookup($gue_info[jag_online_ip]));
				$FlagFile = $Location.".gif";
				
				if (file_exists($FlagPath.$FlagFile))
					{		
					$content .= "						<IMG SRC='".$FlagPath.$FlagFile."' WIDTH='17' HEIGHT='11' ALT='".eregi_replace("_", " ", "$Location")."'>\n";
					}
				else
					{
					$content .= "						<IMG SRC='images/blank.gif' WIDTH='17' HEIGHT='11' ALT=''>\n";
					}					
				}

			$content .= "					</TD>\n";
			$content .= "				</TR>\n";
							
			if ($OnlineCfg[show_gue_detail_loca] == 1)
				{
				if (strlen($gue_info[jag_online_module]) > $OnlineCfg[show_mem_detail_modu_size])
					{
					$module = substr($gue_info[jag_online_module], 0, ($OnlineCfg[show_mem_detail_modu_size] - 1))."&hellip;";
					}
				else
					{
					$module = "$gue_info[jag_online_module]";
					}
			
				$show_module = ereg_replace("_", " ", $module);
	
				$content .= "				<TR>\n";
				$content .= "					<TD ALIGN='right' VALIGN='BOTTOM' COLSPAN='2'>\n";
				$content .= "						<NOBR>&nbsp;&nbsp;&nbsp;&raquo; <A HREF='$gue_info[jag_online_url]'>$show_module</A></TD></NOBR>\n";
				$content .= "				</TR>\n";
				}
			}
		$gue_count++;
		}
		
	$content .= "			</TABLE>\n";
	$content .= "		</TD>\n";
	$content .= "	</TR>\n";		
	}

/* Search Bot Stats Section ---------------------------------------------------------- */
if($OnlineCfg[show_spd] == 1)
	{
	if ($OnlineCfg[show_spd_detail_num] == 1) 	
		{
		$spd_title_num	= number_format($num_on_spd)."&nbsp;";
		}
	if ($OnlineCfg[show_spd_detail_per] == 1)	
		{
		$spd_title_num .= "-";
		$spd_on_per 	= "".GetPercentOn($num_on_spd, $num_on_tot)."";
		}

	$content .= "	<TR>\n";
	$content .= "		<TD ALIGN='right' VALIGN='MIDDLE'>\n";
	$content .= "			<TABLE WIDTH='100%' BORDER='0' CELLPADDING='0' CELLSPACING='0' STYLE='PADDING-TOP:2;'>\n";
	$content .= "				<TR>\n";
	$content .= "					<TD ALIGN='right' VALIGN='MIDDLE' CLASS='boxcontent'>\n";
	$content .= "						<NOBR><B>"._ONLINE_SPDS.":</B></NOBR></TD>\n";
	$content .= "					<TD ALIGN='RIGHT' VALIGN='MIDDLE' CLASS='boxcontent'>\n";
	$content .= "						<NOBR>$spd_title_num</NOBR></TD>\n";
	$content .= "					<TD ALIGN='RIGHT' VALIGN='MIDDLE' WIDTH='038' CLASS='boxcontent'>\n";
	$content .= "						<NOBR>$spd_on_per</NOBR></TD>\n";
	$content .= "				</TR>\n";
	$content .= "			</TABLE>\n";
	$content .= "		</TD>\n";
	$content .= "	</TR>\n";	
	}	

if ($OnlineCfg[show_spd] == 1 && $OnlineCfg[show_spd_detail] == 1)
	{
	$content .= "	<TR>\n";
	$content .= "		<TD ALIGN='right' VALIGN='MIDDLE'>\n";
	$content .= "			<TABLE WIDTH='100%' BORDER='0' CELLPADDING='0' CELLSPACING='0' STYLE='PADDING-BOTTOM:1;'>\n";

	while ($spd_on = sql_fetch_array($R03))
		{
		if (isset($spd_on[jag_online_guest]) && $spd_on[jag_online_guest] == 2)
			{
			$Q08 = "SELECT *
					FROM ".$prefix."_jag_online
					WHERE jag_online_guest = '2' AND jag_online_username = '$spd_on[jag_online_username]'";
			$R08 =  $db -> sql_query($Q08) or die("Bad Q08:".mysql_error());
			$spd_info 		= sql_fetch_array($R08);	
			$spd_info_tot 	= sql_num_rows($R08);
			
			$content .= "				<TR>\n";
			$content .= "					<TD ALIGN='right' VALIGN='TOP' WIDTH='100%'>\n";
					
			if ($OnlineCfg[show_spd_detail_qty] == 1)
				{
				$spd_qty = "#$spd_info_tot ";						
				}

			$content .= "						".$spd_qty."".$spd_info[jag_online_username]."\n";					
			$content .= "					</TD>\n";
			
			if ($OnlineCfg[show_spd_detail_flag] == 1)
				{
				$content .= "					<TD ALIGN='RIGHT' VALIGN='BOTTOM'>\n";
				
				$Location = eregi_replace(" ", "", IPLookup($spd_info[jag_online_ip]));
				$FlagFile = $Location.".gif";
					
				if (file_exists($FlagPath.$FlagFile))
					{		
					$content .= "						<IMG SRC='".$FlagPath.$FlagFile."' WIDTH='17' HEIGHT='11' ALT='".eregi_replace("_", " ", "$Location")."'>\n";
					}
				else
					{
					$content .= "						<IMG SRC='images/blank.gif' WIDTH='17' HEIGHT='11' ALT=''>\n";
					}
				}
				
			$content .= "					</TD>\n";
			$content .= "				</TR>\n";
							
			if ($OnlineCfg[show_gue_detail_loca] == 1)
				{
				if (strlen($spd_info[jag_online_module]) > $OnlineCfg[show_mem_detail_modu_size])
					{
					$module = substr($spd_info[jag_online_module], 0, ($OnlineCfg[show_mem_detail_modu_size] - 1))."&hellip;";
					}
				else
					{
					$module = "$spd_info[jag_online_module]";
					}
			
				$show_module = ereg_replace("_", " ", $module);
	
				$content .= "				<TR>\n";
				$content .= "					<TD ALIGN='right' VALIGN='BOTTOM' COLSPAN='2'>\n";
				$content .= "						<NOBR>&nbsp;&nbsp;&nbsp;&raquo; <A HREF='$spd_info[jag_online_url]'>$show_module</TD></NOBR>\n";
				$content .= "				</TR>\n";
				}
			}
		}
		
	$content .= "			</TABLE>\n";
	$content .= "		</TD>\n";
	$content .= "	</TR>\n";		
	}

	$content .= "	<TR>\n";
	$content .= "		<TD ALIGN='right' VALIGN='TOP' COLSPAN='3'>\n";
	$content .= "			<IMG SRC='images/blank.gif' BORDER='0' WIDTH='100%' HEIGHT='10'></TD>\n";
	$content .= "	</TR>\n";
	$content .= "</TABLE>\n";
?>
