Файл: mail.php
Строк: 159
<?php
/* Мод "Почта"
* Версия v0.0.1
* Дата последнего редактирования 25.11.2014
* Двиг DCMS Special
* Модифицировал densnet
* Файл mail.php
* Описание: выводит переписку пользователя
*/
require_once 'sys/inc/start.php';
require_once 'sys/inc/compress.php';
require_once 'sys/inc/sess.php';
require_once 'sys/inc/settings.php';
require_once 'sys/inc/db_connect.php';
require_once 'sys/inc/ipua.php';
require_once 'sys/inc/fnc.php';
require_once 'sys/inc/user.php';
user::only_reg();
if ((!isset($_SESSION['refer']) || $_SESSION['refer'] == NULL) && isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != NULL &&
!preg_match('#mail.php#', $_SERVER['HTTP_REFERER'])) {
$_SESSION['refer'] = str_replace('&', '&', preg_replace('#^http://[^/]*/#i', '/', $_SERVER['HTTP_REFERER']));
}
if (!isset($_GET['id'])) {
header("Location: /user/konts.php?" . SID);
exit;
}
$ank = user::get_user($_GET['id']);
if (!$ank) {
header("Location: /user/konts.php?" . SID);
exit;
}
$set['title'] = 'Почта: ' . $ank['nick'];
require_once 'sys/inc/thead.php';
// добавляем в контакты
if ($user['add_konts'] == 2 && mysql_result(mysql_query("SELECT COUNT(*) FROM `users_konts` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]'"), 0) == 0) {
mysql_query("INSERT INTO `users_konts` (`id_user`, `id_kont`, `time`) VALUES ('$user[id]', '$ank[id]', '$time')");
}
// обновление сведений о контакте
mysql_query("UPDATE `users_konts` SET `new_msg` = '0' WHERE `id_kont` = '$ank[id]' AND `id_user` = '$user[id]' LIMIT 1");
// помечаем сообщения как прочитанные
mysql_query("UPDATE `mail` SET `read` = '1' WHERE `id_kont` = '$user[id]' AND `id_user` = '$ank[id]'");
if (isset($_POST['msg']) && $ank['id'] != 0) {
$msg = $_POST['msg'];
#if (text::utf8_strlen($msg)>10024)$err[]='Сообщение превышает 10024 символа';
if (text::utf8_strlen($msg) < 2) {
$err[] = 'Слишком короткое сообщение';
}
$mat = text::antimat($msg);
if ($mat) {
$err[] = 'В тексте сообщения обнаружен мат: ' . $mat;
}
if (!isset($err) && mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]' AND `time` > '" . ($time - 360) . "' AND `msg` = '" . mysql_real_escape_string($msg) . "'"), 0) == 0) {
#отправка сообщения
mysql_query("INSERT INTO `mail` (`id_user`, `id_kont`, `msg`, `time`) values('$user[id]', '$ank[id]', '" . mysql_real_escape_string($msg) . "', '$time')");
#добавляем в контакты
if ($user['add_konts'] == 1 && mysql_result(mysql_query("SELECT COUNT(*) FROM `users_konts` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]'"), 0) == 0) {
mysql_query("INSERT INTO `users_konts` (`id_user`, `id_kont`, `time`) VALUES ('$user[id]', '$ank[id]', '$time')");
}
#обновление сведений о контакте
mysql_query("UPDATE `users_konts` SET `time` = '$time' WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]' OR `id_user` = '$ank[id]' AND `id_kont` = '$user[id]'");
msg('Сообщение успешно отправлено');
header("Refresh: 1; url=/mail.php?id=$ank[id]&$passgen");
echo "<div class = 'razd'>";
echo "<a href = '/mail.php?id=$ank[id]&$passgen'>Вернуться</a><br />n";
echo "<a href = '/user/konts.php'>Контакты</a><br />n";
echo "<a href = '/umenu.php'>Кабинет</a><br />n";
echo "</div>n";
require_once 'sys/inc/tfoot.php';
}
}
title();
aut();
err();
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]' OR `id_user` = '$ank[id]' AND `id_kont` = '$user[id]'"), 0);
$k_page = k_page($k_post, $set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page - $set['p_str'];
echo "<div class = 'razd'>Переписка</div>";
if ($k_post == 0) {
echo "<div class = 'errs'>";
echo img16('error.png') . " Нет результатов";
echo "</div>";
}
$q = mysql_query("SELECT * FROM `mail` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]' OR `id_user` = '$ank[id]' AND `id_kont` = '$user[id]' ORDER BY id DESC LIMIT $start, $set[p_str]");
while ($post = mysql_fetch_array($q)) {
$ank2 = user::get_user($post['id_user']);
if ($post['read'] == 0) {
echo "<table class = 'mail_hidden'><tr><td class = 'icon14'>";
} else {
echo "<table class = 'mail'><tr><td class = 'icon14'>";
}
avatar($ank2['id'], '25');
echo "</td><td class='null'>";
echo "<div style = 'float:right;'>" . date::time($post['time']) . "</div>";
if ($ank2) {
echo "<a href = '/info.php?id=$ank2[id]'><b>";
echo text::gradient("$ank2[nick]", "$ank2[ncolor]", "$ank2[ncolor2]");
echo "</b></a><br />";
} else {
echo "[DELETED] (+$kont[count])n";
}
echo text::toOutput($post['msg']) . "n";
echo "</td></tr></table>n";
}
if ($k_page > 1) {
str("mail.php?id=$ank[id]&", $k_page, $page);
}
if ($ank['id'] != 0) {
echo "<form method = 'post' name = 'message' action = '/mail.php?id=$ank[id]&$passgen'>n";
echo "<table class = 'razd'><tr><td class = 'icon14'>";
avatar($user['id'], '40');
echo "</td><td class = 'null'>";
echo "<textarea aria-required = 'true' aria-invalid = 'false' required = 'required' name="msg" rows='2' style='width:70%'></textarea><br />n";
echo "<button class = 'button sign-ins'>Отправить</button>";
echo "</td></tr></table></form>";
}
echo "<div class='razd'>";
if ($ank['id'] != 0) {
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `users_konts` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]'"), 0) == 1) {
$kont = mysql_fetch_array(mysql_query("SELECT * FROM `users_konts` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]'"));
echo "<a class = 'add' href = '/user/konts.php?type=$kont[type]&act=del&id=$ank[id]'>" . img16('minus.png') . " Удалить контакт</a>";
} else {
echo "<a class = 'add' href = '/user/konts.php?type=common&act=add&id=$ank[id]'>" . img16('plus.png') . " Добавить контакт</a>";
}
}
echo "<br /><br /><a class = 'add' href = '/user/konts.php?" . (isset($kont) ? 'type=' . $kont['type'] : null) . "'>" . img16('kont.png') . " Контакты</a><br />n";
echo "</div>n";
echo "<div class = 'razd'>";
if (isset($_SESSION['refer']) && $_SESSION['refer'] != NULL && otkuda($_SESSION['refer'])) {
echo "<a class = 'add' href = '$_SESSION[refer]'>" . img16('left.png') . " " . otkuda($_SESSION['refer']) . "</a><br /><br />";
}
echo "<a class = 'add' href = '/umenu.php'>" . img16('left.png') . " Кабинет</a>";
echo "</div>n";
require_once 'sys/inc/tfoot.php';