2013-05-28 08:01:02 +00:00
|
|
|
<?php
|
2011-10-27 08:00:15 +00:00
|
|
|
|
|
|
|
$UserID = $LoggedUser['ID'];
|
|
|
|
|
|
|
|
|
2013-05-05 08:00:31 +00:00
|
|
|
if (empty($_GET['type'])) {
|
|
|
|
$Section = 'inbox';
|
|
|
|
} else {
|
2011-10-27 08:00:15 +00:00
|
|
|
$Section = $_GET['type']; // either 'inbox' or 'sentbox'
|
|
|
|
}
|
2013-05-05 08:00:31 +00:00
|
|
|
if (!in_array($Section, array('inbox', 'sentbox'))) {
|
2011-10-27 08:00:15 +00:00
|
|
|
print
|
|
|
|
json_encode(
|
|
|
|
array(
|
|
|
|
'status' => 'failure'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2013-05-28 08:01:02 +00:00
|
|
|
list($Page, $Limit) = Format::page_limit(MESSAGES_PER_PAGE);
|
2011-10-27 08:00:15 +00:00
|
|
|
|
|
|
|
$Sort = empty($_GET['sort']) || $_GET['sort'] != "unread" ? "Date DESC" : "cu.Unread = '1' DESC, DATE DESC";
|
|
|
|
|
2013-05-05 08:00:31 +00:00
|
|
|
$sql = "
|
|
|
|
SELECT
|
|
|
|
SQL_CALC_FOUND_ROWS
|
|
|
|
c.ID,
|
|
|
|
c.Subject,
|
|
|
|
cu.Unread,
|
|
|
|
cu.Sticky,
|
|
|
|
cu.ForwardedTo,
|
|
|
|
um2.Username AS ForwardedName,
|
|
|
|
cu2.UserID,
|
|
|
|
um.Username,
|
|
|
|
ui.Donor,
|
|
|
|
ui.Warned,
|
|
|
|
um.Enabled,";
|
2011-10-27 08:00:15 +00:00
|
|
|
$sql .= ($Section == 'sentbox')? ' cu.SentDate ' : ' cu.ReceivedDate ';
|
|
|
|
$sql .= "AS Date
|
|
|
|
FROM pm_conversations AS c
|
2013-05-05 08:00:31 +00:00
|
|
|
LEFT JOIN pm_conversations_users AS cu ON cu.ConvID=c.ID AND cu.UserID='$UserID'
|
|
|
|
LEFT JOIN pm_conversations_users AS cu2 ON cu2.ConvID=c.ID AND cu2.UserID!='$UserID' AND cu2.ForwardedTo=0
|
|
|
|
LEFT JOIN users_main AS um ON um.ID=cu2.UserID
|
|
|
|
LEFT JOIN users_info AS ui ON ui.UserID=um.ID
|
|
|
|
LEFT JOIN users_main AS um2 ON um2.ID=cu.ForwardedTo";
|
2011-10-27 08:00:15 +00:00
|
|
|
|
2013-05-05 08:00:31 +00:00
|
|
|
if (!empty($_GET['search']) && $_GET['searchtype'] == "message") {
|
2011-10-27 08:00:15 +00:00
|
|
|
$sql .= " JOIN pm_messages AS m ON c.ID=m.ConvID";
|
|
|
|
}
|
|
|
|
$sql .= " WHERE ";
|
2013-05-05 08:00:31 +00:00
|
|
|
if (!empty($_GET['search'])) {
|
2011-10-27 08:00:15 +00:00
|
|
|
$Search = db_string($_GET['search']);
|
2013-05-05 08:00:31 +00:00
|
|
|
if ($_GET['searchtype'] == "user") {
|
2011-10-27 08:00:15 +00:00
|
|
|
$sql .= "um.Username LIKE '".$Search."' AND ";
|
2013-05-05 08:00:31 +00:00
|
|
|
} elseif ($_GET['searchtype'] == "subject") {
|
2011-10-27 08:00:15 +00:00
|
|
|
$Words = explode(' ', $Search);
|
|
|
|
$sql .= "c.Subject LIKE '%".implode("%' AND c.Subject LIKE '%", $Words)."%' AND ";
|
2013-05-05 08:00:31 +00:00
|
|
|
} elseif ($_GET['searchtype'] == "message") {
|
2011-10-27 08:00:15 +00:00
|
|
|
$Words = explode(' ', $Search);
|
|
|
|
$sql .= "m.Body LIKE '%".implode("%' AND m.Body LIKE '%", $Words)."%' AND ";
|
|
|
|
}
|
|
|
|
}
|
2013-05-05 08:00:31 +00:00
|
|
|
$sql .= ($Section == 'sentbox') ? ' cu.InSentbox' : ' cu.InInbox';
|
2011-10-27 08:00:15 +00:00
|
|
|
$sql .="='1'";
|
|
|
|
|
|
|
|
$sql .=" GROUP BY c.ID
|
|
|
|
ORDER BY cu.Sticky, ".$Sort." LIMIT $Limit";
|
|
|
|
$Results = $DB->query($sql);
|
|
|
|
$DB->query('SELECT FOUND_ROWS()');
|
|
|
|
list($NumResults) = $DB->next_record();
|
|
|
|
$DB->set_query_id($Results);
|
|
|
|
|
2012-10-11 08:00:15 +00:00
|
|
|
$CurURL = Format::get_url(array('sort'));
|
2013-05-05 08:00:31 +00:00
|
|
|
if (empty($CurURL)) {
|
2011-10-27 08:00:15 +00:00
|
|
|
$CurURL = "inbox.php?";
|
|
|
|
} else {
|
|
|
|
$CurURL = "inbox.php?".$CurURL."&";
|
|
|
|
}
|
|
|
|
|
2013-05-15 08:00:54 +00:00
|
|
|
$Pages = Format::get_pages($Page, $NumResults, MESSAGES_PER_PAGE, 9);
|
2011-10-27 08:00:15 +00:00
|
|
|
|
|
|
|
$JsonMessages = array();
|
2013-05-05 08:00:31 +00:00
|
|
|
while (list($ConvID, $Subject, $Unread, $Sticky, $ForwardedID, $ForwardedName, $SenderID, $Username, $Donor, $Warned, $Enabled, $Date) = $DB->next_record()) {
|
2011-10-27 08:00:15 +00:00
|
|
|
$JsonMessage = array(
|
2011-11-26 08:00:20 +00:00
|
|
|
'convId' => (int) $ConvID,
|
2011-10-27 08:00:15 +00:00
|
|
|
'subject' => $Subject,
|
2011-11-26 08:00:20 +00:00
|
|
|
'unread' => $Unread == 1,
|
|
|
|
'sticky' => $Sticky == 1,
|
|
|
|
'forwardedId' => (int) $ForwardedID,
|
2011-10-27 08:00:15 +00:00
|
|
|
'forwardedName' => $ForwardedName,
|
2011-11-26 08:00:20 +00:00
|
|
|
'senderId' => (int) $SenderID,
|
2011-10-27 08:00:15 +00:00
|
|
|
'username' => $Username,
|
2011-11-26 08:00:20 +00:00
|
|
|
'donor' => $Donor == 1,
|
|
|
|
'warned' => $Warned == 1,
|
2011-10-27 08:00:15 +00:00
|
|
|
'enabled' => ($Enabled == 2 ? false : true),
|
|
|
|
'date' => $Date
|
|
|
|
);
|
|
|
|
$JsonMessages[] = $JsonMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
print
|
|
|
|
json_encode(
|
|
|
|
array(
|
|
|
|
'status' => 'success',
|
|
|
|
'response' => array(
|
2011-11-26 08:00:20 +00:00
|
|
|
'currentPage' => (int) $Page,
|
2013-05-05 08:00:31 +00:00
|
|
|
'pages' => ceil($NumResults / MESSAGES_PER_PAGE),
|
2011-10-27 08:00:15 +00:00
|
|
|
'messages' => $JsonMessages
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2013-05-05 08:00:31 +00:00
|
|
|
?>
|