Файл: mail_diolog.php
Строк: 134
<?php
require_once ('system/func.php');
auth(); // Закроем от не авторизованных
# Настройки #
$id = num($_GET['id']);
$prof = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".$id."'"));
# Ошибки #
if(!$prof){
$prof['id'] = 0;
$prof['login'] = 'Система';
$prof['access'] = 2;
}
if(isset($_GET['text']) and $prof['id'] != 0){
if(isset($_POST['text'])){
$text = text($_POST['text']);
$ban = mysql_query('SELECT * FROM `ban` WHERE `id_user` = "'.$myID.'" AND `last` > "'.time().'" ORDER BY `id` DESC LIMIT 1');
$ban = mysql_fetch_array($ban);
if(strlen($text) < 3 or strlen($text) > 1000)$err = 'Длина сообщения должна быть в пределах 3 - 1000 символов';
if($ban)$err = "На вас наложен, бан осталось ".tl($ban[last]-time());
$ban_ip = mysql_query('SELECT * FROM `ban` WHERE `ip` = "'.$user['ip'].'" AND `last` > "'.time().'" ORDER BY `id` DESC LIMIT 1');
$ban_ip = mysql_fetch_array($ban_ip);
if($ban_ip)$err = "Ваш IP совпадает с нарушителем!<br>Осталось: ".tl($ban_ip['last']-time());
if(!$err){
mysql_query("INSERT INTO `mail` SET `in` = '$myID', `out` = '".$prof['id']."', `text` = '$text' , `time` = '".time()."'");
$kont = mysql_fetch_assoc(mysql_query("SELECT * FROM `kont` WHERE `id_user` = '".$myID."' && `id_kont` = '".$prof['id']."' LIMIT 1"));
if($kont['id_kont'] != $prof['id']){
mysql_query("INSERT INTO `kont` SET `id_user` = '".$prof['id']."', `id_kont` = '".$myID."', `time` = '".time()."'");
mysql_query("INSERT INTO `kont` SET `id_user` = '$myID', `id_kont` = '".$prof['id']."', `time` = '".time()."'");
}else{
mysql_query("update `kont` set `time` = '".time()."' WHERE `id_user` = '".$myID."' && `id_kont` = '".$prof['id']."'");
mysql_query("update `kont` set `time` = '".time()."' WHERE `id_user` = '".$prof['id']."' && `id_kont` = '".$myID."'");
}
header("Location: /mail/$prof[id]");
exit();
}else{
$_SESSION['msg'] = $err;
header("Location: /mail/$prof[id]");
exit();
}
}else{
$_SESSION['msg'] == 'Введите сообщение';
header("Location: /mail/$prof[id]");
exit();
}
}
$title = 'Диалог с '.$prof['login'];
require_once ('system/header.php');
if($prof['id'] != 0){
echo "<div class='block center'>";
if($user['level'] < 10){
echo "В почте можно писать только с ".ico('icons','level.png')." 10 уровня";
}else{
require_once ('modules/smiles_ajax.php');
if(isset($_GET['to'])){
echo "<form method='post' action='' id='ajax_form'>";
$opponent = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".num($_GET['to'])."' LIMIT 1"));
echo "<input type='text' name='text' id='sml' value = '".text($opponent['login']).", '>";
?> <input class="btn" type="button" onClick="mode('ajax_form');" value="Отправить"> <?
echo "<a href='/chat' class='btn'>Обновить</a></form>";
}else{
echo "<form method='post' action='' id='ajax_form'>";
echo "<textarea id='sml' name='text'></textarea>";
?> <input class="btn" type="button" onClick="mode('ajax_form');" value="Отправить"> <?
echo "<a href='' class='btn'>Обновить</a>
</form>";
}
}
echo "</form>";
echo "<div id='indicator'></div><div id='display'></div>";
echo "</div>";
?>
<script type="text/javascript">
function mode(ajax_form)
{
$('#indicator').addClass('ajax_load'); // Подключаем класс
$.ajax({
url: '/include/mail_form_ajax.php?id=<?=$prof['id']?>', // Название файла обработчика
type: 'POST',
data: jQuery('#ajax_form').serialize(),
success: function(data)
{
$('#indicator').removeClass('ajax_load'); // Отключаем класс
$('#display').html(data);
}
});
}
</script>
<script type='text/javascript'>
/*<![CDATA[*/
function sml(id, html) {
var e = document.getElementById(id);
if (e != null) {
e.value += ' ' + html + ' ';
e.focus();
}
}
/*]]>*/
</script>
<?
}
$set['p_str'] = 10;
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE (`in` = '$prof[id]' && `out` = '$user[id]') or (`in` = '$user[id]' && `out` = '".num($_GET['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 id='content'>";
$q = mysql_query("SELECT * FROM `mail` WHERE (`in` = '$prof[id]' && `out` = '$user[id]') or (`in` = '$user[id]' && `out` = '$prof[id]') ORDER BY `id` DESC LIMIT $start, $set[p_str]");
if($k_post == 0) echo "<div class='block'>Сообщений не найдено...</div>";
mysql_query("update `mail` set `online` = '0' WHERE `in` = '".$prof['id']."' && `out` = '".$myID."'");
mysql_query("UPDATE `kont` SET `new_msg` = '0' WHERE `id_kont` = '$ank[id]' AND `id_user` = '$myID' LIMIT 1");
while($post = mysql_fetch_assoc($q)) {
echo "<div class='block'>";
if($post['online'] == 1)$color = 'green';
else $color = '#A8A8A8';
$ank = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = $post[in] LIMIT 1"));
if($ank['id'] == 0){
$ank['id'] = 0;
$ank['login'] = '<span class="grey">Система</span>';
$ank['access'] = 2;
}
if($ank['id'] != 0)echo icons_user($ank[id])." <a href='/profile/$ank[id]'>$ank[login]</a>, <font color='$color'>".vremja($post['time'])."</font><br>".text_msg($post['text'])."";
else echo "$ank[login], <font color='$color'>".vremja($post['time'])."</font><br>".text_msg($post['text'])."";
echo '</div>';
}
echo '</div>';
?>
<script>
function show()
{
$.ajax({
url: "/include/mail_diolog_ajax.php?id=<?=$prof['id']?>&page=<?=$page?>",
cache: false,
success: function(html){
$("#content").html(html);
}
});
}
$(document).ready(function(){
show();
setInterval('show()',1000);
});
</script>
<?
echo "<div class='block'>";
str('?',$k_page,$page); // Вывод страниц
echo "</div>";
echo "<a href='/mail/' class='link'>".ico('icons','arrow.png')." Все контакты ";
if($new_msg >= 1)echo "<font color='green'>(+)</font>";
echo "</a>";
require_once ('system/footer.php');
?>