<?
$page = "messages.php";
include "manager_header.php";

// CHECK THAT PMS ARE ALLOWED
if($group_info[allow_pms] != 1) { exit; }

if(isset($_POST['task'])) { $task = $_POST['task']; } elseif(isset($_GET['task'])) { $task = $_GET['task']; } else { $task = "main"; }
if(isset($_POST['s'])) { $s = $_POST['s']; } elseif(isset($_GET['s'])) { $s = $_GET['s']; } else { $s = "dd"; }







if($task == "read") {
if(!isset($_GET['pm_id']) OR $_GET['pm_id'] == "") { exit; } else { $pm_id = $_GET['pm_id']; }
if(isset($_GET['type'])) { $type = $_GET['type']; } if($type == "") { $type = "received"; }

// GET MESSAGE, SET TO VIEWED
if($type == "received") {

	$pm = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_pms WHERE pm_id='$pm_id'"));
	if($pm[to_u_id] != $user_info[u_id]) { exit; }
	if($pm[viewed] == 0) { mysql_query("UPDATE bhost_pms SET viewed='1' WHERE pm_id='$pm_id'"); }
	header("Location: messages.php?task=doread&pm_id=$pm_id");

} elseif($type == "sent") {

	$pm = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_pms_outbox WHERE pm_id='$pm_id'"));
	if($pm[from_u_id] != $user_info[u_id]) { exit; }
	$type = "&type=sent";
	header("Location: messages.php?task=doread&pm_id=$pm_id&type=sent");
}

exit;
}





// READ MESSAGE
if($task == "doread") {
if(!isset($_GET['pm_id']) OR $_GET['pm_id'] == "") { exit; } else { $pm_id = $_GET['pm_id']; }
if(isset($_GET['type'])) { $type = $_GET['type']; } if($type == "") { $type = "received"; }

if($type == "sent") {
$pm = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_pms_outbox WHERE pm_id='$pm_id'"));
if($pm[from_u_id] != $user_info[u_id]) { exit; }
} else {
$pm = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_pms WHERE pm_id='$pm_id'"));
if($pm[to_u_id] != $user_info[u_id]) { exit; }
}



$date = cdate($admin_info[signup_format_date], timezone($pm[date]));
$time = cdate($admin_info[signup_format_time], timezone($pm[date]));

$contents = nl2br($pm[contents]);

// CREATE ADD FRIEND LINK
if($group_info[allow_friends] == 1) { 
$friend = mysql_query("SELECT friend_u_id FROM bhost_friends WHERE friend_u_id='$pm[from_u_id]' LIMIT 1");

// AUTHOR IS NOT A FRIEND, SHOW LINK
if(mysql_num_rows($friend) == 0) { 
	$add_friend = "&nbsp;&nbsp;[<a href='".url("manager/view_friends.php?task=adddyn&new_u=$pm[from_username]", "")."'>$messages42</a>]";
}
}




// CREATE TITLE, SENDER AND RECEIVER TEXT
if($type == "sent") {

	$pagetitle = "<a href='messages.php?task=outbox'>$messages53</a>";
	$from_username = $user_info[username];
	$to_username = $pm[to_username];

} elseif($type == "received") {

	$pagetitle = "<a href='messages.php'>$messages52</a>";
	$from_username = $pm[from_username];
	$to_username = $user_info[username];
}





// SHOW MESSAGE
echo $head;
echo "
<h2>$pagetitle $messages33</h2>
<br>

<table cellpadding='0' cellspacing='0' class='message'>
<tr>
<td class='message_top1'><font class='bold'>$messages1</font></td>
<td class='message_top2'><a href='".url("profile", "", $pm[from_username])."'>$from_username</a> $add_friend</td>
</tr>
<tr>
<td class='message'><font class='bold'>$messages2</font></td>
<td class='message'><a href='".url("profile", "", $user_info[username])."'>$to_username</a></td>
</tr>
<tr>
<td class='message'><font class='bold'>$messages3</font></td>
<td class='message'>$pm[subject]</td>
</tr>
<tr>
<td class='message' valign='top'><font class='bold'>$messages41</font></td>
<td class='message'>$contents</td>
</tr>
</table>

<br>
<table cellpadding='0' cellspacing='0'>
<form action='messages.php' method='POST'>
<tr>
<td><input type='submit' name='submit' class='button' value='$messages4'>&nbsp;</td>
";

if($type == "received") {
echo "
<td><input type='submit' name='submit' class='button' value='$messages5'>&nbsp;</td>
";
}

echo "
<td><input type='submit' name='submit' class='button' value='$messages6'></td>
</tr>
<input type='hidden' name='pm_id' value='$pm_id'>
<input type='hidden' name='task' value='doread2'>
<input type='hidden' name='type' value='$type'>
</form>
</table>
";
echo $foot;
exit;
}















if($task == "doread2") {
if(isset($_GET['type'])) { $type = $_GET['type']; } if($type == "") { $type = "received"; }

$submit = stripslashes($_POST['submit']);
if(htmlentities($submit, ENT_QUOTES) == htmlentities(html_entity_decode($messages4, ENT_QUOTES), ENT_QUOTES)) {

if($type == "sent") {
	header("Location: messages.php?task=outbox");
} else {
	header("Location: messages.php");
}

exit;
} elseif(htmlentities($submit, ENT_QUOTES) == htmlentities(html_entity_decode($messages5, ENT_QUOTES), ENT_QUOTES)) {
$task = "reply";
} elseif(htmlentities($submit, ENT_QUOTES) == htmlentities(html_entity_decode($messages6, ENT_QUOTES), ENT_QUOTES)) {
$task = "delete";
} else { exit; }
}










if($task == "delete") {
if(isset($_GET['pm_id'])) { $pm_id = $_GET['pm_id']; } elseif(isset($_POST['pm_id'])) { $pm_id = $_POST['pm_id']; }
if(isset($_GET['type'])) { $type = $_GET['type']; } if($type == "") { $type = "received"; }
if($pm_id == "") { exit; }

// IF PM IS FROM INBOX
if($type == "received") {
	$pm = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_pms WHERE pm_id='$pm_id' AND to_u_id='$user_info[u_id]'"));
	mysql_query("DELETE FROM bhost_pms WHERE pm_id='$pm_id' AND to_u_id='$user_info[u_id]'");
	header("Location: messages.php");
	exit;
} elseif($type == "sent") {
	$pm = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_pms_outbox WHERE pm_id='$pm_id' AND from_u_id='$user_info[u_id]'"));
	mysql_query("DELETE FROM bhost_pms_outbox WHERE pm_id='$pm_id' AND from_u_id='$user_info[u_id]'");
	header("Location: messages.php?task=outbox");
	exit;
}

}






// DELETE MULTI OR COMPOSE MESSAGE
if($task == "divert") {

  	$return = $_POST['return'];
  	if(stripslashes(htmlentities($_POST['submit'], ENT_QUOTES)) == htmlentities(html_entity_decode($messages27, ENT_QUOTES), ENT_QUOTES)) {
 		
		$task = "send";

	} else {

		// DELETE MULTI
		if($return == "outbox") { 
			$pms = mysql_query("SELECT * FROM bhost_pms_outbox WHERE from_u_id='$user_info[u_id]' ORDER BY pm_id DESC");
  			while($pm_info = mysql_fetch_assoc($pms)) {
 				$var = "del_".$pm_info[pm_id];
 				if($_POST[$var] == "1") {
   					mysql_query("DELETE FROM bhost_pms_outbox WHERE pm_id='$pm_info[pm_id]' AND from_u_id='$user_info[u_id]'");
				}
			}

			header("Location: messages.php?task=outbox&s=$s");
 			exit;

		} else { 

			$pms = mysql_query("SELECT * FROM bhost_pms WHERE to_u_id='$user_info[u_id]' ORDER BY pm_id DESC");
  			while($pm_info = mysql_fetch_assoc($pms)) {
 				$var = "del_".$pm_info[pm_id];
 				if($_POST[$var] == "1") {
  	 				mysql_query("DELETE FROM bhost_pms WHERE pm_id='$pm_info[pm_id]' AND to_u_id='$user_info[u_id]'");
				}
			}
  			header("Location: messages.php?s=$s");
 			exit;
 		 }
	}
}










// MARK ALL MSGS IN INBOX AS READ
if($task == "markallread") {
$return = $_GET['return'];
if($return != "outbox") { $return = "messages.php"; } else { $return = "messages.php?task=outbox"; }
mysql_query("UPDATE bhost_pms SET viewed='1' WHERE to_u_id='$user_info[u_id]'");
header("Location: $return");
exit;
}










// SEND MESSAGE
if($task == "dosend") {
$to = str_replace(" ", "", $_POST['to']);
$to_friend = $_POST['to_friend'];
$subject = $_POST['subject'];
$message = $_POST['message'];

// CHECK IF TO FIELD IS BLANK
if($to == "" AND $to_friend == "") {
$error = "$messages7";
$task = "send";
}

if(!isset($error)) {
if($to != "" AND $to_friend != "") {
$task = "send";
$error = "$messages37";
}}

// CHECK IF MESSAGE FIELD IS BLANK
if(!isset($error)) {
if($message == "") {
$task = "send";
$error = "$messages8";
}}

// CHECK IF RECIPIENT EXISTS
if(!isset($error)) {
if($to != "") { $recepient = $to; } elseif($to_friend != "") { $recepient = $to_friend; }
$recepient_query = mysql_query("SELECT u_id, g_id, username FROM bhost_users WHERE username='$recepient'");
if(mysql_num_rows($recepient_query) != 1) { 
$task = "send";
$error = "$messages9";
}}

// CHECK IF RECIPIENT HAS FULL INBOX
if(!isset($error)) {
$recepient = mysql_fetch_assoc($recepient_query);
$rec_pms = mysql_num_rows(mysql_query("SELECT pm_id FROM bhost_pms WHERE to_u_id='$recepient[u_id]'"));
$rec_group = mysql_fetch_assoc(mysql_query("SELECT pms_max FROM bhost_groups WHERE g_id='$recepient[g_id]'"));
if($rec_pms >= $rec_group[pms_max]) {
$task = "send";
$error = "$messages10";
}}

// CHECK IF RECIPIENT IS THE SAME AS SENDER
if(!isset($error)) {
if($recepient[u_id] == $user_info[u_id]) {
$task = "send";
$error = "$messages11";
}}

// RATE LIMITER
if(!isset($error)) {
$last_pm = mysql_fetch_assoc(mysql_query("SELECT send_date FROM bhost_pms WHERE from_u_id='$user_info[u_id]' AND from_username='$user_info[username]' ORDER BY pm_id DESC LIMIT 1"));
if($last_pm[send_date] >= time()-15) {
$task = "send";
$error = "$messages47";
}}

// STRIP ANY HTML FROM MESSAGE
$subject = strip_tags($subject);
$contents = strip_tags($message, '<b><i><a>');

// SEND MESSAGE
if(!isset($error)) {
if($subject == "") { $subject = "$messages12"; }
$date = time();
mysql_query("INSERT INTO bhost_pms (from_u_id, from_username, to_u_id, subject, contents, send_date, viewed) VALUES ('$user_info[u_id]', '$user_info[username]', '$recepient[u_id]', '$subject', '$message', '$date', 0)");

// ADD TO OUTBOX
mysql_query("INSERT INTO bhost_pms_outbox (from_u_id, to_username, to_u_id, subject, contents, send_date) VALUES ('$user_info[u_id]', '$recepient[username]', '$recepient[u_id]', '$subject', '$message', '$date')");

echo $head;
echo "
<h2>$messages55</h2>
$messages56 <a href='".url("profile", "", "$recepient[username]")."'>$recepient[username]</a>$messages57
<br><br>
<form action='messages.php' method='POST'>
<input type='submit' class='button' value='$messages58'>
</form>
";
echo $foot;
exit;
}
}








// COMPOSE MESSAGE
if($task == "send" OR $task == "reply") {

$to = "";
$subject = "";
$message = "";

if(isset($_GET['to'])) { $to = $_GET['to']; }


if($task == "reply") {

	if(isset($_GET['pm_id'])) { $pm_id = $_GET['pm_id']; } elseif(isset($_POST['pm_id'])) { $pm_id = $_POST['pm_id']; }

	if($pm_id == "") { exit; }
	$pm = mysql_fetch_assoc(mysql_query("SELECT * FROM bhost_pms WHERE pm_id='$pm_id'"));
	if($pm[to_u_id] != $user_info[u_id]) { exit; }
	$subject = "RE: $pm[subject]";

	$message = "\n\n\n------------------------------\n$messages13 $pm[from_username]:\n\n$pm[contents]";

	$sender = mysql_fetch_assoc(mysql_query("SELECT u_id, username FROM bhost_users WHERE u_id='$pm[from_u_id]'"));
	$to = $sender[username];
	if($to == "") { $subject = ""; $message = ""; }
}

echo $head;
echo "
$messages14
<br>
"; 

if($error != "") {
	echo "<br>";
	show_error($error);
} 


// CREATE SEND TO FIELD
$friendlist = "";
if($group_info[allow_friends] == 1) {
$friends = mysql_query("SELECT bhost_friends.fr_id, bhost_friends.friend_u_id, bhost_users.username FROM bhost_friends LEFT JOIN bhost_users ON bhost_friends.friend_u_id=bhost_users.u_id WHERE bhost_friends.u_id='$user_info[u_id]' ORDER BY bhost_users.username");
if(mysql_num_rows($friends) > 0) {
$friendlist .= "<select name='to_friend'><option value=''>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";
while($friend = mysql_fetch_assoc($friends)) {
	$friend_info = mysql_fetch_assoc(mysql_query("SELECT username FROM bhost_users WHERE u_id='$friend[friend_u_id]'"));
	$friendlist .= "<option"; if($to_friend == $friend_info[username]) { $friendlist .= " SELECTED"; } $friendlist .= ">$friend_info[username]</option>";
}
$friendlist .= "</select>";
}
}

if($group_info[allow_friends] == 1 AND mysql_num_rows($friends) > 0) {
$sendto = "
<table cellpadding='0' cellspacing='0'>
<tr>
<td>$messages34<br>
<input type='text' name='to' class='text' maxlength='20' value='$to'>
</td>
<td><br>&nbsp;&nbsp;<font class='bold'>$messages35</font>&nbsp;&nbsp;</td>
<td>$messages36<br>
$friendlist
</td>
</tr>
</table>
";
} else {
$sendto = "
<input type='text' name='to' class='text' maxlength='20' value='$to'>
";
}

if($return == "outbox") { $return = "?task=outbox"; } else { $return = ""; }

echo "<br>
<table cellpadding='0' cellspacing='0' class='form'>
<form action='messages.php' method='POST'>
<tr>
<td class='form1'>$messages15</td>
<td class='form2'>
$sendto
</td>
</tr>
<tr>
<td class='form1'>$messages16</td>
<td class='form2'><input type='text' name='subject' size='58' class='text' maxlength='60' value='$subject'></td>
</tr>
<tr>
<td class='form1'>$messages17</td>
<td class='form2'><textarea name='message' rows='14' cols='60'>$message</textarea></td>
</tr>
</table>
<br>
<table cellpadding='0' cellspacing='0'>
<tr>
<td><input type='submit' class='button' value='$messages18'>&nbsp;</td>
<input type='hidden' name='task' value='dosend'>
</form>
<form action='messages.php$return' method='POST'>
<td><input type='submit' class='button' value='$messages19'></td>
</form>
</tr>
</table>
";
echo $foot;
exit;
}










// SHOW INBOX OR OUTBOX
if($task == "main" OR $task == "outbox") {

// PREPARE SORTING METHOD
$d = "dd";
$t = "t";
$f = "f";

if($s == "dd") {
	$sort = "send_date DESC";
	$d = "d";
} elseif($s == "d") {
	$sort = "send_date";
	$d = "dd";
} elseif($s == "t") {
	$sort = "subject";
	$t = "td";
} elseif($s == "td") {
	$sort = "subject DESC";
	$t = "t";
} elseif($s == "f") {
	if($task == "outbox") {
		$sort = "to_username, subject";	
	} else {
		$sort = "from_username, subject";
	}
	$f = "fd";
} elseif($s == "fd") {
	if($task == "outbox") {
		$sort = "to_username DESC, subject";
	} else {
		$sort = "from_username DESC, subject";
	}
	$f = "f";
} else {
	$sort = "send_date DESC";
	$d = "d";
	$s = "dd";
}



// GET TOTAL NEW PMS
$pms = mysql_num_rows(mysql_query("SELECT pm_id FROM bhost_pms WHERE to_u_id='$user_info[u_id]' AND viewed='0'"));



// DETERMINE AMOUNT OF SPACE FILLED, INCLUDE OUTBOX
$pms_total = mysql_num_rows(mysql_query("SELECT pm_id FROM bhost_pms WHERE to_u_id='$user_info[u_id]'"));
$pms_outbox_total = mysql_num_rows(mysql_query("SELECT pm_id FROM bhost_pms_outbox WHERE from_u_id='$user_info[u_id]'"));
$pms_total = $pms_total + $pms_outbox_total;
$total_allowed = $group_info[pms_max];
$percent = round((($pms_total / $total_allowed) * 100), 0);
if($percent >= 100) { $percent = 100; }


echo $head;


// SHOW INBOX OUTBOX MENU
$inbox_link = "$messages49";
$outbox_link = "$messages50";
$mark_all_read_link = "<a href='messages.php?task=markallread&return=$task'>$messages54</a>";

switch($task) {
	case "main": 
	$outbox_link = "<a href='messages.php?task=outbox'>$outbox_link</a> "; 
	$pagetitle = "$messages20";
	break;

	case "outbox": 
	$inbox_link = "<a href='messages.php'>$inbox_link</a> "; 
	$pagetitle = "$messages48";
	break;
}

echo "
<h2>$pagetitle</h2>
<font class='gray'>[</font> 
$inbox_link
<font class='gray'>]</font>
<font class='gray'>[</font> 
$outbox_link
<font class='gray'>]</font>
<font class='gray'>[</font> 
$mark_all_read_link
<font class='gray'>]</font>&nbsp;
";




// SHOW NEW MESSAGES
if($pms > 0) {
	echo "$messages21 $pms ";
	if($pms != 1) { echo "$messages24"; } else { echo "$messages44"; }
}

// SHOW PERCENT FULL
echo " $messages22 $percent% $messages23";

if($percent == 100) {
show_error("$messages25");
} elseif($percent >= 75) { 
show_error("$messages26");
} else {
echo "<br>";
}
echo "<br>";




// GET PMS
if($task == "main") {
$pms = mysql_query("SELECT * FROM bhost_pms WHERE to_u_id='$user_info[u_id]' ORDER BY $sort");
} elseif($task == "outbox") {
$pms = mysql_query("SELECT * FROM bhost_pms_outbox WHERE from_u_id='$user_info[u_id]' ORDER BY $sort");
}

$totalpms = mysql_num_rows($pms);



echo "
<table cellpadding='0' cellspacing='0'>
<form action='messages.php' name='pms' method='POST'>
<tr>
<td><input type='submit' name='submit' class='button' value='$messages27'>&nbsp;</td>
<td><input type='submit' name='submit' class='button' value='$messages28'></td>
</tr>
</table>
<br>

<script language='JavaScript'> 
<!--
var checkboxcount = 1;
function doCheckAll() {
if(checkboxcount == 0) {
with (document.pms) {
for (var i=0; i < elements.length; i++) {
if (elements[i].type == 'checkbox') {
elements[i].checked = false;
}}
checkboxcount = checkboxcount + 1;
window.document.pms.check.alt='Check All';
}
} else
with (document.pms) {
for (var i=0; i < elements.length; i++) {
if (elements[i].type == 'checkbox') {
elements[i].checked = true;
}}
checkboxcount = checkboxcount - 1;
window.document.pms.check.alt='Uncheck All';
}}
function changeAlt(imgObj,newAlt){
imgObj.alt = newAlt;
}
// -->
</SCRIPT>
";

// LIST PMS
if($totalpms == 0) { 
	if($task == "main") {
		$no_messages = "$messages32";
	} elseif($task == "outbox") {
		$no_messages = "$messages51";
	}

	echo "
	<table cellpadding='0' cellspacing='0'>
	<tr><td class='messages_none'>$no_messages</td></tr>
	</table>
	";

} else {


if($task == "outbox") {
	$from_to_header = $messages59;
	$outbox_url = "&task=outbox";
} else {
	$from_to_header = $messages30;
	$outbox_url = "";
}


echo "
<table cellpadding='0' cellspacing='0'>
<tr>
<td class='header2' style='padding-bottom: 5px;'><a href='javascript:doCheckAll()'><img src='../images/check.gif' id='check' border='0' alt='$messages29'></a></td>
<td class='header2'><a href='messages.php?s=$f$outbox_url'>$from_to_header</a></td>
<td class='header2'><a href='messages.php?s=$t$outbox_url'>$messages16</a></td>
<td class='header2'><a href='messages.php?s=$d$outbox_url'>$messages31</a></td>
<td class='header'>&nbsp;</td>
</tr>
";



while($pm = mysql_fetch_assoc($pms)) {

// GET APPROPRIATE USERNAME FOR MESSAGE
if($task == "outbox") {
$from_to_username = $pm[to_username];
} else {
$from_to_username = $pm[from_username];
}

// GET AVATAR AND SIZE DOWN
if($admin_info[allow_avatars] == 1) {

if($task == "outbox") {
$author = mysql_fetch_assoc(mysql_query("SELECT avatar FROM bhost_users WHERE u_id='$pm[to_u_id]' LIMIT 1"));
} else {
$author = mysql_fetch_assoc(mysql_query("SELECT avatar FROM bhost_users WHERE u_id='$pm[from_u_id]' LIMIT 1"));
}


$avatar = $author[avatar];

if($avatar == "") { 
	$avatar = "../images/noavatar.gif";
	$width = 40;
	$height = 40;
} else {
	// GET FILE DIMENSIONS
	$dimension = getimagesize($avatar);
	$width = $dimension[0];
	$height = $dimension[1];

	// MAKE THUMBNAILS
	while($width > 40 OR $height > 40) {
		$width = $width * .95;
		$height = $height * .95;
	}
}


$avatar = "
<td><a href='".url("profile", "", $from_to_username)."'><img src='$avatar' border='0' width='$width' height='$height' class='avatar'></a></td>
<td>&nbsp;&nbsp;</td>
";


}


if($task == "outbox") {
$from_link = "<a href='".url("profile", "", $from_to_username)."'>$pm[to_username]</a>";
} else {
$from_link = "<a href='".url("profile", "", $from_to_username)."'>$pm[from_username]</a>";
}

$from = "
<table cellpadding='0' cellspacing='0'>
<tr>
$avatar
<td>$from_link &nbsp;</td>
</tr>
</table>
";

// PREPARE OUTBOX MESSAGES, ADD TO READ MSG URL
if($task == "outbox") { $type = "&type=sent"; }

if(str_replace(" ", "", $pm[subject]) == "") { $subject = "$messages12"; } else { $subject = $pm[subject]; }
$subject = "<a href='messages.php?task=read&pm_id=$pm[pm_id]$type'>$subject</a>";

$date = cdate($admin_info[signup_format_date], timezone($pm[send_date]));
$date .= ", "; 
$date .= cdate($admin_info[signup_format_time], timezone($pm[send_date]));
$date .= "</font>";

// MAKE UNREAD SUBJECTS BOLD IF VIEWING INBOX
if($task == "main") {
	$b1 = ""; $b2 = "";
	if($pm[viewed] != 1) { $b1 = "<font class='bold'>"; $b2 = "</font>"; }
}



// CREATE OPTIONS
$options = "
<a href='messages.php?task=read&pm_id=$pm[pm_id]$type'>$messages38</a>
";
if($task == "main") {
$options .= "
 <font class='gray'>|</font> <a href='messages.php?task=reply&pm_id=$pm[pm_id]$type'>$messages39</a>
";
}
$options .= "
 <font class='gray'>|</font> <a href='messages.php?task=delete&pm_id=$pm[pm_id]$type'>$messages40</a>
";



echo "
<tr>
<td class='list1a' NOWRAP style='padding: 3px;'><input type='checkbox' name='del_$pm[pm_id]' value='1'></td>
<td class='list1a' NOWRAP>$from</td>
<td class='list1a'>$b1$subject$b2&nbsp;&nbsp;</td>
<td class='list1a' NOWRAP>$date&nbsp;&nbsp;</td>
<td class='list1b' NOWRAP>$options</td>
</tr>
";
}}

echo "
</table>
<br>
";


if($totalpms > 5) {
echo "
<table cellpadding='0' cellspacing='0'>
<tr>
<td><input type='submit' name='submit' class='button' value='$messages27'>&nbsp;</td>
";
if($totalpms != 0) { echo "<td><input type='submit' name='submit' class='button' value='$messages28'></td>"; }
echo "
</tr>
</table>
";
}

echo "
<input type='hidden' name='task' value='divert'>
<input type='hidden' name='return' value='$task'>
<input type='hidden' name='s' value='$s'>
</form>
";

echo $foot;
exit;
}