<?
//
//
require_once($_SERVER['DOCUMENT_ROOT']."/jquery/inc/system.php"); 
//
//
if(!$user){
header('location:/login/');
exit();
}
//
//
head([]);
//
//
                $coll = DB::$dbs->querySingle('SELECT COUNT(id) FROM `mail_contact` WHERE `id_user` = "'.$user['id'].'"');
		$num = 10;
		$total = intval(($coll - 1) / $num) + 1;
		$page = isset($_GET['page'])?intval($_GET['page']):1;
		if(empty($page) or $page < 0) $page = 1;
		if($page > $total) $page = $total;
		$start = $page * $num - $num; 

$sql = DB::$dbs->query("SELECT * FROM `mail_contact` WHERE `id_user` = '".$user['id']."' ORDER BY `new` DESC, `time` DESC LIMIT $start, $num")->fetchAll(PDO::FETCH_BOTH);
		?>
<div class="poster -gas">
		    <div class="start">
		        <center>
		            <span class="title-wqi">Мои диалоги</span>
		        </center>

		<?
		if($coll < 1){
		 ?>
		 <div class="menu-not">
		     Диалогов еще нет
		   </div>
		 <?   
		}
			foreach ($sql as $sqlls => $im): 
$message = DB::$dbs->queryFetch("SELECT * FROM `mail` WHERE `id_user` = ? AND `id_ank` = ? OR `id_user` = ? AND `id_ank` = ? ORDER BY `id` DESC LIMIT 1", array($user['id'],$im['id_ank'],$im['id_ank'],$user['id']));

			if($im['new'] == 0)$check = '';
else $check = '- <font color="lime">(не прочитано)</font>';
			?>

<a href="/mail/?id=<?=$im['id_ank'];?>">
<div class="menu-not2">
<?=user_mail($im['id_ank']);?> <?=$check;?>
<span style="float: right;">
<?=times($im['time']);?>
</span>
<br>
<font color="#777777">
<?=bbcode(text_msg($message['text']));?>
</font>
</div>
</a>


			<?php endforeach;
			?>
			</div>
			<?
			echo page('?',$page,$total); ?>
			</div>
<?
//
//
foot([]);
//
//
?>