Файл: modules/mail/chat.php
Строк: 89
<?php
/**
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) 2013, Taras Chornyi, Sergiy Mazurenko, Ivan Kotliar
* @link http://perf-engine.net
* @package PerfEngine
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
$locate = 'in_cabinet';
if(!isset($_GET['id']) || $_GET['id'] == User::Id() || $_GET['id'] == 0 || !User::logged())
{
redirect('/');
}
elseif ($db->query("SELECT * FROM `mail_chat` WHERE (`user_id` = '". User::Id() ."' OR `who_id` = '". User::Id() ."') AND (`who_id` = '". num($_GET['id']) ."' OR `user_id` = '". num($_GET['id']) ."')")->rowCount() == 0)
{
$db->query("INSERT INTO `mail_chat` SET `user_id` = '". User::Id() ."', `who_id` = '". num($_GET['id']) ."', `time_last_message` = '". time() ."'");
redirect('/mail/chat/'.num($_GET['id']).'?rand='.rand(1, 9999));
}
$id = num($_GET['id']);
if($db->query("SELECT * FROM `mail_chat` WHERE `user_id` = '". User::Id()."' AND `who_id` = '". $id ."'")->rowCount() != 0)
{
$chat_id = $db->query("SELECT id FROM `mail_chat` WHERE `user_id` = '". User::Id() ."' AND `who_id` = '". $id ."'")->fetchColumn();
}
else
{
$chat_id = $db->query("SELECT `id` FROM `mail_chat` WHERE `who_id` = '". User::Id() ."' AND `user_id` = '". $id ."'")->fetchColumn();
}
if(isset($_POST['send']) && $_GET['act'] == 'send')
{
$message = input($_POST['text']);
if(!empty($message))
{
$text = mb_substr($message, 0, 5000);
}
else
{
$err = 'Message is empty';
}
if(!isset($err) && antiflood('mail', 'text', $text) == false)
{
$db->query("INSERT INTO `mail` SET `mail_chat_id` = '$chat_id', `user_id` = '$user[id]', `who_id` = '". abs(intval($_GET['id'])) ."', `text` = '". $text ."', `time` = '". time() ."', `read`='0'");
// print_r($db->errorInfo());
$db->query("UPDATE `mail_chat` SET `time_last_message` = '". time() ."' WHERE `id` = '$chat_id'");
// print_r($db->errorInfo());
header('Location: /mail/chat/'.abs(intval($_GET['id'])).'?act=added');
exit;
}
}
$title = _t('chat_with_user').' '.tnick($id);
include_header($title);
$tpl->div('title', $title);
if(isset($_GET['act']) && $_GET['act'] == 'added')
{
$tpl->div('block', _t('mess_added'));
}
echo '<a name="reply"></a>';
$black_list_us = $db->query("SELECT * FROM `black_list` WHERE `user_id` = '".$user['id']."' AND `block_id` = '". abs(intval($_GET['id'])) ."'")->rowCount();
$black_list_id = $db->query("SELECT * FROM `black_list` WHERE `user_id` = '".abs(intval($_GET['id']))."' AND `block_id` = '". $user['id'] ."'")->rowCount();
if ($black_list_us == 0 && $black_list_id == 0)
{
$tpl->div('menu', '<b>'._t('reply') .'</b>:<br/>
<form action="/mail/chat/'.abs(intval($_GET['id'])).'?act=send" method="post">
<textarea name="text" rows="5" cols="26"></textarea><br/>
<input name="send" type="submit" value="'. _t('send').'"/> [<a href="/mail/chat/'.abs(intval($_GET['id'])).'?'.rand(1, 9999).'">'._t('refresh').'</a>]
</form>');
}
elseif($black_list_us != 0)
{
$tpl->div('menu', _t('user_black_list'));
}
elseif($black_list_id != 0)
{
$tpl->div('menu', _t('stop_black_list'));
}
$chat_r = $db->query("SELECT * FROM `mail` WHERE `mail_chat_id` = '$chat_id' AND `del` != '".$user['id']."'")->rowCount();
$pages = new Paginator($chat_r, $ames);
if($chat_r == 0)
{
$tpl->div('menu', _t('no_posts'));
}
else
{
$chat_q = $db->query("SELECT * FROM `mail` WHERE `mail_chat_id` = '$chat_id' AND `del` != '".$user['id']."' ORDER BY time DESC LIMIT $start, $ames");
while($chat = $chat_q->fetch())
{
if ($user['id'] == $chat['who_id']) $db->query("UPDATE `mail` SET `read` = '1' WHERE `id` = '$chat[id]'");
echo '<div class=" '.($chat['read'] == 0 ? 'list': 'post').'">
'. nick($chat['user_id'], '<a href="/mail/delete_post/'.$chat['id'].'/">'.rtime($chat['time']) .'</a>') .'
'. output($chat['text']) .'
</div>';
}
$pages->view();
}
$tpl->div('menu', ($db->query("SELECT * FROM `mail` WHERE `mail_chat_id` = '".$chat_id."' AND `del` != '".$user['id']."'")->rowCount() > 0 ? img('delete.png') .'<a href="/mail/delete_history/'.$chat_id.'/">'._t('delete_history').'</a><br /> ' : NULL).''.($black_list_us == 0 ? img('block.png') .'<a href="/black_list/block/'.abs(intval($_GET['id'])).'/">'._t('block').'</a>' : img('unblock.png') .'<a href="/black_list/unblock/'.abs(intval($_GET['id'])).'/">'._t('unblock').'</a>'));
$tpl->div('block', img('mail.png') .'<a href="/mail/">'._t('u_mail').'</a><br/>'
. NAV .'<a href="/user/panel/">'._t('user_panel').'</a><br/>'
. HICO .'<a href="/">'. _t('home').'</a>');
include_footer();
?>