<?php

if ( ! @include_once( './mainfile.php' ) ) { exit( '!! INCLUDE ERROR. ACCESS DENIED !!' ); }
error_reporting( _E_VALUE );


/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | myPHPNuke Version 188_8 RC2                                          |
// +----------------------------------------------------------------------+
// | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html              |
// +----------------------------------------------------------------------+
// | Support: http://myphpnuke.com/                                       |
// +----------------------------------------------------------------------+
// | Author: myPHPNuke Dev Team                                           |
// +----------------------------------------------------------------------+
// | Copyright: © 2001-2004 myPHPNuke Dev Team                            |
// +----------------------------------------------------------------------+
// $Id: viewpmsg.php,v 1.10.2.15 2004/08/23 21:56:47 kirilt Exp $




/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fburzi@ncc.org.ve)            */
/* 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.       */
/************************************************************************/

if ( ! _MPN_USER ) { $_SERVER['F_LIB'] -> redirectRequest( 'user.php' ); }

$index = 2;

@( include_once __ROOT__ . 'core_ForumEntry.php' )
  OR goBack( translate( 'Include Error' ) );

$order = ( ! isset( $_REQUEST['order'] ) ) ? ( 'DESC' ) : ( $_REQUEST['order'] );

$sql = 'SELECT * FROM ' . $mpnTables['priv_msgs'] . ' WHERE to_userid = ' . $GLOBALS['uinf']['uid'] . ' ORDER BY msg_id ' . $order;

@( $result = mysql_query( $sql ) )
  OR goBack( translate( 'Query Failed' ) . '**' . __FILE__ . '***' .  __LINE__ );

for ( $i = 0; $i < mysql_num_rows( $result ); $i++ )
{
    $msgary[ $i ] = mysql_fetch_array( $result );
    $posters_ary[ $i ] = getPosterData( $msgary[ $i ]['msg_id'], $msgary[ $i ]['from_userid'] );

    if ( $posters_ary[ $i ]['uid'] < 0 || ! is_array( $posters_ary[ $i ] ) )
    {
        if ( _MPN_ADMIN )
        {
             $msgary[ $i ]['msg_text'] .= getAdminWarning( $msgary[ $i ]['from_userid'] );
        }

        if ( ! _UM_SHOW_DELETED_USERS_CONTENT_ && ! _MPN_ADMIN )
        {
            unset( $msgary[ $i ], $posters_ary[ $i ] );
        }
    }
}

$total_messages = sizeof( $msgary );

@( include_once __ROOT__ . 'header.php' )
  OR goBack( translate( 'Include Error' ) );

?>

<script type="text/javascript">
<!--
function CheckAll()
{
        for (var i=0;i<document.prvmsg.elements.length;i++)
        {
                var e = document.prvmsg.elements[i];
                if ((e.name != 'allbox') && (e.type=='checkbox'))
                e.checked = document.prvmsg.allbox.checked;
        }
}
function CheckCheckAll()
{
        var TotalBoxes = 0;
        var TotalOn = 0;
        for (var i=0;i<document.prvmsg.elements.length;i++)
        {
                var e = document.prvmsg.elements[i];
                if ((e.name != 'allbox') && (e.type=='checkbox'))
                {
                        TotalBoxes++;
                if (e.checked)
                {
                        TotalOn++;
                }
                }
        }
        if (TotalBoxes==TotalOn)
        {document.prvmsg.allbox.checked=true;}
        else
        {document.prvmsg.allbox.checked=false;}
}
//-->
</script>

<?php

echo '<h1>' . translate ( 'Private Message' ) . '</h1>' . "\n";
$sortedby = ( $order == 'DESC' ) ? ( translate("Sorted Descending") ) : ( translate("Sorted Ascending") );

echo '<h2>' . $sortedby . '</h2>' . "\n";

echo "<FORM name=\"prvmsg\" METHOD=\"post\" ACTION=\"replypmsg.php\">";

?>

<table class="simpleborders" summary="view private message">

    <tr bgcolor="<?php echo $bgcolor2?>" ALIGN="LEFT">
    <th BGCOLOR="<?php echo $bgcolor2?>" ALIGN="CENTER" VALIGN="MIDDLE"><INPUT name=allbox onclick=CheckAll(); type=checkbox value="Check All"></th>
    <th BGCOLOR="<?php echo $bgcolor2?>" ALIGN="CENTER" VALIGN="MIDDLE"><img src="images/forum/download.gif"></th>
    <th BGCOLOR="<?php echo $bgcolor2?>" ALIGN="CENTER" VALIGN="MIDDLE">&nbsp;</th>
    <th><FONT SIZE=2 COLOR="<?php echo $textcolor2?>"><B><?php echo translate("From")?></B></font></th>
    <th><FONT SIZE=2 COLOR="<?php echo $textcolor2?>"><B><?php echo translate("Subject")?></B></font></th>

<?php

    echo "<th ALIGN=\"CENTER\"><A HREF=\"viewpmsg.php?order=ASC\"><img src=\"images/download/up.gif\" alt=\"".translate("Sort Ascending")."\" border=\"0\" height=\"9\" width=\"15\"></A>&nbsp; <FONT SIZE=2><B>".translate("Date")."</B></font>&nbsp; <A HREF=\"viewpmsg.php?order=DESC\"><img src=\"images/download/down.gif\" alt=\"".translate("Sort Descending")."\" border=\"0\" height=\"9\" width=\"15\"></A></th>
</TR>";

        if ( $total_messages < 1 )
        {
            echo '<tr><td class="center bold" bgcolor="' . $bgcolor3 . '" colspan="6">' . translate( 'You don\'t have any private messages' ) . '</td></tr>' . "\n";
        }
        else
        {
            foreach( $msgary AS $key => $myrow )
            {
                $posterdata = $posters_ary[ $key ];

                if ( $myrow['msg_image'] == '' || $myrow['msg_image'] == '.mappedfiles' )
                {
                    $myrow['msg_image'] = 'icon1.gif';
                }

                $msg_time = getDisplayTime( $myrow['msg_time'], 'forumdatestring2' );

                echo "<TR ALIGN=\"LEFT\">";
                echo "<TD BGCOLOR=\"$bgcolor1\" valign=top WIDTH='2%' ALIGN='CENTER'><INPUT TYPE='CHECKBOX' onclick=CheckCheckAll(); name='msg_id[$key]' value='" . $myrow['msg_id'] . "'></TD>";
                if ($myrow['read_msg'] == "1") echo "<TD valign=top WIDTH='5%' ALIGN='CENTER' BGCOLOR=\"$bgcolor1\">&nbsp;</TD>";
                else echo "<TD valign=top WIDTH='5%' ALIGN='CENTER' BGCOLOR=\"$bgcolor1\"><IMG SRC='images/forum/read.gif' border=0 Alt=\"".translate("Not Read")."\"></TD>";
                echo "<TD BGCOLOR=\"$bgcolor1\" valign=top WIDTH='5%' ALIGN='CENTER'><IMG SRC='images/forum/subject/" . $myrow['msg_image'] . "' border=0></TD>";

                echo "<TD BGCOLOR=\"$bgcolor1\" valign=MIDDLE WIDTH='10%'><a href='user.php?op=userinfo&uname=" . $posterdata['uname'] . "'>" . $posterdata['uname'] . "</a></TD>";
                echo "<TD BGCOLOR=\"$bgcolor1\" valign=MIDDLE><FONT SIZE=1 COLOR=\"$textcolor2\"><a href='readpmsg.$phpEx?start=$key&total_messages=$total_messages&order=$order'>" . $myrow['subject'] . "</a></FONT></TD>";
               echo "<TD BGCOLOR=\"$bgcolor1\" valign=MIDDLE align='center' WIDTH='20%'><FONT SIZE=1 COLOR=\"$textcolor2\">$msg_time</FONT></TD></TR>";
            }
        }

        echo "<tr bgcolor=\"$bgcolor2\" align=\"left\">";
        echo "<td colspan=6 align='left'>\n";

        if ( $total_messages > 0 )
        {
            echo '<input class="button" type="submit" name="send" value="' . translate( 'Send' ) . '" />' . "\n";

            echo '<input class="button" type="submit" name="delete_messages" value="' . translate( 'Delete' ) . '" />' . "\n";

            echo "<INPUT TYPE='hidden' NAME='total_messages' VALUE='$total_messages'>";
        }
        else
        {
            echo '<input class="button" type="submit" name="send" value="' . translate( 'Send' ) . '" />' . "\n";
        }

       echo "</td></tr></table>";

     echo "</form>";

    echo getForumNav();

@( include_once __ROOT__ . 'footer.php' )
  OR goBack( translate( 'Include Error' ) );

?>
