<?php
// -------------------------------------------------------------------------//
//			                 RUNCMS                                         //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: The Xoops Project
// Author Website : http://www.xoops.org
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //

include_once('../../mainfile.php');
include_once('class/pm.class.php');

if (!$xoopsUser) {
	$errormessage = _PM_SORRY.'<br />'._PM_PLZREG;
	redirect_header('user.php', 2, $errormessage);

exit();
}

// ------------------------------------------------------------------------- //


if ( !empty($HTTP_POST_VARS['delete']) ) {
	$pm = new PM(intval($HTTP_POST_VARS['msg_id']));
	if ($pm->getVar('to_userid') == $xoopsUser->getVar('uid')) {
		$pm->delete();
		redirect_header('index.php', 1, _PM_DELETED);
		exit();
	}
}

$start          = !empty($HTTP_GET_VARS['start']) ? intval($HTTP_GET_VARS['start']) : 0;
$total_messages = !empty($HTTP_GET_VARS['total_messages']) ? intval($HTTP_GET_VARS['total_messages']) : 0;
$pm_arr         =& PM::getAllPM(array("to_userid=".$xoopsUser->getVar("uid").""), true, "msg_time", "ASC", 1, $start);

include_once('../../header.php');
OpenTable();
?>

<h4><?php echo _PM_PRIVATEMESSAGE;?></h4>
<br /><a href="<?php echo XOOPS_URL;?>/userinfo.php?uid=<?php echo $xoopsUser->getVar("uid");?>"><?php echo _PM_PROFILE;?></a>
<b>&raquo;&raquo;</b>
<a href="index.php"><?php echo _PM_INBOX;?></a>
<b>&raquo;&raquo;</b>
<?php echo _PM_PRIVATEMESSAGE;?>
<br /><br />
<table border="0" cellpadding="1" cellpadding="2"  width="100%"><tr class="bg2">
<td colspan="2" align="left"><b><?php echo _PM_FROM;?>:</b></td>
</tr>

<?php
if ( empty($pm_arr) ) {
	echo "<tr><td class='bg3' colspan='2' align='center'>"._PM_YOUDONTHAVE."</td></tr>";
	} else {
		$pm_arr[0]->setRead();
		$allow_html = $xoopsConfig['allow_html'] ? 1 : 0;
		$pm_arr[0]->setVar('allow_html', $allow_html);
		$pm_arr[0]->setVar('allow_smileys', 1);
		$pm_arr[0]->setVar('allow_bbcode', 1);

		echo "<tr class='bg3' align='left'>";
		$poster = new XoopsUser($pm_arr[0]->getVar("from_userid"));
		if ( !$poster->isActive() ) {
			$poster = false;
		}
		echo "<td valign='top' width='1%' nowrap>";
		if ($poster != false) {
			echo "<b>".$poster->getVar("uname")."</b><br />";
			$userrank = $poster->rank();
			if ( $userrank['image'] ) {
				echo "<img src='".XOOPS_URL."/images/ranks/".$userrank['image']."' alt='".$userrank['title']."' /><br />";
			}
			if ( $poster->getVar("user_avatar") != "" ) {
				echo "<img src='".XOOPS_URL."/images/avatar/".$poster->getVar("user_avatar")."' alt='' /><br />";
			}
			if ( $poster->getVar("user_from") != "" ) {
				echo _PM_FROMC."".$poster->getVar("user_from")."<br /><br />";
			}
			if ( $poster->isOnline() ) {
				echo "<span style='color:#ee0000;font-weight:bold;'>"._ONLINE."</span><br /><br />";
			}
			} else {
				echo $xoopsConfig['anonymous']; // we need to do this for deleted users
			}
		echo "
		</td><td>
		<img src='".XOOPS_URL."/images/subject/".$pm_arr[0]->getVar("msg_image", "E")."' alt='' />
		"._PM_SENTC."".formatTimestamp($pm_arr[0]->getVar("msg_time"), 'm')."
		<hr /><b>".$pm_arr[0]->getVar("subject")."</b>
		<br /><br />".$pm_arr[0]->getVar("msg_text")."<br /><hr />";

		if ( $poster != false ) {
			echo "<a href='".XOOPS_URL."/userinfo.php?uid=".$poster->getVar("uid")."'><img src='".XOOPS_URL."/images/icons/profile.gif' alt='"._PM_PROFILE."' /></a>";
			if ( $poster->getVar("user_viewemail") == 1 ) {
				echo "<a href='mailto:".$poster->getVar("email", "E")."'><img src='".XOOPS_URL."/images/icons/email.gif' alt='";
				printf(_PM_SENDEMAIL, $poster->getVar("uname"));
				echo "' /></a>";
			}
			$posterurl = $poster->getVar("url");
			if ( $posterurl != "" ) {
				echo "<a href='".$posterurl."' target='_blank'><img src='".XOOPS_URL."/images/icons/www.gif' alt='www' /></a>\n";
			}
			if ( $poster->getVar("user_icq") != "" ) {
				echo "<a href='http://wwp.icq.com/scripts/search.dll?to=".$poster->getVar("user_icq", "E")."'><img src='".XOOPS_URL."/images/icons/icq_add.gif' alt='"._PM_ADDTOLIST."' /></a>";
			}
			if ( $poster->getVar("user_aim") != "" ) {
				echo "<a href='aim:goim?screenname=".$poster->getVar("user_aim", "E")."&amp;message=Hi+".$poster->getVar("user_aim", "E")."+Are+you+there?'><img src='".XOOPS_URL."/images/icons/aim.gif' alt='aim' /></a>";
			}
			if ( $poster->getVar("user_yim") != "" ) {
				echo "<a href='http://edit.yahoo.com/config/send_webmesg?.target=".$poster->getVar("user_yim","E")."&.src=pg'><img src='".XOOPS_URL."/images/icons/yim.gif' alt='yim' /></a>";
			}
			if ( $poster->getVar("user_msnm") != "" ) {
				echo "<a href='".XOOPS_URL."/userinfo.php?uid=".$poster->getVar("uid")."'><img src='".XOOPS_URL."/images/icons/msnm.gif' alt='msnm' /></a>";
			}
			} else {
				echo "&nbsp;";
			}
		echo "
		</td></tr>
		<tr class='bg1' align='right'><td colspan='2' align='right'>";

		$previous = ($start - 1);
		$next     = ($start + 1);

		if ( $previous >= 0 ) {
			echo "<a href='read.php?start=".$previous."&amp;total_messages=".$total_messages."'>"._PM_PREVIOUS."</a> | ";
			} else {
				echo _PM_PREVIOUS." | ";
			}
		if ($next < $total_messages) {
			echo "<a href='read.php?start=".$next."&amp;total_messages=".$total_messages."'>"._PM_NEXT."</a>";
			} else {
				echo _PM_NEXT;
			}
		echo "
		</td>
		</tr><tr class='bg2' align='left'>
		<td colspan='2' align='left'>
		<form action='read.php' method='post' name='delete".$pm_arr[0]->getVar("msg_id")."'>";
		if ( $poster != false ) {
			echo "<a href='pmlite.php?reply=1&amp;msg_id=".$pm_arr[0]->getVar("msg_id")."'><img src='".XOOPS_URL."/images/icons/reply.gif' alt='"._REPLY."' /></a>";
		}
		echo "
		<input type='hidden' name='delete' value='1' />
		<input type='hidden' name='msg_id' value='".$pm_arr[0]->getVar("msg_id")."' />
		<a href='#".$pm_arr[0]->getVar("msg_id")."' onclick='javascript:document.delete".$pm_arr[0]->getVar("msg_id").".submit();'><img src='".XOOPS_URL."/images/icons/delete.gif' alt='"._DELETETHISPOST."' /></a>
		</td></tr></form>";
	}
echo '</table>';

CloseTable();
include_once('../../footer.php');
?>
