<?php
defined('ACCESS') OR die('No direct script access...');
/**
* Author - koder_alex
* ISQ - 669906617
* VK - https://vk.com/koder_alex
* It is forbidden to give, sell, modify.
*/
thead('Диалоги');
if (isset($_GET['p']) && $_GET['p'] != NULL && is_numeric($_GET['p']) && $_GET['p'] > 1) {
$p = abs(intval($_GET['p']));
} else {
$p = 1;
}
$k_post = DB::$pdo->querySingle("SELECT COUNT(m.id) FROM `mail` AS m,
(SELECT MAX(id) AS id FROM `mail` WHERE `unlink` != :user_id AND (`id_kont` = :user_id OR `id_user` = :user_id) GROUP BY IF(`id_user` = :user_id, `id_kont`, `id_user`)) as max
WHERE m.id = max.id AND (m.id_kont = :user_id OR m.id_user = :user_id) AND m.unlink != :user_id", array(':user_id' => $user['id']));
$k_page = 0;
if ($k_post > 10) {
$pagination = new pagination(10, $k_post, $p);
$total_lin = $pagination->limit;
$k_page = $pagination->pages;
} else {
$total_lin = '';
}
?>
<div class='app-block'>
<div class="touch"><a href="/mail/?act=write" class="touch-cont _oh">
<div class="_center"><i class="our our-mail"></i> Написать сообщение</div>
</a></div>
<div id="contactUpdate" data-limit="10" data-update="<?= UPDATE ?>" data-page="<?= $p ?>">
<?
if ($k_post) {
$q = DB::$pdo->query("SELECT *, IF(m.id_user = :user_id, m.id_kont, m.id_user) AS contact,
SUM(IF (m.read = '0' AND m.id_user = :user_id, 1, 0)) AS outbox,
(SELECT COUNT(*) FROM mail WHERE `id_kont` = :user_id and `id_user` = contact AND `read` = '0' AND `unlink` != :user_id) as inbox FROM `mail` AS m,
(SELECT MAX(id) AS id FROM `mail` WHERE `unlink` != :user_id AND (`id_kont` = :user_id OR `id_user` = :user_id) GROUP BY IF(`id_user` = :user_id, `id_kont`, `id_user`)) as max
WHERE m.id = max.id AND (m.id_kont = :user_id OR m.id_user = :user_id) AND m.unlink != :user_id
GROUP BY contact ORDER BY m.time DESC, inbox DESC $total_lin;", array(':user_id' => $user['id']));
while ($post = $q->fetch()) {
$d = d_user($post['contact']);
?>
<a class="dialog_item<?= ($post['outbox'] >= 1 ? ' di_unread_outbox' : '') . ($post['inbox'] >= 1 ? ' di_unread_inbox' : '') ?>"
href="/mail/?act=show&peer=<?= $post['contact'] ?>" data-id="<?= $post['contact'] ?>">
<div class="di_iwrap"><?= $d['avatar'] ?></div>
<div class="di_cont">
<span class="di_date"><?= system::times($post['time']) ?></span>
<div class="di_head">
<span class="mi_author"><?= $d['online'] . $d['group'] . $d['login'] . $d['Medals'] ?></span><?= ($post['inbox'] >= 1 ? '<span class="di_unread_cnt"><span class="di_hide"> (+</span>' . $post['inbox'] . '<span class="di_hide">)</span></span>' : '') ?>
</div>
<div class="di_body">
<?php if($post['attachments']) {
?><div class="mi_medias_plain">Фотография</div><?
} else if($post['gifts'] > 0) { ?>
<div class="mi_medias_plain">Подарок</div>
<?php } else { ?>
<?= ($post['msg'] ? '<div class="di_text">' . short_text(hideLink(system::BBcode(system::textOut($post['msg']))), 14) . '</div>' : '') ?>
<?php } ?>
</div>
</div>
</a>
<?
}
} else
show('История контактов пуста.', 'null');
?></div><?
if ($k_page > 1)
str_vk('?', $k_page, $p);
?></div><?