Файл: monst/core/jphp/chat/add_mess.php
Строк: 17
<?
$HOME = $_SERVER['DOCUMENT_ROOT'];
include $HOME . '/core/in/j.php';
if ( $user['level'] < 5 ) {
exit;
}
if ( !empty($_POST['mess']) AND !empty($_POST['room']) AND $user ) {
$mess = null_html($_POST['mess']);
$p = (int)$_POST['p'];
if ( $p != 1) {
$p = 0;
}
// include 'rooms.php';
$room = 1;
// if ( isset($_SESSION['chat_room']) AND isset($ROOMS[(int)$_SESSION['chat_room']]) ) {
// $room = $_SESSION['chat_room'];
// }
$to_id = 0;
if ( isset($_POST['to_id']) ) {
$to_id = (int)$_POST['to_id'];
}
$find = $_chat -> find(
[
'user_id' => $user['id'],
'to_id' => $to_id,
'room' => $room
]
);
$find -> sort(
[
'id' => -1
]
);
$find -> limit(1);
$last_mess = '';
foreach ( $find as $f ) {
$last_mess = $f['mess'];
break;
}
if ( $mess == $last_mess ) {
$mess = '';
}
if ( $mess ) {
$id = new_id('_chat');
$_chat -> insert(
[
'id' => $id,
'user_id' => $user['id'],
'to_id' => $to_id,
'room' => $room,
'p' => $p,
'mess' => $mess,
'time' => time()
]
);
$_users -> update(
[
'id' => $user['id']
],
[
'$set' => [
'chat_count' => $user['chat_count'] + 1
]
]
);
echo 'ok';
}
}