<?php
include_once("incs/conf.php");
include_once("incs/fmysql.php");
include_once("incs/fnc.php");
include_once("incs/head.php");

$act=fil($_GET['act']);

$ban_ok=$user[ban]-$time;
if($ban_ok>0){
head("Статистика",$meuser,$auth);
echo "<div class='rowup'>";
include_once("incs/title.php");
echo "Статистика</div>";

echo "Вы забанены по причине:<br>";
echo "<b>$user[ban_prich]</b><br>";
echo "До окончания бана осталось: $ban_ok сек.<br>";
echo "Старайтесь больше не нарушать <a href=\"rules.php\">правила</a> сайта!<br>";
include_once("incs/down.php");
}

if($settings[statistik]==1){
head("Статистика",$meuser,$auth);
echo "<div class='rowup'>";
include_once("incs/title.php");
echo "Статистика</div>";

echo "Раздел закрыт<br>";
include_once("incs/down.php");}

switch($act){

case'kto_gde':

head("Статистика - Кто где?",$meuser,$auth);
echo "<div class='rowup'>";
include_once("incs/title.php");
echo "<a href=\"statistik.php\">Статистика</a> - Кто где?</div>";

echo "<b>В чате:</b><br>";
$gde_user_ch = mysql_num_rows(mysql_query("SELECT `id` FROM `user` WHERE `gde` = 'chat' AND `time_gde` > '".($time-180)."'"));
if($gde_user_ch==0){echo "В чате никого нет<br>";}

$gde_chat=mysql_query("SELECT * FROM `user` WHERE `gde` = 'chat' AND `time_gde` > '".($time-180)."'");
while ($gde_chat_us = mysql_fetch_array($gde_chat))
{
echo "<div class='menu'><a href=\"my.php?id=$gde_chat_us[id]\">$gde_chat_us[nick]</a></div>";
}

echo "<b>В форуме:</b><br>";
$gde_user_fo = mysql_num_rows(mysql_query("SELECT `id` FROM `user` WHERE `gde` = 'forum' AND `time_gde` > '".($time-180)."'"));
if($gde_user_fo==0){echo "В форуме никого нет<br>";}

$gde_forum=mysql_query("SELECT * FROM `user` WHERE `gde` = 'forum' AND `time_gde` > '".($time-180)."'");
while ($gde_forum_us = mysql_fetch_array($gde_forum))
{
echo "<div class='menu'><a href=\"my.php?id=$gde_forum_us[id]\">$gde_forum_us[nick]</a></div>";
}

echo "<b>В обменнике:</b><br>";
$gde_user_obm = mysql_num_rows(mysql_query("SELECT `id` FROM `user` WHERE `gde` = 'obmen' AND `time_gde` > '".($time-180)."'"));
if($gde_user_obm==0){echo "В обменнике никого нет<br>";}

$gde_obmen=mysql_query("SELECT * FROM `user` WHERE `gde` = 'obmen' AND `time_gde` > '".($time-180)."'");
while ($gde_obmen_us = mysql_fetch_array($gde_obmen))
{
echo "<div class='menu'><a href=\"my.php?id=$gde_obmen_us[id]\">$gde_obmen_us[nick]</a></div>";
}

echo "<b>В библиотеке:</b><br>";
$gde_user_lib = mysql_num_rows(mysql_query("SELECT `id` FROM `user` WHERE `gde` = 'lib' AND `time_gde` > '".($time-180)."'"));
if($gde_user_lib==0){echo "В библиотеке никого нет<br>";}

$gde_lib=mysql_query("SELECT * FROM `user` WHERE `gde` = 'lib' AND `time_gde` > '".($time-180)."'");
while ($gde_lib_us = mysql_fetch_array($gde_lib))
{
echo "<div class='menu'><a href=\"my.php?id=$gde_lib_us[id]\">$gde_lib_us[nick]</a></div>";
}

include_once("incs/down.php");
break;

}

head("Статистика",$meuser,$auth);
echo "<div class='rowup'>";
include_once("incs/title.php");
echo "Статистика</div>";
$us = mysql_num_rows(mysql_query("SELECT id FROM user"));
$ma = mysql_num_rows(mysql_query("SELECT id FROM mail"));
$qv = mysql_num_rows(mysql_query("SELECT id FROM qv"));
$ch = mysql_num_rows(mysql_query("SELECT id FROM chat_post"));
$fo = mysql_num_rows(mysql_query("SELECT id FROM forum_post"));
$time_user_24h=$time-24*3600;
$user_24h = mysql_num_rows(mysql_query("SELECT id FROM `user` WHERE `date_last` > '$time_user_24h'"));
$obmen_files = mysql_num_rows(mysql_query("SELECT id FROM `obmen` WHERE `id_user` != '0' AND `mod` = '1'"));
$id=fil($_GET['id']);
$my=mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `id` = '$id'"));
echo "Посетителей онлайн за 24 часа: <b>$user_24h</b><br>";
echo "Пользователей зарегистрировано: <b>$us</b><br>";
echo "Сообщений в почте: <b>$ma</b><br>";
echo "Сообщений в гостевой: <b>$qv</b><br>";
echo "Сообщений в чате: <b>$ch</b><br>";
echo "Сообщений в форуме: <b>$fo</b><br>";
echo "Файлов в обменнике: <b>$obmen_files</b><br>";
echo '<div class=\'rowip\'>ТОП 10 лучших поьзователей сайта:</div>';
$t2 = $t = array();
$q = mysql_query("SELECT id, nick FROM user");
while($r = mysql_fetch_assoc($q))
{
$r2 = mysql_num_rows(mysql_query("SELECT id FROM forum_post WHERE id_user=".$r['id']));
$a = mysql_num_rows(mysql_query("SELECT id FROM `forum` WHERE `id_user` = ".$r['id']));
$b = mysql_num_rows(mysql_query("SELECT id FROM `lib` WHERE `id_user` = ".$r['id']));
$c = mysql_num_rows(mysql_query("SELECT id FROM `qv` WHERE `id_user` = ".$r['id']));
$d = mysql_num_rows(mysql_query("SELECT id FROM `obmen` WHERE `id_user` = ".$r['id']));

$t[$r['id']] = $r2+$a+$b+$c+$d+$poz;
$t2[$r['id']] = $r['nick'];
}

echo"<div class='menu'>";
arsort($t);
$i=0;
//Для медалек

$ar = array('img/med/pol-0/m1.gif', 'img/med/pol-0/m2.gif', 'img/med/pol-0/m3.gif', 'img/med/pol-0/m4.gif', 'img/med/pol-0/m5.gif', 'img/med/pol-0/m6.gif', 'img/med/pol-0/m7.gif', 'img/med/pol-0/m8.gif', 'img/med/pol-0/m9.gif', 'img/med/pol-0/m10.gif');


      
foreach($t as $k => $v)
{
	if($v > 0 && $i < 10)

echo ($i+1).'. <img src="'.$ar[$i].'" style="width:25px; height:25px;">'.$t2[$k].' - '.$v.' рейтинг<br>';		     
$i++;
}
echo"</div>";


include_once("incs/down.php");
?>