<?php
session_start();
include ("dbcfg/config.php");
include ("include/geoip.inc");
$steamid = $_GET["authid"];
$_SESSION['steamid'] = $steamid;
//echo "steamid ".$_SESSION['steamid'];
//echo "<br>".session_id();
$sql = mysql_connect($dbhost, $dbuname, $dbpass)or die("Databasen svarar inte");
mysql_select_db($dbname, $sql);
//$a = mysql_query("SELECT count(*) FROM $table1 WHERE authid='".$steamid."'", $sql);
//$an = mysql_result($a,0);
$sqlquery = mysql_query("SELECT nick,uses,ip,date FROM $table1 WHERE authid='".$steamid."' AND `uses`>='$numuses' ORDER BY uses DESC", $sql);
$an = @mysql_num_rows($sqlquery);
//$names = mysql_num_rows($sqlquery);
$sqlquery2 = mysql_query("SELECT time,connects,rounds,date FROM $table2 WHERE authid='".$steamid."'", $sql);
$info = mysql_fetch_array($sqlquery2);
$sqlquery3 = mysql_query("SELECT ip FROM $table1 WHERE authid='".$steamid."'", $sql);
$ip = mysql_fetch_array($sqlquery3);
$time = $info['time'];
if($time == 0)
{
	$time = 0;
}
$weeks = floor($time/604800);
$rest = $time%604800;
$days = floor($rest/86400);
$rest2 = $rest%86400;
$hours = floor($rest2/3600);
$rest3 = $rest2%3600;
$mins = floor($rest3/60);
$sec = $rest3%60; 

if($weeks == 0 && $days == 0 && $hours == 0 && $mins == 0 && $sec == 0)
{
	$thetime = "";
}
else if($weeks == 0 && $days == 0 && $hours == 0 && $mins == 0 && $sec >= 1)
{
	$thetime = $sec."sec";
}
else if($weeks == 0 && $days == 0 && $hours == 0 && $mins >= 1 && $sec >= 0)
{
	$thetime = $mins."mins"." ".$sec."sec";
}
else if($weeks == 0 && $days == 0 && $hours >= 1 && $mins >= 0 && $sec >= 0) 
{
	$thetime = $hours."hours"." ".$mins."mins"." ".$sec."sec";
}
else if($weeks == 0 && $days >= 1 && $hours >= 0 && $mins >= 0 && $sec >= 0)
{
	$thetime = $days."days"." ".$hours."hours"." ".$mins."mins"." ".$sec."sec";
} 
else if($weeks >= 1 && $days >= 0 && $hours >= 0 && $mins >= 0 && $sec >= 0)
{
	$thetime = $weeks."weeks"." ".$days."days"." ".$hours."hours"." ".$mins."mins"." ".$sec."sec";
}

?>
		<table width="100%" border="0" cellspacing="0" cellpadding="2">
  		<tr>
    	<td  align="center" bgcolor="#F0F0F0">
		<table width="80%" border="0" cellpadding="2" cellspacing="1" id="info">
		<!-- 
		<tr> 
        <td align="left" width="40%" bgcolor="#DDDDDD"><a href="<?php //echo $siteurl ?>playerinfo.php?authid=<?php //echo $_SESSION['steamid'] ?>">Refresh</a></td>
		<td align="left" bgcolor="#DDDDDD"><b></b></td>
        </tr>
		-->
		<tr> 
        <td align="left" width="40%" bgcolor="#DDDDDD"><a href=<?php echo $siteurl ?>players.php?ip=<?php echo $ip['ip'] ?> >Other players on the same ip</a></td>
		<td align="left" bgcolor="#DDDDDD"><b>Last connected: </b><?php echo $info['date'] ?></td>
        </tr>
			
      	<tr>
        <td align="left" width="40%" bgcolor="#DDDDDD"><b>Steamid: </b><?php echo $steamid  ?></td>
		<td align="left" bgcolor="#DDDDDD"><b>Total playtime: </b><?php echo $thetime ?></td>
        </tr>
		<tr>
		<td align="left" width="40%" bgcolor="#DDDDDD"><b>Connects: </b><?php echo $info['connects']  ?></td>
		<td align="left" bgcolor="#DDDDDD"><b>Rounds: </b><?php echo $info['rounds']  ?></td>
		</tr>
		</table>
		<tr>
		<td  align="center" bgcolor="#F0F0F0">
		<table width="80%" border="0" cellpadding="2" cellspacing="1" id="info2">
		<tr>
		<td bgcolor="#DDDDDD" width="33%"><b>Names</b></td>
		<td bgcolor="#DDDDDD" width="33%"><b>Uses</b></td>
		<td bgcolor="#DDDDDD" width="34%"><b>Last used</b></td>
		</tr>
<?php	for($i=0;$i <$an;$i++)
		{	
			$playerinfo = mysql_fetch_array($sqlquery);
			$player_ip = $playerinfo['ip'];

			$gi = geoip_open("include/GeoIP.dat",GEOIP_STANDARD);
			$cc = "images/spacer.gif";
			if($cc = strtolower(geoip_country_code_by_addr($gi, $player_ip)))
			{
				$cc = "images/flags/$cc.gif";
			}
			else
			{
				$cc = "images/spacer.gif";
			}
			$cn = geoip_country_name_by_addr($gi, $player_ip);
			geoip_close($gi);
			$bild="<img src=$cc height=12 width=16>";				
//		echo "Namn: ".$playerinfo['nick']." & antal: ".$playerinfo['uses']."<BR>";
?>	
      		<tr>
        	<td bgcolor="#E8E8E8"><?php echo $bild." &#8226; ".$playerinfo['nick'] ?></td>
        	<td bgcolor="#E8E8E8"><?php echo $playerinfo['uses'] ?></td>
			<td bgcolor="#E8E8E8"><?php echo $playerinfo['date'] ?></td>       
      		</tr>
<?php
		} 
?>
   			</table>
			</tr>
			</td>
  			</tr>
			</table>	
<?php
			mysql_close($sql);
?>