<?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($send)) {
	Header("Location: modules.php?name=$module_name&file=reply&send=1");
	exit();
    }
    include('header.php');
    title(""._PRIVATEMESSAGES."");
    if (is_user($user)) {
	include("modules/Your_Account/navbar.php");
	OpenTable();
	nav();
	CloseTable();
	echo "<br>";
    }
    $user = base64_decode($user);
    $userdata = explode(":", $user);
    if (!$result = check_user_pw($userdata[1],$userdata[2],$system))
    $userdata = get_userdata($userdata[1]);
    $sql = "SELECT * FROM ".$prefix."_priv_msgs WHERE (to_userid='$userdata[uid]')";
    $resultID = sql_query($sql, $dbi);
    if (!$resultID) {
	forumerror(0005);
    }
    OpenTable();
    echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" align=\"center\" valign=\"top\" width=\"100%\"><tr><td>"
	."<table border=\"0\" cellspacing=\"1\" cellpadding=\"1\" width=\"100%\">"
	."<form name=\"prvmsg\" method=\"post\" action=\"modules.php?name=$module_name\">"
	."<input type=\"hidden\" name=\"file\" value=\"reply\">"
	."<tr bgcolor=\"$bgcolor3\" align=\"left\">"
	."<td bgcolor=\"$bgcolor3\" align=\"center\" valign=\"middle\"><input name=\"allbox\" onclick=\"CheckAll();\" type=\"checkbox\" value=\""._CHECKALL."\"></td>"
	."<td bgcolor=\"$bgcolor3\" align=\"center\" valign=\"middle\"><img src=\"images/forum/download.gif\" border=\"0\" alt=\""._MSGSTATUS."\" title=\""._MSGSTATUS."\"></td>"
	."<td bgcolor=\"$bgcolor3\" align=\"center\" valign=\"middle\">&nbsp;</td>"
	."<td><font class=\"content\">&nbsp;<b>"._FROM."</b></font></td>"
	."<td><font class=\"content\">&nbsp;<b>"._SUBJECT."</b></font></td>"
	."<td align=\"center\"><font class=\"content\"><b>"._DATE."</b></font></td>"
	."</tr>";
	if (!$total_messages = sql_num_rows($resultID, $dbi)) {
	    echo "<td bgcolor=\"$bgcolor2\" colspan=\"6\" align=\"center\">"._DONTHAVEMESSAGES."</td></tr>\n";
	} else {
	    $display=1;
	}
	$count=0;
	while ($myrow = sql_fetch_array($resultID, $dbi)) {
	    echo "<tr align=\"left\">";
	    echo "<td bgcolor=\"$bgcolor2\" valign=\"top\" width=\"2%\" align=\"center\"><input type=\"checkbox\" onclick=\"CheckCheckAll();\" name=\"msg_id[$count]\" value=\"$myrow[msg_id]\"></td>";
	    if ($myrow[read_msg] == "1") {
		echo "<td valign=\"top\" width=\"5%\" align=\"center\" bgcolor=\"$bgcolor2\">&nbsp;</td>";
	    } else {
		echo "<td valign=\"top\" width=\"5%\" align=\"center\" bgcolor=\"$bgcolor2\"><img src=\"images/forum/read.gif\" border=\"0\" alt=\""._NOTREAD."\" title=\""._NOTREAD."\"></td>";
	    }
	    echo "<td bgcolor=\"$bgcolor2\" valign=\"top\" width=\"5%\" align=\"center\"><img src=\"images/forum/subject/$myrow[msg_image]\" border=\"0\"></td>";
	    $posterdata = get_userdata_from_id($myrow[from_userid]);
	    echo "<td bgcolor=\"$bgcolor2\" valign=\"middle\" width=\"10%\">&nbsp;<a href=\"modules.php?name=$module_name&file=read&start=$count&total_messages=$total_messages\">$posterdata[uname]</a></td>"
		."<td bgcolor=\"$bgcolor2\" valign=\"middle\">&nbsp;<a href=\"modules.php?name=$module_name&file=read&start=$count&total_messages=$total_messages\">$myrow[subject]</a></font></td>"
		."<td bgcolor=\"$bgcolor2\" valign=\"middle\" align=\"center\" width=\"20%\">$myrow[msg_time]</font></td></tr>";
	    $count++;
	}
	if ($display) {
	echo "<tr align=\"left\">";
	echo "<td colspan=6 align='left'><table border=0><tr><td><input type='submit' name='delete_messages' value='"._DELETESELECTED."' border='0'><input type='hidden' name='total_messages' value='$total_messages'></form></td><td><form action=\"modules.php?name=$module_name\" method=\"post\"><input type=\"submit\" name=\"send\" value=\""._SENDNEWMSG."\"></form></tr></td></table></td></tr>";
	}
	else {
	echo "<tr bgcolor=\"$bgcolor2\" align=\"left\">";
	echo "<td colspan=6 align='left'></form><table border=0><tr><td><form action=\"modules.php?name=$module_name\" method=\"post\"><input type=\"submit\" name=\"send\" value=\""._SENDNEWMSG."\"></form></tr></td></table></td></tr>";
	}
    echo "</table></td></tr></table>
    <script type=\"text/javascript\">\n\n
    <!--\n\n
    function CheckAll() {\n
	for (var i=0;i<document.prvmsg.elements.length;i++) {\n
	    var e = document.prvmsg.elements[i];\n
	    if ((e.name != 'allbox') && (e.type=='checkbox'))\n
	    e.checked = document.prvmsg.allbox.checked;\n
	}\n
    }\n\n

    function CheckCheckAll() {\n
	var TotalBoxes = 0;\n
	var TotalOn = 0;\n
	for (var i=0;i<document.prvmsg.elements.length;i++) {\n
	    var e = document.prvmsg.elements[i];\n
	    if ((e.name != 'allbox') && (e.type=='checkbox')) {\n
		TotalBoxes++;\n
		if (e.checked) {\n
		    TotalOn++;\n
		}\n
	    }\n
	}\n
	if (TotalBoxes==TotalOn) {\n
	    document.prvmsg.allbox.checked=true;\n
	} else {\n
	    document.prvmsg.allbox.checked=false;\n
	}\n
    }\n\n

    -->\n
    </script>\n\n";
    CloseTable();
}
include('footer.php');

?>