Файл: ajax/messages/chat/session.php
Строк: 62
<?php
/**
* chat session
*
* @package Sngine
* @author Zamblek
*/
// fetch kernal
$depth = '../../../';
require($depth.'kernal.php');
// check AJAX Request
if(!IsAJAX()) {
header('Location: '.SITE_URL);
}
if(!empty($_SESSION['openChatBoxes'])) {
foreach($_SESSION['openChatBoxes'] as $to => $conversationId) {
$conversation['ConversationID'] = $conversationId;
// get sender
$getSender = $db->query(sprintf("SELECT user.UserFirstName, user.UserLastName FROM messages_conversations_users conv INNER JOIN users user ON conv.UserID = user.UserID WHERE conv.ConversationID = %s AND conv.UserID != %s", SafeSQL($conversationId, 'int'), SafeSQL($userArray['UserID'], 'int') )) or die(ReportError('sql error #1 @/ajax/messages/chat/session'));
$sender = $getSender->fetch_array(MYSQLI_ASSOC);
$conversation['sender'] = $to;
$conversation['title'] = $sender['UserFirstName']." ".$sender['UserLastName'];
// get messages
$getMessages = $db->query(sprintf("SELECT msg.*, user.UserName, user.UserAvatarPathSmall FROM messages msg INNER JOIN users user ON msg.UserID = user.UserID WHERE msg.ConversationID = %s ORDER BY msg.Time ASC", SafeSQL($conversationId, 'int'))) or die(ReportError('sql error #2 @/ajax/messages/chat/session'));
$messages = array();
while($message = $getMessages->fetch_array(MYSQLI_ASSOC)) {
// decode text
$message['Text'] = DecodeText($message['Text']);
$messages[] = $message;
}
$smarty->assign('messages', $messages);
$conversation['messages'] = $smarty->fetch("ajax.chat.messages.tpl");
$conversations[] = $conversation;
}
exit(json_encode($conversations));
}
if(!isset($_SESSION['openChatBoxes'])) {
$_SESSION['openChatBoxes'] = array();
}
?>