<?php

if (! defined ( 'BLOCK_FILE' )) {
	if (function_exists ( "location" ))
		location ( "../index.php" );
	else
		die ();
	exit ();
}
global $tracker_lang;
$blocktitle = $tracker_lang ['statistic'];
$content = ReadCache ( 'stats', true );
if (! $content) {
	global $tracker_lang, $ss_uri, $maxusers, $CURUSER, $CURGROUP, $use_sessions;
	$registered = 0;
	$downloaded = 0;
	$disabled = 0;
	$male = 0;
	$female = 0;
	$unverified = 0;
	$torrents = 0;
	$dead = 0;
	$downtor = 0;
	$upsta = 0;
	$seeders = 0;
	$leechers = 0;
	$warned_users = 0;
	$latestuser = 'Никто';
	$sql = sql_query ( "SELECT id, username, downloaded, warned, enabled, gender, status FROM users" ) or sqlerr ( __FILE__, __LINE__ );
	$sql2 = sql_query ( "SELECT seeder FROM peers" ) or sqlerr ( __FILE__, __LINE__ );
	$sql3 = sql_query ( "SELECT visible, filename, times_completed, size FROM torrents" ) or sqlerr ( __FILE__, __LINE__ );
	while ( $us = mysql_fetch_array ( $sql ) ) {
		$registered ++;
		$downloaded += $us ["downloaded"];
		if ($us ['warned'] == 'yes')
			$warned_users ++;
		if ($us ['enabled'] == 'no')
			$disabled ++;
		if ($us ['gender'] == 1)
			$male ++;
		elseif ($us ['gender'] == 2)
			$female ++;
		if ($us ['status'] == 'pending')
			$unverified ++;
		if ($us ['status'] != 'pending')
			$latestuser = WriteCurgroup ( "<a href=userdetails.php?id=" . $us ["id"] . " class=\"online\">", '$CURGROUP["can_viewprof"]' ) . $us ["username"] . WriteCurgroup ( "</a>", '$CURGROUP["can_viewprof"]' );
	}
	while ( $us = mysql_fetch_array ( $sql3 ) )
		if ($us ['filename']) {
			$torrents ++;
			if ($us ['visible'] == 'no')
				$dead ++;
			if ($us ['times_completed'])
				$downtor ++;
			$upsta += $us ["size"];
		}
		//$downtor -= $torrents;
	while ( $us = mysql_fetch_array ( $sql2 ) )
		if ($us ['seeder'] == 'yes')
			$seeders ++;
		else
			$leechers ++;
	$upstat = mksize ( $upsta );
	if ($leechers == 0)
		$ratio = 0;
	else
		$ratio = round ( $seeders / $leechers * 100 );
	$peers = number_format ( $seeders + $leechers );
	$seeders = number_format ( $seeders );
	$leechers = number_format ( $leechers );
	
	$content .= "<table width=\"100%\" class=\"main\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">
<td align=\"center\" style=\"border: none;\">
<table class=\"main\" border=\"1\" cellspacing=\"0\" cellpadding=\"5\">
<table width=\"100%\" class=\"main\" border=\"0\" cellspacing=\"0\" cellpadding=\"10\">
  <tr>
    <td width=\"50%\"  align=\"center\" style=\"border: none;\">
<table class=\"main\" border=\"0\" width=\"100%\">
<tr><td class=\"a\"><b>" . $tracker_lang ['places_on_tracker'] . "</b></td><td align=right class=\"a\" width=\"45\">$maxusers</td></tr>
<tr><td class=\"b\"><b>" . $tracker_lang ['users_registered'] . "</b></td><td align=right class=\"b\">$registered</td></tr>
<tr><td class=\"a\"><b>" . $tracker_lang ['males'] . "</b><td align=right class=\"a\">$male</td></tr>
<tr><td class=\"b\"><b>" . $tracker_lang ['females'] . "</b><td align=right class=\"b\">$female</td></tr>
<tr><td class=\"a\"><b>" . $tracker_lang ['last_registered_user'] . "</b> </td><td align=right class=\"a\" width=\"45\">$latestuser</td></tr>
<tr><td class=\"b\"><b>" . $tracker_lang ['users_warned'] . "</b></td><td align=right class=\"b\">$warned_users</td></tr>
<tr><td class=\"a\"><b>" . $tracker_lang ['users_disabled'] . "</b></td><td align=right class=\"a\">$disabled</td></tr>

</table></td>
<td width=\"50%\"  align=\"center\" valign=\"top\" style=\"border: none;\">
<table class=main width=100%>
<tr><td class=\"a\" align=left><b>" . $tracker_lang ['tracker_torrents'] . "</b></td><td align=right class=\"a\" width=\"45\">$torrents</td></tr>
<tr><td class=\"a\" align=left><b>" . $tracker_lang ['tracker_upl'] . "</b></td><td align=right class=\"a\" width=\"45\">$upstat</td></tr>
<tr><td class=\"b\" align=left><b>" . $tracker_lang ['tracker_torrentsd'] . "</b></td><td align=right class=\"b\">$downtor</td></tr>
<tr><td class=\"b\" align=left><b>" . $tracker_lang ['tracker_downu'] . "</b></td><td align=right class=\"b\">" . mksize ( $downloaded ) . "</td></tr>
<tr><td class=\"a\" align=left><b>" . $tracker_lang ['tracker_dead_torrents'] . "</b></td><td align=right class=\"a\">$dead</td></tr>
<tr><td class=\"b\" align=left><b>" . $tracker_lang ['tracker_peers'] . "</b></td><td align=right class=\"b\">$peers

</td></tr>";
	if (isset ( $peers )) {
		$content .= "<tr><td class=\"a\" align=left><b>" . $tracker_lang ['tracker_seeders'] . "</b></td><td align=right class=\"a\">$seeders</td></tr>
<tr><td class=\"b\" align=left><b>" . $tracker_lang ['tracker_leechers'] . "</b></td><td align=right class=\"b\">$leechers</td></tr>
<tr><td class=\"a\" align=left><b>" . $tracker_lang ['tracker_seed_peer'] . "</b></td><td align=right class=\"a\">$ratio</td></tr>";
	
	}
	$content .= "</table></td>";
	$content .= "</table>
</td></tr></table>";
	$content = WriteCache ( $content );
}
?>