<?php

/************************************************************************/
/* PHP-NUKE: Advanced Content Management System                         */
/* ============================================                         */
/*                                                                      */
/* Copyright (c) 2002 by Francisco Burzi                                */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* =========================                                            */
/* Part of phpBB integration                                            */
/* Copyright (c) 2001 by                                                */
/*    Richard Tirtadji AKA King Richard (rtirtadji@hotmail.com)         */
/*    Hutdik Hermawan AKA hotFix (hutdik76@hotmail.com)                 */
/* http://www.phpnuke.web.id                                            */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);

include("modules/".$module_name."/functions.php");
include("modules/".$module_name."/auth.php");

if (!is_user($user)) {
    Header("Location: modules.php?name=Your_Account");
} else {	
/*
    if (isset($reply)) {
	global $msg_id;
	Header("Location: modules.php?name=$module_name&file=reply&reply=1&msg_id=$myrow[msg_id]");
	exit();
    }

    if (isset($delete)) {
	Header("Location: modules.php?name=$module_name&file=reply&delete=1&msg_id=$myrow[msg_id]");
	exit();
    }
*/
    include('header.php');
    $user2 = base64_decode($user);
    $userdata = explode(":", $user2);
    if (!$result = check_user_pw($userdata[1],$userdata[2],$db,$system))
    $userdata = get_userdata($userdata[1], $db);
    $sql = "SELECT * FROM ".$prefix."_priv_msgs WHERE to_userid = '$userdata[uid]' LIMIT $start,1";
    $resultID = sql_query($sql, $dbi);
    if (!$resultID) {
	forumerror(0005);
    } else {
	$myrow = sql_fetch_array($resultID, $dbi);
	$sql = "UPDATE ".$prefix."_priv_msgs SET read_msg='1' WHERE msg_id='$myrow[msg_id]'";
	$result = sql_query($sql, $dbi);
	    if (!$result) {
	        forumerror(0005);
	    }
    }
    OpenTable();
    echo "<center><font class=\"title\"><b>"._PRIVATEMESSAGE."</b></font><br><br><font class=\"content\">[ <a href=\"modules.php?name=$module_name\">"._INDEX."</a> | <i>$myrow[subject]</i> ]</font></center>";
    CloseTable();
    echo "<br>";

    if (is_user($user)) {
	include("modules/Your_Account/navbar.php");
	OpenTable();
	nav();
	CloseTable();
	echo "<br>";
    }

    OpenTable();
    echo "<table border=\"0\" cellpadding=\"1\" cellpadding=\"0\" valign=\"top\" width=\"100%\"><tr><td>"
	."<table border=\"0\" cellpadding=\"3\" cellpadding=\"1\" width=\"100%\">"
	."<tr bgcolor=\"$bgcolor3\" align=\"left\">"
	."<td width=\"20%\" colspan=\"2\" align=\"center\"><font class=\"tiny\" color=\"$textcolor2\"><b>"._FROM."</b></font></td>"
	."</tr>";
    if (!sql_num_rows($resultID, $dbi)) {
	echo "<td bgcolor=\"$bgcolor1\" colspan=\"2\" align=\"center\">"._DONTHAVEMESSAGES."</td></tr>\n";
    } else {
	echo "<tr bgcolor=\"$bgcolor2\" align=\"left\">\n";
	$posterdata = get_userdata_from_id($myrow[from_userid], $db);
	echo "<td valign=\"top\"><b>$posterdata[uname]</b><br><br>\n";
	if ($posterdata[user_from] != "") {
	    echo "<font class=\"content\">"._FROM.": $posterdata[user_from]</font><br><br>\n";
	}
	if ($posterdata[user_avatar] != "")
	echo "<img src='images/forum/avatar/$posterdata[user_avatar]' alt=\"\">\n"
	    ."</td><td><img src=\"images/forum/subject/$myrow[msg_image]\" alt=\"\">&nbsp;<b>$myrow[subject]</b> <i>("._SENT.": $myrow[msg_time])</i>"
	    ."<br><img src=\"images/blackpixel.gif\" width=\"100%\" height=\"1\"><br><br><br>\n";
	$message = stripslashes($myrow[msg_text]);
	$message = eregi_replace("\[addsig]", "<br>-----------------<br>".$posterdata[user_attachsig], bbencode_priv($message));
	$message = strip_tags($message, '<br><b><u><i><a><li><strong><blockquote><ul><ol><img>');
	echo $message . "<br><br><br>"
	    ."<img src=\"images/blackpixel.gif\" width=\"100%\" height=\"1\">\n"
	    ."&nbsp;<a href=\"modules.php?name=Your_Account&amp;op=userinfo&uname=$posterdata[uname]\"><img src=\"images/forum/icons/profile.gif\" border=\"0\" alt=\"\"></a><font class=\"tiny\">"._PROFILE."</font>\n";
	if($posterdata["femail"] != 0) 
	    echo "&nbsp;&nbsp;<a href=\"mailto:$posterdata[femail]\"><IMG SRC=\"images/forum/icons/email.gif\" border=\"0\" alt=\"\"></a><font class=\"tiny\">"._EMAIL."</font>\n";
	if($posterdata["url"] != '' AND $posterdata[url] != "http://") {
	    echo "&nbsp;&nbsp;<a href=\"$posterdata[url]\" TARGET=\"_blank\"><IMG SRC=\"images/forum/icons/www_icon.gif\" border=0 Alt=\"\"></a><font class=tiny>www</font>\n";
	}
	if($posterdata["user_icq"] != '')
	    echo "&nbsp;&nbsp;<a href=\"http://wwp.mirabilis.com/$posterdata[icq]\" TARGET=\"_blank\"><IMG SRC=\"http://wwp.icq.com/scripts/online.dll?icq=$posterdata[user_icq]&img=5\" border=0\" Alt=\"\"></a>";
	if($posterdata["user_aim"] != '')
     	    echo "&nbsp;<a href=\"aim:goim?screenname=$posterdata[user_aim]&message=Hi+$posterdata[user_aim].+Are+you+there?\"><img src=\"images/forum/icons/aim.gif\" border=\"0\" Alt=\"\"></a><font class=tiny>aim</font>";
	if($posterdata["user_yim"] != '')
     	    echo "&nbsp;<a href=\"http://edit.yahoo.com/config/send_webmesg?.target=$posterdata[user_yim]&.src=pg\"><img src=\"images/forum/icons/yim.gif\" border=\"0\" Alt=\"\"></a>";
	if($posterdata["user_msnm"] != '')
     	    echo "&nbsp;<a href=\"modules.php?name=Your_Account&amp;op=userinfo&uname=$posterdata[uname]\"><img src=\"images/forum/icons/msnm.gif\" border=\"0\" Alt=\"\"></a>";
	echo "</td></tr></table></td></tr></table>"
	    ."<table border=\"0\" width=\"99%\" cellspacing=\"0\" cellpaddin=\"0\" align=\"center\"><tr><td>"
	    ."<table border=\"0\">"
	    ."<tr align=\"left\"><td align=\"left\">"
	    ."<form action=\"modules.php?name=$module_name&file=reply\" method=\"post\"><input type=\"hidden\" name=\"msg_id\" value=\"$myrow[msg_id]\"><input type=\"submit\" name=\"reply\" value=\""._REPLY."\"></form>\n"
	    ."</td><td>"
	    ."<form action=\"modules.php?name=$module_name&file=reply\" method=\"post\"><input type=\"hidden\" name=\"msg_id\" value=\"$myrow[msg_id]\"><input type=\"submit\" name=\"delete\" value=\""._DELETE."\"></form>\n"
	    ."</td></tr></table>"
	    ."</td><td align=\"right\">";
	$previous = $start-1;
	$next = $start+1;
	if ($previous >= 0) {
	    echo "<a href=\"modules.php?name=$module_name&file=read&start=$previous&total_messages=$total_messages\">"._PREVIOUSMESSAGE."</a> | ";
	} else {
	    echo ""._PREVIOUSMESSAGE." | ";
	}
	if ($next < $total_messages) {
	    echo "<a href=\"modules.php?name=$module_name&file=read&start=$next&total_messages=$total_messages\">"._NEXTMESSAGE."</a></font>&nbsp;";
	} else {
	    echo ""._NEXTMESSAGE."</font>&nbsp;";
	}
    }
    echo "</font></td></tr></table>";
    CloseTable();
}
include('footer.php');

?>