<?php
define('NTLCMS', 1);
$module = 'newmes';
include ('../system/start.php');
include ('../system/function.php');
include ('../system/antidos.php');
include ('../system/head.php');
include ('../system/crypt.class.php');
if (!$active){
header('Location: '.URL);
$_SESSION['fail'] = 'Вы не авторизированы!';
exit;
}
if ($set['mails'] == '1' && $_USER['admin'] != '1'){
echo '<div class="title"><center>Личная почта</center></div>';
echo '<div class="post"><center><i class="fa fa-close fa-fw"></i> Модуль закрыт администратором!</center></div>';
echo '<div class="block"><i class="fa fa-home fa-fw"></i> <a href="'.URL.'/cabinet">В кабинет</a></div>';
include ('../system/foot.php'); exit;
}
$getlogin = isset($_GET['login']) ? filter_var($_GET['login'], FILTER_SANITIZE_STRING) : false;
$mess = DB :: run() -> query("select * from `users` where `login` = ?", array($getlogin)) -> fetch(PDO::FETCH_OBJ);
if (!isset($mess -> login) or $ulogin == $mess -> login){
header('Location: '.URL.'/messages');
$_SESSION['fail'] = 'Произошла ошибка!'; exit;
} else {
echo '<div class="title"><b>'.razd.' Сообщения | Новое сообщение '.$getlogin.'</b></div>';
if (DB :: run() -> querySingle("select count(`id`) from `contacts` where `kogo` = ? and `kto` = ? limit 1", array($mess -> login, $ulogin)) == 0){
DB :: run() -> query("insert into `contacts` (`kto`, `kogo`, `time`, `posl_time`) values (?, ?, ?, ?)", array($ilogin, $mess -> login, TIME, TIME));
DB :: run() -> query("insert into `contacts` (`kto`, `kogo`, `time`, `posl_time`) values (?, ?, ?, ?)", array($mess -> login, $ilogin, TIME, TIME));
}
if (isset($_REQUEST['ok'])){
$text = isset($_POST['text']) ? filter_var($crypt->xoft_encode($_POST['text'], $set['secure']), FILTER_SANITIZE_STRING) : false;
if (empty($text)){
$error.= 'Введите текст сообщения!<br/>';
} elseif (mb_strlen($text, 'UTF-8') < 1 or mb_strlen($text, 'UTF-8') > 2500){
$error.= 'Сообщение должно содержать от 1 до 2500 символов!<br/>';
} elseif (DB :: run() -> querySingle("select (`time`) from `message` where `kto` = ? and `time` > ?", array($ulogin, TIME - $set['antispam']))){
$error.= 'Антиспам! Лимит '.ints($set['antispam']).' секунд!<br/>';
}
if ($error){
echo '<div class="post"><center><i class="fa fa-close fa-fw"></i> '.$error.'</center></div>';
} else {
DB :: run() -> query("update `contacts` set `posl_time` = ? where `kogo` = ? and `kto` = ? limit 1", array(TIME, $ilogin, $mess -> login));
DB :: run() -> query("update `contacts` set `posl_time` = ? where `kto` = ? and `kogo` = ? limit 1", array(TIME, $ilogin, $mess -> login));
DB :: run() -> query("insert into `message` (`text`, `kto`, `komy`, `time`, `readlen`) values (?, ?, ?, ?, ?)", array($text, $ilogin, $mess -> login, TIME, 0));
header('Location: '.URL.'/dialog-'.$mess -> login); exit;
}
}
echo '<div class="menu"><form name="form" action="'.URL.'/newmes-'.checkout($mess -> login).'" method="post">';
echo fast_smile() . panel('text').'<textarea name="text" rows="3" cols="20"></textarea><br/>
<input type="submit" name="ok" value="Написать сообщение"/></form></div>';
}
echo '<div class="block"><i class="fa fa-home fa-fw"></i> <a href="'.URL.'/cabinet">В кабинет</a> | <a href="'.URL.'/messages">Личная почта</a></div>';
include ('../system/foot.php');
?>