<?
$page = "admin_stats.php";
include "admin_header.php";
echo $head;

echo "
<h2>$admin_stats1</h2>
$admin_stats2
<br><br>
";



// SHOW FRIEND OF STATS
echo "
<table cellpadding='0' cellspacing='0' style='margin-top: 3px;'>
<tr><td colspan='2' class='header'>$admin_stats3</td></tr>
<tr><td colspan='2' class='stats1' NOWRAP>$admin_stats4</td></tr>
";

$friends = mysql_query("SELECT friend_u_id, COUNT(friend_u_id) AS mode FROM bhost_friends GROUP BY friend_u_id ORDER BY mode DESC LIMIT 10");
$count = 0;
while($friend = mysql_fetch_assoc($friends)) {
$count++;
$friend_info = mysql_fetch_assoc(mysql_query("SELECT u_id, username FROM bhost_users WHERE u_id='$friend[friend_u_id]'"));
echo "
<tr>
<td class='stats1' width='250'>$count. <a href='admin_useredit.php?u_id=$friend_info[u_id]' target='_blank'>$friend_info[username]</a></td>
<td class='stats2' width='100'>$friend[mode] $admin_stats5&nbsp;</td>
</tr>
";
}
if($count == 0) {
echo "
<tr><td colspan='2' width='365' class='stats1' NOWRAP><i>$admin_stats6</i></td></tr>
";
}

echo "
</table>
<br>
";



// SHOW FRIENDLIST STATS
echo "
<table cellpadding='0' cellspacing='0' style='margin-top: 3px;'>
<tr><td colspan='2' class='header'>$admin_stats7</td></tr>
<tr><td colspan='2' class='stats1' NOWRAP>$admin_stats8</td></tr>
";

$friends = mysql_query("SELECT u_id, COUNT(u_id) AS mode FROM bhost_friends GROUP BY u_id ORDER BY mode DESC LIMIT 10");
$count = 0;
while($friend = mysql_fetch_assoc($friends)) {
$count++;
$friend_info = mysql_fetch_assoc(mysql_query("SELECT u_id, username FROM bhost_users WHERE u_id='$friend[u_id]'"));
echo "
<tr>
<td class='stats1' width='250'>$count. <a href='admin_useredit.php?u_id=$friend_info[u_id]' target='_blank'>$friend_info[username]</a></td>
<td class='stats2' width='100'>$friend[mode] $admin_stats5&nbsp;</td>
</tr>
";
}
if($count == 0) {
echo "
<tr><td colspan='2' width='365' class='stats1' NOWRAP><i>$admin_stats6</i></td></tr>
";
}

echo "
</table>
<br>
";



// SHOW ENTRIES STATS
echo "
<table cellpadding='0' cellspacing='0' style='margin-top: 3px;'>
<tr><td colspan='2' class='header'>$admin_stats9</td></tr>
<tr><td colspan='2' class='stats1' NOWRAP>$admin_stats10</td></tr>
";

$entries = mysql_query("SELECT author_u_id, COUNT(e_id) AS mode FROM bhost_entries GROUP BY author_u_id ORDER BY mode DESC LIMIT 10");
$count = 0;
while($entry = mysql_fetch_assoc($entries)) {
$count++;
$entry_info = mysql_fetch_assoc(mysql_query("SELECT u_id, username FROM bhost_users WHERE u_id='$entry[author_u_id]'"));
echo "
<tr>
<td class='stats1' width='250'>$count. <a href='admin_useredit.php?u_id=$entry_info[u_id]' target='_blank'>$entry_info[username]</a></td>
<td class='stats2' width='100'>$entry[mode] $admin_stats11&nbsp;</td>
</tr>
";
}
if($count == 0) {
echo "
<tr><td colspan='2' width='365' class='stats1' NOWRAP><i>$admin_stats12</i></td></tr>
";
}

echo "
</table>
<br>
";





// SHOW COMMENTS STATS
echo "
<table cellpadding='0' cellspacing='0' style='margin-top: 3px;'>
<tr><td colspan='2' class='header'>$admin_stats13</td></tr>
<tr><td colspan='2' class='stats1' NOWRAP>$admin_stats14</td></tr>
";

$comments = mysql_query("SELECT author_u_id, username, COUNT(author_u_id) AS mode FROM bhost_comments WHERE author_u_id<>'0' GROUP BY author_u_id ORDER BY mode DESC LIMIT 10");
$count = 0;
while($comment = mysql_fetch_assoc($comments)) {
$count++;
$comment_info = mysql_fetch_assoc(mysql_query("SELECT u_id, username FROM bhost_users WHERE u_id='$comment[author_u_id]'"));

if($comment_info == FALSE) {
$user = "$comment[username]";
} else {
$user = "<a href='admin_useredit.php?u_id=$comment_info[u_id]' target='_blank'>$comment_info[username]</a>";
}
echo "
<tr>
<td class='stats1' width='250'>$count. $user</td>
<td class='stats2' width='100'>$comment[mode] $admin_stats15&nbsp;</td>
</tr>
";
}
if($count == 0) {
echo "
<tr><td colspan='2' width='365' class='stats1' NOWRAP><i>$admin_stats16</i></td></tr>
";
}
echo "
</table>
<br>
";






// SHOW LOGINS STATS
echo "
<table cellpadding='0' cellspacing='0' style='margin-top: 3px;'>
<tr><td colspan='2' class='header'>$admin_stats17</td></tr>
<tr><td colspan='2' class='stats1' NOWRAP>$admin_stats18</td></tr>
";

$logins = mysql_query("SELECT username, COUNT(username) AS mode FROM bhost_log WHERE result='1' GROUP BY username ORDER BY mode DESC LIMIT 10");
$count = 0;
while($login = mysql_fetch_assoc($logins)) {
$count++;
$login_info = mysql_fetch_assoc(mysql_query("SELECT u_id, username FROM bhost_users WHERE username='$login[username]'"));

if($login_info[username] != "") { 
$login_username = "<a href='admin_useredit.php?u_id=$login_info[u_id]' target='_blank'>$login_info[username]</a>";
} else {
$login_username = "<i>$admin_stats25</i>";
}

echo "
<tr>
<td class='stats1' width='250'>$count. $login_username</td>
<td class='stats2' width='100'>$login[mode] $admin_stats19&nbsp;</td>
</tr>
";
}
if($count == 0) {
echo "
<tr><td colspan='2' width='365' class='stats1' NOWRAP><i>$admin_stats24</i></td></tr>
";
}

echo "
</table>
<br>
";







// SHOW MALE:FEMALE STATS
$maleusers = mysql_num_rows(mysql_query("SELECT gender FROM bhost_users WHERE gender='Male'"));
$femaleusers = mysql_num_rows(mysql_query("SELECT gender FROM bhost_users WHERE gender='Female'"));
$totalusers = mysql_num_rows(mysql_query("SELECT u_id FROM bhost_users"));

$total_users = $totalusers;
if($totalusers == 0) { $totalusers = 1; $total_users = 0; }

$maleusers_percent = round($maleusers / $totalusers, 2) * 100;
$femaleusers_percent = round($femaleusers / $totalusers, 2) * 100;
$unspecified_percent = abs(100 - ($maleusers_percent + $femaleusers_percent));

if($total_users == 0) { $unspecified_percent = 0; }

$gender_ratio = "$maleusers_percent% $admin_stats21, $femaleusers_percent% $admin_stats22, $unspecified_percent% $admin_stats23";

echo "
<table cellpadding='0' cellspacing='0' style='margin-top: 3px;'>
<tr><td colspan='2' class='header'>$admin_stats20</td></tr>
<tr><td colspan='2' width='365' class='stats1' NOWRAP>$gender_ratio</td></tr>
</table>
";

echo $foot;
?>










