Gazelle/sections/inbox/inbox.php

167 lines
5.6 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
$UserID = $LoggedUser['ID'];
if(empty($_GET['action'])) { $Section = 'inbox'; }
else {
$Section = $_GET['action']; // either 'inbox' or 'sentbox'
}
if(!in_array($Section, array('inbox', 'sentbox'))) { error(404); }
2012-10-11 08:00:15 +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">
<h2><?= ($Section == 'sentbox') ? 'Sentbox' : 'Inbox' ?></h2>
<div class="linkbox">
<?
if($Section == 'inbox') { ?>
2013-01-24 08:00:24 +00:00
<a href="inbox.php?action=sentbox" class="brackets">Sentbox</a>
2011-03-28 14:21:28 +00:00
<? } elseif($Section == 'sentbox') { ?>
2013-01-24 08:00:24 +00:00
<a href="inbox.php" class="brackets">Inbox</a>
2011-03-28 14:21:28 +00:00
<? }
?>
<br /><br />
<?
$Sort = empty($_GET['sort']) || $_GET['sort'] != "unread" ? "Date DESC" : "cu.Unread = '1' DESC, DATE DESC";
$sql = "SELECT
SQL_CALC_FOUND_ROWS
c.ID,
c.Subject,
cu.Unread,
cu.Sticky,
cu.ForwardedTo,
2012-03-28 08:00:20 +00:00
cu2.UserID,";
2011-03-28 14:21:28 +00:00
$sql .= ($Section == 'sentbox')? ' cu.SentDate ' : ' cu.ReceivedDate ';
$sql .= "AS Date
FROM pm_conversations AS c
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
2012-03-28 08:00:20 +00:00
LEFT JOIN users_main AS um ON um.ID=cu2.UserID";
2011-03-28 14:21:28 +00:00
if(!empty($_GET['search']) && $_GET['searchtype'] == "message") {
$sql .= " JOIN pm_messages AS m ON c.ID=m.ConvID";
}
$sql .= " WHERE ";
if(!empty($_GET['search'])) {
$Search = db_string($_GET['search']);
if($_GET['searchtype'] == "user") {
$sql .= "um.Username LIKE '".$Search."' AND ";
} elseif($_GET['searchtype'] == "subject") {
$Words = explode(' ', $Search);
$sql .= "c.Subject LIKE '%".implode("%' AND c.Subject LIKE '%", $Words)."%' AND ";
} elseif($_GET['searchtype'] == "message") {
2011-03-28 14:21:28 +00:00
$Words = explode(' ', $Search);
$sql .= "m.Body LIKE '%".implode("%' AND m.Body LIKE '%", $Words)."%' AND ";
}
2011-03-28 14:21:28 +00:00
}
$sql .= ($Section == 'sentbox')? ' cu.InSentbox' : ' cu.InInbox';
$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'));
2011-03-28 14:21:28 +00:00
if(empty($CurURL)) {
$CurURL = "inbox.php?";
} else {
2013-01-16 08:00:31 +00:00
$CurURL = "inbox.php?".$CurURL."&amp;";
2011-03-28 14:21:28 +00:00
}
2012-10-11 08:00:15 +00:00
$Pages=Format::get_pages($Page,$NumResults,MESSAGES_PER_PAGE,9);
2011-03-28 14:21:28 +00:00
echo $Pages;
?>
</div>
<div class="box pad">
<? if($DB->record_count()==0) { ?>
<h2>Your <?= ($Section == 'sentbox') ? 'sentbox' : 'inbox' ?> is currently empty</h2>
<? } else { ?>
2013-01-16 08:00:31 +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?>" />
<input type="radio" name="searchtype" value="user" checked="checked" /> User
<input type="radio" name="searchtype" value="subject" /> Subject
<input type="radio" name="searchtype" value="message" /> Message
<span style="float: right;">
2011-03-28 14:21:28 +00:00
<? if(empty($_GET['sort']) || $_GET['sort'] != "unread") { ?>
2013-02-04 08:00:13 +00:00
<a href="<?=$CurURL?>sort=unread" class="brackets">List unread first</a>
2011-03-28 14:21:28 +00:00
<? } else { ?>
2013-02-04 08:00:13 +00:00
<a href="<?=$CurURL?>" class="brackets">List latest first</a>
2011-03-28 14:21:28 +00:00
<? } ?>
</span>
<br />
<input type="text" name="search" value="Search <?= ($Section == 'sentbox') ? 'Sentbox' : 'Inbox' ?>" style="width: 98%;"
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']?>" />
2012-07-11 08:00:16 +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-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>
<td><?=($Section == 'sentbox')? 'Receiver' : 'Sender' ?></td>
<td>Date</td>
<? if(check_perms('users_mod')) {?>
<td>Forwarded to</td>
<? } ?>
</tr>
<?
$Row = 'a';
2012-03-28 08:00:20 +00:00
while(list($ConvID, $Subject, $Unread, $Sticky, $ForwardedID, $SenderID, $Date) = $DB->next_record()) {
2011-03-28 14:21:28 +00:00
if($Unread === '1') {
$RowClass = 'unreadpm';
} else {
$Row = ($Row === 'a') ? 'b' : 'a';
$RowClass = 'row'.$Row;
}
?>
<tr class="<?=$RowClass?>">
<td class="center"><input type="checkbox" name="messages[]=" value="<?=$ConvID?>" /></td>
<td>
<? if($Unread) { echo '<strong>'; } ?>
<? if($Sticky) { echo 'Sticky: '; }
?>
<a href="inbox.php?action=viewconv&amp;id=<?=$ConvID?>"><?=$Subject?></a>
<?
if($Unread) { echo '</strong>';} ?>
</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>
<? if(check_perms('users_mod')) { ?>
2012-10-11 08:00:15 +00:00
<td><?=($ForwardedID && $ForwardedID != $LoggedUser['ID'] ? Users::format_username($ForwardedID, false, false, false):'')?></td>
2011-03-28 14:21:28 +00:00
<? } ?>
</tr>
<? } ?>
</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>
<div class="linkbox"><?=$Pages?></div>
</div>
<?
2012-10-11 08:00:15 +00:00
View::show_footer();
2011-03-28 14:21:28 +00:00
?>