2011-10-27 08:00:15 +00:00
|
|
|
<?
|
|
|
|
include(SERVER_ROOT.'/classes/class_text.php');
|
|
|
|
$Text = new TEXT;
|
|
|
|
|
|
|
|
$ConvID = $_GET['id'];
|
|
|
|
if(!$ConvID || !is_number($ConvID)) {
|
|
|
|
print json_encode(array('status' => 'failure'));
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$UserID = $LoggedUser['ID'];
|
|
|
|
$DB->query("SELECT InInbox, InSentbox FROM pm_conversations_users WHERE UserID='$UserID' AND ConvID='$ConvID'");
|
|
|
|
if($DB->record_count() == 0) {
|
|
|
|
print json_encode(array('status' => 'failure'));
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
list($InInbox, $InSentbox) = $DB->next_record();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!$InInbox && !$InSentbox) {
|
|
|
|
print json_encode(array('status' => 'failure'));
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get information on the conversation
|
|
|
|
$DB->query("SELECT
|
|
|
|
c.Subject,
|
|
|
|
cu.Sticky,
|
|
|
|
cu.UnRead,
|
|
|
|
cu.ForwardedTo,
|
|
|
|
um.Username
|
|
|
|
FROM pm_conversations AS c
|
|
|
|
JOIN pm_conversations_users AS cu ON c.ID=cu.ConvID
|
|
|
|
LEFT JOIN users_main AS um ON um.ID=cu.ForwardedTo
|
|
|
|
WHERE c.ID='$ConvID' AND UserID='$UserID'");
|
|
|
|
list($Subject, $Sticky, $UnRead, $ForwardedID, $ForwardedName) = $DB->next_record();
|
|
|
|
|
2012-03-28 08:00:20 +00:00
|
|
|
$DB->query("SELECT um.ID, Username
|
2011-10-27 08:00:15 +00:00
|
|
|
FROM pm_messages AS pm
|
|
|
|
JOIN users_main AS um ON um.ID=pm.SenderID
|
|
|
|
WHERE pm.ConvID='$ConvID'");
|
|
|
|
|
2012-03-28 08:00:20 +00:00
|
|
|
while(list($PMUserID, $Username) = $DB->next_record()) {
|
2011-10-27 08:00:15 +00:00
|
|
|
$PMUserID = (int)$PMUserID;
|
2012-03-28 08:00:20 +00:00
|
|
|
$Users[$PMUserID]['UserStr'] = format_username($PMUserID, true, true, true, true);
|
2011-10-27 08:00:15 +00:00
|
|
|
$Users[$PMUserID]['Username'] = $Username;
|
|
|
|
}
|
|
|
|
$Users[0]['UserStr'] = 'System'; // in case it's a message from the system
|
|
|
|
$Users[0]['Username'] = 'System';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($UnRead=='1') {
|
|
|
|
|
|
|
|
$DB->query("UPDATE pm_conversations_users SET UnRead='0' WHERE ConvID='$ConvID' AND UserID='$UserID'");
|
|
|
|
// Clear the caches of the inbox and sentbox
|
|
|
|
$Cache->decrement('inbox_new_'.$UserID);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get messages
|
|
|
|
$DB->query("SELECT SentDate, SenderID, Body, ID FROM pm_messages AS m WHERE ConvID='$ConvID' ORDER BY ID");
|
|
|
|
|
|
|
|
$JsonMessages = array();
|
|
|
|
while(list($SentDate, $SenderID, $Body, $MessageID) = $DB->next_record()) {
|
|
|
|
$JsonMessage = array(
|
2011-11-26 08:00:20 +00:00
|
|
|
'messageId' => (int) $MessageID,
|
|
|
|
'senderId' => (int) $SenderID,
|
2011-10-27 08:00:15 +00:00
|
|
|
'senderName' => $Users[(int)$SenderID]['Username'],
|
|
|
|
'sentDate' => $SentDate,
|
2012-07-06 08:00:11 +00:00
|
|
|
'bbBody' => $Body,
|
2011-10-27 08:00:15 +00:00
|
|
|
'body' => $Text->full_format($Body)
|
|
|
|
);
|
|
|
|
$JsonMessages[] = $JsonMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
print
|
|
|
|
json_encode(
|
|
|
|
array(
|
|
|
|
'status' => 'success',
|
|
|
|
'response' => array(
|
2011-11-26 08:00:20 +00:00
|
|
|
'convId' => (int) $ConvID,
|
2011-10-27 08:00:15 +00:00
|
|
|
'subject' => $Subject.($ForwardedID > 0 ? ' (Forwarded to '.$ForwardedName.')':''),
|
2011-11-26 08:00:20 +00:00
|
|
|
'sticky' => $Sticky == 1,
|
2011-10-27 08:00:15 +00:00
|
|
|
'messages' => $JsonMessages
|
|
|
|
)
|
|
|
|
)
|
2011-11-26 08:00:20 +00:00
|
|
|
);
|
|
|
|
?>
|