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

Размер файла: 3.56Kb
  1. <?php
  2. /**********************************
  3. * @package: PerfCMS *
  4. * @year: 2012 *
  5. * @author: Artas *
  6. * @link: http://perfcms.ru *
  7. **********************************/
  8. if(isset($user) && $_GET['user_id'] != $user['id']) {
  9. $locate = 'in_cabinet';
  10.  
  11. 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();
  12. else $chat_id = $db->query("SELECT `id` FROM `mail_chat` WHERE `who_id` = '$user[id]' AND `user_id` = '". abs(intval($_GET['user_id'])) ."'")->fetchColumn();
  13. 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) {
  14.  
  15. $db->query("INSERT INTO `mail_chat` SET `user_id` = '$user[id]', `who_id` = '". abs(intval($_GET['user_id'])) ."', `time_last_message` = '". time() ."'");
  16. // print_r($db->errorInfo());
  17. }
  18.  
  19. $title = $lang->word('chat_with_user').' '.tnick($_GET['user_id']);
  20. require_once(SYS.'/view/header.php');
  21. $tpl->div('title', $lang->word('chat_with_user').' '.tnick($_GET['user_id']));
  22. if(isset($_POST['send']) && $_GET['act'] == 'send') {
  23.  
  24. $message = input($_POST['text']);
  25. if(!empty($message)) { $text = substr($message, 0, 5000); } else { $err = 'Message is empty'; }
  26. if(!isset($err)) {
  27. $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'");
  28. // print_r($db->errorInfo());
  29. $db->query("UPDATE `mail_chat` SET `time_last_message` = '". time() ."' WHERE `id` = '$chat_id'");
  30. $tpl->div('menu', $lang->word('mess_added'));
  31. $tpl->div('block', img('nav.png') .'<a href="/mail/chat/'.abs(intval($_GET['user_id'])).'/">'. $lang->word('continue') .'</a><br/>'. img('admin.png') .'<a href="/mail/">'. $lang->word('u_mail') .'</a><br/>'. HICO .'<a href="/">'. $lang->word('home') .'</a>');
  32. require_once(SYS.'/view/footer.php');
  33. exit;
  34. }
  35. $tpl->div('menu', NAV .'<a href="/mail/chat/'.abs(intval($_GET['user_id'])).'/?">'.$lang->word('refresh').'</a>');
  36. $chat_r = $db->query("SELECT * FROM `mail` WHERE `mail_chat_id` = '$chat_id'")->rowCount();
  37. $pages = new Paginator($chat_r, $ames);
  38. if($chat_r == 0) {
  39. $tpl->div('menu', $lang->word('no_posts'));
  40. } else {
  41. $chat_q = $db->query("SELECT * FROM `mail` WHERE `mail_chat_id` = '$chat_id' ORDER BY time DESC LIMIT $start, $ames");
  42. while($chat = $chat_q->fetch()) {
  43. if ($user['id'] == $chat['who_id']) $db->query("UPDATE `mail` SET `read` = '1' WHERE `id` = '$chat[id]'");
  44. echo '<div class="post">
  45. '. nick($chat['user_id']) .' ('. rtime($chat['time']) .')<br/>
  46. '. output($chat['text']) .'
  47. </div>';
  48. }
  49. $pages->view('/mail/chat/'.$_GET['user_id'].'/?');
  50. }
  51. echo '<a name="reply"></a>';
  52. $tpl->div('menu', '<b>'.$lang->word('reply') .'</b>:<br/>
  53. <form action="/mail/chat/'.abs(intval($_GET['user_id'])).'/?act=send" method="post">
  54. <textarea name="text" rows="5" cols="26"></textarea><br/>
  55. <input name="send" type="submit" value="'. $lang->word('send').'"/>
  56. </form>');
  57. $tpl->div('block', img('mail.png') .'<a href="/mail/">'.$lang->word('u_mail').'</a><br/>'
  58. . NAV .'<a href="/user/panel/">'.$lang->word('user_panel').'</a><br/>'
  59. . HICO .'<a href="/">'. $lang->word('home').'</a>');
  60. require_once(SYS.'/view/footer.php');
  61. } else { go('/'); }
  62. ?>