Gazelle/sections/ajax/inbox/viewconv.php

109 lines
2.6 KiB
PHP
Raw Normal View History

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