<?php
//v1.0.4 www.bcoos.net 2006/10 GPL
// www.bcoos.net 2006-09 1.0.2 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']) ) {
	$pm = new XoopsPM(intval($_POST['msg_id']));
	if ($pm->getVar('to_userid') == $xoopsUser->getVar('uid')) {
		$pm->delete();
		redirect_header('viewpmsg.php', 1, _PM_DELETED);
		exit();
	}
}
$start          = !empty($_GET['start']) ? intval($_GET['start']) : 0;
$total_messages = !empty($_GET['total_messages']) ? intval($_GET['total_messages']) : 0;
$pm_arr         =& XoopsPM::getAllPM(array("to_userid=".$xoopsUser->getVar("uid").""), true, "msg_time", "ASC", 1, $start);
if (!defined('EXOOPS_PM_INCLUDED')) {
	define('EXOOPS_PM_INCLUDED', 1);
}
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="viewpmsg.php"><?php echo _PM_INBOX;?></a>
<b>&raquo;&raquo;</b>
<?php echo _PM_PRIVATEMESSAGE;?>
<br /><br />
<script type="text/javascript">
function delete_msg(id) {
var del = confirm("<?php echo _PM_DELETE_PROMPT;?>");
if ( del ) {
	xoopsGetElementById("delete" + id).submit();
}
}
</script>
<?php
if ( empty($pm_arr) ) {
	echo _PM_YOUDONTHAVE;
	} else {
		$pm_arr[0]->setRead();
		$allow_html = $bcoosConfig['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);
		$subject_image = "<img src='".XOOPS_URL."/images/subject/".$pm_arr[0]->getVar("msg_image", "E")."' alt='' />";
		$subject       = $pm_arr[0]->getVar("subject");
		$text          = $pm_arr[0]->getVar("msg_text");
		$post_date     = formatTimestamp($pm_arr[0]->getVar("msg_time"), 'm');
		$message_id    = $pm_arr[0]->getVar("msg_id");
		$delete_image  = "<a href='javascript:delete_msg(\"$message_id\");'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."delete.gif' alt='"._DELETETHISPOST."' /></a>";
		$poster = new XoopsUser($pm_arr[0]->getVar("from_userid"));
		if ($poster->isActive()) {
			$userrank = $poster->rank();
			if ( $userrank['image'] ) {
				$rank_image = "<img src='".XOOPS_URL."/images/ranks/".$userrank['image']."' alt='".$userrank['title']."' />";
			}
			if ( $userrank['title'] ) {
				$rank_title = $userrank['title'];
			}
			if ( $poster->getVar("user_avatar") != "" ) {
				$avatar_image = "<img src='".XOOPS_URL."/images/avatar/".$poster->getVar("user_avatar")."' alt='' />";
			}
			if ( $poster->getVar("user_from") != "" ) {
				$user_from = _PM_FROMC."".$poster->getVar("user_from");
			}
			if ( $poster->isOnline() ) {
				$username      = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$poster->getVar("uid").'"><font color="#FFOOOO">'.$poster->getVar("uname").'</font></a>';
			} else 
			{
			$username      = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$poster->getVar("uid").'">'.$poster->getVar("uname").'</a>';
			}
			if ( $xoopsUser->isAdmin() || $poster->getVar("user_viewemail") == 1 ) {
				$email_image = "<a href='mailto:".$poster->getVar("email", "E")."'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."email.gif' alt='".sprintf(_PM_SENDEMAIL, $poster->getVar("uname"))."' /></a>";
			}
			if ( $poster->getVar("url") != "" ) {
				$www_image = "<a href='".$poster->getVar("url", "E")."' ><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."www.gif' alt='www' /></a>";
			}
			if ( $poster->getVar("user_icq") != "" ) {
				$icq_image = "<a href='http://wwp.icq.com/scripts/search.dll?to=".$poster->getVar("user_icq", "E")."'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."icq_add.gif' alt='"._PM_ADDTOLIST."' /></a>";
			}
			if ( $poster->getVar("user_aim") != "" ) {
				$aim_image = "<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/".$bcoosConfig['iconset']."aim.gif' alt='aim' /></a>";
			}
			if ( $poster->getVar("user_yim") != "" ) {
				$yim_image = "<a href='http://edit.yahoo.com/config/send_webmesg?.target=".$poster->getVar("user_yim","E")."&.src=pg'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."yim.gif' alt='yim' /></a>";
			}
			if ( $poster->getVar("user_msnm") != "" ) {
				$msnm_image = "<a href='".XOOPS_URL."/userinfo.php?uid=".$poster->getVar("uid")."'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."msnm.gif' alt='msnm' /></a>";
			}
			
			$profile_image = "<a href='".XOOPS_URL."/userinfo.php?uid=".$poster->getVar("uid")."'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."profile.gif' alt='"._PM_PROFILE."' /></a>";
			$reply_image   = "<a href='javascript:openWithSelfMain(\"".XOOPS_URL."/pmlite.php?reply=1&amp;msg_id=".$pm_arr[0]->getVar("msg_id")."\",\"pmlite\",360,290);'><img src='".XOOPS_URL."/images/icons/".$bcoosConfig['iconset']."pen.gif' alt='"._REPLY."' /></a>";
			$reg_date   = _JOINED;
			$reg_date  .= formatTimestamp($poster->getVar("user_regdate"), "s");
			$posts      = _POSTS;
			$posts     .= $poster->getVar("posts");
			$user_from  = _FROM;
			$user_from .= $poster->getVar("user_from");
			$user_from .=":&nbsp;";
			if ( ($poster->getVar("attachsig") == 1) && ($poster->getVar("user_sig") != "") ) {
				$text .= "<br /><br />--<br />";
				$text .= $myts->makeTareaData4Show($poster->getVar("user_sig", "N"), 0, 1, 1);
			}
			} else {
				$username = $bcoosConfig['anonymous'];
			}
		showThread(
				1,
				$subject_image,
				$subject,
				$text,
				$post_date,
				$ip_image,
				$reply_image,
				$edit_image,
				$delete_image,
				$username,
				$rank_title,
				$rank_image,
				$avatar_image,
				$reg_date,
				$posts,
				$user_from,
				$online_image,
				$profile_image,
				$pm_image,
				$email_image,
				$www_image,
				$icq_image,
				$aim_image,
				$yim_image,
				$msnm_image);
		echo "
		<table width='100%'><tr>
		<form action='readpmsg.php' method='post' id='delete".$pm_arr[0]->getVar("msg_id")."' name='delete".$pm_arr[0]->getVar("msg_id")."'>
		<td align='right'>
		<input type='hidden' name='delete' value='1' />
		<input type='hidden' name='msg_id' value='".$pm_arr[0]->getVar("msg_id")."' />
		<input type='image' class='image' src='".XOOPS_URL."/images/pixel.gif' name='submit' value='1' />";
		$previous = ($start - 1);
		$next     = ($start + 1);
		if ( $previous >= 0 ) {
			echo "<a href='readpmsg.php?start=".$previous."&amp;total_messages=".$total_messages."'>"._PM_PREVIOUS."</a> | ";
			} else {
				echo _PM_PREVIOUS." | ";
			}
		if ($next < $total_messages) {
			echo "<a href='readpmsg.php?start=".$next."&amp;total_messages=".$total_messages."'>"._PM_NEXT."</a>";
			} else {
				echo _PM_NEXT;
			}
		echo "</td></form></tr></table>";
	}
CloseTable();
include_once('footer.php');
?>
