Просмотр файла modules/mail/chat.php

Размер файла: 3.65Kb
<?php
/**********************************
*	@package: PerfCMS			  *
*	@year: 2012					  *
*	@author: Artas				  *
*	@link: http://perfcms.ru	  *
**********************************/
if(isset($user) && $_GET['user_id'] != $user['id']) { 
$locate = 'in_cabinet'; 

if ($db->query("SELECT * FROM `mail_chat` WHERE `user_id` = '$user[id]' AND `who_id` = '". abs(intval($_GET['user_id'])) ."'")->rowCount() != 0) $chat_id = $db->query("SELECT id FROM `mail_chat` WHERE `user_id` = '$user[id]' AND `who_id` = '". abs(intval($_GET['user_id'])) ."'")->fetchColumn(); 
else $chat_id = $db->query("SELECT `id` FROM `mail_chat` WHERE `who_id` = '$user[id]' AND `user_id` = '". abs(intval($_GET['user_id'])) ."'")->fetchColumn(); 
if ($db->query("SELECT * FROM `mail_chat` WHERE (`user_id` = '$user[id]' OR `who_id` = '$user[id]') AND (`who_id` = '". abs(intval($_GET['user_id'])) ."' OR `user_id` = '". abs(intval($_GET['user_id'])) ."')")->rowCount() == 0) { 

$db->query("INSERT INTO `mail_chat` SET `user_id` = '$user[id]', `who_id` = '". abs(intval($_GET['user_id'])) ."', `time_last_message` = '". time() ."'"); 
// print_r($db->errorInfo()); 
} 
if(isset($_POST['send']) && $_GET['act'] == 'send') { 

$message = input($_POST['text']); 
if(!empty($message)) { $text = substr($message, 0, 5000); } else { $err = 'Message is empty'; } 
if(!isset($err)) { 
$db->query("INSERT INTO `mail` SET `mail_chat_id` = '$chat_id', `user_id` = '$user[id]', `who_id` = '". abs(intval($_GET['user_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['user_id'])).'/?act=added'); 
} 
} 
$title = $lang->word('chat_with_user').' '.tnick($_GET['user_id']); 
require_once(SYS.'/view/header.php'); 
$tpl->div('title', $lang->word('chat_with_user').' '.tnick($_GET['user_id'])); 
if(isset($_GET['act']) && $_GET['act'] == 'added') { 
$tpl->div('block', $lang->word('mess_added')); 
} 
$tpl->div('menu', NAV .'<a href="/mail/chat/'.abs(intval($_GET['user_id'])).'/?">'.$lang->word('refresh').'</a>'); 
$chat_r = $db->query("SELECT * FROM `mail` WHERE `mail_chat_id` = '$chat_id'")->rowCount(); 
$pages = new Paginator($chat_r, $ames); 
if($chat_r == 0) { 
$tpl->div('menu', $lang->word('no_posts')); 
} else { 
$chat_q = $db->query("SELECT * FROM `mail` WHERE `mail_chat_id` = '$chat_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="post"> 
        '.($chat['read'] == 0 ? '<span style="color:red;">*</span> ': NULL).'
		'. nick($chat['user_id']) .' ('. rtime($chat['time']) .')<br/> 
        '. output($chat['text']) .' 
    </div>'; 
} 
$pages->view('/mail/chat/'.$_GET['user_id'].'/?'); 
} 
echo '<a name="reply"></a>'; 
$tpl->div('menu', '<b>'.$lang->word('reply') .'</b>:<br/> 
                    <form action="/mail/chat/'.abs(intval($_GET['user_id'])).'/?act=send" method="post"> 
                    <textarea name="text" rows="5" cols="26"></textarea><br/> 
                    <input name="send" type="submit" value="'. $lang->word('send').'"/> 
                    </form>'); 
$tpl->div('block',     img('mail.png') .'<a href="/mail/">'.$lang->word('u_mail').'</a><br/>' 
                    . NAV .'<a href="/user/panel/">'.$lang->word('user_panel').'</a><br/>' 
                    . HICO .'<a href="/">'. $lang->word('home').'</a>'); 
require_once(SYS.'/view/footer.php'); 
} else { go('/'); }
?>