Файл: user/mail/index.php
Строк: 254
<?PHP
/* DCMS Special
* Дата последнего редактирования 11.12.2015
* Модифицировал densnet
*/
foreach (array('start', 'compress', 'sess', 'settings', 'db_connect', 'ipua', 'fnc', 'user') as $inc) {
require_once "../../sys/inc/{$inc}.php";
}
only_reg();
$listFlagged = array(
'inbox' => 'Активные',
'favorite' => 'Избранное',
'archive' => 'Архив',
'spam' => 'Спам',
'deleted' => 'Корзина',
);
if (isset($_GET['s']) && array_key_exists($_GET['s'], $listFlagged)) {
$listSort[] = " IF(`id_kont` = '$user[id]', `flaggedTo`, `flaggedFrom`) = '" . mysql_real_escape_string($_GET['s']) . "' ";
$flagged = $_GET['s'];
} else {
$listSort[] = " IF(`id_kont` = '$user[id]', `flaggedTo`, `flaggedFrom`) = 'inbox' ";
$listSort[] = " IF(`id_kont` = '$user[id]', `flaggedTo`, `flaggedFrom`) = 'favorite' ";
$flagged = 'inbox';
}
if (isset($_POST['action'])) {
foreach ($_POST AS $key => $value) {
if (preg_match('/^cnt/i', $key)) {
$contactsTo[] = "`id_kont` = '$value'";
$contactsFrom[] = "`id_user` = '$value'";
$actionTrue = true;
}
}
$paramsTo = '(' . implode(' OR ', $contactsTo) . ") AND `id_user` = '$user[id]'";
$paramsFrom = '(' . implode(' OR ', $contactsFrom) . ") AND `id_kont` = '$user[id]'";
if ($_POST['action'] == 'truncate') {
mysql_query("UPDATE `mail` SET `deleted` = '-1' WHERE (`id_user` = '$user[id]' OR `id_kont` = '$user[id]') AND (" . implode(' OR ', $listSort) . ") AND (`deleted` != '0' OR type = 'email')");
mysql_query("UPDATE `mail` SET `deleted` = '$user[id]' WHERE (`id_user` = '$user[id]' OR `id_kont` = '$user[id]') AND (" . implode(' OR ', $listSort) . ") AND `deleted` = '0' AND `type` = 'personal'");
msg('Корзина успешно очищена');
} elseif (array_key_exists($_POST['action'], $listFlagged) && isset($actionTrue)) {
mysql_query("UPDATE `mail` SET `flaggedFrom` = '" . mysql_real_escape_string($_POST['action']) . "' WHERE $paramsTo AND (" . implode(' OR ', $listSort) . ") ");
mysql_query("UPDATE `mail` SET `flaggedTo` = '" . mysql_real_escape_string($_POST['action']) . "' WHERE $paramsFrom AND (" . implode(' OR ', $listSort) . ") ");
msg("Контакты перенесены в " . $listFlagged[$_POST[action]] . "");
}
header('Location: ?s=' . $flagged);
exit;
}
#Поиск контактов по email и нику с id
if (isset($_GET['q'])) {
$search = $_GET['q'];
$sAnk = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `nick` = '" . mysql_real_escape_string($search) . "' OR `id` = '" . (int) $search . "' LIMIT 1"));
if (isset($sAnk['id'])) {
$querySearch[] = "`id_user` = '$sAnk[id]' AND `id_kont` = '$user[id]'";
$querySearch[] = "`id_kont` = '$sAnk[id]' AND `id_kont` = '$sAnk[id]'";
}
$querySearch[] = "`id_user` like '%" . mysql_real_escape_string($search) . "%' AND `id_kont` = '$user[id]'";
$querySearch[] = "`id_kont` like '%" . mysql_real_escape_string($search) . "%' AND `id_user` = '$user[id]'";
$querySearch = ' AND (' . implode(' OR ', $querySearch) . ')';
} else {
$search = null;
$querySearch = null;
}
$set['title'] = ($flagged != 'inbox' ? $listFlagged[$flagged] . '/' : '') . 'Почта/' . $user['nick'];
require_once H . 'sys/inc/thead.php';
aut();
err();
echo "<link rel='stylesheet' href='/style/css/email.css' type='text/css' />";
echo "<ol class='breadcrumb'>";
echo "<li><a href='/'><span class='fa fa-home'></span></a></li>";
echo "<li><a href='/info.php?id=$user[id]'>$user[nick]</a></li>";
if ($search != null) {
echo "<li><a href='/user/mail/'>Почта</a></li>";
if ($flagged != 'inbox') {
echo "<li><a href='?s=$flagged'>$listFlagged[$flagged]</a></li>";
}
echo "<li class='active'>Поиск</li>";
} elseif ($flagged == 'inbox') {
echo "<li class='active'>Почта</li>";
} else {
echo "<li><a href='/user/mail/'>Почта</a></li>";
echo "<li class='active'>$listFlagged[$flagged]</li>";
}
echo "</ol>";
$arrContacts = mysql_query("SELECT e.id_user, IF(e.id_user = '$user[id]', e.id_kont, e.id_user) AS nick, SUM(IF (e.read = '0' AND e.id_kont = '$user[id]', 1, 0)) AS count_new, SUM(IF (e.read = '0' AND e.id_user = '$user[id]', 1, 0)) AS count_read, SUM(IF (e.id_kont = '$user[id]', 1, 0)) AS count_to, SUM(IF (e.id_user = '$user[id]', 1, 0)) AS count_from FROM mail AS e WHERE (e.id_kont = '$user[id]' OR e.id_user = '$user[id]') AND (" . implode(' OR ', $listSort) . ") AND `deleted` != '$user[id]' AND `deleted` != '-1' $querySearch GROUP BY IF(e.id_user = '$user[id]', e.id_kont, e.id_user)");
$countArray = array();
while ($count = mysql_fetch_assoc($arrContacts)) {
$countArray[strtolower($count['nick'])] = $count;
}
$k_post = count($countArray);
if ($k_post > 0 || $querySearch != null) {
echo "<div class='list-group-item'>";
echo "<form action='?' method='GET'>";
echo "<input type='hidden' name='s' value='$flagged' />";
echo "<div class='col-lg-7'><div class='input-group'>";
echo "<input type='search' name='q' class='form-control' placeholder='Поиск контакта' value='" . stripcslashes(htmlspecialchars($search)) . "'/> ";
echo "<span class='input-group-btn'>";
echo "<button type='submit' class='btn btn-primary'> <span class='fa fa-search'></span></button>";
echo "</span>";
echo "</div></div>";
echo "</form><br /><br />";
echo "</div>";
}
echo "<div class='list-group-item'>";
echo "<a href='messageList.php'><span class='fa fa-envelope fa-fw'></span> Новое сообщение</a>";
echo "</div>";
if ($k_post > 0) {
echo "<div class='list-group-item'>";
echo "<label class='c-input c-checkbox'><input id='select_all' type='checkbox'><span class='c-indicator'></span> Отметить все</label>";
echo "</div>";
}
if ($k_post == 0) {
echo "<div class='list-group-item'><span class='fa fa-info-circle fa-fw'></span> Список контактов пуст</div>";
} else {
$k_page = k_page($k_post, $set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page - $set['p_str'];
$q = mysql_query("SELECT *, IF(`id_user` = '$user[id]', `id_kont`, `id_user`) AS contact FROM `mail` AS e , (SELECT MAX(id) AS id FROM `mail` WHERE `deleted` != '$user[id]' AND `deleted` != '-1' AND (" . implode(' OR ', $listSort) . ") AND (`id_kont` = '$user[id]' OR `id_user` = '$user[id]') GROUP BY IF(`id_user` = '$user[id]', `id_kont`, `id_user`))t WHERE e.id = t.id AND (`id_kont` = '$user[id]' OR `id_user` = '$user[id]') AND (" . implode(' OR ', $listSort) . ") AND `deleted` != '$user[id]' AND `deleted` != '-1' $querySearch GROUP BY IF(`id_user` = '$user[id]', `id_kont`, `id_user`) ORDER BY e.id DESC LIMIT $start, $set[p_str]");
echo "<form class='list-group-item' action='?s=$flagged' method='POST'>";
while ($post = mysql_fetch_assoc($q)) {
$EmailUser = new EmailUser($post['contact']);
$ank = $EmailUser->getUser();
echo "<ul class='media-list media-list-conversation " . ($post['read'] == 0 && $post['id_user'] != $user['id'] ? 'dialogs_new_msg' : 'dialogs') . "' style='border-bottom: 1px solid #dcdee3;padding:3px;'>";
echo "<a href='messageList.php?s=$flagged&contact=" . urlencode($post['contact']) . "'>";
echo "<li class='media'>";
echo "<span class='media-left'>";
echo $ank['avatar'];
echo "</span>";
echo "<div class='media-body'><div class='media-body-text'>";
echo "<span data-toggle='tooltip' data-placement='right' title='" . date::time($post['time']) . "' style='color:grey;float:right;'><small>" . date::timek($post['time']) . "</small></span>";
?>
<input class="check_box" type="checkbox" name="cnt<?= $post['id'] ?>" value="<?= stripcslashes(htmlspecialchars($post['contact'])) ?>" >
<?php
echo "$ank[icon] " . gradient("$ank[nick]", "$ank[ncolor]", "$ank[ncolor2]") . " ";
if ($countArray[$post['contact']]['count_new'] == 0) {
$new = null;
} else {
$new = "+{$countArray[$post['contact']]['count_new']}";
}
echo "<span class='label label-default'>{$countArray[$post['contact']]['count_from']}/{$countArray[$post['contact']]['count_to']}</span> <span class='" . ($post['read'] == 0 && $post['id_user'] != $user['id'] ? 'label label-primary' : '') . "'>$new</span>";
echo "<div class='" . ($post['read'] == 0 && $post['id_kont'] != $user['id'] ? 'dialogs_new_msg' : 'dialogs') . "'>";
echo "" . ($post['attachments'] == 1 ? '<span class="fa fa-paperclip fa-fw"></span>' : '') . " " . toOutput($post['msg']);
echo "</div>";
echo "</div></div>";
echo "</li></a>";
echo "</ul>";
}
if ($flagged != 'deleted') {
echo "<br />";
if ($flagged != 'spam') {
echo "<button class='btn btn-success' type='submit' name='action' value='spam'>спам</button> ";
}
if ($flagged != 'archive') {
echo "<button class='btn btn-success' type='submit' name='action' value='archive'>архив</button> ";
} else {
echo "<button class='btn btn-success' type='submit' name='action' value='inbox'>из архива</button> ";
}
}
if ($flagged == 'deleted') {
echo "<button class='btn btn-success' type='submit' name='action' value='inbox'>восстановить</button> ";
echo "<button class='btn btn-success' type='submit' name='action' value='truncate'>очистить корзину</button> ";
} else {
echo "<button class='btn btn-success' type='submit' name='action' value='deleted'>удалить</button>";
}
echo "</form>";
if ($k_page > 1) {
str('?s=' . $flagged . '&', $k_page, $page);
}
}
$listInbox = mysql_fetch_assoc(mysql_query("SELECT SUM(IF(IF (e.id_kont = '$user[id]', flaggedTo, flaggedFrom) = 'favorite', 1, 0)) AS favorite, SUM(IF(IF (e.id_kont = '$user[id]', flaggedTo, flaggedFrom) = 'archive', 1, 0)) AS archive, SUM(IF(IF (e.id_kont = '$user[id]', flaggedTo, flaggedFrom) = 'spam', 1, 0)) AS spam, SUM(IF(IF (e.id_kont = '$user[id]', flaggedTo, flaggedFrom) = 'deleted', 1, 0)) AS deleted FROM `mail` AS e WHERE (e.id_kont = '$user[id]' OR e.id_user = '$user[id]') AND `deleted` != '$user[id]' AND `deleted` != '-1' LIMIT 1"));
if ($flagged == 'inbox' && $search == null) {
foreach ($listInbox AS $key => $value) {
if ($key == 'favorite') {
$img = 'fa fa-star';
} elseif ($key == 'archive') {
$img = 'fa fa-archive';
} elseif ($key == 'spam') {
$img = 'fa fa-ban';
} elseif ($key == 'deleted') {
$img = 'fa fa-trash';
}
echo "<div class='list-group-item'>";
echo "<a href='?s=$key'><span class='$img fa-fw'></span> $listFlagged[$key]</a> <span class='label label-default'>" . ($value ? $value : 0) . "</span><br />";
echo "</div>";
}
echo "<div class='list-group-item'>";
echo "<a href='settings.php'><span class='fa fa-gear fa-fw'></span> Настройки почты</a>";
echo "</div>";
} else {
echo "<div class='list-group-item'>";
echo "<a href='?'><span class='fa fa-arrow-left'></span> Назад</a>";
echo "</div>";
}
if ($flagged == 'deleted' && isset($set['mail_clear_time'])) {
$setnamed = array(
'86400' => '1 дня',
'604800' => '1 недели',
'2419200' => '1 месяца',
'7257600' => '3 месяцев',
'14515200' => '6 месяцев',
'29030400' => '1 года',
);
?>
<div class="list-group-item">
Внимание. Контакты хранятся в корзине не более <?= $setnamed[$set['mail_clear_time']] ?>. После этого они полностью удаляются.
</div>
<?php
}
?>
<script>
$(document).ready(function () {
var select_all = 0;
$('#select_all').click(function () {
if (select_all == 0) {
$('.check_box').prop('checked', true);
select_all = 1;
} else {
$('.check_box').prop('checked', false);
select_all = 0;
}
});
$('.js_not').css({'display': 'inline-block'});
});
</script>
<?php
require_once H . 'sys/inc/tfoot.php';