<?php

@( (bool)FALSE === strpos( $_SERVER['REQUEST_URI'], basename( __FILE__ ) ) ) OR exit( '!! ACCESS DENIED !!' );
error_reporting( _E_VALUE );

/* vim: set expandtab tabstop=4 shiftwidth=4: */

// ***** BEGIN LICENSE BLOCK ( DO NOT REMOVE ) *****

// +----------------------------------------------------------------------+
// | phpBB 1.4.x Forum For MPN 188_8                                      |
// |                                                                      |
// | -> Forum Core Output Functions                                       |
// +----------------------------------------------------------------------+
// | VERSION: 0.1 Alpha                                                   |
// +----------------------------------------------------------------------+
// | LICENSE: GPL 2.0 (see docs/LICENSE_GPL)                              |
// |                                                                      |
// | This file is part of phpBB 1.4.x Forum For MPN 188_8.                |
// |                                                                      |
// | phpBB 1.4.x Forum For MPN 188_8 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, or (at your option) any             |
// | later version.                                                       |
// |                                                                      |
// | phpBB 1.4.x Forum For MPN 188_8 is distributed in the hope that it   |
// | will be useful, but WITHOUT ANY WARRANTY; without even the implied   |
// | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     |
// | See the GNU General Public License for more details.                 |
// |                                                                      |
// | You should have received a copy of the GNU General Public License    |
// | along with phpBB 1.4.x Forum For MPN 188_8; if not, write to the     |
// |                                                                      |
// | Free Software Foundation, Inc.                                       |
// | 59 Temple Place, Suite 330                                           |
// | Boston, MA 02111-1307  USA                                           |
// +----------------------------------------------------------------------+
// | AUTHOR(s):                                                           |
// |                                                                      |
// | The Original Code is the phpbb 1.4.4 Forum For MPN 188_8.            |
// | The Initial Developer of the Original Code is Eric Haddix.           |
// |                                                                      |
// | Portions created by Eric Haddix or Kiril Threndor                    |
// | <support@mpn.illearth.net> are                                       |
// | Copyright (C) 2003 Eric Haddix.  All Rights Reserved.                |
// +----------------------------------------------------------------------+
// | HISTORICAL AUTHORS & COPYRIGHTS:                                     |
// |                                                                      |
// | Portions created by Richard Tirtadji or King Richard                 |
// | <rtirtadji@hotmail.com> are                                          |
// | Copyright (C) 2001 Richard Tirtadji.  All Rights Reserved.           |
// |                                                                      |
// | Portions created by Hutdik Hermawan or hotFix                        |
// | <hutdik76@hotmail.com> are                                           |
// | Copyright (C) 2001 Hutdik Hermawan.  All Rights Reserved.            |
// |                                                                      |
// | Portions created by Nathan Codding, Hombergs, or Francisco Burzi     |
// | are Copyright (C) 2001 Francisco Burzi.  All Rights Reserved.        |
// +----------------------------------------------------------------------+
// | CONTRIBUTOR(s):                                                      |
// |                                                                      |
// |                                                                      |
// +----------------------------------------------------------------------+
// | MODIFICATIONS:                                                       |
// |                                                                      |
// |                                                                      |
// +----------------------------------------------------------------------+
// | NOTES:                                                               |
// |   The MPN 188_8 forum is nearly a complete, and in some cases entire,|
// |   recode of the phpNuke 4.4 forum which was based on phpBB 1.4.x.    |
// +----------------------------------------------------------------------+
// | SUPPORT:                                                             |
// |   WEB:   http://myphpnuke.com/                                       |
// |   EMAIL: support@mpn.illearth.net                                    |
// +----------------------------------------------------------------------+

/**
 * MPN_188_8_Modules
 *
 * @package MPN_188_8_Modules
 * @subpackage forum
 * @version $Id: core_ForumOutput.php,v 1.1.2.47 2004/08/25 13:18:18 kirilt Exp $
 *
 * @author Kiril Threndor <support@mpn.illearth.net>
 * @copyright Copyright (C) 2003 Eric Haddix
 * @license http://www.gnu.org/licenses/gpl.html GPL 2.0
 * @support http://myphpnuke.com/
 * @todo finish CSS & XHTML conversion
 * @todo reformat old style formatted code to new coding style
 * @todo finish and check function comments
 *
 * @tutorial
 * @filesource
 */

// ***** END LICENSE BLOCK ( DO NOT REMOVE ) *****


// ##### PRIMARY PAGE OUTPUT FUNCTIONS #####


/**
 * Get Forum Main Page Output
 *
 * @return string
 */

function getForumMain()
{
    global $bgcolor1, $bgcolor2, $bgcolor3, $sitename;

    $content = '';

    // Get Categories

    $result = getResultSet( 2 );

    for ( $i = 0; $i < mysql_num_rows( $result ); $i++ )
    {
        $tmp = mysql_fetch_array( $result );
        $idx = array_shift( $tmp );
        if ( ! isset( $fcats[ $idx ] ) ) { $fcats[ stripslashes( $idx ) ] = array(); }
        $fcats[ $idx ][ $i ] = $_SERVER['SAN'] -> slashIT( $tmp );
    }

    ( ! empty( $fcats ) )
      OR goBack( 'No Forums Found' . '**' . __FILE__ . '***' .  __LINE__ );

    // Header Welcome

    $content .= '<h1>' . sprintf( translate( 'Welcome to %s Forums!' ), $sitename ) . '</h1>';
    $content .= '<br />' . "\n";
    $content .= getSearchLink();

    if ( _FORUM_SHOW_MAIN_MSG_ )
    {
        $content .= '<h2>' . "\n";
            $content .= translate( _FORUM_WELCOME_MSG_ );
        $content .= '</h2><br />' . "\n";
    }

    $content .= '<b>' . translate( 'Today is ') . ': </b>';
    $content .= getDisplayTime( _MPN_TIMESTAMP, 'forumdatestring2' );
    $content .= '<br />';

    if ( _MPN_USER )
    {
        $content .= '<b>' . translate( 'Your last visit was on ' ) . ': </b>';
        $content .= getDisplayTime( $GLOBALS['uinf']['lastvisit'], 'forumdatestring2' );
    }
    else
    {
        $content .= '<b>' . translate( 'Anonymous users last visit is set to 30 minutes ago' ) . '.</b>';
    }

    $content .= '<br />';
    $content .= '<a href="lastview.php">' . translate( 'New Posts since your last Visit' ) . '</a>';
    $content .= '<br /><hr class="w60" /><br />' . "\n";


    // List Forums


    foreach( $fcats AS $title => $category )
    {
        $linkid = base64_encode( $title );

        $content .= '<a name="cat_' . $linkid . '" id="cat_' . $linkid . '" href="#cat_' . $linkid . '"></a>';
        $content .= '<h3>' . $title . '</h3>' . "\n";
        $content .= '<br />' . "\n";

        $content .= '<table class="forumindex" summary="Forum Index"><tr style="background:' . $bgcolor2 . '">' . "\n";

            $content .= "<th>&nbsp;</th>\n";
            $content .= "<th>" . translate( 'Forum' ) . "</th>\n";
            $content .= "<th>" . translate( "Type" ) . "</th>\n";
            $content .= "<th>" . translate( "Topics" ) . "</th>\n";
            $content .= "<th>" . translate( "Posts" ) . "</th>\n";
            $content .= "<th>" . translate( "Last Post" ) . "</th>\n";
            $content .= "<th width='10%'>" . translate( "Moderated By" ) . "</th>\n";

        $content .= '</tr>' . "\n";

        foreach( $category AS $forumary )
        {
            $stats_ary = getLastForumPost( $forumary['forum_id'] );
            $chkposts = is_array( $stats_ary );

            $content .= '<tr class="t-left top"><td style="background:' . $bgcolor1 . '">' . "\n";
                if ( ! $chkposts )
                {
                    $forumary['replies'] = 0;
                    $content .= activityImage( 0, _MPN_TIMESTAMP );
                }
                else
                {
                    $forumary['replies'] = $stats_ary['total_posts'];
                    $forumary['post_time'] = $stats_ary['post_time'];

                    $content .= activityImage( $forumary['replies'], $forumary['post_time'] );
                }

                if ( $forumary['replies'] == -1 ) { $forumary['replies'] = 0; }

            $content .= '</td><td class="desc" bgcolor="' . $bgcolor3 . '">' . "\n";

            $content .= '<a href="viewforum.php?forum=' . $forumary['forum_id'] . '"><b>' . $forumary['forum_name'] . '</b></a>' . "\n";

            $content .= '<br /><div class="indent15">' . $forumary['forum_desc'] . '</div></td>' . "\n";

            if ( $forumary['forum_access'] == 0 && $forumary['forum_type'] == 0 )
            {
                $content .= "<td bgcolor=\"$bgcolor1\" width=5% align=\"center\" valign=\"middle\"><img src=\"" . _MPN_ROOT_URI . "images/forum/icons/alluser.gif\" alt=\"" . translate( "Everyone Can Post" ) . "\"></td>\n";
            }

            if ( $forumary['forum_type'] == 1 )
            {
                $content .= "<td bgcolor=\"$bgcolor1\" width=5% align=\"center\" valign=\"middle\"><img src=\"" . _MPN_ROOT_URI . "images/forum/icons/privat.gif\" alt=\"" . translate( "Private Forum, Password Required" ) . "\"></td>\n";
            }

            if ( $forumary['forum_access']== 1 && $forumary['forum_type'] == 0 )
            {
                $content .= "<td bgcolor=\"$bgcolor1\" width=5% align=\"center\" valign=\"middle\"><img src=\"" . _MPN_ROOT_URI . "images/forum/icons/member.gif\" alt=\"" . translate( "Only Members Can Post" ) . "\"></td>\n";
            }

            if ( $forumary['forum_access']== 2 && $forumary['forum_type'] == 0 )
            {
                $content .= "<td bgcolor=\"$bgcolor1\" width=5% align=\"center\" valign=\"middle\"><img src=\"" . _MPN_ROOT_URI . "images/forum/icons/modadm.gif\" Alt=\"" . translate( "Only Moderators &amp; Admins Can Post" ) . "\"></td>\n";
            }

            $content .= "<td class='middle center' bgcolor=\"$bgcolor3\" width=\"5%\">\n";

                $cnt = ( $chkposts ) ? ( $stats_ary['total_topics'] ) : ( 0 );

                $content .= $cnt;

            $content .= '</td>' . "\n";

            $content .= "<td class='middle center' bgcolor=\"$bgcolor1\" width=5% align=\"center\" valign=\"middle\">\n";

                $cnt = ( $chkposts ) ? ( $stats_ary['total_posts'] ) : ( 0 );

                $content .= $cnt;

            $content .= '</td>' . "\n";

            if ( ! $chkposts )
            {
                $content .= "<td class='middle center' bgcolor=\"$bgcolor3\"><b>" . translate( 'No posts' ) . "</b></td>\n";
            }
            else
            {
                $content .= "<td class='lastpost middle center' bgcolor=\"$bgcolor3\"><span class='font6'>\n";

                    $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/subject/' . $stats_ary['image'] . '" width="15" height="15" border="0" />';

                    if ( _MPN_ADMIN && $stats_ary['uname'] == 'Unknown' )
                    {
                        $content .= '<span class="warn">( ' . $stats_ary['uname'] . ' )</span>' . "\n";
                    }
                    else
                    {
                        $content .= '( ' . $stats_ary['uname'] . ' )' . "\n";
                    }

                    $content .= '<br />' . $stats_ary['post_time'] . '<br />';

                    $content .= '<a href="viewtopic.php?topic=' . $stats_ary['last_topic_id'] . '&amp;forum=' . $forumary['forum_id'] . $stats_ary['nav'] . '">' . $stats_ary['topic_title'] . '</a>';
                    $content .= '<br />' . "\n";

                $content .= '</span></td>' . "\n";
            }

            $content .= "<td bgcolor=\"$bgcolor1\" width=\"10%\" align=\"center\" valign=\"middle\">\n";

                $content .= '<span class="font6">';

                    $mods = getModerators( $forumary['forum_id'] );

                    if ( $mods != '' )
                    {
                        $content .= $mods;
                    }
                    else
                    {
                        $content .= translate( 'None' );
                    }

                $content .= '</span>' . "\n";

            $content .= '</td></tr>' . "\n";
        }

        $content .= '</table>' . "\n";

        $content .= '<br /><br />' . "\n";
    }

    $content .= getFooterNav();

    return $content;

} // End Function

/**
 * Get Forum Topics Output
 *
 * @return string
 */

function getForumTopics()
{
    global $bgcolor1, $bgcolor2, $bgcolor3, $forumconfig, $forum, $start;

    $content = '';
    $total_topics = getStats( $forum, 'count', 'forum_topics' );
    $page_results = getForumTopicList( $forum );

    $content .= getSearchLink();
    $content .= getHeaderNav( _FORUM_NAME_, 'viewforum', $total_topics );

    if ( $total_topics == 0 || sizeof( $page_results ) == 0 )
    {
        $content .= '<h2>';

            $content .= translate( 'There are no topics for this forum. ' );
            $content .= '<br />' . "\n";
            $content .= '<a href="forum_submit.php?ld=1&amp;forum=' . $forum . '">' . translate( 'You can post one here.' ) . '</a>';

        $content .= '</h2>' . "\n";

        return $content;
    }

    $content .= '<table class="forumtopics"><tr bgcolor="' . $bgcolor2 . '">' . "\n";

        $content .= "<th width='2%'>&nbsp;</th><th width='2%'>&nbsp;</th>";
        $content .= "<th>" . translate( 'Topic' ) . "</th>";
        $content .= "<th width='9%'>".translate("Replies")."</th>";
        $content .= "<th width='8%'>".translate("Views")."</th>";
        $content .= "<th width='15%'>".translate("Created By")."</th>";
        $content .= "<th width='20%'>".translate("Last Reply")."</th>";

        if ( $GLOBALS['uinf']['mod'] )
        {
            $content .= '<th width="15%"><b>' . translate( 'Admin' ) . '</b></th>';
        }

    $content .= '</tr>' . "\n";

    // LIST TOPICS

    $count = 0;

    foreach( $page_results AS $key => $topicinfo )
    {
        $row_color = ( ! ( $count % 2 ) ) ? ( $bgcolor1 ) : ( $bgcolor3 );
        $count++;
        $last_post = sprintf( translate( "%s <br /> by %s" ), getDisplayTime( $topicinfo['post_time'], 'forumdatestring2' ), $topicinfo['uname'] );
        $topiclink = "viewtopic.php?topic=" . $topicinfo['topic_id'] . "&amp;forum=$forum";

        $content .= '<tr class="center" style="background:' . $row_color . '"><td>' . "\n";

            $content .= activityImage( $topicinfo['totalposts'], $topicinfo['post_time'], $topicinfo['topic_status'] );

        $content .= '</td><td>' . "\n";

            $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/subject/' . $topicinfo['image'] . '" alt="subject icon" />' . "\n";

       $content .= '</td><td class="t-left">' . "\n";

            $content .= '<a href="' . $topiclink . '">' . $topicinfo['topic_title'] . '</a>';

            if ( ( $topicinfo['totalposts'] + 1 ) > $forumconfig['posts_per_page'] )
            {
                $content .= '<br />' . "\n";
                $content .= getTopicPageNav( $topiclink, $topicinfo['totalposts'] + 1 );
            }

        $content .= '</td><td>' . "\n";

            $content .= $topicinfo['totalposts'];

        $content .= '</td><td>' . "\n";

            $content .= $topicinfo['topic_views'];

        $content .= '</td><td>' . "\n";

             $content .= $topicinfo['topic_author'];

        $content .= '</td><td>' . "\n";

            $content .= $last_post;

        $content .= '</td>' . "\n";

        if ( $GLOBALS['uinf']['mod'] )
        {
            $content .= '<td class="center" bgcolor="' . $bgcolor1 . '">' . "\n";

                $content .= getAdminLinks( $topicinfo['topic_id'], TRUE, $topicinfo['topic_status'] );

            $content .= '</td>' . "\n";
        }

        $content .= '</tr>' . "\n";

    } // End foreach

    $content .= '</table>' . "\n";

    $content .= getFooterNav( NULL, 'viewforum', $total_topics );

    return $content;

} // End Function

/**
 * Get A Topics Output
 *
 * @return string
 */

function getTopicPosts( $show = TRUE, $loc = NULL, $query = NULL )
{
    global $bgcolor1, $bgcolor2, $bgcolor3, $mpn_anonymous_id, $topic_subject, $topic, $forum, $forumconfig;

    $content = '';
    $count = 0;

    if ( empty( $loc ) )
    {
        $tmpary = getTopicArrays();
        $loc = 'viewtopic';
    }
    else
    {
        $tmpary = getTopicArrays();
    }

    $topic_posts =& $tmpary[0];
    $posters_ary =& $tmpary[1];
    $total_posts =& $tmpary[2];

    // REF: getHeaderNav( $title = NULL, $loc = NULL, $totalcnt = NULL, $limit = NULL, $query = NULL )

    if ( $show )
    {
        $content .= getSearchLink();
        $content .= getHeaderNav( $topic_subject, $loc, $total_posts, NULL, $query );
    }

    if ( sizeof( $topic_posts ) == 0 )
    {
        $content .= '<h1>' . "\n";
            $content .= translate( 'No Valid Posts Found For This Topic' );
        $content .= '</h1><br />' . "\n";
        $content .= '<h2>';
            $content .= translate( 'You can' );
            $content .= '<a href="forum_submit.php?ld=2&amp;topic=' . $topic . '&amp;forum=' . $forum . '">';
            $content .= translate( 'Post One Here' );
        $content .= '</a></h2>' . "\n";

        return $content;
    }

    if ( ! $show )
    {
        $content .= '<p class="subtitle1">' . translate( 'Topic Review' ) . '</p><br />' . "\n";
        $content .= '<h2>' . translate( 'Showing Newest Posts First' ) . '</h2>' . "\n";
        $content .= '<hr class="w80" /><br /><br />' . "\n";
    }

    $content .= '<table class="forumposts" summary="">' . "\n";

    $content .= '<tr bgcolor="' . $bgcolor2 . '">' . "\n";
        $content .= '<th>' . translate( 'Author' ) . '</th>' . "\n";
        $content .= '<th>' . $topic_subject . '</th>' . "\n";
    $content .= '</tr>' . "\n";

    foreach( $topic_posts AS $key => $myrow )
    {
        $old_row_color = ( isset( $row_color ) ) ? ( $row_color ) : ( $bgcolor1 );
        $row_color = ( ! ( $count % 2 ) ) ? ( $bgcolor3 ) : ( $bgcolor1 );
        $count++;

        $content .= '<tr class="t-left"><td class="forumuserstatus" bgcolor="' . $old_row_color . '">' . "\n";

            $content .= '<p class="font6">' . "\n";

                if ( $posters_ary[ $key ]['uid'] > 1 && ( _MPN_USER || _MPN_ADMIN ) )
                {
                    if ( (bool)FALSE != $posters_ary[ $key ]['online'] )
                    {
                        $bullclass = 'online';
                        $online = translate( 'Online' );
                    }
                    else
                    {
                        $bullclass = 'offline';
                        $online = translate( 'Offline' );
                    }

                    $content .= '<span class="' . $bullclass . '" title="' . $online . '">&#149;</span>&nbsp;';
                }

                $content .= '<b>' . $posters_ary[ $key ]['uname'] . '</b><br />' . "\n";

                $content .= $posters_ary[ $key ]['rank_display'] . '<br />';

                if ( $posters_ary[ $key ]['uid'] != $mpn_anonymous_id && $posters_ary[ $key ]['uid'] > 0 )
                {
                    $content .= getPosterDisplayInfo( $posters_ary[ $key ] );
                }

            $content .= '</p>' . "\n";

        // Start Column 2

        $content .= '</td><td class="forummessage" bgcolor="' . $row_color . '">' . "\n";

        $content .= '<span class="font6">' . "\n";

        if ( empty( $myrow['image'] ) || $myrow['image'] == '' || ! is_file( __ROOT__ . 'images/forum/subject/' . $myrow['image'] ) )
        {
           $myrow['image'] = 'icon1.gif';
        }

        $content .= '<a name="f' . $myrow['post_id'] . '" id="f' . $myrow['post_id'] . '" href="#f' . $myrow['post_id'] . '">';
        $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/subject/' . $myrow['image'] . '" alt="posticon" />' . "\n";
        $content .= '</a>' . "\n";
        $content .= '&nbsp;&nbsp;' . translate( 'Posted: ' );
        $content .= getDisplayTime( $myrow['post_time'], 'forumdatestring2' );
        $content .= '</span><br /><br />' . "\n";

        $content .= '<div class="bbcode_msg">' . "\n";

        $content .= processMessage( 1, $myrow['post_text'], FALSE, $posters_ary[ $key ]['user_sig'] );

        $content .= '</div>' . "\n";

        $content .= '<br />';

        $content .= '<div class="forumicons">';

        if ( _MPN_ADMIN && _FORUM_SHOW_POST_INFO_ )
        {
            $content .= '<label>' . translate( 'ID\'s' ) . ':</label>';
            $content .= '&nbsp;&nbsp;' . translate( 'Forum' ) . ': ' . $myrow['forum_id'];
            $content .= '&nbsp;&nbsp;' . translate( 'Topic' ) . ': ' . $myrow['topic_id'];
            $content .= '&nbsp;&nbsp;' . translate( 'Post' ) . ': ' . $myrow['post_id'];
            $content .= '&nbsp;&nbsp;' . translate( 'Poster' ) . ': ' . $myrow['poster_id'];
            $content .= '&nbsp;&nbsp;' . translate( 'IP' ) . ': ' . $myrow['poster_ip'];
        }

        $content .= '<br /><hr class="lft" />' . "\n";

        if ( $posters_ary[ $key ]['uid'] > 1 )
        {
            $content .= getUserIcons( $posters_ary[ $key ] );
        }

        $content .= getSpecialIcons( $myrow['post_id'], $posters_ary[ $key ] );

        $content .= '</div></td></tr>' . "\n";

    }  // End foreach

    $content .= '</table>' . "\n";

    // REF: getFooterNav( $title = NULL, $loc = NULL, $totalcnt = NULL, $limit = NULL, $query = NULL )

    if ( $show || $total_posts > $forumconfig['posts_per_page'] )
    {
        $content .= getFooterNav( $topic_subject, $loc, $total_posts, NULL, $query );

        if ( $GLOBALS['uinf']['mod'] )
        {
            $content .= getAdminLinks( $myrow['topic_id'], FALSE );
        }
    }

    return $content;

} // End Function

/**
 * Generate A User Post Submission Page
 *
 *
 */

function getSubmissionData( $forum, $topic, $post_id )
{
    global $bgcolor1, $bgcolor2, $bgcolor3, $topic_subject, $start, $labelcss, $labelcss1, $formcss;

    $topic_poster = (bool)FALSE;

    if ( _FORUM_POST_TYPE_ == 3 )
    {
        $result = getResultSet( 7, NULL, NULL, $post_id );
        @$finfo = $_SERVER['SAN'] -> slashIT( mysql_fetch_assoc( $result ) );
        @mysql_free_result( $result );

        if ( ! is_array( $finfo ) )
        {
            goBack( 'Query Failed' . '**' . __FILE__ . '***' .  __LINE__ );
        }
    }

    if ( _FORUM_POST_TYPE_ >= 3 && ( $GLOBALS['uinf']['mod'] || ( isset( $post_id ) && @mysql_result( getResultSet( 3, NULL, $topic, $post_id, TRUE ), 0 ) == 1 ) ) )
    {
        $topic_poster = (bool)TRUE;
    }

    switch( _FORUM_POST_TYPE_ )
    {
        case 1: // New Forum Topic

            $message = '';
            $pagetitle = "<h2>" . translate( "Posting New Topic In Forum" ) . "<br /><i>" . _FORUM_NAME_ . "</i></h2>\n";

            $hidinput  = "<input type='hidden' name='ld' value='4' />\n";
            $hidinput .= "<input type='hidden' name='action' value='1' />\n";
            $hidinput .= "<input type='hidden' name='forum' value='$forum' />\n";

        break;

        case 2: // Forum Topic Reply

            $message = '';
            $list_posts = 1;
            $pagetitle = "<h2>" . translate( "Posting Reply in Topic" ) . ":&nbsp;<i>$topic_subject</i></h2>\n";

            if ( isset( $_REQUEST['qid'] ) )
            {
                $message = processMessage( 4 );
            }

            $hidinput  = "<input type='hidden' name='ld' value='4' />\n";
            $hidinput .= "<input type='hidden' name='action' value='2' />\n";
            $hidinput .= "<input type='hidden' name='forum' value='$forum' />\n";
            $hidinput .= "<input type='hidden' name='topic' value='$topic' />\n";
            $hidinput .= "<input type='hidden' name='subject' value='$topic_subject' />\n";

        break;

        case 3: // Edit Forum Post

            $message = processMessage( 3, $finfo['post_text'] );
            $list_posts = 1;
            $pagetitle = "<h2>" . translate( "Editing Post In Topic:" ) . "&nbsp;<i>$topic_subject</i></h2>\n";

            $hidinput  = "<input type='hidden' name='ld' value='4' />\n";
            $hidinput .= "<input type='hidden' name='action' value='3' />\n";
            $hidinput .= "<input type='hidden' name='forum' value='$forum' />\n";
            $hidinput .= "<input type='hidden' name='topic' value='$topic' />\n";
            $hidinput .= "<input type='hidden' name='post_id' value='$post_id' />\n";
            $hidinput .= "<input type='hidden' name='user_sig' value='" . $finfo['user_sig'] . "' />\n";

            if ( (bool)FALSE === $topic_poster )
            {
                $hidinput .= "<input type='hidden' name='subject' value='$topic_subject' />\n";
            }

        break;

        case 4: // Previewing Post

            $pagetitle = '<h2>' . translate( 'Forum Post Preview' ) . '</h2>' . "\n";
            $username = $GLOBALS['uinf']['uname'];

            // Process Message Text For Editing And Previewing

            // REF: BBConversion( $body, $encode, $edited = FALSE, $editby = '' )

            $message = processMessage( 2, $_POST['message'] );

            // Process Message Text For DB ( Required To Simulate DB Message Storage )

            $action = ( isset( $_POST['action'] ) ) ? ( $_POST['action'] ) : ( 3 );

            $hidinput  = "<input type='hidden' name='ld' value='4' />\n";
            $hidinput .= "<input type='hidden' name='action' value='$action' />\n";
            $hidinput .= "<input type='hidden' name='forum' value='$forum' />\n";

            if ( isset( $topic ) )
            {
                $hidinput .= "<input type='hidden' name='topic' value='$topic' />\n";
            }

            if ( (bool)FALSE === $topic_poster )
            {
                $hidinput .= "<input type='hidden' name='subject' value='$topic_subject' />\n";
            }

            if ( isset( $post_id ) )
            {
                $hidinput .= "<input type='hidden' name='post_id' value='$post_id' />\n";
            }

            if ( isset( $GLOBALS['uinf']['user_sig'] ) )
            {
                $hidinput .= "<input type='hidden' name='user_sig' value='{$GLOBALS['uinf']['user_sig']}' />\n";
            }

        break;

/*        case 5: // Private Message

            $message = '';
            $list_posts = 1;
            $pagetitle = "<h2>" . translate( "Posting Reply in Topic" ) . ":&nbsp;<i>$topic_subject</i></h2>\n";

            if ( isset( $_REQUEST['qid'] ) )
            {
                $message = processMessage( 4 );
            }

            $hidinput  = "<input type='hidden' name='ld' value='4' />\n";
            $hidinput .= "<input type='hidden' name='action' value='2' />\n";
            $hidinput .= "<input type='hidden' name='forum' value='$forum' />\n";
            $hidinput .= "<input type='hidden' name='topic' value='$topic' />\n";
            $hidinput .= "<input type='hidden' name='subject' value='$topic_subject' />\n";

        break;*/

    } // End Switch

    // Common & Sanitizer Input Fields

    $hidinput .= "<input type='hidden' name='start' value='$start' />\n";
    $hidinput .= "<input type='hidden' name='clickit_form' value='message' />\n";
    $hidinput .= "<input type='hidden' name='bb_encode' value='1' />\n";
    $hidinput .= "<input type='hidden' name='mpn_sectype' value='1' />\n";

    if ( _FORUM_POST_TYPE_ == 1 )
    {
        $hidinput .= "<input type='hidden' name='stripit_form' value='subject|username|password' />\n";
    }
    else
    {
        $hidinput .= "<input type='hidden' name='stripit_form' value='username|password' />\n";
    }

    // Generate Ouuput String

    $content = '';

    $content .= $pagetitle . '<br />' . "\n";

    if ( _FORUM_POST_TYPE_ == 4 )
    {
        $content .= getMessagePreview( $message );

        $message = processMessage( 3, $message );

        $content .= "<br /><br />\n";

        $content.= "<h2>" . translate( "Edit Your Post" ) . "</h2><br />\n";

        if ( $topic_subject == '' || $message == '' )
        {
            $content .= '<div class="error">' . "\n";

            if ( $topic_subject == '' )
            {
                $content .= translate( 'Please Fill In Subject For This Topic' );
                $content .= '<br /><br />';
            }

            if ( $message == '' )
            {
                $content .= translate( 'Please Fill In Message For This Topic' );
            }

            $content .= '</div>' . "\n";
        }
    }

    $labelcss = 'style="background-color: ' . $bgcolor3 . ';"';
    $labelcss1 = 'style="background-color: ' . $bgcolor3 . ';"';
    $formcss = 'style="background-color: ' . $bgcolor1 . ';"';

    $content .= getSubmissionForm( $message, $hidinput, $topic_subject, $topic_poster, ( isset( $finfo['image'] ) ) ? ( $finfo['image'] ) : ( NULL ) );

    $content .= '<br />' . "\n";

    if ( isset( $list_posts ) && $list_posts === 1 )
    {
        // REF: getTopicPosts( $show = TRUE, $loc = NULL, $query = NULL )

        $query = 'ld=' . _FORUM_POST_TYPE_ . '&amp;forum=' . $forum . '&amp;topic=' . $topic;
        $content .= getTopicPosts( FALSE, 'forum_submit', $query );
    }

    return $content;

} // End Function

/**
 * Generate A Submission Form
 *
 * @return string
 */

function getSubmissionForm( $message, $hidinput, $topic_subject, $topic_poster, $image )
{
    global $topic, $labelcss, $labelcss1, $formcss;

    $content = "<form action='./forum_submit.php' method='post' name='coolsus'>\n";

        $content .= $hidinput;

        $content .= '<table class="forumsubmis" summary="forum submission">' . "\n";

        $content .= '<tr><td class="flabel" ' . $labelcss1 . '>' . "\n";

            $content .= translate( 'Nickname: ' );

        $content .= '</td><td class="formdata" ' . $formcss . '><b><i>';

            $content .= $GLOBALS['uinf']['uname'];

        $content .= '</i></b></td></tr>';

        if ( is_null( $topic ) || $topic == '' || (bool)TRUE === $topic_poster )
        {
            $content .= '<tr><td class="flabel" ' . $labelcss1 . '>' . "\n";

                $content .= translate( 'Subject' ) . ":&nbsp;\n";

            $content .= '</td><td class="formdata" ' . $formcss . '>' . "\n";

                $content .= '<input type="text" name="subject" size="50" maxlength="100" value="' . $topic_subject . '" />' . "\n";

                $content .= '</td></tr>' . "\n";
        }

        $content .= '<tr><td class="flabel" ' . $labelcss . '>' . "\n";

            $content .= translate( 'Message Icon: ' );

        $content .= '</td><td class="formdata" ' . $formcss . '>' . "\n";

		    $content .= getMsgIcons( $image );

        $content .= '</td></tr><tr><td class="formlabel1" ' . $labelcss . '>' . "\n";

            $content .= translate( 'Message' ) . ':&nbsp;';

            $content .= '<br /><br />' . "\n";

            $html_status  = translate( "HTML" );
            $html_status .= ':&nbsp;&nbsp;<em class="look">';

            if ( ! $GLOBALS['bbencoder'] -> allow_html )
            {
                $html_status .= ( $GLOBALS['bbencoder'] -> allow_html ) ? ( translate( 'Allowed' ) ) : ( translate( 'Disabled' ) );
            }
            else
            {
                $html_status .= ( $GLOBALS['bbencoder'] -> allow_html ) ? ( translate( 'ON' ) ) : ( translate( 'OFF' ) );
            }

            $html_status .= '</em>';

            $content .= '<span class="font6">' . $html_status . '</span>' . "\n";

            $content .= '<br /><br />';

            $bbcode_status  = "<a href='bbcode_ref.php' target='blank' title='" . translate( "BBCode Reference" ) . "'>" . translate( "BBCode" ) . "</a>";
            $bbcode_status .= ':&nbsp;&nbsp;<em class="look">';
            $bbcode_status .= ( $GLOBALS['bbencoder'] -> allow_bbcode ) ? ( translate( 'ON' ) ) : ( translate( 'OFF' ) );
            $bbcode_status .= '</em>';

            $content .= "<span class='font6'>$bbcode_status</span>\n";

            $content .= '<br /><br />';

            $smile_status  = "<a href='bb_smilies.php' target='blank' title='" . translate( "Emoticon Reference" ) . "'>" . translate( "Emoticons" ) . "</a>";
            $smile_status .= ':&nbsp;&nbsp;<em class="look">';
            $smile_status .= ( ! isset( $_POST['smile'] ) ) ? ( translate( 'ON' ) ) : ( translate( 'OFF' ) );
            $smile_status .= '</em>';

            $content .= "<span class='font6'>$smile_status</span>\n";

            $content .= '<br /><br /><br /><div class="center">';

            $content .= getClickEmoticons();

            $content .= addFormatOption( TRUE, TRUE );

            $content .= '<br />';

            $tarows = ( isset( $_REQUEST['tarows'] ) ) ? ( $_REQUEST['tarows'] ) : ( 20 );
            $tacols = ( isset( $_REQUEST['tacols'] ) ) ? ( $_REQUEST['tacols'] ) : ( 65 );

            /*$content .= '<span class="label">' . translate( 'Textarea Size' ) . ":  </span>\n";

            $content .= '<br /><br />';

            $content .= '<input type="text" name="tarows" size="3" maxlength="3" value="' . $tarows . '" />' . "\n";

            $content .= translate( 'Rows' ) . "\n";

            $content .= '<input type="text" name="tacols" size="3" maxlength="3" value="' . $tacols . '" />' . "\n";

            $content .= translate( 'Cols' ) . "\n";

            $content .= '<br /><br />';

            $content .= '<input class="button" type="submit" name="tarefresh" value="' . translate( 'Resize' ) . '" />' . "\n";

            $content .= extractQuery();*/

            $content .= '</div>' . "\n";

        $content .= '</td><td class="formdata" ' . $formcss . '>' . "\n";

            $content .= '<span class="label">' . translate( 'NOTE' ) . ": </span>\n";

            $content .= translate( 'ALL Code <b>MUST</b> be posted using the bbcode <i>code</i> tags<br />or by using the <i>Literal</i> text format option' );

            $content .= '<br /><br />';

            $content .= '<textarea name="message" rows="' . $tarows . '" cols="' . $tacols . '" wrap="virtual">' . "\n";

                $content .= $_SERVER['SAN'] -> trimContent( $message );

            $content .= '</textarea>' . "\n";

            if ( $GLOBALS['bbencoder'] -> allow_bbcode || isset( $_POST['bbcode'] ) )
            {
                $content .= getBBButtons();
            }

        $content .= '</td></tr><tr><td class="flabel" ' . $labelcss . '>' . "\n";

            $content .= translate( 'Options: ' ) . "\n";

       $content .= '</td><td class="formdata" ' . $formcss . '>' . "\n";

            if ( $GLOBALS['bbencoder'] -> allow_html || isset( $_POST['html'] ) )
            {
                $sel = ( isset( $_POST['html'] ) ) ? ( 'checked="1"' ) : ( NULL );

                $content .= "<input type='checkbox' name='html' $sel />" . translate( "Disable HTML on this Post" ) . "\n";

                $content .= "<br />\n";
            }

            if ( $GLOBALS['bbencoder'] -> allow_bbcode || isset( $_POST['bbcode'] ) )
            {
                $sel = ( isset( $_POST['bbcode'] ) ) ? ( 'checked="1"' ) : ( NULL );

                $content .= "<input type='checkbox' name='bbcode' $sel />" . translate( "Disable BBCode on this Post" ) . "\n";

                $content .= "<br />\n";
            }

            $sel = ( isset( $_POST['smile'] ) ) ? ( 'checked="1"' ) : ( NULL );

            $content .= "<input type='checkbox' name='smile' $sel />" . translate( "Disable Smiles on this Post" ) . "\n";

            $content .= "<br />\n";

            if ( _MPN_USER )
            {
                $sel = ( $GLOBALS['uinf']['attachsig'] == 1 ) ? ( 'checked="1"' ) : ( NULL );

                $content .= "<input type='checkbox' name='sig' $sel />" . translate( "Show Signature" ) . "\n";

                $content .= "( " . translate( "This can be altered or added in your" ) . " <a href='./user.php' title='" . translate( "User Account Settings" ) . "'>" . translate( "User Profile Page" ) . "</a> )\n";

                $content .= "<br />\n";
            }

            if ( _MPN_ADMIN && $GLOBALS['uinf']['uid'] > 1 )
            {
                $sel = ( _FORUM_ADMIN_USER_ && $GLOBALS['uinf']['uid'] > 1 ) ? ( 'checked="1"' ) : ( NULL );

                $content .= "<input type='checkbox' name='togfausr' $sel />" . translate( "ADMIN: Submit Post Using My User Account" ) . "?\n";
                $content .= "<br />\n";
            }

        $content .= "</td></tr><tr><td colspan='2'>\n";

            $content .= "<div class='submit_lb'>\n";

                $content .= "<input class='button' type='submit' name='preview' value='" . translate( "Preview" ) . "' />\n";
                $content .= "&nbsp;\n";
                $content .= "<input class='button' type='submit' name='submit' value='" . translate( "Submit" ) . "' />\n";
                $content .= "&nbsp;\n";
                $content .= "<input class='button' type='reset' name='clear' value='" . translate( "Clear" ) . "' />\n";

                if ( _FORUM_POST_TYPE_ == 3 )
                {
                    $content .= "&nbsp;\n";
                    $content .= "<input class='button' type='submit' name='delete' value='" . translate( "Delete" ) . "' />\n";
                }

            $content .= '</div>' . "\n";

        $content .= '</td></tr></table>' . "\n";

    $content .= '</form>' . "\n";

    return $content;

} // End Function

/**
 * Preview A Message Before Posting
 *
 * @return string
 */

function getMessagePreview( $message )
{
    global $mpnTables, $serv_offset, $bgcolor1, $bgcolor2, $bgcolor3, $mpn_anonymous_id, $anonymous, $topic_subject;

    $content = '';
    $posterdata = $GLOBALS['uinf'];
    $time = _MPN_TIMESTAMP;
    $image_subject = ( isset( $_POST['image_subject'] ) )
                   ? ( $_POST['image_subject'] )
                   : ( 'icon1.gif' );

    $preview_message = processMessage( 1, $message, FALSE, $posterdata['user_sig'] );
    $posterdata['rank_display'] = getPosterInfo( $posterdata['uid'], $posterdata['rank'], $posterdata['posts'] );

    $content .= '<table class="forumtopic" summary="">' . "\n";

   $content .= '<tr bgcolor="' . $bgcolor2 . '">' . "\n";

        $content .= '<th>' . translate( 'Author' ) . '</th>' . "\n";
        $content .= '<th>' . translate( 'Previewing Forum Post' ) . ' ' . $topic_subject . '</th>' . "\n";

    $content .= '</tr><td class="forumuserstatus" bgcolor="' . $bgcolor1 . '">' . "\n";

        $content .= "<p class='font4'>\n";

            $content .= '<b>' . $posterdata['uname'] . '</b><br />' . "\n";

            $content .= '<span class="font6">' . $posterdata['rank_display'] . '<br />';

            if ( $posterdata['uid'] > 1 )
            {
                $content .= getPosterDisplayInfo( $posterdata );
            }

        $content .= "</p>\n";

    $content .= "</td><td class='forummessage' bgcolor='$bgcolor3'>";

        $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/subject/' . $image_subject . '" alt="posticon" />' . "\n";

        $content .= '<span class="font4">' . "\n";

            $content .= '&nbsp;&nbsp;' . translate( 'Posted: ' );
            $content .= getDisplayTime( $time, 'datestring', FALSE );

        $content .= '</span><br /><br />' . "\n";

        $content .= '<div class="bbcode_msg">' . "\n";

            $content .= $preview_message;

        $content .= '</div>' . "\n";

        $content .= '<br /><br />';

        $content .= "<div class='forumicons'>\n";

            $content .= '<hr class="lft" />' . "\n";

            if ( $posterdata['uid'] > 1 )
            {
                getUserIcons( $posterdata );
            }

        $content .= "</div>\n";

    $content .= '</td></tr></table>' . "\n";

    return $content;

}  // End Function


// ##### PAGE CONTENT SUB-BLOCKS #####


/**
 * Get The Posters Information
 *
 * @return string
 */

function getPosterDisplayInfo( $posterdata )
{
    $content = translate( 'Joined: ');
    $content .= getDisplayTime( $posterdata['user_regdate'], 'linksdatestring' );
    $content .= '<br />' . translate( 'Posts: ' ) . $posterdata['posts'] . "\n";

    if ( isset( $posterdata['user_from'] ) && $posterdata['user_from'] != '' )
    {
        $content .= '<br />' . translate( 'From: ' ) . $posterdata['user_from'] . "\n";
    }

    $content .= '<div>' . "\n";

    if ( isset( $posterdata['user_from_flag'] ) && $posterdata['user_from_flag'] != '' )
    {
       if ( is_file( './images/flags/' . $posterdata['user_from_flag'] ) )
       {
           $content .= '<br /><img class="flag" src="' . _MPN_ROOT_URI . 'images/flags/' . $posterdata['user_from_flag'] . '" width="32" height="20" alt="' . substr( $posterdata['user_from_flag'], 0, strpos( $posterdata['user_from_flag'], '.' ) ) . '" />' . "\n";
           $content .= '&nbsp;&nbsp;' . "\n";
       }
    }

    if ( isset( $posterdata['user_avatar'] ) && $posterdata['user_avatar'] != '' )
    {
        if ( is_file( './images/forum/avatar/' . $posterdata['user_avatar'] ) )
        {
            $content .= '<img class="avatar" src="' . _MPN_ROOT_URI . 'images/forum/avatar/' . $posterdata['user_avatar'] . '" alt="avatar" />' . "\n";
        }
    }

    $content .= '</div>' . "\n";

    return $content;

} // End Function

/**
 * Generates User Icons For Each Post.
 *
 * @param array ( $posterdata -> array of posters data )
 * @return string ( user icons ready for output )
 */

function getUserIcons( $posterdata )
{
    $content = '&nbsp&nbsp;<a href="user.php?op=userinfo&amp;uname=' . $posterdata['uname'] . '"><img src="' . _MPN_ROOT_URI . 'images/forum/icons/profile.gif" alt="' . translate( 'Member Information For' ) . ' ' . $posterdata['uname'] . '" ' . _T_NN4_BORDER . ' /></a><span class="font4">' . translate( 'Profile' ) . '</span>' . "\n";

    $content .= '&nbsp;&nbsp;<a href="./replypmsg.php?send2=1&amp;to_userid=' . $posterdata['uname'] . '"><img src="' . _MPN_ROOT_URI . 'images/forum/icons/inbox.gif" alt="' . translate( 'Send Private Message To' ) . ' ' . $posterdata['uname'] . '" ' . _T_NN4_BORDER . ' /></a>' . "\n";


    if ( isset( $posterdata['femail'] ) && $posterdata['femail'] != '' )
    {
        $content .= '&nbsp;&nbsp;<a href="mailto:' . $posterdata['femail'] . '"><img src="' . _MPN_ROOT_URI . 'images/forum/icons/email.gif" alt="' . translate( 'Send Email To' ) . ' ' . $posterdata['uname'] . '" ' . _T_NN4_BORDER . ' /></a>' . "\n";
    }

    if ( isset( $posterdata['url'] ) && $posterdata['url'] != '' )
    {
        if ( strstr( 'http://', $posterdata['url'] ) )
        {
            $posterdata['url'] = 'http://' . $posterdata['url'];
        }

        $content .= '&nbsp;&nbsp;<a href="' . $posterdata['url'] . '" target="_blank"><img src="' . _MPN_ROOT_URI . 'images/forum/icons/homepage.gif" alt="' . translate( 'Go To' ) . ' ' . $posterdata['uname'] . '\'s ' . translate( 'Website' ) . '" ' . _T_NN4_BORDER . ' /></a>' . "\n";
    }

    if ( isset( $posterdata['user_icq'] ) && $posterdata['user_icq'] != '' )
    {
        $content .= '&nbsp;&nbsp;<a href="http://wwp.icq.com/' . $posterdata['user_icq'] . '#pager" target="_blank">';

        if ( _USR_ICQ_STATUS_ )
        {
            $content .= '<img src="http://online.mirabilis.com/scripts/online.dll?icq=' . $posterdata['user_icq'] . '&amp;img=5" alt="' . translate( 'Send ICQ Meesage To' ) . ' ' . $posterdata['uname'] . '" ' . _T_NN4_BORDER . ' />';
        }
        else
        {
            $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/icons/icq_on.gif" alt="' . translate( 'Send ICQ Meesage To' ) . ' ' . $posterdata['uname'] . '" ' . _T_NN4_BORDER . ' />';
        }

        $content .= '</a>' . "\n";
    }

    if ( isset( $posterdata['user_aim'] ) && $posterdata['user_aim'] != "" )
    {
        $content .= '&nbsp;&nbsp;<a href="aim:goim?screenname=' . $posterdata['user_aim'] . '&amp;message=Hi+' . $posterdata['user_aim'] . '.+Are+you+there?"><img src="' . _MPN_ROOT_URI . 'images/forum/icons/aim.gif" alt="' . translate( 'Send AIM Meesage To' ) . ' ' . $posterdata['uname'] . '" ' . _T_NN4_BORDER . ' /></a>' . "\n";
    }

    if ( isset( $posterdata['user_yim'] ) && $posterdata['user_yim'] != '' )
    {
        $content .= '&nbsp;&nbsp;<a href="http://edit.yahoo.com/config/send_webmesg?.target=' . $posterdata['user_yim'] . '&amp;.src=pg"><img src="' . _MPN_ROOT_URI . 'images/forum/icons/yim.gif" alt="' . translate( 'Send YIM Message To' ) . ' ' . $posterdata['uname'] . '" ' . _T_NN4_BORDER . ' /></a>' . "\n";
    }

    if ( isset( $posterdata['user_msnm'] ) && $posterdata['user_msnm'] != '' )
    {
        $content .= '&nbsp;&nbsp;<a href="./user.php?op=userinfo&amp;uname=' . $posterdata['uname'] . '"><img src="' . _MPN_ROOT_URI . 'images/forum/icons/msnm.gif" alt="' . $posterdata['uname'] . '\'s ' . translate( 'MSNM Number Is' ) . ' ' . $posterdata['user_msnm'] . '" ' . _T_NN4_BORDER . ' /></a>' . "\n";
    }

    return $content;

}  // End Function

/**
 * Generates Special Icons For Each Post.
 *
 * @param integer ( $post_id -> ID of the current post )
 * @param array ( $posterdata -> array of posters data )
 * @global integer ( $forum -> forum id )
 * @global integer ( $topic -> topic id )
 * @global integer ( $start -> page to start on )
 * @return string ( icons ready for output )
 */

function getSpecialIcons( $post_id, $posterdata )
{
    global $forum, $topic, $start, $mpn_anonymous_id;

    $content = '&nbsp;&nbsp;<a href="./forum_submit.php?ld=2&amp;forum=' . $forum . '&amp;topic=' . $topic . '&amp;qid=' . $post_id . '&amp;start=' . $start . '"><img src="' . _MPN_ROOT_URI . 'images/forum/icons/quote.gif" alt="' . translate( 'Quote And Reply To This Message' ) . '" ' . _T_NN4_BORDER . ' /></a><span class="font4">' . translate( 'Quote' ) . '</span>' . "\n";

    if ( $GLOBALS['uinf']['mod'] || ( $posterdata['uid'] == $GLOBALS['uinf']['uid'] && $posterdata['uid'] != $mpn_anonymous_id  ) )
    {
       $content .= '&nbsp;&nbsp;<a href="./forum_submit.php?ld=3&amp;forum=' . $forum . '&amp;topic=' . $topic . '&amp;post_id=' . $post_id . '&amp;start=' . $start . '"><img src="' . _MPN_ROOT_URI . 'images/forum/icons/edit.gif" alt="' . translate( 'Edit This Message' ) . '" ' . _T_NN4_BORDER . ' /></a><span class="font4">' . translate( 'Edit' ) . '</span>' . "\n";
    }

    if ( $GLOBALS['uinf']['mod'] )
    {
        $content .= '&nbsp;&nbsp;<a href="./topicadmin.php?mode=viewip&amp;forum=' . $forum . '&amp;topic=' . $topic . '&amp;post_id=' . $post_id . '"><img src="' . _MPN_ROOT_URI . 'images/forum/icons/ip_logged.gif" alt="' . translate( 'View Logged IP For This User' ) . '" ' . _T_NN4_BORDER . ' /></a> <span class="font4">ip</span>' . "\n";
    }

    return $content;

}  // End Function


/**
 * Get Message Icons And Generate Radio Buttons
 *
 * @global array ( $finfo -> array of image info for current forum )
 * @return string ( icons and radio buttons )
 */

function getMsgIcons( $msgimg = NULL )
{
    if ( isset( $msgimg ) && ! isset( $_REQUEST['image_subject'] ) )
    {
        $msgimg = $msgimg;
    }
    else if ( isset( $_REQUEST['image_subject'] ) )
    {
        $msgimg = $_REQUEST['image_subject'];
    }
    else
    {
        $msgimg = 'icon1.gif';
    }

    return $_SERVER['F_LIB'] -> getShowImageSelect( 'images/forum/subject/', 'coolsus', 'image_subject', $msgimg, 'post_icon' );

    /*// REFERENCE: dirContents( $dir_root, $allowed_files = NULL, $strip_ext = FALSE )

    $dir_root = './images/forum/subject';
    $allowed_files = array( 'gif', 'jpg', 'jpeg', 'png' );
    $icon_ary = $_SERVER['F_LIB'] -> dirContents( $dir_root, $allowed_files );
    $content = '';

    foreach( $icon_ary AS $key => $file )
    {
        $sel = ( $file == $msgimg ) ? ( 'checked="1"' ) : ( '' );

        $content .= '<input type="radio" value="' . $file . '" name="image_subject" ' . $sel . '></input>' . "\n";
        $content .= '<img class="msgicon" src="' . _MPN_ROOT_URI . 'images/forum/subject/' . $file . '" alt="subject icon" ' . _T_NN4_BORDER . ' />' . "\n";

        if ( ( $key % 8 ) == 7 )
        {
            $content .= '<br />';
        }
    }

    return $content;*/

}  // End Function

/**
 * Generate An Administrative Warning If User Is Not Found
 * In The Users Table.
 *
 * @param integer ( $uid -> users_id )
 * @param string ( $uname -> users name if available )
 * @return string
 */

function getAdminWarning( $uid, $topicid = NULL, $uname = NULL )
{
    global $mpnTables;

    $msg = '<div class="adminwarn">' . "\n";
    $msg .= '<br /><br /><em class="warn">!! ' . translate( 'Administrative Warning' ) . ' !!</em><br />';
    $msg .= '<b>' . translate( 'The User' ) . ' ' . $uname . ' ( ' . translate( 'ID' ) . ': ' . abs( $uid ) . ' )';
    $msg .= '<br />' . translate( 'Was Not Found In The User Database' ) . '</b>';

    if ( _ADMIN_TRUSTED && ! is_null( $topicid ) )
    {
        $fcm = new ForumMaint( $mpnTables );
        $msg .= $fcm -> getAdminInterface( $uid, $topicid );
        unset( $fcm );
    }

    $msg .= '</div><br />' . "\n";

    return $msg;

} // End Function


// ##### HEADER AND FOOTER BLOCKS #####


/**
 * Generates Internal Forum Header Navigation.
 *
 * @param string ( $title -> forum or post title )
 * @global string ( $sitename -> sitename )
 * @global integer ( $forum -> forum id )
 * @return string
 */

function getHeaderNav( $title = NULL, $loc = NULL, $totalcnt = NULL, $limit = NULL, $query = NULL )
{
    global $forumconfig, $sitename, $forum, $topic, $bgcolor1, $access_report, $start;
    static $content;

    if ( ! is_null( $content ) ) { return $content; }

    $mods = getModerators();
    $showme = '<span style="font-weight:bold;color:#ff0000">&raquo;&raquo;&nbsp;</span>';

    $content = '<div class="forumhnav" style="background:' . $bgcolor1 . '">' . "\n";

    $content .= '<table class="center"><tr><td class="t-left"><p>' . "\n";

    if ( $mods != '' )
    {
        $content .= '<b>' . translate( 'Moderated By: ' ) . '</b> ' . $mods;
        $content .= '<br />';
    }

    $content .= '<a href="forum.php" title="Forum Main Page">' . $sitename . ' ' . translate( 'Forum Index' ) . '</a>' . "\n";

    $content .= '<br />&nbsp;&nbsp;';

    $content .= $showme;

    if ( $loc == 'viewtopic' )
    {
        $content .= '<a href="./viewforum.php?forum=' . $forum . '" title="List Topics In Forum">' . _FORUM_NAME_ . '</a>' . "\n";
    }
    else
    {
        $content .= _FORUM_NAME_;
    }

    if ( ! empty( $title ) && $title != _FORUM_NAME_ )
    {
        $content .= '<br />&nbsp;&nbsp;&nbsp;&nbsp;';

        $content .= $showme;

        $content .= $title;
    }

    $content .= '</p></td><td class="t-right">' . "\n";

    if ( _FORUM_ALLOW_POSTING_ )
    {
        if ( ! empty( $title ) )
        {
            $content .= '<a href="forum_submit.php?ld=1&amp;forum=' . $forum . '" alt="New Topic"><img src="' . _MPN_ROOT_URI . 'images/forum/icons/new_topic-dark.jpg" alt="New Topic" ' . _T_NN4_BORDER . ' /></a>' . "\n";
        }

        if ( $loc == 'viewtopic' )
        {
            if ( _TOPIC_LOCKED_ )
            {
                $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/icons/reply_locked-dark.jpg" ' . _T_NN4_BORDER . ' />' . "\n";
            }
            else
            {
                $content .= '<a href="forum_submit.php?ld=2&amp;topic=' . $topic . '&amp;forum=' . $forum . '&amp;start=' . $start . '">';
                $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/icons/reply-dark.jpg" ' . _T_NN4_BORDER . ' /></a>' . "\n";
            }
        }
    }
    else
    {
        $content .= '<p>' . $access_report . '</p>' . "\n";
    }

    $content .= '</td></tr></table>' . "\n";

    $content .= getPageNav( $loc, $totalcnt, $limit, $query );

    $content .= '</div><br />' . "\n";

    return $content;

} // End Function

/**
 * Get Footer Naviagation
 *
 * @return string
 */

function getFooterNav( $title = NULL, $loc = NULL, $totalcnt = NULL, $limit = NULL, $query = NULL )
{
    global $bgcolor1, $bgcolor2, $bgcolor3, $forumconfig, $total;

    $content = '<br />' . "\n";

    if ( ! empty( $loc ) && ( $totalcnt > $forumconfig['posts_per_page'] ) && _FORUM_SHOW_BOTTOM_NAV_ )
    {
        $content .= getHeaderNav( $title, $loc, $totalcnt, $limit, $query );

        $content .= '<br />' . "\n";
    }

    $content .= '<div class="forumfnav">' . "\n";

    if ( $loc == 'viewtopic' )
    {
        if ( ! _TOPIC_LOCKED_ && ( ( _MPN_USER || _MPN_ADMIN ) || _FORUM_ACCESS_ <= $GLOBALS['uinf']['level'] ) )
        {
            $content .= getQuickReply( $title );
        }
    }

    $content .= '<div class="forumpmsrch">' . "\n";

    $content .= '<table class="simpleborders"><tr style="background:' . $bgcolor1 . '"><th class="center w50">' . "\n";

    $content .= '<p class="subtitle"><b>' . translate( 'Member Messages' ) . '</p></b>' . "\n";

    $content .= '</th><th class="center w50">' . "\n";

    $content .= '<p class="subtitle"><b>' . translate( 'Forum Search & Navigation' ) . '</p></b>' . "\n";

    $content .= '</th></tr><tr style="background:' . $bgcolor3 . '"><td class="t-left w50">' . "\n";

    $content .= '<br />' . "\n";

    if ( ! _MPN_USER )
    {
        $content .= '&nbsp;<p class="center font1"><b>' . "\n";
        $content .= translate( 'Log in to check your private messages' ) . '</b></p>' . "\n";
        $content .= '<br /><br />' . "\n";

        $content .= userLoginForm( 't-left' );
    }
    else
    {
        $total_messages = getStats( $GLOBALS['uinf']['uid'], 'count', 'pmsgs' );
        $new_messages = getStats( $GLOBALS['uinf']['uid'], 'count', 'newpmsgs' );

        $content .= '<img class="msgicon" src="' . _MPN_ROOT_URI . 'images/forum/icons/inbox.gif" alt="Private Messages" />&nbsp;' . "\n";

        $content .= '<a href="./viewpmsg.php" title="Private Message Read/Write">' . translate( 'Private Message Read/Write' ) . '</a><br /><br />' . "\n";

        $content .= '<span class="font3">';

        if ( $total_messages > 0 )
        {
            if ( $new_messages > 0 )
            {
               $content .= $new_messages . '&nbsp;' . translate( 'New Messages' ) . '&nbsp;|&nbsp;';
            }
            else
            {
                $content .= translate( 'No New Messages' ) . '&nbsp;|&nbsp;';
            }

            $content .= $total_messages . '&nbsp;' . translate( 'Total Messages.' );
        }
        else
        {
            $content .= translate( 'You don\'t have any Messages.' );
        }

       $content .= '</span>' . "\n";
   }

    $content .= '</td>' . "\n";

    $content .= '<td class="t-right w50"><br />' . "\n";

    $content .= getSearchBlock();

    $content .= getForumNav();

    $content .= '</td></tr></table>' . "\n";

    $content .= '</div>' . "\n";

    if ( $loc != 'viewtopic' )
    {
        $content .= '<br /><br />' . "\n";

        $content .= getIconLegend();
    }

    $content .= '</div>' . "\n";

    return $content;

}  // End Function


// ##### HEADER AND FOOTER SUB-BLOCKS #####


/**
 * Generates Forum Navigation Dropdown.
 *
 * @return string
 */

function getForumNav( $css_class = NULL )
{
    $content = '';
    $css_class = ( empty( $css_class ) ) ? ( NULL ) : ( 'class="' . $css_class . '"' );

    if ( ( $result = getResultSet( 1 ) ) )
    {
        $content .= '<br /><form ' . $css_class . ' action="viewforum.php" method="get">' . "\n";

        $content .= '<b>' . translate( 'Jump To Forum:' ) . '</b>&nbsp;' . "\n";

        $content .= '<select name="forum" onChange="submit()">' . "\n";

            $content .= '<option value="cat_all">' . translate( 'Forum Index' ) . '</option>' . "\n";

                $cat = '';

                for( $i = 0; $i < mysql_num_rows( $result ); $i++ )
                {
                    if ( ! @mysql_data_seek( $result, $i ) || ! @( $row = mysql_fetch_array( $result ) ) )
                    {
                        continue;
                    }

                    $_SERVER['SAN'] -> slashIT( $v );

                    $sel = ( isset( $_REQUEST['forum'] ) && $row[0] == $_REQUEST['forum'] )
                         ? ( 'selected="yes"' )
                         : ( '' );

                    if ( $row[2] != $cat )
                    {
                        $content .= '<option></option>' . "\n";

                        $content .= '<option value="cat_' . base64_encode( $row[2] ) . '">' . $row[2] . '</option>' . "\n";
                    }

                    $content .= '<option value="' . $row[0] . '" ' . $sel . '>&nbsp;&nbsp;' . $row[1] . '</option>' . "\n";
                    $cat = $row[2];
                }

                $content .= '<option></option>' . "\n";

           $content .= '</select>' . "\n";

           $content .= '<input class="button" type="submit" value="' . translate( 'Go' ) . '"></input>' . "\n";

       $content .= '</form>' . "\n";
    }

    return $content;

}  // End Function

/**
 * Generates Page Navigation Header Block
 *
 * @return string
 */

function getPageNav( $loc, $totalcnt = NULL, $limit = NULL, $query = NULL )
{
    global $forumconfig, $start, $topic, $forum, $post_id, $bgcolor2;

    static $content;

    if ( ! is_null( $content ) ) { return $content; }

    $content = '';
    $skiplnk = 0;
    $query = trim( $query );

    if ( ! empty( $totalcnt ) )
    {
        $total = $totalcnt;
    }
    else
    {
        $total = ( $loc == 'viewtopic' )
               ? ( getStats( $topic, 'count', 'topic' ) )
               : ( getStats( $forum, 'count', 'forum_topics' ) );

    }

    $limit = ( ! empty( $limit ) && $limit != 0 )
           ? ( $limit )
           : ( $forumconfig['posts_per_page'] );

    if ( $total <= $limit ) { return; }

    $page = 1;
    $curr_page = ceil( $start / $limit ) + 1;
    $total_pages = ceil( $total / $limit );
    $pgrange = array( 1, 2, $curr_page - 1, $curr_page, $curr_page + 1, $total_pages - 1, $total_pages );

    $content .= '<div class="forumpgnav" style="background:' . $bgcolor2 . '">' . "\n";

    $content .= '<p class="subtitle1">' . translate( 'Page' ) . ' ' . $curr_page . ' ' . translate( 'Of' ) . ' ' . $total_pages . '</p>' . "\n";

    $content .= '<br /><br />' . "\n";

    $content .= "<span class='label'><b>" . translate( 'Go To Page: ' ) . "</b></span>";

    for( $x = 0; $x < $total; $x += $limit )
    {
        $link = NULL;

        if ( ! in_array( $page, $pgrange ) )
        {
            if ( ( $skiplnk == 0 || ( $skiplnk > 0 && $page > $pgrange[4] ) ) && substr( $content, - 4 ) != '... ' )
            {
                $content .= ' ... ';
                $skiplnk++;
            }

            $page++;
            continue;
        }

        if ( $page != 1 )
        {
            if ( $skiplnk != 1 && $skiplnk != 3 )
            {
                $content .= ' &middot; ';
            }

            if ( $skiplnk == 1 || $skiplnk == 3 ) { $skiplnk++; }
        }

        if ( $page == $curr_page )
        {
            $link = '<em class="look">' . $page . '</em>';
        }
        else
        {
            $link = $loc . '.php?';
            $qstring = NULL;

            switch( $loc )
            {
                case 'viewforum':
                    $qstring .= ( ! empty( $query ) ) ? ( $query ) : ( 'forum=' . $forum );
                break;

                case 'viewtopic':
                    $qstring .= ( ! empty( $query ) ) ? ( $query ) : ( 'forum=' . $forum . '&amp;topic=' . $topic );
                break;

                case 'searchbb':
                    $qstring .= ( ! empty( $query ) ) ? ( $query ) : ( '' );
                break;

                case 'forum_submit':

                    $qstring .= ( ! empty( $query ) )
                              ? ( ( _FORUM_POST_TYPE_ == 3 )
                                  ? ( $query . '&amp;post_id=' . $post_id )
                                  : ( $query )
                                )
                              : ( '' );
                break;

                DEFAULT:
                    $qstring .= 'forum=' . $forum;
                break;

            } // End Switch

            $qstring .= '&amp;start=' . $x;

            if ( ! empty( $query ) )
            {
                $link = $link . 'qdoc=' . base64_encode( $qstring );
            }
            else
            {
                $link .= $qstring;
            }

            $link = '<a href="' . $link . '" title="' . translate( 'Go To Page ' ) . $page . '">' . $page . '</a>' . "\n";
        }

        $content .= $link;

        $page++;

    } // End for loop

    // Page Quick Jump Form If Pages Num > 2

    if ( $total_pages > 2 )
    {
        $page = 0;
        $qstring = NULL;

        $content .= '  &nbsp;  ' . "\n";

       $content .= "<form class='makeinline' action='" . $loc . ".php' method='get'>\n";

            switch( $loc )
            {
                case 'viewforum':
                    $qstring .= 'forum=' . $forum;
                break;

                case 'viewtopic':
                    $qstring .= 'forum=' . $forum . '&amp;topic=' . $topic;
                break;

                DEFAULT:
                    $qstring .= ( ! empty( $query ) ) ? ( $query ) : ( 'forum=' . $forum );
                break;

            } // End Switch

            $content .= "<b>" . translate( 'Jump To Page' ) . ":</b>\n";

            $content .= '<input type="hidden" name="qdoc" value="' . base64_encode( $qstring ) . '" />' . "\n";

            $content .= '<select name="start" onChange="submit()">' . "\n";

                for( $x = 0; $x < $total; $x += $limit )
                {
                    $page++;
                    $sel = ( $x == $start ) ? ( 'selected="1"' ) : ( NULL );

                    $content .= '<option value="' . $x . '" ' . $sel . '>' . $page . '</option>' . "\n";
                }

            $content .= "</select>\n";

           $content .= "<input class='button' type='submit' value='" . translate( "Go" ) . "'></input>\n";

        $content .= '</form>' . "\n";
    }

    $content .= '</div>' . "\n";

    return $content;

} // End Function

/**
 * Generate Embedded Topic Page Navigation.
 *
 * @return string
 */

function getTopicPageNav( $topiclink, $topic_cnt )
{
    global $forumconfig;

    $pstart = $content = NULL;

    $content .= '&nbsp;&nbsp;&nbsp;<span class="font3">(<img src="' . _MPN_ROOT_URI . 'images/forum/icons/posticon.gif">' . translate( 'Go to Page' ) . '&nbsp;';

    $pagenr = 1;
    $skippages = 0;

    for( $x = 0; $x < $topic_cnt; $x += $forumconfig['posts_per_page'] )
    {
        $lastpage = ( ( $x + $forumconfig['posts_per_page'] ) >= $topic_cnt );

        if ( $lastpage )
        {
            $pstart = '&amp;start=' . $x;
        }
        else
        {
            if ( $x != 0 )
            {
                $pstart = '&amp;start=' . $x;
            }
        }

        if ( $pagenr > 3 && $skippages != 1 )
        {
            $content .= ', ... ';
            $skippages = 1;
        }

        if ( $skippages != 1 || $lastpage )
        {
            if ( $x != 0 )
            {
                $content .= ', ';
            }

            $content .= '<a href="' . $topiclink . $pstart . '">' . $pagenr . '</a>';
        }

        $pagenr++;
    }

    $content .= ")</span>";

    return $content;

} // End Function

/**
 * Generates Forum Type Icon Legend
 *
 * @return string ( legend )
 */

function getIconLegend()
{
    global $forumconfig, $chkpage;

    if ( (bool)FALSE === strpos( $_SERVER['PHP_SELF'], 'forum' ) ) { return; }

    $content = OpenTable( TRUE );

    $content .= '<div class="forumlegend">' . "\n";

    $content .= '<h2>' . translate( 'Icon Legend' ) . '</h2>';
    $content .= '<hr class="w80" />' . "\n";

    $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/icons/folder.gif" alt=""> = ' . translate( 'No New Posts since your last visit.' ) . '&nbsp;&nbsp;' . "\n";

    $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/icons/lock.gif" alt=""> = ' . translate( 'Forum Or Topic is Locked' );

    $content .= '<br /><br />' . "\n";

    $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/icons/red_folder.gif" alt="" /> = ' . translate( 'New Posts Since Your Last Visit.' ) . '&nbsp;&nbsp;' . "\n";

    $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/icons/hot_folder.gif" alt="" /> = ' . translate( 'New Posts In This Forum Or Topic' ) . '&nbsp;&nbsp;' . "\n";;

    $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/icons/hot_red_folder.gif" alt="" /> = ' . translate( 'More Than' ) . ' ' . $forumconfig['hot_threshold'] . ' ' . translate( 'Posts' ) . '&nbsp;&nbsp;' . "\n";

    $content .= '<br /><br />' . "\n";

    $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/icons/alluser.gif" alt="" />' . '&nbsp;&nbsp;' . "\n";

    $content .= translate( 'All Users Can Read/Write' );

    $content .= '&nbsp;&nbsp;' . "\n";

    $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/icons/member.gif" alt="" />' . '&nbsp;&nbsp;' . "\n";

    $content .= translate( 'All Users Can Read/Only Registered User Can Write' );

    $content .= '<br /><br />' . "\n";

    $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/icons/modadm.gif" alt="" />' . '&nbsp;&nbsp;' . "\n";

    $content .= translate( 'All Users Can Read/Only Moderators Can Write' );

    $content .= '&nbsp;&nbsp;' . "\n";

    $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/icons/privat.gif" alt="" />' . '&nbsp;&nbsp;' . "\n";

    $content .= translate( 'Private Area' );

    $content .= '</div>' . "\n";

    $content .= CloseTable(  TRUE );

    return $content;

}  // End Function

/**
 * Generate Forum Search Block
 *
 * @return string ( search form )
 */

function getSearchBlock()
{
    $content = '<form name="fsrch" id="fsrch" action="searchbb.php" method="post">' . "\n";

       $content .= '<input type="hidden" name="addterm" value="any">' . "\n";
       $content .= '<input type="hidden" name="bbsearch" value="1">' . "\n";
       $content .= '<input type="hidden" name="sortby" value="p.post_time">' . "\n";
       $content .= '<label>' . translate( 'Search' ) . ':</label>&nbsp;' . "\n";
       $content .= '<input class="textbox" type="text" name="term" size="25">' . "\n";
       $content .= '<input type="hidden" name="submit" value="submit">' . "\n";

       $content .= '<input class="button" type="submit" value="' . translate( 'Go' ) . '"></input>' . "\n";

       $content .= '<br /><br /><span class="font5">[ <a href="searchbb.php?addterm=any&adv=1">' . translate( 'Advanced Search' ) . '</a> ]</span>' . "\n";

    $content .= '</form>' . "\n";

    return $content;

} // End Function

/**
 *
 *
 *
 */

function getSearchLink()
{
    $content = '<a class="subtitle2" href="#fsrch" title="' . translate( 'Search Forums' ) . '">' . translate( 'Search Forums' ) . '</a>' . "\n";
    $content .= '<br /><br />';

    return $content;
}

/**
 * Generate A Quick Reply Form
 *
 * @return string
 */

function getQuickReply( $topic_subject )
{
    $content = '<div class="forumqreply">' . "\n";

    $content .= '<p class="subtitle1">' . translate( 'Post A Quick Reply' ) . '</p>';

    $content .= '<form action="./forum_submit.php" method="post">' . "\n";

        $content .= '<p class="forms">' . "\n";

            $content .= '<input type="hidden" name="ld" value="4" />' . "\n";
            $content .= '<input type="hidden" name="action" value="2" />' . "\n";
            $content .= '<input type="hidden" name="subject" value="' . $topic_subject . '" />' . "\n";
            $content .= '<input type="hidden" name="clickit_form" value="message" />' . "\n";
            $content .= '<input type="hidden" name="bb_encode" value="1" />' . "\n";
            $content .= '<input type="hidden" name="stripit_form" value="username|password" />' . "\n";
            $content .= '<input type="hidden" name="mpn_sectype" value="1" />' . "\n";

            $content .= extractQuery();

            $content .= '<textarea type="text" name="message" rows="4" cols="55" maxlength="800" /></textarea>' . "\n";

            $content .= '<br /><br />' . "\n";

            $content .= '<input class="button center" type="submit" name="submit" value="' . translate( 'Post Reply' ) . '" />' . "\n";

        $content .= '</p>';

    $content .= '</form>';

    $content .= '</div>';

    return $content;

}  // End Function


// ##### ADMINISTRATION BLOCKS #####


/**
 * Build Administrative Links For Output
 *
 * @return string
 */

function getAdminLinks( $topic_id = NULL, $table = FALSE, $status = NULL )
{
    global $forum, $topic;

    if ( ! $GLOBALS['uinf']['mod'] ) { return ''; }

    $topic = ( ! empty( $topic_id ) ) ? ( $topic_id ) : ( $topic );
    $status = ( is_null( $status ) ) ? ( _TOPIC_LOCKED_ ) : ( $status );
    $content = '';

    $content .= "<div class='forumadmin'>";

    if ( ! $table )
    {
        $content .= '<br /><p class="subtitle1">';
        $content .= translate( 'Administration Tools' );
        $content .= '<hr class="w40" />';
        $content .= '</p>' . "\n";
    }

    if ( $status )
    {
        $content .= "<a href=\"topicadmin.php?mode=unlock&topic=$topic&forum=$forum\"><IMG SRC=\"images/forum/icons/unlock_topic.gif\" ALT=\"".translate("Unlock this Topic")."\" BORDER=0></a> ";
    }
    else
    {
        $content .= "<a href=\"topicadmin.php?mode=lock&topic=$topic&forum=$forum\"><IMG SRC=\"images/forum/icons/lock_topic.gif\" ALT=\"".translate("Lock this Topic")."\" BORDER=0></a> ";
    }

    $content .= "<a href=\"topicadmin.php?mode=move&topic=$topic&forum=$forum\"><IMG SRC=\"images/forum/icons/move_topic.gif\" ALT=\"".translate("Move this Topic")."\" BORDER=0></a> ";

    $content .= "<a href=\"topicadmin.php?mode=del&topic=$topic&forum=$forum\"><IMG SRC=\"images/forum/icons/del_topic.gif\" ALT=\"".translate("Delete this Topic")."\" BORDER=0></a>\n";

    $content .= '</div>' . "\n";

    return $content;

} // End Function


// ##### MISC FUNCTIONS #####


/**
 * Generates An Independent Private Forum Login Page
 *
 * @return void
 */

function getPrivateForumLogin( $esct, $ppass )
{
    @( include_once __ROOT__ . 'header.php' )
      OR goBack( translate( 'Include Error' ) );

    $content = '<div class="subtitle1">' . "\n";

    if ( ! empty( $ppass ) )
    {
        $content .= '<em class="warn">' . "\n";

             $content .= translate( 'Incorret Password.  Please Try Again.' );

        $content .= '</em>' . "\n";

        $content .= '</div>' . "\n";

        goBack( $content );
    }

    $content .= translate( 'This is a Private Forum' );

    $content .= '.<br />' . "\n";

    $content .= translate( 'Please enter the password to gain access.' );

    $content .= '</div>' . "\n";

    $content .= '<br /><br />' . "\n";

    $content .= '<div class="center">' . "\n";

        $content .= '<form action="' . $esct . '.php" method="post">' . "\n";

            $content .= '<input type="hidden" name="forum" value="' . $_REQUEST['forum'] . '">' . "\n";

            if ( ! empty( $_REQUEST['topic'] ) )
            {
                $content .= '<input type="hidden" name="topic" value="' . $_REQUEST['topic'] . '">' . "\n";
            }

            $content .= '<p class="forms">' . "\n";

                $content .= '<input type="password" name="passwd" size="25" maxlength="30">' . "\n";

                $content .= '<input class="button" type="submit" name="submit" value="Enter">' . "\n";

            $content .= '</p>' . "\n";

        $content .= '</form>' . "\n";

    $content .= '</div>' . "\n";

    $content .= '<br /><br />' . "\n";

    $title = translate( 'Return To Forum Listing' );

    $content .= '<a class="subtitle1" href="./forum.php" title="' . $title . '">' . $title . '</a>' . "\n";

    echo $content;

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

    exit;

} // End Function

/**
 * Get Message Insert Items.
 *
 * $return string
 */

function putitems( $retcontent = FALSE )
{
    $content = '';

    $content .= getClickEmoticons();

    if ( $GLOBALS['bbencoder'] -> allow_bbcode )
    {
        $content .= getBBButtons();
    }

    if ( ! $retcontent )
    {
        echo $content;
        return;
    }

    return $content;

} // End Function

/**
 * Get BBCode Insert Buttons.
 *
 * @return string
 */

function getBBButtons()
{
    $content = '';
    $targetElement = 'coolsus.message';

    // $butary array syntax: array( jspromptid => array( 'button text', 'button title attrib' ) )

    $butary = array
    (
        'url' => array( translate( 'URL' ) )
      , 'email' => array( translate( 'Email' ) )
      , 'image' => array( translate( 'Image' ) )
      , 'bold' => array( translate( 'Bold' ) )
      , 'italic' => array( translate( 'Italic' ) )
      , 'literal' => array( translate( 'Literal' ), translate( 'Text You Want Displayed Literally' ) )
      , 'quote' => array( translate( 'Quote' ) )
      , 'code' => array( translate( 'Code' ) )
      , 'listopen' => array( translate( 'List Open' ) )
      , 'listitem' => array( translate( 'List Item' ) )
      , 'listclose' => array( translate( 'List Close' ) )
    );


    $content .= '<div class="bbbuttons">' . "\n";

        $content .= '<p class="label">';

            $content .= translate("Click on the buttons to add <a href='bbcode_ref.php' target='blank'>BBCode</a> to your message:");

        $content .= '</p><p class="row">';

            foreach( $butary AS $jsid => $txtary )
            {
                if ( $jsid == 'quote' ) { $content .= '</p><p class="row">'; }

                $titletext = ( isset( $txtary[1] ) ) ? ( $txtary[1] ) : ( $txtary[0] );

                $content .= '<span class="button">';

                    $content .= '<a href="javascript: x()" onClick="DoPrompt( \'' . $jsid . '\', ' . $targetElement . ' );" title="' . $titletext . '">' . $txtary[0] . '</a>';

                $content .= '</span>' . "\n";
            }

        $content .= '</p>';

    $content .= '</div>' . "\n";

    return $content;

} // End Function

/**
 * Get Insert Emoticons.
 *
 * @return string
 */

function getClickEmoticons()
{
    $_ICON_PATH_ = _MPN_ROOT_URI . 'images/forum/smilies/';
    $dir_root = './images/forum/smilies';
    $allowed_files = array( 'gif', 'jpg', 'jpeg', 'png' );
    $icon_ary = $_SERVER['F_LIB'] -> dirContents( $dir_root, $allowed_files );
    $content = '';

    $showicons = array
    (
        'icon_smile.gif' => ' :-) '
      , 'icon_frown.gif' => ' :-( '
      , 'icon_biggrin.gif' => ' :-D '
      , 'icon_wink.gif' => ' ;-) '
      , 'icon_eek.gif' => ' :-o '
      , 'icon_cool.gif' => ' 8-) '
      , 'icon_confused.gif' => ' :-? '
      , 'icon_razz.gif' => ' :-P '
      , 'icon_mad.gif' => ' :-| '
      , 'icon_lol.gif' => ' :lol: '
      , 'icon_rolleyes.gif' => ' :roll: '
      , 'icon_redface.gif' => ' :oops: '
      /*, 'icon_idea.gif' => ' :idea: '
      , 'icon_hammer.gif' => ' :hammer: '
      , 'icon_drink.gif' => ' :pint: '*/
    );

    $content .= ' &nbsp; <span class="label center">';
    $content .= translate( 'Click Icon To Insert' );
    $content .= '</span>' . "\n";
    $content .= '<br />';

    $content .= '<div class="bbemoticons">';
    $breakat = 0;

    foreach( $icon_ary AS $key => $file )
    {
        if ( ! isset( $showicons[ $file ] ) ) { continue; }

        $breakat++;

        $content .= '<a href="javascript: x()" onClick="DoSmilie( \'' . $showicons[ $file ] . '\' );">';

            $content .= '<img src="' . _MPN_ROOT_URI . 'images/forum/smilies/' . $file . '" ' . _T_NN4_BORDER . ' alt="' . $showicons[ $file ] . '">';

        $content .= '</a>' . "\n";

        if ( $breakat == 4 )
        {
            $content .= '<br />';
            $breakat = 0;
        }
    }

    $content .= '</div>' . "\n";

    return $content;

} // End Function

?>