<?php
include_once ('core/base.php');
falseauth();

$header = 'Почта';
include_once ('core/head.php');

echo '<div class="b">';

echo '<div class="title">Почта</div>';

$k_post = $base -> query("SELECT * FROM `message_c` WHERE `kto` = '".$u['id']."'") -> num_rows;

$k_page = k_page($k_post,10);

$page = page($k_page);

$start = 10 * $page - 10;

$dialog = $base -> query("SELECT * FROM `message_c` WHERE `kto` = '".$u['id']."' ORDER BY `posl_time` DESC LIMIT $start, 10");
if($dialog -> num_rows > 0){
while($d = $dialog -> fetch_assoc()){
if($d['kogo'] != $u['id']){

$messages = $base -> query("SELECT * FROM `message` WHERE `kto` = '".$d['kogo']."' AND `komy` = '".$u['id']."' AND `readlen` = '0'")->num_rows;
if($messages > 0) $newmsg = '<font color="red">(+)</font>';
else $newmsg = '';

echo '<a class="btn" href="/dialog/'.$d['kogo'].'">'.nolinkname($d['kogo']).' '.$newmsg.'<span style="float:right"><font color="#B1B1B1">('.tm($d['time']).')</font></span>';

$count = $base->query("SELECT * FROM `message` WHERE `kto` = '".$u['id']."' and `komy` = '".$d['kogo']."' or `kto` = '".$d['kogo']."' and `komy` = '".$u['id']."' LIMIT 1")->num_rows;

$list = $base->query("SELECT * FROM `message` WHERE `kto` = '".$u['id']."' and `komy` = '".$d['kogo']."' or `kto` = '".$d['kogo']."' and `komy` = '".$u['id']."' ORDER BY `time` DESC LIMIT 1")->fetch_assoc();

if(isset($count)) {

echo '<br/><font color="#FFF">'.$list['text'].'</font>';

} else {

echo '<br/><font color="#B1B1B1">Диалог пуст.</font>';

}

echo '</a>';

}
}
}else{
echo '<br/><center>Список диалогов пуст.</center><br/>';
}

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

echo '<br/><a class="btn" href="javascript:history.go(-1)"><img src="/images/icons/back.png"> Назад</a>';

echo '</div>';

include_once ('core/foot.php');
?>