<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 GPL
//v1.2 www.bcoos.net 2006-08 GPL
//v1.1 www.exoops.info 2006/08 GPL
// ------------------------------------------------------------------------- //
//               E-Xoops: Content Management for the Masses                  //
//                       < http://www.e-xoops.com >                          //
// ------------------------------------------------------------------------- //
// Original Author: The Xoops Project
// Author Website : http://www.xoops.org
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //
$xoopsOption['pagetype'] = 'pmsg';
$xoopsOption['page_style'] = 8;
include_once('mainfile.php');
include_once(XOOPS_ROOT_PATH.'/class/xoopspm.php');
if (!$xoopsUser) {
	$errormessage = _PM_SORRY.'<br />'._PM_PLZREG;
	redirect_header('user.php', 2, $errormessage);
exit();
}
// ------------------------------------------------------------------------- //
if ( !empty($_POST['delete_messages']) ) {
	$size = count($_POST['msg_id']);
	if (empty($size)) {
		redirect_header('viewpmsg.php', 1, _TAKINGBACK);
		exit();
	}
	$msg  = $_POST['msg_id'];
	for ($i=0; $i<$size; $i++) {
		$pm = new XoopsPM($msg[$i]);
		if ($pm->getVar('to_userid') == $xoopsUser->getVar('uid')) {
			$pm->delete();
		}
	}
redirect_header('viewpmsg.php', 1, _PM_DELETED);
exit();
}
if (!defined('EXOOPS_PM_INCLUDED')) {
	define('EXOOPS_PM_INCLUDED', 1);
}
include_once('header.php');
$pm_arr         =& XoopsPM::getAllPM(array("to_userid='".$xoopsUser->getVar("uid")."'"), true);
$total_messages = count($pm_arr);
$max_pms        = intval($bcoosConfig['max_pms']);
if (!empty($total_messages)) {
	$percent = empty($max_pms) ? 0 : round(($total_messages/$max_pms) * 100);
	} else {
		$percent = 0;
	}
OpenTable();
?>
<table align="right"><tr>
<td width="150"><?php echo _PM_USAGE;?>: <?php echo printf("%d %%", $percent);?></td>
</tr><tr>
<td class="bg2" width="150"><img src="<?php echo XOOPS_URL;?>/images/pm_bg.gif" height="10" width="<?php echo $percent;?>%" /></td>
</tr></table>
<h4><?php echo _PM_PRIVATEMESSAGE;?></h4>
<a href="<?php echo XOOPS_URL;?>/userinfo.php?uid=<?php echo $xoopsUser->getVar("uid");?>"><?php echo _PM_PROFILE;?></a>
<b>&raquo;&raquo;</b>
<?php echo _PM_INBOX;?><br /><br />
<table border="0" align="center" cellspacing="1" cellpadding="2" width="100%"><tr class="bg2">
<form name="prvmsg" method="post" action="viewpmsg.php" onsubmit="return confirm('<?php echo _PM_DELETE_PROMPT;?>')">
<td class="bg2" width="1%" align="center"><input name="allbox" id="allbox" onclick="xoopsCheckAll('prvmsg', 'allbox');" type="checkbox" class="checkbox" value="<?php echo _ALL;?>" /></td>
<td class="bg2" width="1%" align="center"><img src="images/down.gif" alt="" border="0" /></td>
<td colspan="1"><b><?php echo _PM_FROM;?>:</b></td>
<td><b><?php echo _SUBJECT;?>:</b></td>
<td align="center" width="1%"><b><?php echo _DATE;?></b></td>
</tr>
<?php
if ($total_messages == 0) {
	echo "<tr><td class='bg3' colspan='5' align='center'>"._PM_YOUDONTHAVE."</td></tr>";
	$display = 0;
	} else {
		$display = 1;
	}
$count = 0;
foreach ($pm_arr as $pm_ele) {
	if ($bg1 == 'bg3') {
		$bg1 = 'bg1';
		$bg3 = 'bg3';
		} else {
			$bg1 = 'bg3';
			$bg3 = 'bg1';
		}
	echo "<tr align='left'><td class='bg2' valign='top' align='center' width='1%'><input class='checkbox' type='checkbox' id='msg_id[]' name='msg_id[]' value='".$pm_ele->getVar("msg_id")."' /></td>";
	if ( $pm_ele->getVar("read_msg") == "1" ) {
		echo "<td valign='top' align='center' class='$bg1' width='1%'>&nbsp;</td>";
		} else {
			echo "<td valign='top' align='center' class='$bg1' width='1%'><img src='images/read.gif' alt='"._PM_NOTREAD."' border='0' /></td>";
		}
	//echo "<td class='$bg3' valign='top' align='center' width='1%'><img src='".XOOPS_URL."/images/subject/".$pm_ele->getVar("msg_image", "E")."' alt='' border='0' /></td>";
	$postername = XoopsUser::getUnameFromId($pm_ele->getVar("from_userid"));
	echo "<td class='$bg1' width='1%' valign='middle' nowrap>";
	// no need to show deleted users
	if ($postername) {
		echo "<a href='".XOOPS_URL."/userinfo.php?uid=".$pm_ele->getVar("from_userid")."'>".$postername."</a>";
		} else {
			echo $bcoosConfig['anonymous'];
		}
	echo "</td>";
	echo "<td class='$bg3' valign='middle'><a href='readpmsg.php?start=$count&amp;total_messages=$total_messages'><img src='".XOOPS_URL."/images/subject/".$pm_ele->getVar("msg_image", "E")."' alt='' border='0' /></a> <a href='readpmsg.php?start=$count&amp;total_messages=$total_messages'>".$pm_ele->getVar("subject")."</a></td>";
	echo "<td class='$bg1' valign='middle' align='center' nowrap>".formatTimestamp($pm_ele->getVar("msg_time"), 'm')."</td></tr>";
$count++;
}
echo "
<tr class='bg2' align='left'>
<td colspan='5' align='left'>
<a href='javascript:openWithSelfMain(\"".XOOPS_URL."/pmlite.php?send=1\",\"pmlite\",420,330);' value='"._SEND."'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."pm.gif' alt='"._SEND."' border='0' /></a>";
if ($display == 1) {
	echo "
	<input type='hidden' name='delete_messages' value='1' />
	<input type='image' class='image' src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."delete.gif' name='submit' alt='"._DELETE."' />";
}
echo '</td></tr></form></table>';
CloseTable();
include_once('footer.php');
?>
