BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

inbox.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. #declare(strict_types=1);
  3. $UserID = $LoggedUser['ID'];
  4. if (empty($_GET['type'])) {
  5. $Section = 'inbox';
  6. } else {
  7. $Section = $_GET['type']; // either 'inbox' or 'sentbox'
  8. }
  9. if (!in_array($Section, array('inbox', 'sentbox'))) {
  10. print
  11. json_encode(
  12. array(
  13. 'status' => 'failure'
  14. )
  15. );
  16. error();
  17. }
  18. list($Page, $Limit) = Format::page_limit(MESSAGES_PER_PAGE);
  19. $Sort = empty($_GET['sort']) || $_GET['sort'] != "unread" ? "Date DESC" : "cu.Unread = '1' DESC, DATE DESC";
  20. $sql = "
  21. SELECT
  22. SQL_CALC_FOUND_ROWS
  23. c.ID,
  24. c.Subject,
  25. cu.Unread,
  26. cu.Sticky,
  27. cu.ForwardedTo,
  28. um2.Username AS ForwardedName,
  29. cu2.UserID,
  30. um.Username,
  31. ui.Donor,
  32. ui.Warned,
  33. um.Enabled,
  34. ui.Avatar,";
  35. $sql .= $Section === 'sentbox' ? ' cu.SentDate ' : ' cu.ReceivedDate ';
  36. $sql .= "AS Date
  37. FROM pm_conversations AS c
  38. LEFT JOIN pm_conversations_users AS cu ON cu.ConvID = c.ID AND cu.UserID = '$UserID'
  39. LEFT JOIN pm_conversations_users AS cu2 ON cu2.ConvID = c.ID AND cu2.UserID != '$UserID' AND cu2.ForwardedTo = 0
  40. LEFT JOIN users_main AS um ON um.ID = cu2.UserID
  41. LEFT JOIN users_info AS ui ON ui.UserID = um.ID
  42. LEFT JOIN users_main AS um2 ON um2.ID = cu.ForwardedTo";
  43. if (!empty($_GET['search']) && $_GET['searchtype'] === 'message') {
  44. $sql .= ' JOIN pm_messages AS m ON c.ID = m.ConvID';
  45. }
  46. $sql .= " WHERE ";
  47. if (!empty($_GET['search'])) {
  48. $Search = db_string($_GET['search']);
  49. if ($_GET['searchtype'] === 'user') {
  50. $sql .= "um.Username LIKE '$Search' AND ";
  51. } elseif ($_GET['searchtype'] === 'subject') {
  52. $Words = explode(' ', $Search);
  53. $sql .= "c.Subject LIKE '%".implode("%' AND c.Subject LIKE '%", $Words)."%' AND ";
  54. } elseif ($_GET['searchtype'] === 'message') {
  55. $Words = explode(' ', $Search);
  56. $sql .= "m.Body LIKE '%".implode("%' AND m.Body LIKE '%", $Words)."%' AND ";
  57. }
  58. }
  59. $sql .= $Section === 'sentbox' ? ' cu.InSentbox' : ' cu.InInbox';
  60. $sql .= " = '1'";
  61. $sql .= "
  62. GROUP BY c.ID
  63. ORDER BY cu.Sticky, $Sort
  64. LIMIT $Limit";
  65. $Results = $DB->query($sql);
  66. $DB->query('SELECT FOUND_ROWS()');
  67. list($NumResults) = $DB->next_record();
  68. $DB->set_query_id($Results);
  69. $CurURL = Format::get_url(array('sort'));
  70. if (empty($CurURL)) {
  71. $CurURL = "inbox.php?";
  72. } else {
  73. $CurURL = "inbox.php?".$CurURL."&";
  74. }
  75. $Pages = Format::get_pages($Page, $NumResults, MESSAGES_PER_PAGE, 9);
  76. $JsonMessages = [];
  77. while (list($ConvID, $Subject, $Unread, $Sticky, $ForwardedID, $ForwardedName, $SenderID, $Username, $Donor, $Warned, $Enabled, $Avatar, $Date) = $DB->next_record()) {
  78. $JsonMessage = array(
  79. 'convId' => (int)$ConvID,
  80. 'subject' => $Subject,
  81. 'unread' => $Unread == 1,
  82. 'sticky' => $Sticky == 1,
  83. 'forwardedId' => (int)$ForwardedID,
  84. 'forwardedName' => $ForwardedName,
  85. 'senderId' => (int)$SenderID,
  86. 'username' => $Username,
  87. 'avatar' => $Avatar,
  88. 'donor' => $Donor == 1,
  89. 'warned' => $Warned == 1,
  90. 'enabled' => $Enabled == 2 ? false : true,
  91. 'date' => $Date
  92. );
  93. $JsonMessages[] = $JsonMessage;
  94. }
  95. print
  96. json_encode(
  97. array(
  98. 'status' => 'success',
  99. 'response' => array(
  100. 'currentPage' => (int)$Page,
  101. 'pages' => ceil($NumResults / MESSAGES_PER_PAGE),
  102. 'messages' => $JsonMessages
  103. )
  104. )
  105. );
  106. ?>