Mod Name / Version Filter PM's 1.0
Description Allows your users to filter their private messages by sender/receiver and or date
Working under UBB.threads 6.1
Any pre-requisites None
Author(s) dimopoulos
Credits ubbdev.com who taught me how to do things in php and ubb threads
Demo None.
Files Altered viewmessages.php, templates/default/viewmessages.tmpl
Database Altered No
New Files None
Any other info Please report any problems you might have and I'll try to fix them as soon as possible.
Step 1
Open viewmessages.php
Step 1.1
Find this:
code:
// Grab the proper private messages
$field1 = $ubbt_lang['TEXT_FROM'];
$field2 = $ubbt_lang['TEXT_REC'];
if ($box == "received") {
$extra = "<>";
}
else {
$extra = "=";
$field1 = $ubbt_lang['SENT_TO'];
$field2 = $ubbt_lang['SENT'];
}
BELOW IT ADD
code:
$strWhere = "";
if (!empty($fltdate))
{
$strWhere .= " AND FROM_UNIXTIME( M_Sent, '%d/%b/%Y' ) = '$fltdate' ";
}
if (!empty($fltfrom))
{
$strWhere .= " AND M_Sender = '$fltfrom' ";
}
Step 1.2
Find this:
code:
$query = "
SELECT M_Status, M_Subject, M_Sender, M_Sent, M_Number
FROM {$config['tbprefix']}Messages
WHERE M_Username = '$username_q'
AND M_Status $extra 'X'
ORDER BY M_Sent DESC
";
CHANGE it to this
code:
$query = "
SELECT M_Status, M_Subject, M_Sender, M_Sent, M_Number
FROM {$config['tbprefix']}Messages
WHERE M_Username = '$username_q'
AND M_Status $extra 'X'
$strWhere
ORDER BY M_Sent DESC
";
Step 1.3
Find this:
code:
$messagesize = sizeof($message);
BELOW IT ADD
code:
$strQuery = "SELECT M_Sender
FROM {$config['tbprefix']}Messages
WHERE M_Username = '$username_q'
AND M_Status $extra 'X'
GROUP BY M_Sender
ORDER BY M_Sender
";
$strUserFilter = populate_combo( $dbh, $strQuery, "fltfrom", $fltfrom );
$strQuery = "SELECT FROM_UNIXTIME( M_Sent, '%d/%b/%Y' ) AS MDate
FROM {$config['tbprefix']}Messages
WHERE M_Username = '$username_q'
AND M_Status $extra 'X'
GROUP BY MDate
ORDER BY M_Sent DESC
";
$strDateFilter = populate_combo( $dbh, $strQuery, "fltdate", $fltdate );
Step 1.4
Find this:
code:
// ----------------
// send the footer
$html -> send_footer();
BELOW IT ADD
code:
function populate_combo( &$dbh, $strSQL, $strControlName, $strChoice="" )
{
// This will create the option box
$strOutput = "";
$strSelected = "";
$arrReturned = array();
$strCr = chr(13);
$strOutput .= "<select name="$strControlName" class="buttons">$strCr";
if ( empty($strChoice) )
{
$strOutput .= "<option value="" selected="selected">No Filter$strCr";
}
else
{
$strOutput .= "<option value="">No Filter$strCr";
}
// Database call
$sth = $dbh -> do_query($strSQL);
while ( $arrReturned = $dbh -> fetch_array($sth) )
{
// Check for the selected option
if ( $strChoice == $arrReturned[0] )
{
$strSelected = "selected="selected"";
}
else
{
$strSelected = "";
}
$strOutput .= "<option value="{$arrReturned[0]}" $strSelected>{$arrReturned[0]}$strCr";
}
$strOutput .= "</select>$strCr";
$dbh -> finish_sth($sth);
return $strOutput;
}
Step 2 OPTIONAL:
For those who have applied the PM Limit modification (to show the private messages in pages) you need to also do the following:
Step 2.3
Find this:
code:
$prevstart = "<a href="{$config['phpurl']}/viewmessages.php?Cat=$Cat&page=$prev&box=$box">";
CHANGE it to this
code:
$prevstart = "<a href="{$config['phpurl']}/viewmessages.php?Cat=$Cat&page=$prev&box=$box&fltfrom=$fltfrom&fltdate=$fltdate">";
Step 1.3
Find this:
code:
$nextstart = "<a href="{$config['phpurl']}/viewmessages.php?Cat=$Cat&page=$next&box=$box">";
CHANGE it to this
code:
$nextstart = "<a href="{$config['phpurl']}/viewmessages.php?Cat=$Cat&page=$next&box=$box&fltfrom=$fltfrom&fltdate=$fltdate">";
Step 3
Open viewmessages.tmpl
Step 3.1
Find this:
code:
<form name="checkboxform1" method="post" action="{$config['phpurl']}/delete.php">
<input type="hidden" name="Cat" value="$Cat" />
<input type="hidden" name="box" value="$box" />
<table width="{$theme['tablewidth']}" align="center" cellpadding="1" cellspacing="1" class="tablesurround">
<tr>
<td>
<table cellpadding="{$theme['cellpadding']}" cellspacing="{$theme['cellspacing']}" width="100%" class="tableborders">
ABOVE IT ADD
code:
<form name="filterform1" method="post" action="{$config['phpurl']}/viewmessages.php">
<input type="hidden" name="Cat" value="$Cat" />
<input type="hidden" name="box" value="$box" />
<table width="{$theme['tablewidth']}" align="center" cellpadding="1" cellspacing="1" class="tablesurround">
<tr>
<td>
<table cellpadding="{$theme['cellpadding']}" cellspacing="{$theme['cellspacing']}" width="100%" class="tableborders">
<td class="tdheader" align="right">
Filter messages:
From: {$strUserFilter}
Date: {$strDateFilter}
<input type="submit" name="refreshpm" value="Refresh" class="buttons" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
This modification is particularly handy to my users who don't delete their PM's - neither do I (no space problems here
)
Enjoy!