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 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. #declare(strict_types=1);
  3. $UserID = $LoggedUser['ID'];
  4. if (empty($_GET['action'])) {
  5. $Section = 'inbox';
  6. } else {
  7. $Section = $_GET['action']; // either 'inbox' or 'sentbox'
  8. }
  9. if (!in_array($Section, array('inbox', 'sentbox'))) {
  10. error(404);
  11. }
  12. list($Page, $Limit) = Format::page_limit(MESSAGES_PER_PAGE);
  13. View::show_header('Inbox');
  14. ?>
  15. <h2 class="header">
  16. <?=($Section === 'sentbox' ? 'Sentbox' : 'Inbox')?>
  17. </h2>
  18. <div class="linkbox">
  19. <?php if ($Section === 'inbox') { ?>
  20. <a href="<?=Inbox::get_inbox_link('sentbox'); ?>"
  21. class="brackets">Sentbox</a>
  22. <?php } elseif ($Section === 'sentbox') { ?>
  23. <a href="<?=Inbox::get_inbox_link(); ?>" class="brackets">Inbox</a>
  24. <?php
  25. }
  26. $Sort = empty($_GET['sort']) || $_GET['sort'] !== 'unread' ? 'Date DESC' : "cu.Unread = '1' DESC, DATE DESC";
  27. $sql = "
  28. SELECT
  29. SQL_CALC_FOUND_ROWS
  30. c.ID,
  31. c.Subject,
  32. cu.Unread,
  33. cu.Sticky,
  34. cu.ForwardedTo,
  35. cu2.UserID,";
  36. $sql .= $Section === 'sentbox' ? ' cu.SentDate ' : ' cu.ReceivedDate ';
  37. $sql .= "AS Date
  38. FROM pm_conversations AS c
  39. LEFT JOIN pm_conversations_users AS cu ON cu.ConvID = c.ID AND cu.UserID = '$UserID'
  40. LEFT JOIN pm_conversations_users AS cu2 ON cu2.ConvID = c.ID AND cu2.UserID != '$UserID' AND cu2.ForwardedTo = 0
  41. LEFT JOIN users_main AS um ON um.ID = cu2.UserID";
  42. if (!empty($_GET['search']) && $_GET['searchtype'] === 'message') {
  43. $sql .= ' JOIN pm_messages AS m ON c.ID = m.ConvID';
  44. }
  45. $sql .= ' WHERE ';
  46. if (!empty($_GET['search'])) {
  47. $Search = db_string($_GET['search']);
  48. if ($_GET['searchtype'] === 'user') {
  49. $sql .= "um.Username LIKE '$Search' AND ";
  50. } elseif ($_GET['searchtype'] === 'subject') {
  51. $Words = explode(' ', $Search);
  52. $sql .= "c.Subject LIKE '%".implode("%' AND c.Subject LIKE '%", $Words)."%' AND ";
  53. } elseif ($_GET['searchtype'] === 'message') {
  54. $Words = explode(' ', $Search);
  55. $sql .= "m.Body LIKE '%".implode("%' AND m.Body LIKE '%", $Words)."%' AND ";
  56. }
  57. }
  58. $sql .= $Section === 'sentbox' ? ' cu.InSentbox' : ' cu.InInbox';
  59. $sql .= " = '1'";
  60. $sql .= "
  61. GROUP BY c.ID
  62. ORDER BY cu.Sticky, $Sort
  63. LIMIT $Limit";
  64. $Results = $DB->query($sql);
  65. $DB->query('SELECT FOUND_ROWS()');
  66. list($NumResults) = $DB->next_record();
  67. $DB->set_query_id($Results);
  68. $Count = $DB->record_count();
  69. $Pages = Format::get_pages($Page, $NumResults, MESSAGES_PER_PAGE, 9);
  70. echo $Pages;
  71. ?>
  72. </div>
  73. <div class="box pad">
  74. <?php if ($Count === 0 && empty($_GET['search'])) { ?>
  75. <h2>Your <?=($Section === 'sentbox' ? 'sentbox' : 'inbox')?>
  76. is empty.</h2>
  77. <?php } else { ?>
  78. <form class="search_form"
  79. name="<?=($Section === 'sentbox' ? 'sentbox' : 'inbox')?>"
  80. action="inbox.php" method="get" id="searchbox">
  81. <div>
  82. <input type="hidden" name="action" value="<?=$Section?>" />
  83. <input type="radio" name="searchtype" value="user" <?=(empty($_GET['searchtype']) || $_GET['searchtype'] === 'user' ? ' checked="checked"' : '')?>
  84. /> User
  85. <input type="radio" name="searchtype" value="subject" <?=(!empty($_GET['searchtype']) && $_GET['searchtype'] === 'subject' ? ' checked="checked"' : '')?>
  86. /> Subject
  87. <input type="radio" name="searchtype" value="message" <?=(!empty($_GET['searchtype']) && $_GET['searchtype'] === 'message' ? ' checked="checked"' : '')?>
  88. /> Message
  89. <span class="float_right">
  90. <?php // provide a temporary toggle for sorting PMs
  91. $ToggleTitle = 'Temporary toggle switch for sorting PMs. To permanently change the sorting behavior, edit the setting in your profile.';
  92. $BaseURL = 'inbox.php';
  93. if (isset($_GET['sort']) && $_GET['sort'] === 'unread') { ?>
  94. <a href="<?=$BaseURL?>" class="brackets tooltip"
  95. title="<?=$ToggleTitle?>">List latest first</a>
  96. <?php } else { ?>
  97. <a href="<?=$BaseURL?>?sort=unread" class="brackets tooltip"
  98. title="<?=$ToggleTitle?>">List
  99. unread first</a>
  100. <?php } ?>
  101. </span>
  102. <br />
  103. <input type="search" name="search"
  104. placeholder="<?=(!empty($_GET['search']) ? display_str($_GET['search']) : 'Search '.($Section === 'sentbox' ? 'sentbox' : 'inbox'))?>" />
  105. </div>
  106. </form>
  107. <form class="manage_form" name="messages" action="inbox.php" method="post" id="messageform">
  108. <input type="hidden" name="action" value="masschange" />
  109. <input type="hidden" name="auth"
  110. value="<?=$LoggedUser['AuthKey']?>" />
  111. <input type="submit" name="read" value="Mark as read" />
  112. <input type="submit" name="unread" value="Mark as unread" />
  113. <input type="submit" name="delete" value="Delete message(s)" />
  114. <table class="message_table checkboxes">
  115. <tr class="colhead">
  116. <td width="10"><input type="checkbox" onclick="toggleChecks('messageform', this);" /></td>
  117. <td width="50%">Subject</td>
  118. <td><?=($Section === 'sentbox' ? 'Receiver' : 'Sender')?>
  119. </td>
  120. <td>Date</td>
  121. <?php if (check_perms('users_mod')) { ?>
  122. <td>Forwarded to</td>
  123. <?php } ?>
  124. </tr>
  125. <?php
  126. if ($Count === 0) { ?>
  127. <tr class="a">
  128. <td colspan="5">No results.</td>
  129. </tr>
  130. <?php } else {
  131. while (list($ConvID, $Subject, $Unread, $Sticky, $ForwardedID, $SenderID, $Date) = $DB->next_record()) {
  132. if ($Unread === '1') {
  133. $RowClass = 'unreadpm';
  134. } else {
  135. $RowClass = "row";
  136. } ?>
  137. <tr class="<?=$RowClass?>">
  138. <td class="center"><input type="checkbox" name="messages[]="
  139. value="<?=$ConvID?>" /></td>
  140. <td>
  141. <?php
  142. if ($Unread) {
  143. echo '<strong>';
  144. }
  145. if ($Sticky) {
  146. echo 'Sticky: ';
  147. }
  148. echo "\n"; ?>
  149. <a href="inbox.php?action=viewconv&amp;id=<?=$ConvID?>"><?=$Subject?></a>
  150. <?php
  151. if ($Unread) {
  152. echo "</strong>\n";
  153. } ?>
  154. </td>
  155. <td><?=Users::format_username($SenderID, true, true, true, true)?>
  156. </td>
  157. <td><?=time_diff($Date)?>
  158. </td>
  159. <?php if (check_perms('users_mod')) { ?>
  160. <td><?=(($ForwardedID && $ForwardedID != $LoggedUser['ID']) ? Users::format_username($ForwardedID, false, false, false) : '')?>
  161. </td>
  162. <?php } ?>
  163. </tr>
  164. <?php
  165. $DB->set_query_id($Results);
  166. }
  167. } ?>
  168. </table>
  169. <input type="submit" name="read" value="Mark as read" />
  170. <input type="submit" name="unread" value="Mark as unread" />
  171. <input type="submit" name="delete" value="Delete message(s)" />
  172. </form>
  173. <?php } ?>
  174. </div>
  175. <div class="linkbox">
  176. <?= $Pages ?>
  177. </div>
  178. <?php View::show_footer();