<?
include_once 'sys/inc/start.php';
include_once 'sys/inc/compress.php';
include_once 'sys/inc/sess.php';
include_once 'sys/inc/home.php';
include_once 'sys/inc/settings.php';
include_once 'sys/inc/db_connect.php';
include_once 'sys/inc/ipua.php';
include_once 'sys/inc/fnc.php';
include_once 'sys/inc/user.php';
only_reg(); 
$set['title']='Свежая почта';
include_once 'sys/inc/thead.php';
title();
echo "<div class='rekl_main'>";
echo "<center><img src='/img/add_fav.gif' alt='' class='icon'/>\n";
echo "<a href='/info/spam.php'><b>Случаи обмана</b> (читать всем)</center></a>";
echo "</div>\n";
$k_post=mysql_result(mysql_query("SELECT COUNT(DISTINCT `mail`.`id_user`) FROM `mail`
 LEFT JOIN `users_konts` ON `mail`.`id_user` = `users_konts`.`id_kont` AND `users_konts`.`id_user` = '$user[id]'
 WHERE `mail`.`id_kont` = '$user[id]' AND (`users_konts`.`type` IS NULL OR `users_konts`.`type` = 'common' OR `users_konts`.`type` = 'favorite') AND `mail`.`read` = '0'"),0);


$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
echo "<table class='post'>\n";
if ($k_post==0)
{
echo "Нет новых сообщений\n";
}
else
{
$q=mysql_query("SELECT MAX(`mail`.`time`) AS `last_time`, COUNT(`mail`.`id`) AS `count`, `mail`.`id_user`, `users_konts`.`name` FROM `mail`
 LEFT JOIN `users_konts` ON `mail`.`id_user` = `users_konts`.`id_kont` AND `users_konts`.`id_user` = '$user[id]'
 WHERE `mail`.`id_kont` = '$user[id]' AND (`users_konts`.`type` IS NULL  OR `users_konts`.`type` = 'common' OR `users_konts`.`type` = 'favorite') AND `mail`.`read` = '0'
  GROUP BY `mail`.`id_user` ORDER BY `count` DESC LIMIT $start, $set[p_str]");
//echo mysql_error(),"<br />\n";
while ($kont = mysql_fetch_assoc($q))
{
$ank=get_user($kont['id_user']);
echo "   <tr>\n";
//".($kont['name']?$kont['name']:$ank['nick'])."
echo '<tr><td class="icon14">';
avatar2($ank['id']);
echo '</td><td class="linechat">';
if ($ank)
echo "<img src='/img/mail.gif'> <a href='/mail.php?id=$ank[id]'>Письма</a><font color='red'> +$kont[count]</font><br/>\n";
echo "От "; 
echo "".online($ank['id'])." <a href='/info.php?id=$ank[id]'><span style=\"color:$ank[ncolor]\">$ank[nick]</span></a>\n";
if($ank['rating']>=0 && $ank['rating']<=99)echo " ";
if($ank['rating']>=100 && $ank['rating']<=199)echo " <img src='/style/rating/bronze.gif'></img> "; 
if($ank['rating']>=200 && $ank['rating']<=299)echo " <img src='/style/rating/silver.gif'></img> ";
if($ank['rating']>=300 && $ank['rating']<=399)echo " <img src='/style/rating/gold.gif'></img> ";
if($ank['rating']>=400 && $ank['rating']<=1000)echo " <img src='/style/rating/lafes_user.gif'></img> ";
if($ank['rating']>=1001 && $ank['rating']<=10000)echo " <img src='/rating/konkurs.png'></img> ";
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `ban` WHERE `id_user` = '$ank[id]' AND `time` > '$time'"), 0)!=0)
echo "<font color='red'>[BAN]</font>\n";
echo "<br />";

echo "<img src='/style/icons/clock.png' alt='' class='icon'/><font color='#afb0a3'> ".vremja($kont['last_time'])."</font><br />\n";

echo '</td></tr>';
}
}
echo "</table>\n";

if ($k_page>1)str('?',$k_page,$page); // Вывод страниц

echo "<div class='aut'>\n";
echo "<img src='/style/icons/forum1.png' alt='' class='icon'/>\n";
echo "<a href='/konts.php?$passgen'>Список контактов</a><br />\n";
echo "</div>\n";
include_once 'sys/inc/tfoot.php';
?>