<?
// Обновление информации
if (isset($user) && mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_who` WHERE `id_user` = '$user[id]'"),0) == 0) {
	mysql_query("INSERT INTO `chat_who` (`id_user`, `time`,  `room`) values('$user[id]', '$time', '0')");
} elseif (isset($user)) {
	mysql_query("UPDATE `chat_who` SET `room` = '0', `time` = '$time' WHERE `id_user` = '$user[id]' LIMIT 1");
}

if (isset($_GET['top'])) {
	$top = ($_GET['top'] == 'anagramm' ? 'anagramm' : 'umnik');
	$set['title'] = ($_GET['top'] == 'anagramma' ? 'Топ 10 анаграммы' : 'Топ 10 самых умных');
} else {
	header('Location: ?');
}

include_once H.'sys/inc/thead.php';
title();
aut(); 

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `chat_who` WHERE `count_" . $top . "` > '0'"), 0);
$k_page = k_page($k_post,$set['p_str']);
$page = page($k_page);
$start = ($set['p_str'] * $page) - $set['p_str'];

?><table class="post"><?

if ($k_post == 0)
{
	?>
	<div class="mess">
	<?= __('В рейтинге никто не учавствует')?>
	</div>
	<?
}

$q = mysql_query("SELECT * FROM `chat_who` WHERE `count_" . $top . "` > '0' ORDER BY `count_" . $top . "` DESC LIMIT $start, $set[p_str]");

while ($post = mysql_fetch_assoc($q)) {
	$num++;
	
	?><div class="<?= ($num % 2 ? 'nav2' : 'nav1')?>"><?
	
	echo user::avatar($post['id_user'], 0) . user::nick($post['id_user'], 1, 1, 1) . '<br />';
	echo '<span style="color: blue; font-weigh: bold;">[' . $post['count_' . $top] . ']</span> правильных ответов в <b>' . ($top == 'umnik' ? 'Викторине' : 'Анаграмме') . '</b>';

	?></div><?
}
?>
</table>

<?
if ($k_page > 1) {
	str('?func=top&amp;top=' . $top . '&amp;', $k_page, $page);
}
?>

<div class="foot">
 <img src="/style/icons/str2.gif" alt="*" /> <a href="?"><?= __('Прихожая')?></a><br />
</div>