<?php
require_once('classes/body.class.php');
require_once('classes/db.class.php');
require_once('classes/system.class.php');
$title= new Body;
$title->SetTitle(homeurl.' - Личные сообщения!');
$title->GetHeader();
if ($b == false) {
header('location: /');
die();
}
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="/"style="text-decoration:none; color:white;"> Главная</a> :: Личные сообщения</div></div></div>';

$do = isset($_GET['do']) ? check($_GET['do']) : false;
$look = DB::$dbs->query("SELECT id FROM `letters` WHERE `idwho` = ? GROUP BY who", [$b['id']]);
echo'<div class="list-group lg-alt">';
$look = $look ->rowCount();
if ($look != FALSE) {
$num = 10;
$k_page = k_page($look, $num);
$page = page($k_page);
$start = $num*$page-$num;
$read = DB::$dbs->query("SELECT who, who AS w, (SELECT COUNT(id) FROM `letters` WHERE `read` = ? AND `idwho` = ? AND `who` = w) AS n,(SELECT COUNT(id) FROM `letters` WHERE `read` = ? AND `idwho` = ? AND `who` = w) AS a FROM `letters` WHERE `idwho` = ?  GROUP BY who ORDER BY MIN(`read`), MAX(data) DESC LIMIT $start,$num", [0,$b['id'],1,$b['id'],$b['id']]);
$cols = 0;
while($a = $read->fetch()){
$ava = (!empty(user_inf($a['who'], 'ava')) ? '<div class="pull-left"><img class="img-avatar" src="/'.user_inf($a['who'], 'ava').'" width="45" height="45" alt="not found"/></div>':'<div class="pull-left"><img class="img-avatar" src="/assets/img/4.jpg" alt="not found"/></div>');
$online = (user_inf($a['who'], 'last')>time()-3600 ? '<img src="/assets/images/on.gif" alt="*"/>':'');
$cols++;
$n = ($start + $cols);
echo '<form method="post" action="?">';
$adresat = Nick($a['who']);
echo '<a class="list-group-item media" href="view_mess.php?id='.$a['who'].'"> '.$ava.' '.user_inf($a['who'], 'name').'  '.user_inf($a['who'], 'family').'          '.$online.' <small class="list-group-item-text">(Новые: <b>'.$a['n'].'</b> :: Входящие: '.$a['a'].')</small></a>';
}
} else err('Почта пуста!');
if (isset($_POST['submitForm']))
{
if (empty($_POST['block']))
{
header('Location: ?');
die();
}
echo'</div>';
if ($_POST['d'] == 1) {
foreach($_POST['block'] as $value) {
DB::$dbs->query("DELETE FROM `letters` WHERE `who` = ? AND `idwho` = ?", [$value,$b['id']]);
header('Location: ?');
}
}
}
if ($k_page>1) {
str('?', $k_page,$page);
}
$title->GetMenu();
$title->GetFooter();
?>