Gazelle/sections/inbox/inbox.php

177 lines
5.9 KiB
PHP
Raw Normal View History

2013-05-28 08:01:02 +00:00
<?php
2011-03-28 14:21:28 +00:00
$UserID = $LoggedUser['ID'];
2013-05-04 08:00:48 +00:00
if (empty($_GET['action'])) {
$Section = 'inbox';
} else {
2011-03-28 14:21:28 +00:00
$Section = $_GET['action']; // either 'inbox' or 'sentbox'
}
2013-05-04 08:00:48 +00:00
if (!in_array($Section, array('inbox', 'sentbox'))) {
error(404);
}
2011-03-28 14:21:28 +00:00
2013-05-28 08:01:02 +00:00
list($Page, $Limit) = Format::page_limit(MESSAGES_PER_PAGE);
2011-03-28 14:21:28 +00:00
2012-10-11 08:00:15 +00:00
View::show_header('Inbox');
2011-03-28 14:21:28 +00:00
?>
<div class="thin">
2013-05-27 08:00:58 +00:00
<h2><?=(($Section == 'sentbox') ? 'Sentbox' : 'Inbox')?></h2>
2011-03-28 14:21:28 +00:00
<div class="linkbox">
<?
2013-05-04 08:00:48 +00:00
if ($Section == 'inbox') { ?>
2013-06-04 08:00:34 +00:00
<a href="<?=Inbox::get_inbox_link($LoggedUser['ListUnreadPMsFirst'], 'sentbox'); ?>" class="brackets">Sentbox</a>
2013-05-04 08:00:48 +00:00
<? } elseif ($Section == 'sentbox') { ?>
2013-06-04 08:00:34 +00:00
<a href="<?=Inbox::get_inbox_link($LoggedUser['ListUnreadPMsFirst']); ?>" class="brackets">Inbox</a>
2011-03-28 14:21:28 +00:00
<? }
?>
<br /><br />
<?
2013-05-27 08:00:58 +00:00
$Sort = (empty($_GET['sort']) || $_GET['sort'] != 'unread' ? 'Date DESC' : "cu.Unread = '1' DESC, DATE DESC");
2011-03-28 14:21:28 +00:00
2013-05-04 08:00:48 +00:00
$sql = "
2013-05-29 08:00:51 +00:00
SELECT
SQL_CALC_FOUND_ROWS
2013-05-04 08:00:48 +00:00
c.ID,
c.Subject,
cu.Unread,
cu.Sticky,
cu.ForwardedTo,
cu2.UserID,";
2013-06-04 08:00:34 +00:00
$sql .= (($Section == 'sentbox') ? ' cu.SentDate ' : ' cu.ReceivedDate ');
2011-03-28 14:21:28 +00:00
$sql .= "AS Date
FROM pm_conversations AS c
2013-05-04 08:00:48 +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";
2011-03-28 14:21:28 +00:00
2013-06-04 08:00:34 +00:00
if (!empty($_GET['search']) && $_GET['searchtype'] == 'message') {
$sql .= ' JOIN pm_messages AS m ON c.ID=m.ConvID';
2011-03-28 14:21:28 +00:00
}
2013-06-04 08:00:34 +00:00
$sql .= ' WHERE ';
2013-05-04 08:00:48 +00:00
if (!empty($_GET['search'])) {
2013-02-18 08:00:22 +00:00
$Search = db_string($_GET['search']);
2013-06-04 08:00:34 +00:00
if ($_GET['searchtype'] == 'user') {
$sql .= "um.Username LIKE '$Search' AND ";
} elseif ($_GET['searchtype'] == 'subject') {
2013-02-18 08:00:22 +00:00
$Words = explode(' ', $Search);
$sql .= "c.Subject LIKE '%".implode("%' AND c.Subject LIKE '%", $Words)."%' AND ";
2013-06-04 08:00:34 +00:00
} elseif ($_GET['searchtype'] == 'message') {
2013-02-18 08:00:22 +00:00
$Words = explode(' ', $Search);
$sql .= "m.Body LIKE '%".implode("%' AND m.Body LIKE '%", $Words)."%' AND ";
}
2011-03-28 14:21:28 +00:00
}
2013-06-04 08:00:34 +00:00
$sql .= (($Section == 'sentbox') ? ' cu.InSentbox' : ' cu.InInbox');
2013-06-11 08:01:24 +00:00
$sql .= "='1'";
2011-03-28 14:21:28 +00:00
2013-06-04 08:00:34 +00:00
$sql .="
GROUP BY c.ID
ORDER BY cu.Sticky, $Sort
LIMIT $Limit";
2011-03-28 14:21:28 +00:00
$Results = $DB->query($sql);
$DB->query('SELECT FOUND_ROWS()');
list($NumResults) = $DB->next_record();
$DB->set_query_id($Results);
2013-02-18 08:00:22 +00:00
$Count = $DB->record_count();
2011-03-28 14:21:28 +00:00
2013-05-15 08:00:54 +00:00
$Pages = Format::get_pages($Page, $NumResults, MESSAGES_PER_PAGE, 9);
2013-06-11 08:01:24 +00:00
echo "\t\t$Pages\n";
2011-03-28 14:21:28 +00:00
?>
</div>
<div class="box pad">
2013-05-04 08:00:48 +00:00
<? if ($Count == 0 && empty($_GET['search'])) { ?>
2013-06-04 08:00:34 +00:00
<h2>Your <?=(($Section == 'sentbox') ? 'sentbox' : 'inbox')?> is currently empty</h2>
2011-03-28 14:21:28 +00:00
<? } else { ?>
2013-05-04 08:00:48 +00:00
<form class="search_form" name="<?=(($Section == 'sentbox') ? 'sentbox' : 'inbox')?>" action="inbox.php" method="get" id="searchbox">
<div>
<input type="hidden" name="action" value="<?=$Section?>" />
2013-02-18 08:00:22 +00:00
<input type="radio" name="searchtype" value="user"<?=(empty($_GET['searchtype']) || $_GET['searchtype'] == 'user' ? ' checked="checked"' : '')?> /> User
<input type="radio" name="searchtype" value="subject"<?=(!empty($_GET['searchtype']) && $_GET['searchtype'] == 'subject' ? ' checked="checked"' : '')?> /> Subject
<input type="radio" name="searchtype" value="message"<?=(!empty($_GET['searchtype']) && $_GET['searchtype'] == 'message' ? ' checked="checked"' : '')?> /> Message
<br />
2013-02-18 08:00:22 +00:00
<input type="text" name="search" value="<?=(!empty($_GET['search']) ? display_str($_GET['search']) : 'Search '.($Section == 'sentbox' ? 'Sentbox' : 'Inbox'))?>" style="width: 98%;"
2013-06-04 08:00:34 +00:00
onfocus="if (this.value == 'Search <?=(($Section == 'sentbox') ? 'Sentbox' : 'Inbox')?>') this.value='';"
onblur="if (this.value == '') this.value='Search <?=(($Section == 'sentbox') ? 'Sentbox' : 'Inbox')?>';"
/>
2011-03-28 14:21:28 +00:00
</div>
</form>
2012-09-15 08:00:25 +00:00
<form class="manage_form" name="messages" action="inbox.php" method="post" id="messageform">
2011-03-28 14:21:28 +00:00
<input type="hidden" name="action" value="masschange" />
<input type="hidden" name="auth" value="<?=$LoggedUser['AuthKey']?>" />
2013-02-18 08:00:22 +00:00
<input type="submit" name="read" value="Mark as read" />&nbsp;
<input type="submit" name="unread" value="Mark as unread" />&nbsp;
<input type="submit" name="delete" value="Delete message(s)" />
2012-07-11 08:00:16 +00:00
2012-09-01 08:00:24 +00:00
<table class="message_table checkboxes">
2011-03-28 14:21:28 +00:00
<tr class="colhead">
<td width="10"><input type="checkbox" onclick="toggleChecks('messageform',this)" /></td>
<td width="50%">Subject</td>
2013-05-16 16:15:57 +00:00
<td><?=(($Section == 'sentbox') ? 'Receiver' : 'Sender')?></td>
2011-03-28 14:21:28 +00:00
<td>Date</td>
2013-05-04 08:00:48 +00:00
<? if (check_perms('users_mod')) { ?>
2011-03-28 14:21:28 +00:00
<td>Forwarded to</td>
<? } ?>
</tr>
<?
2013-05-04 08:00:48 +00:00
if ($Count == 0) { ?>
2013-02-18 08:00:22 +00:00
<tr class="a">
<td colspan="5">No results.</td>
</tr>
<? } else {
$Row = 'a';
2013-05-04 08:00:48 +00:00
while (list($ConvID, $Subject, $Unread, $Sticky, $ForwardedID, $SenderID, $Date) = $DB->next_record()) {
if ($Unread === '1') {
2013-02-18 08:00:22 +00:00
$RowClass = 'unreadpm';
} else {
2013-06-04 08:00:34 +00:00
$Row = (($Row === 'a') ? 'b' : 'a');
2013-02-18 08:00:22 +00:00
$RowClass = 'row'.$Row;
}
2011-03-28 14:21:28 +00:00
?>
<tr class="<?=$RowClass?>">
<td class="center"><input type="checkbox" name="messages[]=" value="<?=$ConvID?>" /></td>
<td>
2013-06-11 08:01:24 +00:00
<? echo "\t\t\t\t\t\t"; // for proper indentation of HTML
if ($Unread) {
2013-05-04 08:00:48 +00:00
echo '<strong>';
}
if ($Sticky) {
echo 'Sticky: ';
}
2013-06-11 08:01:24 +00:00
echo "\n";
2011-03-28 14:21:28 +00:00
?>
<a href="inbox.php?action=viewconv&amp;id=<?=$ConvID?>"><?=$Subject?></a>
<?
2013-06-11 08:01:24 +00:00
echo "\t\t\t\t\t\t"; // for proper indentation of HTML
2013-05-04 08:00:48 +00:00
if ($Unread) {
2013-06-11 08:01:24 +00:00
echo "</strong>\n";
2013-05-04 08:00:48 +00:00
} ?>
2011-03-28 14:21:28 +00:00
</td>
2012-10-11 08:00:15 +00:00
<td><?=Users::format_username($SenderID, true, true, true, true)?></td>
2011-03-28 14:21:28 +00:00
<td><?=time_diff($Date)?></td>
2013-05-04 08:00:48 +00:00
<? if (check_perms('users_mod')) { ?>
2013-05-27 08:00:58 +00:00
<td><?=(($ForwardedID && $ForwardedID != $LoggedUser['ID']) ? Users::format_username($ForwardedID, false, false, false) : '')?></td>
2013-02-18 08:00:22 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
</tr>
2013-02-18 08:00:22 +00:00
<? }
2013-05-15 08:00:54 +00:00
} ?>
2011-03-28 14:21:28 +00:00
</table>
<input type="submit" name="read" value="Mark as read" />&nbsp;
<input type="submit" name="unread" value="Mark as unread" />&nbsp;
<input type="submit" name="delete" value="Delete message(s)" />
2011-03-28 14:21:28 +00:00
</form>
<? } ?>
</div>
2013-06-11 08:01:24 +00:00
<div class="linkbox">
<? echo "\t\t$Pages\n"; ?>
</div>
2011-03-28 14:21:28 +00:00
</div>
<?
2012-10-11 08:00:15 +00:00
View::show_footer();
2011-03-28 14:21:28 +00:00
?>