Oppaitime'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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. $UserID = $LoggedUser['ID'];
  3. if (empty($_GET['action'])) {
  4. $Section = 'inbox';
  5. } else {
  6. $Section = $_GET['action']; // either 'inbox' or 'sentbox'
  7. }
  8. if (!in_array($Section, array('inbox', 'sentbox'))) {
  9. error(404);
  10. }
  11. list($Page, $Limit) = Format::page_limit(MESSAGES_PER_PAGE);
  12. View::show_header('Inbox');
  13. ?>
  14. <div class="thin">
  15. <h2><?=($Section === 'sentbox' ? 'Sentbox' : 'Inbox')?></h2>
  16. <div class="linkbox">
  17. <?
  18. if ($Section === 'inbox') { ?>
  19. <a href="<?=Inbox::get_inbox_link('sentbox'); ?>" class="brackets">Sentbox</a>
  20. <? } elseif ($Section === 'sentbox') { ?>
  21. <a href="<?=Inbox::get_inbox_link(); ?>" class="brackets">Inbox</a>
  22. <? }
  23. ?>
  24. <br /><br />
  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 "\t\t$Pages\n";
  71. ?>
  72. </div>
  73. <div class="box pad">
  74. <? if ($Count == 0 && empty($_GET['search'])) { ?>
  75. <h2>Your <?=($Section === 'sentbox' ? 'sentbox' : 'inbox')?> is empty.</h2>
  76. <? } else { ?>
  77. <form class="search_form" name="<?=($Section === 'sentbox' ? 'sentbox' : 'inbox')?>" action="inbox.php" method="get" id="searchbox">
  78. <div>
  79. <input type="hidden" name="action" value="<?=$Section?>" />
  80. <input type="radio" name="searchtype" value="user"<?=(empty($_GET['searchtype']) || $_GET['searchtype'] === 'user' ? ' checked="checked"' : '')?> /> User
  81. <input type="radio" name="searchtype" value="subject"<?=(!empty($_GET['searchtype']) && $_GET['searchtype'] === 'subject' ? ' checked="checked"' : '')?> /> Subject
  82. <input type="radio" name="searchtype" value="message"<?=(!empty($_GET['searchtype']) && $_GET['searchtype'] === 'message' ? ' checked="checked"' : '')?> /> Message
  83. <span style="float: right;">
  84. <? // provide a temporary toggle for sorting PMs
  85. $ToggleTitle = 'Temporary toggle switch for sorting PMs. To permanently change the sorting behavior, edit the setting in your profile.';
  86. $BaseURL = 'inbox.php';
  87. if (isset($_GET['sort']) && $_GET['sort'] === 'unread') { ?>
  88. <a href="<?=$BaseURL?>" class="brackets tooltip" title="<?=$ToggleTitle?>">List latest first</a>
  89. <? } else { ?>
  90. <a href="<?=$BaseURL?>?sort=unread" class="brackets tooltip" title="<?=$ToggleTitle?>">List unread first</a>
  91. <? } ?>
  92. </span>
  93. <br />
  94. <input type="search" name="search" placeholder="<?=(!empty($_GET['search']) ? display_str($_GET['search']) : 'Search '.($Section === 'sentbox' ? 'sentbox' : 'inbox'))?>" />
  95. </div>
  96. </form>
  97. <form class="manage_form" name="messages" action="inbox.php" method="post" id="messageform">
  98. <input type="hidden" name="action" value="masschange" />
  99. <input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
  100. <input type="submit" name="read" value="Mark as read" />
  101. <input type="submit" name="unread" value="Mark as unread" />
  102. <input type="submit" name="delete" value="Delete message(s)" />
  103. <table class="message_table checkboxes">
  104. <tr class="colhead">
  105. <td width="10"><input type="checkbox" onclick="toggleChecks('messageform', this);" /></td>
  106. <td width="50%">Subject</td>
  107. <td><?=($Section === 'sentbox' ? 'Receiver' : 'Sender')?></td>
  108. <td>Date</td>
  109. <? if (check_perms('users_mod')) { ?>
  110. <td>Forwarded to</td>
  111. <? } ?>
  112. </tr>
  113. <?
  114. if ($Count == 0) { ?>
  115. <tr class="a">
  116. <td colspan="5">No results.</td>
  117. </tr>
  118. <? } else {
  119. while (list($ConvID, $Subject, $Unread, $Sticky, $ForwardedID, $SenderID, $Date) = $DB->next_record()) {
  120. if ($Unread === '1') {
  121. $RowClass = 'unreadpm';
  122. } else {
  123. $RowClass = "row";
  124. }
  125. ?>
  126. <tr class="<?=$RowClass?>">
  127. <td class="center"><input type="checkbox" name="messages[]=" value="<?=$ConvID?>" /></td>
  128. <td>
  129. <?
  130. echo "\t\t\t\t\t\t"; // for proper indentation of HTML
  131. if ($Unread) {
  132. echo '<strong>';
  133. }
  134. if ($Sticky) {
  135. echo 'Sticky: ';
  136. }
  137. echo "\n";
  138. ?>
  139. <a href="inbox.php?action=viewconv&amp;id=<?=$ConvID?>"><?=$Subject?></a>
  140. <?
  141. echo "\t\t\t\t\t\t"; // for proper indentation of HTML
  142. if ($Unread) {
  143. echo "</strong>\n";
  144. } ?>
  145. </td>
  146. <td><?=Users::format_username($SenderID, true, true, true, true)?></td>
  147. <td><?=time_diff($Date)?></td>
  148. <? if (check_perms('users_mod')) { ?>
  149. <td><?=(($ForwardedID && $ForwardedID != $LoggedUser['ID']) ? Users::format_username($ForwardedID, false, false, false) : '')?></td>
  150. <? } ?>
  151. </tr>
  152. <?
  153. $DB->set_query_id($Results);
  154. }
  155. } ?>
  156. </table>
  157. <input type="submit" name="read" value="Mark as read" />
  158. <input type="submit" name="unread" value="Mark as unread" />
  159. <input type="submit" name="delete" value="Delete message(s)" />
  160. </form>
  161. <? } ?>
  162. </div>
  163. <div class="linkbox">
  164. <? echo "\t\t$Pages\n"; ?>
  165. </div>
  166. </div>
  167. <?
  168. View::show_footer();
  169. ?>